Skip to content

Commit f8aa58b

Browse files
committed
[GR-59770] Make PanamaNFILanguage load cleanly on JDK 21
* PanamaNFILanguageProvider must be compiled as 17+ to avoid breaking ServiceLoader. * ServiceLoader has no way to ignore UnsupportedClassVersionError errors, it breaks the ServiceLoader iterator. * Remove @SuppressWarnings("preview") since on JDK 22 it is not a preview anymore.
1 parent d275ae4 commit f8aa58b

File tree

21 files changed

+358
-116
lines changed

21 files changed

+358
-116
lines changed

truffle/mx.truffle/suite.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,32 @@
949949
"graalCompilerSourceEdition": "ignore",
950950
},
951951

952+
# PanamaNFILanguage itself must be 17+ so that PanamaNFILanguageProvider can be loaded without
953+
# breaking the ServiceLoader which unfortunately cannot ignore newer class files (GR-59770)
952954
"com.oracle.truffle.nfi.backend.panama" : {
953955
"subDir" : "src",
954956
"sourceDirs" : ["src"],
955957
"dependencies" : [
956958
"com.oracle.truffle.nfi.backend.spi",
957959
],
958960
"checkstyle" : "com.oracle.truffle.api",
959-
# GR-51699
961+
"javaCompliance" : "17+",
962+
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
963+
"workingSets" : "Truffle",
964+
"graalCompilerSourceEdition": "ignore",
965+
},
966+
967+
"com.oracle.truffle.nfi.backend.panama.jdk22" : {
968+
"overlayTarget" : "com.oracle.truffle.nfi.backend.panama",
969+
"multiReleaseJarVersion" : "22",
970+
"subDir" : "src",
971+
"sourceDirs" : ["src"],
972+
"dependencies" : [
973+
"com.oracle.truffle.nfi.backend.panama",
974+
],
975+
"checkstyle" : "com.oracle.truffle.api",
960976
"javaCompliance" : "22+",
961-
"forceJavac": True,
977+
"forceJavac": True, # GR-51699
962978
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
963979
"workingSets" : "Truffle",
964980
# disable SpotBugs and Jacoco as long as JDK 22 is unsupported [GR-49566]
@@ -1906,9 +1922,8 @@
19061922
],
19071923
},
19081924
"subDir" : "src",
1909-
"javaCompliance" : "22+",
1910-
# GR-51699
1911-
"forceJavac": True,
1925+
"javaCompliance" : "17+",
1926+
"forceJavac": True, # GR-51699
19121927
"dependencies" : [
19131928
"com.oracle.truffle.nfi.backend.panama",
19141929
],
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,18 @@
4848

4949
import com.oracle.truffle.api.InternalResource.OS;
5050

