-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread::Backtrace::Location#label for top-level blocks includes filename instead of <main> #5166
Comments
+1 testcase. Not sure I'll get to this for 9.2.8 but I'll look at it along with #5165. |
Appears to only happen in the JIT:
|
Ok, I found a trivial fix for this, by encoding "<main>" as the block's method name rather than whatever we have in the IRClosure (the filename in this case): diff --git a/core/src/main/java/org/jruby/util/JavaNameMangler.java b/core/src/main/java/org/jruby/util/JavaNameMangler.java
index daa2c2bc97..fab7f35eb2 100644
--- a/core/src/main/java/org/jruby/util/JavaNameMangler.java
+++ b/core/src/main/java/org/jruby/util/JavaNameMangler.java
@@ -286,7 +286,11 @@ public class JavaNameMangler {
return "RUBY$method$" + mangleMethodNameInternal(scope.getId());
}
if (scope instanceof IRClosure) {
- return "RUBY$block$" + mangleMethodNameInternal(scope.getNearestTopLocalVariableScope().getId());
+ if (scope.getNearestTopLocalVariableScope() instanceof IRScriptBody) {
+ return "RUBY$block$" + mangleMethodNameInternal("<main>");
+ } else {
+ return "RUBY$block$" + mangleMethodNameInternal(scope.getNearestTopLocalVariableScope().getId());
+ }
}
if (scope instanceof IRMetaClassBody) {
return "RUBY$metaclass"; However I realized that MRI does not always use "<main>" for the top-level scope; in a loaded or required file, it uses "<top (required)>" or similar, which would require some clever handling to support. I will punt this to 9.2.9 to think on it more. The tricky bit for us is that in general, we don't have access to the original code at each level when generating a stack trace, so any information we want to convey needs to be encoded into the Backtrace object or the Java method name. The latter requirement makes it challenging to support AOT-compiled code, since it would not reflect whether it was run directly ("<main>") or required ("<top (required)>"). |
Hello again!
I'm using
Thread#backtrace_locations
and noticed several differences between MRI and JRuby.I'll report them separately because they may have different fixes, but feel free to mark any as duplicate if it makes sense to do so.
Environment
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
Linux u186024434db159d25c92 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Ubuntu 16.04.4 LTS
Expected Behavior
(Last one, I promise!)
When looking at a
Thread::Backtrace::Location
, for a top-level block, MRI returnsblock in <main>
.Testcase:
Output on MRI:
Actual Behavior
JRuby returns
block in <filename>
for the same testcase:If it would be helpful I can also submit a testcase to RubySpec.
The text was updated successfully, but these errors were encountered: