Skip to content

Commit 32ac72c

Browse files
JornVerneemcimadamoreminborg
committed
8312522: Implementation of Foreign Function & Memory API
Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org> Co-authored-by: Jorn Vernee <jvernee@openjdk.org> Co-authored-by: Per Minborg <pminborg@openjdk.org> Reviewed-by: dholmes, psandoz, mcimadamore, alanb
1 parent 9728e21 commit 32ac72c

File tree

261 files changed

+3142
-2127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+3142
-2127
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -146,8 +146,8 @@ jobs:
146146
apt-architecture: 'i386'
147147
# Some multilib libraries do not have proper inter-dependencies, so we have to
148148
# install their dependencies manually.
149-
apt-extra-packages: 'libfreetype-dev:i386 libtiff-dev:i386 libcupsimage2-dev:i386 libc6-i386 libgcc-s1:i386 libstdc++6:i386'
150-
extra-conf-options: '--with-target-bits=32'
149+
apt-extra-packages: 'libfreetype-dev:i386 libtiff-dev:i386 libcupsimage2-dev:i386 libc6-i386 libgcc-s1:i386 libstdc++6:i386 libffi-dev:i386'
150+
extra-conf-options: '--with-target-bits=32 --enable-fallback-linker --enable-libffi-bundling'
151151
configure-arguments: ${{ github.event.inputs.configure-arguments }}
152152
make-arguments: ${{ github.event.inputs.make-arguments }}
153153
if: needs.select.outputs.linux-x86 == 'true'

make/conf/jib-profiles.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,14 @@ var getJibProfilesProfiles = function (input, common, data) {
426426
target_os: "linux",
427427
target_cpu: "x86",
428428
build_cpu: "x64",
429-
dependencies: ["devkit", "gtest"],
430-
configure_args: concat(common.configure_args_32bit,
431-
"--with-jvm-variants=minimal,server", "--with-zlib=system"),
429+
dependencies: ["devkit", "gtest", "libffi"],
430+
configure_args: concat(common.configure_args_32bit, [
431+
"--with-jvm-variants=minimal,server",
432+
"--with-zlib=system",
433+
"--with-libffi=" + input.get("libffi", "home_path"),
434+
"--enable-libffi-bundling",
435+
"--enable-fallback-linker"
436+
])
432437
},
433438

