Skip to content

Commit 06dc7b5

Browse files
Renamings and small cleanups.
1 parent 1d966f7 commit 06dc7b5

File tree

14 files changed

+34
-35
lines changed

14 files changed

+34
-35
lines changed

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Threading.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private Threading() {
6060
* Registers a {@link RecurringCallback callback handler} that is called by the current thread
6161
* approximately at the provided interval. This functionality is only supported if the native
6262
* binary is built with {@code -H:+SupportRecurringCallback}. Note that only carefully crafted,
63-
* uninterruptible code can be executed safely in a recurring callback. Executing any other code
64-
* can result in deadlocks or crashes.
63+
* uninterruptible code can execute safely in a recurring callback. Executing any other code
64+
* easily results in deadlocks, crashes, and difficult-to-debug anomalies.
6565
* <p>
6666
* Only one callback can be active per thread. Each thread can have its own callback with a
6767
* different interval (or none at all). No guarantees are made about the actual interval. For

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private static int runCore0() {
268268

269269
@Uninterruptible(reason = "The caller initialized the thread state, so the callees do not need to be uninterruptible.", calleeMustBe = false)
270270
private static void runShutdown() {
271-
RecurringCallbackSupport.suspendCallbackExecution("Recurring callbacks can't be executed during shutdown.");
271+
RecurringCallbackSupport.suspendCallbackTimer("Recurring callbacks can't be executed during shutdown.");
272272
runShutdown0();
273273
}
274274

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ private static int tearDownIsolate() {
666666
}
667667

668668
/* After threadExit(), only uninterruptible code may be executed. */
669-
RecurringCallbackSupport.suspendCallbackExecution("Execution of arbitrary code is prohibited during the last teardown steps.");
669+
RecurringCallbackSupport.suspendCallbackTimer("Execution of arbitrary code is prohibited during the last teardown steps.");
670670

671671
/* Shut down VM thread. */
672672
if (VMOperationControl.useDedicatedVMOperationThread()) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/DeoptTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static void deoptTest() {
118118
try {
119119
if (Heap.getHeap().isAllocationDisallowed() ||
120120
!CEntryPointSnippets.isIsolateInitialized() ||
121-
(RecurringCallbackSupport.isEnabled() && RecurringCallbackSupport.isCallbackExecutionSuspended()) ||
121+
(RecurringCallbackSupport.isEnabled() && RecurringCallbackSupport.isCallbackTimerSuspended()) ||
122122
VMOperation.isInProgress() ||
123123
SafepointBehavior.ignoresSafepoints() ||
124124
!PlatformThreads.isCurrentAssigned()) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/StackOverflowCheckImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private static void onYellowZoneMadeAvailable(int oldState, int newState) {
201201
* a recurring callback in the yellow zone is dangerous because a stack overflow in the
202202
* recurring callback would then lead to a fatal error.
203203
*/
204-
RecurringCallbackSupport.suspendCallbackExecution("Recurring callbacks are considered user code and must not run in yellow zone");
204+
RecurringCallbackSupport.suspendCallbackTimer("Recurring callbacks are considered user code and must not run in yellow zone");
205205

206206
stackBoundaryTL.set(stackBoundaryTL.get().subtract(Options.StackYellowZoneSize.getValue()));
207207
}
@@ -241,7 +241,7 @@ private static void onYellowZoneProtected(int oldState, int newState) {
241241
VMError.guarantee(newState < oldState && newState >= STATE_YELLOW_ENABLED, "StackOverflowCheckImpl.onYellowZoneProtected: Illegal state");
242242

243243
if (newState == STATE_YELLOW_ENABLED) {
244-
RecurringCallbackSupport.resumeCallbackExecutionAtNextSafepoint();
244+
RecurringCallbackSupport.resumeCallbackTimerAtNextSafepointCheck();
245245

246246
stackBoundaryTL.set(stackBoundaryTL.get().add(Options.StackYellowZoneSize.getValue()));
247247
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/ReferenceHandlerThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static boolean isReferenceHandlerThread(Thread other) {
7676

7777
@Override
7878
public void run() {
79-
RecurringCallbackSupport.suspendCallbackExecution("An exception in a recurring callback must not interrupt pending reference processing because it could result in a memory leak.");
79+
RecurringCallbackSupport.suspendCallbackTimer("An exception in a recurring callback must not interrupt pending reference processing because it could result in a memory leak.");
8080

8181
this.isolateThread = CurrentIsolate.getCurrentThread();
8282
try {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/dump/HeapDumpWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public HeapDumpWriter(HeapDumpMetadata metadata) {
421421

422422
public boolean dumpHeap(RawFileDescriptor fd) {
423423
assert VMOperation.isInProgressAtSafepoint();
424-
assert RecurringCallbackSupport.isCallbackExecutionNotSupportedOrSuspended();
424+
assert RecurringCallbackSupport.isCallbackUnsupportedOrTimerSuspended();
425425

426426
noAllocationVerifier.open();
427427
try {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkFileWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ private void changeEpoch() {
673673
@Uninterruptible(reason = "Prevent JFR recording.")
674674
private static void processSamplerBuffers() {
675675
assert VMOperation.isInProgressAtSafepoint();
676-
assert RecurringCallbackSupport.isCallbackExecutionNotSupportedOrSuspended();
676+
assert RecurringCallbackSupport.isCallbackUnsupportedOrTimerSuspended();
677677

678678
JfrExecutionSampler.singleton().disallowThreadsInSamplerCode();
679679
try {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/sampler/JfrRecurringCallbackExecutionSampler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.graalvm.nativeimage.hosted.Feature;
4141
import org.graalvm.word.Pointer;
4242

43+
import com.oracle.svm.core.BuildPhaseProvider;
4344
import com.oracle.svm.core.NeverInline;
4445
import com.oracle.svm.core.Uninterruptible;
4546
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
@@ -53,6 +54,7 @@
5354
import com.oracle.svm.core.thread.VMOperation;
5455
import com.oracle.svm.core.thread.VMThreads;
5556
import com.oracle.svm.core.util.TimeUtils;
57+
import com.oracle.svm.core.util.VMError;
5658

5759
import jdk.graal.compiler.api.replacements.Fold;
5860

@@ -65,6 +67,7 @@ public final class JfrRecurringCallbackExecutionSampler extends AbstractJfrExecu
6567

6668
@Fold
6769
public static boolean isPresent() {
70+
VMError.guarantee(BuildPhaseProvider.isSetupFinished(), "JfrRecurringCallbackExecutionSampler.isPresent() must not be called too early");
6871
if (ImageSingletons.contains(JfrExecutionSampler.class)) {
6972
JfrExecutionSampler sampler = ImageSingletons.lookup(JfrExecutionSampler.class);
7073
return sampler instanceof JfrRecurringCallbackExecutionSampler;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/RecurringCallbackSupport.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.graalvm.nativeimage.Threading.RecurringCallback;
3535
import org.graalvm.nativeimage.Threading.RecurringCallbackAccess;
3636

37-
import com.oracle.svm.core.BuildPhaseProvider;
3837
import com.oracle.svm.core.Uninterruptible;
3938
import com.oracle.svm.core.heap.RestrictHeapAccess;
4039
import com.oracle.svm.core.jdk.UninterruptibleUtils;
@@ -60,14 +59,12 @@
6059
* VM. Even allocating Java objects can already be enough to cause problems.
6160
*/
6261
public class RecurringCallbackSupport {
63-
public static class Options {
64-
@Option(help = "Test whether a thread's recurring callback is pending on each transition from native code to Java.") //
65-
public static final HostedOptionKey<Boolean> CheckRecurringCallbackOnNativeToJavaTransition = new HostedOptionKey<>(false);
66-
}
67-
6862
public static class ConcealedOptions {
6963
@Option(help = "Support a per-thread timer that is called at a specific interval.") //
7064
public static final HostedOptionKey<Boolean> SupportRecurringCallback = new HostedOptionKey<>(false);
65+
66+
@Option(help = "Test whether a thread's recurring callback is pending on each transition from native code to Java.") //
67+
static final HostedOptionKey<Boolean> CheckRecurringCallbackOnNativeToJavaTransition = new HostedOptionKey<>(false);
7168
}
7269

7370
/**
@@ -80,7 +77,6 @@ public static class ConcealedOptions {
8077

8178
@Fold
8279
public static boolean isEnabled() {
83-
VMError.guarantee(BuildPhaseProvider.isSetupFinished(), "JfrRecurringCallbackExecutionSampler.isPresent() must not be called too early");
8480
return ConcealedOptions.SupportRecurringCallback.getValue() || JfrRecurringCallbackExecutionSampler.isPresent();
8581
}
8682

@@ -158,7 +154,7 @@ static boolean isCallbackInstalled(IsolateThread thread) {
158154
}
159155

160156
static boolean needsNativeToJavaSlowpath() {
161-
return isEnabled() && Options.CheckRecurringCallbackOnNativeToJavaTransition.getValue() && timerTL.get() != null && !isCallbackExecutionSuspended();
157+
return isEnabled() && ConcealedOptions.CheckRecurringCallbackOnNativeToJavaTransition.getValue() && timerTL.get() != null && !isCallbackTimerSuspended();
162158
}
163159

164160
/**
@@ -167,7 +163,7 @@ static boolean needsNativeToJavaSlowpath() {
167163
* temporarily because we can't deal with arbitrary code execution or thrown exceptions.
168164
*/
169165
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
170-
public static void suspendCallbackExecution(@SuppressWarnings("unused") String reason) {
166+
public static void suspendCallbackTimer(@SuppressWarnings("unused") String reason) {
171167
if (!isEnabled()) {
172168
return;
173169
}
@@ -184,13 +180,13 @@ public static void suspendCallbackExecution(@SuppressWarnings("unused") String r
184180
* might be triggered at the next safepoint check.
185181
*/
186182
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
187-
public static void resumeCallbackExecutionAtNextSafepoint() {
183+
public static void resumeCallbackTimerAtNextSafepointCheck() {
188184
if (!isEnabled()) {
189185
return;
190186
}
191187

192188
decrementSuspended();
193-
if (!isCallbackExecutionSuspended()) {
189+
if (!isCallbackTimerSuspended()) {
194190
RecurringCallbackTimer timer = timerTL.get();
195191
if (timer != null) {
196192
timer.updateStatistics();
@@ -200,22 +196,22 @@ public static void resumeCallbackExecutionAtNextSafepoint() {
200196
}
201197

202198
/**
203-
* Like {@link #resumeCallbackExecutionAtNextSafepoint()} but with the difference that this
199+
* Like {@link #resumeCallbackTimerAtNextSafepointCheck()} but with the difference that this
204200
* method may trigger the execution of the recurring callback right away.
205201
*/
206-
public static void resumeCallbackExecution() {
202+
public static void resumeCallbackTimer() {
207203
if (!isEnabled()) {
208204
return;
209205
}
210206

211207
decrementSuspended();
212-
if (!isCallbackExecutionSuspended()) {
213-
resumeCallbackExecution0();
208+
if (!isCallbackTimerSuspended()) {
209+
resumeCallbackTimer0();
214210
}
215211
}
216212

217213
@Uninterruptible(reason = "Prevent unexpected recurring callback execution (pending exception must not be destroyed).")
218-
private static void resumeCallbackExecution0() {
214+
private static void resumeCallbackTimer0() {
219215
try {
220216
maybeExecuteCallback();
221217
} catch (SafepointException e) {
@@ -225,12 +221,12 @@ private static void resumeCallbackExecution0() {
225221
}
226222

227223
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
228-
public static boolean isCallbackExecutionNotSupportedOrSuspended() {
229-
return !isEnabled() || isCallbackExecutionSuspended();
224+
public static boolean isCallbackUnsupportedOrTimerSuspended() {
225+
return !isEnabled() || isCallbackTimerSuspended();
230226
}
231227

232228
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
233-
public static boolean isCallbackExecutionSuspended() {
229+
public static boolean isCallbackTimerSuspended() {
234230
assert isEnabled();
235231
return suspendedTL.get() != 0;
236232
}
@@ -403,7 +399,7 @@ void setCounter(int value) {
403399

404400
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
405401
private boolean isCallbackDisabled() {
406-
return isExecuting || isCallbackExecutionSuspended();
402+
return isExecuting || isCallbackTimerSuspended();
407403
}
408404

409405
/**

0 commit comments

Comments
 (0)