Skip to content

Commit

Permalink
[GR-47832] Support JEP 424 ("Panama") foreign upcalls in Native Image.
Browse files Browse the repository at this point in the history
PullRequest: graal/15204
  • Loading branch information
Ef55 authored and zapster committed Mar 11, 2024
2 parents 9f82b63 + 9d8926a commit 7b51429
Show file tree
Hide file tree
Showing 40 changed files with 2,127 additions and 189 deletions.
2 changes: 1 addition & 1 deletion docs/reference-manual/native-image/BuildOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ There are some expert level options that a user may find useful or needed. For e

Native Image provides an informative [build output](BuildOutput.md) including various statistics during the build process.
The build output in a JSON-based, machine-readable format can be requested using the `-H:BuildOutputJSONFile` option, and later processed by a monitoring tool.
The JSON files validate against the JSON schema defined in [build-output-schema-v0.9.2.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/build-output-schema-v0.9.2.json).
The JSON files validate against the JSON schema defined in [build-output-schema-v0.9.3.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/build-output-schema-v0.9.3.json).
A comprehensive report with additional information can be requested using the `-H:+BuildReport` option.

### Graph Dumping
Expand Down
6 changes: 3 additions & 3 deletions docs/reference-manual/native-image/BuildOutput.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ Large numbers can cause significant reflection overheads, slow down the build pr
#### <a name="glossary-jni-access-registrations"></a>JNI Access Registrations
The number of types, fields, and methods that are registered for [JNI](JNI.md) access.
#### <a name="glossary-foreign-downcall-registrations"></a>Foreign functions stubs
The number of downcalls registered for [foreign](ForeignInterface.md) function access.
#### <a name="glossary-foreign-downcall-and-upcall-registrations"></a>Foreign functions stubs
The number of downcalls and upcalls registered for [foreign](ForeignInterface.md) function access.
#### <a name="glossary-runtime-methods"></a>Runtime Compiled Methods
The number of methods marked for runtime compilation.
Expand Down Expand Up @@ -356,7 +356,7 @@ This schema also contains descriptions for each possible artifact type and expla
The build output produced by the `native-image` builder is designed for humans, can evolve with new releases, and should thus not be parsed in any way by tools.
Instead, use the `-H:BuildOutputJSONFile=<file.json>` option to instruct the builder to produce machine-readable build output in JSON format that can be used, for example, for building monitoring tools.
Such a JSON file validates against the JSON schema defined in [`build-output-schema-v0.9.2.json`](https://github.com/oracle/graal/tree/master/docs/reference-manual/native-image/assets/build-output-schema-v0.9.2.json).
Such a JSON file validates against the JSON schema defined in [`build-output-schema-v0.9.3.json`](https://github.com/oracle/graal/tree/master/docs/reference-manual/native-image/assets/build-output-schema-v0.9.3.json).
Note that a JSON file is produced if and only if a build succeeds.
The following example illustrates how this could be used in a CI/CD build pipeline to check that the number of reachable methods does not exceed a certain threshold:
Expand Down
13 changes: 6 additions & 7 deletions docs/reference-manual/native-image/ForeignInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Shared arenas are currently not supported.
The FFM API enables Java code to call _down_ to native functions, and conversely allows native code to call _up_ to invoke Java code via method handles.
These two kinds of calls are referred to as "downcalls" and "upcalls" respectively, and are collectively referred to as "foreign calls".

> Note: Currently, only downcalls are supported, and only on the x64 architecture.
> Note: Currently, foreign calls are supported on the x64 architecture.
> Specifically, downcalls are supported on x64 Linux, Windows and MacOS, while upcalls are supported only on x64 Linux.
### Looking Up Native Functions

Expand All @@ -43,8 +44,10 @@ import static java.lang.foreign.ValueLayout.*;
class ForeignRegistrationFeature implements Feature {
public void duringSetup(DuringSetupAccess access) {
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid());
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(), Linker.Option.isTrivial());
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForUpcall(FunctionDescriptor.ofVoid());
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(), Linker.Option.critical(false));
RuntimeForeignAccess.registerForUpcall(FunctionDescriptor.of(JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForUpcall(FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_INT), Linker.Option.firstVariadicArg(1));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_INT), Linker.Option.captureCallState("errno"));
}
Expand All @@ -53,10 +56,6 @@ class ForeignRegistrationFeature implements Feature {
To activate the custom feature, pass the `--features=com.example.ForeignRegistrationFeature` option (the fully-qualified name of the feature class) to `native-image`.
It is recommended to do so [with a _native-image.properties_ file](BuildConfiguration.md#embed-a-configuration-file).

### Upcalls

Upcalls are not yet supported.

### Related Documentation

- [Interoperability with Native Code](InteropWithNativeCode.md)
Loading

0 comments on commit 7b51429

Please sign in to comment.