|
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,35 +580,34 @@ 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 createString(nameSymbol.tstring, nameSymbol.encoding); |
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 |
| - String newName = status.getString(); |
| 595 | + ThreadStatus previous = thread.status; |
596 | 596 |
|
597 |
| - if (newName.equals("run")) { |
| 597 | + if (status == coreSymbols().RUN) { |
598 | 598 | thread.status = ThreadStatus.RUN;
|
599 |
| - } else if (newName.equals("sleep")) { |
| 599 | + } else if (status == coreSymbols().SLEEP) { |
600 | 600 | thread.status = ThreadStatus.SLEEP;
|
601 |
| - } else if (newName.equals("aborting")) { |
| 601 | + } else if (status == coreSymbols().ABORTING) { |
602 | 602 | thread.status = ThreadStatus.ABORTING;
|
603 |
| - } else if (newName.equals("dead")) { |
| 603 | + } else if (status == coreSymbols().DEAD) { |
604 | 604 | thread.status = ThreadStatus.DEAD;
|
605 | 605 | } else {
|
606 |
| - throw new RaiseException(getContext(), |
607 |
| - coreExceptions().argumentError("Unknown thread status: " + newName, this)); |
| 606 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 607 | + throw CompilerDirectives.shouldNotReachHere("Unknown thread status: " + status.getString()); |
608 | 608 | }
|
609 | 609 |
|
610 |
| - String currentName = StringUtils.toLowerCase(current.name()); |
611 |
| - return getLanguage().getSymbol(currentName); |
| 610 | + return threadStatusToRubySymbol(previous, coreSymbols()); |
612 | 611 | }
|
613 | 612 | }
|
614 | 613 |
|
@@ -1083,4 +1082,24 @@ Object eachCallerLocation(VirtualFrame frame, Nil block) {
|
1083 | 1082 | throw new RaiseException(getContext(), coreExceptions().localJumpError("no block given", this));
|
1084 | 1083 | }
|
1085 | 1084 | }
|
| 1085 | + |
| 1086 | + private static RubySymbol threadStatusToRubySymbol(ThreadStatus status, CoreSymbols coreSymbols) { |
| 1087 | + final RubySymbol symbol; |
| 1088 | + |
| 1089 | + if (status == ThreadStatus.RUN) { |
| 1090 | + symbol = coreSymbols.RUN; |
| 1091 | + } else if (status == ThreadStatus.SLEEP) { |
| 1092 | + symbol = coreSymbols.SLEEP; |
| 1093 | + } else if (status == ThreadStatus.ABORTING) { |
| 1094 | + symbol = coreSymbols.ABORTING; |
| 1095 | + } else if (status == ThreadStatus.DEAD) { |
| 1096 | + symbol = coreSymbols.DEAD; |
| 1097 | + } else { |
| 1098 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 1099 | + throw CompilerDirectives.shouldNotReachHere("Unknown thread status: " + status); |
| 1100 | + } |
| 1101 | + |
| 1102 | + return symbol; |
| 1103 | + } |
| 1104 | + |
1086 | 1105 | }
|
0 commit comments