Skip to content

Commit

Permalink
8330027: Identity hashes of archived objects must be based on a repro…
Browse files Browse the repository at this point in the history
…ducible random seed

Reviewed-by: mdoerr
Backport-of: 9f43ce5a725b212cec0f3cd17491c4bada953676
  • Loading branch information
tstuefe committed Jun 27, 2024
1 parent cbd67f9 commit 75287b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/hotspot/share/cds/archiveHeapWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,8 @@ void ArchiveHeapWriter::update_header_for_requested_obj(oop requested_obj, oop s
fake_oop->set_narrow_klass(nk);

// We need to retain the identity_hash, because it may have been used by some hashtables
// in the shared heap. This also has the side effect of pre-initializing the
// identity_hash for all shared objects, so they are less likely to be written
// into during run time, increasing the potential of memory sharing.
if (src_obj != nullptr) {
// in the shared heap.
if (src_obj != nullptr && !src_obj->fast_no_hash_check()) {
int src_hash = src_obj->identity_hash();
fake_oop->set_mark(markWord::prototype().copy_set_hash(src_hash));
assert(fake_oop->mark().is_unlocked(), "sanity");
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/cds/heapShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ bool HeapShared::archive_object(oop obj) {
} else {
count_allocation(obj->size());
ArchiveHeapWriter::add_source_obj(obj);

// The archived objects are discovered in a predictable order. Compute
// their identity_hash() as soon as we see them. This ensures that the
// the identity_hash in the object header will have a predictable value,
// making the archive reproducible.
obj->identity_hash();
CachedOopInfo info = make_cached_oop_info();
archived_object_cache()->put(obj, info);
mark_native_pointers(obj);
Expand Down
5 changes: 4 additions & 1 deletion src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ Thread::Thread() {
_vm_error_callbacks = nullptr;

// thread-specific hashCode stream generator state - Marsaglia shift-xor form
_hashStateX = os::random();
// If we are dumping, keep ihashes constant. Note that during dumping we only
// ever run one java thread, and no other thread should generate ihashes either,
// so using a constant seed should work fine.
_hashStateX = DumpSharedSpaces ? 0x12345678 : os::random();
_hashStateY = 842502087;
_hashStateZ = 0x8767; // (int)(3579807591LL & 0xffff) ;
_hashStateW = 273326509;
Expand Down

1 comment on commit 75287b5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.