Path: blob/master/jcl/src/java.base/share/classes/java/lang/Object.java
12513 views
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/1/*******************************************************************************2* Copyright (c) 1998, 2021 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package java.lang;2324/**25* Object is the root of the java class hierarchy. All non-base types26* respond to the messages defined in this class.27*28* @author OTI29* @version initial30*/31public class Object {3233/**34* Constructs a new instance of this class.35*/36public Object() {37}3839/**40* Answers a new instance of the same class as the receiver,41* whose slots have been filled in with the values in the42* slots of the receiver.43* <p>44* Classes which wish to support cloning must specify that45* they implement the Cloneable interface, since the native46* implementation checks for this.47*48* @return Object49* a shallow copy of this object.50* @exception CloneNotSupportedException51* if the receiver's class does not implement52* the interface Cloneable.53*/54protected Object clone() throws CloneNotSupportedException55{56return J9VMInternals.primitiveClone(this);57}5859/**60* Compares the argument to the receiver, and answers true61* if they represent the <em>same</em> object using a class62* specific comparison. The implementation in Object answers63* true only if the argument is the exact same object as the64* receiver (==).65*66* @param o Object67* the object to compare with this object.68* @return boolean69* <code>true</code>70* if the object is the same as this object71* <code>false</code>72* if it is different from this object.73* @see #hashCode74*/75public boolean equals(Object o) {76return this == o;77}7879/**80* Called by the virtual machine when there are no longer any (non-weak)81* references to the receiver. Subclasses can use this facility to82* guarantee that any associated resources are cleaned up before83* the receiver is garbage collected. Uncaught exceptions which are84* thrown during the running of the method cause it to terminate85* immediately, but are otherwise ignored.86* <p>87* Note: The virtual machine assumes that the implementation88* in class Object is empty.89*90* @exception Throwable91* The virtual machine ignores any exceptions92* which are thrown during finalization.93*94/*[IF Sidecar19-SE]95* @deprecated May cause performance issues, deadlocks and hangs.96* Errors in finalizers can lead to resource leaks.97/*[ENDIF]98*/99/*[IF]100We leave this one in even if no Thread flag because the user can still101explicitly call runAllFinalizers(). So, he won't get finalization for free,102but he can still invoke it. Since this method is empty, the space cost for it103is negligible, so we leave it in.104/*[ENDIF]*/105/*[IF JAVA_SPEC_VERSION >= 18] */106@Deprecated(forRemoval=true, since="9")107/*[ELSEIF JAVA_SPEC_VERSION >= 9] */108@Deprecated(forRemoval=false, since="9")109/*[ENDIF] JAVA_SPEC_VERSION >= 18 */110protected void finalize () throws Throwable {111}112113/**114* Answers the unique instance of java.lang.Class which115* represents the class of the receiver.116*117* @return the receiver's Class118*/119public final native Class<? extends Object> getClass();120121/**122* Answers an integer hash code for the receiver. Any two123* objects which answer <code>true</code> when passed to124* <code>.equals</code> must answer the same value for this125* method.126*127* @return the receiver's hash.128*129* @see #equals130*/131public int hashCode() {132return J9VMInternals.fastIdentityHashCode(this);133}134135/**136* Causes one thread which is <code>wait</code>ing on the137* receiver to be made ready to run. This does not guarantee138* that the thread will immediately run. The method can only139* be invoked by a thread which owns the receiver's monitor.140*141* @see #notifyAll142* @see #wait()143* @see #wait(long)144* @see #wait(long,int)145* @see java.lang.Thread146*/147public final native void notify();148149/**150* Causes all threads which are <code>wait</code>ing on the151* receiver to be made ready to run. The threads are scheduled152* according to their priorities as specified in class Thread.153* Between any two threads of the same priority the one which154* waited first will be the first thread that runs after155* being notified. The method can only be invoked by a thread156* which owns the receiver's monitor.157*158* @see #notify159* @see #wait()160* @see #wait(long)161* @see #wait(long,int)162* @see java.lang.Thread163*/164public final native void notifyAll();165166/**167* Answers a string containing a concise, human-readable168* description of the receiver.169*170* @return String171* a printable representation for the receiver.172*/173public String toString() {174/*[IF]175The explicit use of StringBuffer is not necessary as the hex string will not exceed 8 chars176and thus the StringBuffer (allocated with classname.length()+16) in the will not grow.177/*[ENDIF]*/178return this.getClass().getName() + '@' + Integer.toHexString(this.hashCode());179}180181/**182* Causes the thread which sent this message to be made not183* ready to run pending some change in the receiver (as184* indicated by <code>notify</code> or <code>notifyAll</code>).185* The method can only be invoked by a thread which owns the186* receiver's monitor. A waiting thread can be sent187* <code>interrupt()</code> to cause it to prematurely stop188* waiting, so senders of wait should check that the condition189* they were waiting for has been met.190* <p>191* When the thread waits, it gives up ownership of the192* receiver's monitor. When it is notified (or interrupted) it193* re-acquires the monitor before it starts running.194*195* @exception InterruptedException196* to interrupt the wait.197*198* @see Thread#interrupt199* @see #notify200* @see #notifyAll201* @see #wait(long)202* @see #wait(long,int)203* @see java.lang.Thread204*/205public final void wait() throws InterruptedException {206wait(0, 0);207}208209/**210* Causes the thread which sent this message to be made not211* ready to run either pending some change in the receiver212* (as indicated by <code>notify</code> or <code>notifyAll</code>)213* or the expiration of the timeout. The method can only be invoked214* by a thread which owns the receiver's monitor. A waiting thread215* can be sent <code>interrupt()</code> to cause it to prematurely216* stop waiting, so senders of wait should check that the condition217* they were waiting for has been met.218* <p>219* When the thread waits, it gives up ownership of the220* receiver's monitor. When it is notified (or interrupted) it221* re-acquires the monitor before it starts running.222*223* @param time long224* The maximum time to wait in milliseconds.225* @exception InterruptedException226* to interrupt the wait.227*228* @see #notify229* @see #notifyAll230* @see #wait()231* @see #wait(long,int)232* @see java.lang.Thread233*/234public final void wait(long time) throws InterruptedException {235wait(time, 0);236}237238/**239* Causes the thread which sent this message to be made not240* ready to run either pending some change in the receiver241* (as indicated by <code>notify</code> or <code>notifyAll</code>)242* or the expiration of the timeout. The method can only be invoked243* by a thread which owns the receiver's monitor. A waiting thread244* can be sent <code>interrupt()</code> to cause it to prematurely245* stop waiting, so senders of wait should check that the condition246* they were waiting for has been met.247* <p>248* When the thread waits, it gives up ownership of the249* receiver's monitor. When it is notified (or interrupted) it250* re-acquires the monitor before it starts running.251*252* @param time long253* The maximum time to wait in milliseconds.254* @param frac int255* The fraction of a mSec to wait, specified256* in nano seconds.257* @exception InterruptedException258* to interrupt the wait.259*260* @see #notify261* @see #notifyAll262* @see #wait()263* @see #wait(long)264* @see java.lang.Thread265*/266public final native void wait(long time, int frac) throws InterruptedException;267268/*269* Used as a prototype for the jit.270*/271/*[PR CMVC 114139]InstantiationException has wrong detail message */272private Object newInstancePrototype(Class callerClass) {273return null;274}275}276277278