Skip to content

Commit

Permalink
Merge pull request #6 from GoodforGod/dev
Browse files Browse the repository at this point in the history
[0.18.0]
  • Loading branch information
GoodforGod authored Apr 13, 2022
2 parents ee0f989 + 2d6d2d9 commit 3a91d95
Show file tree
Hide file tree
Showing 65 changed files with 1,364 additions and 525 deletions.
155 changes: 117 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features:
- Generate Resource Hints ([resource-config.json](#resourcehint))
- Generate Options hints ([native-image.properties](#nativeimagehint))
- Generate Initialization Hints ([native-image.properties](#initializationhint))
- Generate Dynamic Proxy Hints ([dynamic-proxy-hint.json](#dynamicproxyhint))
- Generate JNI Hints ([jni-config.json](#jnihint))

## Dependency :rocket:
Expand All @@ -23,8 +24,8 @@ Java 11+ is supported.

[**Gradle**](https://mvnrepository.com/artifact/io.goodforgod/graalvm-hint-processor)
```groovy
annotationProcessor "io.goodforgod:graalvm-hint-processor:0.17.1"
compilyOnly "io.goodforgod:graalvm-hint-annotations:0.17.1"
annotationProcessor "io.goodforgod:graalvm-hint-processor:0.18.0"
compilyOnly "io.goodforgod:graalvm-hint-annotations:0.18.0"
```

[**Maven**](https://mvnrepository.com/artifact/io.goodforgod/graalvm-hint-processor)
Expand All @@ -33,14 +34,14 @@ compilyOnly "io.goodforgod:graalvm-hint-annotations:0.17.1"
<dependency>
<groupId>io.goodforgod</groupId>
<artifactId>graalvm-hint-annotations</artifactId>
<version>0.17.1</version>
<version>0.18.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.goodforgod</groupId>
<artifactId>graalvm-hint-processor</artifactId>
<version>0.17.1</version>
<version>0.18.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -58,7 +59,7 @@ compilyOnly "io.goodforgod:graalvm-hint-annotations:0.17.1"
<path>
<groupId>io.goodforgod</groupId>
<artifactId>graalvm-hint-processor</artifactId>
<version>0.17.1</version>
<version>0.18.0</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand All @@ -67,13 +68,9 @@ compilyOnly "io.goodforgod:graalvm-hint-annotations:0.17.1"
</build>
```

## Examples
## ReflectionHint

Below are illustrated examples for usage of such library.

### ReflectionHint

You can read more about GraalVM reflection configuration [here](https://www.graalvm.org/reference-manual/native-image/Reflection/).
You can read more about GraalVM reflection configuration [in official documentation here](https://www.graalvm.org/reference-manual/native-image/Reflection/).

There are available access hints:
- allPublicFields
Expand All @@ -94,7 +91,7 @@ public class RequestOnly {
}
```

Generated reflection config:
Generated *reflection-config.json*:
```json
[{
"name": "io.goodforgod.graalvm.hint.processor.RequestOnly",
Expand All @@ -116,7 +113,7 @@ public class ReflectionConfig {
}
```

Resulted reflection-config.json:
Generated *reflection-config.json*:
```json
[{
"name": "io.goodforgod.graalvm.hint.processor",
Expand All @@ -134,34 +131,73 @@ Resulted reflection-config.json:
}]
```

### ResourceHint
## ResourceHint

You can read more about GraalVM resource configuration [in official documentation here](https://www.graalvm.org/reference-manual/native-image/Resources/).

Hint allows generating config for resource files to be included/excluded when building native application.
You can also include bundles into native image using this Hint.

Include Hint:
```java
@ResourceHint(include = { "simplelogger.properties", "application.yml", "*.xml" })
public class ResourceNames {

You can read more about GraalVM resource configuration [here](https://www.graalvm.org/reference-manual/native-image/Resources/).
}
```

Hint allows generating config for resource files to include into native application.
Generated *resource-config.json*:
```json
{
"resources": {
"includes": [
{ "pattern" : "*.xml" },
{ "pattern": "application.yml" },
{ "pattern": "simplelogger.properties" }
]
}
}
```

Exclude Hint:
```java
@ResourceHint(exclude = { "*.xml" })
public class ResourceNames {

}
```

Generated *resource-config.json*:
```json
{
"resources": {
"excludes": [
{ "pattern": "*.xml" }
]
}
}
```

Hint configuration:
Bundle Hint:
```java
@ResourceHint(patterns = { "simplelogger.properties", "application.yml", "*.xml" })
@ResourceHint(bundles = { "your.pkg.Bundle" })
public class ResourceNames {

}
```

Resulted resource-config.json:
Generated *resource-config.json*:
```json
{
"resources": [
{ "pattern" : "*.xml" },
{ "pattern" : "application.yml" },
{ "pattern" : "simplelogger.properties" }
"bundles": [
{ "name": "your.pkg.Bundle" }
]
}
```

### NativeImageHint
## NativeImageHint

You can read more about GraalVM native-image options [here](https://www.graalvm.org/reference-manual/native-image/Options/).
You can read more about GraalVM native-image options [in official documentation here](https://www.graalvm.org/reference-manual/native-image/Options/).

Hint allows generating config for native-image options and initial application entrypoint.

Expand All @@ -174,7 +210,7 @@ public class EntrypointOnly {
}
```

Resulted native-image.properties:
Generated *native-image.properties*:
```properties
Args = -H:Class=io.goodforgod.graalvm.hint.processor.EntrypointOnly
```
Expand All @@ -188,16 +224,16 @@ public class Entrypoint {
}
```

Resulted native-image.properties:
Generated *native-image.properties*:
```properties
Args = -H:Name=myapp -H:Class=io.goodforgod.graalvm.hint.processor.Entrypoint \
Args = -H:Class=io.goodforgod.graalvm.hint.processor.Entrypoint -H:Name=myapp \
-H:+PrintClassInitialization \
-H:+InlineBeforeAnalysis
```

### InitializationHint
## InitializationHint

You can read more about GraalVM initialization configuration [here](https://www.graalvm.org/reference-manual/native-image/ClassInitialization/).
You can read more about GraalVM initialization configuration [in official documentation here](https://www.graalvm.org/reference-manual/native-image/ClassInitialization/).

Hint allows generating config for what classes to instantiate in runtime and what classes to instantiate in compile time.

Expand All @@ -210,9 +246,9 @@ public class EntrypointOnly {
}
```

Resulted native-image.properties:
Generated *native-image.properties*:
```properties
Args = --initialize-at-build-time=io.goodforgod.graalvm.hint.processor.HintOptions.class \
Args = --initialize-at-build-time=io.goodforgod.graalvm.hint.processor.HintOrigin.class \
--initialize-at-run-time=io.goodforgod.graalvm.hint.processor
```

Expand All @@ -227,16 +263,59 @@ public class Entrypoint {
}
```

Resulted native-image.properties:
Generated *native-image.properties*:
```properties
Args = -H:Class=io.goodforgod.graalvm.hint.processor.Entrypoint \
--initialize-at-build-time=io.goodforgod.graalvm.hint.processor.HintOptions.class \
--initialize-at-build-time=io.goodforgod.graalvm.hint.processor.HintOrigin.class \
--initialize-at-run-time=io.goodforgod.graalvm.hint.processor
```

### JniHint
## DynamicProxyHint

You can read more about GraalVM DynamicProxyHint configuration [in official documentation here](https://www.graalvm.org/reference-manual/native-image/DynamicProxy/).

Use can pass dynamic proxy resources (*-H:DynamicProxyConfigurationResources*) or files (*-H:DynamicProxyConfigurationFiles*) using corresponding options:
```java
@DynamicProxyHint(resources = {"proxy-resource.json"}, files = {"proxy-file.json"})
public class Resource {

}
```

Generated *native-image.properties*:
```properties
Args = -H:DynamicProxyConfigurationFiles=proxy-file.json \
-H:DynamicProxyConfigurationResources=proxy-resource.json
```

You can configure files yourself using annotations only without the need for manually creating JSON configurations.

```java
@DynamicProxyHint(value = {
@DynamicProxyHint.Configuration(interfaces = {OptionParser.class, HintOrigin.class}),
@DynamicProxyHint.Configuration(interfaces = {HintOrigin.class})
})
public class Config {

}
```

Generated *dynamic-proxy-hint-config.json*:
```json
[
{ "interfaces": [ "io.goodforgod.graalvm.hint.processor.OptionParser", "io.goodforgod.graalvm.hint.processor.HintOrigin" ] },
{ "interfaces": [ "io.goodforgod.graalvm.hint.processor.HintOrigin" ] }
]
```

Generated *native-image.properties*:
```properties
Args = -H:DynamicProxyConfigurationResources=META-INF/native-image/io.goodforgod.graalvm.hint.processor/hint/dynamic-proxy-config.json
```

## JniHint

You can read more about GraalVM JNI configuration [here](https://www.graalvm.org/reference-manual/native-image/JNI/).
You can read more about GraalVM JNI configuration [in official documentation here](https://www.graalvm.org/reference-manual/native-image/JNI/).

There are available JNI access hints:
- allPublicFields
Expand All @@ -255,7 +334,7 @@ public class RequestOnly {
}
```

Generated JNI config:
Generated *jni-config.json*:
```json
[{
"name": "io.goodforgod.graalvm.hint.processor.RequestOnly",
Expand All @@ -276,7 +355,7 @@ public final class JniConfig {
}
```

Resulted jni-config.json:
Generated *jni-config.json*:
```json
[{
"name": "io.goodforgod.graalvm.hint.processor",
Expand Down
2 changes: 1 addition & 1 deletion graalvm-hint-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publishing {
pom {
name = "GraalVM Hint Annotations"
url = "https://github.com/GoodforGod/$artifactRootId"
description = "GraalVM Hint Annotations helps marking GraalVM hints for GraalVM Hint Processor."
description = "Annotations that help marking GraalVM native-image hints for GraalVM Hint Processor."

license {
name = "Apache License 2.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.goodforgod.graalvm.hint.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Java dynamic proxies, implemented by java.lang.reflect.Proxy, provide a mechanism which enables
* object level access control by routing all method invocations through
* java.lang.reflect.InvocationHandler
*
* @see <a href="https://www.graalvm.org/reference-manual/native-image/DynamicProxy/">GraalVM
* Info</a>
* @author Anton Kurako (GoodforGod)
* @since 07.04.2022
*/
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE })
@Retention(RetentionPolicy.SOURCE)
public @interface DynamicProxyHint {

@Target({})
@Retention(RetentionPolicy.SOURCE)
@interface Configuration {

/**
* @return The interfaces to provide a hint (preferred because typesafe)
*/
Class<?>[] interfaces();
}

/**
* @see <a href=
* "https://www.graalvm.org/22.0/reference-manual/native-image/DynamicProxy/#manual-configuration">GraalVM</a>
* @return Manual configurations for Dynamic proxy
*/
Configuration[] value() default {};

/**
* @return file configs to include under -H:DynamicProxyConfigurationFiles option
*/
String[] files() default {};

/**
* @return resources configs to include under -H:DynamicProxyConfigurationResources option
*/
String[] resources() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public enum NativeImageOptions {
ENABLE_HTTPS("--enable-https"),
ENABLE_URL_PROTOCOLS("--enable-url-protocols"),
ALLOW_INCOMPLETE_CLASSPATH("--allow-incomplete-classpath"),
REPORT_UNSUPPORTED("--report-unsupported-elements-at-runtime");
REPORT_UNSUPPORTED("--report-unsupported-elements-at-runtime"),
INCLUDE_ALL_LOCALES("-H:+IncludeAllLocales"),
LOCALISATION_OPTIMIZED_MODE("-H:-LocalizationOptimizedMode"),
LOG_REGISTERED_RESOURCE_MIN("-H:Log=registerResource:1"),
LOG_REGISTERED_RESOURCE_MAX("-H:Log=registerResource:5");

private final String option;

Expand Down
Loading

0 comments on commit 3a91d95

Please sign in to comment.