Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.vm.ci.meta.ResolvedJavaMethod;

@AutomaticallyRegisteredFeature
Expand Down Expand Up @@ -191,45 +190,33 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
* the cost of having to recreate the Locale and BaseLocale objects once when they're
* requested.
*
* On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist, so we can't reference them
* directly and have to go through reflection.
* On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist. We have to go through
* reflection to access them because analysis tools like spotbugs still run on JDK21
*/
if (JavaVersionUtil.JAVA_SPEC > 21) {
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE");
Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE");

access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> {
/*
* Executes `ReferencedKeySet.create(true,
* ReferencedKeySet.concurrentHashMapSupplier())` with reflection.
*/
Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet");
Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class);
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier");
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
});

access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> {
/*
* Executes `ReferencedKeyMap.create(true,
* ReferencedKeyMap.concurrentHashMapSupplier())` with reflection.
*/
Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap");
Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class);
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier");
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
});
} else {
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE");
Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE");

access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> {
/*
* These fields contain an instance of the declaring class (Cache). It has a default
* constructor that we can invoke to create an empty cache.
* Executes `ReferencedKeySet.create(true,
* ReferencedKeySet.concurrentHashMapSupplier())` with reflection.
*/
Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$Cache", "CACHE");
Field localeCacheField = accessImpl.findField("java.util.Locale$Cache", "LOCALECACHE");
Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet");
Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class);
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier");
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
});

access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass()));
access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass()));
}
access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> {
/*
* Executes `ReferencedKeyMap.create(true,
* ReferencedKeyMap.concurrentHashMapSupplier())` with reflection.
*/
Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap");
Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class);
Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier");
return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.jdk.JDK21OrEarlier;
import com.oracle.svm.core.jdk.JDKLatest;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.webimage.fs.WebImageNIOFileSystemProvider;
import com.oracle.svm.webimage.functionintrinsics.JSFunctionIntrinsics;
Expand Down Expand Up @@ -175,7 +173,6 @@ private long length0() {
}

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

@Substitute
@TargetElement(name = "open", onlyWith = JDK21OrEarlier.class)
public static FileChannel openJDK21(FileDescriptor fd, String path, boolean readable, boolean writable, boolean direct, Closeable parent) {
throw new UnsupportedOperationException("FileChannelImpl.open");
}

@Substitute
@TargetElement(onlyWith = JDKLatest.class)
public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, boolean sync, boolean direct, Closeable parent) {
throw new UnsupportedOperationException("FileChannelImpl.open");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,18 @@

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

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.function.BooleanSupplier;

import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK21OrEarlier;
import com.oracle.svm.webimage.substitute.WebImageUtil;

import sun.security.provider.NativePRNG;

public class WebImageSecuritySubstitutions {
}

@TargetClass(value = AccessController.class, onlyWith = JDK21OrEarlier.class)
final class Target_java_security_AccessController_Web {

/**
* We need this substitution to avoid doing a stack walk.
*/
@Substitute
static <T> T doPrivileged(PrivilegedAction<T> action,
@SuppressWarnings("unused") AccessControlContext context, @SuppressWarnings("unused") Permission... perms) {
return action.run();
}

@Substitute
static AccessControlContext getStackAccessControlContext() {
return null;
}

@Substitute
@SuppressWarnings({"deprecation", "unused"}) // deprecated starting JDK 17
static <T> T executePrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Class<?> caller) throws Throwable {
if (action == null) {
throw new NullPointerException("Null action");
}

if (action == null) {
throw new NullPointerException("Null action");
}

return action.run();
}

@Substitute
@SuppressWarnings({"deprecation", "unused"}) // deprecated starting JDK 17
static <T> T executePrivileged(PrivilegedAction<T> action, AccessControlContext context, Class<?> caller) throws Throwable {
if (action == null) {
throw new NullPointerException("Null action");
}

return action.run();
}
}

// Windows does not have a NativePRNG implementation
@TargetClass(value = NativePRNG.class, onlyWith = IsUnix.class)
@SuppressWarnings("all")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.jdk.JDK21OrEarlier;
import com.oracle.svm.core.jdk.JDKLatest;

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

@Substitute
@TargetElement(onlyWith = JDK21OrEarlier.class)
static void futimes(int fd, long times0, long times1) {
throw new UnsupportedOperationException("UnixNativeDispatcher.futimes");
}

@Substitute
static void fchmod(int fd, int mode) {
throw new UnsupportedOperationException("UnixNativeDispatcher.fchmod");
Expand Down Expand Up @@ -160,31 +151,11 @@ static int fgetxattr0(int filedes, long nameAddress, long valueAddress, int valu
}

@Substitute
@TargetElement(onlyWith = JDKLatest.class, name = "access0")
static int access0JDK23(long pathAddress, int amode) {
throw new UnsupportedOperationException("UnixNativeDispatcher.access0");
}

@Substitute
@TargetElement(onlyWith = JDK21OrEarlier.class)
static void access0(long pathAddress, int amode) {
static int access0(long pathAddress, int amode) {
throw new UnsupportedOperationException("UnixNativeDispatcher.access0");
}

@Substitute
@TargetElement(onlyWith = JDK21OrEarlier.class)
static boolean exists0(long pathAddress) {
throw new UnsupportedOperationException("UnixNativeDispatcher.exists0");
}

@Substitute
@TargetElement(onlyWith = JDK21OrEarlier.class)
static void utimes0(long pathAddress, long times0, long times1) {
throw new UnsupportedOperationException("UnixNativeDispatcher.utimes0");
}

@Substitute
@TargetElement(onlyWith = JDKLatest.class)
private static void utimensat0(int fd, long pathAddress, long times0, long times1, int flags) {
throw new UnsupportedOperationException("UnixNativeDispatcher.utimensat0");
}
Expand Down Expand Up @@ -219,12 +190,6 @@ static void mknod0(long pathAddress, int mode, long dev) {
throw new UnsupportedOperationException("UnixNativeDispatcher.mknod0");
}

@Substitute
@TargetElement(onlyWith = JDK21OrEarlier.class)
static void lutimes0(long pathAddress, long times0, long times1) {
throw new UnsupportedOperationException("UnixNativeDispatcher.lutimes0");
}

@Substitute
static void lchown0(long pathAddress, int uid, int gid) {
throw new UnsupportedOperationException("UnixNativeDispatcher.lchown0");
Expand Down
Loading