From d866fa4c1f3f216f2d4ddab4d2841cf730e07b6f Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Thu, 27 Jun 2024 12:58:19 -0400 Subject: [PATCH 1/2] remove duplicate thread sleep events and use a constant clock for JFR chunks --- .../src/com/oracle/svm/core/jfr/JfrTicks.java | 3 ++- .../svm/core/thread/PlatformThreads.java | 18 ++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTicks.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTicks.java index 0c012bfb21e6..f1d13c66e87d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTicks.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTicks.java @@ -26,6 +26,7 @@ import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.util.TimeUtils; +import com.oracle.svm.core.util.PlatformTimeUtils; /** * Utility class to manage ticks for event timestamps based on an initial start point when the @@ -72,6 +73,6 @@ public static long millisToTicks(long millis) { } public static long currentTimeNanos() { - return TimeUtils.millisToNanos(System.currentTimeMillis()); + return PlatformTimeUtils.singleton().nanosNow(); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index 02b739935554..af15dc896ac9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -89,7 +89,6 @@ import com.oracle.svm.core.heap.VMOperationInfos; import com.oracle.svm.core.jdk.StackTraceUtils; import com.oracle.svm.core.jdk.UninterruptibleUtils; -import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.locks.VMMutex; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.memory.NativeMemory; @@ -110,7 +109,6 @@ import jdk.graal.compiler.api.replacements.Fold; import jdk.graal.compiler.core.common.SuppressFBWarnings; -import jdk.internal.event.ThreadSleepEvent; import jdk.internal.misc.Unsafe; /** @@ -983,23 +981,11 @@ static void unpark(Thread thread) { } /** - * Sleeps for the given number of nanoseconds, dealing with JFR events, wakups and - * interruptions. + * Sleeps for the given number of nanoseconds, wake-ups and interruptions. */ static void sleep(long nanos) throws InterruptedException { assert !isCurrentThreadVirtual(); - if (HasJfrSupport.get() && ThreadSleepEvent.isTurnedOn()) { - ThreadSleepEvent event = new ThreadSleepEvent(); - try { - event.time = nanos; - event.begin(); - sleep0(nanos); - } finally { - event.commit(); - } - } else { - sleep0(nanos); - } + sleep0(nanos); } /** Sleep for the given number of nanoseconds, dealing with early wakeups and interruptions. */ From 2caaa38f924760e55668094aa5968192457f0db8 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Thu, 11 Jul 2024 10:47:21 +0200 Subject: [PATCH 2/2] Cleanups. --- .../com/oracle/svm/core/thread/PlatformThreads.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index af15dc896ac9..e8930ec79a07 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -981,25 +981,20 @@ static void unpark(Thread thread) { } /** - * Sleeps for the given number of nanoseconds, wake-ups and interruptions. + * Sleeps for the given number of nanoseconds, dealing with early wake-ups and interruptions. */ static void sleep(long nanos) throws InterruptedException { assert !isCurrentThreadVirtual(); - sleep0(nanos); - } - - /** Sleep for the given number of nanoseconds, dealing with early wakeups and interruptions. */ - static void sleep0(long nanos) throws InterruptedException { if (nanos < 0) { throw new IllegalArgumentException("Timeout value is negative"); } - sleep1(nanos); + sleep0(nanos); if (Thread.interrupted()) { // clears the interrupted flag as required of Thread.sleep() throw new InterruptedException(); } } - private static void sleep1(long durationNanos) { + private static void sleep0(long durationNanos) { VMOperationControl.guaranteeOkayToBlock("[PlatformThreads.sleep(long): Should not sleep when it is not okay to block.]"); Thread thread = currentThread.get(); Parker sleepEvent = getCurrentThreadData().ensureSleepParker();