Skip to content

Commit fa98a28

Browse files
committed
Introduce core symbols for thread statuses
1 parent a9f0108 commit fa98a28

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/main/java/org/truffleruby/core/symbol/CoreSymbols.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public final class CoreSymbols {
4747
public final RubySymbol DECONSTRUCT = createRubySymbol("deconstruct");
4848
public final RubySymbol DECONSTRUCT_KEYS = createRubySymbol("deconstruct_keys");
4949

50+
public final RubySymbol RUN = createRubySymbol("run");
51+
public final RubySymbol SLEEP = createRubySymbol("sleep");
52+
public final RubySymbol ABORTING = createRubySymbol("aborting");
53+
public final RubySymbol DEAD = createRubySymbol("dead");
54+
5055
// Added to workaround liquid's no symbols leaked test (SecurityTest#test_does_not_permanently_add_filters_to_symbol_table)
5156
public final RubySymbol IMMEDIATE_SWEEP = createRubySymbol("immediate_sweep");
5257
public final RubySymbol IMMEDIATE_MARK = createRubySymbol("immediate_mark");

src/main/java/org/truffleruby/core/thread/ThreadNodes.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,19 +592,17 @@ public abstract static class ThreadSetStatusPrimitiveNode extends PrimitiveArray
592592
@Specialization
593593
Object threadSetStatus(RubyThread thread, RubySymbol status) {
594594
ThreadStatus current = thread.status;
595-
String newName = status.getString();
596595

597-
if (newName.equals("run")) {
596+
if (status == coreSymbols().RUN) {
598597
thread.status = ThreadStatus.RUN;
599-
} else if (newName.equals("sleep")) {
598+
} else if (status == coreSymbols().SLEEP) {
600599
thread.status = ThreadStatus.SLEEP;
601-
} else if (newName.equals("aborting")) {
600+
} else if (status == coreSymbols().ABORTING) {
602601
thread.status = ThreadStatus.ABORTING;
603-
} else if (newName.equals("dead")) {
602+
} else if (status == coreSymbols().DEAD) {
604603
thread.status = ThreadStatus.DEAD;
605604
} else {
606-
throw new RaiseException(getContext(),
607-
coreExceptions().argumentError("Unknown thread status: " + newName, this));
605+
throw CompilerDirectives.shouldNotReachHere("Unknown thread status: " + status);
608606
}
609607

610608
String currentName = StringUtils.toLowerCase(current.name());

tool/generate-core-symbols.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
public final RubySymbol DECONSTRUCT = createRubySymbol("deconstruct");
6767
public final RubySymbol DECONSTRUCT_KEYS = createRubySymbol("deconstruct_keys");
6868
69+
public final RubySymbol RUN = createRubySymbol("run");
70+
public final RubySymbol SLEEP = createRubySymbol("sleep");
71+
public final RubySymbol ABORTING = createRubySymbol("aborting");
72+
public final RubySymbol DEAD = createRubySymbol("dead");
73+
6974
// Added to workaround liquid's no symbols leaked test (SecurityTest#test_does_not_permanently_add_filters_to_symbol_table)
7075
public final RubySymbol IMMEDIATE_SWEEP = createRubySymbol("immediate_sweep");
7176
public final RubySymbol IMMEDIATE_MARK = createRubySymbol("immediate_mark");

0 commit comments

Comments
 (0)