6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotArtifactFinder.hpp"
26 #include "cds/aotClassLinker.hpp"
27 #include "cds/aotCompressedPointers.hpp"
28 #include "cds/aotLogging.hpp"
29 #include "cds/aotMapLogger.hpp"
30 #include "cds/aotMetaspace.hpp"
31 #include "cds/archiveBuilder.hpp"
32 #include "cds/archiveUtils.hpp"
33 #include "cds/cdsConfig.hpp"
34 #include "cds/cppVtables.hpp"
35 #include "cds/dumpAllocStats.hpp"
36 #include "cds/dynamicArchive.hpp"
37 #include "cds/heapShared.hpp"
38 #include "cds/regeneratedClasses.hpp"
39 #include "classfile/classLoader.hpp"
40 #include "classfile/classLoaderDataShared.hpp"
41 #include "classfile/javaClasses.hpp"
42 #include "classfile/symbolTable.hpp"
43 #include "classfile/systemDictionaryShared.hpp"
44 #include "classfile/vmClasses.hpp"
45 #include "code/aotCodeCache.hpp"
46 #include "interpreter/abstractInterpreter.hpp"
47 #include "jvm.h"
48 #include "logging/log.hpp"
49 #include "memory/allStatic.hpp"
50 #include "memory/memoryReserver.hpp"
51 #include "memory/memRegion.hpp"
52 #include "memory/resourceArea.hpp"
53 #include "oops/compressedKlass.inline.hpp"
54 #include "oops/instanceKlass.hpp"
55 #include "oops/methodCounters.hpp"
56 #include "oops/methodData.hpp"
57 #include "oops/objArrayKlass.hpp"
58 #include "oops/objArrayOop.inline.hpp"
59 #include "oops/oopHandle.inline.hpp"
60 #include "oops/trainingData.hpp"
61 #include "runtime/arguments.hpp"
62 #include "runtime/globals_extension.hpp"
63 #include "runtime/javaThread.hpp"
64 #include "runtime/sharedRuntime.hpp"
65 #include "utilities/align.hpp"
66 #include "utilities/bitMap.inline.hpp"
67 #include "utilities/formatBuffer.hpp"
68
69 ArchiveBuilder* ArchiveBuilder::_current = nullptr;
70
71 ArchiveBuilder::OtherROAllocMark::~OtherROAllocMark() {
72 char* newtop = ArchiveBuilder::current()->_ro_region.top();
73 ArchiveBuilder::alloc_stats()->record_other_type(int(newtop - _oldtop), true);
74 }
75
76 ArchiveBuilder::SourceObjList::SourceObjList() : _ptrmap(16 * K, mtClassShared) {
77 _total_bytes = 0;
78 _objs = new (mtClassShared) GrowableArray<SourceObjInfo*>(128 * K, mtClassShared);
79 }
80
81 ArchiveBuilder::SourceObjList::~SourceObjList() {
82 delete _objs;
83 }
166 _ptrmap.iterate(&relocator, start, end);
167 }
168
169 ArchiveBuilder::ArchiveBuilder() :
170 _current_dump_region(nullptr),
171 _buffer_bottom(nullptr),
172 _requested_static_archive_bottom(nullptr),
173 _requested_static_archive_top(nullptr),
174 _requested_dynamic_archive_bottom(nullptr),
175 _requested_dynamic_archive_top(nullptr),
176 _mapped_static_archive_bottom(nullptr),
177 _mapped_static_archive_top(nullptr),
178 _buffer_to_requested_delta(0),
179 _pz_region("pz"), // protection zone -- used only during dumping; does NOT exist in cds archive.
180 _rw_region("rw"),
181 _ro_region("ro"),
182 _ac_region("ac"),
183 _ptrmap(mtClassShared),
184 _rw_ptrmap(mtClassShared),
185 _ro_ptrmap(mtClassShared),
186 _rw_src_objs(),
187 _ro_src_objs(),
188 _src_obj_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
189 _buffered_to_src_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
190 _total_heap_region_size(0)
191 {
192 _klasses = new (mtClassShared) GrowableArray<Klass*>(4 * K, mtClassShared);
193 _symbols = new (mtClassShared) GrowableArray<Symbol*>(256 * K, mtClassShared);
194 _entropy_seed = 0x12345678;
195 _relocated_ptr_info._num_ptrs = 0;
196 _relocated_ptr_info._num_tagged_ptrs = 0;
197 _relocated_ptr_info._num_nulled_ptrs = 0;
198 assert(_current == nullptr, "must be");
199 _current = this;
200 }
201
202 ArchiveBuilder::~ArchiveBuilder() {
203 assert(_current == this, "must be");
204 _current = nullptr;
205
782
783 for (int i = 0; i < klasses()->length(); i++) {
784 // Some of the code in ConstantPool::remove_unshareable_info() requires the classes
785 // to be in linked state, so it must be call here before the next loop, which returns
786 // all classes to unlinked state.
787 Klass* k = get_buffered_addr(klasses()->at(i));
788 if (k->is_instance_klass()) {
789 InstanceKlass::cast(k)->constants()->remove_unshareable_info();
790 }
791 }
792
793 for (int i = 0; i < klasses()->length(); i++) {
794 const char* type;
795 const char* unlinked = "";
796 const char* kind = "";
797 const char* hidden = "";
798 const char* old = "";
799 const char* generated = "";
800 const char* aotlinked_msg = "";
801 const char* inited_msg = "";
802 Klass* k = get_buffered_addr(klasses()->at(i));
803 bool inited = false;
804 k->remove_java_mirror();
805 #ifdef _LP64
806 if (UseCompactObjectHeaders) {
807 Klass* requested_k = to_requested(k);
808 address narrow_klass_base = _requested_static_archive_bottom; // runtime encoding base == runtime mapping start
809 const int narrow_klass_shift = precomputed_narrow_klass_shift();
810 narrowKlass nk = CompressedKlassPointers::encode_not_null_without_asserts(requested_k, narrow_klass_base, narrow_klass_shift);
811 k->set_prototype_header(markWord::prototype().set_narrow_klass(nk));
812 }
813 #endif //_LP64
814 if (k->is_objArray_klass()) {
815 // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
816 // on their array classes.
817 num_obj_array_klasses ++;
818 type = "array";
819 } else if (k->is_typeArray_klass()) {
820 num_type_array_klasses ++;
821 type = "array";
890 ADD_COUNT(num_enum_klasses);
891 }
892
893 if (CDSConfig::is_old_class_for_verifier(ik)) {
894 ADD_COUNT(num_old_klasses);
895 old = " old";
896 }
897
898 if (ik->is_aot_generated_class()) {
899 generated = " generated";
900 }
901 if (aotlinked) {
902 aotlinked_msg = " aot-linked";
903 }
904 if (inited) {
905 if (InstanceKlass::cast(k)->static_field_size() == 0) {
906 inited_msg = " inited (no static fields)";
907 } else {
908 inited_msg = " inited";
909 }
910 }
911
912 AOTMetaspace::rewrite_bytecodes_and_calculate_fingerprints(Thread::current(), ik);
913 ik->remove_unshareable_info();
914 }
915
916 if (aot_log_is_enabled(Debug, aot, class)) {
917 ResourceMark rm;
918 aot_log_debug(aot, class)("klasses[%5d] = " PTR_FORMAT " %-5s %s%s%s%s%s%s%s%s", i,
919 p2i(to_requested(k)), type, k->external_name(),
920 kind, hidden, old, unlinked, generated, aotlinked_msg, inited_msg);
921 }
922 }
923
924 #define STATS_FORMAT "= %5d, aot-linked = %5d, inited = %5d"
925 #define STATS_PARAMS(x) num_ ## x, num_ ## x ## _a, num_ ## x ## _i
926
927 aot_log_info(aot)("Number of classes %d", num_instance_klasses + num_obj_array_klasses + num_type_array_klasses);
928 aot_log_info(aot)(" instance classes " STATS_FORMAT, STATS_PARAMS(instance_klasses));
929 aot_log_info(aot)(" boot " STATS_FORMAT, STATS_PARAMS(boot_klasses));
930 aot_log_info(aot)(" vm " STATS_FORMAT, STATS_PARAMS(vm_klasses));
931 aot_log_info(aot)(" platform " STATS_FORMAT, STATS_PARAMS(platform_klasses));
932 aot_log_info(aot)(" app " STATS_FORMAT, STATS_PARAMS(app_klasses));
933 aot_log_info(aot)(" unregistered " STATS_FORMAT, STATS_PARAMS(unregistered_klasses));
934 aot_log_info(aot)(" (enum) " STATS_FORMAT, STATS_PARAMS(enum_klasses));
935 aot_log_info(aot)(" (hidden) " STATS_FORMAT, STATS_PARAMS(hidden_klasses));
936 aot_log_info(aot)(" (old) " STATS_FORMAT, STATS_PARAMS(old_klasses));
937 aot_log_info(aot)(" (unlinked) = %5d, boot = %d, plat = %d, app = %d, unreg = %d",
938 num_unlinked_klasses, boot_unlinked, platform_unlinked, app_unlinked, unreg_unlinked);
939 aot_log_info(aot)(" obj array classes = %5d", num_obj_array_klasses);
940 aot_log_info(aot)(" type array classes = %5d", num_type_array_klasses);
1124 patcher.doit();
1125 }
1126 }
1127
1128 void ArchiveBuilder::print_stats() {
1129 _alloc_stats.print_stats(int(_ro_region.used()), int(_rw_region.used()));
1130 }
1131
1132 void ArchiveBuilder::write_archive(FileMapInfo* mapinfo, AOTMappedHeapInfo* mapped_heap_info, AOTStreamedHeapInfo* streamed_heap_info) {
1133 // Make sure NUM_CDS_REGIONS (exported in cds.h) agrees with
1134 // AOTMetaspace::n_regions (internal to hotspot).
1135 assert(NUM_CDS_REGIONS == AOTMetaspace::n_regions, "sanity");
1136
1137 ResourceMark rm;
1138
1139 write_region(mapinfo, AOTMetaspace::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
1140 write_region(mapinfo, AOTMetaspace::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
1141 write_region(mapinfo, AOTMetaspace::ac, &_ac_region, /*read_only=*/false,/*allow_exec=*/false);
1142
1143 // Split pointer map into read-write and read-only bitmaps
1144 ArchivePtrMarker::initialize_rw_ro_maps(&_rw_ptrmap, &_ro_ptrmap);
1145
1146 size_t bitmap_size_in_bytes;
1147 char* bitmap = mapinfo->write_bitmap_region(ArchivePtrMarker::rw_ptrmap(),
1148 ArchivePtrMarker::ro_ptrmap(),
1149 mapped_heap_info,
1150 streamed_heap_info,
1151 bitmap_size_in_bytes);
1152
1153 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
1154 _total_heap_region_size = mapinfo->write_mapped_heap_region(mapped_heap_info);
1155 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
1156 _total_heap_region_size = mapinfo->write_streamed_heap_region(streamed_heap_info);
1157 }
1158
1159 print_region_stats(mapinfo, mapped_heap_info, streamed_heap_info);
1160
1161 mapinfo->set_requested_base((char*)AOTMetaspace::requested_base_address());
1162 mapinfo->set_header_crc(mapinfo->compute_header_crc());
1163 // After this point, we should not write any data into mapinfo->header() since this
1164 // would corrupt its checksum we have calculated before.
1165 mapinfo->write_header();
1166 mapinfo->close();
1167
1168 if (log_is_enabled(Info, aot)) {
1169 log_info(aot)("Full module graph = %s", CDSConfig::is_dumping_full_module_graph() ? "enabled" : "disabled");
1170 print_stats();
1171 }
1172
1173 if (log_is_enabled(Info, aot, map)) {
1174 AOTMapLogger::dumptime_log(this, mapinfo, mapped_heap_info, streamed_heap_info, bitmap, bitmap_size_in_bytes);
1175 }
1176 CDS_JAVA_HEAP_ONLY(HeapShared::destroy_archived_object_cache());
1177 FREE_C_HEAP_ARRAY(char, bitmap);
1178 }
1179
1180 void ArchiveBuilder::write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region, bool read_only, bool allow_exec) {
1181 mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
1182 }
1183
1184 void ArchiveBuilder::count_relocated_pointer(bool tagged, bool nulled) {
1185 _relocated_ptr_info._num_ptrs ++;
1186 _relocated_ptr_info._num_tagged_ptrs += tagged ? 1 : 0;
1187 _relocated_ptr_info._num_nulled_ptrs += nulled ? 1 : 0;
1188 }
1189
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotArtifactFinder.hpp"
26 #include "cds/aotCacheAccess.hpp"
27 #include "cds/aotClassLinker.hpp"
28 #include "cds/aotCompressedPointers.hpp"
29 #include "cds/aotLogging.hpp"
30 #include "cds/aotMapLogger.hpp"
31 #include "cds/aotMetaspace.hpp"
32 #include "cds/archiveBuilder.hpp"
33 #include "cds/archiveUtils.hpp"
34 #include "cds/cdsConfig.hpp"
35 #include "cds/cppVtables.hpp"
36 #include "cds/dumpAllocStats.hpp"
37 #include "cds/dynamicArchive.hpp"
38 #include "cds/finalImageRecipes.hpp"
39 #include "cds/heapShared.hpp"
40 #include "cds/regeneratedClasses.hpp"
41 #include "classfile/classLoader.hpp"
42 #include "classfile/classLoaderDataShared.hpp"
43 #include "classfile/javaClasses.hpp"
44 #include "classfile/symbolTable.hpp"
45 #include "classfile/systemDictionaryShared.hpp"
46 #include "classfile/vmClasses.hpp"
47 #include "code/aotCodeCache.hpp"
48 #include "interpreter/abstractInterpreter.hpp"
49 #include "jvm.h"
50 #include "logging/log.hpp"
51 #include "memory/allStatic.hpp"
52 #include "memory/memoryReserver.hpp"
53 #include "memory/memRegion.hpp"
54 #include "memory/resourceArea.hpp"
55 #include "oops/compressedKlass.inline.hpp"
56 #include "oops/instanceKlass.hpp"
57 #include "oops/methodCounters.hpp"
58 #include "oops/methodData.hpp"
59 #include "oops/objArrayKlass.hpp"
60 #include "oops/objArrayOop.inline.hpp"
61 #include "oops/oopHandle.inline.hpp"
62 #include "oops/trainingData.hpp"
63 #include "runtime/arguments.hpp"
64 #include "runtime/globals_extension.hpp"
65 #include "runtime/javaThread.hpp"
66 #include "runtime/safepointVerifiers.hpp"
67 #include "runtime/sharedRuntime.hpp"
68 #include "utilities/align.hpp"
69 #include "utilities/bitMap.inline.hpp"
70 #include "utilities/formatBuffer.hpp"
71
72 ArchiveBuilder* ArchiveBuilder::_current = nullptr;
73
74 ArchiveBuilder::OtherROAllocMark::~OtherROAllocMark() {
75 char* newtop = ArchiveBuilder::current()->_ro_region.top();
76 ArchiveBuilder::alloc_stats()->record_other_type(int(newtop - _oldtop), true);
77 }
78
79 ArchiveBuilder::SourceObjList::SourceObjList() : _ptrmap(16 * K, mtClassShared) {
80 _total_bytes = 0;
81 _objs = new (mtClassShared) GrowableArray<SourceObjInfo*>(128 * K, mtClassShared);
82 }
83
84 ArchiveBuilder::SourceObjList::~SourceObjList() {
85 delete _objs;
86 }
169 _ptrmap.iterate(&relocator, start, end);
170 }
171
172 ArchiveBuilder::ArchiveBuilder() :
173 _current_dump_region(nullptr),
174 _buffer_bottom(nullptr),
175 _requested_static_archive_bottom(nullptr),
176 _requested_static_archive_top(nullptr),
177 _requested_dynamic_archive_bottom(nullptr),
178 _requested_dynamic_archive_top(nullptr),
179 _mapped_static_archive_bottom(nullptr),
180 _mapped_static_archive_top(nullptr),
181 _buffer_to_requested_delta(0),
182 _pz_region("pz"), // protection zone -- used only during dumping; does NOT exist in cds archive.
183 _rw_region("rw"),
184 _ro_region("ro"),
185 _ac_region("ac"),
186 _ptrmap(mtClassShared),
187 _rw_ptrmap(mtClassShared),
188 _ro_ptrmap(mtClassShared),
189 _ac_ptrmap(mtClassShared),
190 _rw_src_objs(),
191 _ro_src_objs(),
192 _src_obj_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
193 _buffered_to_src_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
194 _total_heap_region_size(0)
195 {
196 _klasses = new (mtClassShared) GrowableArray<Klass*>(4 * K, mtClassShared);
197 _symbols = new (mtClassShared) GrowableArray<Symbol*>(256 * K, mtClassShared);
198 _entropy_seed = 0x12345678;
199 _relocated_ptr_info._num_ptrs = 0;
200 _relocated_ptr_info._num_tagged_ptrs = 0;
201 _relocated_ptr_info._num_nulled_ptrs = 0;
202 assert(_current == nullptr, "must be");
203 _current = this;
204 }
205
206 ArchiveBuilder::~ArchiveBuilder() {
207 assert(_current == this, "must be");
208 _current = nullptr;
209
786
787 for (int i = 0; i < klasses()->length(); i++) {
788 // Some of the code in ConstantPool::remove_unshareable_info() requires the classes
789 // to be in linked state, so it must be call here before the next loop, which returns
790 // all classes to unlinked state.
791 Klass* k = get_buffered_addr(klasses()->at(i));
792 if (k->is_instance_klass()) {
793 InstanceKlass::cast(k)->constants()->remove_unshareable_info();
794 }
795 }
796
797 for (int i = 0; i < klasses()->length(); i++) {
798 const char* type;
799 const char* unlinked = "";
800 const char* kind = "";
801 const char* hidden = "";
802 const char* old = "";
803 const char* generated = "";
804 const char* aotlinked_msg = "";
805 const char* inited_msg = "";
806 const char* early_init_msg = "";
807 Klass* k = get_buffered_addr(klasses()->at(i));
808 bool inited = false;
809 k->remove_java_mirror();
810 #ifdef _LP64
811 if (UseCompactObjectHeaders) {
812 Klass* requested_k = to_requested(k);
813 address narrow_klass_base = _requested_static_archive_bottom; // runtime encoding base == runtime mapping start
814 const int narrow_klass_shift = precomputed_narrow_klass_shift();
815 narrowKlass nk = CompressedKlassPointers::encode_not_null_without_asserts(requested_k, narrow_klass_base, narrow_klass_shift);
816 k->set_prototype_header(markWord::prototype().set_narrow_klass(nk));
817 }
818 #endif //_LP64
819 if (k->is_objArray_klass()) {
820 // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
821 // on their array classes.
822 num_obj_array_klasses ++;
823 type = "array";
824 } else if (k->is_typeArray_klass()) {
825 num_type_array_klasses ++;
826 type = "array";
895 ADD_COUNT(num_enum_klasses);
896 }
897
898 if (CDSConfig::is_old_class_for_verifier(ik)) {
899 ADD_COUNT(num_old_klasses);
900 old = " old";
901 }
902
903 if (ik->is_aot_generated_class()) {
904 generated = " generated";
905 }
906 if (aotlinked) {
907 aotlinked_msg = " aot-linked";
908 }
909 if (inited) {
910 if (InstanceKlass::cast(k)->static_field_size() == 0) {
911 inited_msg = " inited (no static fields)";
912 } else {
913 inited_msg = " inited";
914 }
915 if (AOTCacheAccess::is_early_aot_inited_class(ik)) {
916 early_init_msg = " early";
917 }
918 }
919
920 AOTMetaspace::rewrite_bytecodes_and_calculate_fingerprints(Thread::current(), ik);
921 ik->remove_unshareable_info();
922 }
923
924 if (aot_log_is_enabled(Debug, aot, class)) {
925 ResourceMark rm;
926 aot_log_debug(aot, class)("klasses[%5d] = " PTR_FORMAT " %-5s %s%s%s%s%s%s%s%s%s", i,
927 p2i(to_requested(k)), type, k->external_name(),
928 kind, hidden, old, unlinked, generated, aotlinked_msg, early_init_msg, inited_msg);
929 }
930 }
931
932 #define STATS_FORMAT "= %5d, aot-linked = %5d, inited = %5d"
933 #define STATS_PARAMS(x) num_ ## x, num_ ## x ## _a, num_ ## x ## _i
934
935 aot_log_info(aot)("Number of classes %d", num_instance_klasses + num_obj_array_klasses + num_type_array_klasses);
936 aot_log_info(aot)(" instance classes " STATS_FORMAT, STATS_PARAMS(instance_klasses));
937 aot_log_info(aot)(" boot " STATS_FORMAT, STATS_PARAMS(boot_klasses));
938 aot_log_info(aot)(" vm " STATS_FORMAT, STATS_PARAMS(vm_klasses));
939 aot_log_info(aot)(" platform " STATS_FORMAT, STATS_PARAMS(platform_klasses));
940 aot_log_info(aot)(" app " STATS_FORMAT, STATS_PARAMS(app_klasses));
941 aot_log_info(aot)(" unregistered " STATS_FORMAT, STATS_PARAMS(unregistered_klasses));
942 aot_log_info(aot)(" (enum) " STATS_FORMAT, STATS_PARAMS(enum_klasses));
943 aot_log_info(aot)(" (hidden) " STATS_FORMAT, STATS_PARAMS(hidden_klasses));
944 aot_log_info(aot)(" (old) " STATS_FORMAT, STATS_PARAMS(old_klasses));
945 aot_log_info(aot)(" (unlinked) = %5d, boot = %d, plat = %d, app = %d, unreg = %d",
946 num_unlinked_klasses, boot_unlinked, platform_unlinked, app_unlinked, unreg_unlinked);
947 aot_log_info(aot)(" obj array classes = %5d", num_obj_array_klasses);
948 aot_log_info(aot)(" type array classes = %5d", num_type_array_klasses);
1132 patcher.doit();
1133 }
1134 }
1135
1136 void ArchiveBuilder::print_stats() {
1137 _alloc_stats.print_stats(int(_ro_region.used()), int(_rw_region.used()));
1138 }
1139
1140 void ArchiveBuilder::write_archive(FileMapInfo* mapinfo, AOTMappedHeapInfo* mapped_heap_info, AOTStreamedHeapInfo* streamed_heap_info) {
1141 // Make sure NUM_CDS_REGIONS (exported in cds.h) agrees with
1142 // AOTMetaspace::n_regions (internal to hotspot).
1143 assert(NUM_CDS_REGIONS == AOTMetaspace::n_regions, "sanity");
1144
1145 ResourceMark rm;
1146
1147 write_region(mapinfo, AOTMetaspace::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
1148 write_region(mapinfo, AOTMetaspace::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
1149 write_region(mapinfo, AOTMetaspace::ac, &_ac_region, /*read_only=*/false,/*allow_exec=*/false);
1150
1151 // Split pointer map into read-write and read-only bitmaps
1152 ArchivePtrMarker::initialize_rw_ro_ac_maps(&_rw_ptrmap, &_ro_ptrmap, &_ac_ptrmap);
1153
1154 size_t bitmap_size_in_bytes;
1155 char* bitmap = mapinfo->write_bitmap_region(ArchivePtrMarker::rw_ptrmap(),
1156 ArchivePtrMarker::ro_ptrmap(),
1157 ArchivePtrMarker::ac_ptrmap(),
1158 mapped_heap_info,
1159 streamed_heap_info,
1160 bitmap_size_in_bytes);
1161
1162 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
1163 _total_heap_region_size = mapinfo->write_mapped_heap_region(mapped_heap_info);
1164 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
1165 _total_heap_region_size = mapinfo->write_streamed_heap_region(streamed_heap_info);
1166 }
1167
1168 print_region_stats(mapinfo, mapped_heap_info, streamed_heap_info);
1169
1170 mapinfo->set_requested_base((char*)AOTMetaspace::requested_base_address());
1171 mapinfo->set_header_crc(mapinfo->compute_header_crc());
1172 // After this point, we should not write any data into mapinfo->header() since this
1173 // would corrupt its checksum we have calculated before.
1174 mapinfo->write_header();
1175 mapinfo->close();
1176
1177 aot_log_info(aot)("Full module graph = %s", CDSConfig::is_dumping_full_module_graph() ? "enabled" : "disabled");
1178 if (log_is_enabled(Info, aot)) {
1179 print_stats();
1180 }
1181
1182 if (log_is_enabled(Info, aot, map)) {
1183 AOTMapLogger::dumptime_log(this, mapinfo, mapped_heap_info, streamed_heap_info, bitmap, bitmap_size_in_bytes);
1184 }
1185 CDS_JAVA_HEAP_ONLY(HeapShared::destroy_archived_object_cache());
1186 FREE_C_HEAP_ARRAY(char, bitmap);
1187 }
1188
1189 void ArchiveBuilder::write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region, bool read_only, bool allow_exec) {
1190 mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
1191 }
1192
1193 void ArchiveBuilder::count_relocated_pointer(bool tagged, bool nulled) {
1194 _relocated_ptr_info._num_ptrs ++;
1195 _relocated_ptr_info._num_tagged_ptrs += tagged ? 1 : 0;
1196 _relocated_ptr_info._num_nulled_ptrs += nulled ? 1 : 0;
1197 }
1198
|