Skip to content

Commit 5b910ab

Browse files
committed
8367375: Crash when using CDS archive created with -XX:+UseCompactObjectHeaders and preview mode
Reviewed-by: chagedorn, matsaave
1 parent b1a388b commit 5b910ab

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

src/hotspot/share/cds/archiveBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ void ArchiveBuilder::make_klasses_shareable() {
850850
address narrow_klass_base = _requested_static_archive_bottom; // runtime encoding base == runtime mapping start
851851
const int narrow_klass_shift = precomputed_narrow_klass_shift();
852852
narrowKlass nk = CompressedKlassPointers::encode_not_null_without_asserts(requested_k, narrow_klass_base, narrow_klass_shift);
853-
k->set_prototype_header(markWord::prototype().set_narrow_klass(nk));
853+
k->set_prototype_header_klass(nk);
854854
}
855855
#endif //_LP64
856856
if (k->is_flatArray_klass()) {

src/hotspot/share/cds/archiveHeapWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ objArrayOop ArchiveHeapWriter::allocate_root_segment(size_t offset, int element_
192192
if (UseCompactObjectHeaders) {
193193
oopDesc::release_set_mark(mem, Universe::objectArrayKlass()->prototype_header());
194194
} else {
195+
assert(!EnableValhalla || Universe::objectArrayKlass()->prototype_header() == markWord::prototype(), "should be the same");
195196
oopDesc::set_mark(mem, markWord::prototype());
196197
oopDesc::release_set_klass(mem, Universe::objectArrayKlass());
197198
}

src/hotspot/share/cds/heapShared.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ static void copy_java_mirror_hashcode(oop orig_mirror, oop scratch_m) {
598598
narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
599599
scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));
600600
} else {
601+
// For valhalla, the prototype header is the same as markWord::prototype();
601602
scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
602603
}
603604
assert(scratch_m->mark().is_unlocked(), "sanity");

src/hotspot/share/oops/klass.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ class Klass : public Metadata {
755755
inline void set_prototype_header(markWord header);
756756
static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
757757
static inline markWord default_prototype_header(Klass* k);
758+
inline void set_prototype_header_klass(narrowKlass klass);
758759

759760
JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
760761

src/hotspot/share/oops/klass.inline.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -95,6 +95,10 @@ inline markWord Klass::default_prototype_header(Klass* k) {
9595
return (k == nullptr) ? markWord::prototype() : k->prototype_header();
9696
}
9797

98+
inline void Klass::set_prototype_header_klass(narrowKlass klass) {
99+
// Merge narrowKlass in existing prototype header.
100+
_prototype_header = _prototype_header.set_narrow_klass(klass);
101+
}
98102

99103
// Loading the java_mirror does not keep its holder alive. See Klass::keep_alive().
100104
inline oop Klass::java_mirror() const {

0 commit comments

Comments
 (0)