Skip to content

Commit 149f675

Browse files
committed
[GR-40738] Add JDK 19 to the CI, remove the deprecated --fiber-pool option and cleanups based on that
PullRequest: truffleruby/3473
2 parents a5ab456 + 7cf3aee commit 149f675

File tree

59 files changed

+202
-420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+202
-420
lines changed

ci.jsonnet

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ local part_definitions = {
238238
JAVA_HOME: common.jdks["labsjdk-ce-17"],
239239
},
240240
},
241+
242+
v19: with_path {
243+
downloads+: {
244+
JAVA_HOME: common.jdks["labsjdk-ce-19"],
245+
},
246+
},
241247
},
242248

243249
platform: {
@@ -537,10 +543,13 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
537543
# Order: platform, jdk, mx_env. Keep aligned for an easy visual comparison.
538544
"ruby-test-specs-linux-11": $.platform.linux + $.jdk.v11 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:20:00" },
539545
"ruby-test-specs-linux-17": $.platform.linux + $.jdk.v17 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:20:00" },
546+
"ruby-test-specs-linux-19": $.platform.linux + $.jdk.v19 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:20:00" },
540547
"ruby-test-specs-darwin-amd64-11": $.platform.darwin_amd64 + $.jdk.v11 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
541548
"ruby-test-specs-darwin-amd64-17": $.platform.darwin_amd64 + $.jdk.v17 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
549+
"ruby-test-specs-darwin-amd64-19": $.platform.darwin_amd64 + $.jdk.v19 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
542550
"ruby-test-specs-darwin-aarch64-11": $.platform.darwin_aarch64 + $.jdk.v11 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
543551
"ruby-test-specs-darwin-aarch64-17": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
552+
"ruby-test-specs-darwin-aarch64-19": $.platform.darwin_aarch64 + $.jdk.v19 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
544553
"ruby-test-fast-linux-aarch64": $.platform.linux_aarch64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "45:00" },
545554
"ruby-test-fast-linux": $.platform.linux + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + { timelimit: "45:00" }, # To catch missing slow tags
546555
"ruby-test-mri-linux": $.platform.linux + $.jdk.v11 + $.env.native + gate + $.run.test_mri + { timelimit: "01:20:00" },
@@ -559,15 +568,20 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
559568

560569
"ruby-test-compiler-graal-core-11": $.platform.linux + $.jdk.v11 + $.env.jvm_ce + gate + $.use.truffleruby + $.run.test_compiler,
561570
"ruby-test-compiler-graal-core-17": $.platform.linux + $.jdk.v17 + $.env.jvm_ce + gate + $.use.truffleruby + $.run.test_compiler,
571+
"ruby-test-compiler-graal-core-19": $.platform.linux + $.jdk.v19 + $.env.jvm_ce + gate + $.use.truffleruby + $.run.test_compiler,
562572
"ruby-test-compiler-graal-enterprise-11": $.platform.linux + $.jdk.v11 + $.env.jvm_ee + gate + $.use.truffleruby + $.run.test_compiler,
563573
"ruby-test-compiler-graal-enterprise-17": $.platform.linux + $.jdk.v17 + $.env.jvm_ee + gate + $.use.truffleruby + $.run.test_compiler,
574+
"ruby-test-compiler-graal-enterprise-19": $.platform.linux + $.jdk.v19 + $.env.jvm_ee + gate + $.use.truffleruby + $.run.test_compiler,
564575