434439
"macosx-x64": {

src/java.base/share/classes/java/lang/Class.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import jdk.internal.reflect.ReflectionFactory;
8484
import jdk.internal.vm.annotation.ForceInline;
8585
import jdk.internal.vm.annotation.IntrinsicCandidate;
86+
import jdk.internal.vm.annotation.Stable;
8687

8788
import sun.invoke.util.Wrapper;
8889
import sun.reflect.generics.factory.CoreReflectionFactory;
@@ -1060,6 +1061,7 @@ public Module getModule() {
10601061
}
10611062

10621063
// set by VM
1064+
@Stable
10631065
private transient Module module;
10641066

10651067
// Initialized in JVM not by private constructor

src/java.base/share/classes/java/lang/Module.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ Module implAddEnableNativeAccess() {
272272
* <a href="foreign/package-summary.html#restricted"><em>restricted</em></a> methods.
273273
*
274274
* @return {@code true} if this module can access <em>restricted</em> methods.
275-
* @since 20
275+
* @since 22
276276
*/
277-
@PreviewFeature(feature = PreviewFeature.Feature.FOREIGN)
278277
public boolean isNativeAccessEnabled() {
279278
Module target = moduleForNativeAccess();
280279
return EnableNativeAccess.isNativeAccessEnabled(target);
@@ -309,7 +308,7 @@ private Module moduleForNativeAccess() {
309308
}
310309

311310
// This is invoked from Reflection.ensureNativeAccess
312-
void ensureNativeAccess(Class<?> owner, String methodName) {
311+
void ensureNativeAccess(Class<?> owner, String methodName, Class<?> currentClass) {
313312
// The target module whose enableNativeAccess flag is ensured
314313
Module target = moduleForNativeAccess();
315314
if (!EnableNativeAccess.isNativeAccessEnabled(target)) {
@@ -320,13 +319,15 @@ void ensureNativeAccess(Class<?> owner, String methodName) {
320319
// warn and set flag, so that only one warning is reported per module
321320
String cls = owner.getName();
322321
String mtd = cls + "::" + methodName;
323-
String mod = isNamed() ? "module " + getName() : "the unnamed module";
322+
String mod = isNamed() ? "module " + getName() : "an unnamed module";
324323
String modflag = isNamed() ? getName() : "ALL-UNNAMED";
324+
String caller = currentClass != null ? currentClass.getName() : "code";
325325
System.err.printf("""
326326
WARNING: A restricted method in %s has been called
327-
WARNING: %s has been called by %s
328-
WARNING: Use --enable-native-access=%s to avoid a warning for this module
329-
%n""", cls, mtd, mod, modflag);
327+
WARNING: %s has been called by %s in %s
328+
WARNING: Use --enable-native-access=%s to avoid a warning for callers in this module
329+
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
330+
%n""", cls, mtd, caller, mod, modflag);
330331
}
331332
}
332333
}

src/java.base/share/classes/java/lang/ModuleLayer.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -307,9 +307,7 @@ public Controller addOpens(Module source, String pn, Module target) {
307307
*
308308
* <p> This method is <a href="foreign/package-summary.html#restricted"><em>restricted</em></a>.
309309
* Restricted methods are unsafe, and, if used incorrectly, their use might crash
310-
* the JVM or, worse, silently result in memory corruption. Thus, clients should refrain
311-
* from depending on restricted methods, and use safe and supported functionalities,
312-
* where possible.
310+
* the JVM or, worse, silently result in memory corruption.
313311
*
314312
* @param target
315313
* The module to update
@@ -322,9 +320,8 @@ public Controller addOpens(Module source, String pn, Module target) {
322320
* @throws IllegalCallerException
323321
* If the caller is in a module that does not have native access enabled
324322
*
325-
* @since 20
323+
* @since 22
326324
*/
327-
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
328325
@CallerSensitive
329326
@Restricted
330327
public Controller enableNativeAccess(Module target) {

src/java.base/share/classes/java/lang/System.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,8 +2454,8 @@ public Module addEnableNativeAccess(Module m) {
24542454
public void addEnableNativeAccessToAllUnnamed() {
24552455
Module.implAddEnableNativeAccessToAllUnnamed();
24562456
}
2457-
public void ensureNativeAccess(Module m, Class<?> owner, String methodName) {
2458-
m.ensureNativeAccess(owner, methodName);
2457+
public void ensureNativeAccess(Module m, Class<?> owner, String methodName, Class<?> currentClass) {
2458+
m.ensureNativeAccess(owner, methodName, currentClass);
24592459
}
24602460
public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
24612461
return layer.getServicesCatalog();

src/java.base/share/classes/java/lang/foreign/AddressLayout.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package java.lang.foreign;
2727

2828
import jdk.internal.foreign.layout.ValueLayouts;
29-
import jdk.internal.javac.PreviewFeature;
3029
import jdk.internal.javac.Restricted;
3130
import jdk.internal.reflect.CallerSensitive;
3231

@@ -51,11 +50,13 @@
5150
* <li>When creating an upcall stub, using {@link Linker#upcallStub(MethodHandle, FunctionDescriptor, Arena, Option...)}.
5251
* </ul>
5352
*
53+
* @implSpec
54+
* Implementations of this interface are immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
55+
*
5456
* @see #ADDRESS
5557
* @see #ADDRESS_UNALIGNED
56-
* @since 19
58+
* @since 22
5759
*/
58-
@PreviewFeature(feature = PreviewFeature.Feature.FOREIGN)
5960
public sealed interface AddressLayout extends ValueLayout permits ValueLayouts.OfAddressImpl {
6061

6162
/**
@@ -95,13 +96,12 @@ public sealed interface AddressLayout extends ValueLayout permits ValueLayouts.O
9596
* {@snippet lang = java:
9697
* AddressLayout addressLayout = ...
9798
* AddressLayout unboundedLayout = addressLayout.withTargetLayout(
98-
* MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE));
99+
* MemoryLayout.sequenceLayout(Long.MAX_VALUE, ValueLayout.JAVA_BYTE));
99100
*}
100101
* <p>
101102
* This method is <a href="package-summary.html#restricted"><em>restricted</em></a>.
102103
* Restricted methods are unsafe, and, if used incorrectly, their use might crash
103-
* the JVM or, worse, silently result in memory corruption. Thus, clients should refrain from depending on
104-
* restricted methods, and use safe and supported functionalities, where possible.
104+
* the JVM or, worse, silently result in memory corruption.
105105
*
106106
* @param layout the target layout.
107107
* @return an address layout with same characteristics as this layout, but with the provided target layout.

src/java.base/share/classes/java/lang/foreign/Arena.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package java.lang.foreign;
2727

2828
import jdk.internal.foreign.MemorySessionImpl;
29-
import jdk.internal.javac.PreviewFeature;
3029
import jdk.internal.ref.CleanerFactory;
3130

3231
import java.lang.foreign.MemorySegment.Scope;
@@ -184,7 +183,7 @@
184183
* {@snippet lang = java:
185184
* try (Arena slicingArena = new SlicingArena(1000)) {
186185
* for (int i = 0; i < 10; i++) {
187-
* MemorySegment s = slicingArena.allocateArray(JAVA_INT, 1, 2, 3, 4, 5);
186+
* MemorySegment s = slicingArena.allocateFrom(JAVA_INT, 1, 2, 3, 4, 5);
188187
* ...
189188
* }
190189
* } // all memory allocated is released here
@@ -195,9 +194,8 @@
195194
*
196195
* @see MemorySegment
197196
*
198-
* @since 20
197+
* @since 22
199198
*/
200-
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
201199
public interface Arena extends SegmentAllocator, AutoCloseable {
202200

203201
/**
@@ -269,9 +267,7 @@ static Arena ofShared() {
269267
* other than the arena's owner thread.
270268
*/
271269
@Override
272-
default MemorySegment allocate(long byteSize, long byteAlignment) {
273-
return ((MemorySessionImpl)scope()).allocate(byteSize, byteAlignment);
274-
}
270+
MemorySegment allocate(long byteSize, long byteAlignment);
275271

276272
/**
277273
* {@return the arena scope}

src/java.base/share/classes/java/lang/foreign/FunctionDescriptor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.List;
3333

3434
import jdk.internal.foreign.FunctionDescriptorImpl;
35-
import jdk.internal.javac.PreviewFeature;
3635

3736
/**
3837
* A function descriptor models the signature of a foreign function. A function descriptor is made up of zero or more
@@ -44,9 +43,8 @@
4443
* Implementing classes are immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
4544
*
4645
* @see MemoryLayout
47-
* @since 19
46+
* @since 22
4847
*/
49-
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
5048
public sealed interface FunctionDescriptor permits FunctionDescriptorImpl {
5149

5250
/**

src/java.base/share/classes/java/lang/foreign/GroupLayout.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package java.lang.foreign;
2727

2828
import java.util.List;
29-
import jdk.internal.javac.PreviewFeature;
3029

3130
/**
3231
* A compound layout that is an aggregation of multiple, heterogeneous <em>member layouts</em>. There are two ways in which member layouts
@@ -38,9 +37,8 @@
3837
* This class is immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
3938
*
4039
* @sealedGraph
41-
* @since 19
40+
* @since 22
4241
*/
43-
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
4442
public sealed interface GroupLayout extends MemoryLayout permits StructLayout, UnionLayout {
4543

4644
/**

0 commit comments

Comments
 (0)