Skip to content

Commit 8acbbf8

Browse files
committed
[GR-64960] Remove JDK 21 specific code from Web Image
PullRequest: graal/20796
2 parents 8983aa7 + 348d68c commit 8acbbf8

File tree

4 files changed

+24
-130
lines changed

4 files changed

+24
-130
lines changed

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
import jdk.graal.compiler.graph.Node;
114114
import jdk.graal.compiler.options.OptionValues;
115115
import jdk.graal.compiler.phases.util.Providers;
116-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
117116
import jdk.vm.ci.meta.ResolvedJavaMethod;
118117

119118
@AutomaticallyRegisteredFeature
@@ -192,45 +191,33 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
192191
* the cost of having to recreate the Locale and BaseLocale objects once when they're
193192
* requested.
194193
*
195-
* On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist, so we can't reference them
196-
* directly and have to go through reflection.
194+
* On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist. We have to go through
195+
* reflection to access them because analysis tools like spotbugs still run on JDK21
197196
*/
198-
if (JavaVersionUtil.JAVA_SPEC > 21) {
199-
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE");
200-
Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE");
201-
202-
access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> {
203-
/*
204-
* Executes `ReferencedKeySet.create(true,
205-
* ReferencedKeySet.concurrentHashMapSupplier())` with reflection.
206-
*/
207-
Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet");
208-
Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class);
209-
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier");
210-
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
211-
});
212-
213-
access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> {
214-
/*
215-
* Executes `ReferencedKeyMap.create(true,
216-
* ReferencedKeyMap.concurrentHashMapSupplier())` with reflection.
217-
*/
218-
Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap");
219-
Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class);
220-
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier");
221-
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
222-
});
223-
} else {
197+
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE");
198+
Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE");
199+
200+
access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> {
224201
/*
225-
* These fields contain an instance of the declaring class (Cache). It has a default
226-
* constructor that we can invoke to create an empty cache.
202+
* Executes `ReferencedKeySet.create(true,
203+
* ReferencedKeySet.concurrentHashMapSupplier())` with reflection.
227204
*/
228-
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$Cache", "CACHE");
229-
Field localeCacheField = accessImpl.findField("java.util.Locale$Cache", "LOCALECACHE");
205+
Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet");
206+
Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class);
207+
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier");
208+
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
209+
});
230210

231-
access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass()));
232-
access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass()));
233-
}
211+
access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> {
212+
/*
213+
* Executes `ReferencedKeyMap.create(true,
214+
* ReferencedKeyMap.concurrentHashMapSupplier())` with reflection.
215+
*/
216+
Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap");
217+
Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class);
218+
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier");
219+
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
220+
});
234221
}
235222

236223
@Override

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageIOSubstitutions.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import com.oracle.svm.core.annotate.Substitute;
5353
import com.oracle.svm.core.annotate.TargetClass;
5454
import com.oracle.svm.core.annotate.TargetElement;
55-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
56-
import com.oracle.svm.core.jdk.JDKLatest;
5755
import com.oracle.svm.core.util.VMError;
5856
import com.oracle.svm.webimage.fs.WebImageNIOFileSystemProvider;
5957
import com.oracle.svm.webimage.functionintrinsics.JSFunctionIntrinsics;
@@ -175,7 +173,6 @@ private long length0() {
175173
}
176174

177175
@Substitute
178-
@TargetElement(onlyWith = JDKLatest.class)
179176
@SuppressWarnings({"static-method"})
180177
private boolean isRegularFile() {
181178
return !fd.equals(FileDescriptor.in);
@@ -414,13 +411,6 @@ public int read(ByteBuffer var1) throws IOException {
414411
}
415412

416413
@Substitute
417-
@TargetElement(name = "open", onlyWith = JDK21OrEarlier.class)
418-
public static FileChannel openJDK21(FileDescriptor fd, String path, boolean readable, boolean writable, boolean direct, Closeable parent) {
419-
throw new UnsupportedOperationException("FileChannelImpl.open");
420-
}
421-
422-
@Substitute
423-
@TargetElement(onlyWith = JDKLatest.class)
424414
public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, boolean sync, boolean direct, Closeable parent) {
425415
throw new UnsupportedOperationException("FileChannelImpl.open");
426416
}

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageSecuritySubstitutions.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,66 +25,18 @@
2525

2626
package com.oracle.svm.webimage.substitute.system;
2727

28-
import java.security.AccessControlContext;
29-
import java.security.AccessController;
30-
import java.security.Permission;
31-
import java.security.PrivilegedAction;
32-
import java.security.PrivilegedExceptionAction;
3328
import java.util.function.BooleanSupplier;
3429

3530
import com.oracle.svm.core.annotate.Delete;
3631
import com.oracle.svm.core.annotate.Substitute;
3732
import com.oracle.svm.core.annotate.TargetClass;
38-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
3933
import com.oracle.svm.webimage.substitute.WebImageUtil;
4034

