Skip to content

Commit e55e5b5

Browse files
committed
Provide module operand to trace
This avoids needing a frame to get the frame class.
1 parent 91878c5 commit e55e5b5

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

core/src/main/java/org/jruby/ir/IRBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public void addInstr(Instr instr) {
377377
}
378378

379379
if (RubyInstanceConfig.FULL_TRACE_ENABLED) {
380-
addInstr(new TraceInstr(RubyEvent.LINE, methodNameFor(), getFileName(), lastProcessedLineNum + 1));
380+
addInstr(new TraceInstr(RubyEvent.LINE, getCurrentModuleVariable(), methodNameFor(), getFileName(), lastProcessedLineNum + 1));
381381
}
382382
}
383383

@@ -2791,7 +2791,7 @@ protected InterpreterContext defineMethodInner(DefNode defNode, IRScope parent,
27912791
addInstr(manager.newLineNumber(scope.getLine() + 1));
27922792
}
27932793

2794-
addInstr(new TraceInstr(RubyEvent.CALL, getName(), getFileName(), scope.getLine() + 1));
2794+
addInstr(new TraceInstr(RubyEvent.CALL, getCurrentModuleVariable(), getName(), getFileName(), scope.getLine() + 1));
27952795

27962796
prepareImplicitState(); // recv_self, add frame block, etc)
27972797

@@ -2811,7 +2811,7 @@ protected InterpreterContext defineMethodInner(DefNode defNode, IRScope parent,
28112811
addInstr(new LineNumberInstr(defNode.getEndLine() + 1));
28122812
}
28132813

2814-
addInstr(new TraceInstr(RubyEvent.RETURN, getName(), getFileName(), defNode.getEndLine() + 1));
2814+
addInstr(new TraceInstr(RubyEvent.RETURN, getCurrentModuleVariable(), getName(), getFileName(), defNode.getEndLine() + 1));
28152815

28162816
if (rv != null) addInstr(new ReturnInstr(rv));
28172817

