# HG changeset patch # User iklam # Date 1574462920 28800 # Node ID ee0030a2a306c7aa9a87b2f14c6b21427fb4970a # Parent bd9dba789919954236f2ebf961e60afe49fc3645 8234429: appcds/dynamicArchive tests crashing with Graal Reviewed-by: ccheung diff -r bd9dba789919 -r ee0030a2a306 src/hotspot/share/memory/dynamicArchive.cpp --- a/src/hotspot/share/memory/dynamicArchive.cpp Fri Nov 22 17:03:55 2019 -0800 +++ b/src/hotspot/share/memory/dynamicArchive.cpp Fri Nov 22 14:48:40 2019 -0800 @@ -494,6 +494,7 @@ size_t estimate_class_file_size(); address reserve_space_and_init_buffer_to_target_delta(); void init_header(address addr); + void release_header(); void make_trampolines(); void make_klasses_shareable(); void sort_methods(InstanceKlass* ik) const; @@ -664,6 +665,7 @@ } write_archive(serialized_data_start); + release_header(); assert(_num_dump_regions_used == _total_dump_regions, "must be"); verify_universe("After CDS dynamic dump"); @@ -755,6 +757,7 @@ init_first_dump_space(reserved_bottom); FileMapInfo* mapinfo = new FileMapInfo(false); + assert(FileMapInfo::dynamic_info() == mapinfo, "must be"); _header = mapinfo->dynamic_header(); Thread* THREAD = Thread::current(); @@ -766,6 +769,19 @@ _header->populate(base_info, os::vm_allocation_granularity()); } +void DynamicArchiveBuilder::release_header() { + // We temporarily allocated a dynamic FileMapInfo for dumping, which makes it appear we + // have mapped a dynamic archive, but we actually have not. We are in a safepoint now. + // Let's free it so that if class loading happens after we leave the safepoint, nothing + // bad will happen. + assert(SafepointSynchronize::is_at_safepoint(), "must be"); + FileMapInfo *mapinfo = FileMapInfo::dynamic_info(); + assert(mapinfo != NULL && _header == mapinfo->dynamic_header(), "must be"); + delete mapinfo; + assert(!DynamicArchive::is_mapped(), "must be"); + _header = NULL; +} + size_t DynamicArchiveBuilder::estimate_trampoline_size() { size_t total = 0; size_t each_method_bytes =