Skip to content

Commit

Permalink
Manually register Glob pattern nodes as instantiated in the base laye…
Browse files Browse the repository at this point in the history
…r to avoid missed types
  • Loading branch information
Zeavee committed Oct 28, 2024
1 parent d300938 commit ffa764a
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport;
import com.oracle.svm.hosted.config.ConfigurationParserUtils;
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
import com.oracle.svm.hosted.jdk.localization.LocalizationFeature;
import com.oracle.svm.hosted.reflect.NativeImageConditionResolver;
import com.oracle.svm.hosted.snippets.SubstrateGraphBuilderPlugins;
Expand Down Expand Up @@ -393,9 +394,10 @@ protected boolean collectEmbeddedResourcesInfo() {
}

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
public void beforeAnalysis(BeforeAnalysisAccess a) {
FeatureImpl.BeforeAnalysisAccessImpl access = (FeatureImpl.BeforeAnalysisAccessImpl) a;
/* load and parse resource configuration files */
ConfigurationConditionResolver<ConfigurationCondition> conditionResolver = new NativeImageConditionResolver(((FeatureImpl.BeforeAnalysisAccessImpl) access).getImageClassLoader(),
ConfigurationConditionResolver<ConfigurationCondition> conditionResolver = new NativeImageConditionResolver(access.getImageClassLoader(),
ClassInitializationSupport.singleton());

ResourceConfigurationParser<ConfigurationCondition> parser = ResourceConfigurationParser.create(true, conditionResolver, ResourcesRegistry.singleton(),
Expand All @@ -415,6 +417,21 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
GlobTrieNode<ConditionWithOrigin> trie = CompressedGlobTrie.CompressedGlobTrieBuilder.build(patternsWithInfo);
Resources.singleton().setResourcesTrieRoot(trie);

/*
* GR-58701: The SVM core is currently not included in the base layer of a Layered Image.
* Those specific types can be reachable from Resources#resourcesTrieRoot, but they can be
* missed by the analysis because the GlobTrieNode#children field is only available after
* analysis and the only reference to those types is with ThrowMissingRegistrationErrors
* enabled. Until a clear SVM core separation is created and included in the base layer,
* those types should be manually registered as instantiated before the analysis.
*/
if (HostedImageLayerBuildingSupport.buildingSharedLayer()) {
String reason = "Included in the base image";
access.getMetaAccess().lookupJavaType(ReflectionUtil.lookupClass(false, "com.oracle.svm.core.jdk.resources.CompressedGlobTrie.LiteralNode")).registerAsInstantiated(reason);
access.getMetaAccess().lookupJavaType(ReflectionUtil.lookupClass(false, "com.oracle.svm.core.jdk.resources.CompressedGlobTrie.DoubleStarNode")).registerAsInstantiated(reason);
access.getMetaAccess().lookupJavaType(ReflectionUtil.lookupClass(false, "com.oracle.svm.core.jdk.resources.CompressedGlobTrie.StarTrieNode")).registerAsInstantiated(reason);
}

/* prepare regex patterns for resource registration */
resourcePatternWorkSet.addAll(Options.IncludeResources.getValue()
.getValuesWithOrigins()
Expand Down

0 comments on commit ffa764a

Please sign in to comment.