Skip to content

Commit ea27a54

Browse files
committed
8224509: Incorrect alignment in CDS related allocation code on 32-bit platforms
Reviewed-by: iklam, stuefe
1 parent 4d29116 commit ea27a54

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,7 @@ InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
20532053
const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name);
20542054
if (record != NULL) {
20552055
assert(!record->_klass->is_hidden(), "hidden class cannot be looked up by name");
2056+
assert(check_alignment(record->_klass), "Address not aligned");
20562057
return record->_klass;
20572058
} else {
20582059
return NULL;

src/hotspot/share/memory/archiveBuilder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s
460460
address src = ref->obj();
461461
int bytes = src_info->size_in_bytes();
462462
char* dest;
463-
size_t alignment = BytesPerWord;
464463
char* oldtop;
465464
char* newtop;
466465

@@ -473,10 +472,10 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s
473472
Klass* klass = (Klass*)src;
474473
if (klass->is_instance_klass()) {
475474
SystemDictionaryShared::validate_before_archiving(InstanceKlass::cast(klass));
476-
dump_region->allocate(sizeof(address), BytesPerWord);
475+
dump_region->allocate(sizeof(address));
477476
}
478477
}
479-
dest = dump_region->allocate(bytes, alignment);
478+
dest = dump_region->allocate(bytes);
480479
newtop = dump_region->top();
481480

482481
memcpy(dest, src, bytes);

src/hotspot/share/memory/archiveUtils.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ address* ArchivePtrMarker::_ptr_base;
3737
address* ArchivePtrMarker::_ptr_end;
3838
bool ArchivePtrMarker::_compacted;
3939

40+
// Metaspace::allocate() requires that all blocks must be aligned with KlassAlignmentInBytes.
41+
// We enforce the same alignment rule in blocks allocated from the shared space.
42+
const int SharedSpaceObjectAlignment = KlassAlignmentInBytes;
43+
4044
void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end) {
4145
assert(_ptrmap == NULL, "initialize only once");
4246
_ptr_base = ptr_base;
@@ -165,9 +169,9 @@ char* DumpRegion::expand_top_to(char* newtop) {
165169
return _top;
166170
}
167171

168-
char* DumpRegion::allocate(size_t num_bytes, size_t alignment) {
169-
char* p = (char*)align_up(_top, alignment);
170-
char* newtop = p + align_up(num_bytes, alignment);
172+
char* DumpRegion::allocate(size_t num_bytes) {
173+
char* p = (char*)align_up(_top, (size_t)SharedSpaceObjectAlignment);
174+
char* newtop = p + align_up(num_bytes, (size_t)SharedSpaceObjectAlignment);
171175
expand_top_to(newtop);
172176
memset(p, 0, newtop - p);
173177
return p;

src/hotspot/share/memory/archiveUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class DumpRegion {
157157
DumpRegion(const char* name) : _name(name), _base(NULL), _top(NULL), _end(NULL), _is_packed(false) {}
158158

159159
char* expand_top_to(char* newtop);
160-
char* allocate(size_t num_bytes, size_t alignment=BytesPerWord);
160+
char* allocate(size_t num_bytes);
161161

162162
void append_intptr_t(intptr_t n, bool need_to_mark = false);
163163

src/hotspot/share/memory/cppVtables.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ template <class T>
117117
intptr_t* CppVtableCloner<T>::allocate(const char* name) {
118118
assert(is_aligned(mc_region()->top(), sizeof(intptr_t)), "bad alignment");
119119
int n = get_vtable_length(name);
120-
_info = (CppVtableInfo*)mc_region()->allocate(CppVtableInfo::byte_size(n), sizeof(intptr_t));
120+
_info = (CppVtableInfo*)mc_region()->allocate(CppVtableInfo::byte_size(n));
121121
_info->set_vtable_size(n);
122122

123123
intptr_t* p = clone_vtable(name, _info);
@@ -242,7 +242,7 @@ static intptr_t** _cloned_cpp_vtptrs = NULL;
242242
void CppVtables::allocate_cloned_cpp_vtptrs() {
243243
assert(DumpSharedSpaces, "must");
244244
size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(intptr_t*);
245-
_cloned_cpp_vtptrs = (intptr_t**)mc_region()->allocate(vtptrs_bytes, sizeof(intptr_t*));
245+
_cloned_cpp_vtptrs = (intptr_t**)mc_region()->allocate(vtptrs_bytes);
246246
}
247247

248248
void CppVtables::serialize_cloned_cpp_vtptrs(SerializeClosure* soc) {

0 commit comments

Comments
 (0)