Skip to content

Commit a5afb7a

Browse files
committed
[GR-18163] Fix the label of the first location reported by Thread#backtrace_locations (#2229)
PullRequest: truffleruby/2339
2 parents f01379b + 1d5e736 commit a5afb7a

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88

99
* `Range#to_a` wasn't working for `long` ranges (#2198, @tomstuart and @LillianZ).
1010
* Show the interleaved host and guest stacktrace for host exceptions (#2226).
11+
* Fix the label of the first location reported by `Thread#backtrace_locations` (#2229).
1112

1213
Compatibility:
1314

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private void rethrowOnMainThread(Node currentNode, RuntimeException e) {
332332
"rethrow " + e.getClass() + " to main thread",
333333
getRootThread(),
334334
currentNode,
335-
(rubyThread, actionCurrentNode) -> {
335+
(rubyThread, threadCurrentNode) -> {
336336
throw e;
337337
});
338338
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ protected Object backtraceLocations(RubyThread rubyThread, int first, int second
190190
private Object backtraceLocationsInternal(RubyThread rubyThread, int omit, int length) {
191191
final Memo<Object> backtraceLocationsMemo = new Memo<>(null);
192192

193-
final SafepointAction safepointAction = (thread1, currentNode) -> {
193+
final SafepointAction safepointAction = (thread, currentNode) -> {
194194
final Backtrace backtrace = getContext().getCallStack().getBacktrace(this, omit);
195-
backtraceLocationsMemo.set(backtrace.getBacktraceLocations(getContext(), getLanguage(), length, this));
195+
Object locations = backtrace.getBacktraceLocations(getContext(), getLanguage(), length, currentNode);
196+
backtraceLocationsMemo.set(locations);
196197
};
197198

198199
getContext()
@@ -690,9 +691,9 @@ public static void raiseInThread(RubyLanguage language, RubyContext context, Rub
690691
"Thread#raise",
691692
rubyThread,
692693
currentNode,
693-
(currentThread, currentNode1) -> {
694+
(currentThread, threadCurrentNode) -> {
694695
if (exception.backtrace == null) {
695-
exception.backtrace = context.getCallStack().getBacktrace(currentNode1);
696+
exception.backtrace = context.getCallStack().getBacktrace(threadCurrentNode);
696697
}
697698

698699
VMRaiseExceptionNode.reRaiseException(context, exception);

src/main/java/org/truffleruby/language/SafepointManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ public void pauseRubyThreadAndExecute(String reason, RubyThread rubyThread, Node
320320
// fast path if we are already the right thread
321321
action.accept(rubyThread, currentNode);
322322
} else {
323-
pauseAllThreadsAndExecute(reason, currentNode, false, (thread, currentNode1) -> {
323+
pauseAllThreadsAndExecute(reason, currentNode, false, (thread, threadCurrentNode) -> {
324324
if (thread == rubyThread &&
325325
threadManager.getRubyFiberFromCurrentJavaThread() == fiberManager.getCurrentFiber()) {
326-
action.accept(thread, currentNode1);
326+
action.accept(thread, threadCurrentNode);
327327
}
328328
});
329329
}

src/main/java/org/truffleruby/language/backtrace/Backtrace.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,20 @@ public int getTotalUnderlyingElements() {
147147

148148
public static String labelFor(TruffleStackTraceElement e) {
149149
RootNode root = e.getTarget().getRootNode();
150-
return root instanceof RubyRootNode
150+
String label = root instanceof RubyRootNode
151151
// Ruby backtraces do not include the class name for MRI compatibility.
152152
? ((RubyRootNode) root).getSharedMethodInfo().getBacktraceName()
153153
: getRootName(root);
154+
return label == null ? "<unknown>" : label;
154155
}
155156

156157
public static String baseLabelFor(TruffleStackTraceElement e) {
157158
RootNode root = e.getTarget().getRootNode();
158-
return root instanceof RubyRootNode
159+
String baseLabel = root instanceof RubyRootNode
159160
// Ruby backtraces do not include the class name for MRI compatibility.
160161
? ((RubyRootNode) root).getSharedMethodInfo().getMethodName()
161162
: getRootName(root);
163+
return baseLabel == null ? "<unknown>" : baseLabel;
162164
}
163165

164166
@TruffleBoundary

src/main/java/org/truffleruby/language/objects/ObjectGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static Set<Object> stopAndGetAllObjects(String reason, RubyContext contex
4343

4444
final Thread initiatingJavaThread = Thread.currentThread();
4545

46-
context.getSafepointManager().pauseAllThreadsAndExecute(reason, currentNode, false, (thread, currentNode1) -> {
46+
context.getSafepointManager().pauseAllThreadsAndExecute(reason, currentNode, false, (thread, node) -> {
4747
synchronized (visited) {
4848
final Set<Object> reachable = newObjectSet();
4949
// Thread.current
@@ -84,7 +84,7 @@ public static Set<Object> stopAndGetRootObjects(String reason, RubyContext conte
8484

8585
final Thread initiatingJavaThread = Thread.currentThread();
8686

87-
context.getSafepointManager().pauseAllThreadsAndExecute(reason, currentNode, false, (thread, currentNode1) -> {
87+
context.getSafepointManager().pauseAllThreadsAndExecute(reason, currentNode, false, (thread, node) -> {
8888
synchronized (visited) {
8989
visited.add(thread);
9090

0 commit comments

Comments
 (0)