-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
Can't attach to jre/jdk 9 using ByteBuddy #374
Comments
It is expected to not work for a JRE as the required libraries are missing. It is supposed to work for a JDK. What operating system are you using? |
@raphw Windows 10. (Version 10.0.16299.19) About JRE, it should work fine on JRE I think, in JRE 8 you could run byte buddy agent with manually provided tools.jar and added attach.dll to command line or via reflections directly to class loader - ofc you need to choose valid lib/tools for each system etc, but it works fine. So something like this should be possible in JRE 9 too. By somehow loading |
If it was possible to include the attachment module in a JRE, this would be possible but I have never tried that. Could you help me debug this by checking what arguments are provided here: https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/ByteBuddyAgent.java#L423 Could you then try to run https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/Attacher.java with these arguments? I assume an exception is thrown, maybe some folder with spaces that is not escaped correctly. |
And like I said, output is empty: https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/Attacher.java#L56 ugh, that would explain empty output |
The result is communicated using a status code what is the easiest. Status code 1 means: the self attachment failed. |
@raphw I think that it should still print that stractrace and bytebuddy should read it if process failed, as now it is just hard to debug. oh...
So just bad args.length check, probably typo? |
This is unfortunately difficult to implement as Byte Buddy should not print to standard output, this can cause quite some trouble in managed environments. But I agree that it is difficult to debug. The argument check is guarded against a missing argument as Windows translates the missing argument to "null" whereas on Linux, it is translated to an empty string. The check is however overly careful (off by one error). This should however not cause an error. |
@raphw it does, as when 3 args are provided
|
Of course, too late at night. I have fixed the off by one index check what should fix that by the next release. Could you build Byte Buddy and verify the fix, just to make sure it now works? |
@raphw seems to works fine, returned instrumentation instance on jdk 9 |
@raphw also, maybe some argument can be used to provide information if stacktrace should be printed/ignored/saved to some .log file, it would make debugging simple while default behavior will be still this same. |
Unfortunately, the argument is already used by custom instrumentation. It could be done by an additional argument. In general, this does however add some overhead, I wil think about it. |
@raphw
// this reflection hack can be replaced with -Djava.library.path starup argument
System.setProperty("java.library.path", System.getProperty("java.library.path") + ";B:\\Java\\tools\\j8"); // path to where attach.dll is
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
File toolsJar = new File("B:\\Java\\tools\\j8\\tools-min.jar");
Instrumentation instrumentation = ByteBuddyAgent.install(
() -> {
try {
return Accessor.Simple.of(new URLClassLoader(new URL[]{toolsJar.toURI().toURL()}, ClassLoader.getSystemClassLoader()), toolsJar);
}
catch (MalformedURLException e) { throw new InternalError("Can't load tools"); }
});
System.out.println(instrumentation); And it works fine on JRE So something like this can be used to provide instrumentation on JRE - but for library it would require multiple versions for multiple JRE versions are systems. But it should be possible to use this same tools/attach lib for java 6/7/8, I didn't test that tho. But I can't do this same for JRE 9 yet, as now there are that modules... and even if I try to run custom Attacher with manually provided modules for attach (only So maybe you know something more about java 9 and how it can be done. |
ByteBuddy agent fails for jdk/jre 9.
For jdk i got:
I tried to debug that code, and all I can see is that process return 1, but I don't see anything in output/error stream of process. But if throw is skipped (via debugger) it still does fail (returns null instead of instrumentation)
For sure it does see my java_home, as I changed command to -version and it does work fine.
For JRE I got:
I used 1.7.9 version of ByteBuddy agent
The text was updated successfully, but these errors were encountered: