eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.28k stars 721 forks source link

Cannot wrap Object.notify() with a JVMTI agent #4069

Open urisimchoni opened 5 years ago

urisimchoni commented 5 years ago

With a JVMTI agent, it's generally possible to replace or wrap native methods using the NativeMethodBind event. When running on OpenJ9, I can't seem to do so for java.lang.Object.notify().

The NativeMethodBind even is invoked whenever a native method is bound to a class. My expectation is that the agent gets a notification for all native method of all loaded classes. However, I don't seem to be getting an event for Object.notify().

The sample project in https://gitlab.com/urisimchoni/agentbind demonstrates the issue - when running with HotSpot/OpenJDK, both Object.notify() and "my" method are detected. When running on OpenJ9/OpenJDK, only "my" method is detected.

My end goal would be to wrap Object.notify() one way or another, in order to detect when it is invoked.

Thanks, Uri.

gacholio commented 5 years ago

notify() is not a JNI native, so NativeMethodBind is cannot be sent for it (the address we'd have to give out for the original native is not JNI-callable, so it could not be wrapped).

It should be possible to wrap the native using native method prefixing instead.

I'll discuss the possibility of fixing this with @DanHeidinga in the new year.