51-
public class ErrorContext {
52-
private static final String ERRNO_LOCATION;
51+
public class ErrorContext extends AbstractErrorContext {
5352

54-
static {
55-
ERRNO_LOCATION = switch (OS.getCurrent()) {
56-
case DARWIN -> "__error";
57-
case LINUX -> "__errno_location";
58-
case WINDOWS -> "_errno";
59-
};
60-
}
53+
private static final String ERRNO_LOCATION = switch (OS.getCurrent()) {
54+
case DARWIN -> "__error";
55+
case LINUX -> "__errno_location";
56+
case WINDOWS -> "_errno";
57+
};
6158

62-
@SuppressWarnings("preview") private MemorySegment errnoLocation;
63-
final PanamaNFIContext ctx;
59+
private MemorySegment errnoLocation;
6460

65-
@SuppressWarnings({"preview", "restricted"})
66-
MemorySegment lookupErrnoLocation() {
61+
@SuppressWarnings("restricted")
62+
private MemorySegment lookupErrnoLocation() {
6763
try {
6864
Linker linker = Linker.nativeLinker();
6965
FunctionDescriptor desc = FunctionDescriptor.of(ValueLayout.JAVA_LONG);
@@ -79,8 +75,9 @@ MemorySegment lookupErrnoLocation() {
7975
}
8076
}
8177

78+
@Override
8279
void initialize() {
83-
if (this.errnoLocation == null) {
80+
if (errnoLocation == null) {
8481
errnoLocation = lookupErrnoLocation();
8582
}
8683
}
@@ -90,17 +87,14 @@ private MemorySegment getErrnoLocation() {
9087
return errnoLocation;
9188
}
9289

93-
@SuppressWarnings("preview")
90+
@Override
9491
int getNativeErrno() {
9592
return getErrnoLocation().get(ValueLayout.JAVA_INT, 0);
9693
}
9794

98-
@SuppressWarnings("preview")
95+
@Override
9996
void setNativeErrno(int newErrno) {
10097
getErrnoLocation().set(ValueLayout.JAVA_INT, 0, newErrno);
10198
}
10299

103-
ErrorContext(PanamaNFIContext ctx, Thread thread) {
104-
this.ctx = ctx;
105-
}
106100
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ abstract static class SignatureExecuteNode extends RootNode {
123123
@Override
124124
public abstract Object execute(VirtualFrame frame);
125125

126-
@SuppressWarnings("preview")
127126
MemorySegment getAddress(VirtualFrame frame) {
128127
return MemorySegment.ofAddress((long) frame.getArguments()[0]);
129128
}
@@ -140,7 +139,6 @@ PanamaSignature getSig(VirtualFrame frame) {
140139
@ExplodeLoop
141140
public Object doGeneric(VirtualFrame frame) {
142141
Object[] args = getArgs(frame);
143-
@SuppressWarnings("preview")
144142
MemorySegment address = getAddress(frame);
145143
PanamaSignature signature = getSig(frame);
146144

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.truffle.nfi.backend.panama;
42+
43+
import com.oracle.truffle.api.TruffleLanguage.Env;
44+
import com.oracle.truffle.nfi.backend.spi.NFIBackend;
45+
46+
public abstract class PanamaAccessor {
47+
48+
private PanamaAccessor() {
49+
// No instances.
50+
}
51+
52+
static boolean isSupported() {
53+
return true;
54+
}
55+
56+
static NFIBackend createNFIBackend(PanamaNFILanguage language) {
57+
return new PanamaNFIBackend(language);
58+
}
59+
60+
static AbstractPanamaNFIContext createPanamaNFIContext(PanamaNFILanguage language, Env env) {
61+
return new PanamaNFIContext(language, env);
62+
}
63+
64+
static AbstractErrorContext createErrorContext() {
65+
return new ErrorContext();
66+
}
67+
68+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272

7373
@ExportLibrary(InteropLibrary.class)
7474
final class PanamaClosure implements TruffleObject {
75-
@SuppressWarnings("preview") final MemorySegment symbol;
75+
final MemorySegment symbol;
7676

77-
PanamaClosure(@SuppressWarnings("preview") MemorySegment symbol) {
77+
PanamaClosure(MemorySegment symbol) {
7878
this.symbol = symbol;
7979
}
8080

@@ -239,7 +239,7 @@ public Object execute(VirtualFrame frame) {
239239
// to avoid the JVM clobbering it
240240
PanamaNFILanguage language = PanamaNFILanguage.get(this);
241241
NFIState nfiState = language.getNFIState();
242-
ErrorContext ctx = language.errorContext.get();
242+
ErrorContext ctx = (ErrorContext) language.errorContext.get();
243243
nfiState.setNFIErrno(ctx.getNativeErrno());
244244
try {
245245
Object ret = callClosure.execute(frame);
@@ -290,7 +290,7 @@ public Object execute(VirtualFrame frame) {
290290
// to avoid the JVM clobbering it
291291
PanamaNFILanguage language = PanamaNFILanguage.get(this);
292292
NFIState nfiState = language.getNFIState();
293-
ErrorContext ctx = language.errorContext.get();
293+
ErrorContext ctx = (ErrorContext) language.errorContext.get();
294294
nfiState.setNFIErrno(ctx.getNativeErrno());
295295
try {
296296
callClosure.execute(frame);
@@ -337,7 +337,7 @@ public Object execute(VirtualFrame frame) {
337337
// to avoid the JVM clobbering it
338338
PanamaNFILanguage language = PanamaNFILanguage.get(this);
339339
NFIState nfiState = language.getNFIState();
340-
ErrorContext ctx = language.errorContext.get();
340+
ErrorContext ctx = (ErrorContext) language.errorContext.get();
341341
nfiState.setNFIErrno(ctx.getNativeErrno());
342342
try {
343343
Object ret = callClosure.execute(frame);

0 commit comments

Comments
 (0)