diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkWriter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkWriter.java index fd137a3dd33..1b063b855da 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkWriter.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkWriter.java @@ -422,13 +422,13 @@ private void changeEpoch() { */ @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private void processSamplerBuffers() { - SubstrateSigprofHandler.singleton().preventThreadsFromEnteringSigProfHandler(); + SubstrateSigprofHandler.preventThreadsFromEnteringSigProfHandler(); try { - SubstrateSigprofHandler.singleton().waitUntilAllThreadsExitedSignalHandler(); + SubstrateSigprofHandler.waitUntilAllThreadsExitedSignalHandler(); SamplerBuffersAccess.processActiveBuffers(); SamplerBuffersAccess.processFullBuffers(); } finally { - SubstrateSigprofHandler.singleton().allowThreadsInSigProfHandler(); + SubstrateSigprofHandler.allowThreadsInSigProfHandler(); } } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/sampler/SubstrateSigprofHandler.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/sampler/SubstrateSigprofHandler.java index 83f16e636c9..36762a4fc85 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/sampler/SubstrateSigprofHandler.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/sampler/SubstrateSigprofHandler.java @@ -214,22 +214,50 @@ public static SamplerStackWalkVisitor visitor() { } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - boolean isProfilingEnabled() { - return enabled; + public static void preventThreadsFromEnteringSigProfHandler() { + if (ImageSingletons.contains(SubstrateSigprofHandler.class)) { + singleton().preventThreadsFromEnteringSigProfHandler0(); + } + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + public static void allowThreadsInSigProfHandler() { + if (ImageSingletons.contains(SubstrateSigprofHandler.class)) { + singleton().allowThreadsInSigProfHandler0(); + } } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public void preventThreadsFromEnteringSigProfHandler() { + public static void waitUntilAllThreadsExitedSignalHandler() { + if (ImageSingletons.contains(SubstrateSigprofHandler.class)) { + singleton().waitUntilAllThreadsExitedSignalHandler0(); + } + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + private void preventThreadsFromEnteringSigProfHandler0() { int value = isSignalHandlerDisabledTemporarily.incrementAndGet(); assert value > 0; } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public void allowThreadsInSigProfHandler() { + private void allowThreadsInSigProfHandler0() { int value = isSignalHandlerDisabledTemporarily.decrementAndGet(); assert value >= 0; } + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + private void waitUntilAllThreadsExitedSignalHandler0() { + while (threadsInSignalHandler.get() > 0) { + VMThreads.singleton().yield(); + } + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + boolean isProfilingEnabled() { + return enabled; + } + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public SamplerBufferStack availableBuffers() { return availableBuffers; @@ -240,13 +268,6 @@ public SamplerBufferStack fullBuffers() { return fullBuffers; } - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public void waitUntilAllThreadsExitedSignalHandler() { - while (threadsInSignalHandler.get() > 0) { - VMThreads.singleton().yield(); - } - } - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) SubstrateThreadMXBean substrateThreadMXBean() { return threadMXBean;