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

Commit 9b3187f

Browse files
committed
8330027: Identity hashes of archived objects must be based on a reproducible random seed
Reviewed-by: phh Backport-of: 9f43ce5a725b212cec0f3cd17491c4bada953676
1 parent 9486b7c commit 9b3187f

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/hotspot/share/cds/archiveHeapWriter.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,8 @@ void ArchiveHeapWriter::update_header_for_requested_obj(oop requested_obj, oop s
474474
fake_oop->set_narrow_klass(nk);
475475

476476
// We need to retain the identity_hash, because it may have been used by some hashtables
477-
// in the shared heap. This also has the side effect of pre-initializing the
478-
// identity_hash for all shared objects, so they are less likely to be written
479-
// into during run time, increasing the potential of memory sharing.
480-
if (src_obj != nullptr) {
477+
// in the shared heap.
478+
if (src_obj != nullptr && !src_obj->fast_no_hash_check()) {
481479
intptr_t src_hash = src_obj->identity_hash();
482480
fake_oop->set_mark(markWord::prototype().copy_set_hash(src_hash));
483481
assert(fake_oop->mark().is_unlocked(), "sanity");

src/hotspot/share/cds/heapShared.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,6 @@ bool HeapShared::archive_object(oop obj) {
279279
count_allocation(obj->size());
280280
ArchiveHeapWriter::add_source_obj(obj);
281281

282-
// The archived objects are discovered in a predictable order. Compute
283-
// their identity_hash() as soon as we see them. This ensures that the
284-
// the identity_hash in the object header will have a predictable value,
285-
// making the archive reproducible.
286-
obj->identity_hash();
287282
CachedOopInfo info = make_cached_oop_info();
288283
archived_object_cache()->put(obj, info);
289284
mark_native_pointers(obj);

src/hotspot/share/runtime/thread.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include "precompiled.hpp"
27+
#include "cds/cdsConfig.hpp"
2728
#include "classfile/javaClasses.hpp"
2829
#include "classfile/javaThreadStatus.hpp"
2930
#include "gc/shared/barrierSet.hpp"
@@ -103,7 +104,10 @@ Thread::Thread() {
103104
_vm_error_callbacks = nullptr;
104105

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

0 commit comments

Comments
 (0)