Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-33955] Handle bundle instances in the heap in the localization optimized mode. #3956

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,40 @@ public void afterRegistration(AfterRegistrationAccess access) {
}
}

@Override
public void duringSetup(DuringSetupAccess access) {
if (optimizedMode) {
access.registerObjectReplacer(this::eagerlyInitializeBundles);
}
}

/**
* In the optimized localization support, the bundles are stored in a map. In order to make the
* getContents methods unreachable, the bundles are initialized eagerly and the lookup methods
* are substituted. However, if there are bundle instances somewhere in the heap that were not
* put in the map, they won't be initialized and therefore accessing their content will cause
* runtime failures. Therefore, we visit each object in the heap and if it is a ResourceBundle,
* we eagerly initialize it.
*/
private Object eagerlyInitializeBundles(Object object) {
assert optimizedMode : "Should only be triggered in the optimized mode.";
if (object instanceof ResourceBundle) {
ResourceBundle bundle = (ResourceBundle) object;
try {
/*
* getKeys can be null for ResourceBundle.NONEXISTENT_BUNDLE, which causes the
* keySet method to crash.
*/
if (bundle.getKeys() != null) {
bundle.keySet();
}
} catch (Exception ex) {
trace("Failed to eagerly initialize bundle " + bundle + ", " + bundle.getBaseBundleName() + ", reason " + ex.getClass() + " " + ex.getMessage());
}
}
return object;
}

@Platforms(Platform.HOSTED_ONLY.class)
private LocalizationSupport selectLocalizationSupport() {
if (optimizedMode) {
Expand Down