Skip to content

Commit 25d8798

Browse files
committed
Rename VirtualThreads.get() to .singleton() for consistency.
1 parent 773115e commit 25d8798

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private <T> T walk(Function<? super Stream<StackFrame>, ? extends T> function) {
146146
JavaStackWalk walk = StackValue.get(JavaStackWalk.class);
147147
Pointer sp = KnownIntrinsics.readCallerStackPointer();
148148

149-
if (LoomSupport.isEnabled() && (this.contScope != null || VirtualThreads.get().isVirtual(thread))) {
149+
if (LoomSupport.isEnabled() && (this.contScope != null || VirtualThreads.singleton().isVirtual(thread))) {
150150
// has a delimitation scope
151151
Target_java_lang_ContinuationScope delimitationScope = this.contScope != null ? this.contScope : Target_java_lang_VirtualThread.continuationScope();
152152
Target_java_lang_Continuation topContinuation = Target_java_lang_Continuation.getCurrentContinuation(delimitationScope);

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ final class Target_java_util_concurrent_locks_LockSupport {
4545
@Substitute
4646
static void unpark(Thread thread) {
4747
if (thread != null) {
48-
if (VirtualThreads.get().isVirtual(thread)) {
49-
VirtualThreads.get().unpark(thread);
48+
if (VirtualThreads.singleton().isVirtual(thread)) {
49+
VirtualThreads.singleton().unpark(thread);
5050
} else {
5151
U.unpark(thread);
5252
}
@@ -58,8 +58,8 @@ static void park(Object blocker) {
5858
Thread t = Thread.currentThread();
5959
setBlocker(t, blocker);
6060
try {
61-
if (VirtualThreads.get().isVirtual(t)) {
62-
VirtualThreads.get().park();
61+
if (VirtualThreads.singleton().isVirtual(t)) {
62+
VirtualThreads.singleton().park();
6363
} else {
6464
U.park(false, 0L);
6565
}
@@ -74,8 +74,8 @@ static void parkNanos(Object blocker, long nanos) {
7474
Thread t = Thread.currentThread();
7575
setBlocker(t, blocker);
7676
try {
77-
if (VirtualThreads.get().isVirtual(t)) {
78-
VirtualThreads.get().parkNanos(nanos);
77+
if (VirtualThreads.singleton().isVirtual(t)) {
78+
VirtualThreads.singleton().parkNanos(nanos);
7979
} else {
8080
U.park(false, nanos);
8181
}
@@ -90,8 +90,8 @@ static void parkUntil(Object blocker, long deadline) {
9090
Thread t = Thread.currentThread();
9191
setBlocker(t, blocker);
9292
try {
93-
if (VirtualThreads.get().isVirtual(t)) {
94-
VirtualThreads.get().parkUntil(deadline);
93+
if (VirtualThreads.singleton().isVirtual(t)) {
94+
VirtualThreads.singleton().parkUntil(deadline);
9595
} else {
9696
U.park(true, deadline);
9797
}
@@ -102,8 +102,8 @@ static void parkUntil(Object blocker, long deadline) {
102102

103103
@Substitute
104104
static void park() {
105-
if (VirtualThreads.get().isVirtual(Thread.currentThread())) {
106-
VirtualThreads.get().park();
105+
if (VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
106+
VirtualThreads.singleton().park();
107107
} else {
108108
U.park(false, 0L);
109109
}
@@ -112,8 +112,8 @@ static void park() {
112112
@Substitute
113113
public static void parkNanos(long nanos) {
114114
if (nanos > 0) {
115-
if (VirtualThreads.get().isVirtual(Thread.currentThread())) {
116-
VirtualThreads.get().parkNanos(nanos);
115+
if (VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
116+
VirtualThreads.singleton().parkNanos(nanos);
117117
((SubstrateVirtualThread) Thread.currentThread()).parkNanos(nanos);
118118
} else {
119119
U.park(false, nanos);
@@ -123,8 +123,8 @@ public static void parkNanos(long nanos) {
123123

124124
@Substitute
125125
public static void parkUntil(long deadline) {
126-
if (VirtualThreads.get().isVirtual(Thread.currentThread())) {
127-
VirtualThreads.get().parkUntil(deadline);
126+
if (VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
127+
VirtualThreads.singleton().parkUntil(deadline);
128128
} else {
129129
U.park(true, deadline);
130130
}
@@ -147,12 +147,12 @@ static int get(Target_sun_nio_ch_NativeThreadSet that) {
147147

148148
static void set(Target_sun_nio_ch_NativeThreadSet that, int value) {
149149
// Note that the accessing method holds a lock that prevents concurrent updates
150-
if (VirtualThreads.get().isVirtual(Thread.currentThread())) {
150+
if (VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
151151
int diff = value - that.injectedUsed;
152152
if (diff == 1) {
153-
VirtualThreads.get().pinCurrent();
153+
VirtualThreads.singleton().pinCurrent();
154154
} else if (diff == -1) {
155-
VirtualThreads.get().unpinCurrent();
155+
VirtualThreads.singleton().unpinCurrent();
156156
} else {
157157
assert value == 0 : "must only be incremented or decremented by 1 (or initialized to 0)";
158158
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
public final class Continuations {
3030
public static ThreadFactory virtualThreadFactory() {
31-
return VirtualThreads.get().createFactory();
31+
return VirtualThreads.singleton().createFactory();
3232
}
3333

3434
private Continuations() {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static boolean getInterruptedFlag(Thread thread) {
123123

124124
static boolean getAndClearInterrupt(Thread thread) {
125125
if (supportsVirtual() && isVirtual(thread)) {
126-
return VirtualThreads.get().getAndClearInterrupt(thread);
126+
return VirtualThreads.singleton().getAndClearInterrupt(thread);
127127
}
128128
return getAndClearInterruptedFlag(thread);
129129
}
@@ -162,7 +162,7 @@ static boolean supportsVirtual() {
162162
}
163163

164164
static boolean isVirtual(Thread thread) {
165-
return supportsVirtual() && VirtualThreads.get().isVirtual(thread);
165+
return supportsVirtual() && VirtualThreads.singleton().isVirtual(thread);
166166
}
167167

168168
private static boolean isVirtualDisallowLoom(Thread thread) {
@@ -183,15 +183,15 @@ static void join(Thread thread, long millis) throws InterruptedException {
183183
throw new IllegalArgumentException("timeout value is negative");
184184
}
185185
if (supportsVirtual() && isVirtual(thread)) {
186-
VirtualThreads.get().join(thread, millis);
186+
VirtualThreads.singleton().join(thread, millis);
187187
} else {
188188
PlatformThreads.join(thread, millis);
189189
}
190190
}
191191

192192
static void yieldCurrent() {
193193
if (supportsVirtual() && isVirtualDisallowLoom(Thread.currentThread())) {
194-
VirtualThreads.get().yield();
194+
VirtualThreads.singleton().yield();
195195
} else {
196196
PlatformThreads.singleton().yieldCurrent();
197197
}
@@ -281,7 +281,7 @@ static void initializeNewThread(
281281
}
282282
LoomSupport.CompatibilityUtil.initThreadFields(tjlt, group, target, stackSize, priority, daemon, ThreadStatus.NEW);
283283

284-
if (!LoomSupport.isEnabled() && !(VirtualThreads.isSupported() && VirtualThreads.get().isVirtual(fromTarget(tjlt)))) {
284+
if (!LoomSupport.isEnabled() && !(VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(fromTarget(tjlt)))) {
285285
JavaThreads.toTarget(group).addUnstarted();
286286
}
287287

@@ -295,15 +295,15 @@ static void initializeNewThread(
295295

296296
static void sleep(long millis) throws InterruptedException {
297297
if (supportsVirtual() && isVirtualDisallowLoom(Thread.currentThread())) {
298-
VirtualThreads.get().sleepMillis(millis);
298+
VirtualThreads.singleton().sleepMillis(millis);
299299
} else {
300300
PlatformThreads.sleep(millis);
301301
}
302302
}
303303

304304
static boolean isAlive(Thread thread) {
305305
if (supportsVirtual() && isVirtualDisallowLoom(thread)) {
306-
return VirtualThreads.get().isAlive(thread);
306+
return VirtualThreads.singleton().isAlive(thread);
307307
}
308308
return PlatformThreads.isAlive(thread);
309309
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ private static boolean holdsLock(Object obj) {
518518

519519
@Substitute
520520
private StackTraceElement[] getStackTrace() {
521-
if (LoomSupport.isEnabled() && VirtualThreads.get().isVirtual(JavaThreads.fromTarget(this))) {
521+
if (LoomSupport.isEnabled() && VirtualThreads.singleton().isVirtual(JavaThreads.fromTarget(this))) {
522522
return asyncGetStackTrace();
523523
}
524524
return JavaThreads.getStackTrace(JavaThreads.fromTarget(this));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void unpark(Object threadObj) {
7474
throw new IllegalArgumentException("Unsafe.unpark(!(thread instanceof Thread))");
7575
}
7676
Thread thread = (Thread) threadObj;
77-
if (!VirtualThreads.isSupported() || !VirtualThreads.get().isVirtual(thread)) {
77+
if (!VirtualThreads.isSupported() || !VirtualThreads.singleton().isVirtual(thread)) {
7878
PlatformThreads.unpark(thread);
7979
}
8080
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/** Operations on virtual threads. */
3333
public interface VirtualThreads {
3434
@Fold
35-
static VirtualThreads get() {
35+
static VirtualThreads singleton() {
3636
ContinuationsFeature.abortIfUnsupported();
3737
return ImageSingletons.lookup(VirtualThreads.class);
3838
}

substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/functions/JNIFunctions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,11 @@ static int MonitorEnter(JNIEnvironment env, JNIObjectHandle handle) {
10171017
throw new NullPointerException();
10181018
}
10191019
boolean pinned = false;
1020-
if (VirtualThreads.isSupported() && VirtualThreads.get().isVirtual(Thread.currentThread())) {
1020+
if (VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
10211021
// Acquiring monitors via JNI associates them with the carrier thread via
10221022
// JNIThreadOwnedMonitors, so we must pin the virtual thread
10231023
try {
1024-
VirtualThreads.get().pinCurrent();
1024+
VirtualThreads.singleton().pinCurrent();
10251025
} catch (IllegalStateException e) { // too many pins
10261026
throw new IllegalMonitorStateException();
10271027
}
@@ -1041,7 +1041,7 @@ static int MonitorEnter(JNIEnvironment env, JNIObjectHandle handle) {
10411041
MonitorSupport.singleton().monitorExit(obj);
10421042
}
10431043
if (pinned) {
1044-
VirtualThreads.get().unpinCurrent();
1044+
VirtualThreads.singleton().unpinCurrent();
10451045
}
10461046
} catch (Throwable u) {
10471047
throw VMError.shouldNotReachHere(u);
@@ -1065,9 +1065,9 @@ static int MonitorExit(JNIEnvironment env, JNIObjectHandle handle) {
10651065
}
10661066
MonitorSupport.singleton().monitorExit(obj);
10671067
JNIThreadOwnedMonitors.exited(obj);
1068-
if (VirtualThreads.isSupported() && VirtualThreads.get().isVirtual(Thread.currentThread())) {
1068+
if (VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(Thread.currentThread())) {
10691069
try {
1070-
VirtualThreads.get().unpinCurrent();
1070+
VirtualThreads.singleton().unpinCurrent();
10711071
} catch (IllegalStateException e) { // not pinned?
10721072
throw new IllegalMonitorStateException();
10731073
}

0 commit comments

Comments
 (0)