Skip to content

Commit 4743a57

Browse files
committed
Prune classloading-logic out of libgraal image
1 parent 2348c9c commit 4743a57

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalSubstitutions.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
*/
2525
package jdk.graal.compiler.libgraal;
2626

27+
import java.util.Collections;
28+
import java.util.Set;
29+
2730
import com.oracle.svm.core.annotate.Alias;
2831
import com.oracle.svm.core.annotate.RecomputeFieldValue;
32+
import com.oracle.svm.core.annotate.Substitute;
2933
import com.oracle.svm.core.annotate.TargetClass;
3034

3135
class LibGraalSubstitutions {
@@ -54,4 +58,49 @@ static final class Target_jdk_vm_ci_hotspot_Cleaner {
5458
@Alias
5559
public static native void clean();
5660
}
61+
62+
/*
63+
* There are no String-based class-lookups happening at libgraal runtime. Thus, we can safely
64+
* prune all classloading-logic out of the image.
65+
*/
66+
@TargetClass(value = java.lang.Class.class, onlyWith = LibGraalFeature.IsEnabled.class)
67+
static final class Target_java_lang_Class {
68+
@Substitute
69+
public static Class<?> forName(String name, boolean initialize, ClassLoader loader)
70+
throws ClassNotFoundException {
71+
throw new ClassNotFoundException(name);
72+
}
73+
74+
@Substitute
75+
private static Class<?> forName(String className, Class<?> caller)
76+
throws ClassNotFoundException {
77+
throw new ClassNotFoundException(className);
78+
}
79+
80+
@Substitute
81+
public static Class<?> forName(Module module, String name) {
82+
return null;
83+
}
84+
}
85+
86+
@TargetClass(value = java.lang.Module.class, onlyWith = LibGraalFeature.IsEnabled.class)
87+
static final class Target_java_lang_Module {
88+
@Substitute
89+
public Set<String> getPackages() {
90+
return Collections.emptySet();
91+
}
92+
}
93+
94+
@TargetClass(value = java.lang.ClassLoader.class, onlyWith = LibGraalFeature.IsEnabled.class)
95+
static final class Target_java_lang_ClassLoader {
96+
@Substitute
97+
public Class<?> loadClass(String name) throws ClassNotFoundException {
98+
throw new ClassNotFoundException(name);
99+
}
100+
101+
@Substitute
102+
static Class<?> findBootstrapClassOrNull(String name) {
103+
return null;
104+
}
105+
}
57106
}

0 commit comments

Comments
 (0)