From 5f2494396766fb86ee1a2bfc226d0d4c1095ff21 Mon Sep 17 00:00:00 2001 From: jvukicev Date: Tue, 29 Jul 2025 16:34:18 +0200 Subject: [PATCH 1/3] Introduce NeverInlineTrivial option and fix -H:TrackDynamicAccess=all gathering entries from non-application class and module paths --- .../src/com/oracle/svm/core/SubstrateOptions.java | 3 +++ .../oracle/svm/hosted/DynamicAccessDetectionFeature.java | 6 +++--- .../src/com/oracle/svm/hosted/SVMHost.java | 9 +++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) 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 934259f4c1c2..82fbdfdb2163 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 @@ -913,6 +913,9 @@ public static long getTearDownFailureNanos() { @Option(help = "file:doc-files/NeverInlineHelp.txt", type = OptionType.Debug)// public static final HostedOptionKey NeverInline = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); + @Option(help = "Never trivially inline provided methods. Uses the same method pattern syntax as the 'NeverInline' option.")// + public static final HostedOptionKey NeverInlineTrivial = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); + @Option(help = "Maximum number of nodes in a method so that it is considered trivial.")// public static final HostedOptionKey MaxNodesInTrivialMethod = new HostedOptionKey<>(20); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java index 837adeb26e98..06cc1d5dc228 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java @@ -99,7 +99,7 @@ public ConcurrentLinkedQueue getMethodCallLocations(String methodName) { } } - private static final Set neverInlineMethods = Set.of( + private static final Set neverInlineTrivialMethods = Set.of( "java.lang.invoke.MethodHandles$Lookup.unreflectGetter", "java.lang.invoke.MethodHandles$Lookup.unreflectSetter", "java.io.ObjectInputStream.readObject", @@ -363,8 +363,8 @@ public static void parseDynamicAccessOptions(EconomicMap, Object> h } }); if (!classLoaderSupport.dynamicAccessSelectorsEmpty()) { - for (String method : neverInlineMethods) { - SubstrateOptions.NeverInline.update(hostedValues, method); + for (String method : neverInlineTrivialMethods) { + SubstrateOptions.NeverInlineTrivial.update(hostedValues, method); } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index afca15548259..bb4d27e77da9 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -829,7 +829,9 @@ public boolean hasNeverInlineDirective(ResolvedJavaMethod method) { return false; } - return SubstrateOptions.NeverInline.getValue().values().stream().anyMatch(re -> MethodFilter.parse(re).matches(method)); + return SubstrateOptions.NeverInline.getValue().values().stream() + .map(MethodFilter::parse) + .anyMatch(filter -> filter.matches(method)); } private InlineBeforeAnalysisPolicy inlineBeforeAnalysisPolicy(MultiMethod.MultiMethodKey multiMethodKey) { @@ -1108,7 +1110,10 @@ public boolean neverInlineTrivial(AnalysisMethod caller, AnalysisMethod callee) return true; } } - return false; + if (!SubstrateOptions.NeverInlineTrivial.hasBeenSet()) { + return false; + } + return SubstrateOptions.NeverInlineTrivial.getValue().values().stream().anyMatch(re -> MethodFilter.parse(re).matches(callee)); } private static boolean shouldEvaluateNeverInlineTrivialOnlyWith(Class[] onlyWith) { From 09df29fe2cb861c2757f8a120a0431b6e8e0e2f6 Mon Sep 17 00:00:00 2001 From: jvukicev Date: Fri, 1 Aug 2025 09:32:13 +0200 Subject: [PATCH 2/3] Update docs --- .../com/oracle/svm/core/SubstrateOptions.java | 2 +- .../core/doc-files/NeverInlineTrivialHelp.txt | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt 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 82fbdfdb2163..06662c95a4ea 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 @@ -913,7 +913,7 @@ public static long getTearDownFailureNanos() { @Option(help = "file:doc-files/NeverInlineHelp.txt", type = OptionType.Debug)// public static final HostedOptionKey NeverInline = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); - @Option(help = "Never trivially inline provided methods. Uses the same method pattern syntax as the 'NeverInline' option.")// + @Option(help = "file:doc-files/NeverInlineTrivialHelp.txt")// public static final HostedOptionKey NeverInlineTrivial = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); @Option(help = "Maximum number of nodes in a method so that it is considered trivial.")// diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt new file mode 100644 index 000000000000..3c36eb3167b0 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt @@ -0,0 +1,40 @@ +Pattern for disabling trivial inlining of methods during image generation. +The syntax for a pattern is: + + SourcePatterns = SourcePattern ["," SourcePatterns] . + SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] . + Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" . + Class = { package "." } class . + +Glob pattern matching (*, ?) is allowed in all parts of the source pattern. + +Examples of method filters: +--------- + visit(Argument;BlockScope) + + Matches all methods named "visit", with the first parameter of + type "Argument", and the second parameter of type "BlockScope". + The packages of the parameter types are irrelevant. +--------- + arraycopy(Object;;;;) + + Matches all methods named "arraycopy", with the first parameter + of type "Object", and four more parameters of any type. The + packages of the parameter types are irrelevant. +--------- + jdk.graal.compiler.core.graph.PostOrderNodeIterator.* + + Matches all methods in the class "jdk.graal.compiler.core.graph.PostOrderNodeIterator". +--------- + * + + Matches all methods in all classes +--------- + jdk.graal.compiler.core.graph.*.visit + + Matches all methods named "visit" in classes in the package + "jdk.graal.compiler.core.graph". +--------- + arraycopy,toString + + Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an or operator. From c9f20fc4b9c62ecd412cecfbba90757a63c8a655 Mon Sep 17 00:00:00 2001 From: jvukicev Date: Fri, 1 Aug 2025 11:26:51 +0200 Subject: [PATCH 3/3] Remove duplicate docs and reference the same NeverInlineHelp.txt --- .../com/oracle/svm/core/SubstrateOptions.java | 2 +- .../core/doc-files/NeverInlineTrivialHelp.txt | 40 ------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt 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 06662c95a4ea..ccb2d42832e6 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 @@ -913,7 +913,7 @@ public static long getTearDownFailureNanos() { @Option(help = "file:doc-files/NeverInlineHelp.txt", type = OptionType.Debug)// public static final HostedOptionKey NeverInline = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); - @Option(help = "file:doc-files/NeverInlineTrivialHelp.txt")// + @Option(help = "file:doc-files/NeverInlineHelp.txt")// public static final HostedOptionKey NeverInlineTrivial = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build()); @Option(help = "Maximum number of nodes in a method so that it is considered trivial.")// diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt deleted file mode 100644 index 3c36eb3167b0..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/NeverInlineTrivialHelp.txt +++ /dev/null @@ -1,40 +0,0 @@ -Pattern for disabling trivial inlining of methods during image generation. -The syntax for a pattern is: - - SourcePatterns = SourcePattern ["," SourcePatterns] . - SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] . - Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" . - Class = { package "." } class . - -Glob pattern matching (*, ?) is allowed in all parts of the source pattern. - -Examples of method filters: ---------- - visit(Argument;BlockScope) - - Matches all methods named "visit", with the first parameter of - type "Argument", and the second parameter of type "BlockScope". - The packages of the parameter types are irrelevant. ---------- - arraycopy(Object;;;;) - - Matches all methods named "arraycopy", with the first parameter - of type "Object", and four more parameters of any type. The - packages of the parameter types are irrelevant. ---------- - jdk.graal.compiler.core.graph.PostOrderNodeIterator.* - - Matches all methods in the class "jdk.graal.compiler.core.graph.PostOrderNodeIterator". ---------- - * - - Matches all methods in all classes ---------- - jdk.graal.compiler.core.graph.*.visit - - Matches all methods named "visit" in classes in the package - "jdk.graal.compiler.core.graph". ---------- - arraycopy,toString - - Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an or operator.