Skip to content

Commit

Permalink
Use JVMCI for @delete classes
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed May 13, 2024
1 parent 1ebbcbd commit 83c7648
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
@Option(help = "Allow MethodTypeFlow to see @Fold methods")//
public static final HostedOptionKey<Boolean> AllowFoldMethods = new HostedOptionKey<>(false);

@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.")//
@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.")//
@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)//
public static final HostedOptionKey<Boolean> ReportUnsupportedElementsAtRuntime = new HostedOptionKey<>(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,23 +585,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);
}
Expand Down

0 comments on commit 83c7648

Please sign in to comment.