From 65e51884595a88cfb9a8ba6d0d9dc81bed6b3c44 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Sun, 22 Sep 2024 08:38:36 -0700 Subject: [PATCH] Add option to disable substitutions --- .../src/com/oracle/svm/core/SubstrateOptions.java | 6 ++++++ .../AnnotationSubstitutionProcessor.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 5892e0c57bad..effbce4e3e47 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -570,6 +570,12 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap, Object @Option(help = "Verify naming conventions during image construction.")// public static final HostedOptionKey VerifyNamingConventions = new HostedOptionKey<>(false); + @Option(help = "Disable the substitutions matched by the option value. " + + "A value can be a fully qualified method name with parameter list, a fully qualified method name without parameter list, or a fully qualified type name. " + + "When multiple methods match a value, then all matching substitutions are disabled.")// + public static final HostedOptionKey DisableSubstitution = new HostedOptionKey<>( + AccumulatingLocatableMultiOptionValue.Strings.build()); + @Option(help = "Deprecated, has no effect.", deprecated = true) // public static final HostedOptionKey MultiThreaded = new HostedOptionKey<>(true); 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 7a75a3ec2e82..baee27b1bf5e 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 @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BooleanSupplier; import java.util.function.Function; @@ -116,6 +117,7 @@ public class AnnotationSubstitutionProcessor extends SubstitutionProcessor { private final Map fieldSubstitutions; private Map unsafeAccessedFields = new HashMap<>(); private final ClassInitializationSupport classInitializationSupport; + private final Set disabledSubstitutions; public AnnotationSubstitutionProcessor(ImageClassLoader imageClassLoader, MetaAccessProvider metaAccess, ClassInitializationSupport classInitializationSupport) { this.imageClassLoader = imageClassLoader; @@ -127,6 +129,7 @@ public AnnotationSubstitutionProcessor(ImageClassLoader imageClassLoader, MetaAc methodSubstitutions = new ConcurrentHashMap<>(); polymorphicMethodSubstitutions = new HashMap<>(); fieldSubstitutions = new ConcurrentHashMap<>(); + disabledSubstitutions = Set.copyOf(SubstrateOptions.DisableSubstitution.getValue().values()); } @Override @@ -422,6 +425,18 @@ private void handleMethodInAliasClass(Executable annotatedMethod, Class origi return; } + if (!disabledSubstitutions.isEmpty()) { + /* + * Substitutions can be disabled on the command line. The three formats to match are + * specified in the help text of the option DisableSubstitution. + */ + if (disabledSubstitutions.contains(annotated.format("%H")) || + disabledSubstitutions.contains(annotated.format("%H.%n")) || + disabledSubstitutions.contains(annotated.format("%H.%n(%P)"))) { + return; + } + } + if (deleteAnnotation != null) { if (SubstrateOptions.VerifyNamingConventions.getValue()) { int modifiers = original.getModifiers();