Skip to content

Commit 2ad587c

Browse files
author
Christian Wimmer
committed
Allow reflection registration of all ClassLoader methods
1 parent f2b8141 commit 2ad587c

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,8 +1622,10 @@ public Optional<?> describeConstable() {
16221622
@Delete
16231623
private native Class<?>[] getInterfaces0();
16241624

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

16281630
@Delete
16291631
private native java.security.ProtectionDomain getProtectionDomain0();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ final class Target_jdk_internal_jimage_ImageReaderFactory_JRTEnabled {
136136
*/
137137
@TargetClass(className = "jdk.internal.module.SystemModuleFinders", innerClass = "SystemImage", onlyWith = {JDK11OrLater.class, JRTDisabled.class})
138138
final class Target_jdk_internal_module_SystemModuleFinders_SystemImage_JRTDisabled {
139-
@Delete
140-
static native Object reader();
139+
@Substitute
140+
static Object reader() {
141+
throw VMError.unsupportedFeature("JRT file system is disabled");
142+
}
141143
}
142144

143145
@TargetClass(className = "sun.net.www.protocol.jrt.Handler", onlyWith = {JDK11OrLater.class, JRTDisabled.class})

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.security.ProtectionDomain;
3131
import java.util.Enumeration;
3232
import java.util.HashMap;
33+
import java.util.Map;
34+
import java.util.Set;
3335
import java.util.Vector;
3436
import java.util.concurrent.ConcurrentHashMap;
3537

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

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

259+
@Delete
260+
private static native long findNative(ClassLoader loader, String entryName);
261+
254262
@Substitute
255263
@SuppressWarnings({"unused", "static-method"})
256264
Class<?> defineClass(byte[] b, int off, int len) throws ClassFormatError {
@@ -333,6 +341,41 @@ protected void resolveClass(@SuppressWarnings("unused") Class<?> c) {
333341

334342
@Delete
335343
private static native Target_java_lang_AssertionStatusDirectives retrieveDirectives();
344+
345+
/*
346+
* Ensure that fields and methods that hold state of the image generator are not reachable when
347+
* all fields or methods of the class are registered for reflection.
348+
*/
349+
350+
@Delete //
351+
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
352+
private static Set<String> loadedLibraryNames;
353+
@Delete //
354+
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
355+
private static Map<String, Target_java_lang_ClassLoader_NativeLibrary> systemNativeLibraries;
356+
@Delete //
357+
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class}) //
358+
private Map<String, Target_java_lang_ClassLoader_NativeLibrary> nativeLibraries;
359+
// Checkstyle: stop
360+
@Delete //
361+
@TargetElement(onlyWith = JDK11OrEarlier.class) //
362+
private static String[] usr_paths;
363+
@Delete //
364+
@TargetElement(onlyWith = JDK11OrEarlier.class) //
365+
private static String[] sys_paths;
366+
// Checkstyle: resume
367+
368+
@Delete
369+
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class})
370+
private native Map<String, Target_java_lang_ClassLoader_NativeLibrary> nativeLibraries();
371+
372+
@Delete
373+
@TargetElement(onlyWith = {JDK11OrLater.class, JDK11OrEarlier.class})
374+
private static native Map<String, Target_java_lang_ClassLoader_NativeLibrary> systemNativeLibraries();
375+
376+
@Delete
377+
@TargetElement(onlyWith = JDK11OrEarlier.class)
378+
private static native boolean loadLibrary0(Class<?> fromClass, File file);
336379
}
337380

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

0 commit comments

Comments
 (0)