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

spring-loaded doesn't work with JVMCI #184

Merged
merged 2 commits into from Nov 29, 2017

Conversation

jtulach
Copy link
Contributor

@jtulach jtulach commented Nov 24, 2016

Java Virtual Machine Compiler Interface is coming to JDK. It has already been integrated into JDK9 and there are backports to JDK8 as well (download from OTN). However the spring-loaded project doesn't work with the JVMCI builds. Download the JVMCI JDK and try:

 ~/bin/labs1.8.0/bin/java -XX:+BootstrapJVMCI -XX:+UseJVMCICompiler -javaagent:springloaded-1.2.6.RELEASE.jar -noverify -version
Bootstrapping JVMCIjava.lang.NoClassDefFoundError: org/springsource/loaded/ri/ReflectiveInterceptor
        at jdk.vm.ci.hotspot.UnsafeAccess.initUnsafe(UnsafeAccess.java:43)
        at jdk.vm.ci.hotspot.UnsafeAccess.<clinit>(UnsafeAccess.java:34)
        at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.getHolder(HotSpotResolvedJavaMethodImpl.java:87)
        at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.fromMetaspace(HotSpotResolvedJavaMethodImpl.java:104)

This pull request fixes the problem by not creating a TypeRegistry for classloaders that don't see the application class path like JVMCI classloader & co.

@jtulach
Copy link
Contributor Author

jtulach commented Nov 24, 2017

I've created this PR a year ago and there hasn't been a single reply! That is partially explainable as I was asking people to download a special JDK - however the situation is different today. As @chrisseaton wrote in his Understanding How Graal Works - the Graal compiler is part of standard JDK9. I hope that might increase your motivation to accept my fix.

@jtulach
Copy link
Contributor Author

jtulach commented Nov 24, 2017

To reproduce: get JDK9, my version is:

$ /usr/lib/jvm/java-9-oracle/bin/java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

and run any long running computation with springloaded.jar agent and following options: -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler. For my own testing purposes I used the Sieve of Eratosthenes, but any other long running application will do. If I run with 1.2.6-RELEASE agent, I get bunch of exceptions from the Graal compiler (as it is using completely isolated classloaders that don't see the agent classes):

$ /usr/lib/jvm/java-9-oracle/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.PrintCompilation=true -javaagent:/springloaded-1.2.6/springloaded.jar -Xverify:none -jar java/algorithm/target/sieve-algorithm-1.0-SNAPSHOT.jar
Computed 97 primes in 1 ms. Last one is 509
Computed 194 primes in 1 ms. Last one is 1181
Computed 388 primes in 2 ms. Last one is 2677
Computed 776 primes in 2 ms. Last one is 5897
Computed 1552 primes in 3 ms. Last one is 13033
Computed 3104 primes in 4 ms. Last one is 28541
Computed 6208 primes in 7 ms. Last one is 61687
Computed 12416 primes in 14 ms. Last one is 133033
Computed 24832 primes in 36 ms. Last one is 284831
Nov 24, 2017 5:13:51 PM org.springsource.loaded.agent.SpringLoadedPreProcessor preProcess
SEVERE: Unexpected problem transforming call sites
java.lang.IllegalArgumentException
        at sl.org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at sl.org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.springsource.loaded.MethodInvokerRewriter.rewrite(MethodInvokerRewriter.java:345)
        at org.springsource.loaded.MethodInvokerRewriter.rewrite(MethodInvokerRewriter.java:99)
        at org.springsource.loaded.TypeRegistry.methodCallRewriteUseCacheIfAvailable(TypeRegistry.java:1002)
        at org.springsource.loaded.agent.SpringLoadedPreProcessor.preProcess(SpringLoadedPreProcessor.java:361)
        at org.springsource.loaded.agent.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:107)
        at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
        at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
        at java.base/java.lang.ClassLoader.defineClass2(Native Method)

with my patch, I can successfully execute the same command and even see that the Graal compiler does its compilations:

$ /usr/lib/jvm/java-9-oracle/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.PrintCompilation=true -javaagent:/spring-loaded/springloaded/build/libs/springloaded-1.2.9.BUILD-SNAPSHOT.jar -Xverify:none -jar java/algorithm/target/sieve-algorithm-1.0-SNAPSHOT.jar 
134    JVMCI Ljava/lang/StringLatin1;                                               hashCode                                      ([B)I                                              (OSR@10) ...
135    JVMCI Ljava/lang/String;                                                     coder                                         ()B                                                ...
Computed 49664 primes in 104 ms. Last one is 607417
135    JVMCI                                                                                                                                                                         |  334ms    15B    63B 10171kB
468    JVMCI Lorg/apidesign/demo/sieve/eratosthenes/Filter;                         acceptAndAdd                                  (I)Z                                               ...
134    JVMCI                                                                                                                                                                         |  345ms    42B   314B  9823kB
419    JVMCI Ljdk/internal/jimage/ImageStringsReader;                               unmaskedHashCode                              (Ljava/lang/String;I)I                          

Does it make sense to integrate my bugfix now?

@aclement
Copy link
Contributor

Just before I do, have you signed the CLA? https://cla.pivotal.io/sign/pivotal/icla

…cation class path like JVMCI classloader & co.
@jtulach
Copy link
Contributor Author

jtulach commented Nov 29, 2017

Hello Andy, I've just signed the CLA with my apidesign.org address. I hope my PR is now in acceptable state to be merged.

@aclement
Copy link
Contributor

Thanks for confirming, and contributing!

@aclement aclement merged commit d6555bf into spring-projects:master Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants