From 5532e37800252bf65fce34c73e220ecb53734d76 Mon Sep 17 00:00:00 2001 From: iklam Date: Fri, 16 May 2025 14:18:13 -0700 Subject: [PATCH 1/2] 8343892: Default CDS archive becomes non-deterministic after JDK-8305895 --- src/hotspot/share/oops/klass.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index a41f3540f39e8..7395b45891493 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -810,10 +810,18 @@ void Klass::remove_unshareable_info() { set_class_loader_data(nullptr); set_is_shared(); - // FIXME: validation in Klass::hash_secondary_supers() may fail for shared klasses. - // Even though the bitmaps always match, the canonical order of elements in the table - // is not guaranteed to stay the same (see tie breaker during Robin Hood hashing in Klass::hash_insert). - //assert(compute_secondary_supers_bitmap(secondary_supers()) == _secondary_supers_bitmap, "broken table"); + if (CDSConfig::is_dumping_classic_static_archive()) { + // "Classic" static archives are required to have deterministic contents. + // The elements in _secondary_supers are addresses in the ArchiveBuilder + // output buffer, so they should have deterministic values. If we rehash + // _secondary_supers, its elements will appear in a deterministic order. + // + // Note that the bitmap is guatanteed to be deterministic, regardless of the + // actual addresses of the elements in _secondary_supers. So rehashing shouldn't + // change it. + uintx bitmap = hash_secondary_supers(secondary_supers(), true); + assert(bitmap == _secondary_supers_bitmap, "bitmap should not be changed due to rehashing"); + } } void Klass::remove_java_mirror() { From e632ac67015a4bc6b6de9759e25ce9b6a932a9f8 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 27 May 2025 11:07:44 -0700 Subject: [PATCH 2/2] @shipilev comments -- fixed typo --- src/hotspot/share/oops/klass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index 7395b45891493..256d4a53c9bf4 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -816,7 +816,7 @@ void Klass::remove_unshareable_info() { // output buffer, so they should have deterministic values. If we rehash // _secondary_supers, its elements will appear in a deterministic order. // - // Note that the bitmap is guatanteed to be deterministic, regardless of the + // Note that the bitmap is guaranteed to be deterministic, regardless of the // actual addresses of the elements in _secondary_supers. So rehashing shouldn't // change it. uintx bitmap = hash_secondary_supers(secondary_supers(), true);