byte-buddy
byte-buddy copied to clipboard
Graal support - reflection and runtime loading
Add support for running Byte Buddy on Graal native image by offering a runtime mode where generated classes are cached in a location and retreived in a different runtime mode such that no runtime code generation needs to take place.
The final API should ideally not require any changes to make it automatically applicable for any Byte Buddy user, direct or indirect.
Also, files for required reflection should be added as a convenience to support the runtime.
Probably the target milestone is no longer valid. Do you mind changing it or removing it altogether?
I abuse the field to note the report version. Sorry for the confusion.
Hi Rafael,
I was also looking for a similar solution, as we are having a lot of Mockito tests that we are trying to run with Graal's new JUnit native support. Mockito uses ByteBuddy to generate classes at runtime. So, I found this issue here.
Investigating further, I saw that dynamic class loading is a PR in the Graal project that has recently been merged:
https://github.com/oracle/graal/pull/2442
So maybe, ByteBuddy can leverage the upcoming functionality of Graal to realize this feature. What do you think?
Interesting. This would require that the default naming strategy is deterministic what is certainly possible, but it would likely also require reflection to work but this should be picked up by the agent. I will certainly look into this!
Byte Buddy can now kind of work with this, as long as class names are deterministic. There are still some rough edges but we are moving forward, at least!
@raphw Pretty awesome to see this working out of the box if collecting predefined classes using an agent run 🎉
Though, I noticed predefined classes are not collected if the dynamic type is loaded using ClassLoadingStrategy.UsingLookup.of(MethodHandles$Lookup)
. Is there any way to get this to work or continue using the old INJECTION strategy on Java 11 with the GraalVM agent?
This would be a bug in Graal if so. Byte Buddy only adjiusts its default class naming strategy to work with the Graal agent out of the box. It's Graal that is responsible of collecting class files.
Thanks @raphw! In deed, classes injected into the system class loader are skipped (https://github.com/oracle/graal/issues/4248). Unfortunately, that's what will typically happen when defining a class using a lookup :/