This is an automated email from the ASF dual-hosted git repository. wusheng pushed a commit to branch groovy-replace in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 9cd7a040e8d5ec3f2c881ea77d047290f2b649fb Author: Wu Sheng <[email protected]> AuthorDate: Mon Mar 2 21:40:28 2026 +0800 Add LocalVariableTable to LAL and Hierarchy generated bytecode Add LVT attribute to LAL execute() and consumer accept() methods, and to Hierarchy apply() method, so decompilers show meaningful variable names (filterSpec, binding, _t, u, l) instead of var0, var1, etc. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../v2/compiler/HierarchyRuleClassGenerator.java | 37 ++++++++++++++++++- .../analyzer/v2/compiler/LALClassGenerator.java | 41 ++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/oap-server/analyzer/hierarchy/src/main/java/org/apache/skywalking/oap/server/core/config/v2/compiler/HierarchyRuleClassGenerator.java b/oap-server/analyzer/hierarchy/src/main/java/org/apache/skywalking/oap/server/core/config/v2/compiler/HierarchyRuleClassGenerator.java index 23ddf5d7c0..2a3f4b5768 100644 --- a/oap-server/analyzer/hierarchy/src/main/java/org/apache/skywalking/oap/server/core/config/v2/compiler/HierarchyRuleClassGenerator.java +++ b/oap-server/analyzer/hierarchy/src/main/java/org/apache/skywalking/oap/server/core/config/v2/compiler/HierarchyRuleClassGenerator.java @@ -111,6 +111,33 @@ public final class HierarchyRuleClassGenerator { } } + private void addLocalVariableTable(final javassist.CtMethod method, + final String className, + final String[][] vars) { + try { + final javassist.bytecode.MethodInfo mi = method.getMethodInfo(); + final javassist.bytecode.CodeAttribute code = mi.getCodeAttribute(); + if (code == null) { + return; + } + final javassist.bytecode.ConstPool cp = mi.getConstPool(); + final int len = code.getCodeLength(); + final javassist.bytecode.LocalVariableAttribute lva = + new javassist.bytecode.LocalVariableAttribute(cp); + lva.addEntry(0, len, + cp.addUtf8Info("this"), + cp.addUtf8Info("L" + className.replace('.', '/') + ";"), 0); + for (int i = 0; i < vars.length; i++) { + lva.addEntry(0, len, + cp.addUtf8Info(vars[i][0]), + cp.addUtf8Info(vars[i][1]), i + 1); + } + code.getAttributes().add(lva); + } catch (Exception e) { + log.warn("Failed to add LocalVariableTable: {}", e.getMessage()); + } + } + /** * Compiles a hierarchy rule expression into a BiFunction class. * @@ -145,7 +172,15 @@ public final class HierarchyRuleClassGenerator { log.debug("Hierarchy compile [{}] apply():\n{}", ruleName, applyBody); } - ctClass.addMethod(CtNewMethod.make(applyBody, ctClass)); + final javassist.CtMethod applyMethod = CtNewMethod.make(applyBody, ctClass); + ctClass.addMethod(applyMethod); + final String svcDesc = "Lorg/apache/skywalking/oap/server/core/query/type/Service;"; + addLocalVariableTable(applyMethod, className, new String[][]{ + {"arg0", "Ljava/lang/Object;"}, + {"arg1", "Ljava/lang/Object;"}, + {model.getUpperParam(), svcDesc}, + {model.getLowerParam(), svcDesc} + }); writeClassFile(ctClass); final Class<?> clazz = ctClass.toClass(HierarchyRulePackageHolder.class); diff --git a/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALClassGenerator.java b/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALClassGenerator.java index eddb98155d..ab4014eaed 100644 --- a/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALClassGenerator.java +++ b/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALClassGenerator.java @@ -140,6 +140,33 @@ public final class LALClassGenerator { } } + private void addLocalVariableTable(final javassist.CtMethod method, + final String className, + final String[][] vars) { + try { + final javassist.bytecode.MethodInfo mi = method.getMethodInfo(); + final javassist.bytecode.CodeAttribute code = mi.getCodeAttribute(); + if (code == null) { + return; + } + final javassist.bytecode.ConstPool cp = mi.getConstPool(); + final int len = code.getCodeLength(); + final javassist.bytecode.LocalVariableAttribute lva = + new javassist.bytecode.LocalVariableAttribute(cp); + lva.addEntry(0, len, + cp.addUtf8Info("this"), + cp.addUtf8Info("L" + className.replace('.', '/') + ";"), 0); + for (int i = 0; i < vars.length; i++) { + lva.addEntry(0, len, + cp.addUtf8Info(vars[i][0]), + cp.addUtf8Info(vars[i][1]), i + 1); + } + code.getAttributes().add(lva); + } catch (Exception e) { + log.warn("Failed to add LocalVariableTable: {}", e.getMessage()); + } + } + /** * Compiles a LAL DSL script into a LalExpression implementation. @@ -204,7 +231,12 @@ public final class LALClassGenerator { log.debug("LAL compile execute():\n{}", executeBody); } - ctClass.addMethod(CtNewMethod.make(executeBody, ctClass)); + final javassist.CtMethod execMethod = CtNewMethod.make(executeBody, ctClass); + ctClass.addMethod(execMethod); + addLocalVariableTable(execMethod, className, new String[][]{ + {"filterSpec", "L" + FILTER_SPEC.replace('.', '/') + ";"}, + {"binding", "L" + BINDING.replace('.', '/') + ";"} + }); writeClassFile(ctClass); @@ -848,7 +880,12 @@ public final class LALClassGenerator { log.debug("LAL compile consumer {} body:\n{}", className, method); } - ctClass.addMethod(CtNewMethod.make(method, ctClass)); + final javassist.CtMethod acceptMethod = CtNewMethod.make(method, ctClass); + ctClass.addMethod(acceptMethod); + addLocalVariableTable(acceptMethod, className, new String[][]{ + {"arg", "Ljava/lang/Object;"}, + {"_t", "L" + info.castType.replace('.', '/') + ";"} + }); writeClassFile(ctClass);
