@@ -742,24 +742,29 @@ private void initializeBaseLayerTypeBeforePublishing(AnalysisType type, Persiste
742742 public void initializeBaseLayerType (AnalysisType type ) {
743743 VMError .guarantee (type .isInBaseLayer ());
744744 PersistedAnalysisType .Reader td = findType (getBaseLayerTypeId (type ));
745- registerFlag (td .getIsInstantiated (), _ -> type .registerAsInstantiated (PERSISTED ));
746- registerFlag (td .getIsUnsafeAllocated (), _ -> type .registerAsUnsafeAllocated (PERSISTED ));
747- registerFlag (td .getIsReachable (), _ -> type .registerAsReachable (PERSISTED ));
745+ postTask (td .getIsInstantiated (), _ -> type .registerAsInstantiated (PERSISTED ));
746+ postTask (td .getIsUnsafeAllocated (), _ -> type .registerAsUnsafeAllocated (PERSISTED ));
747+ postTask (td .getIsReachable (), _ -> type .registerAsReachable (PERSISTED ));
748748
749- if (!td .getIsInstantiated () && td .getIsAnySubtypeInstantiated ()) {
749+ if (td .getIsAnySubtypeInstantiated ()) {
750+ /*
751+ * Once a base layer type is loaded, loading all its instantiated subtypes ensures that
752+ * the application layer typestate is coherent with the base layer typestate. Otherwise,
753+ * unwanted optimizations could occur as the typestate would not contain some missed
754+ * types from the base layer.
755+ */
750756 var subTypesReader = td .getSubTypes ();
751757 for (int i = 0 ; i < subTypesReader .size (); ++i ) {
752758 int tid = subTypesReader .get (i );
753759 var subTypeReader = findType (tid );
754- if (subTypeReader .getIsInstantiated ()) {
755- registerFlag (true , _ -> getAnalysisTypeForBaseLayerId (subTypeReader .getId ()));
756- }
760+ /* Only load instantiated subtypes. */
761+ postTask (subTypeReader .getIsInstantiated (), _ -> getAnalysisTypeForBaseLayerId (subTypeReader .getId ()));
757762 }
758763 }
759764 }
760765
761- private void registerFlag (boolean flag , DebugContextRunnable task ) {
762- if (flag ) {
766+ private void postTask (boolean condition , DebugContextRunnable task ) {
767+ if (condition ) {
763768 if (universe .getBigbang () != null ) {
764769 universe .getBigbang ().postTask (task );
765770 } else {
@@ -1025,11 +1030,11 @@ public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
10251030 methods .putIfAbsent (analysisMethod .getId (), analysisMethod );
10261031
10271032 PersistedAnalysisMethod .Reader md = getMethodData (analysisMethod );
1028- registerFlag (md .getIsVirtualRootMethod (), _ -> analysisMethod .registerAsVirtualRootMethod (PERSISTED ));
1029- registerFlag (md .getIsDirectRootMethod (), _ -> analysisMethod .registerAsDirectRootMethod (PERSISTED ));
1030- registerFlag (md .getIsInvoked (), _ -> analysisMethod .registerAsInvoked (PERSISTED ));
1031- registerFlag (md .getIsImplementationInvoked (), _ -> analysisMethod .registerAsImplementationInvoked (PERSISTED ));
1032- registerFlag (md .getIsIntrinsicMethod (), _ -> analysisMethod .registerAsIntrinsicMethod (PERSISTED ));
1033+ postTask (md .getIsVirtualRootMethod (), _ -> analysisMethod .registerAsVirtualRootMethod (PERSISTED ));
1034+ postTask (md .getIsDirectRootMethod (), _ -> analysisMethod .registerAsDirectRootMethod (PERSISTED ));
1035+ postTask (md .getIsInvoked (), _ -> analysisMethod .registerAsInvoked (PERSISTED ));
1036+ postTask (md .getIsImplementationInvoked (), _ -> analysisMethod .registerAsImplementationInvoked (PERSISTED ));
1037+ postTask (md .getIsIntrinsicMethod (), _ -> analysisMethod .registerAsIntrinsicMethod (PERSISTED ));
10331038
10341039 LayeredCompilationBehavior .Behavior compilationBehavior = LayeredCompilationBehavior .Behavior .values ()[md .getCompilationBehaviorOrdinal ()];
10351040 analysisMethod .setCompilationBehavior (compilationBehavior );
@@ -1312,17 +1317,17 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
13121317 if (!analysisField .isStatic () && (isAccessed || isRead )) {
13131318 analysisField .getDeclaringClass ().getInstanceFields (true );
13141319 }
1315- registerFlag (isAccessed , _ -> {
1320+ postTask (isAccessed , _ -> {
13161321 analysisField .injectDeclaredType ();
13171322 analysisField .registerAsAccessed (PERSISTED );
13181323 });
1319- registerFlag (isRead , _ -> analysisField .registerAsRead (PERSISTED ));
1320- registerFlag (fieldData .getIsWritten (), _ -> {
1324+ postTask (isRead , _ -> analysisField .registerAsRead (PERSISTED ));
1325+ postTask (fieldData .getIsWritten (), _ -> {
13211326 analysisField .injectDeclaredType ();
13221327 analysisField .registerAsWritten (PERSISTED );
13231328 });
1324- registerFlag (fieldData .getIsFolded (), _ -> analysisField .registerAsFolded (PERSISTED ));
1325- registerFlag (fieldData .getIsUnsafeAccessed (), _ -> analysisField .registerAsUnsafeAccessed (PERSISTED ));
1329+ postTask (fieldData .getIsFolded (), _ -> analysisField .registerAsFolded (PERSISTED ));
1330+ postTask (fieldData .getIsUnsafeAccessed (), _ -> analysisField .registerAsUnsafeAccessed (PERSISTED ));
13261331
13271332 /*
13281333 * Inject the base layer position. If the position computed for this layer, either before
0 commit comments