From bbba6e1a6acdf55beb857f1442a6b321bd5a1c3f Mon Sep 17 00:00:00 2001 From: Vojin Jovanovic Date: Mon, 29 Apr 2024 19:42:53 +0200 Subject: [PATCH] Use JVMCI for @Delete classes (cherry picked from commit 30ae9d3c8dce269e1bcb9f1a090fddfff7d8eea4) --- .../AnnotationSubstitutionProcessor.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java index 8f35f4f73891..687344c79623 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java @@ -635,23 +635,35 @@ private static boolean hasDefaultValue(Field annotatedField) { private void handleDeletedClass(Class originalClass, Delete deleteAnnotation) { if (NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) { + ResolvedJavaType type = metaAccess.lookupJavaType(originalClass); + + try { + type.link(); + } catch (LinkageError ignored) { + /* + * Ignore any linking errors. A type that cannot be linked doesn't need elements + * replaced: it will simply fail at runtime with the same linkage error before + * reaching those elements. + */ + return; + } + /* * We register all methods and fields as deleted. That still allows usage of the type in * type checks. */ - for (Executable m : originalClass.getDeclaredMethods()) { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); + for (ResolvedJavaMethod method : type.getDeclaredMethods()) { registerAsDeleted(null, method, deleteAnnotation); } - for (Executable m : originalClass.getDeclaredConstructors()) { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); - registerAsDeleted(null, method, deleteAnnotation); + for (ResolvedJavaMethod constructor : type.getDeclaredConstructors()) { + registerAsDeleted(null, constructor, deleteAnnotation); } - for (Field f : originalClass.getDeclaredFields()) { - ResolvedJavaField field = metaAccess.lookupJavaField(f); - registerAsDeleted(null, field, deleteAnnotation); + for (ResolvedJavaField f : type.getInstanceFields(false)) { + registerAsDeleted(null, f, deleteAnnotation); + } + for (ResolvedJavaField f : type.getStaticFields()) { + registerAsDeleted(null, f, deleteAnnotation); } - } else { deleteAnnotations.put(metaAccess.lookupJavaType(originalClass), deleteAnnotation); }