clojure-goes-fast / clj-async-profiler

Embedded high-precision Clojure profiler
http://clojure-goes-fast.com/kb/profiling/clj-async-profiler/
411 stars 17 forks source link

Add support for new ARM macOS (M1 chip et al) #20

Closed avocade closed 2 years ago

avocade commented 3 years ago

Guess we need to wait for support from async-profiler.

TheMode commented 3 years ago

Has been pushed, see https://github.com/jvm-profiling-tools/async-profiler/issues/390#issuecomment-851729544

alexander-yakushev commented 3 years ago

@avocade @TheMode Hey guys, version 0.5.1 includes the experimental darwin-aarch64 binary that the author of async-profiler has published in June. clj-async-profiler should choose use it automatically when you run it on this platform. Could you please try it out? Thank you!

samrat commented 3 years ago

I get a "Can not attach to current VM" exception on a M1 mac when I try with 0.5.1. Full stacktrace:


2. Unhandled java.lang.reflect.InvocationTargetException
   (No message)

NativeMethodAccessorImpl.java:   -2  jdk.internal.reflect.NativeMethodAccessorImpl/invoke0
NativeMethodAccessorImpl.java:   78  jdk.internal.reflect.NativeMethodAccessorImpl/invoke
DelegatingMethodAccessorImpl.java:   43  jdk.internal.reflect.DelegatingMethodAccessorImpl/invoke
               Method.java:  567  java.lang.reflect.Method/invoke
                  core.clj:  199  clj-async-profiler.core/mk-vm
                  core.clj:  196  clj-async-profiler.core/mk-vm
                  core.clj:  215  clj-async-profiler.core/attach-agent
                  core.clj:  212  clj-async-profiler.core/attach-agent
                  core.clj:  270  clj-async-profiler.core/start
                  core.clj:  257  clj-async-profiler.core/start
                      REPL:   46  user/eval57126
                      REPL:   46  user/eval57126
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  202  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  201  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  831  java.lang.Thread/run

1. Caused by java.io.IOException
   Can not attach to current VM

HotSpotVirtualMachine.java:   75  sun.tools.attach.HotSpotVirtualMachine/<init>
   VirtualMachineImpl.java:   56  sun.tools.attach.VirtualMachineImpl/<init>
   AttachProviderImpl.java:   58  sun.tools.attach.AttachProviderImpl/attachVirtualMachine
       VirtualMachine.java:  207  com.sun.tools.attach.VirtualMachine/attach
NativeMethodAccessorImpl.java:   -2  jdk.internal.reflect.NativeMethodAccessorImpl/invoke0
NativeMethodAccessorImpl.java:   78  jdk.internal.reflect.NativeMethodAccessorImpl/invoke
DelegatingMethodAccessorImpl.java:   43  jdk.internal.reflect.DelegatingMethodAccessorImpl/invoke
               Method.java:  567  java.lang.reflect.Method/invoke
                  core.clj:  199  clj-async-profiler.core/mk-vm
                  core.clj:  196  clj-async-profiler.core/mk-vm
                  core.clj:  215  clj-async-profiler.core/attach-agent
                  core.clj:  212  clj-async-profiler.core/attach-agent
                  core.clj:  270  clj-async-profiler.core/start
                  core.clj:  257  clj-async-profiler.core/start
                      REPL:   46  user/eval57126
                      REPL:   46  user/eval57126
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  202  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  201  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  831  java.lang.Thread/run
alexander-yakushev commented 3 years ago

Oof, which JDK version?

samrat commented 3 years ago
java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
alexander-yakushev commented 3 years ago

May I ask where did you get it from? It's certainly related to reflection restrictions in JDK16, I'd like to test it, so might as well install the same build as you.

samrat commented 3 years ago

@alexander-yakushev I used SDKman(https://sdkman.io/ ) to install it.

sogaiu commented 3 years ago

I may be mistaken, but it looks like that lets you install a variety of JDKs: https://sdkman.io/jdks

alexander-yakushev commented 3 years ago

I'm asking because I couldn't find AdoptOpenJDK (which I used to use before) builds for M1, so I'm currently using Zulu build of JDK8 for M1. So which one did you install?

samrat commented 3 years ago

Ah, I should have been more specific. I'm using the Java.net one. The SDKman "identifier" is 16.0.1-open

alexander-yakushev commented 3 years ago

My hunch was right, this is not really an aarch64-built JDK 😆. It's the x64 version that is run on M1 via Rosetta. I'll investigate the reflection issue, but this won't test the new aarch64 binary of async-profiler.

alexander-yakushev commented 3 years ago

@samrat Wait, I just understood. This is not related to reflection – starting from JDK9 you must start the JVM with -Djdk.attach.allowAttachSelf flag to be able to use clj-async-profiler. Did it work for you before JDK16? Or did you use JDK8 before?

samrat commented 2 years ago

Sorry for the extremely late reply-- but it does work for me with the flag you mentioned :+1:

alexander-yakushev commented 2 years ago

No problem, thanks for confirming!