I am trying to use the Attach tools within a native image, but down the road the implementation causes an exception because of missing support in sun.misc.Perf:
java.lang.UnsatisfiedLinkError: sun.misc.Perf.attach(Ljava/lang/String;II)Ljava/nio/ByteBuffer; [symbol: Java_sun_misc_Perf_attach or Java_sun_misc_Perf_attach__Ljava_lang_String_2II]
at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
at sun.misc.Perf.attach(Perf.java)
at sun.misc.Perf.attachImpl(Perf.java:270)
at sun.misc.Perf.attach(Perf.java:200)
at sun.jvmstat.perfdata.monitor.protocol.local.PerfDataBuffer.<init>(PerfDataBuffer.java:64)
at sun.jvmstat.perfdata.monitor.protocol.local.LocalMonitoredVm.<init>(LocalMonitoredVm.java:68)
at
sun.jvmstat.perfdata.monitor.protocol.local.MonitoredHostProvider.getMonitoredVm(MonitoredHostProvider.java:27)
at sun.tools.attach.HotSpotAttachProvider.listVirtualMachines(HotSpotAttachProvider.java:101)
at com.sun.tools.attach.VirtualMachine.list(VirtualMachine.java:147)
at org.test.tools.VirtualMachineTest.main(VirtualMachineTest.java:17)
It would be awesome if support for this could be added to SVM.
Are you planning on attaching to a full JVM (HotSpot)? Supporting sun.misc.Perf might not be sufficient for that on its own. If you're trying to attach to a native image, I doubt that we currently support the required interfaces.
@peter-hofer I am trying to attach to a regular HotSpot JVM. I don't know whether support for sun.misc.Perf is enough to support that case, this is just how far I got up to now in my experiments.
And yes, I am aware that native images don't support any of these mechanisms yet, but since I don't want to attach to a native image, that is fine for me... :-)
It looks like sun.misc.Perf is implemented in HotSpot itself and uses shared memory with knowledge about internal data structures. I don't think this is very high-priority at the moment.
@thurka informed me that we do have some code for that in GraalVM Enterprise Edition and support for sun.misc.Perf will eventually be added.
On the note of trying to use the Attach API, there is this multi-platform C-based project jattach. May be it can be used / adapted for use via JNI / JNA / etc. to work with native-image?
With the native-image C interface, that is a certainly possible!
Most helpful comment
@thurka informed me that we do have some code for that in GraalVM Enterprise Edition and support for
sun.misc.Perfwill eventually be added.