diff --git a/asm/README.md b/asm/README.md new file mode 100644 index 0000000..573a16e --- /dev/null +++ b/asm/README.md @@ -0,0 +1,54 @@ +Related issue on GraalVM bugtracker: [graal#999](https://github.com/oracle/graal/issues/999). + +Here's the app that is broken: + +``` +public class App { + + public static void main(String[] args) throws Exception { + System.err.println(AnnotationUtils + .findAnnotation(Config.class, ConfigurationProperties.class).value()); + } + +} +``` + +In a normal JVM: + +``` +$ java -jar target/config-props-1.0-SNAPSHOT.jar +... +app +``` + +Breaks on native image compilation: + +``` +[target/demo:25999] classlist: 1,774.59 ms +[target/demo:25999] (cap): 780.59 ms +[target/demo:25999] setup: 1,778.58 ms +Warning: class initialization of class org.apache.commons.logging.LogAdapter$Log4jLog failed with exception java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager. This class will be initialized at run time because either option --report-unsupported-elements-at-runtime or option --allow-incomplete-classpath is used for image building. Use the option --delay-class-initialization-to-runtime=org.apache.commons.logging.LogAdapter$Log4jLog to explicitly request delayed initialization of this class. +[target/demo:25999] analysis: 3,883.40 ms +Fatal error: java.lang.NullPointerException + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598) + at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005) + at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:427) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:285) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:407) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:106) +Caused by: java.lang.NullPointerException + at com.oracle.svm.hosted.code.CFunctionSubstitutionProcessor.lookup(CFunctionSubstitutionProcessor.java:44) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:389) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:369) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:73) + at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaMethod(UniverseMetaAccess.java:99) + at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:66) +... +``` \ No newline at end of file diff --git a/asm/build.sh b/asm/build.sh new file mode 100755 index 0000000..66e4950 --- /dev/null +++ b/asm/build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mvn clean install +native-image --no-server -H:Name=target/demo -H:ReflectionConfigurationFiles=config.json \ + -H:IncludeResources='META-INF/spring.factories|application.properties|com/sample/.*' \ + --report-unsupported-elements-at-runtime --allow-incomplete-classpath \ + -H:DynamicProxyConfigurationFiles=proxy.json \ + -cp target/asm-1.0-SNAPSHOT.jar com.sample.App + +echo "In regular JVM" +java -jar target/asm-1.0-SNAPSHOT.jar +echo "" +echo "As GraalVM native image" +./target/demo diff --git a/asm/config.json b/asm/config.json new file mode 100644 index 0000000..69032c6 --- /dev/null +++ b/asm/config.json @@ -0,0 +1,14 @@ +[ + { + "name": "com.sample.ConfigurationProperties", + "allDeclaredConstructors": true, + "allDeclaredFields": true, + "allPublicMethods": true + }, + { + "name": "com.sample.Config", + "allDeclaredConstructors": true, + "allDeclaredFields": true, + "allPublicMethods": true + } +] diff --git a/asm/pom.xml b/asm/pom.xml new file mode 100644 index 0000000..7fb7711 --- /dev/null +++ b/asm/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + com.sample + asm + 1.0-SNAPSHOT + + asm + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework + spring-core + 5.1.3.RELEASE + + + + + + + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + com.sample.App + + + true + true + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + true + true + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + diff --git a/asm/proxy.json b/asm/proxy.json new file mode 100644 index 0000000..3a7dc84 --- /dev/null +++ b/asm/proxy.json @@ -0,0 +1,4 @@ +[ + + ["com.sample.ConfigurationProperties"] +] \ No newline at end of file diff --git a/asm/src/main/java/com/sample/App.java b/asm/src/main/java/com/sample/App.java new file mode 100644 index 0000000..62453ef --- /dev/null +++ b/asm/src/main/java/com/sample/App.java @@ -0,0 +1,58 @@ +package com.sample; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; + +public class App { + + public static void main(String[] args) throws Exception { + System.err.println( + Config.class.getAnnotation(ConfigurationProperties.class).value()); + SimpleMetadataReaderFactory factory = new SimpleMetadataReaderFactory(); + MetadataReader reader = factory.getMetadataReader(Config.class.getName()); + System.err.println(reader.getAnnotationMetadata() + .hasAnnotation(ConfigurationProperties.class.getName())); + } + +} + +class Interceptor implements InvocationHandler { + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return "blah"; + } + +} + +@ConfigurationProperties("app") +class Config { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} + +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@interface ConfigurationProperties { + + String value() default ""; + +} \ No newline at end of file diff --git a/java-util-logging/build.sh b/java-util-logging/build.sh index f284b7d..76ea841 100755 --- a/java-util-logging/build.sh +++ b/java-util-logging/build.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash mvn clean install -native-image -cp target/classes com.sample.App +native-image --no-server -cp target/classes com.sample.App echo "In regular JVM" java -cp target/classes com.sample.App echo "As GraalVM native image" -./com.sample.app \ No newline at end of file +./demo diff --git a/java-util-logging/demo b/java-util-logging/demo new file mode 100755 index 0000000..e17e03a Binary files /dev/null and b/java-util-logging/demo differ diff --git a/java-util-logging/src/main/resources/META-INF/native-image/com.example/app/native-image.properties b/java-util-logging/src/main/resources/META-INF/native-image/com.example/app/native-image.properties new file mode 100644 index 0000000..04dd3a4 --- /dev/null +++ b/java-util-logging/src/main/resources/META-INF/native-image/com.example/app/native-image.properties @@ -0,0 +1 @@ +ImageName = demo diff --git a/property-descriptor/README.md b/property-descriptor/README.md new file mode 100644 index 0000000..573a16e --- /dev/null +++ b/property-descriptor/README.md @@ -0,0 +1,54 @@ +Related issue on GraalVM bugtracker: [graal#999](https://github.com/oracle/graal/issues/999). + +Here's the app that is broken: + +``` +public class App { + + public static void main(String[] args) throws Exception { + System.err.println(AnnotationUtils + .findAnnotation(Config.class, ConfigurationProperties.class).value()); + } + +} +``` + +In a normal JVM: + +``` +$ java -jar target/config-props-1.0-SNAPSHOT.jar +... +app +``` + +Breaks on native image compilation: + +``` +[target/demo:25999] classlist: 1,774.59 ms +[target/demo:25999] (cap): 780.59 ms +[target/demo:25999] setup: 1,778.58 ms +Warning: class initialization of class org.apache.commons.logging.LogAdapter$Log4jLog failed with exception java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager. This class will be initialized at run time because either option --report-unsupported-elements-at-runtime or option --allow-incomplete-classpath is used for image building. Use the option --delay-class-initialization-to-runtime=org.apache.commons.logging.LogAdapter$Log4jLog to explicitly request delayed initialization of this class. +[target/demo:25999] analysis: 3,883.40 ms +Fatal error: java.lang.NullPointerException + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598) + at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005) + at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:427) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:285) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:407) + at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:106) +Caused by: java.lang.NullPointerException + at com.oracle.svm.hosted.code.CFunctionSubstitutionProcessor.lookup(CFunctionSubstitutionProcessor.java:44) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:389) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:369) + at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:73) + at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaMethod(UniverseMetaAccess.java:99) + at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:66) +... +``` \ No newline at end of file diff --git a/property-descriptor/build.sh b/property-descriptor/build.sh new file mode 100755 index 0000000..0646dd6 --- /dev/null +++ b/property-descriptor/build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mvn clean install +native-image --no-server -H:Name=target/demo -H:ReflectionConfigurationFiles=config.json \ + -H:IncludeResources='META-INF/spring.factories|application.properties|com/sample/.*' \ + --report-unsupported-elements-at-runtime --allow-incomplete-classpath \ + -H:DynamicProxyConfigurationFiles=proxy.json \ + -cp target/property-descriptor-1.0-SNAPSHOT.jar com.sample.App + +echo "In regular JVM" +java -jar target/property-descriptor-1.0-SNAPSHOT.jar +echo "" +echo "As GraalVM native image" +./target/demo diff --git a/property-descriptor/config.json b/property-descriptor/config.json new file mode 100644 index 0000000..48ed208 --- /dev/null +++ b/property-descriptor/config.json @@ -0,0 +1,11 @@ +[ + { + "name": "com.sample.Bar", + "allDeclaredConstructors": true, + "allDeclaredFields": true, + "allPublicMethods": true + }, + { + "name": "java.util.List" + } +] diff --git a/property-descriptor/pom.xml b/property-descriptor/pom.xml new file mode 100644 index 0000000..a49502f --- /dev/null +++ b/property-descriptor/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + com.sample + property-descriptor + 1.0-SNAPSHOT + + property-descriptor + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework + spring-core + 5.1.3.RELEASE + + + + + + + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + com.sample.App + + + true + true + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + true + true + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + diff --git a/property-descriptor/proxy.json b/property-descriptor/proxy.json new file mode 100644 index 0000000..32960f8 --- /dev/null +++ b/property-descriptor/proxy.json @@ -0,0 +1,2 @@ +[ +] \ No newline at end of file diff --git a/property-descriptor/src/main/java/com/sample/App.java b/property-descriptor/src/main/java/com/sample/App.java new file mode 100644 index 0000000..dba1fe1 --- /dev/null +++ b/property-descriptor/src/main/java/com/sample/App.java @@ -0,0 +1,55 @@ +package com.sample; + +import java.beans.PropertyDescriptor; +import java.util.List; + +public class App { + + public void setBar(Bar bar) { + } + + public void setConverters(List converters) { + } + + public static void main(String[] args) throws Exception { + new App().run(); + } + + private void run() throws Exception { + PropertyDescriptor[] pds = new PropertyDescriptor[] { + new PropertyDescriptor("bar", null, + App.class.getMethod("setBar", Bar.class)), + new PropertyDescriptor("converters", null, + App.class.getMethod("setConverters", List.class)) }; + for (PropertyDescriptor pd : pds) { + System.err.println("Property: " + pd); + } + } + +} + +class Bar { + + private String value; + + public Bar() { + } + + public Bar(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return "Foo [value=" + this.value + "]"; + } + +} \ No newline at end of file