4545import com .oracle .svm .core .deopt .DeoptimizationSupport ;
4646import com .oracle .svm .core .deopt .DeoptimizedFrame ;
4747import com .oracle .svm .core .deopt .Deoptimizer ;
48- import com .oracle .svm .core .heap .RestrictHeapAccess ;
4948import com .oracle .svm .core .log .Log ;
5049import com .oracle .svm .core .snippets .SnippetRuntime .SubstrateForeignCallDescriptor ;
5150import com .oracle .svm .core .stack .JavaFrame ;
5251import com .oracle .svm .core .stack .JavaFrames ;
5352import com .oracle .svm .core .stack .JavaStackWalk ;
5453import com .oracle .svm .core .stack .JavaStackWalker ;
55- import com .oracle .svm .core .stack .StackOverflowCheck ;
5654import com .oracle .svm .core .thread .VMThreads ;
5755import com .oracle .svm .core .threadlocal .FastThreadLocalBytes ;
5856import com .oracle .svm .core .threadlocal .FastThreadLocalFactory ;
@@ -100,43 +98,25 @@ static boolean exceptionsAreFatal() {
10098
10199 /** Foreign call: {@link #UNWIND_EXCEPTION_WITHOUT_CALLEE_SAVED_REGISTERS}. */
102100 @ SubstrateForeignCallTarget (stubCallingConvention = true )
103- @ Uninterruptible (reason = "Must not execute recurring callbacks or a stack overflow check." , calleeMustBe = false )
104- @ RestrictHeapAccess (access = RestrictHeapAccess .Access .NO_ALLOCATION , reason = "Must not allocate when unwinding the stack." )
101+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions." )
105102 private static void unwindExceptionWithoutCalleeSavedRegisters (Throwable exception , Pointer callerSP ) {
106- /*
107- * Make the yellow zone available and pause recurring callbacks to avoid that unexpected
108- * exceptions are thrown. This is reverted before execution continues in the exception
109- * handler (see ExceptionStackFrameVisitor.visitFrame).
110- */
111- StackOverflowCheck .singleton ().makeYellowZoneAvailable ();
112-
113- unwindExceptionInterruptible (exception , callerSP , false , false );
103+ unwindException (exception , callerSP , false , false );
114104 }
115105
116106 /** Foreign call: {@link #UNWIND_EXCEPTION_WITH_CALLEE_SAVED_REGISTERS}. */
117107 @ SubstrateForeignCallTarget (stubCallingConvention = true )
118- @ Uninterruptible (reason = "Must not execute recurring callbacks or a stack overflow check." , calleeMustBe = false )
119- @ RestrictHeapAccess (access = RestrictHeapAccess .Access .NO_ALLOCATION , reason = "Must not allocate when unwinding the stack." )
108+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions." )
120109 private static void unwindExceptionWithCalleeSavedRegisters (Throwable exception , Pointer callerSP ) {
121- StackOverflowCheck .singleton ().makeYellowZoneAvailable ();
122-
123- unwindExceptionInterruptible (exception , callerSP , true , false );
110+ unwindException (exception , callerSP , true , false );
124111 }
125112
126- @ Uninterruptible (reason = "Must not execute recurring callbacks or a stack overflow check." , calleeMustBe = false )
127- @ RestrictHeapAccess (access = RestrictHeapAccess .Access .NO_ALLOCATION , reason = "Must not allocate when unwinding the stack." )
113+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions." )
128114 public static void unwindExceptionSkippingCaller (Throwable exception , Pointer callerSP ) {
129- StackOverflowCheck .singleton ().makeYellowZoneAvailable ();
130-
131- unwindExceptionInterruptible (exception , callerSP , true , true );
115+ unwindException (exception , callerSP , true , true );
132116 }
133117
134- /*
135- * The stack walking objects must be stateless (no instance fields), because multiple threads
136- * can use them simultaneously. All state must be in separate VMThreadLocals.
137- */
138- @ RestrictHeapAccess (access = RestrictHeapAccess .Access .NO_ALLOCATION , reason = "Must not allocate when unwinding the stack." )
139- private static void unwindExceptionInterruptible (Throwable exception , Pointer callerSP , boolean fromMethodWithCalleeSavedRegisters , boolean skipCaller ) {
118+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions." )
119+ private static void unwindException (Throwable exception , Pointer callerSP , boolean fromMethodWithCalleeSavedRegisters , boolean skipCaller ) {
140120 if (currentException .get () != null ) {
141121 reportRecursiveUnwind (exception );
142122 return ; /* Unreachable code. */
@@ -168,6 +148,7 @@ private static void unwindExceptionInterruptible(Throwable exception, Pointer ca
168148 * Exception unwinding cannot be called recursively. The most likely reason to end up here is an
169149 * exception being thrown while walking the stack to find an exception handler.
170150 */
151+ @ Uninterruptible (reason = "Does not need to be uninterruptible because it throws a fatal error." , calleeMustBe = false )
171152 private static void reportRecursiveUnwind (Throwable exception ) {
172153 Log .log ().string ("Fatal error: recursion in exception handling: " ).string (exception .getClass ().getName ());
173154 Log .log ().string (" thrown while unwinding " ).string (currentException .get ().getClass ().getName ()).newline ().newline ();
@@ -182,6 +163,7 @@ private static void reportRecursiveUnwind(Throwable exception) {
182163 * exception checks such as null pointer or array bounds checks. In such cases, exceptions are
183164 * treated as fatal errors.
184165 */
166+ @ Uninterruptible (reason = "Does not need to be uninterruptible because it throws a fatal error." , calleeMustBe = false )
185167 private static void reportFatalUnwind (Throwable exception ) {
186168 Log .log ().string ("Fatal error: exception unwind while thread is not in Java state: " );
187169 Log .log ().exception (exception ).newline ().newline ();
@@ -194,13 +176,15 @@ private static void reportFatalUnwind(Throwable exception) {
194176 * proper exception handling and reporting of "unhandled" user exceptions is at a higher level
195177 * using a normal Java catch-all exception handler.
196178 */
179+ @ Uninterruptible (reason = "Does not need to be uninterruptible because it throws a fatal error." , calleeMustBe = false )
197180 private static void reportUnhandledException (Throwable exception ) {
198181 Log .log ().string ("Fatal error: unhandled exception in isolate " ).hex (CurrentIsolate .getIsolate ()).string (": " );
199182 Log .log ().exception (exception ).newline ().newline ();
200183 VMError .shouldNotReachHere ("Unhandled exception" );
201184 }
202185
203186 /** Hook to allow a {@link Feature} to install custom exception unwind code. */
187+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions." )
204188 protected abstract void customUnwindException (Pointer callerSP );
205189
206190 /**
@@ -212,7 +196,7 @@ private static void reportUnhandledException(Throwable exception) {
212196 * @param skipCaller Whether the first (caller) frame should be skipped. If this is true, then
213197 * the value of fromMethodWithCalleeSavedRegisters will be ignored.
214198 */
215- @ Uninterruptible (reason = "Prevent deoptimization apart from the few places explicitly considered safe for deoptimization " )
199+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions. " )
216200 private static void defaultUnwindException (Pointer startSP , boolean fromMethodWithCalleeSavedRegisters , boolean skipCaller ) {
217201 IsolateThread thread = CurrentIsolate .getCurrentThread ();
218202 boolean hasCalleeSavedRegisters = fromMethodWithCalleeSavedRegisters ;
@@ -236,7 +220,7 @@ private static void defaultUnwindException(Pointer startSP, boolean fromMethodWi
236220 DeoptimizedFrame deoptFrame = Deoptimizer .checkEagerDeoptimized (frame );
237221 if (deoptFrame != null ) {
238222 /* Deoptimization entry points always have an exception handler. */
239- deoptTakeExceptionInterruptible ( deoptFrame );
223+ deoptFrame . takeException ( );
240224 jumpToHandler (sp , DeoptimizationSupport .getEagerDeoptStubPointer (), hasCalleeSavedRegisters );
241225 UnreachableNode .unreachable ();
242226 return ; /* Unreachable */
@@ -273,15 +257,13 @@ private static void defaultUnwindException(Pointer startSP, boolean fromMethodWi
273257 }
274258 }
275259
276- @ Uninterruptible (reason = "Prevent deoptimization while dispatching to exception handler " )
260+ @ Uninterruptible (reason = "Code that is fully uninterruptible may throw and catch exceptions. " )
277261 private static void jumpToHandler (Pointer sp , CodePointer handlerIP , boolean hasCalleeSavedRegisters ) {
278262 verifyTopFrameAnchor (sp );
279263
280264 Throwable exception = currentException .get ();
281265 currentException .set (null );
282266
283- StackOverflowCheck .singleton ().protectYellowZone ();
284-
285267 if (hasCalleeSavedRegisters ) {
286268 /*
287269 * The fromMethodWithCalleeSavedRegisters parameter of farReturn must be a compile-time
@@ -294,9 +276,4 @@ private static void jumpToHandler(Pointer sp, CodePointer handlerIP, boolean has
294276 }
295277 /* Unreachable code: the intrinsic performs a jump to the specified instruction pointer. */
296278 }
297-
298- @ Uninterruptible (reason = "Wrap call to interruptible code." , calleeMustBe = false )
299- private static void deoptTakeExceptionInterruptible (DeoptimizedFrame deoptFrame ) {
300- deoptFrame .takeException ();
301- }
302279}
0 commit comments