Skip to content

Commit 9d7699d

Browse files
committed
Implement new foreign configuration file syntax
1 parent df624d2 commit 9d7699d

File tree

9 files changed

+657
-322
lines changed

9 files changed

+657
-322
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
"returnType": {
10+
"type": "string",
11+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
12+
},
13+
"parameterTypes": {
14+
"default": [],
15+
"items": {
16+
"type": "string",
17+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
18+
},
19+
"type": "array",
20+
"title": "List of the function descriptor's parameter types "
21+
},
22+
"options": {
23+
"type": "object",
24+
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
25+
"properties": {
26+
"captureCallState": {
27+
"type": "boolean",
28+
"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'"
29+
},
30+
"critical": {
31+
"type": ["boolean", "object"],
32+
"title": "see 'java.lang.foreign.Linker.Option.critical'",
33+
"properties": {
34+
"allowHeapAccess": {
35+
"type": "boolean"
36+
}
37+
},
38+
"additionalProperties": false
39+
},
40+
"firstVariadicArg": {
41+
"type": "integer",
42+
"title": "see 'java.lang.foreign.Linker.Option.firstVariadicArg'"
43+
}
44+
},
45+
"additionalProperties": false
46+
}
47+
},
48+
"additionalProperties": false,
49+
"type": "object",
50+
"title": "A function descriptor to be registered for a downcall"
51+
},
52+
"type": "array",
53+
"title": "List of function descriptors that should be registered for downcalls"
54+
},
55+
"upcalls": {
56+
"default": [],
57+
"items": {
58+
"properties": {
59+
"returnType": {
60+
"type": "string",
61+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
62+
},
63+
"parameterTypes": {
64+
"default": [],
65+
"items": {
66+
"type": "string",
67+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
68+
},
69+
"type": "array",
70+
"title": "List of the function descriptor's parameter types "
71+
},
72+
"options": {
73+
"type": "object",
74+
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
75+
"description": "Currently, no linker options are allowed for upcalls. This may change in future.",
76+
"properties": { },
77+
"additionalProperties": false
78+
}
79+
},
80+
"additionalProperties": false,
81+
"type": "object",
82+
"title": "A function descriptor to be registered for an upcall"
83+
},
84+
"type": "array",
85+
"title": "List of function descriptors that should be registered for upcalls"
86+
},
87+
"directUpcalls": {
88+
"default": [],
89+
"items": {
90+
"properties": {
91+
"class": {
92+
"type": "string",
93+
"title": "Full-qualified class name (e.g. 'org.package.OuterClass$InnerClass')"
94+
},
95+
"method": {
96+
"type": "string",
97+
"title": "Method name"
98+
},
99+
"returnType": {
100+
"type": "string",
101+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
102+
},
103+
"parameterTypes": {
104+
"default": [],
105+
"items": {
106+
"type": "string",
107+
"title": "A memory layout definition (allows canonical layouts; see 'java.lang.foreign.Linker')"
108+
},
109+
"type": "array",
110+
"title": "List of the function descriptor's parameter types "
111+
},
112+
"options": {
113+
"type": "object",
114+
"title": "Linker options (see 'java.lang.foreign.Linker.Option')",
115+
"description": "Currently, no linker options are allowed for direct upcalls. This may change in future.",
116+
"properties": { },
117+
"additionalProperties": false
118+
}
119+
},
120+
"additionalProperties": false,
121+
"type": "object",
122+
"title": "A Java method and function descriptor to be registered for a direct upcall"
123+
},
124+
"type": "array",
125+
"title": "List of Java methods and function descriptors that should be registered for direct upcalls"
126+
}
127+
},
128+
"type": "object",
129+
"additionalProperties": false,
130+
"title": "JSON schema for the FFM API configuration that GraalVM Native Image uses",
131+
"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"
132+
}

