Skip to content

Commit

Permalink
Introduce more flexible type descriptors for JSON configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Feb 20, 2024
1 parent 6b2a631 commit 690c759
Show file tree
Hide file tree
Showing 19 changed files with 451 additions and 60 deletions.
4 changes: 2 additions & 2 deletions docs/reference-manual/native-image/ReachabilityMetadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Integer.class.getMethod("parseInt", params2);
### Specifying Reflection Metadata in JSON
Reflection metadata should be specified in a _reflect-config.json_ file and conform to the JSON schema defined in
[reflect-config-schema-v1.0.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/reflect-config-schema-v1.0.0.json).
[reflect-config-schema-v1.1.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/reflect-config-schema-v1.1.0.json).
The schema also includes further details and explanations how this configuration works. Here is the example of the reflect-config.json:
```json
[
Expand Down Expand Up @@ -209,7 +209,7 @@ It is not possible to specify JNI metadata in code.
### JNI Metadata in JSON
JNI metadata should be specified in a _jni-config.json_ file and conform to the JSON schema defined in
[jni-config-schema-v1.0.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/jni-config-schema-v1.0.0.json).
[jni-config-schema-v1.1.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/jni-config-schema-v1.1.0.json).
The schema also includes further details and explanations how this configuration works. The example of jni-config.json is the same
as the example of reflect-config.json described above.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/config-condition-schema-v1.0.0.json",
"title": "JSON schema for the conditions used in GraalVM Native Image configuration files",
"properties": {
"typeReachable": {
"type": "string",
"title": "Fully qualified name of the class that must be reachable in order to register the type <type> for reflection"
}
},
"required": [
"typeReachable"
],
"additionalProperties": false,
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/config-type-schema-v1.0.0.json",
"type": "string",
"title": "JSON schema for the type descriptors GraalVM Native Image configuration files use"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/jni-config-schema-v1.1.0.json",
"default": [],
"items": {
"properties": {
"condition": {
"$ref": "config-condition-schema-v1.0.0.json",
"title": "Condition under which the class should be registered for access through JNI"
},
"type": {
"$ref": "config-type-schema-v1.0.0.json",
"title": "Type descriptor of the class that should be registered for access through JNI"
},
"methods": {
"default": [],
"items": {
"properties": {
"name": {
"type": "string",
"title": "Method name that should be registered for this class"
},
"parameterTypes": {
"default": [],
"items": {
"type": "string",
"title": "List of the method's parameter types"
},
"type": "array"
}
},
"required": [
"name"
],
"additionalProperties": false,
"type": "object",
"title": "List of methods from this class that are registered for access through JNI"
},
"type": "array",
"title": "List of methods that should be registered for the class declared in <name>"
},
"fields": {
"default": [],
"items": {
"properties": {
"name": {
"type": "string",
"title": "Name of the field that should be registered for access through JNI"
}
},
"required": [
"name"
],
"additionalProperties": false,
"type": "object"
},
"type": "array",
"title": "List of fields that should be registered for the class declared in <name>"
},
"allDeclaredMethods": {
"default": false,
"type": "boolean",
"title": "Register methods which would be returned by the java.lang.Class#getDeclaredMethods call"
},
"allDeclaredFields": {
"default": false,
"type": "boolean",
"title": "Register fields which would be returned by the java.lang.Class#getDeclaredFields call"
},
"allDeclaredConstructors": {
"default": false,
"type": "boolean",
"title": "Register constructors which would be returned by the java.lang.Class#getDeclaredConstructors call"
},
"allPublicMethods": {
"default": false,
"type": "boolean",
"title": "Register all public methods which would be returned by the java.lang.Class#getMethods call"
},
"allPublicFields": {
"default": false,
"type": "boolean",
"title": "Register all public fields which would be returned by the java.lang.Class#getFields call"
},
"allPublicConstructors": {
"default": false,
"type": "boolean",
"title": "Register all public constructors which would be returned by the java.lang.Class#getConstructors call"
},
"unsafeAllocated": {
"default": false,
"type": "boolean",
"title": "Allow objects of this class to be instantiated with a call to jdk.internal.misc.Unsafe#allocateInstance"
}
},
"required": [
"type"
],
"additionalProperties": false,
"type": "object"
},
"type": "array",
"title": "JSON schema for the JNI configuration that GraalVM Native Image uses"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/reflect-config-schema-v1.1.0.json",
"default": [],
"items": {
"properties": {
"condition": {
"$ref": "config-condition-schema-v1.0.0.json",
"title": "Condition under which the class should be registered for reflection"
},
"type": {
"$ref": "config-type-schema-v1.0.0.json",
"title": "Type descriptor of the class that should be registered for reflection"
},
"methods": {
"default": [],
"items": {
"properties": {
"name": {
"type": "string",
"title": "Method name that should be registered for this class"
},
"parameterTypes": {
"default": [],
"items": {
"type": "string",
"title": "List of the method's parameter types"
},
"type": "array"
}
},
"required": [
"name"
],
"additionalProperties": false,
"type": "object",
"title": "List of methods from this class that are registered for reflection"
},
"type": "array",
"title": "List of methods that should be registered for the type declared in <type>"
},
"fields": {
"default": [],
"items": {
"properties": {
"name": {
"type": "string",
"title": "Name of the field that should be registered for reflection"
}
},
"required": [
"name"
],
"additionalProperties": false,
"type": "object"
},
"type": "array",
"title": "List of class fields that can be looked up, read, or modified for the type declared in <type>"
},
"allDeclaredMethods": {
"default": false,
"type": "boolean",
"title": "Register methods which would be returned by the java.lang.Class#getDeclaredMethods call"
},
"allDeclaredFields": {
"default": false,
"type": "boolean",
"title": "Register fields which would be returned by the java.lang.Class#getDeclaredFields call"
},
"allDeclaredConstructors": {
"default": false,
"type": "boolean",
"title": "Register constructors which would be returned by the java.lang.Class#getDeclaredConstructors call"
},
"allPublicMethods": {
"default": false,
"type": "boolean",
"title": "Register all public methods which would be returned by the java.lang.Class#getMethods call"
},
"allPublicFields": {
"default": false,
"type": "boolean",
"title": "Register all public fields which would be returned by the java.lang.Class#getFields call"
},
"allPublicConstructors": {
"default": false,
"type": "boolean",
"title": "Register all public constructors which would be returned by the java.lang.Class#getConstructors call"
},
"unsafeAllocated": {
"default": false,
"type": "boolean",
"title": "Allow objects of this class to be instantiated with a call to jdk.internal.misc.Unsafe#allocateInstance"
}
},
"required": [
"type"
],
"additionalProperties": false,
"type": "object"
},
"type": "array",
"title": "JSON schema for the reflection configuration that GraalVM Native Image uses"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -260,11 +260,11 @@ Map<ConfigurationMethod, ConfigurationMemberDeclaration> getMethodsMap(Configura
}

void populateConfig() {
ConfigurationType oldType = new ConfigurationType(UnresolvedConfigurationCondition.alwaysTrue(), getTypeName());
ConfigurationType oldType = new ConfigurationType(UnresolvedConfigurationCondition.alwaysTrue(), getTypeName(), true);
setFlags(oldType);
previousConfig.add(oldType);

ConfigurationType newType = new ConfigurationType(UnresolvedConfigurationCondition.alwaysTrue(), getTypeName());
ConfigurationType newType = new ConfigurationType(UnresolvedConfigurationCondition.alwaysTrue(), getTypeName(), true);
for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustExist.entrySet()) {
newType.addMethod(methodEntry.getKey().getName(), methodEntry.getKey().getInternalSignature(), methodEntry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,7 +43,7 @@ public static boolean isConstructorName(String name) {
public static String toInternalParamsSignature(List<ConfigurationType> types) {
StringBuilder sb = new StringBuilder("(");
for (ConfigurationType type : types) {
sb.append(MetaUtil.toInternalName(type.getQualifiedJavaName()));
sb.append(MetaUtil.toInternalName(((NamedConfigurationTypeDescriptor) type.getTypeDescriptor()).name()));
}
sb.append(')');
// we are missing the return type, so this is only a partial signature
Expand Down
Loading

0 comments on commit 690c759

Please sign in to comment.