Skip to content

Commit c534af7

Browse files
committed
extra compilation dumps
1 parent 7e88258 commit c534af7

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
611611
compileQueue = HostedConfiguration.instance().createCompileQueue(debug, featureHandler, hUniverse, runtime, DeoptTester.enabled(), bb.getProviders().getSnippetReflection(),
612612
compilationExecutor);
613613
compileQueue.finish(debug);
614+
System.out.println("Number of parsed methods: " + CompileQueue.parsedMethods.size());
615+
System.out.println("Number of compiled methods: " + CompileQueue.compiledMethods.size());
616+
dumpParseTree(compileQueue);
614617

615618
/* release memory taken by graphs for the image writing */
616619
hUniverse.getMethods().forEach(HostedMethod::clear);
@@ -679,6 +682,7 @@ private void doRun(Map<Method, CEntryPointData> entryPoints,
679682
}
680683

681684
private static final String DUMP_FOLDER = "/Users/dkozak/tmp/hello-dir/stats/";
685+
private static final String METHOD_FORMAT = "%H.%n(%P)";
682686

683687
private void dumpAnalysisStats() {
684688
AnalysisUniverse universe = getBigbang().getUniverse();
@@ -689,14 +693,13 @@ private void dumpAnalysisStats() {
689693
System.out.println("Invoked methods " + invokedMethods.size());
690694
System.out.println("Implementation invoked methods " + implInvokedMethods.size());
691695

692-
boolean useReachability = NativeImageOptions.UseExperimentalReachabilityAnalysis.getValue();
693-
String fileName = useReachability ? "reachability_" : "points-to_";
696+
String prefix = analysisPrefix();
694697

695698
List<Pair<List<String>, String>> pairs = Arrays.asList(Pair.create(reachableTypes, "types"), Pair.create(invokedMethods, "invokedMethods"),
696699
Pair.create(implInvokedMethods, "implInvokedMethods"));
697700

698701
for (Pair<List<String>, String> pair : pairs) {
699-
try (FileWriter writer = new FileWriter(DUMP_FOLDER + fileName + pair.getRight())) {
702+
try (FileWriter writer = new FileWriter(DUMP_FOLDER + prefix + pair.getRight())) {
700703
for (String line : pair.getLeft()) {
701704
writer.write(line);
702705
writer.write('\n');
@@ -706,10 +709,10 @@ private void dumpAnalysisStats() {
706709
}
707710
}
708711

709-
try (FileWriter writer = new FileWriter(DUMP_FOLDER + fileName + "invokeStats")) {
712+
try (FileWriter writer = new FileWriter(DUMP_FOLDER + prefix + "invokeStats")) {
710713
List<AnalysisMethod> implInvoked = universe.getMethods().stream().filter(AnalysisMethod::isImplementationInvoked).collect(Collectors.toList());
711714
for (AnalysisMethod method : implInvoked) {
712-
writer.write(method.format("%H.%n(%P)"));
715+
writer.write(method.format(METHOD_FORMAT));
713716
writer.write(',');
714717
List<AnalysisMethod> callees = getCallees(method);
715718
writer.write(Integer.toString(callees.size()));
@@ -720,6 +723,26 @@ private void dumpAnalysisStats() {
720723
}
721724
}
722725

726+
private String analysisPrefix() {
727+
return NativeImageOptions.UseExperimentalReachabilityAnalysis.getValue() ? "reachability_" : "points-to_";
728+
}
729+
730+
private void dumpParseTree(CompileQueue compileQueue) {
731+
String prefix = analysisPrefix();
732+
List<Map.Entry<HostedMethod, List<HostedMethod>>> entries = CompileQueue.parseTree.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getKey().format(METHOD_FORMAT)))
733+
.collect(Collectors.toList());
734+
try (FileWriter writer = new FileWriter(DUMP_FOLDER + prefix + "parse_tree")) {
735+
for (Map.Entry<HostedMethod, List<HostedMethod>> entry : entries) {
736+
writer.write(entry.getKey().format(METHOD_FORMAT));
737+
writer.write(',');
738+
writer.write(Integer.toString(entry.getValue().size()));
739+
writer.write('\n');
740+
}
741+
} catch (IOException e) {
742+
e.printStackTrace();
743+
}
744+
}
745+
723746
private List<AnalysisMethod> getCallees(AnalysisMethod method) {
724747
if (bb instanceof NativeImageReachabilityAnalysis) {
725748
return getCalleesR(((NativeImageReachabilityAnalysis) bb), method);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
3131
import java.util.Collection;
32+
import java.util.Collections;
3233
import java.util.Comparator;
3334
import java.util.HashMap;
3435
import java.util.IdentityHashMap;
3536
import java.util.List;
3637
import java.util.Map;
3738
import java.util.Map.Entry;
3839
import java.util.Objects;
40+
import java.util.Set;
3941
import java.util.TreeMap;
4042
import java.util.concurrent.ConcurrentHashMap;
4143
import java.util.concurrent.ConcurrentMap;
4244
import java.util.concurrent.ForkJoinPool;
45+
import java.util.stream.Collectors;
4346

4447
import org.graalvm.collections.EconomicMap;
4548
import org.graalvm.compiler.api.replacements.Fold;
@@ -419,7 +422,7 @@ protected PhaseSuite<HighTierContext> afterParseCanonicalization() {
419422
phaseSuite.appendPhase(new DeadStoreRemovalPhase());
420423
phaseSuite.appendPhase(new DevirtualizeCallsPhase());
421424
phaseSuite.appendPhase(CanonicalizerPhase.create());
422-
phaseSuite.appendPhase(new StrengthenStampsPhase());
425+
// phaseSuite.appendPhase(new StrengthenStampsPhase());
423426
phaseSuite.appendPhase(CanonicalizerPhase.create());
424427
phaseSuite.appendPhase(new OptimizeExceptionPathsPhase());
425428
if (ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(universe.hostVM().options())) {
@@ -516,14 +519,19 @@ protected void parseAll() throws InterruptedException {
516519
* parsed methods.
517520
*/
518521
private void parseAheadOfTimeCompiledMethods() {
519-
universe.getMethods().stream()
522+
List<HostedMethod> entryPoints = universe.getMethods().stream()
520523
.filter(method -> method.isEntryPoint() || CompilationInfoSupport.singleton().isForcedCompilation(method))
521-
.forEach(method -> ensureParsed(method, new EntryPointReason()));
524+
.collect(Collectors.toList());
525+
System.out.println("Entry points: " + entryPoints.size());
526+
entryPoints.forEach(method -> ensureParsed(method, new EntryPointReason()));
522527

523528
SubstrateForeignCallsProvider foreignCallsProvider = (SubstrateForeignCallsProvider) runtimeConfig.getProviders().getForeignCalls();
524-
foreignCallsProvider.getForeignCalls().values().stream()
529+
List<HostedMethod> foreignCallEntryPoints = foreignCallsProvider.getForeignCalls().values().stream()
525530
.map(linkage -> (HostedMethod) linkage.getDescriptor().findMethod(runtimeConfig.getProviders().getMetaAccess()))
526531
.filter(method -> method.wrapped.isRootMethod())
532+
.collect(Collectors.toList());
533+
System.out.println("Foreign call entry points: " + foreignCallEntryPoints.size());
534+
foreignCallEntryPoints
527535
.forEach(method -> ensureParsed(method, new EntryPointReason()));
528536
}
529537

@@ -892,6 +900,8 @@ public static Object replaceAnalysisObjects(Object obj, Node node, IdentityHashM
892900

893901
private final boolean parseOnce = SubstrateOptions.parseOnce();
894902

903+
public static final Set<HostedMethod> parsedMethods = ConcurrentHashMap.newKeySet();
904+
895905
@SuppressWarnings("try")
896906
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
897907
if ((!NativeImageOptions.AllowFoldMethods.getValue() && method.getAnnotation(Fold.class) != null) || method.getAnnotation(NodeIntrinsic.class) != null) {
@@ -966,6 +976,8 @@ private void defaultParseFunction(DebugContext debug, HostedMethod method, Compi
966976
}
967977
}
968978

979+
parsedMethods.add(method);
980+
969981
} catch (Throwable ex) {
970982
GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
971983
error.addContext("method: " + method.format("%r %H.%n(%p)"));
@@ -977,9 +989,18 @@ private void defaultParseFunction(DebugContext debug, HostedMethod method, Compi
977989
}
978990
}
979991

992+
public static final Map<HostedMethod, List<HostedMethod>> parseTree = new ConcurrentHashMap<>();
993+
994+
private static List<HostedMethod> getEntry(HostedMethod method) {
995+
return parseTree.computeIfAbsent(method, key -> Collections.synchronizedList(new ArrayList<>()));
996+
}
997+
980998
private void ensureParsed(HostedMethod method, CompileReason reason, CallTargetNode targetNode, HostedMethod invokeTarget, boolean isIndirect) {
981999
if (isIndirect) {
982-
for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
1000+
HostedMethod[] implementations = invokeTarget.getImplementations();
1001+
List<HostedMethod> targets = getEntry(method);
1002+
Collections.addAll(targets, implementations);
1003+
for (HostedMethod invokeImplementation : implementations) {
9831004
handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
9841005
ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
9851006
}
@@ -995,6 +1016,7 @@ private void ensureParsed(HostedMethod method, CompileReason reason, CallTargetN
9951016
* implementation invoked status.
9961017
*/
9971018
if (invokeTarget.wrapped.isSimplyImplementationInvoked()) {
1019+
getEntry(method).add(invokeTarget);
9981020
handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
9991021
ensureParsed(invokeTarget, new DirectCallReason(method, reason));
10001022
}
@@ -1173,6 +1195,8 @@ protected CompilationResult doCompile(DebugContext debug, final HostedMethod met
11731195
return fun.compile(debug, method, compilationIdentifier, reason, runtimeConfig);
11741196
}
11751197

1198+
public static final Set<HostedMethod> compiledMethods = ConcurrentHashMap.newKeySet();
1199+
11761200
@SuppressWarnings("try")
11771201
private CompilationResult defaultCompileFunction(DebugContext debug, HostedMethod method, CompilationIdentifier compilationIdentifier, CompileReason reason, RuntimeConfiguration config) {
11781202
if (NativeImageOptions.PrintAOTCompilation.getValue()) {
@@ -1223,6 +1247,8 @@ private CompilationResult defaultCompileFunction(DebugContext debug, HostedMetho
12231247
result.setTargetCode(Arrays.copyOf(result.getTargetCode(), result.getTargetCodeSize()), result.getTargetCodeSize());
12241248
}
12251249

1250+
compiledMethods.add(method);
1251+
12261252
return result;
12271253
}
12281254
} catch (Throwable ex) {

0 commit comments

Comments
 (0)