Skip to content

Add JNI registration Attach API #11199

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dev-jonghoonpark
Copy link

related issue: #11103

I resolved an issue where using the attach method in an application built with native-image resulted in the error:
java.lang.UnsatisfiedLinkError: Can't load library: attach


Additionally, during implementation, I discovered that in applications built with native-image, VirtualMachine.list() returns an empty list.
(This was not addressed in this PR.)

Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label May 14, 2025
Signed-off-by: jonghoonpark <[email protected]>
@dev-jonghoonpark dev-jonghoonpark force-pushed the add-attach-jni-library branch from 142ea03 to ff384ab Compare May 14, 2025 16:00
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels May 15, 2025
@roberttoyonaga
Copy link
Collaborator

I tested out and the funcitonality seems to be working. I used this procedure:

  1. Build your branch
  2. javac SimpleShortAttachClient.java
  3. mx native-unittest SimpleShortAttachClient
  4. java -m jdk.httpserver (In another terminal)
  5. jcmd and find the PID of jdk.httpserver
  6. jcmd PID ManagementAgent.status verify the management agent is off
  7. ./simpleshortattachclient PID (This should cause the Native Image binary to attach and start the management agent in the other JVM)
  8. jcmd PID ManagementAgent.status verify the management agent is on
$ jcmd
2205600 org.jetbrains.idea.maven.server.RemoteMavenServer36
2225971 jdk.httpserver
2125315 com.intellij.idea.Main
2225998 jdk.jcmd/sun.tools.jcmd.JCmd

$ jcmd  2225971 ManagementAgent.status
2225971:
Agent: disabled

$ ./simpleshortattachclient 2225971
PID.. 2226067
{sun.java.command=jdk.httpserver, sun.jvm.flags=, sun.jvm.args=-Djdk.module.main=jdk.httpserver}
{sun.java.command=jdk.httpserver, sun.jvm.flags=, sun.jvm.args=-Djdk.module.main=jdk.httpserver}


$ jcmd  2225971 ManagementAgent.status
2225971:
Agent: enabled

Connection Type: remote
Protocol       : rmi
...

@dev-jonghoonpark
Copy link
Author

Thank you for sharing the detailed testing procedure.
I also used a similar approach during my development.

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.

2 participants