Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
/ jdk22u Public archive

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: phh
Backport-of: 9f43ce5a725b212cec0f3cd17491c4bada953676
  • Loading branch information
tstuefe committed May 14, 2024
1 parent 9486b7c commit 9b3187f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 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 @@ -474,10 +474,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()) {
intptr_t 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
5 changes: 0 additions & 5 deletions src/hotspot/share/cds/heapShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ bool HeapShared::archive_object(oop obj) {
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
6 changes: 5 additions & 1 deletion src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "precompiled.hpp"
#include "cds/cdsConfig.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/javaThreadStatus.hpp"
#include "gc/shared/barrierSet.hpp"
Expand Down Expand Up @@ -103,7 +104,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 = CDSConfig::is_dumping_static_archive() ? 0x12345678 : os::random();
_hashStateY = 842502087;
_hashStateZ = 0x8767; // (int)(3579807591LL & 0xffff) ;
_hashStateW = 273326509;
Expand Down

1 comment on commit 9b3187f

@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.