Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [GR-45171] Basic JVMTI infrastructure. #8507

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Mar 4, 2024

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:

  • 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_*).

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 4, 2024
@christianhaeubl christianhaeubl changed the title [GR-45171] Basic JVMTI infrastructure. [WIP] [GR-45171] Basic JVMTI infrastructure. Mar 4, 2024
@graalvmbot graalvmbot force-pushed the chaeubl/GR-45171-v5 branch 3 times, most recently from 24eacfc to 7c63d9a Compare March 5, 2024 10:48
Removed all JVMTI code that uses JNI object handles.
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.

None yet

3 participants