From 2d5e79de90d7e5daaec2f77b4e2d0b64c1e523eb Mon Sep 17 00:00:00 2001 From: jovsteva Date: Wed, 5 Jun 2024 14:07:40 +0200 Subject: [PATCH] JFR CPU profiler should respect the sampling period. --- ....java => PosixSubstrateGlobalSigprofHandler.java} | 10 ++++------ .../svm/core/posix/PosixSubstrateSigprofHandler.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) rename substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/{darwin/DarwinSubstrateSigprofHandler.java => PosixSubstrateGlobalSigprofHandler.java} (89%) diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstrateSigprofHandler.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateGlobalSigprofHandler.java similarity index 89% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstrateSigprofHandler.java rename to substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateGlobalSigprofHandler.java index 2398a7c78367..e39a05d005a6 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstrateSigprofHandler.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateGlobalSigprofHandler.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.core.posix.darwin; +package com.oracle.svm.core.posix; import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE; @@ -34,18 +34,16 @@ import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue; -import com.oracle.svm.core.posix.PosixSubstrateSigprofHandler; -import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.Time; import com.oracle.svm.core.util.TimeUtils; /** - * Darwin supports only global timer from POSIX (see {@link PosixSubstrateSigprofHandler}). + * Support for POSIX global timer (see {@link PosixSubstrateSigprofHandler}). */ -public final class DarwinSubstrateSigprofHandler extends PosixSubstrateSigprofHandler { +public final class PosixSubstrateGlobalSigprofHandler extends PosixSubstrateSigprofHandler { @Platforms(Platform.HOSTED_ONLY.class) - public DarwinSubstrateSigprofHandler() { + public PosixSubstrateGlobalSigprofHandler() { } @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateSigprofHandler.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateSigprofHandler.java index 3a90c84f5369..03c90de21811 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateSigprofHandler.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateSigprofHandler.java @@ -47,12 +47,12 @@ import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.heap.RestrictHeapAccess; +import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.JfrExecutionSamplerSupported; import com.oracle.svm.core.jfr.JfrFeature; import com.oracle.svm.core.jfr.sampler.JfrExecutionSampler; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.SubstrateOptionsParser; -import com.oracle.svm.core.posix.darwin.DarwinSubstrateSigprofHandler; import com.oracle.svm.core.posix.headers.Signal; import com.oracle.svm.core.posix.linux.LinuxSubstrateSigprofHandler; import com.oracle.svm.core.sampler.SubstrateSigprofHandler; @@ -152,10 +152,14 @@ public void afterRegistration(AfterRegistrationAccess access) { } private static SubstrateSigprofHandler makeNewSigprofHandler() { - if (Platform.includedIn(Platform.LINUX.class)) { + /* + * For JFR, we should employ a global timer instead of a per-thread timer to adhere to the + * sampling frequency specified in .jfc. + */ + if (Platform.includedIn(Platform.DARWIN.class) || HasJfrSupport.get()) { + return new PosixSubstrateGlobalSigprofHandler(); + } else if (Platform.includedIn(Platform.LINUX.class)) { return new LinuxSubstrateSigprofHandler(); - } else if (Platform.includedIn(Platform.DARWIN.class)) { - return new DarwinSubstrateSigprofHandler(); } else { throw VMError.shouldNotReachHere("The JFR-based sampler is not supported on this platform."); }