8379148: [lworld] Wrapper class caches should not be used when --enable-preview#2249
8379148: [lworld] Wrapper class caches should not be used when --enable-preview#2249Arraying wants to merge 10 commits intoopenjdk:lworldfrom
Conversation
|
/contributor add @xmas92 |
|
👋 Welcome back phubner! A progress list of the required criteria for merging this PR into |
|
@Arraying This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 23 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@Arraying |
|
What does this really solve? This doesn't identify the sites that incorrectly initialized these caches. This doesn't remove the C2 recognition of special wrapper arrays. Why do we need this? |
|
Thanks for your comments @liach.
The purpose of this PR is to clean up the remaining box cache changes that are necessary. Once the scope of this task is finalized and the PR goes out of draft, I will update the description to be more representative.
There are likely other usage sites that I have not overhauled. This is still a draft.
We cannot remove C2's recognition of these arrays. The box caches are VM symbols, we can only restrict their usages from the VM's side by ensuring control flow does not use them and verifying this through assertions. One prominent usage is during deoptimization. Axel has already changed the VM code for this in JDK-8378531. We still had underlying test failures, for instance JDK-8379863, which was a missing piece for this PR. Now that this has been integrated, things will look a lot clearer.
When it comes to boxed caches, we should not initialize from (nor write to) the CDS archives. |
matias9927
left a comment
There was a problem hiding this comment.
So far, the design makes sense to me! The caches will still exist in the CDS archive because they will be in the default classlist, but minimizing their use in preview mode will help transition to its deprecation.
|
Thanks for the feedback folks, I've RFR'd this PR and I'm re-running testing. Further comments/feedback welcome! |
Webrevs
|
TobiHartmann
left a comment
There was a problem hiding this comment.
JIT changes look good to me.
| if (ByteCache.isEnabled()) { | ||
| final int offset = 128; | ||
| return ByteCache.cache[(int) b + offset]; | ||
| return ByteCache.cache[(int)b + offset]; |
There was a problem hiding this comment.
I think the introduction of XxxCache.isEnabled and all the changes to valueOf methods are redundant.
There was a problem hiding this comment.
Thanks for the input. Axel raised a point regarding this in #2249 (comment)
There was a problem hiding this comment.
I don't see how that comment relates to my suggestion. Axel says PreviewFeatures.isEnabled can already reliably constant fold, so there is no cost restoring the old calls.
There was a problem hiding this comment.
I agree if someone can confirm that the static final field jdk.internal.misc.PreviewFeatures.ENABLED is constant folded. My guess is that it should be because we have had a lot of JEPs restricting access to our internals, and there is JEP-500, however I do not know the details.
The only reason this was in my original patch is because I know that @stable with an @stable sentinel check will be constant folded (unless changing the diagnostic flag FoldStableValues) .
There was a problem hiding this comment.
Axel says
PreviewFeatures.isEnabledcan already reliably constant fold
What I am trying to say is that I do not know if that is the case, but if that was the case we should just use it directly.
My original patch was just defensive with what I know works.
There was a problem hiding this comment.
Good to know. So @Stable is only useful for non final fields.
Is the reason that the box caches cache fields are not final, (and @Stable instead)? Some AOT / CDS interaction?
There was a problem hiding this comment.
There are some inconsistencies. For instance, Integer sees its cache as non-final, so I think a @Stable makes sense there given that the setup is performed outside of the static initializer. It's not immediately clear to me why this decision was made, but this is also how it is in mainline.
Moving forwards, I propose:
- Ensure all
cachevariables are consistent with mainline and eitherstatic finalor@Stable static. - If in preview,
static finalcaches withnulland@Stable staticcaches with an empty array. - Remove
isEnabled. - Revert changes in
valueOf, i.e., callPreviewFeatures.
Thoughts?
There was a problem hiding this comment.
On mainline Integer's cache is not final because the archived data may be invalid and need to be thrown away if a system property is changed. (This has always been the biggest headache with AOT)
@xmas92 I think only IntegerCache.cache is non-final @Stable. Others seem to be final @Stable. A final @Stable is meaningful for arrays because a read of such an array element is considered a compiler constant if it is non-zero/null.
There was a problem hiding this comment.
If in preview,
static finalcaches withnulland@Stable staticcaches with an empty array.
If we do not touch the cache array at all in preview, we can leave that array null because it won't be touched by code and thus won't be dealt by JIT.
There was a problem hiding this comment.
On mainline Integer's cache is not final because the archived data may be invalid and need to be thrown away if a system property is changed. (This has always been the biggest headache with AOT)
Right so the cache can have an unstable @stable non-null value. Scary.
Will be nice when Integer lose their identity and we do not have to worry about these sort of things.
@Stableis meaningful for arrays because a read of such an array element is considered a compiler constant if it is non-zero/null.
Did not know that the @Stable property was not shallow. Thanks for the information!
src/hotspot/share/cds/heapShared.cpp
Outdated
| {"java/lang/Byte$ByteCache", "archivedCache"}, | ||
| {"java/lang/Short$ShortCache", "archivedCache"}, | ||
| {"java/lang/Character$CharacterCache", "archivedCache"}, | ||
| {"java/lang/Integer$IntegerCache", _archived_cache_name}, |
There was a problem hiding this comment.
I don't think this change is necessary, we should avoid unneeded diffs if possible.
There was a problem hiding this comment.
It's used to re-use _archived_cache_name in the new assertion later on. Would you like me to revert this assertion?
There was a problem hiding this comment.
Or should I use the "archivedCache" literal twice?
There was a problem hiding this comment.
I think you should just use the string literal instead of _archived_cache_name to mimimize the diff to just the assert you add later.
src/hotspot/share/cds/heapShared.cpp
Outdated
| {"java/lang/Byte$ByteCache", "archivedCache"}, | ||
| {"java/lang/Short$ShortCache", "archivedCache"}, | ||
| {"java/lang/Character$CharacterCache", "archivedCache"}, | ||
| {"java/lang/Integer$IntegerCache", _archived_cache_name}, |
There was a problem hiding this comment.
I think you should just use the string literal instead of _archived_cache_name to mimimize the diff to just the assert you add later.
|
Thanks for the feedback everyone, I've incorporated it and I'm re-running testing as we speak. |
matias9927
left a comment
There was a problem hiding this comment.
Updates look good, thanks!
src/hotspot/share/cds/heapShared.cpp
Outdated
| // With preview mode enabled, the boxed class caches should all be null. | ||
| assert(strcmp("archivedCache", field_name) != 0 || | ||
| !Arguments::is_valhalla_enabled(), | ||
| "field %s must be null when using Valhalla preview features", field_name); |
There was a problem hiding this comment.
I think this assert should be removed. Even though the field name archivedCache is currently used only for the number classes, this just happens to be a coincident.
|
Since HS RT & JIT is happy, @liach are you content enough with the Java changes? |
liach
left a comment
There was a problem hiding this comment.
Oops, seems I forgot to leave an approval
|
Thanks everyone for the extensive feedback! |
|
Going to push as commit 897f6db.
Your commit was automatically rebased without conflicts. |
Hi all,
This change eliminates more box cache usages when running with
--enable-preview:Notably, this change does not prevent the
XXXCache'scachevariables from being CDS archived. This is due to the fact that the infrastructure is common to preview and non-preview mode, and the code complexity is not justifiable when the cost is storing fivenulls. Instead, it is ensured that the cache is never read from.Testing: tiers 1-4.
Progress
Issue
Reviewers
Contributors
<aboldtch@openjdk.org>Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2249/head:pull/2249$ git checkout pull/2249Update a local copy of the PR:
$ git checkout pull/2249$ git pull https://git.openjdk.org/valhalla.git pull/2249/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2249View PR using the GUI difftool:
$ git pr show -t 2249Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2249.diff
Using Webrev
Link to Webrev Comment