< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/newclass02/java.base/java/lang/Object.java

Print this page

  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.misc.Blocker;
 27 import nsk.jvmti.scenarios.bcinstr.BI04.bi04t002a;
 28 
 29 /**
 30  * Class <code>Object</code> is the root of the class hierarchy.
 31  * Every class has <code>Object</code> as a superclass. All objects,
 32  * including arrays, implement the methods of this class.
 33  *
 34  * @author  unascribed
 35  * @version 1.67, 02/03/04
 36  * @see     java.lang.Class
 37  * @since   JDK1.0
 38  */
 39 public class Object {
 40 
 41     /**
 42      * Returns the runtime class of an object. That <tt>Class</tt>
 43      * object is the object that is locked by <tt>static synchronized</tt>
 44      * methods of the represented class.
 45      *
 46      * @return The <code>java.lang.Class</code> object that represents

351      * <p>
352      * This method should only be called by a thread that is the owner
353      * of this object's monitor. See the <code>notify</code> method for a
354      * description of the ways in which a thread can become the owner of
355      * a monitor.
356      *
357      * @param      timeout   the maximum time to wait in milliseconds.
358      * @exception  IllegalArgumentException      if the value of timeout is
359      *               negative.
360      * @exception  IllegalMonitorStateException  if the current thread is not
361      *               the owner of the object's monitor.
362      * @exception  InterruptedException if another thread interrupted the
363      *             current thread before or while the current thread
364      *             was waiting for a notification.  The <i>interrupted
365      *             status</i> of the current thread is cleared when
366      *             this exception is thrown.
367      * @see        java.lang.Object#notify()
368      * @see        java.lang.Object#notifyAll()
369      */
370     public final void wait(long timeoutMillis) throws InterruptedException {
371         if (!Thread.currentThread().isVirtual()) {
372             wait0(timeoutMillis);
373             return;
374         }
375 
376         // virtual thread waiting
377         boolean attempted = Blocker.begin();
378         try {










379             wait0(timeoutMillis);
380         } catch (InterruptedException e) {
381             // virtual thread's interrupt status needs to be cleared
382             Thread.currentThread().getAndClearInterrupt();
383             throw e;
384         } finally {
385             Blocker.end(attempted);
386         }
387     }
388 
389     /**
390      * Causes current thread to wait until another thread invokes the
391      * {@link java.lang.Object#notify()} method or the
392      * {@link java.lang.Object#notifyAll()} method for this object, or
393      * some other thread interrupts the current thread, or a certain
394      * amount of real time has elapsed.
395      * <p>
396      * This method is similar to the <code>wait</code> method of one
397      * argument, but it allows finer control over the amount of time to
398      * wait for a notification before giving up. The amount of real time,
399      * measured in nanoseconds, is given by:
400      * <blockquote>
401      * <pre>
402      * 1000000*timeout+nanos</pre></blockquote>
403      * <p>
404      * In all other respects, this method does the same thing as the
405      * method {@link #wait(long)} of one argument. In particular,

444      *               the owner of this object's monitor.
445      * @exception  InterruptedException if another thread interrupted the
446      *             current thread before or while the current thread
447      *             was waiting for a notification.  The <i>interrupted
448      *             status</i> of the current thread is cleared when
449      *             this exception is thrown.
450      */
451     public final void wait(long timeout, int nanos) throws InterruptedException {
452 
453         bi04t002a.instrInvoke(bi04t002a.INSTR_WAIT_JI);
454 
455         if (timeout < 0) {
456             throw new IllegalArgumentException("timeout value is negative");
457         }
458 
459         if (nanos < 0 || nanos > 999999) {
460             throw new IllegalArgumentException(
461                                 "nanosecond timeout value out of range");
462         }
463 
464             if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
465                 timeout++;
466             }
467 
468             wait(timeout);
469     }
470 
471     // final modifier so method not in vtable
472     private final native void wait0(long timeoutMillis) throws InterruptedException;
473 
474     /**
475      * Causes current thread to wait until another thread invokes the
476      * {@link java.lang.Object#notify()} method or the
477      * {@link java.lang.Object#notifyAll()} method for this object.
478      * In other words, this method behaves exactly as if it simply
479      * performs the call <tt>wait(0)</tt>.
480      * <p>
481      * The current thread must own this object's monitor. The thread
482      * releases ownership of this monitor and waits until another thread
483      * notifies threads waiting on this object's monitor to wake up
484      * either through a call to the <code>notify</code> method or the
485      * <code>notifyAll</code> method. The thread then waits until it can
486      * re-obtain ownership of the monitor and resumes execution.
487      * <p>
488      * As in the one argument version, interrupts and spurious wakeups are

  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 nsk.jvmti.scenarios.bcinstr.BI04.bi04t002a;
 27 
 28 /**
 29  * Class <code>Object</code> is the root of the class hierarchy.
 30  * Every class has <code>Object</code> as a superclass. All objects,
 31  * including arrays, implement the methods of this class.
 32  *
 33  * @author  unascribed
 34  * @version 1.67, 02/03/04
 35  * @see     java.lang.Class
 36  * @since   JDK1.0
 37  */
 38 public class Object {
 39 
 40     /**
 41      * Returns the runtime class of an object. That <tt>Class</tt>
 42      * object is the object that is locked by <tt>static synchronized</tt>
 43      * methods of the represented class.
 44      *
 45      * @return The <code>java.lang.Class</code> object that represents

350      * <p>
351      * This method should only be called by a thread that is the owner
352      * of this object's monitor. See the <code>notify</code> method for a
353      * description of the ways in which a thread can become the owner of
354      * a monitor.
355      *
356      * @param      timeout   the maximum time to wait in milliseconds.
357      * @exception  IllegalArgumentException      if the value of timeout is
358      *               negative.
359      * @exception  IllegalMonitorStateException  if the current thread is not
360      *               the owner of the object's monitor.
361      * @exception  InterruptedException if another thread interrupted the
362      *             current thread before or while the current thread
363      *             was waiting for a notification.  The <i>interrupted
364      *             status</i> of the current thread is cleared when
365      *             this exception is thrown.
366      * @see        java.lang.Object#notify()
367      * @see        java.lang.Object#notifyAll()
368      */
369     public final void wait(long timeoutMillis) throws InterruptedException {
370         if (timeoutMillis < 0) {
371             throw new IllegalArgumentException("timeout value is negative");

372         }
373 
374         if (Thread.currentThread() instanceof VirtualThread vthread) {
375             try {
376                 wait0(timeoutMillis);
377             } catch (InterruptedException e) {
378                 // virtual thread's interrupt status needs to be cleared
379                 vthread.getAndClearInterrupt();
380                 throw e;
381             } finally {
382                 if (timeoutMillis > 0) {
383                     vthread.cancelWaitTimeout();
384                 }
385             }
386         } else {
387             wait0(timeoutMillis);






388         }
389     }
390 
391     /**
392      * Causes current thread to wait until another thread invokes the
393      * {@link java.lang.Object#notify()} method or the
394      * {@link java.lang.Object#notifyAll()} method for this object, or
395      * some other thread interrupts the current thread, or a certain
396      * amount of real time has elapsed.
397      * <p>
398      * This method is similar to the <code>wait</code> method of one
399      * argument, but it allows finer control over the amount of time to
400      * wait for a notification before giving up. The amount of real time,
401      * measured in nanoseconds, is given by:
402      * <blockquote>
403      * <pre>
404      * 1000000*timeout+nanos</pre></blockquote>
405      * <p>
406      * In all other respects, this method does the same thing as the
407      * method {@link #wait(long)} of one argument. In particular,

446      *               the owner of this object's monitor.
447      * @exception  InterruptedException if another thread interrupted the
448      *             current thread before or while the current thread
449      *             was waiting for a notification.  The <i>interrupted
450      *             status</i> of the current thread is cleared when
451      *             this exception is thrown.
452      */
453     public final void wait(long timeout, int nanos) throws InterruptedException {
454 
455         bi04t002a.instrInvoke(bi04t002a.INSTR_WAIT_JI);
456 
457         if (timeout < 0) {
458             throw new IllegalArgumentException("timeout value is negative");
459         }
460 
461         if (nanos < 0 || nanos > 999999) {
462             throw new IllegalArgumentException(
463                                 "nanosecond timeout value out of range");
464         }
465 
466         if (nanos > 0 && timeout < Long.MAX_VALUE) {
467             timeout++;
468         }
469 
470         wait(timeout);
471     }
472 
473     // final modifier so method not in vtable
474     private final native void wait0(long timeoutMillis) throws InterruptedException;
475 
476     /**
477      * Causes current thread to wait until another thread invokes the
478      * {@link java.lang.Object#notify()} method or the
479      * {@link java.lang.Object#notifyAll()} method for this object.
480      * In other words, this method behaves exactly as if it simply
481      * performs the call <tt>wait(0)</tt>.
482      * <p>
483      * The current thread must own this object's monitor. The thread
484      * releases ownership of this monitor and waits until another thread
485      * notifies threads waiting on this object's monitor to wake up
486      * either through a call to the <code>notify</code> method or the
487      * <code>notifyAll</code> method. The thread then waits until it can
488      * re-obtain ownership of the monitor and resumes execution.
489      * <p>
490      * As in the one argument version, interrupts and spurious wakeups are
< prev index next >