|
109 | 109 | import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
|
110 | 110 | import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin;
|
111 | 111 | import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
| 112 | +import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
112 | 113 | import org.graalvm.compiler.nodes.spi.Replacements;
|
113 | 114 | import org.graalvm.compiler.options.Option;
|
114 | 115 | import org.graalvm.compiler.options.OptionValues;
|
@@ -184,6 +185,9 @@ public String getDescription() {
|
184 | 185 | }
|
185 | 186 |
|
186 | 187 | public static class Options {
|
| 188 | + @Option(help = "Print truffle boundaries found during the analysis")// |
| 189 | + public static final HostedOptionKey<Boolean> PrintStaticTruffleBoundaries = new HostedOptionKey<>(false); |
| 190 | + |
187 | 191 | @Option(help = "Check that CompilerAsserts.neverPartOfCompilation is not reachable for runtime compilation")//
|
188 | 192 | public static final HostedOptionKey<Boolean> TruffleCheckNeverPartOfCompilation = new HostedOptionKey<>(true);
|
189 | 193 |
|
@@ -813,6 +817,10 @@ private static void collectImplementations(HostedType type, Set<HostedType> impl
|
813 | 817 |
|
814 | 818 | @Override
|
815 | 819 | public void afterAnalysis(AfterAnalysisAccess access) {
|
| 820 | + if (Options.PrintStaticTruffleBoundaries.getValue()) { |
| 821 | + printStaticTruffleBoundaries(); |
| 822 | + } |
| 823 | + |
816 | 824 | SubstrateTruffleRuntime truffleRuntime = (SubstrateTruffleRuntime) Truffle.getRuntime();
|
817 | 825 | AfterAnalysisAccessImpl config = (AfterAnalysisAccessImpl) access;
|
818 | 826 | truffleRuntime.initializeHostedKnownMethods(config.getMetaAccess());
|
@@ -844,6 +852,30 @@ public void afterAnalysis(AfterAnalysisAccess access) {
|
844 | 852 | }
|
845 | 853 | }
|
846 | 854 |
|
| 855 | + private static void printStaticTruffleBoundaries() { |
| 856 | + HashSet<ResolvedJavaMethod> foundBoundaries = new HashSet<>(); |
| 857 | + int callSiteCount = 0; |
| 858 | + int calleeCount = 0; |
| 859 | + for (CallTreeNode node : ImageSingletons.lookup(GraalFeature.class).getRuntimeCompiledMethods().values()) { |
| 860 | + StructuredGraph graph = node.getGraph(); |
| 861 | + for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) { |
| 862 | + ResolvedJavaMethod targetMethod = callTarget.targetMethod(); |
| 863 | + TruffleBoundary truffleBoundary = targetMethod.getAnnotation(TruffleBoundary.class); |
| 864 | + if (truffleBoundary != null) { |
| 865 | + ++callSiteCount; |
| 866 | + if (foundBoundaries.contains(targetMethod)) { |
| 867 | + // nothing to do |
| 868 | + } else { |
| 869 | + foundBoundaries.add(targetMethod); |
| 870 | + System.out.println("Truffle boundary found: " + targetMethod); |
| 871 | + calleeCount++; |
| 872 | + } |
| 873 | + } |
| 874 | + } |
| 875 | + } |
| 876 | + System.out.printf("Number of Truffle call boundaries: %d, number of unique called methods outside the boundary: %d%n", callSiteCount, calleeCount); |
| 877 | + } |
| 878 | + |
847 | 879 | @Override
|
848 | 880 | public void registerGraalPhases(Providers providers, SnippetReflectionProvider snippetReflection, Suites suites, boolean hosted) {
|
849 | 881 | if (hosted && TruffleHostInliningPhase.Options.TruffleHostInlining.getValue(HostedOptionValues.singleton()) && suites.getHighTier() instanceof HighTier) {
|
|
0 commit comments