substratevm/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This changelog summarizes major changes to GraalVM Native Image.
1515
* (GR-49525) Introduced `--future-defaults=[all|<options>|none]` that enables options that are planned to become defaults in future releases. The enabled options are:
1616
1. `run-time-initialized-jdk` shifts away from build-time initialization of the JDK, instead initializing most of it at run time. This transition is gradual, with individual components of the JDK becoming run-time initialized in each release. This process should complete with JDK 29 when this option should not be needed anymore. Unless you store classes from the JDK in the image heap, this option should not affect you. In case this option breaks your build, follow the suggestions in the error messages.
1717
* (GR-63494) Recurring callback support is no longer enabled by default. If this feature is needed, please specify `-H:+SupportRecurringCallback` at image build-time.
18+
* (GR-60209) New syntax for configuration of the [Foreign Function & Memory API](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md)
1819

1920
## GraalVM for JDK 24 (Internal Version 24.2.0)
2021
* (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/mx.substratevm/suite.py

+1
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@
798798
"sourceDirs": ["src"],
799799
"dependencies": [
800800
"com.oracle.svm.hosted",
801+
"com.oracle.svm.configure",
801802
"com.oracle.svm.core.foreign"
802803
],
803804
"distDependencies": [

substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/AbiUtils.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,13 @@ public static AbiUtils singleton() {
499499
*/
500500
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+11/src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java#L99")
501501
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+11/src/java.base/share/classes/jdk/internal/foreign/abi/DowncallLinker.java#L71-L85")
502-
public NativeEntryPointInfo makeNativeEntrypoint(FunctionDescriptor desc, Linker.Option... options) {
502+
public NativeEntryPointInfo makeNativeEntrypoint(FunctionDescriptor desc, LinkerOptions linkerOptions) {
503503
// From Linker.downcallHandle implemented in AbstractLinker.downcallHandle:
504504
// From AbstractLinker.downcallHandle0
505-
LinkerOptions optionSet = LinkerOptions.forDowncall(desc, options);
506505
MethodType type = desc.toMethodType();
507506

508507
// makeCallingSequence calls platform specific code
509-
var callingSequence = makeCallingSequence(type, desc, false, optionSet);
508+
var callingSequence = makeCallingSequence(type, desc, false, linkerOptions);
510509

511510
// From DowncallLinker.getBoundMethodHandle
512511
var argMoveBindings = ABIs.Downcalls.argMoveBindingsStream(callingSequence).toArray(Binding.VMStore[]::new);
@@ -517,18 +516,17 @@ public NativeEntryPointInfo makeNativeEntrypoint(FunctionDescriptor desc, Linker
517516

518517
// From NativeEntrypoint.make
519518
return NativeEntryPointInfo.make(argMoves, returnMoves, boundaryType, needsReturnBuffer, callingSequence.capturedStateMask(), callingSequence.needsTransition(),
520-
optionSet.allowsHeapAccess());
519+
linkerOptions.allowsHeapAccess());
521520
}
522521

523522
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+11/src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java#L124")
524523
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+11/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java#L62-L110")
525-
public JavaEntryPointInfo makeJavaEntryPoint(FunctionDescriptor desc, Linker.Option... options) {
524+
public JavaEntryPointInfo makeJavaEntryPoint(FunctionDescriptor desc, LinkerOptions linkerOptions) {
526525
// Linker.upcallStub implemented in AbstractLinker.upcallStub
527526
MethodType type = desc.toMethodType();
528-
LinkerOptions optionSet = LinkerOptions.forUpcall(desc, options);
529527

530528
// From CallArranger.arrangeUpcall
531-
var callingSequence = makeCallingSequence(type, desc, true, optionSet);
529+
var callingSequence = makeCallingSequence(type, desc, true, linkerOptions);
532530

533531
// From SharedUtil.arrangeUpcallHelper
534532
// From UpcallLinker.makeFactory

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFiles.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public static final class Options {
133133
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> ReachabilityMetadataResources = new HostedOptionKey<>(
134134
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());
135135

136-
@Option(help = "Files describing stubs allowing foreign calls.", type = OptionType.User)//
136+
@OptionMigrationMessage("Use a foreign-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead.")//
137+
@Option(help = "Files describing stubs allowing foreign calls according to the schema at " +
138+
"https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/foreign-config-schema-v0.1.0.json", type = OptionType.User)//
137139
@BundleMember(role = BundleMember.Role.Input)//
138140
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Paths> ForeignConfigurationFiles = new HostedOptionKey<>(
139141
AccumulatingLocatableMultiOptionValue.Paths.buildWithCommaDelimiter());

0 commit comments

Comments
 (0)