Skip to content

Commit

Permalink
Fix base layer component hub rescanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Jan 17, 2025
1 parent 0db3edf commit 20791fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,7 @@ public void initializeMetaData(ImageHeapScanner heapScanner, AnalysisType type)
registerPackage(heapScanner, javaClass, hub);
}

boolean rescan = true;
/*
* The constant should not be rescanned directly if it is from the base layer, as it would
* try to access the constant again, which would trigger the dynamic hub initialization
* again. The constant has to be rescanned after the initialization is finished.
*/
if (hostVM.useBaseLayer()) {
ImageHeapConstant hubConstant = (ImageHeapConstant) heapScanner.createImageHeapConstant(hub, OtherReason.HUB);
rescan = hubConstant == null || !hubConstant.isInBaseLayer();
}
boolean rescan = shouldRescanHub(heapScanner, hub);

/*
* Start by rescanning the hub itself. This ensures the correct scan reason in case this is
Expand All @@ -131,7 +122,7 @@ public void initializeMetaData(ImageHeapScanner heapScanner, AnalysisType type)
if (type.isArray()) {
AnalysisError.guarantee(hub.getComponentHub().getArrayHub() == null, "Array hub already initialized for %s.", type.getComponentType().toJavaName(true));
hub.getComponentHub().setArrayHub(hub);
if (rescan) {
if (shouldRescanHub(heapScanner, hub.getComponentHub())) {
heapScanner.rescanField(hub.getComponentHub().getCompanion(), hubCompanionArrayHubField);
}
}
Expand All @@ -156,6 +147,20 @@ public void initializeMetaData(ImageHeapScanner heapScanner, AnalysisType type)
}
}

/**
* The hub should not be rescanned directly if it is from the base layer, as it would try to
* access the constant again, which would trigger the dynamic hub initialization again. The hub
* has to be rescanned after the initialization is finished. This will be simplified by
* GR-60254.
*/
private boolean shouldRescanHub(ImageHeapScanner heapScanner, DynamicHub hub) {
if (hostVM.useBaseLayer()) {
ImageHeapConstant hubConstant = (ImageHeapConstant) heapScanner.createImageHeapConstant(hub, OtherReason.HUB);
return hubConstant == null || !hubConstant.isInBaseLayer();
}
return true;
}

/**
* For reachable classes, register class's package in appropriate class loader.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public void onTypeReachable(AnalysisType type) {
*/
HostedImageLayerBuildingSupport.singleton().getLoader().rescanHub(type, ((SVMHost) hostVM).dynamicHub(type));
}
if (type.isArray() && type.getComponentType().isInBaseLayer()) {
/* Rescan the component hub. This will be simplified by GR-60254. */
HostedImageLayerBuildingSupport.singleton().getLoader().rescanHub(type.getComponentType(), ((SVMHost) hostVM).dynamicHub(type).getComponentHub());
}
if (SubstrateOptions.includeAll()) {
/*
* Using getInstanceFields and getStaticFields allows to include the fields from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ private void ensureHubInitialized(ImageHeapConstant constant) {
* created and the initializeMetaDataTask needs to be executed to ensure the hosted
* object matches the persisted constant.
*/
PersistedAnalysisType.Reader typeData = findBaseLayerType(type);
PersistedAnalysisType.Reader typeData = findType(getBaseLayerTypeId(type));
if (typeData != null && typeData.getHasArrayType()) {
AnalysisType arrayClass = type.getArrayClass();
ensureHubInitialized(arrayClass);
Expand Down

0 comments on commit 20791fe

Please sign in to comment.