Skip to content

Commit 31be89d

Browse files
committed
Integrate foreign configuration into reachability-metadata.json
1 parent 782b28c commit 31be89d

File tree

11 files changed

+171
-190
lines changed

11 files changed

+171
-190
lines changed
Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +0,0 @@
1-
{
2-
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://raw.githubusercontent.com/oracle/graal/master/docs/reference-manual/native-image/assets/foreign-config-schema-v0.1.0.json",
4-
"properties": {
5-
"downcalls": {
6-
"default": [],
7-
"items": {
8-
"properties": {
9-
"condition": {
10-
"$ref": "config-condition-schema-v1.0.0.json",
11-
"title": "Condition under which the downcall stub should be registered"
12-
},
13-
"returnType": {
14-
"type": "string",
15-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
16-
},
17-
"parameterTypes": {
18-
"default": [],
19-
"items": {
20-
"type": "string",
21-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
22-
},
23-
"type": "array",
24-
"title": "List of the function descriptor's parameter types "
25-
},
26-
"options": {
27-
"type": "object",
28-
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
29-
"properties": {
30-
"captureCallState": {
31-
"type": "boolean",
32-
"title": "Specifies if a call state should be captured. Which states to capture is determined at run time. See also: 'java.lang.foreign.Linker.Option.captureCallState'"
33-
},
34-
"critical": {
35-
"type": "object",
36-
"title": "see 'java.lang.foreign.Linker.Option.critical'",
37-
"properties": {
38-
"allowHeapAccess": {
39-
"type": "boolean"
40-
}
41-
},
42-
"additionalProperties": false
43-
},
44-
"firstVariadicArg": {
45-
"type": "integer",
46-
"title": "see 'java.lang.foreign.Linker.Option.firstVariadicArg'"
47-
}
48-
},
49-
"additionalProperties": false
50-
}
51-
},
52-
"additionalProperties": false,
53-
"type": "object",
54-
"title": "A function descriptor to be registered for a downcall"
55-
},
56-
"type": "array",
57-
"title": "List of function descriptors that should be registered for downcalls"
58-
},
59-
"upcalls": {
60-
"default": [],
61-
"items": {
62-
"properties": {
63-
"condition": {
64-
"$ref": "config-condition-schema-v1.0.0.json",
65-
"title": "Condition under which the upcall stub should be registered"
66-
},
67-
"returnType": {
68-
"type": "string",
69-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
70-
},
71-
"parameterTypes": {
72-
"default": [],
73-
"items": {
74-
"type": "string",
75-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
76-
},
77-
"type": "array",
78-
"title": "List of the function descriptor's parameter types "
79-
},
80-
"options": {
81-
"type": "object",
82-
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
83-
"description": "Currently, no linker options are allowed for upcalls. This may change in future.",
84-
"properties": { },
85-
"additionalProperties": false
86-
}
87-
},
88-
"additionalProperties": false,
89-
"type": "object",
90-
"title": "A function descriptor to be registered for an upcall"
91-
},
92-
"type": "array",
93-
"title": "List of function descriptors that should be registered for upcalls"
94-
},
95-
"directUpcalls": {
96-
"default": [],
97-
"items": {
98-
"properties": {
99-
"condition": {
100-
"$ref": "config-condition-schema-v1.0.0.json",
101-
"title": "Condition under which the direct upcall stub should be registered"
102-
},
103-
"class": {
104-
"type": "string",
105-
"title": "Full-qualified class name (e.g. 'org.package.OuterClass$InnerClass')"
106-
},
107-
"method": {
108-
"type": "string",
109-
"title": "Method name"
110-
},
111-
"returnType": {
112-
"type": "string",
113-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
114-
},
115-
"parameterTypes": {
116-
"default": [],
117-
"items": {
118-
"type": "string",
119-
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
120-
},
121-
"type": "array",
122-
"title": "List of the function descriptor's parameter types "
123-
},
124-
"options": {
125-
"type": "object",
126-
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
127-
"description": "Currently, no linker options are allowed for direct upcalls. This may change in future.",
128-
"properties": { },
129-
"additionalProperties": false
130-
}
131-
},
132-
"additionalProperties": false,
133-
"type": "object",
134-
"title": "A Java method and function descriptor to be registered for a direct upcall"
135-
},
136-
"type": "array",
137-
"title": "List of Java methods and function descriptors that should be registered for direct upcalls"
138-
}
139-
},
140-
"type": "object",
141-
"additionalProperties": false,
142-
"title": "JSON schema for the FFM API configuration that GraalVM Native Image uses",
143-
"description": "A description and examples for writing an FFM API configuration can be found at https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md"
144-
}

