Skip to content

Commit 5145bed

Browse files
committed
8254125: Assertion in cppVtables.cpp during builds on 32bit Windows
Reviewed-by: shade, ccheung
1 parent bdda205 commit 5145bed

File tree

11 files changed

+109
-139
lines changed

11 files changed

+109
-139
lines changed

src/hotspot/share/classfile/compactHashtable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ void CompactHashtableWriter::allocate_table() {
113113
_compact_entries = MetaspaceShared::new_ro_array<u4>(entries_space);
114114

115115
_stats->bucket_count = _num_buckets;
116-
_stats->bucket_bytes = _compact_buckets->size() * BytesPerWord;
116+
_stats->bucket_bytes = align_up(_compact_buckets->size() * BytesPerWord,
117+
SharedSpaceObjectAlignment);
117118
_stats->hashentry_count = _num_entries_written;
118-
_stats->hashentry_bytes = _compact_entries->size() * BytesPerWord;
119+
_stats->hashentry_bytes = align_up(_compact_entries->size() * BytesPerWord,
120+
SharedSpaceObjectAlignment);
119121
}
120122

121123
// Write the compact table's buckets

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "memory/heapShared.hpp"
4646
#include "memory/metadataFactory.hpp"
4747
#include "memory/metaspaceClosure.hpp"
48+
#include "memory/metaspaceShared.hpp"
4849
#include "memory/oopFactory.hpp"
4950
#include "memory/resourceArea.hpp"
5051
#include "memory/universe.hpp"
@@ -1860,7 +1861,7 @@ class EstimateSizeForArchive : StackObj {
18601861
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
18611862
if (!info.is_excluded()) {
18621863
size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_verifier_constraints(), info.num_loader_constraints());
1863-
_shared_class_info_size += align_up(byte_size, BytesPerWord);
1864+
_shared_class_info_size += align_up(byte_size, SharedSpaceObjectAlignment);
18641865
}
18651866
return true; // keep on iterating
18661867
}
@@ -1877,8 +1878,9 @@ size_t SystemDictionaryShared::estimate_size_for_archive() {
18771878
CompactHashtableWriter::estimate_size(_dumptime_table->count_of(true)) +
18781879
CompactHashtableWriter::estimate_size(_dumptime_table->count_of(false));
18791880
if (_dumptime_lambda_proxy_class_dictionary != NULL) {
1881+
size_t bytesize = align_up(sizeof(RunTimeLambdaProxyClassInfo), SharedSpaceObjectAlignment);
18801882
total_size +=
1881-
(sizeof(RunTimeLambdaProxyClassInfo) * _dumptime_lambda_proxy_class_dictionary->_count) +
1883+
(bytesize * _dumptime_lambda_proxy_class_dictionary->_count) +
18821884
CompactHashtableWriter::estimate_size(_dumptime_lambda_proxy_class_dictionary->_count);
18831885
} else {
18841886
total_size += CompactHashtableWriter::estimate_size(0);

src/hotspot/share/memory/archiveBuilder.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ArchiveBuilder::ArchiveBuilder(DumpRegion* mc_region, DumpRegion* rw_region, Dum
154154
_rw_region = rw_region;
155155
_ro_region = ro_region;
156156

157-
_estimated_metsapceobj_bytes = 0;
157+
_estimated_metaspaceobj_bytes = 0;
158158
}
159159

160160
ArchiveBuilder::~ArchiveBuilder() {
@@ -205,7 +205,8 @@ bool ArchiveBuilder::gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool re
205205
_num_type_array_klasses ++;
206206
}
207207
}
208-
_estimated_metsapceobj_bytes += BytesPerWord; // See RunTimeSharedClassInfo::get_for()
208+
// See RunTimeSharedClassInfo::get_for()
209+
_estimated_metaspaceobj_bytes += align_up(BytesPerWord, SharedSpaceObjectAlignment);
209210
} else if (ref->msotype() == MetaspaceObj::SymbolType) {
210211
// Make sure the symbol won't be GC'ed while we are dumping the archive.
211212
Symbol* sym = (Symbol*)ref->obj();
@@ -214,7 +215,7 @@ bool ArchiveBuilder::gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool re
214215
}
215216

