2929import java .util .ArrayList ;
3030import java .util .Arrays ;
3131import java .util .Collection ;
32+ import java .util .Collections ;
3233import java .util .Comparator ;
3334import java .util .HashMap ;
3435import java .util .IdentityHashMap ;
3536import java .util .List ;
3637import java .util .Map ;
3738import java .util .Map .Entry ;
3839import java .util .Objects ;
40+ import java .util .Set ;
3941import java .util .TreeMap ;
4042import java .util .concurrent .ConcurrentHashMap ;
4143import java .util .concurrent .ConcurrentMap ;
4244import java .util .concurrent .ForkJoinPool ;
45+ import java .util .stream .Collectors ;
4346
4447import org .graalvm .collections .EconomicMap ;
4548import 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