12cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom/*
22cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * Licensed to the Apache Software Foundation (ASF) under one or more
32cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * contributor license agreements.  See the NOTICE file distributed with
42cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * this work for additional information regarding copyright ownership.
52cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * The ASF licenses this file to You under the Apache License, Version 2.0
62cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * (the "License"); you may not use this file except in compliance with
72cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * the License.  You may obtain a copy of the License at
82cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
92cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     http://www.apache.org/licenses/LICENSE-2.0
102cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
112cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * Unless required by applicable law or agreed to in writing, software
122cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
132cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * See the License for the specific language governing permissions and
152cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * limitations under the License.
162cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom */
172cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom/*
182cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * Copyright (C) 2008 The Android Open Source Project
192cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
202cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License");
212cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * you may not use this file except in compliance with the License.
222cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * You may obtain a copy of the License at
232cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
242cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *      http://www.apache.org/licenses/LICENSE-2.0
252cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
262cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * Unless required by applicable law or agreed to in writing, software
272cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
282cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
292cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * See the License for the specific language governing permissions and
302cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * limitations under the License.
312cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom */
322cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
332cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrompackage java.lang;
342cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
352cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom/**
362cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * The root class of the Java class hierarchy. All non-primitive types
372cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * (including arrays) inherit either directly or indirectly from this class.
382cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
392cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <a name="writing_equals"><h4>Writing a correct {@code equals} method</h4></a>
402cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>Follow this style to write a canonical {@code equals} method:
412cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <pre>
422cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   // Use @Override to avoid accidental overloading.
432cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   &#x0040;Override public boolean equals(Object o) {
442cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Return true if the objects are identical.
452cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // (This is just an optimization, not required for correctness.)
462cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     if (this == o) {
472cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *       return true;
482cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     }
492cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
502cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Return false if the other object has the wrong type.
512cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // This type may be an interface depending on the interface's specification.
522cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     if (!(o instanceof MyType)) {
532cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *       return false;
542cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     }
552cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
562cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Cast to the appropriate type.
572cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // This will succeed because of the instanceof, and lets us access private fields.
582cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     MyType lhs = (MyType) o;
592cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
602cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Check each field. Primitive fields, reference fields, and nullable reference
612cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // fields are all treated differently.
622cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     return primitiveField == lhs.primitiveField &amp;&amp;
632cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *             referenceField.equals(lhs.referenceField) &amp;&amp;
642cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *             (nullableField == null ? lhs.nullableField == null
652cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *                                    : nullableField.equals(lhs.nullableField));
662cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   }
672cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * </pre>
682cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>If you override {@code equals}, you should also override {@code hashCode}: equal
692cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * instances must have equal hash codes.
702cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
712cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>See <i>Effective Java</i> item 8 for much more detail and clarification.
722cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
732cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <a name="writing_hashCode"><h4>Writing a correct {@code hashCode} method</h4></a>
742cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>Follow this style to write a canonical {@code hashCode} method:
752cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <pre>
762cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   &#x0040;Override public int hashCode() {
772cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Start with a non-zero constant.
782cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     int result = 17;
792cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
802cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     // Include a hash for each field.
812cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + (booleanField ? 1 : 0);
822cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
832cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + byteField;
842cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + charField;
852cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + shortField;
862cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + intField;
872cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
882cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + (int) (longField ^ (longField >>> 32));
892cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
902cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + Float.floatToIntBits(floatField);
912cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
922cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     long doubleFieldBits = Double.doubleToLongBits(doubleField);
932cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + (int) (doubleFieldBits ^ (doubleFieldBits >>> 32));
942cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
952cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + Arrays.hashCode(arrayField);
962cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
972cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result + referenceField.hashCode();
982cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     result = 31 * result +
992cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *         (nullableReferenceField == null ? 0
1002cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *                                         : nullableReferenceField.hashCode());
1012cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
1022cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     return result;
1032cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   }
1042cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * </pre>
1052cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
1062cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>If you don't intend your type to be used as a hash key, don't simply rely on the default
1072cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * {@code hashCode} implementation, because that silently and non-obviously breaks any future
1082cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * code that does use your type as a hash key. You should throw instead:
1092cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <pre>
1102cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   &#x0040;Override public int hashCode() {
1112cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     throw new UnsupportedOperationException();
1122cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   }
1132cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * </pre>
1142cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
1152cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>See <i>Effective Java</i> item 9 for much more detail and clarification.
1162cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *
1172cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <a name="writing_toString"><h4>Writing a useful {@code toString} method</h4></a>
1182cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>For debugging convenience, it's common to override {@code toString} in this style:
1192cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <pre>
1202cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   &#x0040;Override public String toString() {
1212cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *     return getClass().getName() + "[" +
1222cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *         "primitiveField=" + primitiveField + ", " +
1232cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *         "referenceField=" + referenceField + ", " +
1242cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *         "arrayField=" + Arrays.toString(arrayField) + "]";
1252cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom *   }
1262cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * </pre>
1272cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>The set of fields to include is generally the same as those that would be tested
1282cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * in your {@code equals} implementation.
1292cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom * <p>See <i>Effective Java</i> item 10 for much more detail and clarification.
1302cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom */
1312cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrompublic class Object {
1322cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
1332cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    private transient Class<?> shadow$_klass_;
1342cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    private transient int shadow$_monitor_;
1352cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
136a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi    // Uncomment the following two fields to enable brooks pointers.
137a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi    // Meant to do "#ifdef USE_BROOKS_POINTER ... #endif" but no macros.
138a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi    //
13989f30966ad2678ddc1c5088b76604a065eacaa67Hiroshi Yamauchi    // Note names use a 'x' prefix and the _x_rb_ptr_ field is of
140a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi    // type int instead of Object to go with the alphabetical/by-type
141a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi    // field order.
14289f30966ad2678ddc1c5088b76604a065eacaa67Hiroshi Yamauchi    // private transient int shadow$_x_rb_ptr_;
14389f30966ad2678ddc1c5088b76604a065eacaa67Hiroshi Yamauchi    // private transient int shadow$_x_xpadding_;
144a7c69f785f7d1b07b7da22cfb9150c584ee143f4Hiroshi Yamauchi
1452cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
1462cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Constructs a new instance of {@code Object}.
1472cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
1482cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public Object() {
1492cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
1502cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
1512cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
1522cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Creates and returns a copy of this {@code Object}. The default
1532cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * implementation returns a so-called "shallow" copy: It creates a new
1542cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * instance of the same class and then copies the field values (including
1552cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * object references) from this instance to the new instance. A "deep" copy,
1562cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * in contrast, would also recursively clone nested objects. A subclass that
1572cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * needs to implement this kind of cloning should call {@code super.clone()}
1582cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * to create the new instance and then create deep copies of the nested,
1592cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * mutable objects.
1602cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
1612cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @return a copy of this object.
1622cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws CloneNotSupportedException
1632cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if this object's class does not implement the {@code
1642cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             Cloneable} interface.
1652cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
1662cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    protected Object clone() throws CloneNotSupportedException {
1672cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        if (!(this instanceof Cloneable)) {
1682cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom            throw new CloneNotSupportedException("Class " + getClass().getName() +
1692cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom                                                 " doesn't implement Cloneable");
1702cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        }
1712cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
1722cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        return internalClone();
1732cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
1742cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
1752cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /*
1762cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Native helper method for cloning.
1772cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
1782cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    private native Object internalClone();
1792cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
1802cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
1812cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Compares this instance with the specified object and indicates if they
1822cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * are equal. In order to be equal, {@code o} must represent the same object
1832cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * as this instance using a class-specific comparison. The general contract
1842cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * is that this comparison should be reflexive, symmetric, and transitive.
1852cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Also, no object reference other than null is equal to null.
1862cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
1872cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>The default implementation returns {@code true} only if {@code this ==
1882cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * o}. See <a href="{@docRoot}reference/java/lang/Object.html#writing_equals">Writing a correct
1892cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@code equals} method</a>
1902cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * if you intend implementing your own {@code equals} method.
1912cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
1922cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>The general contract for the {@code equals} and {@link
1932cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * #hashCode()} methods is that if {@code equals} returns {@code true} for
1942cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * any two objects, then {@code hashCode()} must return the same value for
1952cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * these objects. This means that subclasses of {@code Object} usually
1962cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * override either both methods or neither of them.
1972cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
1982cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @param o
1992cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *            the object to compare this instance with.
2002cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @return {@code true} if the specified object is equal to this {@code
2012cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *         Object}; {@code false} otherwise.
2022cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #hashCode
2032cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
2042cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public boolean equals(Object o) {
2052cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        return this == o;
2062cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
2072cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
2082cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
2092cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Invoked when the garbage collector has detected that this instance is no longer reachable.
2102cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * The default implementation does nothing, but this method can be overridden to free resources.
2112cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2122cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>Note that objects that override {@code finalize} are significantly more expensive than
2132cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * objects that don't. Finalizers may be run a long time after the object is no longer
2142cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
2152cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Note also that finalizers are run on a single VM-wide finalizer thread,
2162cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
2172cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * for a class that has a native peer and needs to call a native method to destroy that peer.
2182cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Even then, it's better to provide an explicit {@code close} method (and implement
2192cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@link java.io.Closeable}), and insist that callers manually dispose of instances. This
2202cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * works well for something like files, but less well for something like a {@code BigInteger}
2212cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * where typical calling code would have to deal with lots of temporaries. Unfortunately,
2222cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * code that creates lots of temporaries is the worst kind of code from the point of view of
2232cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * the single finalizer thread.
2242cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2252cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>If you <i>must</i> use finalizers, consider at least providing your own
2262cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@link java.lang.ref.ReferenceQueue} and having your own thread process that queue.
2272cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2282cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>Unlike constructors, finalizers are not automatically chained. You are responsible for
2292cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * calling {@code super.finalize()} yourself.
2302cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2312cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer
2322cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * thread.
2332cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2342cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * See <i>Effective Java</i> Item 7, "Avoid finalizers" for more.
2352cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
2362cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    @FindBugsSuppressWarnings("FI_EMPTY")
2372cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    protected void finalize() throws Throwable {
2382cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
2392cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
2402cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
2412cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Returns the unique instance of {@link Class} that represents this
2422cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * object's class. Note that {@code getClass()} is a special case in that it
2432cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * actually returns {@code Class<? extends Foo>} where {@code Foo} is the
2442cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * erasure of the type of the expression {@code getClass()} was called upon.
2452cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>
2462cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * As an example, the following code actually compiles, although one might
2472cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * think it shouldn't:
2482cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>
2492cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <pre>{@code
2502cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *   List<Integer> l = new ArrayList<Integer>();
2512cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *   Class<? extends List> c = l.getClass();}</pre>
2522cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2532cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @return this object's {@code Class} instance.
2542cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
2552cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final Class<?> getClass() {
2562cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom      return shadow$_klass_;
2572cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
2582cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
2592cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
2602cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Returns an integer hash code for this object. By contract, any two
2612cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * objects for which {@link #equals} returns {@code true} must return
2622cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * the same hash code value. This means that subclasses of {@code Object}
2632cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * usually override both methods or neither method.
2642cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2652cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>Note that hash values must not change over time unless information used in equals
2662cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * comparisons also changes.
2672cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2682cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>See <a href="{@docRoot}reference/java/lang/Object.html#writing_hashCode">Writing a correct
2692cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@code hashCode} method</a>
2702cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * if you intend implementing your own {@code hashCode} method.
2712cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
2722cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @return this object's hash code.
2732cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #equals
2742cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
2752cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public int hashCode() {
2766917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier        int lockWord = shadow$_monitor_;
2776917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier        final int lockWordMask = 0xC0000000;  // Top 2 bits.
2786917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier        final int lockWordStateHash = 0x80000000;  // Top 2 bits are value 2 (kStateHash).
2796917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier        if ((lockWord & lockWordMask) == lockWordStateHash) {
2806917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier            return lockWord & ~lockWordMask;
2816917aebf2eb26c2b003a72d09c1c5bb6310160b0Mathieu Chartier        }
2822cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        return System.identityHashCode(this);
2832cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
2842cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
2852cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
2862cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Causes a thread which is waiting on this object's monitor (by means of
2872cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * calling one of the {@code wait()} methods) to be woken up. If more than
2882cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * one thread is waiting, one of them is chosen at the discretion of the
2892cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * VM. The chosen thread will not run immediately. The thread
2902cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * that called {@code notify()} has to release the object's monitor first.
2912cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Also, the chosen thread still has to compete against other threads that
2922cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * try to synchronize on the same object.
29323122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
29423122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>This method can only be invoked by a thread which owns this object's
2952cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * monitor. A thread becomes owner of an object's monitor
2962cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <ul>
2972cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing a synchronized method of that object;</li>
2982cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing the body of a {@code synchronized} statement that
2992cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * synchronizes on the object;</li>
3002cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing a synchronized static method if the object is of type
3012cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@code Class}.</li>
3022cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * </ul>
3032cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
3042cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notifyAll
3052cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait()
3062cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long)
3072cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long,int)
3082cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see java.lang.Thread
3092cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
3102cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final native void notify();
3112cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
3122cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
3132cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Causes all threads which are waiting on this object's monitor (by means
3142cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * of calling one of the {@code wait()} methods) to be woken up. The threads
3152cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * will not run immediately. The thread that called {@code notify()} has to
3162cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * release the object's monitor first. Also, the threads still have to
3172cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * compete against other threads that try to synchronize on the same object.
31823122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
31923122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>This method can only be invoked by a thread which owns this object's
3202cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * monitor. A thread becomes owner of an object's monitor
3212cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <ul>
3222cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing a synchronized method of that object;</li>
3232cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing the body of a {@code synchronized} statement that
3242cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * synchronizes on the object;</li>
3252cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <li>by executing a synchronized static method if the object is of type
3262cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@code Class}.</li>
3272cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * </ul>
3282cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
3292cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalMonitorStateException
3302cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if the thread calling this method is not the owner of this
3312cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             object's monitor.
3322cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notify
3332cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait()
3342cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long)
3352cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long,int)
3362cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see java.lang.Thread
3372cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
3382cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final native void notifyAll();
3392cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
3402cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
3412cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Returns a string containing a concise, human-readable description of this
3422cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * object. Subclasses are encouraged to override this method and provide an
3432cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * implementation that takes into account the object's type and data. The
3442cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * default implementation is equivalent to the following expression:
3452cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <pre>
3462cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *   getClass().getName() + '@' + Integer.toHexString(hashCode())</pre>
3472cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * <p>See <a href="{@docRoot}reference/java/lang/Object.html#writing_toString">Writing a useful
3482cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@code toString} method</a>
3492cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * if you intend implementing your own {@code toString} method.
3502cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
3512cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @return a printable representation of this object.
3522cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
3532cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public String toString() {
3542cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        return getClass().getName() + '@' + Integer.toHexString(hashCode());
3552cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
3562cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
3572cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
3582cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Causes the calling thread to wait until another thread calls the {@code
3592cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * notify()} or {@code notifyAll()} method of this object. This method can
3602cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * only be invoked by a thread which owns this object's monitor; see
3612cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * {@link #notify()} on how a thread can become the owner of a monitor.
36223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
36323122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>A waiting thread can be sent {@code interrupt()} to cause it to
3642cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * prematurely stop waiting, so {@code wait} should be called in a loop to
3652cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * check that the condition that has been waited for has been met before
3662cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * continuing.
36723122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
36823122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>While the thread waits, it gives up ownership of this object's
36923122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * monitor. When it is notified (or interrupted), it re-acquires the monitor
37023122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * before it starts running.
3712cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
3722cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalMonitorStateException
3732cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if the thread calling this method is not the owner of this
3742cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             object's monitor.
37523122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * @throws InterruptedException if the current thread has been interrupted.
37623122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             The interrupted status of the current thread will be cleared before the exception
37723122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             is thrown.
3782cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notify
3792cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notifyAll
3802cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long)
3812cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long,int)
3822cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see java.lang.Thread
3832cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
3842cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final native void wait() throws InterruptedException;
3852cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
3862cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
3872cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Causes the calling thread to wait until another thread calls the {@code
3882cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * notify()} or {@code notifyAll()} method of this object or until the
3892cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * specified timeout expires. This method can only be invoked by a thread
3902cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * which owns this object's monitor; see {@link #notify()} on how a thread
3912cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * can become the owner of a monitor.
39223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
39323122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>A waiting thread can be sent {@code interrupt()} to cause it to
3942cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * prematurely stop waiting, so {@code wait} should be called in a loop to
3952cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * check that the condition that has been waited for has been met before
3962cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * continuing.
39723122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
39823122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>While the thread waits, it gives up ownership of this object's
39923122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * monitor. When it is notified (or interrupted), it re-acquires the monitor
40023122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * before it starts running.
40123122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
40223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>A timeout of zero means the calling thread should wait forever unless interrupted or
40323122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * notified.
4042cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
4052cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @param millis
4062cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *            the maximum time to wait in milliseconds.
4072cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalArgumentException
4082cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if {@code millis < 0}.
4092cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalMonitorStateException
4102cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if the thread calling this method is not the owner of this
4112cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             object's monitor.
41223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * @throws InterruptedException if the current thread has been interrupted.
41323122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             The interrupted status of the current thread will be cleared before the exception
41423122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             is thrown.
4152cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notify
4162cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notifyAll
4172cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait()
4182cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long,int)
4192cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see java.lang.Thread
4202cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
4212cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final void wait(long millis) throws InterruptedException {
4222cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom        wait(millis, 0);
4232cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    }
4242cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom
4252cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    /**
4262cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * Causes the calling thread to wait until another thread calls the {@code
4272cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * notify()} or {@code notifyAll()} method of this object or until the
4282cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * specified timeout expires. This method can only be invoked by a thread
4292cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * that owns this object's monitor; see {@link #notify()} on how a thread
4302cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * can become the owner of a monitor.
43123122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
43223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>A waiting thread can be sent {@code interrupt()} to cause it to
4332cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * prematurely stop waiting, so {@code wait} should be called in a loop to
4342cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * check that the condition that has been waited for has been met before
4352cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * continuing.
43623122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
43723122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>While the thread waits, it gives up ownership of this object's
43823122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * monitor. When it is notified (or interrupted), it re-acquires the monitor
43923122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * before it starts running.
44023122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *
44123122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * <p>A timeout of zero means the calling thread should wait forever unless interrupted or
44223122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * notified.
4432cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *
4442cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @param millis
4452cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *            the maximum time to wait in milliseconds.
4462cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @param nanos
4472cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *            the fraction of a millisecond to wait, specified in
4482cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *            nanoseconds.
4492cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalArgumentException
4502cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if {@code millis < 0}, {@code nanos < 0} or {@code nanos >
4512cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             999999}.
4522cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @throws IllegalMonitorStateException
4532cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             if the thread calling this method is not the owner of this
4542cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     *             object's monitor.
45523122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     * @throws InterruptedException if the current thread has been interrupted.
45623122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             The interrupted status of the current thread will be cleared before the exception
45723122dc6c511936935ceaccaed94adafdc9fddafNeil Fuller     *             is thrown.
4582cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notify
4592cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #notifyAll
4602cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait()
4612cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see #wait(long,int)
4622cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     * @see java.lang.Thread
4632cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom     */
4642cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom    public final native void wait(long millis, int nanos) throws InterruptedException;
4652cf03dc15c40b92634ff606694af5a6e9aa4db09Brian Carlstrom}
466