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 jdk.internal.misc.Blocker;
29 import jdk.internal.vm.annotation.IntrinsicCandidate;
30
31 /**
32 * Class {@code Object} is the root of the class hierarchy.
33 * Every class has {@code Object} as a superclass. All objects,
34 * including arrays, implement the methods of this class.
35 *
36 * @see java.lang.Class
37 * @since 1.0
38 */
39 public class Object {
40
41 /**
42 * Constructs a new object.
43 */
44 @IntrinsicCandidate
45 public Object() {}
46
47 /**
353 * by being <em>notified</em> or <em>interrupted</em>, or until a
354 * certain amount of real time has elapsed.
355 * <p>
356 * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
357 * had been called. See the specification of the {@link #wait(long, int)} method
358 * for details.
359 *
360 * @param timeoutMillis the maximum time to wait, in milliseconds
361 * @throws IllegalArgumentException if {@code timeoutMillis} is negative
362 * @throws IllegalMonitorStateException if the current thread is not
363 * the owner of the object's monitor
364 * @throws InterruptedException if any thread interrupted the current thread before or
365 * while the current thread was waiting. The <em>interrupted status</em> of the
366 * current thread is cleared when this exception is thrown.
367 * @see #notify()
368 * @see #notifyAll()
369 * @see #wait()
370 * @see #wait(long, int)
371 */
372 public final void wait(long timeoutMillis) throws InterruptedException {
373 long comp = Blocker.begin();
374 try {
375 wait0(timeoutMillis);
376 } catch (InterruptedException e) {
377 Thread thread = Thread.currentThread();
378 if (thread.isVirtual())
379 thread.getAndClearInterrupt();
380 throw e;
381 } finally {
382 Blocker.end(comp);
383 }
384 }
385
386 // final modifier so method not in vtable
387 private final native void wait0(long timeoutMillis) throws InterruptedException;
388
389 /**
390 * Causes the current thread to wait until it is awakened, typically
391 * by being <em>notified</em> or <em>interrupted</em>, or until a
392 * certain amount of real time has elapsed.
393 * <p>
394 * The current thread must own this object's monitor lock. See the
395 * {@link #notify notify} method for a description of the ways in which
396 * a thread can become the owner of a monitor lock.
397 * <p>
398 * This method causes the current thread (referred to here as <var>T</var>) to
399 * place itself in the wait set for this object and then to relinquish any
400 * and all synchronization claims on this object. Note that only the locks
401 * on this object are relinquished; any other objects on which the current
402 * thread may be synchronized remain locked while the thread waits.
|
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 jdk.internal.event.VirtualThreadPinnedEvent;
29 import jdk.internal.misc.Blocker;
30 import jdk.internal.vm.annotation.IntrinsicCandidate;
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 * @see java.lang.Class
38 * @since 1.0
39 */
40 public class Object {
41
42 /**
43 * Constructs a new object.
44 */
45 @IntrinsicCandidate
46 public Object() {}
47
48 /**
354 * by being <em>notified</em> or <em>interrupted</em>, or until a
355 * certain amount of real time has elapsed.
356 * <p>
357 * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
358 * had been called. See the specification of the {@link #wait(long, int)} method
359 * for details.
360 *
361 * @param timeoutMillis the maximum time to wait, in milliseconds
362 * @throws IllegalArgumentException if {@code timeoutMillis} is negative
363 * @throws IllegalMonitorStateException if the current thread is not
364 * the owner of the object's monitor
365 * @throws InterruptedException if any thread interrupted the current thread before or
366 * while the current thread was waiting. The <em>interrupted status</em> of the
367 * current thread is cleared when this exception is thrown.
368 * @see #notify()
369 * @see #notifyAll()
370 * @see #wait()
371 * @see #wait(long, int)
372 */
373 public final void wait(long timeoutMillis) throws InterruptedException {
374 if (!Thread.currentThread().isVirtual()) {
375 wait0(timeoutMillis);
376 return;
377 }
378
379 // virtual thread waiting
380 VirtualThreadPinnedEvent event;
381 try {
382 event = new VirtualThreadPinnedEvent();
383 event.begin();
384 } catch (OutOfMemoryError e) {
385 event = null;
386 }
387 long comp = Blocker.begin();
388 try {
389 wait0(timeoutMillis);
390 } catch (InterruptedException e) {
391 // virtual thread's interrupt status needs to be cleared
392 Thread.currentThread().getAndClearInterrupt();
393 throw e;
394 } finally {
395 Blocker.end(comp);
396 if (event != null) {
397 try {
398 event.commit();
399 } catch (OutOfMemoryError e) {
400 // ignore
401 }
402 }
403 }
404 }
405
406 // final modifier so method not in vtable
407 private final native void wait0(long timeoutMillis) throws InterruptedException;
408
409 /**
410 * Causes the current thread to wait until it is awakened, typically
411 * by being <em>notified</em> or <em>interrupted</em>, or until a
412 * certain amount of real time has elapsed.
413 * <p>
414 * The current thread must own this object's monitor lock. See the
415 * {@link #notify notify} method for a description of the ways in which
416 * a thread can become the owner of a monitor lock.
417 * <p>
418 * This method causes the current thread (referred to here as <var>T</var>) to
419 * place itself in the wait set for this object and then to relinquish any
420 * and all synchronization claims on this object. Note that only the locks
421 * on this object are relinquished; any other objects on which the current
422 * thread may be synchronized remain locked while the thread waits.
|