Skip to content

Commit 4d43c67

Browse files
Mark compiler threads as crashed in both isolates.
1 parent a1ce776 commit 4d43c67

35 files changed

+175
-84
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ public interface pthread_key_tPointer extends PointerBase {
8383
pthread_key_t read();
8484
}
8585

86-
@CConstant
87-
public static native int PTHREAD_KEYS_MAX();
88-
8986
@CConstant
9087
public static native int PTHREAD_CREATE_JOINABLE();
9188

@@ -98,9 +95,6 @@ public interface pthread_key_tPointer extends PointerBase {
9895
@CFunction(value = "pthread_create", transition = Transition.NO_TRANSITION)
9996
public static native int pthread_create_no_transition(pthread_tPointer newthread, pthread_attr_t attr, WordBase start_routine, WordBase arg);
10097

101-
@CFunction
102-
public static native int pthread_join(pthread_t th, WordPointer thread_return);
103-
10498
@CFunction(value = "pthread_join", transition = Transition.NO_TRANSITION)
10599
public static native int pthread_join_no_transition(pthread_t th, WordPointer thread_return);
106100

@@ -188,9 +182,6 @@ public interface pthread_key_tPointer extends PointerBase {
188182
@CFunction(transition = Transition.NO_TRANSITION)
189183
public static native int pthread_condattr_destroy(pthread_condattr_t attr);
190184

191-
@CFunction
192-
public static native int pthread_kill(pthread_t thread, Signal.SignalEnum sig);
193-
194185
@CFunction(transition = Transition.NO_TRANSITION)
195186
public static native int pthread_key_create(pthread_key_tPointer key, PointerBase keyDestructor);
196187

@@ -203,4 +194,8 @@ public interface pthread_key_tPointer extends PointerBase {
203194
@CFunction(transition = Transition.NO_TRANSITION)
204195
public static native VoidPointer pthread_getspecific(pthread_key_t key);
205196

197+
public static class NoTransition {
198+
@CFunction(transition = Transition.NO_TRANSITION)
199+
public static native int pthread_exit(VoidPointer retval);
200+
}
206201
}

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/ClientHandle.java renamed to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/isolated/ClientHandle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
2626

2727
/**
2828
* A handle to an object of type T that exists in the {@linkplain ClientIsolateThread compilation
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
2626

2727
import org.graalvm.nativeimage.IsolateThread;
2828

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/CompilerHandle.java renamed to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/isolated/CompilerHandle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
2626

2727
/**
2828
* A handle to an object of type T that exists in the {@linkplain CompilerIsolateThread compilation
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
2626

2727
import org.graalvm.nativeimage.IsolateThread;
2828

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
2626

2727
import java.io.ByteArrayOutputStream;
2828
import java.io.PrintWriter;
@@ -37,8 +37,6 @@
3737
import com.oracle.svm.core.c.function.CEntryPointOptions;
3838
import com.oracle.svm.core.threadlocal.FastThreadLocalFactory;
3939
import com.oracle.svm.core.threadlocal.FastThreadLocalObject;
40-
import com.oracle.svm.hosted.code.CEntryPointCallStubMethod;
41-
import com.oracle.svm.hosted.code.CEntryPointJavaCallStubMethod;
4240

4341
import jdk.graal.compiler.core.common.GraalBailoutException;
4442

@@ -83,13 +81,13 @@ protected static void throwPendingException() {
8381
* entry point.
8482
* <p>
8583
* Note that the caller isolate cannot have called from uninterruptible code because
86-
* {@link CEntryPointJavaCallStubMethod} does thread state transitions that require a safepoint
84+
* {@code CEntryPointJavaCallStubMethod} does thread state transitions that require a safepoint
8785
* check, so this method calling it back to dispatch the exception in interruptible code is
8886
* considered acceptable.
8987
* <p>
9088
* Our (callee) entry point might intend to execute only uninterruptible code save for this
9189
* exception handler, but as of writing this, isolated compilation nowhere requires relying on
92-
* that and {@link CEntryPointCallStubMethod} also does state transitions and safepoint checks.
90+
* that and {@code CEntryPointCallStubMethod} also does state transitions and safepoint checks.
9391
* <p>
9492
* Also note that an exception's stack trace contains all its isolate's frames up until the last
9593
* entry frame, but not another isolate's frames in between. When an exception is propagated
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
26+
27+
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
2628

2729
import org.graalvm.nativeimage.IsolateThread;
2830
import org.graalvm.nativeimage.ObjectHandle;
@@ -102,6 +104,7 @@ public IsolatedCompileClient(CompilerIsolateThread compiler) {
102104
this.compiler = compiler;
103105
}
104106

107+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
105108
public CompilerIsolateThread getCompiler() {
106109
return compiler;
107110
}
@@ -113,7 +116,7 @@ protected IsolateThread getOtherIsolate() {
113116
}
114117

115118
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
116-
ThreadLocalHandles<ObjectHandle> getHandleSet() {
119+
public ThreadLocalHandles<ObjectHandle> getHandleSet() {
117120
return handles;
118121
}
119122

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.graal.isolated;
25+
package com.oracle.svm.core.graal.isolated;
26+
27+
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
2628

2729
import org.graalvm.nativeimage.IsolateThread;
2830
import org.graalvm.nativeimage.ObjectHandle;
@@ -116,6 +118,7 @@ public IsolatedCompileContext(ClientIsolateThread clientIsolate) {
116118
this.client = clientIsolate;
117119
}
118120

121+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
119122
public ClientIsolateThread getClient() {
120123
return client;
121124
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.graal.isolated;
26+
27+
import org.graalvm.nativeimage.ObjectHandle;
28+
29+
/**
30+
* An object handle for isolated compilation with added static type information.
31+
*
32+
* @param <T> The type of the object referenced by the handle.
33+
*/
34+
public interface IsolatedHandle<T> extends ObjectHandle {
35+
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
import org.graalvm.word.UnsignedWord;
4040

4141
import com.oracle.svm.core.NeverInline;
42+
import com.oracle.svm.core.SubstrateOptions;
4243
import com.oracle.svm.core.Uninterruptible;
4344
import com.oracle.svm.core.c.function.CEntryPointErrors;
4445
import com.oracle.svm.core.c.function.CFunctionOptions;
4546
import com.oracle.svm.core.config.ConfigurationValues;
4647
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4748
import com.oracle.svm.core.feature.InternalFeature;
49+
import com.oracle.svm.core.graal.isolated.IsolatedCompileClient;
50+
import com.oracle.svm.core.graal.isolated.IsolatedCompileContext;
4851
import com.oracle.svm.core.heap.Heap;
4952
import com.oracle.svm.core.heap.VMOperationInfos;
5053
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
@@ -1016,7 +1019,23 @@ public static void preventSafepoints() {
10161019
*/
10171020
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
10181021
public static void markThreadAsCrashed() {
1019-
// It would be nice if we could retire the TLAB here but that wouldn't work reliably.
1022+
if (SubstrateOptions.supportCompileInIsolates()) {
1023+
/*
1024+
* Threads that are used for isolated compilation may be attached to both the main
1025+
* and a compilation isolate. So, mark it as crashed in both isolates.
1026+
*/
1027+
IsolatedCompileContext compileContext = IsolatedCompileContext.get();
1028+
if (compileContext != null) {
1029+
safepointBehaviorTL.setVolatile(compileContext.getClient(), THREAD_CRASHED);
1030+
}
1031+
1032+
IsolatedCompileClient compileClient = IsolatedCompileClient.get();
1033+
if (compileClient != null) {
1034+
safepointBehaviorTL.setVolatile(compileClient.getCompiler(), THREAD_CRASHED);
1035+
}
1036+
}
1037+
1038+
/* It would be nice if we could retire the TLAB here but that wouldn't work reliably. */
10201039
safepointBehaviorTL.setVolatile(THREAD_CRASHED);
10211040
}
10221041

0 commit comments

Comments
 (0)