You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Foreign Interface is a native API that enables Java code to interact with native code and vice versa.
11
-
It is currently a preview API of the Java platform and must be enabled with `--enable-preview`.
12
-
This page gives an overview of its support in Native Image.
10
+
The Foreign Function & Memory (FFM) API is a native interface that enables Java code to interact with native code and vice versa.
11
+
As of [JEP 442](https://openjdk.org/jeps/442){:target="_blank"}, it is a preview API of the Java platform and must be enabled with `--enable-preview`.
12
+
Modules that are permitted to perform "restricted" native operations (including creating handles for calls to or from native code) must be specified using `--enable-native-access=`.
13
+
This page gives an overview of support for the FFM API in Native Image.
13
14
14
15
## Foreign memory
15
-
Shared arenas are not supported.
16
+
Foreign memory functionality is generally supported. Shared arenas are currently not supported.
16
17
17
18
## Foreign functions
18
-
The Foreign Functions Interface (FFI) allows Java code to call native functions, and conversely allows native code to invoke Java method handles.
19
-
These two kind of calls are referred to as "downcalls" and "upcalls" respectively and are collectively referred to as "foreign calls".
19
+
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.
20
+
These two kinds of calls are referred to as "downcalls" and "upcalls" respectively and are collectively referred to as "foreign calls".
20
21
21
-
This feature is currently only supportedon the AMD64 platform.
22
+
Currently, only downcalls are supported, and only on the AMD64 architecture.
22
23
23
24
### Looking up native functions
24
-
FFI provides the `SymbolLookup` interface which allows to search native libraries for functions by name.
25
-
`loaderLookup` is currently the only supported `SymbolLookup`.
25
+
The FFM API provides the `SymbolLookup` interface to find functions in native libraries by name.
26
+
`SymbolLookup.loaderLookup()` is currently the only supported kind of`SymbolLookup`.
26
27
27
28
### Registering foreign calls
28
-
In order to perform a call to native, some glue code is required and thus must be generated at build time.
29
-
Therefore, a list of the types of downcall which will be performed must be provided to the `native-image` builder.
29
+
In order to perform calls to nativecode at runtime, supporting code must be generated at image build time.
30
+
Therefore, the `native-image` tool must be provided with descriptors that characterize functions to which downcalls may be performed at runtime.
30
31
31
-
This list can be specified using a custom `Feature`. For example:
32
+
These descriptors can be registered using a custom `Feature`, for example:
@@ -40,7 +43,9 @@ class ForeignRegistrationFeature implements Feature {
40
43
}
41
44
}
42
45
```
43
-
To activate the custom feature `--features=<fully qualified name of ForeignRegistrationFeature class>` needs to be passed to native-image.
44
-
[Native Image Build Configuration](BuildConfiguration.md#embed-a-configuration-file) explains how this can be automated with a `native-image.properties` file in `META-INF/native-image`.
46
+
To activate the custom feature, `--features=com.example.ForeignRegistrationFeature` (the fully-qualified name of the feature class) needs to be passed to `native-image`.
47
+
It is recommended to do so [with a _native-image.properties_ file](BuildConfiguration.md#embed-a-configuration-file).
0 commit comments