1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 package java.lang;
28 
29 import dalvik.annotation.optimization.FastNative;
30 
31 /**
32  * Class {@code Object} is the root of the class hierarchy.
33  * Every class has {@code Object} as a superclass. All objects,
34  * including arrays, implement the methods of this class.
35  *
36  * @author  unascribed
37  * @see     java.lang.Class
38  * @since   JDK1.0
39  */
40 public class Object {
41 
42     // Android-removed: registerNatives() not used on Android
43     // private static native void registerNatives();
44     // static {
45     //     registerNatives();
46     // }
47 
48     // Android-added: Use Android specific fields for Class and monitor.
49     private transient Class<?> shadow$_klass_;
50     private transient int shadow$_monitor_;
51 
52     /**
53      * Returns the runtime class of this {@code Object}. The returned
54      * {@code Class} object is the object that is locked by {@code
55      * static synchronized} methods of the represented class.
56      *
57      * <p><b>The actual result type is {@code Class<? extends |X|>}
58      * where {@code |X|} is the erasure of the static type of the
59      * expression on which {@code getClass} is called.</b> For
60      * example, no cast is required in this code fragment:</p>
61      *
62      * <p>
63      * {@code Number n = 0;                             }<br>
64      * {@code Class<? extends Number> c = n.getClass(); }
65      * </p>
66      *
67      * @return The {@code Class} object that represents the runtime
68      *         class of this object.
69      * @jls 15.8.2 Class Literals
70      */
71     // Android-changed: Use Android specific fields for Class and monitor.
72     // public final native Class<?> getClass();
getClass()73     public final Class<?> getClass() {
74       return shadow$_klass_;
75     }
76 
77     /**
78      * Returns a hash code value for the object. This method is
79      * supported for the benefit of hash tables such as those provided by
80      * {@link java.util.HashMap}.
81      * <p>
82      * The general contract of {@code hashCode} is:
83      * <ul>
84      * <li>Whenever it is invoked on the same object more than once during
85      *     an execution of a Java application, the {@code hashCode} method
86      *     must consistently return the same integer, provided no information
87      *     used in {@code equals} comparisons on the object is modified.
88      *     This integer need not remain consistent from one execution of an
89      *     application to another execution of the same application.
90      * <li>If two objects are equal according to the {@code equals(Object)}
91      *     method, then calling the {@code hashCode} method on each of
92      *     the two objects must produce the same integer result.
93      * <li>It is <em>not</em> required that if two objects are unequal
94      *     according to the {@link java.lang.Object#equals(java.lang.Object)}
95      *     method, then calling the {@code hashCode} method on each of the
96      *     two objects must produce distinct integer results.  However, the
97      *     programmer should be aware that producing distinct integer results
98      *     for unequal objects may improve the performance of hash tables.
99      * </ul>
100      * <p>
101      * As much as is reasonably practical, the hashCode method defined by
102      * class {@code Object} does return distinct integers for distinct
103      * objects. (This is typically implemented by converting the internal
104      * address of the object into an integer, but this implementation
105      * technique is not required by the
106      * Java&trade; programming language.)
107      *
108      * @return  a hash code value for this object.
109      * @see     java.lang.Object#equals(java.lang.Object)
110      * @see     java.lang.System#identityHashCode
111      */
112     // BEGIN Android-changed: Added a local helper for identityHashCode.
113     // public native int hashCode();
hashCode()114     public int hashCode() {
115         return identityHashCode(this);
116     }
117 
118     // Package-private to be used by j.l.System. We do the implementation here
119     // to avoid Object.hashCode doing a clinit check on j.l.System, and also
120     // to avoid leaking shadow$_monitor_ outside of this class.
identityHashCode(Object obj)121     /* package-private */ static int identityHashCode(Object obj) {
122         int lockWord = obj.shadow$_monitor_;
123         final int lockWordStateMask = 0xC0000000;  // Top 2 bits.
124         final int lockWordStateHash = 0x80000000;  // Top 2 bits are value 2 (kStateHash).
125         final int lockWordHashMask = 0x0FFFFFFF;  // Low 28 bits.
126         if ((lockWord & lockWordStateMask) == lockWordStateHash) {
127             return lockWord & lockWordHashMask;
128         }
129         return identityHashCodeNative(obj);
130     }
131 
132     /**
133      * Return the identity hash code when the information in the monitor field
134      * is not sufficient.
135      */
136     @FastNative
identityHashCodeNative(Object obj)137     private static native int identityHashCodeNative(Object obj);
138     // END Android-changed: Added a local helper for identityHashCode.
139 
140     /**
141      * Indicates whether some other object is "equal to" this one.
142      * <p>
143      * The {@code equals} method implements an equivalence relation
144      * on non-null object references:
145      * <ul>
146      * <li>It is <i>reflexive</i>: for any non-null reference value
147      *     {@code x}, {@code x.equals(x)} should return
148      *     {@code true}.
149      * <li>It is <i>symmetric</i>: for any non-null reference values
150      *     {@code x} and {@code y}, {@code x.equals(y)}
151      *     should return {@code true} if and only if
152      *     {@code y.equals(x)} returns {@code true}.
153      * <li>It is <i>transitive</i>: for any non-null reference values
154      *     {@code x}, {@code y}, and {@code z}, if
155      *     {@code x.equals(y)} returns {@code true} and
156      *     {@code y.equals(z)} returns {@code true}, then
157      *     {@code x.equals(z)} should return {@code true}.
158      * <li>It is <i>consistent</i>: for any non-null reference values
159      *     {@code x} and {@code y}, multiple invocations of
160      *     {@code x.equals(y)} consistently return {@code true}
161      *     or consistently return {@code false}, provided no
162      *     information used in {@code equals} comparisons on the
163      *     objects is modified.
164      * <li>For any non-null reference value {@code x},
165      *     {@code x.equals(null)} should return {@code false}.
166      * </ul>
167      * <p>
168      * The {@code equals} method for class {@code Object} implements
169      * the most discriminating possible equivalence relation on objects;
170      * that is, for any non-null reference values {@code x} and
171      * {@code y}, this method returns {@code true} if and only
172      * if {@code x} and {@code y} refer to the same object
173      * ({@code x == y} has the value {@code true}).
174      * <p>
175      * Note that it is generally necessary to override the {@code hashCode}
176      * method whenever this method is overridden, so as to maintain the
177      * general contract for the {@code hashCode} method, which states
178      * that equal objects must have equal hash codes.
179      *
180      * @param   obj   the reference object with which to compare.
181      * @return  {@code true} if this object is the same as the obj
182      *          argument; {@code false} otherwise.
183      * @see     #hashCode()
184      * @see     java.util.HashMap
185      */
equals(Object obj)186     public boolean equals(Object obj) {
187         return (this == obj);
188     }
189 
190     /**
191      * Creates and returns a copy of this object.  The precise meaning
192      * of "copy" may depend on the class of the object. The general
193      * intent is that, for any object {@code x}, the expression:
194      * <blockquote>
195      * <pre>
196      * x.clone() != x</pre></blockquote>
197      * will be true, and that the expression:
198      * <blockquote>
199      * <pre>
200      * x.clone().getClass() == x.getClass()</pre></blockquote>
201      * will be {@code true}, but these are not absolute requirements.
202      * While it is typically the case that:
203      * <blockquote>
204      * <pre>
205      * x.clone().equals(x)</pre></blockquote>
206      * will be {@code true}, this is not an absolute requirement.
207      * <p>
208      * By convention, the returned object should be obtained by calling
209      * {@code super.clone}.  If a class and all of its superclasses (except
210      * {@code Object}) obey this convention, it will be the case that
211      * {@code x.clone().getClass() == x.getClass()}.
212      * <p>
213      * By convention, the object returned by this method should be independent
214      * of this object (which is being cloned).  To achieve this independence,
215      * it may be necessary to modify one or more fields of the object returned
216      * by {@code super.clone} before returning it.  Typically, this means
217      * copying any mutable objects that comprise the internal "deep structure"
218      * of the object being cloned and replacing the references to these
219      * objects with references to the copies.  If a class contains only
220      * primitive fields or references to immutable objects, then it is usually
221      * the case that no fields in the object returned by {@code super.clone}
222      * need to be modified.
223      * <p>
224      * The method {@code clone} for class {@code Object} performs a
225      * specific cloning operation. First, if the class of this object does
226      * not implement the interface {@code Cloneable}, then a
227      * {@code CloneNotSupportedException} is thrown. Note that all arrays
228      * are considered to implement the interface {@code Cloneable} and that
229      * the return type of the {@code clone} method of an array type {@code T[]}
230      * is {@code T[]} where T is any reference or primitive type.
231      * Otherwise, this method creates a new instance of the class of this
232      * object and initializes all its fields with exactly the contents of
233      * the corresponding fields of this object, as if by assignment; the
234      * contents of the fields are not themselves cloned. Thus, this method
235      * performs a "shallow copy" of this object, not a "deep copy" operation.
236      * <p>
237      * The class {@code Object} does not itself implement the interface
238      * {@code Cloneable}, so calling the {@code clone} method on an object
239      * whose class is {@code Object} will result in throwing an
240      * exception at run time.
241      *
242      * @return     a clone of this instance.
243      * @throws  CloneNotSupportedException  if the object's class does not
244      *               support the {@code Cloneable} interface. Subclasses
245      *               that override the {@code clone} method can also
246      *               throw this exception to indicate that an instance cannot
247      *               be cloned.
248      * @see java.lang.Cloneable
249      */
250     // BEGIN Android-changed: Use native local helper for clone()
251     // Checks whether cloning is allowed before calling native local helper.
252     // protected native Object clone() throws CloneNotSupportedException;
clone()253     protected Object clone() throws CloneNotSupportedException {
254         if (!(this instanceof Cloneable)) {
255             throw new CloneNotSupportedException("Class " + getClass().getName() +
256                                                  " doesn't implement Cloneable");
257         }
258 
259         return internalClone();
260     }
261 
262     /*
263      * Native helper method for cloning.
264      */
265     @FastNative
internalClone()266     private native Object internalClone();
267     // END Android-changed: Use native local helper for clone()
268 
269     /**
270      * Returns a string representation of the object. In general, the
271      * {@code toString} method returns a string that
272      * "textually represents" this object. The result should
273      * be a concise but informative representation that is easy for a
274      * person to read.
275      * It is recommended that all subclasses override this method.
276      * <p>
277      * The {@code toString} method for class {@code Object}
278      * returns a string consisting of the name of the class of which the
279      * object is an instance, the at-sign character `{@code @}', and
280      * the unsigned hexadecimal representation of the hash code of the
281      * object. In other words, this method returns a string equal to the
282      * value of:
283      * <blockquote>
284      * <pre>
285      * getClass().getName() + '@' + Integer.toHexString(hashCode())
286      * </pre></blockquote>
287      *
288      * @return  a string representation of the object.
289      */
toString()290     public String toString() {
291         return getClass().getName() + "@" + Integer.toHexString(hashCode());
292     }
293 
294     /**
295      * Wakes up a single thread that is waiting on this object's
296      * monitor. If any threads are waiting on this object, one of them
297      * is chosen to be awakened. The choice is arbitrary and occurs at
298      * the discretion of the implementation. A thread waits on an object's
299      * monitor by calling one of the {@code wait} methods.
300      * <p>
301      * The awakened thread will not be able to proceed until the current
302      * thread relinquishes the lock on this object. The awakened thread will
303      * compete in the usual manner with any other threads that might be
304      * actively competing to synchronize on this object; for example, the
305      * awakened thread enjoys no reliable privilege or disadvantage in being
306      * the next thread to lock this object.
307      * <p>
308      * This method should only be called by a thread that is the owner
309      * of this object's monitor. A thread becomes the owner of the
310      * object's monitor in one of three ways:
311      * <ul>
312      * <li>By executing a synchronized instance method of that object.
313      * <li>By executing the body of a {@code synchronized} statement
314      *     that synchronizes on the object.
315      * <li>For objects of type {@code Class,} by executing a
316      *     synchronized static method of that class.
317      * </ul>
318      * <p>
319      * Only one thread at a time can own an object's monitor.
320      *
321      * @throws  IllegalMonitorStateException  if the current thread is not
322      *               the owner of this object's monitor.
323      * @see        java.lang.Object#notifyAll()
324      * @see        java.lang.Object#wait()
325      */
326     @FastNative
notify()327     public final native void notify();
328 
329     /**
330      * Wakes up all threads that are waiting on this object's monitor. A
331      * thread waits on an object's monitor by calling one of the
332      * {@code wait} methods.
333      * <p>
334      * The awakened threads will not be able to proceed until the current
335      * thread relinquishes the lock on this object. The awakened threads
336      * will compete in the usual manner with any other threads that might
337      * be actively competing to synchronize on this object; for example,
338      * the awakened threads enjoy no reliable privilege or disadvantage in
339      * being the next thread to lock this object.
340      * <p>
341      * This method should only be called by a thread that is the owner
342      * of this object's monitor. See the {@code notify} method for a
343      * description of the ways in which a thread can become the owner of
344      * a monitor.
345      *
346      * @throws  IllegalMonitorStateException  if the current thread is not
347      *               the owner of this object's monitor.
348      * @see        java.lang.Object#notify()
349      * @see        java.lang.Object#wait()
350      */
351     @FastNative
notifyAll()352     public final native void notifyAll();
353 
354     /**
355      * Causes the current thread to wait until either another thread invokes the
356      * {@link java.lang.Object#notify()} method or the
357      * {@link java.lang.Object#notifyAll()} method for this object, or a
358      * specified amount of time has elapsed.
359      * <p>
360      * The current thread must own this object's monitor.
361      * <p>
362      * This method causes the current thread (call it <var>T</var>) to
363      * place itself in the wait set for this object and then to relinquish
364      * any and all synchronization claims on this object. Thread <var>T</var>
365      * becomes disabled for thread scheduling purposes and lies dormant
366      * until one of four things happens:
367      * <ul>
368      * <li>Some other thread invokes the {@code notify} method for this
369      * object and thread <var>T</var> happens to be arbitrarily chosen as
370      * the thread to be awakened.
371      * <li>Some other thread invokes the {@code notifyAll} method for this
372      * object.
373      * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
374      * thread <var>T</var>.
375      * <li>The specified amount of real time has elapsed, more or less.  If
376      * {@code timeout} is zero, however, then real time is not taken into
377      * consideration and the thread simply waits until notified.
378      * </ul>
379      * The thread <var>T</var> is then removed from the wait set for this
380      * object and re-enabled for thread scheduling. It then competes in the
381      * usual manner with other threads for the right to synchronize on the
382      * object; once it has gained control of the object, all its
383      * synchronization claims on the object are restored to the status quo
384      * ante - that is, to the situation as of the time that the {@code wait}
385      * method was invoked. Thread <var>T</var> then returns from the
386      * invocation of the {@code wait} method. Thus, on return from the
387      * {@code wait} method, the synchronization state of the object and of
388      * thread {@code T} is exactly as it was when the {@code wait} method
389      * was invoked.
390      * <p>
391      * A thread can also wake up without being notified, interrupted, or
392      * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
393      * occur in practice, applications must guard against it by testing for
394      * the condition that should have caused the thread to be awakened, and
395      * continuing to wait if the condition is not satisfied.  In other words,
396      * waits should always occur in loops, like this one:
397      * <pre>
398      *     synchronized (obj) {
399      *         while (&lt;condition does not hold&gt;)
400      *             obj.wait(timeout);
401      *         ... // Perform action appropriate to condition
402      *     }
403      * </pre>
404      * (For more information on this topic, see Section 3.2.3 in Doug Lea's
405      * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
406      * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
407      * Language Guide" (Addison-Wesley, 2001).
408      *
409      * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
410      * interrupted} by any thread before or while it is waiting, then an
411      * {@code InterruptedException} is thrown.  This exception is not
412      * thrown until the lock status of this object has been restored as
413      * described above.
414      *
415      * <p>
416      * Note that the {@code wait} method, as it places the current thread
417      * into the wait set for this object, unlocks only this object; any
418      * other objects on which the current thread may be synchronized remain
419      * locked while the thread waits.
420      * <p>
421      * This method should only be called by a thread that is the owner
422      * of this object's monitor. See the {@code notify} method for a
423      * description of the ways in which a thread can become the owner of
424      * a monitor.
425      *
426      * @param      timeout   the maximum time to wait in milliseconds.
427      * @throws  IllegalArgumentException      if the value of timeout is
428      *               negative.
429      * @throws  IllegalMonitorStateException  if the current thread is not
430      *               the owner of the object's monitor.
431      * @throws  InterruptedException if any thread interrupted the
432      *             current thread before or while the current thread
433      *             was waiting for a notification.  The <i>interrupted
434      *             status</i> of the current thread is cleared when
435      *             this exception is thrown.
436      * @see        java.lang.Object#notify()
437      * @see        java.lang.Object#notifyAll()
438      */
439     // Android-changed: Implement wait(long) non-natively.
440     // public final native void wait(long timeout) throws InterruptedException;
wait(long timeout)441     public final void wait(long timeout) throws InterruptedException {
442         wait(timeout, 0);
443     }
444 
445     /**
446      * Causes the current thread to wait until another thread invokes the
447      * {@link java.lang.Object#notify()} method or the
448      * {@link java.lang.Object#notifyAll()} method for this object, or
449      * some other thread interrupts the current thread, or a certain
450      * amount of real time has elapsed.
451      * <p>
452      * This method is similar to the {@code wait} method of one
453      * argument, but it allows finer control over the amount of time to
454      * wait for a notification before giving up. The amount of real time,
455      * measured in nanoseconds, is given by:
456      * <blockquote>
457      * <pre>
458      * 1000000*timeout+nanos</pre></blockquote>
459      * <p>
460      * In all other respects, this method does the same thing as the
461      * method {@link #wait(long)} of one argument. In particular,
462      * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
463      * <p>
464      * The current thread must own this object's monitor. The thread
465      * releases ownership of this monitor and waits until either of the
466      * following two conditions has occurred:
467      * <ul>
468      * <li>Another thread notifies threads waiting on this object's monitor
469      *     to wake up either through a call to the {@code notify} method
470      *     or the {@code notifyAll} method.
471      * <li>The timeout period, specified by {@code timeout}
472      *     milliseconds plus {@code nanos} nanoseconds arguments, has
473      *     elapsed.
474      * </ul>
475      * <p>
476      * The thread then waits until it can re-obtain ownership of the
477      * monitor and resumes execution.
478      * <p>
479      * As in the one argument version, interrupts and spurious wakeups are
480      * possible, and this method should always be used in a loop:
481      * <pre>
482      *     synchronized (obj) {
483      *         while (&lt;condition does not hold&gt;)
484      *             obj.wait(timeout, nanos);
485      *         ... // Perform action appropriate to condition
486      *     }
487      * </pre>
488      * This method should only be called by a thread that is the owner
489      * of this object's monitor. See the {@code notify} method for a
490      * description of the ways in which a thread can become the owner of
491      * a monitor.
492      *
493      * @param      timeout   the maximum time to wait in milliseconds.
494      * @param      nanos      additional time, in nanoseconds range
495      *                       0-999999.
496      * @throws  IllegalArgumentException      if the value of timeout is
497      *                      negative or the value of nanos is
498      *                      not in the range 0-999999.
499      * @throws  IllegalMonitorStateException  if the current thread is not
500      *               the owner of this object's monitor.
501      * @throws  InterruptedException if any thread interrupted the
502      *             current thread before or while the current thread
503      *             was waiting for a notification.  The <i>interrupted
504      *             status</i> of the current thread is cleared when
505      *             this exception is thrown.
506      */
507     // Android-changed: Implement wait(long, int) natively.
508     /*
509     public final void wait(long timeout, int nanos) throws InterruptedException {
510         if (timeout < 0) {
511             throw new IllegalArgumentException("timeout value is negative");
512         }
513 
514         if (nanos < 0 || nanos > 999999) {
515             throw new IllegalArgumentException(
516                                 "nanosecond timeout value out of range");
517         }
518 
519         if (nanos > 0) {
520             timeout++;
521         }
522 
523         wait(timeout);
524     }
525     */
526     @FastNative
wait(long timeout, int nanos)527     public final native void wait(long timeout, int nanos) throws InterruptedException;
528 
529     /**
530      * Causes the current thread to wait until another thread invokes the
531      * {@link java.lang.Object#notify()} method or the
532      * {@link java.lang.Object#notifyAll()} method for this object.
533      * In other words, this method behaves exactly as if it simply
534      * performs the call {@code wait(0)}.
535      * <p>
536      * The current thread must own this object's monitor. The thread
537      * releases ownership of this monitor and waits until another thread
538      * notifies threads waiting on this object's monitor to wake up
539      * either through a call to the {@code notify} method or the
540      * {@code notifyAll} method. The thread then waits until it can
541      * re-obtain ownership of the monitor and resumes execution.
542      * <p>
543      * As in the one argument version, interrupts and spurious wakeups are
544      * possible, and this method should always be used in a loop:
545      * <pre>
546      *     synchronized (obj) {
547      *         while (&lt;condition does not hold&gt;)
548      *             obj.wait();
549      *         ... // Perform action appropriate to condition
550      *     }
551      * </pre>
552      * This method should only be called by a thread that is the owner
553      * of this object's monitor. See the {@code notify} method for a
554      * description of the ways in which a thread can become the owner of
555      * a monitor.
556      *
557      * @throws  IllegalMonitorStateException  if the current thread is not
558      *               the owner of the object's monitor.
559      * @throws  InterruptedException if any thread interrupted the
560      *             current thread before or while the current thread
561      *             was waiting for a notification.  The <i>interrupted
562      *             status</i> of the current thread is cleared when
563      *             this exception is thrown.
564      * @see        java.lang.Object#notify()
565      * @see        java.lang.Object#notifyAll()
566      */
wait()567     public final void wait() throws InterruptedException {
568         wait(0);
569     }
570 
571     /**
572      * Called by the garbage collector on an object when garbage collection
573      * determines that there are no more references to the object.
574      * A subclass overrides the {@code finalize} method to dispose of
575      * system resources or to perform other cleanup.
576      * <p>
577      * The general contract of {@code finalize} is that it is invoked
578      * if and when the Java&trade; virtual
579      * machine has determined that there is no longer any
580      * means by which this object can be accessed by any thread that has
581      * not yet died, except as a result of an action taken by the
582      * finalization of some other object or class which is ready to be
583      * finalized. The {@code finalize} method may take any action, including
584      * making this object available again to other threads; the usual purpose
585      * of {@code finalize}, however, is to perform cleanup actions before
586      * the object is irrevocably discarded. For example, the finalize method
587      * for an object that represents an input/output connection might perform
588      * explicit I/O transactions to break the connection before the object is
589      * permanently discarded.
590      * <p>
591      * The {@code finalize} method of class {@code Object} performs no
592      * special action; it simply returns normally. Subclasses of
593      * {@code Object} may override this definition.
594      * <p>
595      * The Java programming language does not guarantee which thread will
596      * invoke the {@code finalize} method for any given object. It is
597      * guaranteed, however, that the thread that invokes finalize will not
598      * be holding any user-visible synchronization locks when finalize is
599      * invoked. If an uncaught exception is thrown by the finalize method,
600      * the exception is ignored and finalization of that object terminates.
601      * <p>
602      * After the {@code finalize} method has been invoked for an object, no
603      * further action is taken until the Java virtual machine has again
604      * determined that there is no longer any means by which this object can
605      * be accessed by any thread that has not yet died, including possible
606      * actions by other objects or classes which are ready to be finalized,
607      * at which point the object may be discarded.
608      * <p>
609      * The {@code finalize} method is never invoked more than once by a Java
610      * virtual machine for any given object.
611      * <p>
612      * Any exception thrown by the {@code finalize} method causes
613      * the finalization of this object to be halted, but is otherwise
614      * ignored.
615      *
616      * @throws Throwable the {@code Exception} raised by this method
617      * @see java.lang.ref.WeakReference
618      * @see java.lang.ref.PhantomReference
619      * @jls 12.6 Finalization of Class Instances
620      */
finalize()621     protected void finalize() throws Throwable { }
622 }
623