Skip to content

Commit

Permalink
Add a couple of new samples
Browse files Browse the repository at this point in the history
property-descriptor -> oracle/graal#522

asm -> test if asm can be used to inspect class files

Both of them work, but they maybe can be tweaked to require less
manual configuration.
  • Loading branch information
Dave Syer committed Apr 1, 2019
1 parent b07f814 commit d07c7a2
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 2 deletions.
54 changes: 54 additions & 0 deletions asm/README.md
Original file line number Diff line number Diff line change
@@ -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)
...
```
14 changes: 14 additions & 0 deletions asm/build.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions asm/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "com.sample.ConfigurationProperties",
"allDeclaredConstructors": true,
"allDeclaredFields": true,
"allPublicMethods": true
},
{
"name": "com.sample.Config",
"allDeclaredConstructors": true,
"allDeclaredFields": true,
"allPublicMethods": true
}
]
81 changes: 81 additions & 0 deletions asm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.sample</groupId>
<artifactId>asm</artifactId>
<version>1.0-SNAPSHOT</version>

<name>asm</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.sample.App</mainClass>
</transformer>
</transformers>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>

</project>
4 changes: 4 additions & 0 deletions asm/proxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[

["com.sample.ConfigurationProperties"]
]
58 changes: 58 additions & 0 deletions asm/src/main/java/com/sample/App.java
Original file line number Diff line number Diff line change
@@ -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 "";

}
4 changes: 2 additions & 2 deletions java-util-logging/build.sh
Original file line number Diff line number Diff line change
@@ -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
./demo
Binary file added java-util-logging/demo
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ImageName = demo
54 changes: 54 additions & 0 deletions property-descriptor/README.md
Original file line number Diff line number Diff line change
@@ -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)
...
```
14 changes: 14 additions & 0 deletions property-descriptor/build.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions property-descriptor/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"name": "com.sample.Bar",
"allDeclaredConstructors": true,
"allDeclaredFields": true,
"allPublicMethods": true
},
{
"name": "java.util.List"
}
]
Loading

0 comments on commit d07c7a2

Please sign in to comment.