From 9a4ec8d5fe82c52c7f0d1b91a12ee12575df922a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Sun, 10 Sep 2023 23:27:07 +0200 Subject: [PATCH] Improve line numbers for generated dynscopes This is to help debug #7815 and hopefully provide more meaningful traces going forward. The non-specialized methods have line numbers from 0 up. Generated nullable getters have lines 100 + (variable offset). Generated non-nullable getters (nil for null) have lines 200 + (variable offset). Generated setters have lines 300 + (variable offset). --- .../runtime/scope/DynamicScopeGenerator.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/jruby/runtime/scope/DynamicScopeGenerator.java b/core/src/main/java/org/jruby/runtime/scope/DynamicScopeGenerator.java index 72f0544e586..30352c5684f 100644 --- a/core/src/main/java/org/jruby/runtime/scope/DynamicScopeGenerator.java +++ b/core/src/main/java/org/jruby/runtime/scope/DynamicScopeGenerator.java @@ -176,6 +176,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final final String baseName = p(DynamicScope.class); JiteClass jiteClass = new JiteClass(clsPath, baseName, new String[0]) {{ + setSourceFile(clsPath + ".java"); + // parent class constructor defineMethod("", ACC_PUBLIC, sig(void.class, StaticScope.class, DynamicScope.class), new CodeBlock() {{ aload(0); @@ -238,38 +240,56 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final iload(3); pushInt(1); isub(); + + line(6); invokevirtual(baseName, "setValueVoid", sig(void.class, IRubyObject.class, int.class, int.class)); voidreturn(); }}); // optional overrides defineMethod("getValueDepthZero", ACC_PUBLIC, sig(IRubyObject.class, int.class), new CodeBlock() {{ - line(6); + line(7); if (size > 0) genGetSwitch(clsPath, newFields, this, 1); - line(1); + line(8); invokestatic(clsPath, "sizeError", sig(RuntimeException.class)); athrow(); }}); defineMethod("setValueDepthZeroVoid", ACC_PUBLIC, sig(void.class, IRubyObject.class, int.class), new CodeBlock() {{ - line(6); + line(9); if (size > 0) genPutSwitch(clsPath, newFields, this, 2); - line(1); + line(10); invokestatic(clsPath, "sizeError", sig(RuntimeException.class)); athrow(); }}); + // utilities + + defineMethod("sizeError", ACC_PRIVATE | ACC_STATIC, sig(RuntimeException.class), new CodeBlock() {{ + line(11); + newobj(p(RuntimeException.class)); + dup(); + ldc(clsName + " only supports scopes with " + size + " variables"); + + line(12); + invokespecial(p(RuntimeException.class), "", sig(void.class, String.class)); + areturn(); + }}); + + // specialized getters and setters + for (int i = 0; i < SPECIALIZED_GETS.size(); i++) { final int offset = i; defineMethod(SPECIALIZED_GETS.get(offset), ACC_PUBLIC, sig(IRubyObject.class), new CodeBlock() {{ - line(6); + // line numbers for specialized getters are 100 + offset + line(100 + offset); if (size <= offset) { invokestatic(clsPath, "sizeError", sig(RuntimeException.class)); @@ -286,7 +306,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final final int offset = i; defineMethod(SPECIALIZED_GETS_OR_NIL.get(offset), ACC_PUBLIC, sig(IRubyObject.class, IRubyObject.class), new CodeBlock() {{ - line(6); + // line numbers for specialized get-or-nils are 200 + offset + line(200 + offset); if (size <= offset) { invokestatic(clsPath, "sizeError", sig(RuntimeException.class)); @@ -317,7 +338,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final final int offset = i; defineMethod(SPECIALIZED_SETS.get(offset), ACC_PUBLIC, sig(void.class, IRubyObject.class), new CodeBlock() {{ - line(6); + // line numbers for specialized setters are 300 + offset + line(300 + offset); if (size <= offset) { invokestatic(clsPath, "sizeError", sig(RuntimeException.class)); @@ -332,18 +354,10 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final } // fields + for (String prop : newFields) { defineField(prop, ACC_PUBLIC, ci(IRubyObject.class), null); } - - // utilities - defineMethod("sizeError", ACC_PRIVATE | ACC_STATIC, sig(RuntimeException.class), new CodeBlock() {{ - newobj(p(RuntimeException.class)); - dup(); - ldc(clsName + " only supports scopes with " + size + " variables"); - invokespecial(p(RuntimeException.class), "", sig(void.class, String.class)); - areturn(); - }}); }}; return defineClass(cdcl, jiteClass);