1 /*
   2  * Copyright (c) 1994, 2018, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package java.lang;
  25 
  26 import jdk.internal.HotSpotIntrinsicCandidate;
  27 
  28 /**
  29  * Slightly modified version of java.lang.Object that replaces
  30  * finalize() by finalizeObject() to avoid overriding in subclasses.
  31  */
  32 public class Object {
  33 
  34     @HotSpotIntrinsicCandidate
  35     public Object() {}
  36 
  37     private static native void registerNatives();
  38     static {
  39         registerNatives();
  40     }
  41 
  42     @HotSpotIntrinsicCandidate
  43     public final native Class<?> getClass();
  44 
  45     @HotSpotIntrinsicCandidate
  46     public native int hashCode();
  47 
  48     public boolean equals(Object obj) {
  49         return (this == obj);
  50     }
  51 
  52     @HotSpotIntrinsicCandidate
  53     protected native Object clone() throws CloneNotSupportedException;
  54 
  55     public String toString() {
  56         return getClass().getName() + "@" + Integer.toHexString(hashCode());
  57     }
  58 
  59     @HotSpotIntrinsicCandidate
  60     public final native void notify();
  61 
  62     @HotSpotIntrinsicCandidate
  63     public final native void notifyAll();
  64 
  65     private final native void wait0(long timeout) throws InterruptedException;
  66 
  67     public final void wait(long timeout) throws InterruptedException {
  68         wait0(timeout);
  69     }
  70 
  71     public final void wait(long timeout, int nanos) throws InterruptedException {
  72         if (timeout < 0) {
  73             throw new IllegalArgumentException("timeout value is negative");
  74         }
  75 
  76         if (nanos < 0 || nanos > 999999) {
  77             throw new IllegalArgumentException(
  78                                 "nanosecond timeout value out of range");
  79         }
  80 
  81         if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
  82             timeout++;
  83         }
  84 
  85         wait0(timeout);
  86     }
  87 
  88     public final void wait() throws InterruptedException {
  89         wait0(0);
  90     }
  91 
  92     /**
  93      * Replaces original finalize() method and is therefore not
  94      * overridden by any subclasses of Object.
  95      * @throws Throwable
  96      */
  97     // protected void finalize() throws Throwable { }
  98     public void finalizeObject() throws Throwable { }
  99 }