Skip to content

Commit

Permalink
Allow reflection registration of all ClassLoader methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Wimmer committed Oct 27, 2021
1 parent f2b8141 commit 2ad587c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1622,8 +1622,10 @@ public Optional<?> describeConstable() {
@Delete
private native Class<?>[] getInterfaces0();

@Delete
native void setSigners(Object[] signers);
@Substitute
private void setSigners(@SuppressWarnings("unused") Object[] signers) {
throw VMError.unsupportedFeature("Class metadata cannot be changed at run time");
}

@Delete
private native java.security.ProtectionDomain getProtectionDomain0();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ final class Target_jdk_internal_jimage_ImageReaderFactory_JRTEnabled {
*/
@TargetClass(className = "jdk.internal.module.SystemModuleFinders", innerClass = "SystemImage", onlyWith = {JDK11OrLater.class, JRTDisabled.class})
final class Target_jdk_internal_module_SystemModuleFinders_SystemImage_JRTDisabled {
@Delete
static native Object reader();
@Substitute
static Object reader() {
throw VMError.unsupportedFeature("JRT file system is disabled");
}
}

@TargetClass(className = "sun.net.www.protocol.jrt.Handler", onlyWith = {JDK11OrLater.class, JRTDisabled.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -242,6 +244,9 @@ private void clearAssertionStatus() {
throw VMError.unsupportedFeature("The assertion status of classes is fixed at image build time.");
}

@Delete
private native void initializeJavaAssertionMaps();

/*
* We are defensive and also handle private native methods by marking them as deleted. If they
* are reachable, the user is certainly doing something wrong. But we do not want to fail with a
Expand All @@ -251,6 +256,9 @@ private void clearAssertionStatus() {
@Delete
private static native void registerNatives();

@Delete
private static native long findNative(ClassLoader loader, String entryName);

@Substitute
@SuppressWarnings({"unused", "static-method"})
Class<?> defineClass(byte[] b, int off, int len) throws ClassFormatError {
Expand Down Expand Up @@ -333,6 +341,41 @@ protected void resolveClass(@SuppressWarnings("unused") Class<?> c) {

@Delete
private static native Target_java_lang_AssertionStatusDirectives retrieveDirectives();

/*
* Ensure that fields and methods that hold state of the image generator are not reachable when
* all fields or methods of the class are registered for reflection.
*/

@Delete //
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
private static Set<String> loadedLibraryNames;
@Delete //
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
private static Map<String, Target_java_lang_ClassLoader_NativeLibrary> systemNativeLibraries;
@Delete //
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
private Map<String, Target_java_lang_ClassLoader_NativeLibrary> nativeLibraries;
// Checkstyle: stop
@Delete //
@TargetElement(onlyWith = JDK11OrEarlier.class) //
private static String[] usr_paths;
@Delete //
@TargetElement(onlyWith = JDK11OrEarlier.class) //
private static String[] sys_paths;
// Checkstyle: resume

@Delete
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class})
private native Map<String, Target_java_lang_ClassLoader_NativeLibrary> nativeLibraries();

@Delete
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class})
private static native Map<String, Target_java_lang_ClassLoader_NativeLibrary> systemNativeLibraries();

@Delete
@TargetElement(onlyWith = JDK11OrEarlier.class)
private static native boolean loadLibrary0(Class<?> fromClass, File file);
}

@TargetClass(value = ClassLoader.class, innerClass = "NativeLibrary", onlyWith = JDK11OrEarlier.class)
Expand Down

0 comments on commit 2ad587c

Please sign in to comment.