Skip to content

Commit 47ad520

Browse files
committed
Exclude substituted class from build time initialization
The class substituted with @substitute or @delete annotation should not be initialized at build time because it will not appear in the run time. It makes no sense to put it in the native heap but causing initialization errors.
1 parent 9d0a251 commit 47ad520

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.hosted.classinitialization;
2626

27+
import java.lang.annotation.Annotation;
2728
import java.util.Collection;
2829
import java.util.Collections;
2930
import java.util.HashMap;
@@ -36,10 +37,14 @@
3637
import com.oracle.graal.pointsto.meta.AnalysisMethod;
3738
import com.oracle.graal.pointsto.meta.AnalysisType;
3839
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
40+
import com.oracle.svm.core.annotate.Delete;
41+
import com.oracle.svm.core.annotate.Substitute;
3942
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
4043
import com.oracle.svm.hosted.SVMHost;
4144
import com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin;
4245
import com.oracle.svm.hosted.substitute.SubstitutionMethod;
46+
import com.oracle.svm.hosted.substitute.SubstitutionType;
47+
import jdk.vm.ci.meta.ResolvedJavaType;
4348

4449
/**
4550
* Keeps a type-hierarchy dependency graph for {@link AnalysisType}s from {@code universe}. Each
@@ -216,7 +221,18 @@ private boolean isInvokeUnsafeIterative(InvokeTypeFlow i) {
216221
}
217222

218223
private void addInitializer(AnalysisType t) {
219-
types.put(t, initialTypeInitializerSafety(t));
224+
ResolvedJavaType rt = t.getWrappedWithoutResolve();
225+
boolean isSubstituted = false;
226+
if (rt instanceof SubstitutionType) {
227+
SubstitutionType substitutionType = (SubstitutionType) rt;
228+
for (Annotation annotation : substitutionType.getAnnotations()) {
229+
if (annotation instanceof Substitute || annotation instanceof Delete) {
230+
isSubstituted = true;
231+
break;
232+
}
233+
}
234+
}
235+
types.put(t, isSubstituted ? Safety.UNSAFE :initialTypeInitializerSafety(t));
220236
dependencies.put(t, new HashSet<>());
221237
}
222238

0 commit comments

Comments
 (0)