Skip to content

Commit 9340c06

Browse files
committed
Use JVMCI for @delete classes
1 parent 721466c commit 9340c06

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
143143
@Option(help = "Allow MethodTypeFlow to see @Fold methods")//
144144
public static final HostedOptionKey<Boolean> AllowFoldMethods = new HostedOptionKey<>(false);
145145

146-
@APIOption(name = "report-unsupported-elements-at-runtime", deprecated = "The flag is not needed anymore as usage of unsupported elements is now reported at run time by default.")//
146+
@APIOption(name = "report-unsupported-elements-at-runtime", deprecated = "The option is deprecated and will be removed in the future. The use of unsupported elements is always reported at run time.")//
147147
@Option(help = "Report usage of unsupported methods and fields at run time when they are accessed the first time, instead of as an error during image building", type = Debug)//
148148
public static final HostedOptionKey<Boolean> ReportUnsupportedElementsAtRuntime = new HostedOptionKey<>(true);
149149

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -585,23 +585,30 @@ private static boolean hasDefaultValue(Field annotatedField) {
585585

586586
private void handleDeletedClass(Class<?> originalClass, Delete deleteAnnotation) {
587587
if (NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
588-
/*
589-
* We register all methods and fields as deleted. That still allows usage of the type in
590-
* type checks.
591-
*/
592-
for (Executable m : originalClass.getDeclaredMethods()) {
593-
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
594-
registerAsDeleted(null, method, deleteAnnotation);
595-
}
596-
for (Executable m : originalClass.getDeclaredConstructors()) {
597-
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
598-
registerAsDeleted(null, method, deleteAnnotation);
599-
}
600-
for (Field f : originalClass.getDeclaredFields()) {
601-
ResolvedJavaField field = metaAccess.lookupJavaField(f);
602-
registerAsDeleted(null, field, deleteAnnotation);
588+
try {
589+
/*
590+
* We register all methods and fields as deleted. That still allows usage of the
591+
* type in type checks.
592+
*/
593+
ResolvedJavaType type = metaAccess.lookupJavaType(originalClass);
594+
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
595+
registerAsDeleted(null, method, deleteAnnotation);
596+
}
597+
for (ResolvedJavaMethod constructor : type.getDeclaredConstructors()) {
598+
registerAsDeleted(null, constructor, deleteAnnotation);
599+
}
600+
for (ResolvedJavaField f : type.getInstanceFields(false)) {
601+
registerAsDeleted(null, f, deleteAnnotation);
602+
}
603+
for (ResolvedJavaField f : type.getStaticFields()) {
604+
registerAsDeleted(null, f, deleteAnnotation);
605+
}
606+
} catch (LinkageError ignored) {
607+
/*
608+
* Type that can't be linked doesn't need elements replaced: it will simply fail at
609+
* runtime with the same linkage error before reaching those elements.
610+
*/
603611
}
604-
605612
} else {
606613
deleteAnnotations.put(metaAccess.lookupJavaType(originalClass), deleteAnnotation);
607614
}

0 commit comments

Comments
 (0)