Skip to content

Commit 773115e

Browse files
committed
Split class PlatformThreads off from JavaThreads.
1 parent 60ba3d9 commit 773115e

File tree

31 files changed

+1174
-1055
lines changed

31 files changed

+1174
-1055
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31-
import com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets;
3231
import org.graalvm.compiler.api.replacements.Fold;
3332
import org.graalvm.compiler.core.common.NumUtil;
3433
import org.graalvm.compiler.core.common.SuppressFBWarnings;
@@ -58,6 +57,7 @@
5857
import com.oracle.svm.core.genscavenge.ThreadLocalAllocation.Descriptor;
5958
import com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader;
6059
import com.oracle.svm.core.genscavenge.remset.RememberedSet;
60+
import com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets;
6161
import com.oracle.svm.core.heap.GC;
6262
import com.oracle.svm.core.heap.Heap;
6363
import com.oracle.svm.core.heap.NoAllocationVerifier;
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,25 @@
6868
import com.oracle.svm.core.posix.headers.linux.LinuxPthread;
6969
import com.oracle.svm.core.posix.pthread.PthreadConditionUtils;
7070
import com.oracle.svm.core.stack.StackOverflowCheck;
71-
import com.oracle.svm.core.thread.JavaThreads;
7271
import com.oracle.svm.core.thread.ParkEvent;
7372
import com.oracle.svm.core.thread.ParkEvent.ParkEventFactory;
73+
import com.oracle.svm.core.thread.PlatformThreads;
7474
import com.oracle.svm.core.util.UnsignedUtils;
7575
import com.oracle.svm.core.util.VMError;
7676

