< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2004, 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  */


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


 375 
 376     /**
 377      * Causes current thread to wait until another thread invokes the
 378      * {@link java.lang.Object#notify()} method or the
 379      * {@link java.lang.Object#notifyAll()} method for this object, or
 380      * some other thread interrupts the current thread, or a certain
 381      * amount of real time has elapsed.
 382      * <p>
 383      * This method is similar to the <code>wait</code> method of one
 384      * argument, but it allows finer control over the amount of time to
 385      * wait for a notification before giving up. The amount of real time,
 386      * measured in nanoseconds, is given by:
 387      * <blockquote>
 388      * <pre>
 389      * 1000000*timeout+nanos</pre></blockquote>
 390      * <p>
 391      * In all other respects, this method does the same thing as the
 392      * method {@link #wait(long)} of one argument. In particular,
 393      * <tt>wait(0, 0)</tt> means the same thing as <tt>wait(0)</tt>.
 394      * <p>


 437      */
 438     public final void wait(long timeout, int nanos) throws InterruptedException {
 439 
 440         bi04t002a.instrInvoke(bi04t002a.INSTR_WAIT_JI);
 441 
 442         if (timeout < 0) {
 443             throw new IllegalArgumentException("timeout value is negative");
 444         }
 445 
 446         if (nanos < 0 || nanos > 999999) {
 447             throw new IllegalArgumentException(
 448                                 "nanosecond timeout value out of range");
 449         }
 450 
 451             if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 452                 timeout++;
 453             }
 454 
 455             wait(timeout);
 456     }



 457 
 458     /**
 459      * Causes current thread to wait until another thread invokes the
 460      * {@link java.lang.Object#notify()} method or the
 461      * {@link java.lang.Object#notifyAll()} method for this object.
 462      * In other words, this method behaves exactly as if it simply
 463      * performs the call <tt>wait(0)</tt>.
 464      * <p>
 465      * The current thread must own this object's monitor. The thread
 466      * releases ownership of this monitor and waits until another thread
 467      * notifies threads waiting on this object's monitor to wake up
 468      * either through a call to the <code>notify</code> method or the
 469      * <code>notifyAll</code> method. The thread then waits until it can
 470      * re-obtain ownership of the monitor and resumes execution.
 471      * <p>
 472      * As in the one argument version, interrupts and spurious wakeups are
 473      * possible, and this method should always be used in a loop:
 474      * <pre>
 475      *     synchronized (obj) {
 476      *         while (&lt;condition does not hold&gt;)


   1 /*
   2  * Copyright (c) 2004, 2019, 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  */


 354      * locked while the thread waits.
 355      * <p>
 356      * This method should only be called by a thread that is the owner
 357      * of this object's monitor. See the <code>notify</code> method for a
 358      * description of the ways in which a thread can become the owner of
 359      * a monitor.
 360      *
 361      * @param      timeout   the maximum time to wait in milliseconds.
 362      * @exception  IllegalArgumentException      if the value of timeout is
 363      *               negative.
 364      * @exception  IllegalMonitorStateException  if the current thread is not
 365      *               the owner of the object's monitor.
 366      * @exception  InterruptedException if another thread interrupted the
 367      *             current thread before or while the current thread
 368      *             was waiting for a notification.  The <i>interrupted
 369      *             status</i> of the current thread is cleared when
 370      *             this exception is thrown.
 371      * @see        java.lang.Object#notify()
 372      * @see        java.lang.Object#notifyAll()
 373      */
 374     public final void wait(long timeoutMillis) throws InterruptedException {
 375         wait0(timeoutMillis);
 376     }
 377 
 378     /**
 379      * Causes current thread to wait until another thread invokes the
 380      * {@link java.lang.Object#notify()} method or the
 381      * {@link java.lang.Object#notifyAll()} method for this object, or
 382      * some other thread interrupts the current thread, or a certain
 383      * amount of real time has elapsed.
 384      * <p>
 385      * This method is similar to the <code>wait</code> method of one
 386      * argument, but it allows finer control over the amount of time to
 387      * wait for a notification before giving up. The amount of real time,
 388      * measured in nanoseconds, is given by:
 389      * <blockquote>
 390      * <pre>
 391      * 1000000*timeout+nanos</pre></blockquote>
 392      * <p>
 393      * In all other respects, this method does the same thing as the
 394      * method {@link #wait(long)} of one argument. In particular,
 395      * <tt>wait(0, 0)</tt> means the same thing as <tt>wait(0)</tt>.
 396      * <p>


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


< prev index next >