26
26
27
27
import java .util .function .Function ;
28
28
29
- import jdk .graal .compiler .word .Word ;
30
29
import org .graalvm .nativeimage .CurrentIsolate ;
31
30
import org .graalvm .nativeimage .Isolate ;
32
31
import org .graalvm .nativeimage .IsolateThread ;
41
40
import com .oracle .svm .core .c .function .CEntryPointOptions .NoPrologue ;
42
41
import com .oracle .svm .core .thread .VMThreads ;
43
42
43
+ import jdk .graal .compiler .word .Word ;
44
+
44
45
@ CHeader (value = GraalIsolateHeader .class )
45
46
public final class CEntryPointNativeFunctions {
46
47
@@ -158,12 +159,25 @@ public static int detachThread(IsolateThread thread) {
158
159
return CEntryPointActions .leaveDetachThread ();
159
160
}
160
161
162
+ static final String THREAD_TERMINATION_NOTE = """
163
+ If this call blocks indefinitely, this means there are still Java threads running
164
+ which do not terminate after receiving the Thread.interrupt() event.
165
+ To prevent indefinite blocking, these threads should be cooperatively shut down
166
+ within Java before invoking this call.
167
+ To diagnose such issues, use the option '-R:TearDownWarningSeconds=<secs>' to detect
168
+ the threads that are still running.
169
+ This will print the stack traces of all threads that block tear-down.
170
+ """ ;
171
+
161
172
@ Uninterruptible (reason = UNINTERRUPTIBLE_REASON )
162
- @ CEntryPoint (name = "tear_down_isolate" , documentation = {
163
- "Tears down the isolate of the passed (and still attached) isolate thread," ,
164
- "waiting for any attached threads to detach from it, then discards its objects," ,
165
- "threads, and any other state or context that is associated with it." ,
166
- "Returns 0 on success, or a non-zero value on failure." })
173
+ @ CEntryPoint (name = "tear_down_isolate" , documentation = {"""
174
+ Tears down the isolate of the passed (and still attached) isolate thread,
175
+ waiting for any attached threads to detach from it, then discards its objects,
176
+ threads, and any other state or context that is associated with it.
177
+ Returns 0 on success, or a non-zero value on failure.
178
+ """ ,
179
+ THREAD_TERMINATION_NOTE ,
180
+ })
167
181
@ CEntryPointOptions (prologue = NoPrologue .class , epilogue = NoEpilogue .class , nameTransformation = NameTransformation .class )
168
182
public static int tearDownIsolate (IsolateThread isolateThread ) {
169
183
int result = CEntryPointActions .enter (isolateThread );
@@ -174,17 +188,20 @@ public static int tearDownIsolate(IsolateThread isolateThread) {
174
188
}
175
189
176
190
@ Uninterruptible (reason = UNINTERRUPTIBLE_REASON )
177
- @ CEntryPoint (name = "detach_all_threads_and_tear_down_isolate" , documentation = {
178
- "In the isolate of the passed isolate thread, detach all those threads that were" ,
179
- "externally started (not within Java, which includes the \" main thread\" ) and were" ,
180
- "attached to the isolate afterwards. Afterwards, all threads that were started" ,
181
- "within Java undergo a regular shutdown process, followed by the tear-down of the" ,
182
- "entire isolate, which detaches the current thread and discards the objects," ,
183
- "threads, and any other state or context associated with the isolate." ,
184
- "None of the manually attached threads targeted by this function may be executing" ,
185
- "Java code at the time when this function is called or at any point in the future" ,
186
- "or this will cause entirely undefined (and likely fatal) behavior." ,
187
- "Returns 0 on success, or a non-zero value on (non-fatal) failure." })
191
+ @ CEntryPoint (name = "detach_all_threads_and_tear_down_isolate" , documentation = {"""
192
+ In the isolate of the passed isolate thread, detach all those threads that were
193
+ externally started (not within Java, which includes the "main thread") and were
194
+ attached to the isolate afterwards. Afterwards, all threads that were started
195
+ within Java undergo a regular shutdown process, followed by the tear-down of the
196
+ entire isolate, which detaches the current thread and discards the objects,
197
+ threads, and any other state or context associated with the isolate.
198
+ None of the manually attached threads targeted by this function may be executing
199
+ Java code at the time when this function is called or at any point in the future
200
+ or this will cause entirely undefined (and likely fatal) behavior.
201
+ Returns 0 on success, or a non-zero value on (non-fatal) failure.
202
+ """ ,
203
+ THREAD_TERMINATION_NOTE ,
204
+ })
188
205
@ CEntryPointOptions (prologue = NoPrologue .class , epilogue = NoEpilogue .class , nameTransformation = NameTransformation .class )
189
206
public static int detachAllThreadsAndTearDownIsolate (IsolateThread isolateThread ) {
190
207
int result = CEntryPointActions .enter (isolateThread );
0 commit comments