--- old/src/hotspot/share/memory/heapShared.cpp 2018-07-06 15:18:01.546829901 -0400 +++ new/src/hotspot/share/memory/heapShared.cpp 2018-07-06 15:18:00.182751252 -0400 @@ -81,13 +81,13 @@ } // Add an entry field to the current KlassSubGraphInfo. -void KlassSubGraphInfo::add_subgraph_entry_field(int field_offset, oop v) { +void KlassSubGraphInfo::add_subgraph_entry_field(int static_field_offset, oop v) { assert(DumpSharedSpaces, "dump time only"); if (_subgraph_entry_fields == NULL) { _subgraph_entry_fields = new(ResourceObj::C_HEAP, mtClass) GrowableArray(10, true); } - _subgraph_entry_fields->append((juint)field_offset); + _subgraph_entry_fields->append((juint)static_field_offset); _subgraph_entry_fields->append(CompressedOops::encode(v)); } @@ -95,6 +95,8 @@ // Only objects of boot classes can be included in sub-graph. void KlassSubGraphInfo::add_subgraph_object_klass(Klass* orig_k, Klass *relocated_k) { assert(DumpSharedSpaces, "dump time only"); + assert(relocated_k == MetaspaceShared::get_relocated_klass(orig_k), + "must be the relocated Klass in the shared space"); if (_subgraph_object_klasses == NULL) { _subgraph_object_klasses = @@ -365,16 +367,17 @@ return; } - size_t delta = pointer_delta((HeapWord*)_archived_referencing_obj, - (HeapWord*)_orig_referencing_obj); - T* new_p = (T*)((HeapWord*)p + delta); + size_t field_delta = pointer_delta( + p, _orig_referencing_obj, sizeof(char)); + T* new_p = (T*)(address(_archived_referencing_obj) + field_delta); oop archived = MetaspaceShared::find_archived_heap_object(obj); if (archived != NULL) { // There is an archived copy existing, update reference to point // to the archived copy RawAccess::oop_store(new_p, archived); - log.print("--- archived copy existing, store archived " PTR_FORMAT " in " PTR_FORMAT, - p2i(archived), p2i(new_p)); + log.print( + "--- found existing archived copy, store archived " PTR_FORMAT " in " PTR_FORMAT, + p2i(archived), p2i(new_p)); return; } @@ -400,8 +403,6 @@ // module system initialization Klass *orig_k = obj->klass(); Klass *relocated_k = archived->klass(); - assert(relocated_k == MetaspaceShared::get_relocated_klass(orig_k), - "must be the relocated Klass in the shared space"); _subgraph_info->add_subgraph_object_klass(orig_k, relocated_k); } } @@ -442,10 +443,10 @@ // for loading and initialzing before any object in the archived graph can // be accessed at runtime. // -void HeapShared::walk_from_field_and_archiving(Klass *k, - int field_offset, - BasicType field_type, - TRAPS) { +void HeapShared::archive_reachable_objects_from_static_field(Klass *k, + int field_offset, + BasicType field_type, + TRAPS) { assert(DumpSharedSpaces, "dump time only"); assert(k->is_instance_klass(), "sanity"); assert(InstanceKlass::cast(k)->is_shared_boot_class(), @@ -472,8 +473,10 @@ // get the archived copy of the field referenced object oop af = MetaspaceShared::archive_heap_object(f, THREAD); - WalkOopAndArchiveClosure walker(1, subgraph_info, f, af); - f->oop_iterate(&walker); + if (!MetaspaceShared::is_archive_object(f)) { + WalkOopAndArchiveClosure walker(1, subgraph_info, f, af); + f->oop_iterate(&walker); + } // The field value is not preserved in the archived mirror. // Record the field as a new subGraph entry point. The recorded @@ -481,8 +484,6 @@ subgraph_info->add_subgraph_entry_field(field_offset, af); Klass *relocated_k = af->klass(); Klass *orig_k = f->klass(); - assert(relocated_k == MetaspaceShared::get_relocated_klass(orig_k), - "must be the relocated Klass in the shared space"); subgraph_info->add_subgraph_object_klass(orig_k, relocated_k); } else { // The field contains null, we still need to record the entry point, @@ -500,6 +501,6 @@ archive_object_graph_do(SystemDictionary::ArchivedModuleGraph_klass(), jdk_internal_module_ArchivedModuleGraph::archivedMainModule_offset(), T_OBJECT, CHECK) void HeapShared::archive_module_graph_objects(Thread* THREAD) { - do_module_object_graph(walk_from_field_and_archiving); + do_module_object_graph(archive_reachable_objects_from_static_field); } #endif // INCLUDE_CDS_JAVA_HEAP