Skip to content

Commit

Permalink
[GR-37501] Move TRUFFLE_API dependency to com.oracle.svm.truffle proj…
Browse files Browse the repository at this point in the history
…ect.

PullRequest: graal/11821
  • Loading branch information
pejovica committed May 26, 2022
2 parents bb50c72 + 36afea0 commit 7aaa527
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
5 changes: 1 addition & 4 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.hosted",
"truffle:TRUFFLE_API",
],
"requiresConcealed" : {
"java.base" : [
Expand Down Expand Up @@ -882,6 +881,7 @@
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.graal",
"truffle:TRUFFLE_API",
],
"requiresConcealed" : {
"java.base" : [
Expand All @@ -902,9 +902,6 @@
"dependencies": [
"com.oracle.svm.truffle",
],
"requires": [
"jdk.unsupported", # workaround to make TRUFFLE_DSL_PROCESSOR work with ECJ
],
"checkstyle": "com.oracle.svm.hosted",
"javaCompliance": "11+",
"annotationProcessors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
import com.oracle.svm.hosted.phases.StrengthenStampsPhase;
import com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin;
import com.oracle.svm.hosted.phases.SubstrateGraphBuilderPhase;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;

import jdk.vm.ci.meta.DeoptimizationAction;
import jdk.vm.ci.meta.DeoptimizationReason;
Expand All @@ -157,9 +156,6 @@ public static class Options {
@Option(help = "Print call tree of methods available for runtime compilation")//
public static final HostedOptionKey<Boolean> PrintRuntimeCompileMethods = new HostedOptionKey<>(false);

@Option(help = "Print truffle boundaries found during the analysis")//
public static final HostedOptionKey<Boolean> PrintStaticTruffleBoundaries = new HostedOptionKey<>(false);

@Option(help = "Maximum number of methods allowed for runtime compilation.")//
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> MaxRuntimeCompileMethods = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());

Expand Down Expand Up @@ -657,10 +653,6 @@ public void beforeCompilation(BeforeCompilationAccess c) {
printCallTree();
}

if (Options.PrintStaticTruffleBoundaries.getValue()) {
printStaticTruffleBoundaries();
}

int maxMethods = 0;
for (String value : Options.MaxRuntimeCompileMethods.getValue().values()) {
String numberStr = null;
Expand Down Expand Up @@ -830,30 +822,6 @@ private void printDeepestLevelPath() {
}
}

private void printStaticTruffleBoundaries() {
HashSet<ResolvedJavaMethod> foundBoundaries = new HashSet<>();
int callSiteCount = 0;
int calleeCount = 0;
for (CallTreeNode node : methods.values()) {
StructuredGraph graph = node.graph;
for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
TruffleBoundary truffleBoundary = targetMethod.getAnnotation(TruffleBoundary.class);
if (truffleBoundary != null) {
++callSiteCount;
if (foundBoundaries.contains(targetMethod)) {
// nothing to do
} else {
foundBoundaries.add(targetMethod);
System.out.println("Truffle boundary found: " + targetMethod);
calleeCount++;
}
}
}
}
System.out.println(String.format("Number of Truffle call boundaries: %d, number of unique called methods outside the boundary: %d", callSiteCount, calleeCount));
}

private void printCallTree() {
System.out.println("depth;method;Graal nodes;invoked from source;full method name;full name of invoked virtual method");
for (CallTreeNode node : methods.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
import org.graalvm.compiler.nodes.spi.Replacements;
import org.graalvm.compiler.options.Option;
import org.graalvm.compiler.options.OptionValues;
Expand Down Expand Up @@ -184,6 +185,9 @@ public String getDescription() {
}

public static class Options {
@Option(help = "Print truffle boundaries found during the analysis")//
public static final HostedOptionKey<Boolean> PrintStaticTruffleBoundaries = new HostedOptionKey<>(false);

@Option(help = "Check that CompilerAsserts.neverPartOfCompilation is not reachable for runtime compilation")//
public static final HostedOptionKey<Boolean> TruffleCheckNeverPartOfCompilation = new HostedOptionKey<>(true);

Expand Down Expand Up @@ -813,6 +817,10 @@ private static void collectImplementations(HostedType type, Set<HostedType> impl

@Override
public void afterAnalysis(AfterAnalysisAccess access) {
if (Options.PrintStaticTruffleBoundaries.getValue()) {
printStaticTruffleBoundaries();
}

SubstrateTruffleRuntime truffleRuntime = (SubstrateTruffleRuntime) Truffle.getRuntime();
AfterAnalysisAccessImpl config = (AfterAnalysisAccessImpl) access;
truffleRuntime.initializeHostedKnownMethods(config.getMetaAccess());
Expand Down Expand Up @@ -844,6 +852,30 @@ public void afterAnalysis(AfterAnalysisAccess access) {
}
}

private static void printStaticTruffleBoundaries() {
HashSet<ResolvedJavaMethod> foundBoundaries = new HashSet<>();
int callSiteCount = 0;
int calleeCount = 0;
for (CallTreeNode node : ImageSingletons.lookup(GraalFeature.class).getRuntimeCompiledMethods().values()) {
StructuredGraph graph = node.getGraph();
for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
TruffleBoundary truffleBoundary = targetMethod.getAnnotation(TruffleBoundary.class);
if (truffleBoundary != null) {
++callSiteCount;
if (foundBoundaries.contains(targetMethod)) {
// nothing to do
} else {
foundBoundaries.add(targetMethod);
System.out.println("Truffle boundary found: " + targetMethod);
calleeCount++;
}
}
}
}
System.out.printf("Number of Truffle call boundaries: %d, number of unique called methods outside the boundary: %d%n", callSiteCount, calleeCount);
}

@Override
public void registerGraalPhases(Providers providers, SnippetReflectionProvider snippetReflection, Suites suites, boolean hosted) {
if (hosted && TruffleHostInliningPhase.Options.TruffleHostInlining.getValue(HostedOptionValues.singleton()) && suites.getHighTier() instanceof HighTier) {
Expand Down

0 comments on commit 7aaa527

Please sign in to comment.