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,24 @@ 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-application threads running.
164
+ To prevent indefinite blocking, these threads must be cooperatively shut down within Java before invoking this call.
165
+ To fix this use the option '-R:TearDownWarningSeconds=<secs>' at image build time to detect the threads that are still running.
166
+ This will print the stack traces of all threads that have not been cooperatively terminated.
167
+ Those threads need to be terminated from Java before calling tear_down_isolate.
168
+ """ ;
169
+
161
170
@ 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." })
171
+ @ CEntryPoint (name = "tear_down_isolate" , documentation = {"""
172
+ Tears down the isolate of the passed (and still attached) isolate thread,
173
+ waiting for any attached threads to detach from it, then discards its objects,
174
+ threads, and any other state or context that is associated with it.
175
+ Returns 0 on success, or a non-zero value on failure.
176
+
177
+ """ ,
178
+ THREAD_TERMINATION_NOTE ,
179
+ })
167
180
@ CEntryPointOptions (prologue = NoPrologue .class , epilogue = NoEpilogue .class , nameTransformation = NameTransformation .class )
168
181
public static int tearDownIsolate (IsolateThread isolateThread ) {
169
182
int result = CEntryPointActions .enter (isolateThread );
@@ -174,17 +187,20 @@ public static int tearDownIsolate(IsolateThread isolateThread) {
174
187
}
175
188
176
189
@ 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." })
190
+ @ CEntryPoint (name = "detach_all_threads_and_tear_down_isolate" , documentation = {"""
191
+ In the isolate of the passed isolate thread, detach all those threads that were
192
+ externally started (not within Java, which includes the "main thread") and were
193
+ attached to the isolate afterwards. Afterwards, all threads that were started
194
+ within Java undergo a regular shutdown process, followed by the tear-down of the
195
+ entire isolate, which detaches the current thread and discards the objects,
196
+ threads, and any other state or context associated with the isolate.
197
+ None of the manually attached threads targeted by this function may be executing
198
+ Java code at the time when this function is called or at any point in the future
199
+ or this will cause entirely undefined (and likely fatal) behavior.
200
+ Returns 0 on success, or a non-zero value on (non-fatal) failure.
201
+ """ ,
202
+ THREAD_TERMINATION_NOTE ,
203
+ })
188
204
@ CEntryPointOptions (prologue = NoPrologue .class , epilogue = NoEpilogue .class , nameTransformation = NameTransformation .class )
189
205
public static int detachAllThreadsAndTearDownIsolate (IsolateThread isolateThread ) {
190
206
int result = CEntryPointActions .enter (isolateThread );
0 commit comments