Skip to content

Commit 881f560

Browse files
committed
Minor cleanup
1 parent c13cfb9 commit 881f560

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

doc/user/compatibility.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ When TruffleRuby is run as part of a polyglot application, any signals that are
145145

146146
TruffleRuby provides similar `GC.stat` statistics to MRI, but not all statistics are available, and some statistics may be approximations. Use `GC.stat.keys` to see which are provided with real or approximate values. Missing values will return `0`.
147147

148+
### Caller locations
149+
150+
Using `Kernel#caller_locations` or `Thread.each_caller_location` might contain engine specific location objects and/or
151+
paths. This is expected and should be filtered in application code where necessary.
152+
153+
The enumerator returned by `Thread.to_enum(:each_caller_location)` is not supporting iteration with `.next`. In CRuby
154+
this raises a `StopIteration`, while in TruffleRuby it iterates on an undetermined (related to where and how `.next` is
155+
called) call stack. It is not recommended to use this in any circumstance (neither CRuby nor TruffleRuby).
156+
148157
## Features with Very Low Performance
149158

150159
### `ObjectSpace`
@@ -167,15 +176,6 @@ It is not recommended to use exceptions for control flow on any implementation o
167176

168177
To help alleviate this problem, backtraces are automatically disabled in cases where we can detect that they will not be used.
169178

170-
### Caller locations
171-
172-
Using `Kernel#caller_locations` or `Thread.each_caller_location` might contain engine specific location objects and/or
173-
paths. This is expected and should be filtered in application code where necessary.
174-
175-
The enumerator returned by `Thread.to_enum(:each_caller_location)` is not supporting iteration with `.next`. In CRuby
176-
this raises a `StopIteration`, while in TruffleRuby it iterates on an undetermined (related to where and how `.next` is
177-
called) call stack. It is not recommended to use this in any circumstance (neither CRuby nor TruffleRuby).
178-
179179
## C Extension Compatibility
180180

181181
### Identifiers may be macros or functions

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.oracle.truffle.api.TruffleSafepoint.Interrupter;
5151
import com.oracle.truffle.api.dsl.Bind;
5252
import com.oracle.truffle.api.TruffleStackTraceElement;
53-
import com.oracle.truffle.api.frame.FrameInstance;
5453
import com.oracle.truffle.api.frame.VirtualFrame;
5554
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5655
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -1048,44 +1047,38 @@ protected Object runBlockingSystemCall(Object executable, RubyArray argsArray,
10481047
@CoreMethod(names = "each_caller_location", needsBlock = true, onSingleton = true)
10491048
public abstract static class EachCallerLocationNode extends CoreMethodArrayArgumentsNode {
10501049

1051-
private static final Object STOP_ITERATE = new Object();
1052-
10531050
// Skip the block of `Thread#each_caller_location` + its internal iteration.
10541051
private static final int SKIP = 2;
10551052

10561053
@Child private CallBlockNode yieldNode = CallBlockNode.create();
10571054

10581055
@Specialization
10591056
protected Object eachCallerLocation(VirtualFrame frame, RubyProc block) {
1060-
final List<TruffleStackTraceElement> stackTraceElements = new ArrayList<>();
1057+
final List<TruffleStackTraceElement> elements = new ArrayList<>();
10611058

10621059
getContext().getCallStack().iterateFrameBindings(SKIP, frameInstance -> {
10631060
final Node location = frameInstance.getCallNode();
10641061

1065-
final RootCallTarget rootCallTarget = (RootCallTarget) frameInstance.getCallTarget();
1066-
final TruffleStackTraceElement stackTraceElement = TruffleStackTraceElement.create(
1067-
location,
1068-
rootCallTarget,
1069-
frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY));
1070-
stackTraceElements.add(stackTraceElement);
1062+
final var rootCallTarget = (RootCallTarget) frameInstance.getCallTarget();
1063+
final var element = TruffleStackTraceElement.create(location, rootCallTarget, null);
1064+
elements.add(element);
10711065

1072-
final TruffleStackTraceElement[] finalStackTraceElements = stackTraceElements
1073-
.toArray(TruffleStackTraceElement[]::new);
1074-
final boolean readyToYield = BacktraceFormatter.nextAvailableSourceSection(finalStackTraceElements,
1066+
final var elementsArray = elements.toArray(Backtrace.EMPTY_STACK_TRACE_ELEMENTS_ARRAY);
1067+
final boolean readyToYield = BacktraceFormatter.nextAvailableSourceSection(elementsArray,
10751068
0) != null;
10761069

10771070
if (readyToYield) {
1078-
for (int i = 0; i < finalStackTraceElements.length; i++) {
1079-
final Backtrace backtrace = new Backtrace(location, 0, finalStackTraceElements);
1080-
RubyBacktraceLocation rubyBacktraceLocation = new RubyBacktraceLocation(
1071+
for (int i = 0; i < elementsArray.length; i++) {
1072+
final var backtrace = new Backtrace(location, 0, elementsArray);
1073+
final var rubyBacktraceLocation = new RubyBacktraceLocation(
10811074
getContext().getCoreLibrary().threadBacktraceLocationClass,
10821075
getLanguage().threadBacktraceLocationShape,
10831076
backtrace,
10841077
i);
10851078

10861079
yieldNode.yield(block, rubyBacktraceLocation);
10871080
}
1088-
stackTraceElements.clear();
1081+
elements.clear();
10891082
}
10901083

10911084
return null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public final class Backtrace {
7777
private TruffleStackTraceElement[] stackTrace;
7878
private int totalUnderlyingElements;
7979

80+
public static final TruffleStackTraceElement[] EMPTY_STACK_TRACE_ELEMENTS_ARRAY = new TruffleStackTraceElement[0];
81+
8082
// endregion
8183
// region Constructors
8284

@@ -249,8 +251,6 @@ public TruffleStackTraceElement[] getStackTrace() {
249251
return getStackTrace(this.raiseException);
250252
}
251253

252-
private static final TruffleStackTraceElement[] EMPTY_STACK_TRACE_ELEMENTS_ARRAY = new TruffleStackTraceElement[0];
253-
254254
/** Returns a ruby array of {@code Thread::Backtrace::Locations} with maximum length {@code length}, and omitting
255255
* locations as requested ({@link #getOmitted()}). If more locations are omitted than are available, return a Ruby
256256
* {@code nil}.

0 commit comments

Comments
 (0)