jvm-profiling-tools / ap-loader

Packages async-profiler with binaries for all platforms in a single JAR
Apache License 2.0
128 stars 10 forks source link

ap-loader-all in maven not the same as the released #7

Open maxandersen opened 1 year ago

maxandersen commented 1 year ago

I've been trying to use ap-loader-* artifacts from maven but afaics the released jar's from github release page and the maven central jars are NOT the same.

Resulting in this error using the maven jars:

run: /Users/manderse/.jbang/cache/jdks/19/bin/java '-javaagent:/Users/manderse/.m2/repository/me/bechberger/ap-loader-macos/2.9-4/ap-loader-macos-2.9-4.jar=start,event=cpu,file=profile.html' --enable-preview --add-opens java.base/java.lang=ALL-UNNAMED -classpath /Users/manderse/.jbang/cache/jars/VirtualThreadReflectionBenchmark.java.7d632a1c2e33734f11f5a17bf40fd430f897bd02269d088fa6ed26853056da8b.jar:/Users/manderse/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.36/jmh-generator-annprocess-1.36.jar:/Users/manderse/.m2/repository/org/openjdk/jmh/jmh-core/1.36/jmh-core-1.36.jar:/Users/manderse/.m2/repository/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar:/Users/manderse/.m2/repository/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar org.openjdk.jmh.Main
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)
Caused by: java.lang.NoClassDefFoundError: dev/dirs/ProjectDirectories
    at one.profiler.AsyncProfilerLoader.getExtractionDirectory(AsyncProfilerLoader.java:128)
    at one.profiler.AsyncProfilerLoader.getAsyncProfilerPath(AsyncProfilerLoader.java:345)
    at one.profiler.AsyncProfilerLoader.attach(AsyncProfilerLoader.java:613)
    at one.profiler.AsyncProfilerLoader.agentmain(AsyncProfilerLoader.java:625)
    at one.profiler.AsyncProfilerLoader.premain(AsyncProfilerLoader.java:586)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 3 more
Caused by: java.lang.ClassNotFoundException: dev.dirs.ProjectDirectories
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed

Using the downloaded jar works fine so I tried to compare them and notice that the released jars has dev/dirs embedded but the ones in maven central does not.

2023-02-14_11-37-27

There is also native image config missing and the manifest.mf is slightly different:

2023-02-14_11-38-14

Is there a reason for this difference?

parttimenerd commented 1 year ago

Both should be different, as the maven package does not contain the project-dir dependency. The JARs from GitHub are usually built from snapshots, then released later on maven central (albeit I release them rather often). Does this help you?

maxandersen commented 1 year ago

okey - it just means the ap-loader in maven central can't be used as agent and that the github jar says SNAPSHOT in them.

Thus for the jbang-catalog discussed in #6 I would need to use the github released jar not the maven central one.

parttimenerd commented 1 year ago

okey - it just means the ap-loader in maven central can't be used as agent and that the github jar says SNAPSHOT in them.

You could use the maven JAR if you put the dependency on the class path.

It might be a bug that the GitHub JAR says SNAPSHOT.

maxandersen commented 1 year ago

Javaagent only allows one jar.

And yes, could add to classpath it pollutes the applications classpath.

Second best option is boot classpath but that is a non-public openjdk feature.

So don't really see a way to use the agent unless using the GitHub releases where the necessary dependencies are included.