-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support dynamic class loading and serialization #2323
Conversation
955abc5
to
ad767fe
Compare
f6bdf5e
to
d508fa5
Compare
Can this be updated? It also only supports java8 so can java11 be included? I tried to get it working locally but I don't know enough of both java & graal internals to manage setting it up myself. |
It seems many classes have changed since I committed last time. I will update the commit. The development and testing of this PR are all based on JDK8. We didn't check if it works with JDK11. |
If it helps, this is a patch of what I ended up with. However it crashes the agent at runtime, i just don't know why. https://we.tl/t-rxorTEeQs2 |
1.Dump dynamically defined classes to file system (specified by -agentlib:native-image-agent=dynmaic-class-dump-dir=) by Agent at a beforehand run and the dumped class files must be on build time's classpath to compile them into native-image. 2.Dynamically generated class's name could be decided at runtime(e.g. runtime serial number as postfix) or null when defineClass is invoked. The former is supported by using same rule to generate fixed names for both Agent runtime and native-image runtime. The latter is supported by retrieving class name from dumped class bytecode at native-image runtime. 3.Support JDK serialization/deserialization which replies on dynamic class loading and reflection. Known issue: 1.Don't support serialize proxied class, because the proxy class name differs at Agent runtime and native-image build time. 2.It is possible the jar file on classpath has a different signature file from dynamically generated class'. Current solution is to delete the signature file at native-image build time. 3.Warning message such as "WARNING: Method java.lang.Object.<clinit>() not found." will be reported at native-image build time. Because such method has been accessed via JNI calls at serialization time to calculate serializeVersionUID and the Agent has intercepted and recorded them.
d508fa5
to
b0fbdd5
Compare
@kristofdho I have updated the PR to the lastest commit(fd11c68) on master branch. |
I greatly support this PR and I believe it is quite important to get this right--thank you very much! This PR introduces two distinct features: (1) support for dynamic class loading and (2) serialization. In order to get this right, I propose that we merge dynamic class loading and serialization |
I committed this PR as one patch because it was started to solve the serialization requirement at the very beginning, and the serial tests in SPECjvm2008 were choosen to test the correctness. It makes sense to seperate this patch into two, but may need to prepare extra tests for dynamic class loading. Should I start two new PRs for each feature or modify this one to dynamic class loading and start a new for serialization? |
Biggest issue i have with this, is after adding the .class files to my jar, I get the following exception during image building: This probably has something to do with the module system in java11 and I can't figure out how to work around that. Edit: I seem to be able to get around it by adding |
It does not support JDK11 yet. Not only module, but also runtime behaviors are different. Can you try on JDK 8 if possible? |
My project is in java 11 so sadly no, cannot try it on 8. What I'm using locally is a modified version to include java 11 based on this. Basically add the package switching between It would be great if java 11 could be included in this, or if you know what has to change I can try to do it myself. |
You need to check the JDK methods required for serialization in JDK11 and provide proper substitutions. |
We should open start a separate PR for this and add a few basic tests. I have a few minor comments, but I can put them on that PR. |
I'll start this work next week. |
That is what I ment with "the package switching between |
substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java
Show resolved
Hide resolved
Started a new PR for dynamic class loading only: #2442 |
This patch provides supports for dynamic class loading and serialization/deserialization features for substratevm.
Overview
The basic idea for supporting dynamic class loading is dumping classes generated at run time in a beforehand run with native-image-agent to a specified directory which is added to the classpath to build native-image. Serialization/deserialization is basically dynamic class loading + reflection.
This is implemented in 3 steps:
Features:
-agentlib:native-image-agent=dynmaic-class-dump-dir=
to specify where to dump the dynamically generated classs, the default value is "dynClass" if not specified.Limitations:
java.lang.ClassLoader.checkCerts(String name, CodeSource cs)
at native-image build time. Current solution is to delete jar's signature file before building.Tests
We have prepared the
serial
test cases in SPECjvm2008 to test this patch. Simply unzip specjvm2008-for-serial.zip, change $GRAALVM_HOME to your GraalVM home and runThe script builds and runs
spec.benchmarks.serial.Main
in SPECjvm2008."TestProxy" was excluded from the
serial
tests because of the 1st limitation mentioned above.Dependency
This patch depends on PR #2322