216217
int bytes = ref->size() * BytesPerWord;
217-
_estimated_metsapceobj_bytes += bytes;
218+
_estimated_metaspaceobj_bytes += align_up(bytes, SharedSpaceObjectAlignment);
218219

219220
return true; // recurse
220221
}
@@ -238,8 +239,8 @@ void ArchiveBuilder::gather_klasses_and_symbols() {
238239

239240
if (DumpSharedSpaces) {
240241
// To ensure deterministic contents in the static archive, we need to ensure that
241-
// we iterate the MetsapceObjs in a deterministic order. It doesn't matter where
242-
// the MetsapceObjs are located originally, as they are copied sequentially into
242+
// we iterate the MetaspaceObjs in a deterministic order. It doesn't matter where
243+
// the MetaspaceObjs are located originally, as they are copied sequentially into
243244
// the archive during the iteration.
244245
//
245246
// The only issue here is that the symbol table and the system directories may be
@@ -483,7 +484,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s
483484

484485
memcpy(dest, src, bytes);
485486

486-
intptr_t* archived_vtable = CppVtables::get_archived_cpp_vtable(ref->msotype(), (address)dest);
487+
intptr_t* archived_vtable = CppVtables::get_archived_vtable(ref->msotype(), (address)dest);
487488
if (archived_vtable != NULL) {
488489
*(address*)dest = (address)archived_vtable;
489490
ArchivePtrMarker::mark_pointer((address*)dest);

src/hotspot/share/memory/archiveBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class ArchiveBuilder : public StackObj {
198198
virtual void iterate_roots(MetaspaceClosure* it, bool is_relocating_pointers) = 0;
199199

200200
// Conservative estimate for number of bytes needed for:
201-
size_t _estimated_metsapceobj_bytes; // all archived MetsapceObj's.
201+
size_t _estimated_metaspaceobj_bytes; // all archived MetaspaceObj's.
202202

203203
protected:
204204
DumpRegion* _current_dump_space;

src/hotspot/share/memory/archiveUtils.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ 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-
4440
void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end) {
4541
assert(_ptrmap == NULL, "initialize only once");
4642
_ptr_base = ptr_base;

src/hotspot/share/memory/cppVtables.cpp

Lines changed: 46 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
// + at run time: we clone the actual contents of the vtables from libjvm.so
5050
// into our own tables.
5151

52-
// Currently, the archive contain ONLY the following types of objects that have C++ vtables.
53-
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
52+
// Currently, the archive contains ONLY the following types of objects that have C++ vtables.
53+
#define CPP_VTABLE_TYPES_DO(f) \
5454
f(ConstantPool) \
5555
f(InstanceKlass) \
5656
f(InstanceClassLoaderKlass) \
@@ -78,60 +78,36 @@ class CppVtableInfo {
7878
}
7979
};
8080

81-
static inline intptr_t* vtable_of(Metadata* m) {
81+
static inline intptr_t* vtable_of(const Metadata* m) {
8282
return *((intptr_t**)m);
8383
}
8484

85-
static inline DumpRegion* mc_region() {
86-
return MetaspaceShared::misc_code_dump_space();
87-
}
88-
89-
template <class T> class CppVtableCloner : public T {
90-
static CppVtableInfo* _info;
91-
85+
template <class T> class CppVtableCloner {
9286
static int get_vtable_length(const char* name);
9387

9488
public:
95-
// Allocate and initialize the C++ vtable, starting from top, but do not go past end.
96-
static intptr_t* allocate(const char* name);
89+
// Allocate a clone of the vtable of T from the shared metaspace;
90+
// Initialize the contents of this clone.
91+
static CppVtableInfo* allocate_and_initialize(const char* name);
9792

98-
// Clone the vtable to ...
99-
static intptr_t* clone_vtable(const char* name, CppVtableInfo* info);
100-
101-
static void zero_vtable_clone() {
102-
assert(DumpSharedSpaces, "dump-time only");
103-
_info->zero();
104-
}
105-
106-
static bool is_valid_shared_object(const T* obj) {
107-
intptr_t* vptr = *(intptr_t**)obj;
108-
return vptr == _info->cloned_vtable();
109-
}
93+
// Copy the contents of the vtable of T into info->_cloned_vtable;
94+
static void initialize(const char* name, CppVtableInfo* info);
11095

11196
static void init_orig_cpp_vtptr(int kind);
11297
};
11398

114-
template <class T> CppVtableInfo* CppVtableCloner<T>::_info = NULL;
115-
11699
template <class T>
117-
intptr_t* CppVtableCloner<T>::allocate(const char* name) {
118-
assert(is_aligned(mc_region()->top(), sizeof(intptr_t)), "bad alignment");
100+
CppVtableInfo* CppVtableCloner<T>::allocate_and_initialize(const char* name) {
119101
int n = get_vtable_length(name);
120-
_info = (CppVtableInfo*)mc_region()->allocate(CppVtableInfo::byte_size(n));
121-
_info->set_vtable_size(n);
122-
123-
intptr_t* p = clone_vtable(name, _info);
124-
assert((char*)p == mc_region()->top(), "must be");
125-
126-
return _info->cloned_vtable();
102+
CppVtableInfo* info =
103+
(CppVtableInfo*)MetaspaceShared::misc_code_dump_space()->allocate(CppVtableInfo::byte_size(n));
104+
info->set_vtable_size(n);
105+
initialize(name, info);
106+
return info;
127107
}
128108

129109
template <class T>
130-
intptr_t* CppVtableCloner<T>::clone_vtable(const char* name, CppVtableInfo* info) {
131-
if (!DumpSharedSpaces) {
132-
assert(_info == 0, "_info is initialized only at dump time");
133-
_info = info; // Remember it -- it will be used by MetaspaceShared::is_valid_shared_method()
134-
}
110+
void CppVtableCloner<T>::initialize(const char* name, CppVtableInfo* info) {
135111
T tmp; // Allocate temporary dummy metadata object to get to the original vtable.
136112
int n = info->vtable_size();
137113
intptr_t* srcvtable = vtable_of(&tmp);
@@ -141,7 +117,6 @@ intptr_t* CppVtableCloner<T>::clone_vtable(const char* name, CppVtableInfo* info
141117
// safe to do memcpy.
142118
log_debug(cds, vtables)("Copying %3d vtable entries for %s", n, name);
143119
memcpy(dstvtable, srcvtable, sizeof(intptr_t) * n);
144-
return dstvtable + n;
145120
}
146121

147122
// To determine the size of the vtable for each type, we use the following
@@ -195,15 +170,12 @@ int CppVtableCloner<T>::get_vtable_length(const char* name) {
195170
return vtable_len;
196171
}
197172

198-
#define ALLOC_CPP_VTABLE_CLONE(c) \
199-
_cloned_cpp_vtptrs[c##_Kind] = CppVtableCloner<c>::allocate(#c); \
200-
ArchivePtrMarker::mark_pointer(&_cloned_cpp_vtptrs[c##_Kind]);
173+
#define ALLOCATE_AND_INITIALIZE_VTABLE(c) \
174+
_index[c##_Kind] = CppVtableCloner<c>::allocate_and_initialize(#c); \
175+
ArchivePtrMarker::mark_pointer(&_index[c##_Kind]);
201176

202-
#define CLONE_CPP_VTABLE(c) \
203-
p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p);
204-
205-
#define ZERO_CPP_VTABLE(c) \
206-
CppVtableCloner<c>::zero_vtable_clone();
177+
#define INITIALIZE_VTABLE(c) \
178+
CppVtableCloner<c>::initialize(#c, _index[c##_Kind]);
207179

208180
#define INIT_ORIG_CPP_VTPTRS(c) \
209181
CppVtableCloner<c>::init_orig_cpp_vtptr(c##_Kind);
@@ -212,7 +184,7 @@ int CppVtableCloner<T>::get_vtable_length(const char* name) {
212184

213185
enum ClonedVtableKind {
214186
// E.g., ConstantPool_Kind == 0, InstanceKlass_Kind == 1, etc.
215-
CPP_VTABLE_PATCH_TYPES_DO(DECLARE_CLONED_VTABLE_KIND)
187+
CPP_VTABLE_TYPES_DO(DECLARE_CLONED_VTABLE_KIND)
216188
_num_cloned_vtable_kinds
217189
};
218190

@@ -235,23 +207,30 @@ void CppVtableCloner<T>::init_orig_cpp_vtptr(int kind) {
235207
// ConstantPool* cp = ....; // an archived constant pool
236208
// InstanceKlass* ik = ....;// an archived class
237209
// the following holds true:
238-
// _cloned_cpp_vtptrs[ConstantPool_Kind] == ((intptr_t**)cp)[0]
239-
// _cloned_cpp_vtptrs[InstanceKlass_Kind] == ((intptr_t**)ik)[0]
240-
static intptr_t** _cloned_cpp_vtptrs = NULL;
210+
// _index[ConstantPool_Kind]->cloned_vtable() == ((intptr_t**)cp)[0]
211+
// _index[InstanceKlass_Kind]->cloned_vtable() == ((intptr_t**)ik)[0]
212+
CppVtableInfo** CppVtables::_index = NULL;
241213

242-
void CppVtables::allocate_cloned_cpp_vtptrs() {
214+
char* CppVtables::dumptime_init() {
243215
assert(DumpSharedSpaces, "must");
244-
size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(intptr_t*);
245-
_cloned_cpp_vtptrs = (intptr_t**)mc_region()->allocate(vtptrs_bytes);
216+
size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(CppVtableInfo*);
217+
_index = (CppVtableInfo**)MetaspaceShared::misc_code_dump_space()->allocate(vtptrs_bytes);
218+
219+
CPP_VTABLE_TYPES_DO(ALLOCATE_AND_INITIALIZE_VTABLE);
220+
221+
return (char*)_index;
246222
}
247223

248-
void CppVtables::serialize_cloned_cpp_vtptrs(SerializeClosure* soc) {
249-
soc->do_ptr((void**)&_cloned_cpp_vtptrs);
224+
void CppVtables::serialize(SerializeClosure* soc) {
225+
soc->do_ptr((void**)&_index);
226+
if (soc->reading()) {
227+
CPP_VTABLE_TYPES_DO(INITIALIZE_VTABLE);
228+
}
250229
}
251230

252-
intptr_t* CppVtables::get_archived_cpp_vtable(MetaspaceObj::Type msotype, address obj) {
231+
intptr_t* CppVtables::get_archived_vtable(MetaspaceObj::Type msotype, address obj) {
253232
if (!_orig_cpp_vtptrs_inited) {
254-
CPP_VTABLE_PATCH_TYPES_DO(INIT_ORIG_CPP_VTPTRS);
233+
CPP_VTABLE_TYPES_DO(INIT_ORIG_CPP_VTPTRS);
255234
_orig_cpp_vtptrs_inited = true;
256235
}
257236

@@ -283,50 +262,27 @@ intptr_t* CppVtables::get_archived_cpp_vtable(MetaspaceObj::Type msotype, addres
283262
}
284263
if (kind >= _num_cloned_vtable_kinds) {
285264
fatal("Cannot find C++ vtable for " INTPTR_FORMAT " -- you probably added"
286-
" a new subtype of Klass or MetaData without updating CPP_VTABLE_PATCH_TYPES_DO",
265+
" a new subtype of Klass or MetaData without updating CPP_VTABLE_TYPES_DO",
287266
p2i(obj));
288267
}
289268
}
290269

291270
if (kind >= 0) {
292271
assert(kind < _num_cloned_vtable_kinds, "must be");
293-
return _cloned_cpp_vtptrs[kind];
272+
return _index[kind]->cloned_vtable();
294273
} else {
295274
return NULL;
296275
}
297276
}
298277

299-
// This can be called at both dump time and run time:
300-
// - clone the contents of the c++ vtables into the space
301-
// allocated by allocate_cpp_vtable_clones()
302-
void CppVtables::clone_cpp_vtables(intptr_t* p) {
303-
assert(DumpSharedSpaces || UseSharedSpaces, "sanity");
304-
CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE);
305-
}
306-
307-
void CppVtables::zero_cpp_vtable_clones_for_writing() {
278+
void CppVtables::zero_archived_vtables() {
308279
assert(DumpSharedSpaces, "dump-time only");
309-
CPP_VTABLE_PATCH_TYPES_DO(ZERO_CPP_VTABLE);
310-
}
311-
312-
// Allocate and initialize the C++ vtables, starting from top, but do not go past end.
313-
char* CppVtables::allocate_cpp_vtable_clones() {
314-
char* cloned_vtables = mc_region()->top(); // This is the beginning of all the cloned vtables
315-
316-
assert(DumpSharedSpaces, "dump-time only");
317-
// Layout (each slot is a intptr_t):
318-
// [number of slots in the first vtable = n1]
319-
// [ <n1> slots for the first vtable]
320-
// [number of slots in the first second = n2]
321-
// [ <n2> slots for the second vtable]
322-
// ...
323-
// The order of the vtables is the same as the CPP_VTAB_PATCH_TYPES_DO macro.
324-
CPP_VTABLE_PATCH_TYPES_DO(ALLOC_CPP_VTABLE_CLONE);
325-
326-
return cloned_vtables;
280+
for (int kind = 0; kind < _num_cloned_vtable_kinds; kind ++) {
281+
_index[kind]->zero();
282+
}
327283
}
328284

329285
bool CppVtables::is_valid_shared_method(const Method* m) {
330286
assert(MetaspaceShared::is_in_shared_metaspace(m), "must be");
331-
return CppVtableCloner<Method>::is_valid_shared_object(m);
287+
return vtable_of(m) == _index[Method_Kind]->cloned_vtable();
332288
}

src/hotspot/share/memory/cppVtables.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@
3131

3232
class Method;
3333
class SerializeClosure;
34+
class CppVtableInfo;
3435

3536
// Support for C++ vtables in CDS archive.
3637
class CppVtables : AllStatic {
37-
static void patch_cpp_vtable_pointers();
38+
static CppVtableInfo** _index;
3839
public:
39-
static char* allocate_cpp_vtable_clones();
40-
static void allocate_cloned_cpp_vtptrs();
41-
static void clone_cpp_vtables(intptr_t* p);
42-
static void zero_cpp_vtable_clones_for_writing();
43-
static intptr_t* get_archived_cpp_vtable(MetaspaceObj::Type msotype, address obj);
44-
static void serialize_cloned_cpp_vtptrs(SerializeClosure* sc);
40+
static char* dumptime_init();
41+
static void zero_archived_vtables();
42+
static intptr_t* get_archived_vtable(MetaspaceObj::Type msotype, address obj);
43+
static void serialize(SerializeClosure* sc);
4544
static bool is_valid_shared_method(const Method* m) NOT_CDS_RETURN_(false);
4645
};
4746

0 commit comments

Comments
 (0)