Skip to content

Commit

Permalink
Ensure all frame names are non-null
Browse files Browse the repository at this point in the history
These names will leak out in stack traces so may need to be
reconsidered.
  • Loading branch information
headius committed Apr 12, 2024
1 parent 823dce1 commit 9121f72
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
InterpretedIRBodyMethod bodyMethod = (InterpretedIRBodyMethod) getModuleBody().retrieve(context, self, currScope, currDynScope, temp);
RubyModule implClass = bodyMethod.getImplementationClass();

return bodyMethod.call(context, implClass, implClass, null, Block.NULL_BLOCK);
return bodyMethod.call(context, implClass, implClass, "<module>", Block.NULL_BLOCK);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public static IRubyObject INTERPRET_BLOCK(ThreadContext context, Block block, IR
}

public static IRubyObject INTERPRET_CLASS(ThreadContext context, IRScope body, RubyModule clazz) {
return interpretFrameScope(context, null, body, clazz, null, Visibility.PUBLIC, clazz, null, null, Block.NULL_BLOCK);
return interpretFrameScope(context, null, body, clazz, null, Visibility.PUBLIC, clazz, "<class>", null, Block.NULL_BLOCK);
}

public static IRubyObject INTERPRET_MODULE(ThreadContext context, IRScope body, RubyModule clazz) {
return interpretFrameScope(context, null, body, clazz, null, Visibility.PUBLIC, clazz, null, null, Block.NULL_BLOCK);
return interpretFrameScope(context, null, body, clazz, null, Visibility.PUBLIC, clazz, "<module>", null, Block.NULL_BLOCK);
}

public static IRubyObject INTERPRET_METACLASS(ThreadContext context, IRScope body, RubyModule clazz, Visibility visibility) {
return interpretFrameScope(context, null, body, clazz, context.getCurrentScope(), visibility, clazz, null, null, Block.NULL_BLOCK);
return interpretFrameScope(context, null, body, clazz, context.getCurrentScope(), visibility, clazz, "<metaclass>", null, Block.NULL_BLOCK);
}

public static IRubyObject INTERPRET_METHOD(ThreadContext context, IRScope body, RubyModule implClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle
public static IRubyObject invokeModuleBody(ThreadContext context, DynamicMethod method) {
RubyModule implClass = method.getImplementationClass();

return method.call(context, implClass, implClass, null, Block.NULL_BLOCK);
return method.call(context, implClass, implClass, "<module>", Block.NULL_BLOCK);
}

@JIT
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ private void defineRunMethod(IRScriptBody script, String scopeName, String scope
method.aconst_null(); // args
method.getstatic(p(Block.class), "NULL_BLOCK", ci(Block.class)); // block
method.aload(4); // self class
method.aconst_null(); // call name
method.ldc("<root>"); // call name

method.invokestatic(clsName, scopeName, sig(signature.type().returnType(), signature.type().parameterArray()));
method.areturn();
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/runtime/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public final class Frame {
* when needed.
*/
public Frame() {
name = "<root>";
}

/**
Expand All @@ -112,6 +113,7 @@ private Frame(Block nullBlock) {
*/
private Frame(Frame frame) {
assert frame.block != null;
assert frame.name != null;

this.self = frame.self;
this.name = frame.name;
Expand All @@ -135,6 +137,7 @@ public void updateFrame() {
* @param name The name of the method being called
*/
public void updateFrame(String name) {
assert name != null;
this.name = name;
}

Expand All @@ -147,6 +150,7 @@ public void updateFrame(String name) {
public void updateFrame(Frame frame) {
Block block = frame.block;
assert block != null;
assert frame.name != null;

this.self = frame.self;
this.name = frame.name;
Expand All @@ -165,6 +169,7 @@ public void updateFrame(Frame frame) {
*/
public void updateFrame(RubyModule klazz, IRubyObject self, String name, Block block) {
assert block != null;
assert name != null;
this.self = self;
this.name = name;
this.klazz = klazz;
Expand All @@ -182,6 +187,7 @@ public void updateFrame(RubyModule klazz, IRubyObject self, String name, Block b
*/
public void updateFrame(RubyModule klazz, IRubyObject self, String name, Visibility visibility, Block block) {
assert block != null;
assert name != null;
this.self = self;
this.name = name;
this.klazz = klazz;
Expand All @@ -196,7 +202,7 @@ public void updateFrame(RubyModule klazz, IRubyObject self, String name, Visibil
*/
public void updateFrameForEval(IRubyObject self) {
this.self = self;
this.name = null;
this.name = "<eval>";
this.visibility = Visibility.PRIVATE;
}

Expand Down Expand Up @@ -267,6 +273,7 @@ public void setKlazz(RubyModule klazz) {
* @param name the new name
*/
public void setName(String name) {
assert name != null;
this.name = name;
}

Expand Down

0 comments on commit 9121f72

Please sign in to comment.