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