Skip to content

Commit b2dacd6

Browse files
committed
[GR-64941] Consolidate Native Image JNI classes after JDK 21 drop
PullRequest: graal/20965
2 parents 4372d25 + f14dce0 commit b2dacd6

File tree

8 files changed

+37
-174
lines changed

8 files changed

+37
-174
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.svm.core.jni.headers.JNIInvokeInterface;
4545
import com.oracle.svm.core.jni.headers.JNIJavaVM;
4646
import com.oracle.svm.core.jni.headers.JNINativeInterface;
47-
import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDKLatest;
4847
import com.oracle.svm.core.util.VMError;
4948

5049
import jdk.graal.compiler.word.Word;
@@ -74,7 +73,7 @@ public static JNIFunctionTables singleton() {
7473
private final CIsolateData<JNIJavaVM> jniJavaVM = CIsolateDataFactory.createStruct("jniJavaVM", JNIJavaVM.class);
7574

7675
private static int getFunctionTableSize() {
77-
return SizeOf.get(JNINativeInterfaceJDKLatest.class);
76+
return SizeOf.get(JNINativeInterface.class);
7877
}
7978

8079
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
import com.oracle.svm.core.jni.headers.JNIObjectHandle;
110110
import com.oracle.svm.core.jni.headers.JNIObjectRefType;
111111
import com.oracle.svm.core.jni.headers.JNIValue;
112-
import com.oracle.svm.core.jni.headers.JNIVersionJDKLatest;
112+
import com.oracle.svm.core.jni.headers.JNIVersion;
113113
import com.oracle.svm.core.log.Log;
114114
import com.oracle.svm.core.monitor.MonitorInflationCause;
115115
import com.oracle.svm.core.monitor.MonitorSupport;
@@ -168,7 +168,7 @@ public final class JNIFunctions {
168168
@CEntryPointOptions(prologue = CEntryPointOptions.NoPrologue.class, epilogue = CEntryPointOptions.NoEpilogue.class)
169169
@Uninterruptible(reason = "No need to enter the isolate and also no way to report errors if unable to.")
170170
static int GetVersion(JNIEnvironment env) {
171-
return JNIVersionJDKLatest.JNI_VERSION_LATEST();
171+
return JNIVersion.JNI_VERSION_LATEST();
172172
}
173173

174174
/*
@@ -1623,6 +1623,17 @@ static void SetStaticDoubleField(JNIEnvironment env, JNIObjectHandle clazz, JNIF
16231623
U.putDouble(JNIAccessibleField.getStaticPrimitiveFieldsAtRuntime(fieldId), offset, value);
16241624
}
16251625

1626+
/*
1627+
* jlong GetStringUTFLengthAsLong(JNIEnv *env, jstring string);
1628+
*/
1629+
1630+
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnMinusOne.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = Publish.NotPublished)
1631+
@CEntryPointOptions(prologue = JNIEnvEnterPrologue.class, prologueBailout = ReturnMinusOneLong.class)
1632+
static long GetStringUTFLengthAsLong(JNIEnvironment env, JNIObjectHandle hstr) {
1633+
String str = JNIObjectHandles.getObject(hstr);
1634+
return Utf8.utf8LengthAsLong(str);
1635+
}
1636+
16261637
// Checkstyle: resume
16271638

16281639
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionsJDKLatest.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,4 +1479,12 @@ public interface JNINativeInterface extends PointerBase {
14791479

14801480
@CField
14811481
void setIsVirtualThread(CFunctionPointer p);
1482+
1483+
// JNI_VERSION_24
1484+
1485+
@CField
1486+
CFunctionPointer getGetStringUTFLengthAsLong();
1487+
1488+
@CField
1489+
void setGetStringUTFLengthAsLong(CFunctionPointer p);
14821490
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterfaceJDKLatest.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import org.graalvm.nativeimage.c.constant.CConstant;
2929

3030
import com.oracle.svm.core.Uninterruptible;
31+
import com.oracle.svm.core.util.BasedOnJDKFile;
3132

3233
@CContext(JNIHeaderDirectives.class)
3334
public final class JNIVersion {
3435
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
3536
public static boolean isSupported(int version, boolean builtInLibrary) {
36-
if (version == JNIVersionJDKLatest.JNI_VERSION_LATEST() || version == JNI_VERSION_21() || version == JNI_VERSION_20() || version == JNI_VERSION_19() || version == JNI_VERSION_10() ||
37-
version == JNI_VERSION_9() || version == JNI_VERSION_1_8()) {
37+
if (version == JNI_VERSION_LATEST() || version == JNI_VERSION_24() || version == JNI_VERSION_21() || version == JNI_VERSION_20() || version == JNI_VERSION_19() ||
38+
version == JNI_VERSION_10() || version == JNI_VERSION_9() || version == JNI_VERSION_1_8()) {
3839
return true;
3940
}
4041
if (builtInLibrary) {
@@ -76,6 +77,17 @@ public static boolean isSupported(int version, boolean builtInLibrary) {
7677
@CConstant
7778
public static native int JNI_VERSION_21();
7879

80+
@CConstant
81+
public static native int JNI_VERSION_24();
82+
83+
/*
84+
* GR-50948: there is not yet a JNI_VERSION_XX constant defined for JDK latest. As soon as it
85+
* gets available, the "value" property of the CConstant annotation below must be removed.
86+
*/
87+
@CConstant(value = "JNI_VERSION_24")
88+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+16/src/java.base/share/native/include/jni.h#L1994-L2006")
89+
public static native int JNI_VERSION_LATEST();
90+
7991
// Checkstyle: resume
8092

8193
private JNIVersion() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@
4343
import com.oracle.svm.core.jni.functions.JNIFunctions;
4444
import com.oracle.svm.core.jni.functions.JNIFunctions.UnimplementedWithJNIEnvArgument;
4545
import com.oracle.svm.core.jni.functions.JNIFunctions.UnimplementedWithJavaVMArgument;
46-
import com.oracle.svm.core.jni.functions.JNIFunctionsJDKLatest;
4746
import com.oracle.svm.core.jni.functions.JNIInvocationInterface;
4847
import com.oracle.svm.core.jni.headers.JNIInvokeInterface;
4948
import com.oracle.svm.core.jni.headers.JNINativeInterface;
50-
import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDKLatest;
5149
import com.oracle.svm.core.meta.MethodPointer;
5250
import com.oracle.svm.core.util.VMError;
5351
import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl;
@@ -83,7 +81,6 @@ public class JNIFunctionTablesFeature implements Feature {
8381
* for the Interface Function Table</a>
8482
*/
8583
private StructInfo functionTableMetadata;
86-
private StructInfo functionTableMetadataJDKLatest;
8784

8885
/**
8986
* Metadata about the table pointed to by the {@code JavaVM*} C pointer.
@@ -111,14 +108,12 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) {
111108
invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface);
112109
AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class);
113110
functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable);
114-
functionTableMetadataJDKLatest = (StructInfo) nativeLibraries.findElementInfo(metaAccess.lookupJavaType(JNINativeInterfaceJDKLatest.class));
115111

116112
// Manually add functions as entry points so this is only done when JNI features are enabled
117113
AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class);
118114
AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class);
119115
AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class);
120-
AnalysisType functionsJDKLatest = metaAccess.lookupJavaType(JNIFunctionsJDKLatest.class);
121-
Stream<AnalysisMethod> analysisMethods = Stream.of(invokes, functions, functionsJDKLatest, exports).flatMap(type -> Stream.of(type.getDeclaredMethods(false)));
116+
Stream<AnalysisMethod> analysisMethods = Stream.of(invokes, functions, exports).flatMap(type -> Stream.of(type.getDeclaredMethods(false)));
122117
Stream<AnalysisMethod> unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class),
123118
(AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class));
124119
Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> {
@@ -184,12 +179,6 @@ private void fillJNIFunctionsTable(CompilationAccessImpl access) {
184179
int offset = field.getOffsetInfo().getProperty();
185180
tables.initFunctionEntry(offset, getStubFunctionPointer(access, method));
186181
}
187-
HostedType functionsJDKLatest = access.getMetaAccess().lookupJavaType(JNIFunctionsJDKLatest.class);
188-
for (HostedMethod method : functionsJDKLatest.getDeclaredMethods(false)) {
189-
StructFieldInfo field = findFieldFor(functionTableMetadataJDKLatest, method.getName());
190-
int offset = field.getOffsetInfo().getProperty();
191-
tables.initFunctionEntry(offset, getStubFunctionPointer(access, method));
192-
}
193182
for (CallVariant variant : CallVariant.values()) {
194183
CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
195184
String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");

0 commit comments

Comments
 (0)