11/*
2- * Copyright (c) 2018, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2022 , 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
@@ -128,7 +128,6 @@ const static int num_fmg_open_archive_subgraph_entry_fields =
128128 sizeof (fmg_open_archive_subgraph_entry_fields) / sizeof (ArchivableStaticFieldInfo);
129129
130130GrowableArrayCHeap<oop, mtClassShared>* HeapShared::_pending_roots = NULL ;
131- narrowOop HeapShared::_roots_narrow;
132131OopHandle HeapShared::_roots;
133132
134133#ifdef ASSERT
@@ -152,7 +151,6 @@ void HeapShared::fixup_regions() {
152151 fill_failed_loaded_region ();
153152 }
154153 if (is_fully_available ()) {
155- _roots = OopHandle (Universe::vm_global (), decode_from_archive (_roots_narrow));
156154 if (!MetaspaceShared::use_full_module_graph ()) {
157155 // Need to remove all the archived java.lang.Module objects from HeapShared::roots().
158156 ClassLoaderDataShared::clear_archived_oops ();
@@ -236,12 +234,6 @@ objArrayOop HeapShared::roots() {
236234 return roots;
237235}
238236
239- void HeapShared::set_roots (narrowOop roots) {
240- assert (UseSharedSpaces, " runtime only" );
241- assert (is_fully_available (), " must be" );
242- _roots_narrow = roots;
243- }
244-
245237// Returns an objArray that contains all the roots of the archived objects
246238oop HeapShared::get_root (int index, bool clear) {
247239 assert (index >= 0 , " sanity" );
@@ -670,7 +662,23 @@ void HeapShared::write_subgraph_info_table() {
670662 writer.dump (&_run_time_subgraph_info_table, " subgraphs" );
671663}
672664
673- void HeapShared::serialize_subgraph_info_table_header (SerializeClosure* soc) {
665+ void HeapShared::serialize (SerializeClosure* soc) {
666+ oop roots_oop = NULL ;
667+
668+ if (soc->reading ()) {
669+ soc->do_oop (&roots_oop); // read from archive
670+ assert (oopDesc::is_oop_or_null (roots_oop), " is oop" );
671+ // Create an OopHandle only if we have actually mapped or loaded the roots
672+ if (roots_oop != NULL ) {
673+ assert (HeapShared::is_fully_available (), " must be" );
674+ _roots = OopHandle (Universe::vm_global (), roots_oop);
675+ }
676+ } else {
677+ // writing
678+ roots_oop = roots ();
679+ soc->do_oop (&roots_oop); // write to archive
680+ }
681+
674682 _run_time_subgraph_info_table.serialize_header (soc);
675683}
676684
@@ -1695,7 +1703,6 @@ bool HeapShared::load_heap_regions(FileMapInfo* mapinfo) {
16951703
16961704 init_loaded_heap_relocation (loaded_regions, num_loaded_regions);
16971705 _is_loaded = true ;
1698- set_roots (mapinfo->heap_obj_roots ());
16991706
17001707 return true ;
17011708}
0 commit comments