Skip to content

Commit 797023b

Browse files
committed
[GR-20396] Reorganize Backtrace#{getActivations,getBacktraceLocations}.
PullRequest: truffleruby/1257
2 parents 490f78e + c523131 commit 797023b

File tree

5 files changed

+210
-143
lines changed

5 files changed

+210
-143
lines changed

src/main/java/org/truffleruby/core/exception/ExceptionNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected Object backtraceLocations(DynamicObject exception,
187187
DynamicObject backtraceLocations = Layouts.EXCEPTION.getBacktraceLocations(exception);
188188
if (hasLocationsProfile.profile(backtraceLocations == null)) {
189189
Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
190-
backtraceLocations = backtrace.getBacktraceLocations(GetBacktraceException.UNLIMITED);
190+
backtraceLocations = backtrace.getBacktraceLocations(GetBacktraceException.UNLIMITED, null);
191191
Layouts.EXCEPTION.setBacktraceLocations(exception, backtraceLocations);
192192
}
193193
return backtraceLocations;

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,7 @@ private DynamicObject innerCallerLocations(int omit, int length) {
318318
// Always skip #caller_locations.
319319
final int omitted = omit + 1;
320320
final Backtrace backtrace = getContext().getCallStack().getBacktrace(this, omitted);
321-
322-
// We can't set an effective limit when dealing with negative range endings.
323-
final int limit = length < 0
324-
? GetBacktraceException.UNLIMITED
325-
: omitted + length;
326-
327-
// Fill in the stack trace.
328-
backtrace.getActivations(new GetBacktraceException(this, limit));
329-
330-
return backtrace.getBacktraceLocations(length);
321+
return backtrace.getBacktraceLocations(length, this);
331322
}
332323
}
333324

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,30 +153,21 @@ protected DynamicObject backtraceLocations(
153153

154154
@TruffleBoundary
155155
private DynamicObject backtraceLocationsInternal(DynamicObject rubyThread, int omit, int length) {
156-
final Memo<Backtrace> backtraceMemo = new Memo<>(null);
157-
158-
// We can't set an effective limit when dealing with negative range endings.
159-
final int stackTraceElementsLimit = length < 0
160-
? GetBacktraceException.UNLIMITED
161-
: omit + length;
156+
final Memo<DynamicObject> backtraceLocationsMemo = new Memo<>(null);
162157

163158
final SafepointAction safepointAction = (thread1, currentNode) -> {
164159
final Backtrace backtrace = getContext().getCallStack().getBacktrace(this, omit);
165-
backtraceMemo.set(backtrace);
166-
// Fill in the stack trace.
167-
backtrace.getActivations(new GetBacktraceException(this, stackTraceElementsLimit));
160+
backtraceLocationsMemo.set(backtrace.getBacktraceLocations(length, this));
168161
};
169162

170163
getContext()
171164
.getSafepointManager()
172165
.pauseRubyThreadAndExecute(rubyThread, this, safepointAction);
173166

174167
// If the thread is dead or aborting the SafepointAction will not run.
175-
if (backtraceMemo.get() == null) {
176-
return nil();
177-
}
178-
179-
return backtraceMemo.get().getBacktraceLocations(length);
168+
return backtraceLocationsMemo.get() == null
169+
? nil()
170+
: backtraceLocationsMemo.get();
180171
}
181172
}
182173

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,8 @@ public boolean ignoreFrame(Node callNode, RootCallTarget callTarget) {
228228
}
229229
}
230230

231-
if (rootNode instanceof InternalRootNode) {
232-
return true;
233-
}
234-
235-
236-
if (callNode.getEncapsulatingSourceSection() == null) {
237-
return true;
238-
}
231+
return rootNode instanceof InternalRootNode || callNode.getEncapsulatingSourceSection() == null;
239232

240-
return false;
241233
}
242234

243235
}

0 commit comments

Comments
 (0)