btraceio / btrace

BTrace - a safe, dynamic tracing tool for the Java platform
5.82k stars 961 forks source link

NoClassDefFoundError for ConcurrentAutoTable and others when running an application with BTrace #643

Closed magicwerk closed 1 year ago

magicwerk commented 1 year ago

The fix provided for #632 seem not be fully working. If I try to trace with https://github.com/btraceio/btrace/blob/master/btrace-dist/src/main/resources/samples/HistoOnEvent.java more classes are reported as missing

To make it work locally, I disabled all the exclusions for org/jctools. As the JAR files does get much bigger, I wonder whether fiddling with the excludes is worth the pain.

I'm also surprised that an official example seems not be running - may be unit tests covering them could help.

java.lang.NoClassDefFoundError: Lorg/openjdk/btrace/libs/org/jctools/maps/ConcurrentAutoTable;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredField(Class.java:2068)
    at org.openjdk.btrace.libs.org.jctools.util.UnsafeAccess.fieldOffset(UnsafeAccess.java:107)
    at org.openjdk.btrace.libs.org.jctools.maps.NonBlockingIdentityHashMap.<clinit>(NonBlockingIdentityHashMap.java:105)
    at org.openjdk.btrace.instr.ClassCache.<init>(ClassCache.java:80)
    at org.openjdk.btrace.instr.ClassCache$Singleton.<clinit>(ClassCache.java:158)
    at org.openjdk.btrace.instr.ClassCache.getInstance(ClassCache.java:90)
    at org.openjdk.btrace.instr.InstrumentUtils.collectHierarchyClosure(InstrumentUtils.java:78)
    at org.openjdk.btrace.instr.InstrumentUtils.collectHierarchyClosure(InstrumentUtils.java:60)
    at org.openjdk.btrace.instr.BTraceClassWriter.getCommonSuperClass(BTraceClassWriter.java:111)
    at org.openjdk.btrace.libs.org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1202)
    at org.openjdk.btrace.libs.org.objectweb.asm.Frame.merge(Frame.java:1299)
    at org.openjdk.btrace.libs.org.objectweb.asm.Frame.merge(Frame.java:1197)
    at org.openjdk.btrace.libs.org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1611)
    at org.openjdk.btrace.libs.org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1547)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:767)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:647)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:468)
    at org.openjdk.btrace.instr.BTraceProbeNode.getBytecode(BTraceProbeNode.java:252)
    at org.openjdk.btrace.instr.BTraceProbeNode.getFullBytecode(BTraceProbeNode.java:210)
    at org.openjdk.btrace.instr.BTraceProbePersisted.<init>(BTraceProbePersisted.java:83)
    at org.openjdk.btrace.instr.BTraceProbePersisted.from(BTraceProbePersisted.java:90)
    at org.openjdk.btrace.instr.InstrPackGenerator.generateProbePack(InstrPackGenerator.java:19)
    at org.openjdk.btrace.compiler.CompilerHelper.compile(CompilerHelper.java:122)
    at org.openjdk.btrace.compiler.Compiler.compile(Compiler.java:244)
    at org.openjdk.btrace.compiler.Compiler.compile(Compiler.java:234)
    at org.openjdk.btrace.compiler.Compiler.main(Compiler.java:172)
Caused by: java.lang.ClassNotFoundException: org.openjdk.btrace.libs.org.jctools.maps.ConcurrentAutoTable
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 28 more

java.lang.NoClassDefFoundError: org/openjdk/btrace/libs/org/jctools/util/RangeUtil
    at org.openjdk.btrace.libs.org.jctools.maps.NonBlockingIdentityHashMap.initialize(NonBlockingIdentityHashMap.java:265)
    at org.openjdk.btrace.libs.org.jctools.maps.NonBlockingIdentityHashMap.<init>(NonBlockingIdentityHashMap.java:263)
    at org.openjdk.btrace.libs.org.jctools.maps.NonBlockingIdentityHashMap.<init>(NonBlockingIdentityHashMap.java:256)
    at org.openjdk.btrace.instr.ClassCache.<init>(ClassCache.java:80)
    at org.openjdk.btrace.instr.ClassCache$Singleton.<clinit>(ClassCache.java:158)
    at org.openjdk.btrace.instr.ClassCache.getInstance(ClassCache.java:90)
    at org.openjdk.btrace.instr.InstrumentUtils.collectHierarchyClosure(InstrumentUtils.java:78)
    at org.openjdk.btrace.instr.InstrumentUtils.collectHierarchyClosure(InstrumentUtils.java:60)
    at org.openjdk.btrace.instr.BTraceClassWriter.getCommonSuperClass(BTraceClassWriter.java:111)
    at org.openjdk.btrace.libs.org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1202)
    at org.openjdk.btrace.libs.org.objectweb.asm.Frame.merge(Frame.java:1299)
    at org.openjdk.btrace.libs.org.objectweb.asm.Frame.merge(Frame.java:1197)
    at org.openjdk.btrace.libs.org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1611)
    at org.openjdk.btrace.libs.org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1547)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:767)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:647)
    at org.openjdk.btrace.libs.org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:468)
    at org.openjdk.btrace.instr.BTraceProbeNode.getBytecode(BTraceProbeNode.java:252)
    at org.openjdk.btrace.instr.BTraceProbeNode.getFullBytecode(BTraceProbeNode.java:210)
    at org.openjdk.btrace.instr.BTraceProbePersisted.<init>(BTraceProbePersisted.java:83)
    at org.openjdk.btrace.instr.BTraceProbePersisted.from(BTraceProbePersisted.java:90)
    at org.openjdk.btrace.instr.InstrPackGenerator.generateProbePack(InstrPackGenerator.java:19)
    at org.openjdk.btrace.compiler.CompilerHelper.compile(CompilerHelper.java:122)
    at org.openjdk.btrace.compiler.Compiler.compile(Compiler.java:244)
    at org.openjdk.btrace.compiler.Compiler.compile(Compiler.java:234)
    at org.openjdk.btrace.compiler.Compiler.main(Compiler.java:172)
Caused by: java.lang.ClassNotFoundException: org.openjdk.btrace.libs.org.jctools.util.RangeUtil
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 26 more
jbachorik commented 1 year ago

Hi, as usual, thanks for reporting!

I have changed the dist to shade full jctools to avoid this issue.

As for the missing tests for the examples - there are definitely some blind spots there, the functional tests are not 100% replicating the examples, but there is only so much I can do in my spare time :(

Another thing is that you need a particular class you want to retransform to hit this issue - it must force ASM to find the common superclass for stackmap frame calculation in order to call the affected code.