@@ -3786,7 +3786,7 @@ private InterpreterContext buildIterInner(RubySymbol methodName, IterNode iterNo
37863786
boolean forNode = iterNode instanceof ForNode;
37873787
prepareClosureImplicitState(); // recv_self, add frame block, etc)
37883788

3789-
addInstr(new TraceInstr(RubyEvent.B_CALL, getName(), getFileName(), scope.getLine() + 1));
3789+
addInstr(new TraceInstr(RubyEvent.B_CALL, getCurrentModuleVariable(), getName(), getFileName(), scope.getLine() + 1));
37903790

37913791
if (!forNode) addCurrentModule(); // %current_module
37923792
receiveBlockArgs(iterNode);
@@ -3800,7 +3800,7 @@ private InterpreterContext buildIterInner(RubySymbol methodName, IterNode iterNo
38003800
// Build closure body and return the result of the closure
38013801
Operand closureRetVal = iterNode.getBodyNode() == null ? manager.getNil() : build(iterNode.getBodyNode());
38023802

3803-
addInstr(new TraceInstr(RubyEvent.B_RETURN, getName(), getFileName(), iterNode.getEndLine() + 1));
3803+
addInstr(new TraceInstr(RubyEvent.B_RETURN, getCurrentModuleVariable(), getName(), getFileName(), iterNode.getEndLine() + 1));
38043804

38053805
// can be U_NIL if the node is an if node with returns in both branches.
38063806
if (closureRetVal != U_NIL) addInstr(new ReturnInstr(closureRetVal));
@@ -4580,7 +4580,7 @@ public Operand buildReturn(ReturnNode returnNode) {
45804580
} else {
45814581
retVal = processEnsureRescueBlocks(retVal);
45824582

4583-
addInstr(new TraceInstr(RubyEvent.RETURN, getName(), getFileName(), returnNode.getLine() + 1));
4583+
addInstr(new TraceInstr(RubyEvent.RETURN, getCurrentModuleVariable(), getName(), getFileName(), returnNode.getLine() + 1));
45844584
addInstr(new ReturnInstr(retVal));
45854585
}
45864586

@@ -4971,7 +4971,7 @@ private Operand[] adjustVariableDepth(Operand[] args, int depthFromSuper) {
49714971
}
49724972

49734973
private InterpreterContext buildModuleOrClassBody(Node bodyNode, int startLine, int endLine) {
4974-
addInstr(new TraceInstr(RubyEvent.CLASS, null, getFileName(), startLine + 1));
4974+
addInstr(new TraceInstr(RubyEvent.CLASS, getCurrentModuleVariable(), null, getFileName(), startLine + 1));
49754975

49764976
prepareImplicitState(); // recv_self, add frame block, etc)
49774977
addCurrentModule(); // %current_module
@@ -4981,7 +4981,7 @@ private InterpreterContext buildModuleOrClassBody(Node bodyNode, int startLine,
49814981
// This is only added when tracing is enabled because an 'end' will normally have no other instrs which can
49824982
// raise after this point. When we add trace we need to add one so backtrace generated shows the 'end' line.
49834983
addInstr(manager.newLineNumber(endLine));
4984-
addInstr(new TraceInstr(RubyEvent.END, null, getFileName(), endLine + 1));
4984+
addInstr(new TraceInstr(RubyEvent.END, getCurrentModuleVariable(), null, getFileName(), endLine + 1));
49854985

49864986
addInstr(new ReturnInstr(bodyReturnValue));
49874987

core/src/main/java/org/jruby/ir/instructions/TraceInstr.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.jruby.ir.instructions;
22

3+
import org.jruby.RubyModule;
34
import org.jruby.RubySymbol;
45
import org.jruby.ir.IRFlags;
56
import org.jruby.ir.IRScope;
67
import org.jruby.ir.IRVisitor;
78
import org.jruby.ir.Operation;
9+
import org.jruby.ir.operands.Operand;
810
import org.jruby.ir.persistence.IRReaderDecoder;
911
import org.jruby.ir.persistence.IRWriterEncoder;
1012
import org.jruby.ir.runtime.IRRuntimeHelpers;
@@ -24,22 +26,24 @@
2426
*/
2527
public class TraceInstr extends NoOperandInstr {
2628
private final RubyEvent event;
29+
private final Operand module;
2730
private final RubySymbol name;
2831
private final String filename;
2932
private final int linenumber;
3033

31-
public TraceInstr(RubyEvent event, RubySymbol name, String filename, int linenumber) {
34+
public TraceInstr(RubyEvent event, Operand module, RubySymbol name, String filename, int linenumber) {
3235
super(Operation.TRACE);
3336

3437
this.event = event;
38+
this.module = module;
3539
this.name = name;
3640
this.filename = filename;
3741
this.linenumber = linenumber;
3842
}
3943

4044
@Override
4145
public Instr clone(CloneInfo ii) {
42-
return new TraceInstr(event, name, filename, linenumber);
46+
return new TraceInstr(event, module, name, filename, linenumber);
4347
}
4448

4549
public RubyEvent getEvent() {
@@ -67,18 +71,20 @@ public String[] toStringNonOperandArgs() {
6771
public void encode(IRWriterEncoder e) {
6872
super.encode(e);
6973
e.encode(getEvent());
74+
e.encode(module);
7075
e.encode(name);
7176
e.encode(getFilename());
7277
e.encode(getLinenumber());
7378
}
7479

7580
public static TraceInstr decode(IRReaderDecoder d) {
76-
return new TraceInstr(d.decodeRubyEvent(), d.decodeSymbol(), d.decodeString(), d.decodeInt());
81+
return new TraceInstr(d.decodeRubyEvent(), d.decodeOperand(), d.decodeSymbol(), d.decodeString(), d.decodeInt());
7782
}
7883

7984
@Override
8085
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
81-
IRRuntimeHelpers.callTrace(context, context.getFrameKlazz(), getEvent(), getName(), getFilename(), getLinenumber());
86+
IRubyObject selfClass = (IRubyObject) module.retrieve(context, self, currScope, currDynScope, temp);
87+
IRRuntimeHelpers.callTrace(context, selfClass, getEvent(), getName(), getFilename(), getLinenumber());
8288

8389
return null;
8490
}

core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ public static RubyString getFileNameStringFromScope(ThreadContext context, Stati
24502450
}
24512451

24522452
@JIT
2453-
public static void callTrace(ThreadContext context, RubyModule selfClass, RubyEvent event, String name, String filename, int line) {
2453+
public static void callTrace(ThreadContext context, IRubyObject selfClass, RubyEvent event, String name, String filename, int line) {
24542454
Ruby runtime = context.runtime;
24552455
if (runtime.hasEventHooks()) {
24562456
// FIXME: Try and statically generate END linenumber instead of hacking it.

0 commit comments

Comments
 (0)