565576
"ruby-test-svm-graal-core-linux-11": $.platform.linux + $.jdk.v11 + $.env.native + $.env.gdb_svm + gate + native_tests,
566577
"ruby-test-svm-graal-core-linux-17": $.platform.linux + $.jdk.v17 + $.env.native + $.env.gdb_svm + gate + native_tests,
578+
"ruby-test-svm-graal-core-linux-19": $.platform.linux + $.jdk.v19 + $.env.native + $.env.gdb_svm + gate + native_tests,
567579
"ruby-test-svm-graal-core-darwin-amd64-11": $.platform.darwin_amd64 + $.jdk.v11 + $.env.native + $.env.gdb_svm + gate + native_tests,
568580
"ruby-test-svm-graal-core-darwin-amd64-17": $.platform.darwin_amd64 + $.jdk.v17 + $.env.native + $.env.gdb_svm + gate + native_tests,
581+
"ruby-test-svm-graal-core-darwin-amd64-19": $.platform.darwin_amd64 + $.jdk.v19 + $.env.native + $.env.gdb_svm + gate + native_tests,
569582
"ruby-test-svm-graal-core-darwin-aarch64-11": $.platform.darwin_aarch64 + $.jdk.v11 + $.env.native + gate + native_tests,
570583
"ruby-test-svm-graal-core-darwin-aarch64-17": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.native + gate + native_tests,
584+
"ruby-test-svm-graal-core-darwin-aarch64-19": $.platform.darwin_aarch64 + $.jdk.v19 + $.env.native + gate + native_tests,
571585
"ruby-test-svm-graal-enterprise-linux": $.platform.linux + $.jdk.v11 + $.env.native_ee + $.env.gdb_svm + gate + native_tests,
572586
"ruby-test-svm-graal-enterprise-darwin-aarch64 ": $.platform.darwin_aarch64 + $.jdk.v11 + $.env.native_ee + gate + native_tests,
573587
},

src/launcher/java/org/truffleruby/launcher/CommandLineException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
***** END LICENSE BLOCK *****/
2828
package org.truffleruby.launcher;
2929

