3434import org .graalvm .nativeimage .Threading .RecurringCallback ;
3535import org .graalvm .nativeimage .Threading .RecurringCallbackAccess ;
3636
37- import com .oracle .svm .core .BuildPhaseProvider ;
3837import com .oracle .svm .core .Uninterruptible ;
3938import com .oracle .svm .core .heap .RestrictHeapAccess ;
4039import com .oracle .svm .core .jdk .UninterruptibleUtils ;
6059 * VM. Even allocating Java objects can already be enough to cause problems.
6160 */
6261public 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