-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8290833: Remove ConstantPoolCache::walk_entries_for_initialization() #9759
8290833: Remove ConstantPoolCache::walk_entries_for_initialization() #9759
Conversation
👋 Welcome back iklam! A progress list of the required criteria for merging this PR into |
/label remove hotspot |
@iklam |
@iklam |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a nice improvement, not having to figure out how to reinitialize the cpCache properly.
|
||
// The saved cp entries array is not modified by the ArchiveBuilder, so there's | ||
// no need to make a deep copy. It will be freed when the holder class is removed. | ||
_saved_cpcache_entries = src._saved_cpcache_entries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're copying these entries, should you make src._saved_cpcache_entries null so you don't double delete them? Or just for safety in case someone adds deleting it to the destructor later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the _saved_cpcache_entries
has a different lifecycle than the DumpTimeClassInfo
. We set the _saved_cpcache_entries
after the cpCache is allocated, and it's never changed afterwards. It's freed when the cpCache is deallocated.
I can see why the current code is confusing. I'll try to move it to a new table of cpCache*
-> ConstantPoolEntry*
which will make the code easier to understand and maintain.
@iklam 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might need some more comments.
ConstantPoolCache* cpc = k->constants()->cache(); | ||
if (cpc != NULL) { | ||
remove_saved_cpcache_entries_locked(cpc); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you need the separate table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two reasons:
- The old table was indexed by
InstanceKlass*
. However, with class redefinition, a second ConstantPoolCache may be created for a class. Trying to keep this one-to-many relationship with the old table is doable but awkward. - The old table was cloned when the archive is dumped. However, the saved_cpcache_entries don't need to be cloned because they are never modified. I don't want to have to explain why parts of the DumpTimeClassInfo are not deep-copied.
InstanceKlass* ik = constant_pool()->pool_holder(); | ||
ConstantPoolCacheEntry* saved = SystemDictionaryShared::get_saved_cpcache_entries_locked(ik); | ||
ConstantPoolCache* orig_cpc = ArchiveBuilder::current()->get_src_obj(this); | ||
ConstantPoolCacheEntry* saved = SystemDictionaryShared::get_saved_cpcache_entries_locked(orig_cpc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do? get_src_obj looks like it just returns the address with a cast to the type T.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused with the template. get_src_obj() gets in-memory (current) version of the metadata object. It has a mapping to the copy in the archive. right?
"this" is the copy in the archive. The comment helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a couple more comments, otherwise, looks good. Approving again.
InstanceKlass* ik = constant_pool()->pool_holder(); | ||
ConstantPoolCacheEntry* saved = SystemDictionaryShared::get_saved_cpcache_entries_locked(ik); | ||
ConstantPoolCache* orig_cpc = ArchiveBuilder::current()->get_src_obj(this); | ||
ConstantPoolCacheEntry* saved = SystemDictionaryShared::get_saved_cpcache_entries_locked(orig_cpc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused with the template. get_src_obj() gets in-memory (current) version of the metadata object. It has a mapping to the copy in the archive. right?
"this" is the copy in the archive. The comment helps.
@@ -200,6 +200,7 @@ class ArchiveBuilder : public StackObj { | |||
SourceObjList _rw_src_objs; // objs to put in rw region | |||
SourceObjList _ro_src_objs; // objs to put in ro region | |||
ResizeableResourceHashtable<address, SourceObjInfo, ResourceObj::C_HEAP, mtClassShared> _src_obj_table; | |||
ResizeableResourceHashtable<address, address, ResourceObj::C_HEAP, mtClassShared> _dumped_to_src_obj_table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to sort out these tables. Can you have a comment above these tables what they are mapping? The names are somewhat opaque.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people will first reach these functions when reading the code, so I added some comments there:
// + When creating a CDS archive, we first load Java classes and create metadata
// objects as usual. These are call "source" objects.
// + We then copy the source objects into the output buffer at "dumped addrsses".
//
// The following functions translate between these two (non-overlapping) spaces.
// (The API should be renamed to be less confusing!)
address get_dumped_addr(address src_obj) const;
address get_src_obj(address dumped_addr) const;
I have filed an RFE JDK-8292225 to clean up the names to make the core easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, yes thanks. but addrsses is missing an 'e' above. Thanks for filing an additional bug so that one can guess what the tables mean even without knowing all the context.
…addresses (will be properly fixed in JDK-8292225)
…remove-walk_entries_for_initialization
…remove-walk_entries_for_initialization
Thanks @coleenp and @calvinccheung for the review. |
Going to push as commit bd58553. |
Background:
ConstantPoolCache::walk_entries_for_initialization()
is called byConstantPoolCache::remove_unshareable_info()
to restore the CpCache to the state immediately after the class has been rewritten by the Rewriter (which happens during the class linking phase). In most part, this means theConstantPoolCacheEntry
's need to be zeroed. However, the_f2
fields of some of the entries are initialized to be non-zero by the Rewriter and must be preserved.The reason
walk_entries_for_initialization()
exists is that afterRewriter::rewrite()
has finished, some information about what is stored inside the CpCache is discarded (e.g.,Rewriter::_invokedynamic_references_map
). As a result, we cannot easily determine which entries has a_f2
field that need to be preserved. We must walk all the bytecodes in all the methods of this class to recompute this information.This is awkward and time consuming. It also needs to be updated if the
Rewriter
ever changes.Also, for future optimizations, we may need to pre-resolve a subset of the CpCache entries during CDS dump time. Trying to make that work alongside
walk_entries_for_initialization()
seems too complicated.Fix:
Store a copy of the CpCache after rewritting. Use this to revert the CpCache's state inside
ConstantPoolCache::remove_unshareable_info()
.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9759/head:pull/9759
$ git checkout pull/9759
Update a local copy of the PR:
$ git checkout pull/9759
$ git pull https://git.openjdk.org/jdk pull/9759/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9759
View PR using the GUI difftool:
$ git pr show -t 9759
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9759.diff