82
82
import org .truffleruby .core .proc .ProcOperations ;
83
83
import org .truffleruby .core .proc .RubyProc ;
84
84
import org .truffleruby .core .string .RubyString ;
85
- import org .truffleruby .core .string .StringUtils ;
86
85
import org .truffleruby .core .support .RubyPRNGRandomizer ;
86
+ import org .truffleruby .core .symbol .CoreSymbols ;
87
87
import org .truffleruby .core .symbol .RubySymbol ;
88
88
import org .truffleruby .core .thread .ThreadManager .BlockingCallInterruptible ;
89
89
import org .truffleruby .interop .ForeignToRubyNode ;
@@ -580,18 +580,19 @@ Object status(RubyThread self) {
580
580
return false ;
581
581
}
582
582
}
583
- return createString (fromJavaStringNode , StringUtils .toLowerCase (status .name ()), Encodings .US_ASCII ); // CR_7BIT
583
+
584
+ RubySymbol nameSymbol = threadStatusToRubySymbol (status , coreSymbols ());
585
+ return nameSymbol .getString ();
584
586
}
585
587
586
588
}
587
589
588
590
@ Primitive (name = "thread_set_status" )
589
591
public abstract static class ThreadSetStatusPrimitiveNode extends PrimitiveArrayArgumentsNode {
590
592
591
- @ TruffleBoundary
592
593
@ Specialization
593
594
Object threadSetStatus (RubyThread thread , RubySymbol status ) {
594
- ThreadStatus current = thread .status ;
595
+ ThreadStatus previous = thread .status ;
595
596
596
597
if (status == coreSymbols ().RUN ) {
597
598
thread .status = ThreadStatus .RUN ;
@@ -602,11 +603,10 @@ Object threadSetStatus(RubyThread thread, RubySymbol status) {
602
603
} else if (status == coreSymbols ().DEAD ) {
603
604
thread .status = ThreadStatus .DEAD ;
604
605
} else {
605
- throw CompilerDirectives .shouldNotReachHere ("Unknown thread status: " + status );
606
+ throw CompilerDirectives .shouldNotReachHere (status . toString () );
606
607
}
607
608
608
- String currentName = StringUtils .toLowerCase (current .name ());
609
- return getLanguage ().getSymbol (currentName );
609
+ return threadStatusToRubySymbol (previous , coreSymbols ());
610
610
}
611
611
}
612
612
@@ -1081,4 +1081,23 @@ Object eachCallerLocation(VirtualFrame frame, Nil block) {
1081
1081
throw new RaiseException (getContext (), coreExceptions ().localJumpError ("no block given" , this ));
1082
1082
}
1083
1083
}
1084
+
1085
+ private static RubySymbol threadStatusToRubySymbol (ThreadStatus status , CoreSymbols coreSymbols ) {
1086
+ final RubySymbol symbol ;
1087
+
1088
+ if (status == ThreadStatus .RUN ) {
1089
+ symbol = coreSymbols .RUN ;
1090
+ } else if (status == ThreadStatus .SLEEP ) {
1091
+ symbol = coreSymbols .SLEEP ;
1092
+ } else if (status == ThreadStatus .ABORTING ) {
1093
+ symbol = coreSymbols .ABORTING ;
1094
+ } else if (status == ThreadStatus .DEAD ) {
1095
+ symbol = coreSymbols .DEAD ;
1096
+ } else {
1097
+ throw CompilerDirectives .shouldNotReachHere (status .toString ());
1098
+ }
1099
+
1100
+ return symbol ;
1101
+ }
1102
+
1084
1103
}
0 commit comments