docs/reference-manual/native-image/assets/reachability-metadata-schema-v1.1.0.json

Lines changed: 153 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,148 @@
157157
],
158158
"additionalProperties": false
159159
}
160+
},
161+
"foreign": {
162+
"properties": {
163+
"downcalls": {
164+
"default": [],
165+
"items": {
166+
"properties": {
167+
"condition": {
168+
"$ref": "config-condition-schema-v1.0.0.json",
169+
"title": "Condition under which the downcall stub should be registered"
170+
},
171+
"returnType": {
172+
"type": "string",
173+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
174+
},
175+
"parameterTypes": {
176+
"default": [],
177+
"items": {
178+
"type": "string",
179+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
180+
},
181+
"type": "array",
182+
"title": "List of the function descriptor's parameter types"
183+
},
184+
"options": {
185+
"type": "object",
186+
"title": "Linker options (see `java.lang.foreign.Linker.Option`)",
187+
"properties": {
188+
"captureCallState": {
189+
"type": "boolean",
190+
"title": "Specifies whether a call state should be captured. The specific states to capture are determined at run time. See also: `java.lang.foreign.Linker.Option.captureCallState`"
191+
},
192+
"critical": {
193+
"type": "object",
194+
"title": "See `java.lang.foreign.Linker.Option.critical`",
195+
"properties": {
196+
"allowHeapAccess": {
197+
"type": "boolean"
198+
}
199+
},
200+
"additionalProperties": false
201+
},
202+
"firstVariadicArg": {
203+
"type": "integer",
204+
"title": "See `java.lang.foreign.Linker.Option.firstVariadicArg`"
205+
}
206+
},
207+
"additionalProperties": false
208+
}
209+
},
210+
"additionalProperties": false,
211+
"type": "object",
212+
"title": "Function descriptor to be registered for a downcall"
213+
},
214+
"type": "array",
215+
"title": "List of function descriptors that should be registered for downcalls"
216+
},
217+
"upcalls": {
218+
"default": [],
219+
"items": {
220+
"properties": {
221+
"condition": {
222+
"$ref": "config-condition-schema-v1.0.0.json",
223+
"title": "Condition under which the upcall stub should be registered"
224+
},
225+
"returnType": {
226+
"type": "string",
227+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
228+
},
229+
"parameterTypes": {
230+
"default": [],
231+
"items": {
232+
"type": "string",
233+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
234+
},
235+
"type": "array",
236+
"title": "List of the function descriptor's parameter types"
237+
},
238+
"options": {
239+
"type": "object",
240+
"title": "Linker options (see `java.lang.foreign.Linker.Option`)",
241+
"description": "Currently, no linker options are allowed for upcalls. This may change in the future.",
242+
"properties": { },
243+
"additionalProperties": false
244+
}
245+
},
246+
"additionalProperties": false,
247+
"type": "object",
248+
"title": "Function descriptor to be registered for an upcall"
249+
},
250+
"type": "array",
251+
"title": "List of function descriptors that should be registered for upcalls"
252+
},
253+
"directUpcalls": {
254+
"default": [],
255+
"items": {
256+
"properties": {
257+
"condition": {
258+
"$ref": "config-condition-schema-v1.0.0.json",
259+
"title": "Condition under which the direct upcall stub should be registered"
260+
},
261+
"class": {
262+
"type": "string",
263+
"title": "Fully-qualified class name (e.g. `org.package.OuterClass$InnerClass`)"
264+
},
265+
"method": {
266+
"type": "string",
267+
"title": "Method name"
268+
},
269+
"returnType": {
270+
"type": "string",
271+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
272+
},
273+
"parameterTypes": {
274+
"default": [],
275+
"items": {
276+
"type": "string",
277+
"title": "Memory layout definition (allows canonical layouts; see `java.lang.foreign.Linker`)"
278+
},
279+
"type": "array",
280+
"title": "List of the function descriptor's parameter types "
281+
},
282+
"options": {
283+
"type": "object",
284+
"title": "Linker options (see `java.lang.foreign.Linker.Option`)",
285+
"description": "Currently, no linker options are allowed for direct upcalls. This may change in the future.",
286+
"properties": { },
287+
"additionalProperties": false
288+
}
289+
},
290+
"additionalProperties": false,
291+
"type": "object",
292+
"title": "Java method and function descriptor to be registered for a direct upcall"
293+
},
294+
"type": "array",
295+
"title": "List of Java methods and function descriptors that should be registered for direct upcalls"
296+
}
297+
},
298+
"type": "object",
299+
"additionalProperties": false,
300+
"title": "JSON schema for the FFM API configuration used by GraalVM Native Image",
301+
"description": "For a description and examples of writing an FFM API configuration, see: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md"
160302
}
161303
},
162304
"required": [],
@@ -352,7 +494,7 @@
352494
"type": "array",
353495
"default": [],
354496
"items": {
355-
"title": "Fully qualified name of the interface defining the proxy class",
497+
"title": "Fully-qualified name of the interface defining the proxy class",
356498
"type": "string"
357499
}
358500
},
@@ -362,27 +504,27 @@
362504
"properties": {
363505
"declaringClass": {
364506
"title": "The class in which the lambda class is defined",
365-
"type": "#/$defs/type"
507+
"$ref": "#/$defs/type"
366508
},
367509
"declaringMethod": {
368510
"title": "The method in which the lambda class is defined",
369-
"type": "#/$defs/method",
511+
"$ref": "#/$defs/method",
370512
"default": {}
371513
},
372514
"interfaces": {
373515
"title": "Non-empty list of interfaces implemented by the lambda class",
374516
"type": "array",
375517
"items": {
376-
"title": "Fully qualified name of the interface implemented by the lambda class",
518+
"title": "Fully-qualified name of the interface implemented by the lambda class",
377519
"type": "string"
378520
}
379-
},
380-
"required": [
381-
"declaringClass",
382-
"interfaces"
383-
],
384-
"additionalProperties": false
385-
}
521+
}
522+
},
523+
"required": [
524+
"declaringClass",
525+
"interfaces"
526+
],
527+
"additionalProperties": false
386528
}
387529
},
388530
"oneOf": [

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This changelog summarizes major changes to GraalVM Native Image.
3232
Run-time initialization of security providers helps reduce image heap size by avoiding unnecessary objects inclusion.
3333
* (GR-48191) Enable lambda classes to be registered for reflection and serialization in _reachability-metadata.json_. The format is detailed [here](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ReachabilityMetadata.md).
3434
* (GR-54697) Parallelize debug info generation and add support for run-time debug info generation. `-H:+RuntimeDebugInfo` adds a run-time debug info generator into a native image for use with GDB.
35+
* (GR-65773) Integrate Foreign Function and Memory (FFM) API metadata into _reachability-metadata.json_.
3536

3637
## GraalVM for JDK 24 (Internal Version 24.2.0)
3738
* (GR-59717) Added `DuringSetupAccess.registerObjectReachabilityHandler` to allow registering a callback that is executed when an object of a specified type is marked as reachable during heap scanning.

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public enum ConfigurationFile {
4444
DYNAMIC_PROXY("proxy", null, true, false),
4545
PREDEFINED_CLASSES_NAME("predefined-classes", null, true, false),
4646
/* Non-metadata categories */
47-
FOREIGN("foreign", FOREIGN_KEY, true, false),
47+
FOREIGN("foreign", FOREIGN_KEY, true, true),
4848
SERIALIZATION_DENY("serialization-deny", null, false, false);
4949

5050
public static final String LEGACY_FILE_NAME_SUFFIX = "-config.json";

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void parseAndRegister(Reader reader) throws IOException {
128128

129129
public Object getFromGlobalFile(Object json, String key) {
130130
EconomicMap<String, Object> map = asMap(json, "top level of reachability metadata file must be an object");
131-
checkAttributes(map, "reachability metadata", Collections.emptyList(), List.of(REFLECTION_KEY, JNI_KEY, SERIALIZATION_KEY, RESOURCES_KEY, BUNDLES_KEY, "reason", "comment"));
131+
checkAttributes(map, "reachability metadata", Collections.emptyList(), List.of(REFLECTION_KEY, JNI_KEY, SERIALIZATION_KEY, RESOURCES_KEY, BUNDLES_KEY, FOREIGN_KEY, "reason", "comment"));
132132
return map.get(key);
133133
}
134134

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ForeignConfigurationParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public ForeignConfigurationParser(EnumSet<ConfigurationParserOption> parserOptio
4646

4747
@Override
4848
public void parseAndRegister(Object json, URI origin) {
49-
var topLevel = asMap(json, "first level of document must be a map");
49+
var foreignJson = getFromGlobalFile(json, FOREIGN_KEY);
50+
if (foreignJson == null) {
51+
return;
52+
}
53+
var topLevel = asMap(foreignJson, "first level of document must be a map");
5054
checkAttributes(topLevel, "foreign methods categories", List.of(), List.of("downcalls", "upcalls", "directUpcalls"));
5155

5256
var downcalls = asList(topLevel.get("downcalls", List.of()), "downcalls must be an array of function descriptor and linker options");

0 commit comments

Comments
 (0)