77-
public final class PosixJavaThreads extends JavaThreads {
77+
public final class PosixPlatformThreads extends PlatformThreads {
7878

7979
@SuppressFBWarnings(value = "BC", justification = "Cast for @TargetClass")
8080
private static Target_java_lang_Thread toTarget(Thread thread) {
8181
return Target_java_lang_Thread.class.cast(thread);
8282
}
8383

8484
@Platforms(HOSTED_ONLY.class)
85-
PosixJavaThreads() {
85+
PosixPlatformThreads() {
8686
}
8787

8888
@Override
89-
protected boolean startOSThread(Thread thread, long stackSize) {
89+
protected boolean doStartThread(Thread thread, long stackSize) {
9090
pthread_attr_t attributes = StackValue.get(pthread_attr_t.class);
9191
if (Pthread.pthread_attr_init(attributes) != 0) {
9292
return false;
@@ -112,7 +112,7 @@ protected boolean startOSThread(Thread thread, long stackSize) {
112112
ThreadStartData startData = prepareStart(thread, SizeOf.get(ThreadStartData.class));
113113

114114
Pthread.pthread_tPointer newThread = StackValue.get(Pthread.pthread_tPointer.class);
115-
if (Pthread.pthread_create(newThread, attributes, PosixJavaThreads.pthreadStartRoutine.getFunctionPointer(), startData) != 0) {
115+
if (Pthread.pthread_create(newThread, attributes, PosixPlatformThreads.pthreadStartRoutine.getFunctionPointer(), startData) != 0) {
116116
undoPrepareStartOnError(thread, startData);
117117
return false;
118118
}
@@ -168,17 +168,17 @@ protected void setNativeName(Thread thread, String name) {
168168
assert thread == Thread.currentThread() : "Darwin only allows setting the name of the current thread";
169169
DarwinPthread.pthread_setname_np(threadNameHolder.get());
170170
} else {
171-
VMError.unsupportedFeature("PosixJavaThreads.setNativeName on unknown OS");
171+
VMError.unsupportedFeature("PosixPlatformThreads.setNativeName on unknown OS");
172172
}
173173
}
174174
}
175175

176176
@Override
177-
protected void platformYield() {
177+
protected void yieldCurrent() {
178178
Sched.sched_yield();
179179
}
180180

181-
private static final CEntryPointLiteral<CFunctionPointer> pthreadStartRoutine = CEntryPointLiteral.create(PosixJavaThreads.class, "pthreadStartRoutine", ThreadStartData.class);
181+
private static final CEntryPointLiteral<CFunctionPointer> pthreadStartRoutine = CEntryPointLiteral.create(PosixPlatformThreads.class, "pthreadStartRoutine", ThreadStartData.class);
182182

183183
private static class PthreadStartRoutinePrologue implements CEntryPointOptions.Prologue {
184184
private static final CGlobalData<CCharPointer> errorMessage = CGlobalDataFactory.createCString("Failed to attach a newly launched thread.");
@@ -217,7 +217,9 @@ final class Target_java_lang_Thread {
217217
@Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
218218
boolean hasPthreadIdentifier;
219219

220-
/** Every thread started by {@link PosixJavaThreads#startOSThread} has an opaque pthread_t. */
220+
/**
221+
* Every thread started by {@link PosixPlatformThreads#doStartThread} has an opaque pthread_t.
222+
*/
221223
@Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
222224
Pthread.pthread_t pthreadIdentifier;
223225
}
@@ -334,7 +336,7 @@ public ParkEvent create() {
334336
class PosixThreadsFeature implements Feature {
335337
@Override
336338
public void afterRegistration(AfterRegistrationAccess access) {
337-
ImageSingletons.add(JavaThreads.class, new PosixJavaThreads());
339+
ImageSingletons.add(PlatformThreads.class, new PosixPlatformThreads());
338340
ImageSingletons.add(ParkEventFactory.class, new PosixParkEventFactory());
339341
}
340342
}

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/Target_jdk_internal_misc_Signal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import com.oracle.svm.core.annotate.TargetClass;
4141
import com.oracle.svm.core.jdk.Jvm;
4242
import com.oracle.svm.core.jdk.RuntimeSupport;
43-
import com.oracle.svm.core.thread.JavaThreads;
43+
import com.oracle.svm.core.thread.PlatformThreads;
4444
import com.oracle.svm.core.util.VMError;
4545
import com.oracle.svm.core.windows.headers.WinBase;
4646

@@ -76,7 +76,7 @@ class SignalDispatcher implements Runnable {
7676
/** A thread (in the image heap) to dispatch signals as they are raised. */
7777
private static final Thread signalDispatcherThread;
7878
static {
79-
signalDispatcherThread = new Thread(JavaThreads.singleton().systemGroup,
79+
signalDispatcherThread = new Thread(PlatformThreads.singleton().systemGroup,
8080
new SignalDispatcher(), "Signal Dispatcher");
8181
signalDispatcherThread.setPriority(NEAR_MAX_PRIORITY);
8282
signalDispatcherThread.setDaemon(true);
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@
5353
import com.oracle.svm.core.c.function.CEntryPointSetup.LeaveDetachThreadEpilogue;
5454
import com.oracle.svm.core.log.Log;
5555
import com.oracle.svm.core.stack.StackOverflowCheck;
56-
import com.oracle.svm.core.thread.JavaThreads;
5756
import com.oracle.svm.core.thread.ParkEvent;
5857
import com.oracle.svm.core.thread.ParkEvent.ParkEventFactory;
58+
import com.oracle.svm.core.thread.PlatformThreads;
5959
import com.oracle.svm.core.util.TimeUtils;
6060
import com.oracle.svm.core.util.VMError;
6161
import com.oracle.svm.core.windows.headers.Process;
6262
import com.oracle.svm.core.windows.headers.SynchAPI;
6363
import com.oracle.svm.core.windows.headers.WinBase;
6464

6565
@Platforms(Platform.WINDOWS.class)
66-
public final class WindowsJavaThreads extends JavaThreads {
66+
public final class WindowsPlatformThreads extends PlatformThreads {
6767
@Platforms(HOSTED_ONLY.class)
68-
WindowsJavaThreads() {
68+
WindowsPlatformThreads() {
6969
}
7070

7171
@Override
72-
protected boolean startOSThread(Thread thread, long stackSize) {
72+
protected boolean doStartThread(Thread thread, long stackSize) {
7373
int threadStackSize = (int) stackSize;
7474
int initFlag = Process.CREATE_SUSPENDED();
7575

@@ -82,7 +82,7 @@ protected boolean startOSThread(Thread thread, long stackSize) {
8282

8383
CIntPointer osThreadID = StackValue.get(CIntPointer.class);
8484
WinBase.HANDLE osThreadHandle = Process._beginthreadex(WordFactory.nullPointer(), threadStackSize,
85-
WindowsJavaThreads.osThreadStartRoutine.getFunctionPointer(), startData, initFlag, osThreadID);
85+
WindowsPlatformThreads.osThreadStartRoutine.getFunctionPointer(), startData, initFlag, osThreadID);
8686
if (osThreadHandle.isNull()) {
8787
undoPrepareStartOnError(thread, startData);
8888
return false;
@@ -103,7 +103,7 @@ protected void setNativeName(Thread thread, String name) {
103103
}
104104

105105
@Override
106-
protected void platformYield() {
106+
protected void yieldCurrent() {
107107
Process.SwitchToThread();
108108
}
109109

@@ -117,7 +117,7 @@ interface WindowsThreadStartData extends ThreadStartData {
117117
void setOSThreadHandle(WinBase.HANDLE osHandle);
118118
}
119119

120-
private static final CEntryPointLiteral<CFunctionPointer> osThreadStartRoutine = CEntryPointLiteral.create(WindowsJavaThreads.class, "osThreadStartRoutine", WindowsThreadStartData.class);
120+
private static final CEntryPointLiteral<CFunctionPointer> osThreadStartRoutine = CEntryPointLiteral.create(WindowsPlatformThreads.class, "osThreadStartRoutine", WindowsThreadStartData.class);
121121

122122
private static class OSThreadStartRoutinePrologue implements CEntryPointOptions.Prologue {
123123
private static final CGlobalData<CCharPointer> errorMessage = CGlobalDataFactory.createCString("Failed to attach a newly launched thread.");
@@ -243,7 +243,7 @@ public ParkEvent create() {
243243
class WindowsThreadsFeature implements Feature {
244244
@Override
245245
public void afterRegistration(AfterRegistrationAccess access) {
246-
ImageSingletons.add(JavaThreads.class, new WindowsJavaThreads());
246+
ImageSingletons.add(PlatformThreads.class, new WindowsPlatformThreads());
247247
ImageSingletons.add(ParkEventFactory.class, new WindowsParkEventFactory());
248248
}
249249
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.svm.core.jdk.RuntimeSupport;
6060
import com.oracle.svm.core.log.Log;
6161
import com.oracle.svm.core.thread.JavaThreads;
62+
import com.oracle.svm.core.thread.PlatformThreads;
6263
import com.oracle.svm.core.util.Counter;
6364

6465
import jdk.vm.ci.code.Architecture;
@@ -164,7 +165,7 @@ public static int runCore() {
164165
/*
165166
* Shutdown sequence: First wait for all non-daemon threads to exit.
166167
*/
167-
JavaThreads.singleton().joinAllNonDaemons();
168+
PlatformThreads.singleton().joinAllNonDaemons();
168169
/*
169170
* Run shutdown hooks (both our own hooks and application-registered hooks. Note that
170171
* this can start new non-daemon threads. We are not responsible to wait until they have

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
import com.oracle.svm.core.stack.ThreadStackPrinter.StackFramePrintVisitor;
7979
import com.oracle.svm.core.stack.ThreadStackPrinter.Stage0StackFramePrintVisitor;
8080
import com.oracle.svm.core.stack.ThreadStackPrinter.Stage1StackFramePrintVisitor;
81-
import com.oracle.svm.core.thread.JavaThreads;
81+
import com.oracle.svm.core.thread.PlatformThreads;
8282
import com.oracle.svm.core.thread.VMOperation;
8383
import com.oracle.svm.core.thread.VMOperationControl;
8484
import com.oracle.svm.core.thread.VMThreads;
@@ -658,7 +658,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
658658
log.string(" (").string(SafepointBehavior.toString(safepointBehavior)).string(")");
659659

660660
if (allowJavaHeapAccess) {
661-
Thread threadObj = JavaThreads.fromVMThread(thread);
661+
Thread threadObj = PlatformThreads.fromVMThread(thread);
662662
log.string(" \"").string(threadObj.getName()).string("\" - ").zhex(Word.objectToUntrackedPointer(threadObj));
663663
if (threadObj != null && threadObj.isDaemon()) {
664664
log.string(", daemon");

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
import com.oracle.svm.core.log.Log;
4747
import com.oracle.svm.core.stack.JavaStackWalker;
4848
import com.oracle.svm.core.stack.ThreadStackPrinter.StackFramePrintVisitor;
49-
import com.oracle.svm.core.thread.JavaThreads;
5049
import com.oracle.svm.core.thread.JavaVMOperation;
50+
import com.oracle.svm.core.thread.PlatformThreads;
5151
import com.oracle.svm.core.thread.VMThreads;
5252

5353
import sun.misc.Signal;
@@ -123,7 +123,7 @@ public void handle(Signal arg0) {
123123
}
124124

125125
private static void dumpStack(Log log, IsolateThread vmThread) {
126-
Thread javaThread = JavaThreads.fromVMThread(vmThread);
126+
Thread javaThread = PlatformThreads.fromVMThread(vmThread);
127127
if (javaThread != null) {
128128
log.character('"').string(javaThread.getName()).character('"');
129129
log.string(" #").signed(javaThread.getId());

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointActions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.graalvm.word.WordFactory;
3232

3333
import com.oracle.svm.core.annotate.Uninterruptible;
34-
import com.oracle.svm.core.thread.JavaThreads;
34+
import com.oracle.svm.core.thread.PlatformThreads;
3535

3636
/**
3737
* Advanced entry and leave actions for entry point methods annotated with {@link CEntryPoint}.
@@ -65,8 +65,8 @@ private CEntryPointActions() {
6565
* @param ensureJavaThread when set to true, the method ensures that the
6666
* {@link java.lang.Thread} object for the newly attached thread is created. If the
6767
* parameter is set to false, a later call to one of the
68-
* {@link JavaThreads#ensurePlatformThread} methods early after the prologue must be
69-
* used to do the initialization manually.
68+
* {@link PlatformThreads#ensureCurrentAssigned} methods early after the prologue
69+
* must be used to do the initialization manually.
7070
* @return 0 on success, otherwise non-zero.
7171
*/
7272
public static native int enterAttachThread(Isolate isolate, boolean ensureJavaThread);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor;
9898
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
9999
import com.oracle.svm.core.stack.StackOverflowCheck;
100-
import com.oracle.svm.core.thread.JavaThreads;
100+
import com.oracle.svm.core.thread.PlatformThreads;
101101
import com.oracle.svm.core.thread.Safepoint;
102102
import com.oracle.svm.core.thread.VMOperationControl;
103103
import com.oracle.svm.core.thread.VMThreads;
@@ -225,7 +225,7 @@ private static int createIsolate(CEntryPointCreateIsolateParameters parameters,
225225
return error;
226226
}
227227

228-
JavaThreads.singleton().initializeIsolate();
228+
PlatformThreads.singleton().initializeIsolate();
229229

230230
return CEntryPointErrors.NO_ERROR;
231231
}
@@ -407,7 +407,7 @@ private static int attachUnattachedThread(Isolate isolate, boolean inCrashHandle
407407

408408
@SubstrateForeignCallTarget(stubCallingConvention = false)
409409
private static void ensureJavaThread() {
410-
JavaThreads.ensurePlatformThread();
410+
PlatformThreads.ensureCurrentAssigned();
411411
}
412412

413413
@Snippet
@@ -445,7 +445,7 @@ public static int tearDownIsolateSnippet() {
445445
private static int tearDownIsolate() {
446446
try {
447447
RuntimeSupport.executeTearDownHooks();
448-
if (!JavaThreads.singleton().tearDown()) {
448+
if (!PlatformThreads.singleton().tearDown()) {
449449
return CEntryPointErrors.UNSPECIFIED;
450450
}
451451

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/DeoptTester.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
4949
import com.oracle.svm.core.stack.JavaStackWalker;
5050
import com.oracle.svm.core.stack.StackFrameVisitor;
51-
import com.oracle.svm.core.thread.JavaThreads;
51+
import com.oracle.svm.core.thread.PlatformThreads;
5252
import com.oracle.svm.core.thread.ThreadingSupportImpl;
5353
import com.oracle.svm.core.thread.VMOperation;
5454
import com.oracle.svm.core.thread.VMThreads.SafepointBehavior;
@@ -112,7 +112,7 @@ public static void deoptTest() {
112112
ThreadingSupportImpl.isRecurringCallbackPaused() ||
113113
VMOperation.isInProgress() ||
114114
SafepointBehavior.ignoresSafepoints() ||
115-
!JavaThreads.currentPlatformThreadInitialized()) {
115+
!PlatformThreads.isCurrentAssigned()) {
116116
return; // Thread or VM is not in a safe (or sane) state for deoptimization
117117
}
118118
Pointer startSp = KnownIntrinsics.readCallerStackPointer();

0 commit comments

Comments
 (0)