4135
import sun.security.provider.NativePRNG;
4236

4337
public class WebImageSecuritySubstitutions {
4438
}
4539

46-
@TargetClass(value = AccessController.class, onlyWith = JDK21OrEarlier.class)
47-
final class Target_java_security_AccessController_Web {
48-
49-
/**
50-
* We need this substitution to avoid doing a stack walk.
51-
*/
52-
@Substitute
53-
static <T> T doPrivileged(PrivilegedAction<T> action,
54-
@SuppressWarnings("unused") AccessControlContext context, @SuppressWarnings("unused") Permission... perms) {
55-
return action.run();
56-
}
57-
58-
@Substitute
59-
static AccessControlContext getStackAccessControlContext() {
60-
return null;
61-
}
62-
63-
@Substitute
64-
@SuppressWarnings({"deprecation", "unused"}) // deprecated starting JDK 17
65-
static <T> T executePrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Class<?> caller) throws Throwable {
66-
if (action == null) {
67-
throw new NullPointerException("Null action");
68-
}
69-
70-
if (action == null) {
71-
throw new NullPointerException("Null action");
72-
}
73-
74-
return action.run();
75-
}
76-
77-
@Substitute
78-
@SuppressWarnings({"deprecation", "unused"}) // deprecated starting JDK 17
79-
static <T> T executePrivileged(PrivilegedAction<T> action, AccessControlContext context, Class<?> caller) throws Throwable {
80-
if (action == null) {
81-
throw new NullPointerException("Null action");
82-
}
83-
84-
return action.run();
85-
}
86-
}
87-
8840
// Windows does not have a NativePRNG implementation
8941
@TargetClass(value = NativePRNG.class, onlyWith = IsUnix.class)
9042
@SuppressWarnings("all")

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageUnixIOSubstitutions.java

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232

3333
import com.oracle.svm.core.annotate.Substitute;
3434
import com.oracle.svm.core.annotate.TargetClass;
35-
import com.oracle.svm.core.annotate.TargetElement;
36-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
37-
import com.oracle.svm.core.jdk.JDKLatest;
3835

3936
/*
4037
* Checkstyle: stop method name check
@@ -83,12 +80,6 @@ static void unlink0(long l) {
8380
throw new UnsupportedOperationException("UnixNativeDispatcher.unlink");
8481
}
8582

86-
@Substitute
87-
@TargetElement(onlyWith = JDK21OrEarlier.class)
88-
static void futimes(int fd, long times0, long times1) {
89-
throw new UnsupportedOperationException("UnixNativeDispatcher.futimes");
90-
}
91-
9283
@Substitute
9384
static void fchmod(int fd, int mode) {
9485
throw new UnsupportedOperationException("UnixNativeDispatcher.fchmod");
@@ -160,31 +151,11 @@ static int fgetxattr0(int filedes, long nameAddress, long valueAddress, int valu
160151
}
161152

162153
@Substitute
163-
@TargetElement(onlyWith = JDKLatest.class, name = "access0")
164-
static int access0JDK23(long pathAddress, int amode) {
165-
throw new UnsupportedOperationException("UnixNativeDispatcher.access0");
166-
}
167-
168-
@Substitute
169-
@TargetElement(onlyWith = JDK21OrEarlier.class)
170-
static void access0(long pathAddress, int amode) {
154+
static int access0(long pathAddress, int amode) {
171155
throw new UnsupportedOperationException("UnixNativeDispatcher.access0");
172156
}
173157

174158
@Substitute
175-
@TargetElement(onlyWith = JDK21OrEarlier.class)
176-
static boolean exists0(long pathAddress) {
177-
throw new UnsupportedOperationException("UnixNativeDispatcher.exists0");
178-
}
179-
180-
@Substitute
181-
@TargetElement(onlyWith = JDK21OrEarlier.class)
182-
static void utimes0(long pathAddress, long times0, long times1) {
183-
throw new UnsupportedOperationException("UnixNativeDispatcher.utimes0");
184-
}
185-
186-
@Substitute
187-
@TargetElement(onlyWith = JDKLatest.class)
188159
private static void utimensat0(int fd, long pathAddress, long times0, long times1, int flags) {
189160
throw new UnsupportedOperationException("UnixNativeDispatcher.utimensat0");
190161
}
@@ -219,12 +190,6 @@ static void mknod0(long pathAddress, int mode, long dev) {
219190
throw new UnsupportedOperationException("UnixNativeDispatcher.mknod0");
220191
}
221192

222-
@Substitute
223-
@TargetElement(onlyWith = JDK21OrEarlier.class)
224-
static void lutimes0(long pathAddress, long times0, long times1) {
225-
throw new UnsupportedOperationException("UnixNativeDispatcher.lutimes0");
226-
}
227-
228193
@Substitute
229194
static void lchown0(long pathAddress, int uid, int gid) {
230195
throw new UnsupportedOperationException("UnixNativeDispatcher.lchown0");

0 commit comments

Comments
 (0)