Skip to content

Conversation

graalvmbot
Copy link
Collaborator

This PR adds basic JVM Tool Interface (JVM TI) support to Native Image so that JVM TI agents can be used at run-time:

  • If JVMTI should be used at run-time, it needs to be be enabled during the image build with -H:+JVMTI.
  • When running a native executable that was built with JVM TI support, an agent can then be attached to the native executable with -XX:JVMTIAgentLib=... or -XX:JVMTIAgentPath=... (similar to -agentlib:... and -agentpath:... on HotSpot).

Restrictions:

  • only a single agent is supported at the moment
  • only the following JVM TI functions are supported at the moment
    • Allocate
    • Deallocate
    • ForceGarbageCollection
    • SetEventCallbacks
    • SetEventNotificationMode
    • GetPotentialCapabilities
    • GetCapabilities
    • AddCapabilities
    • RelinquishCapabilities
    • GetTime
    • GetPhase (only returns JVMTI_PHASE_LIVE and JVMTI_PHASE_DEAD)
    • DisposeEnvironment
    • GetVersionNumber
    • GetErrorName
  • only the following JVM TI events are supported at the moment
    • JVMTI_EVENT_VM_INIT
    • JVMTI_EVENT_VM_START
    • JVMTI_EVENT_VM_DEATH
  • no JVM TI capabilities are supported at the moment

Open for discussions:

  • At the moment, Native Image calls Agent_OnLoad after VM startup (i.e., some Java code may already have been executed at this point). This does not really match with the JVM TI specification. The alternative would be to call Agent_OnAttach instead.
  • Native Image triggers the events JVMTI_EVENT_VM_INIT and JVMTI_EVENT_VM_START directly after invoking Agent_OnLoad.

Open issues (won't be addressed for now):

  • The JNI implementation in Native Image allocates Java heap memory at the moment (especially for object handles). This needs to be changed before more complex functionality can be implemented (i.e., native memory needs to be used instead). Otherwise, it is impossible to implement certain JVM TI events (e.g., JVMTI_EVENT_RESOURCE_EXHAUSTED, JVMTI_EVENT_GARBAGE_COLLECTION_*).

Where to start reviewing:

  • build-time logic: JvmtiFeature and JvmtiFunctionTable
  • run-time entrypoints: methods annotated with @CEntryPoint in JvmtiFunctions

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 23, 2024
Removed all JVMTI code that uses JNI object handles.
@graalvmbot graalvmbot closed this Sep 11, 2024
@graalvmbot graalvmbot deleted the chaeubl/GR-45171-v6 branch September 11, 2024 00:52
@graalvmbot graalvmbot merged commit 59a07aa into master Sep 11, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants