8299419: Thread.sleep(millis) may throw OOME

Reviewed-by: alanb
This commit is contained in:
Viktor Klang 2024-09-11 20:02:49 +00:00
parent 591aa7c5c7
commit b0cff6b528
5 changed files with 8 additions and 19 deletions

View File

@ -457,19 +457,20 @@ public class Thread implements Runnable {
* Called before sleeping to create a jdk.ThreadSleep event.
*/
private static ThreadSleepEvent beforeSleep(long nanos) {
ThreadSleepEvent event = null;
if (ThreadSleepEvent.isTurnedOn()) {
try {
event = new ThreadSleepEvent();
try {
ThreadSleepEvent event = new ThreadSleepEvent();
if (event.isEnabled()) {
event.time = nanos;
event.begin();
} catch (OutOfMemoryError e) {
event = null;
return event;
}
} catch (OutOfMemoryError e) {
// ignore
}
return event;
return null;
}
/**
* Called after sleeping to commit the jdk.ThreadSleep event.
*/

View File

@ -30,14 +30,5 @@ package jdk.internal.event;
*/
public final class ThreadSleepEvent extends Event {
private static final ThreadSleepEvent EVENT = new ThreadSleepEvent();
/**
* Returns {@code true} if event is enabled, {@code false} otherwise.
*/
public static boolean isTurnedOn() {
return EVENT.isEnabled();
}
public long time;
}

View File

@ -665,7 +665,6 @@ class SleepingThread extends BaseThread {
// jdk.internal.event.ThreadSleepEvent not accessible
expectedMethods.add("jdk.internal.event.ThreadSleepEvent.<clinit>");
expectedMethods.add("jdk.internal.event.ThreadSleepEvent.isEnabled");
expectedMethods.add("jdk.internal.event.ThreadSleepEvent.isTurnedOn");
expectedMethods.add(SleepingThread.class.getName() + ".run");
switch (controller.invocationType) {

View File

@ -42,7 +42,6 @@ public class SleepingThread extends RecursiveMonitoringThread {
"java.lang.Thread.afterSleep",
"java.util.concurrent.TimeUnit.toNanos",
"jdk.internal.event.ThreadSleepEvent.<clinit>",
"jdk.internal.event.ThreadSleepEvent.isTurnedOn",
"jdk.internal.event.ThreadSleepEvent.isEnabled",
"nsk.monitoring.share.thread.SleepingThread.runInside"
};

View File

@ -151,7 +151,6 @@ public class strace001 {
"java.util.concurrent.TimeUnit.toNanos",
"jdk.internal.event.ThreadSleepEvent.<clinit>",
"jdk.internal.event.ThreadSleepEvent.<init>",
"jdk.internal.event.ThreadSleepEvent.isTurnedOn",
"jdk.internal.event.ThreadSleepEvent.isEnabled"
};