btraceio / btrace

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

NoClassDefFoundError for NonBlockingIdentityHashMap when running an application with BTrace #632

Closed magicwerk closed 1 year ago

magicwerk commented 1 year ago

When running an application with BTrace, the following error occurs:

java.lang.NoClassDefFoundError: org/openjdk/btrace/libs/org/jctools/maps/NonBlockingIdentityHashMap at org.openjdk.btrace.instr.ClassCache.(ClassCache.java:80) at org.openjdk.btrace.instr.ClassCache$Singleton.(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.(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.NonBlockingIdentityHashMap 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) ... 23 more

Reason seems to be that ClassCache does the following imports

jbachorik commented 1 year ago

Hi @magicwerk Can you try the fix from #634 if it resolves your issue? Thanks!

magicwerk commented 1 year ago

There seems to be something wrong with the build - btrace-client.jar comes out empty.

magicwerk commented 1 year ago

There was simply a "&&" missing at the end of one line, I think the exclude below should be correct:

exclude {
    it.path.startsWith('org/jctools/maps/') &&
    !it.path.startsWith("org/jctools/maps/NonBlockingIdentityHashMap") &&
    !it.path.startsWith("org/jctools/maps/NonBlockingHashMap")
}
jbachorik commented 1 year ago

Good catch! Thanks! It is fixed now.