30+
@SuppressWarnings("serial")
3031
public class CommandLineException extends Exception {
3132

32-
private static final long serialVersionUID = -8585821821150293755L;
33-
3433
private final boolean usageError;
3534

3635
public CommandLineException(String message) {

src/main/.checkstyle_checks.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@
251251
<property name="format" value='@Cached.+AbstractTruffleString'/>
252252
<property name="message" value='Do not cache on AbstractTruffleString (which can be mutable), cache on TruffleString and use RubyStringLibrary#asTruffleStringUncached()'/>
253253
</module>
254+
<module name="RegexpSinglelineJava">
255+
<property name="format" value='serialVersionUID'/>
256+
<property name="message" value='Use @SuppressWarnings("serial") instead.'/>
257+
</module>
254258
<module name="IllegalType">
255259
<!-- Use PrintStream instead of PrintWriter, PrintWriter does not consistently flush, even when writing \n.-->
256260
<property name="illegalClassNames" value="TruffleObject,DynamicObject,PrintWriter"/>

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import java.io.IOException;
1414
import java.lang.ref.Cleaner;
1515
import java.util.Arrays;
16+
import java.util.Map;
1617
import java.util.Objects;
1718
import java.util.Optional;
19+
import java.util.concurrent.ConcurrentHashMap;
1820
import java.util.concurrent.atomic.AtomicLong;
1921
import java.util.logging.Level;
2022

@@ -50,7 +52,6 @@
5052
import org.truffleruby.core.exception.RubySyntaxError;
5153
import org.truffleruby.core.exception.RubySystemCallError;
5254
import org.truffleruby.core.exception.RubySystemExit;
53-
import org.truffleruby.core.fiber.FiberPoolThread;
5455
import org.truffleruby.core.fiber.RubyFiber;
5556
import org.truffleruby.core.hash.RubyHash;
5657
import org.graalvm.options.OptionValues;
@@ -185,16 +186,44 @@ public final class RubyLanguage extends TruffleLanguage<RubyContext> {
185186
* {@link TranslatorEnvironment#newFrameDescriptorBuilder(org.truffleruby.parser.ParentFrameDescriptor, boolean)}. */
186187
public static final FrameDescriptor EMPTY_FRAME_DESCRIPTOR = new FrameDescriptor(Nil.INSTANCE);
187188

188-
/** We need an extra indirection added to ContextThreadLocal due to multiple Fibers of different Ruby Threads
189-
* sharing the same Java Thread when using the fiber pool. */
190-
public static final class ThreadLocalState {
191-
public RubyThread rubyThread;
189+
private RubyThread getOrCreateForeignThread(RubyContext context, Thread thread) {
190+
RubyThread foreignThread = rubyThreadInitMap.remove(thread);
191+
if (foreignThread == null) {
192+
foreignThread = context.getThreadManager().createForeignThread();
193+
rubyThreadInitMap.put(thread, foreignThread);
194+
}
195+
return foreignThread;
192196
}
193197

194-
private final ContextThreadLocal<ThreadLocalState> threadLocalState = createContextThreadLocal(
195-
(context, thread) -> thread instanceof FiberPoolThread
196-
? ((FiberPoolThread) thread).threadLocalState
197-
: new ThreadLocalState());
198+
public final Map<Thread, RubyThread> rubyThreadInitMap = new ConcurrentHashMap<>();
199+
private final ContextThreadLocal<RubyThread> rubyThread = createContextThreadLocal(
200+
(context, thread) -> {
201+
if (thread == context.getThreadManager().getOrInitializeRootJavaThread()) {
202+
// Already initialized when creating the context
203+
return context.getThreadManager().getRootThread();
204+
}
205+
206+
if (context.getThreadManager().isRubyManagedThread(thread)) {
207+
return Objects.requireNonNull(rubyThreadInitMap.remove(thread));
208+
}
209+
210+
return getOrCreateForeignThread(context, thread);
211+
});
212+
213+
public final Map<Thread, RubyFiber> rubyFiberInitMap = new ConcurrentHashMap<>();
214+
private final ContextThreadLocal<RubyFiber> rubyFiber = createContextThreadLocal(
215+
(context, thread) -> {
216+
if (thread == context.getThreadManager().getOrInitializeRootJavaThread()) {
217+
// Already initialized when creating the context
218+
return context.getThreadManager().getRootThread().getRootFiber();
219+
}
220+
221+
if (context.getThreadManager().isRubyManagedThread(thread)) {
222+
return Objects.requireNonNull(rubyFiberInitMap.remove(thread));
223+
}
224+
225+
return getOrCreateForeignThread(context, thread).getRootFiber();
226+
});
198227

199228
private final CyclicAssumption tracingCyclicAssumption = new CyclicAssumption("object-space-tracing");
200229
@CompilationFinal private volatile Assumption tracingAssumption = tracingCyclicAssumption.getAssumption();
@@ -330,18 +359,11 @@ public RubyLanguage() {
330359
}
331360

332361
public RubyThread getCurrentThread() {
333-
final RubyThread rubyThread = threadLocalState.get().rubyThread;
334-
if (rubyThread == null) {
335-
CompilerDirectives.transferToInterpreterAndInvalidate();
336-
throw CompilerDirectives.shouldNotReachHere(
337-
"No Ruby Thread is associated with current Java Thread: " + Thread.currentThread());
338-
}
339-
return rubyThread;
362+
return rubyThread.get();
340363
}
341364

342-
public void setupCurrentThread(Thread javaThread, RubyThread rubyThread) {
343-
final ThreadLocalState threadLocalState = this.threadLocalState.get(javaThread);
344-
threadLocalState.rubyThread = rubyThread;
365+
public RubyFiber getCurrentFiber() {
366+
return rubyFiber.get();
345367
}
346368

347369
@TruffleBoundary
@@ -553,39 +575,34 @@ protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
553575

554576
@Override
555577
public void initializeThread(RubyContext context, Thread thread) {
556-
LOGGER.fine(() -> "initializeThread(#" + thread.getId() + " " + thread + ")");
578+
LOGGER.fine(() -> "initializeThread(#" + getThreadId(thread) + " " + thread + ")");
557579

558580
if (thread == context.getThreadManager().getOrInitializeRootJavaThread()) {
559581
// Already initialized when creating the context
560-
setupCurrentThread(thread, context.getThreadManager().getRootThread());
561582
return;
562583
}
563584

564585
if (context.getThreadManager().isRubyManagedThread(thread)) {
565-
final RubyThread rubyThread = context.getThreadManager().getCurrentThreadOrNull();
566-
if (rubyThread != null && rubyThread.thread == thread) { // new Ruby Thread
586+
final RubyThread rubyThread = getCurrentThread();
587+
if (rubyThread.thread == thread) { // new Ruby Thread
567588
if (thread != Thread.currentThread()) {
568589
throw CompilerDirectives
569590
.shouldNotReachHere("Ruby threads should be initialized on their Java thread");
570591
}
571592
context.getThreadManager().start(rubyThread, thread);
572-
setupCurrentThread(thread, rubyThread);
573593
} else {
574594
// Fiber
575595
}
576596
return;
577597
}
578598

579-
final RubyThread foreignThread = context.getThreadManager().createForeignThread();
599+
final RubyThread foreignThread = getCurrentThread();
580600
context.getThreadManager().startForeignThread(foreignThread, thread);
581-
setupCurrentThread(thread, foreignThread);
582601
}
583602

584603
@Override
585604
public void disposeThread(RubyContext context, Thread thread) {
586-
LOGGER.fine(
587-
() -> "disposeThread(#" + thread.getId() + " " + thread + " on " +
588-
context.getThreadManager().getCurrentThreadOrNull() + ")");
605+
LOGGER.fine(() -> "disposeThread(#" + getThreadId(thread) + " " + thread + " on " + getCurrentThread() + ")");
589606

590607
if (thread == context.getThreadManager().getRootJavaThread()) {
591608
if (context.getEnv().isPreInitialization()) {
@@ -604,8 +621,8 @@ public void disposeThread(RubyContext context, Thread thread) {
604621
}
605622

606623
if (context.getThreadManager().isRubyManagedThread(thread)) {
607-
final RubyThread rubyThread = context.getThreadManager().getCurrentThreadOrNull();
608-
if (rubyThread != null && rubyThread.thread == thread) { // Thread
624+
final RubyThread rubyThread = getCurrentThread();
625+
if (rubyThread.thread == thread) { // Thread
609626
if (thread != Thread.currentThread()) {
610627
throw CompilerDirectives.shouldNotReachHere("Ruby threads should be disposed on their Java thread");
611628
}
@@ -617,7 +634,7 @@ public void disposeThread(RubyContext context, Thread thread) {
617634
}
618635

619636
// A foreign Thread, its Fibers are considered isRubyManagedThread()
620-
final RubyThread rubyThread = context.getThreadManager().getRubyThreadForJavaThread(thread);
637+
final RubyThread rubyThread = this.rubyThread.get(thread);
621638
context.getThreadManager().cleanup(rubyThread, thread);
622639
}
623640

@@ -848,4 +865,9 @@ private static String buildCoreLoadPath(String coreLoadPath) {
848865
throw CompilerDirectives.shouldNotReachHere(e);
849866
}
850867
}
868+
869+
@SuppressWarnings("deprecation") // deprecated on JDK19 by Thread#threadId, but that's added in JDK19
870+
public static long getThreadId(Thread thread) {
871+
return thread.getId();
872+
}
851873
}

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ public abstract static class CallWithCExtLockAndFrameNode extends PrimitiveArray
171171
@Specialization
172172
protected Object callWithCExtLockAndFrame(
173173
VirtualFrame frame, Object receiver, RubyArray argsArray, Object specialVariables, Object block) {
174-
final ExtensionCallStack extensionStack = getLanguage()
175-
.getCurrentThread()
176-
.getCurrentFiber().extensionCallStack;
174+
final ExtensionCallStack extensionStack = getLanguage().getCurrentFiber().extensionCallStack;
177175
final boolean keywordsGiven = RubyArguments.getDescriptor(frame) instanceof KeywordArgumentsDescriptor;
178176
extensionStack.push(keywordsGiven, specialVariables, block);
179177
try {
@@ -195,9 +193,7 @@ protected Object callWithCExtLockAndFrame(
195193
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
196194
@Cached ConditionProfile ownedProfile,
197195
@Cached UnwrapNode unwrapNode) {
198-
final ExtensionCallStack extensionStack = getLanguage()
199-
.getCurrentThread()
200-
.getCurrentFiber().extensionCallStack;
196+
final ExtensionCallStack extensionStack = getLanguage().getCurrentFiber().extensionCallStack;
201197
final boolean keywordsGiven = RubyArguments.getDescriptor(frame) instanceof KeywordArgumentsDescriptor;
202198
extensionStack.push(keywordsGiven, specialVariables, block);
203199
try {
@@ -845,7 +841,7 @@ public abstract static class RbKeywordGivenNode extends CoreMethodArrayArguments
845841

846842
@Specialization
847843
protected boolean keywordGiven() {
848-
return getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.areKeywordsGiven();
844+
return getLanguage().getCurrentFiber().extensionCallStack.areKeywordsGiven();
849845
}
850846
}
851847

@@ -854,7 +850,7 @@ public abstract static class BlockProcNode extends CoreMethodArrayArgumentsNode
854850

855851
@Specialization
856852
protected Object block() {
857-
return getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.getBlock();
853+
return getLanguage().getCurrentFiber().extensionCallStack.getBlock();
858854
}
859855
}
860856

@@ -863,7 +859,7 @@ public abstract static class VarsFromStackNode extends PrimitiveArrayArgumentsNo
863859

864860
@Specialization
865861
protected Object variables() {
866-
return getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.getSpecialVariables();
862+
return getLanguage().getCurrentFiber().extensionCallStack.getSpecialVariables();
867863
}
868864
}
869865

@@ -1379,9 +1375,7 @@ public abstract static class StoreException extends YieldingCoreMethodNode {
13791375

13801376
@Specialization
13811377
protected Object storeException(CapturedException captured) {
1382-
final ExtensionCallStack extensionStack = getLanguage()
1383-
.getCurrentThread()
1384-
.getCurrentFiber().extensionCallStack;
1378+
final ExtensionCallStack extensionStack = getLanguage().getCurrentFiber().extensionCallStack;
13851379
extensionStack.setException(captured);
13861380
return nil;
13871381
}
@@ -1392,9 +1386,7 @@ public abstract static class RetrieveException extends YieldingCoreMethodNode {
13921386

13931387
@Specialization
13941388
protected Object retrieveException() {
1395-
final ExtensionCallStack extensionStack = getLanguage()
1396-
.getCurrentThread()
1397-
.getCurrentFiber().extensionCallStack;
1389+
final ExtensionCallStack extensionStack = getLanguage().getCurrentFiber().extensionCallStack;
13981390
return extensionStack.getException();
13991391
}
14001392
}

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ValueWrapperManager {
6464
private volatile HandleBlockWeakReference[] blockMap = new HandleBlockWeakReference[0];
6565

6666
public static HandleBlockHolder getBlockHolder(RubyContext context, RubyLanguage language) {
67-
return language.getCurrentThread().getCurrentFiber().handleData;
67+
return language.getCurrentFiber().handleData;
6868
}
6969

7070
/* We keep a map of long wrappers that have been generated because various C extensions assume that any given fixnum

src/main/java/org/truffleruby/core/DataObjectFinalizationService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ private void runFinalizer(DataObjectFinalizerReference ref) throws Error {
8181
if (!getContext().isFinalizing()) {
8282
Object data = ref.dataHolder.getPointer();
8383
if (!nullNode.isNull(data)) {
84-
final ExtensionCallStack stack = getLanguage().getCurrentThread()
85-
.getCurrentFiber().extensionCallStack;
84+
final ExtensionCallStack stack = getLanguage().getCurrentFiber().extensionCallStack;
8685
stack.push(false, stack.getSpecialVariables(), stack.getBlock());
8786
try {
8887
callNode.execute(ref.callable, data);

src/main/java/org/truffleruby/core/FinalizationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected void processReference(RubyContext context, RubyLanguage language,
9595

9696
protected void processReferenceInternal(RubyContext context, RubyLanguage language,
9797
FinalizerReference finalizerReference) {
98-
final ExtensionCallStack stack = language.getCurrentThread().getCurrentFiber().extensionCallStack;
98+
final ExtensionCallStack stack = language.getCurrentFiber().extensionCallStack;
9999
stack.push(stack.areKeywordsGiven(), stack.getSpecialVariables(), stack.getBlock());
100100
try {
101101
while (!context.isFinalizing()) {

0 commit comments

Comments
 (0)