Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/java/lang/Object.java
12513 views
1
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
2
/*******************************************************************************
3
* Copyright (c) 1998, 2021 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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-exception
22
*******************************************************************************/
23
package java.lang;
24
25
/**
26
* Object is the root of the java class hierarchy. All non-base types
27
* respond to the messages defined in this class.
28
*
29
* @author OTI
30
* @version initial
31
*/
32
public class Object {
33
34
/**
35
* Constructs a new instance of this class.
36
*/
37
public Object() {
38
}
39
40
/**
41
* Answers a new instance of the same class as the receiver,
42
* whose slots have been filled in with the values in the
43
* slots of the receiver.
44
* <p>
45
* Classes which wish to support cloning must specify that
46
* they implement the Cloneable interface, since the native
47
* implementation checks for this.
48
*
49
* @return Object
50
* a shallow copy of this object.
51
* @exception CloneNotSupportedException
52
* if the receiver's class does not implement
53
* the interface Cloneable.
54
*/
55
protected Object clone() throws CloneNotSupportedException
56
{
57
return J9VMInternals.primitiveClone(this);
58
}
59
60
/**
61
* Compares the argument to the receiver, and answers true
62
* if they represent the <em>same</em> object using a class
63
* specific comparison. The implementation in Object answers
64
* true only if the argument is the exact same object as the
65
* receiver (==).
66
*
67
* @param o Object
68
* the object to compare with this object.
69
* @return boolean
70
* <code>true</code>
71
* if the object is the same as this object
72
* <code>false</code>
73
* if it is different from this object.
74
* @see #hashCode
75
*/
76
public boolean equals(Object o) {
77
return this == o;
78
}
79
80
/**
81
* Called by the virtual machine when there are no longer any (non-weak)
82
* references to the receiver. Subclasses can use this facility to
83
* guarantee that any associated resources are cleaned up before
84
* the receiver is garbage collected. Uncaught exceptions which are
85
* thrown during the running of the method cause it to terminate
86
* immediately, but are otherwise ignored.
87
* <p>
88
* Note: The virtual machine assumes that the implementation
89
* in class Object is empty.
90
*
91
* @exception Throwable
92
* The virtual machine ignores any exceptions
93
* which are thrown during finalization.
94
*
95
/*[IF Sidecar19-SE]
96
* @deprecated May cause performance issues, deadlocks and hangs.
97
* Errors in finalizers can lead to resource leaks.
98
/*[ENDIF]
99
*/
100
/*[IF]
101
We leave this one in even if no Thread flag because the user can still
102
explicitly call runAllFinalizers(). So, he won't get finalization for free,
103
but he can still invoke it. Since this method is empty, the space cost for it
104
is negligible, so we leave it in.
105
/*[ENDIF]*/
106
/*[IF JAVA_SPEC_VERSION >= 18] */
107
@Deprecated(forRemoval=true, since="9")
108
/*[ELSEIF JAVA_SPEC_VERSION >= 9] */
109
@Deprecated(forRemoval=false, since="9")
110
/*[ENDIF] JAVA_SPEC_VERSION >= 18 */
111
protected void finalize () throws Throwable {
112
}
113
114
/**
115
* Answers the unique instance of java.lang.Class which
116
* represents the class of the receiver.
117
*
118
* @return the receiver's Class
119
*/
120
public final native Class<? extends Object> getClass();
121
122
/**
123
* Answers an integer hash code for the receiver. Any two
124
* objects which answer <code>true</code> when passed to
125
* <code>.equals</code> must answer the same value for this
126
* method.
127
*
128
* @return the receiver's hash.
129
*
130
* @see #equals
131
*/
132
public int hashCode() {
133
return J9VMInternals.fastIdentityHashCode(this);
134
}
135
136
/**
137
* Causes one thread which is <code>wait</code>ing on the
138
* receiver to be made ready to run. This does not guarantee
139
* that the thread will immediately run. The method can only
140
* be invoked by a thread which owns the receiver's monitor.
141
*
142
* @see #notifyAll
143
* @see #wait()
144
* @see #wait(long)
145
* @see #wait(long,int)
146
* @see java.lang.Thread
147
*/
148
public final native void notify();
149
150
/**
151
* Causes all threads which are <code>wait</code>ing on the
152
* receiver to be made ready to run. The threads are scheduled
153
* according to their priorities as specified in class Thread.
154
* Between any two threads of the same priority the one which
155
* waited first will be the first thread that runs after
156
* being notified. The method can only be invoked by a thread
157
* which owns the receiver's monitor.
158
*
159
* @see #notify
160
* @see #wait()
161
* @see #wait(long)
162
* @see #wait(long,int)
163
* @see java.lang.Thread
164
*/
165
public final native void notifyAll();
166
167
/**
168
* Answers a string containing a concise, human-readable
169
* description of the receiver.
170
*
171
* @return String
172
* a printable representation for the receiver.
173
*/
174
public String toString() {
175
/*[IF]
176
The explicit use of StringBuffer is not necessary as the hex string will not exceed 8 chars
177
and thus the StringBuffer (allocated with classname.length()+16) in the will not grow.
178
/*[ENDIF]*/
179
return this.getClass().getName() + '@' + Integer.toHexString(this.hashCode());
180
}
181
182
/**
183
* Causes the thread which sent this message to be made not
184
* ready to run pending some change in the receiver (as
185
* indicated by <code>notify</code> or <code>notifyAll</code>).
186
* The method can only be invoked by a thread which owns the
187
* receiver's monitor. A waiting thread can be sent
188
* <code>interrupt()</code> to cause it to prematurely stop
189
* waiting, so senders of wait should check that the condition
190
* they were waiting for has been met.
191
* <p>
192
* When the thread waits, it gives up ownership of the
193
* receiver's monitor. When it is notified (or interrupted) it
194
* re-acquires the monitor before it starts running.
195
*
196
* @exception InterruptedException
197
* to interrupt the wait.
198
*
199
* @see Thread#interrupt
200
* @see #notify
201
* @see #notifyAll
202
* @see #wait(long)
203
* @see #wait(long,int)
204
* @see java.lang.Thread
205
*/
206
public final void wait() throws InterruptedException {
207
wait(0, 0);
208
}
209
210
/**
211
* Causes the thread which sent this message to be made not
212
* ready to run either pending some change in the receiver
213
* (as indicated by <code>notify</code> or <code>notifyAll</code>)
214
* or the expiration of the timeout. The method can only be invoked
215
* by a thread which owns the receiver's monitor. A waiting thread
216
* can be sent <code>interrupt()</code> to cause it to prematurely
217
* stop waiting, so senders of wait should check that the condition
218
* they were waiting for has been met.
219
* <p>
220
* When the thread waits, it gives up ownership of the
221
* receiver's monitor. When it is notified (or interrupted) it
222
* re-acquires the monitor before it starts running.
223
*
224
* @param time long
225
* The maximum time to wait in milliseconds.
226
* @exception InterruptedException
227
* to interrupt the wait.
228
*
229
* @see #notify
230
* @see #notifyAll
231
* @see #wait()
232
* @see #wait(long,int)
233
* @see java.lang.Thread
234
*/
235
public final void wait(long time) throws InterruptedException {
236
wait(time, 0);
237
}
238
239
/**
240
* Causes the thread which sent this message to be made not
241
* ready to run either pending some change in the receiver
242
* (as indicated by <code>notify</code> or <code>notifyAll</code>)
243
* or the expiration of the timeout. The method can only be invoked
244
* by a thread which owns the receiver's monitor. A waiting thread
245
* can be sent <code>interrupt()</code> to cause it to prematurely
246
* stop waiting, so senders of wait should check that the condition
247
* they were waiting for has been met.
248
* <p>
249
* When the thread waits, it gives up ownership of the
250
* receiver's monitor. When it is notified (or interrupted) it
251
* re-acquires the monitor before it starts running.
252
*
253
* @param time long
254
* The maximum time to wait in milliseconds.
255
* @param frac int
256
* The fraction of a mSec to wait, specified
257
* in nano seconds.
258
* @exception InterruptedException
259
* to interrupt the wait.
260
*
261
* @see #notify
262
* @see #notifyAll
263
* @see #wait()
264
* @see #wait(long)
265
* @see java.lang.Thread
266
*/
267
public final native void wait(long time, int frac) throws InterruptedException;
268
269
/*
270
* Used as a prototype for the jit.
271
*/
272
/*[PR CMVC 114139]InstantiationException has wrong detail message */
273
private Object newInstancePrototype(Class callerClass) {
274
return null;
275
}
276
}
277
278