38 #include "classfile/classLoader.hpp"
39 #include "classfile/classLoader.inline.hpp"
40 #include "classfile/classLoaderData.inline.hpp"
41 #include "classfile/classLoaderExt.hpp"
42 #include "classfile/symbolTable.hpp"
43 #include "classfile/systemDictionaryShared.hpp"
44 #include "classfile/vmClasses.hpp"
45 #include "classfile/vmSymbols.hpp"
46 #include "jvm.h"
47 #include "logging/log.hpp"
48 #include "logging/logMessage.hpp"
49 #include "logging/logStream.hpp"
50 #include "memory/iterator.inline.hpp"
51 #include "memory/metadataFactory.hpp"
52 #include "memory/metaspaceClosure.hpp"
53 #include "memory/oopFactory.hpp"
54 #include "memory/universe.hpp"
55 #include "nmt/memTracker.hpp"
56 #include "oops/compressedOops.hpp"
57 #include "oops/compressedOops.inline.hpp"
58 #include "oops/objArrayOop.hpp"
59 #include "oops/oop.inline.hpp"
60 #include "prims/jvmtiExport.hpp"
61 #include "runtime/arguments.hpp"
62 #include "runtime/globals_extension.hpp"
63 #include "runtime/java.hpp"
64 #include "runtime/mutexLocker.hpp"
65 #include "runtime/os.hpp"
66 #include "runtime/vm_version.hpp"
67 #include "utilities/align.hpp"
68 #include "utilities/bitMap.inline.hpp"
69 #include "utilities/classpathStream.hpp"
70 #include "utilities/defaultStream.hpp"
71 #include "utilities/ostream.hpp"
72 #if INCLUDE_G1GC
73 #include "gc/g1/g1CollectedHeap.hpp"
74 #include "gc/g1/g1HeapRegion.hpp"
75 #endif
76
77 # include <sys/stat.h>
187 void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
188 size_t header_size, size_t base_archive_name_size,
189 size_t base_archive_name_offset, size_t common_app_classpath_prefix_size) {
190 // 1. We require _generic_header._magic to be at the beginning of the file
191 // 2. FileMapHeader also assumes that _generic_header is at the beginning of the file
192 assert(offset_of(FileMapHeader, _generic_header) == 0, "must be");
193 set_header_size((unsigned int)header_size);
194 set_base_archive_name_offset((unsigned int)base_archive_name_offset);
195 set_base_archive_name_size((unsigned int)base_archive_name_size);
196 set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
197 set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
198 set_version(CURRENT_CDS_ARCHIVE_VERSION);
199
200 if (!info->is_static() && base_archive_name_size != 0) {
201 // copy base archive name
202 copy_base_archive_name(CDSConfig::static_archive_path());
203 }
204 _core_region_alignment = core_region_alignment;
205 _obj_alignment = ObjectAlignmentInBytes;
206 _compact_strings = CompactStrings;
207 if (CDSConfig::is_dumping_heap()) {
208 _narrow_oop_mode = CompressedOops::mode();
209 _narrow_oop_base = CompressedOops::base();
210 _narrow_oop_shift = CompressedOops::shift();
211 }
212 _compressed_oops = UseCompressedOops;
213 _compressed_class_ptrs = UseCompressedClassPointers;
214 _use_secondary_supers_table = UseSecondarySupersTable;
215 _max_heap_size = MaxHeapSize;
216 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
217 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
218
219 // The following fields are for sanity checks for whether this archive
220 // will function correctly with this JVM and the bootclasspath it's
221 // invoked with.
222
223 // JVM version string ... changes on each build.
224 get_header_version(_jvm_ident);
225
226 _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
227 _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
228 _max_used_path_index = ClassLoaderExt::max_used_path_index();
229 _num_module_paths = ClassLoader::num_module_path_entries();
230
231 _verify_local = BytecodeVerificationLocal;
232 _verify_remote = BytecodeVerificationRemote;
233 _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
234 _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
254 st->print_cr("- magic: 0x%08x", magic());
255 st->print_cr("- crc: 0x%08x", crc());
256 st->print_cr("- version: 0x%x", version());
257 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
258 st->print_cr("- common_app_classpath_size: " UINT32_FORMAT, common_app_classpath_prefix_size());
259 st->print_cr("- base_archive_name_offset: " UINT32_FORMAT, base_archive_name_offset());
260 st->print_cr("- base_archive_name_size: " UINT32_FORMAT, base_archive_name_size());
261
262 for (int i = 0; i < NUM_CDS_REGIONS; i++) {
263 FileMapRegion* r = region_at(i);
264 r->print(st, i);
265 }
266 st->print_cr("============ end regions ======== ");
267
268 st->print_cr("- core_region_alignment: " SIZE_FORMAT, _core_region_alignment);
269 st->print_cr("- obj_alignment: %d", _obj_alignment);
270 st->print_cr("- narrow_oop_base: " INTPTR_FORMAT, p2i(_narrow_oop_base));
271 st->print_cr("- narrow_oop_base: " INTPTR_FORMAT, p2i(_narrow_oop_base));
272 st->print_cr("- narrow_oop_shift %d", _narrow_oop_shift);
273 st->print_cr("- compact_strings: %d", _compact_strings);
274 st->print_cr("- max_heap_size: " UINTX_FORMAT, _max_heap_size);
275 st->print_cr("- narrow_oop_mode: %d", _narrow_oop_mode);
276 st->print_cr("- compressed_oops: %d", _compressed_oops);
277 st->print_cr("- compressed_class_ptrs: %d", _compressed_class_ptrs);
278 st->print_cr("- use_secondary_supers_table: %d", _use_secondary_supers_table);
279 st->print_cr("- cloned_vtables_offset: " SIZE_FORMAT_X, _cloned_vtables_offset);
280 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_X, _serialized_data_offset);
281 st->print_cr("- jvm_ident: %s", _jvm_ident);
282 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_X, _shared_path_table_offset);
283 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
284 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
285 st->print_cr("- num_module_paths: %d", _num_module_paths);
286 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
287 st->print_cr("- verify_local: %d", _verify_local);
288 st->print_cr("- verify_remote: %d", _verify_remote);
289 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
290 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
291 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
292 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
293 st->print_cr("- heap_roots_offset: " SIZE_FORMAT, _heap_roots_offset);
294 st->print_cr("- _heap_oopmap_start_pos: " SIZE_FORMAT, _heap_oopmap_start_pos);
295 st->print_cr("- _heap_ptrmap_start_pos: " SIZE_FORMAT, _heap_ptrmap_start_pos);
296 st->print_cr("- _rw_ptrmap_start_pos: " SIZE_FORMAT, _rw_ptrmap_start_pos);
297 st->print_cr("- _ro_ptrmap_start_pos: " SIZE_FORMAT, _ro_ptrmap_start_pos);
298 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
2035 }
2036
2037 bool FileMapInfo::can_use_heap_region() {
2038 if (!has_heap_region()) {
2039 return false;
2040 }
2041 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
2042 ShouldNotReachHere(); // CDS should have been disabled.
2043 // The archived objects are mapped at JVM start-up, but we don't know if
2044 // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
2045 // which would make the archived String or mirror objects invalid. Let's be safe and not
2046 // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
2047 //
2048 // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
2049 // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
2050 // because we won't install an archived object subgraph if the klass of any of the
2051 // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
2052 }
2053
2054 // We pre-compute narrow Klass IDs with the runtime mapping start intended to be the base, and a shift of
2055 // ArchiveHeapWriter::precomputed_narrow_klass_shift. We enforce this encoding at runtime (see
2056 // CompressedKlassPointers::initialize_for_given_encoding()). Therefore, the following assertions must
2057 // hold:
2058 address archive_narrow_klass_base = (address)header()->mapped_base_address();
2059 const int archive_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
2060
2061 log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:",
2062 max_heap_size()/M);
2063 log_info(cds)(" narrow_klass_base at mapping start address, narrow_klass_shift = %d",
2064 archive_narrow_klass_shift);
2065 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2066 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
2067 log_info(cds)("The current max heap size = " SIZE_FORMAT "M, G1HeapRegion::GrainBytes = " SIZE_FORMAT,
2068 MaxHeapSize/M, G1HeapRegion::GrainBytes);
2069 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
2070 p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift());
2071 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2072 CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift());
2073 log_info(cds)(" heap range = [" PTR_FORMAT " - " PTR_FORMAT "]",
2074 UseCompressedOops ? p2i(CompressedOops::begin()) :
2075 UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().start()) : 0L,
2076 UseCompressedOops ? p2i(CompressedOops::end()) :
2077 UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().end()) : 0L);
2078
2079 assert(archive_narrow_klass_base == CompressedKlassPointers::base(), "Unexpected encoding base encountered "
2080 "(" PTR_FORMAT ", expected " PTR_FORMAT ")", p2i(CompressedKlassPointers::base()), p2i(archive_narrow_klass_base));
2081 assert(archive_narrow_klass_shift == CompressedKlassPointers::shift(), "Unexpected encoding shift encountered "
2082 "(%d, expected %d)", CompressedKlassPointers::shift(), archive_narrow_klass_shift);
2083
2084 return true;
2085 }
2086
2087 // The actual address of this region during dump time.
2088 address FileMapInfo::heap_region_dumptime_address() {
2089 FileMapRegion* r = region_at(MetaspaceShared::hp);
2090 assert(CDSConfig::is_using_archive(), "runtime only");
2091 assert(is_aligned(r->mapping_offset(), sizeof(HeapWord)), "must be");
2092 if (UseCompressedOops) {
2093 return /*dumptime*/ narrow_oop_base() + r->mapping_offset();
2094 } else {
2095 return heap_region_requested_address();
2096 }
2097 }
2098
2099 // The address where this region can be mapped into the runtime heap without
2100 // patching any of the pointers that are embedded in this region.
2101 address FileMapInfo::heap_region_requested_address() {
2102 assert(CDSConfig::is_using_archive(), "runtime only");
2433 }
2434
2435 if (_allow_archiving_with_java_agent) {
2436 log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2437 "for testing purposes only and should not be used in a production environment");
2438 }
2439
2440 log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2441 compressed_oops(), compressed_class_pointers());
2442 if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2443 log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2444 "different from runtime, CDS will be disabled.");
2445 return false;
2446 }
2447
2448 if (! _use_secondary_supers_table && UseSecondarySupersTable) {
2449 log_warning(cds)("The shared archive was created without UseSecondarySupersTable.");
2450 return false;
2451 }
2452
2453 if (!_use_optimized_module_handling) {
2454 CDSConfig::stop_using_optimized_module_handling();
2455 log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2456 }
2457
2458 if (is_static() && !_has_full_module_graph) {
2459 // Only the static archive can contain the full module graph.
2460 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2461 }
2462
2463 return true;
2464 }
2465
2466 bool FileMapInfo::validate_header() {
2467 if (!header()->validate()) {
2468 return false;
2469 }
2470 if (_is_static) {
2471 return true;
2472 } else {
|
38 #include "classfile/classLoader.hpp"
39 #include "classfile/classLoader.inline.hpp"
40 #include "classfile/classLoaderData.inline.hpp"
41 #include "classfile/classLoaderExt.hpp"
42 #include "classfile/symbolTable.hpp"
43 #include "classfile/systemDictionaryShared.hpp"
44 #include "classfile/vmClasses.hpp"
45 #include "classfile/vmSymbols.hpp"
46 #include "jvm.h"
47 #include "logging/log.hpp"
48 #include "logging/logMessage.hpp"
49 #include "logging/logStream.hpp"
50 #include "memory/iterator.inline.hpp"
51 #include "memory/metadataFactory.hpp"
52 #include "memory/metaspaceClosure.hpp"
53 #include "memory/oopFactory.hpp"
54 #include "memory/universe.hpp"
55 #include "nmt/memTracker.hpp"
56 #include "oops/compressedOops.hpp"
57 #include "oops/compressedOops.inline.hpp"
58 #include "oops/compressedKlass.hpp"
59 #include "oops/objArrayOop.hpp"
60 #include "oops/oop.inline.hpp"
61 #include "prims/jvmtiExport.hpp"
62 #include "runtime/arguments.hpp"
63 #include "runtime/globals_extension.hpp"
64 #include "runtime/java.hpp"
65 #include "runtime/mutexLocker.hpp"
66 #include "runtime/os.hpp"
67 #include "runtime/vm_version.hpp"
68 #include "utilities/align.hpp"
69 #include "utilities/bitMap.inline.hpp"
70 #include "utilities/classpathStream.hpp"
71 #include "utilities/defaultStream.hpp"
72 #include "utilities/ostream.hpp"
73 #if INCLUDE_G1GC
74 #include "gc/g1/g1CollectedHeap.hpp"
75 #include "gc/g1/g1HeapRegion.hpp"
76 #endif
77
78 # include <sys/stat.h>
188 void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
189 size_t header_size, size_t base_archive_name_size,
190 size_t base_archive_name_offset, size_t common_app_classpath_prefix_size) {
191 // 1. We require _generic_header._magic to be at the beginning of the file
192 // 2. FileMapHeader also assumes that _generic_header is at the beginning of the file
193 assert(offset_of(FileMapHeader, _generic_header) == 0, "must be");
194 set_header_size((unsigned int)header_size);
195 set_base_archive_name_offset((unsigned int)base_archive_name_offset);
196 set_base_archive_name_size((unsigned int)base_archive_name_size);
197 set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
198 set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
199 set_version(CURRENT_CDS_ARCHIVE_VERSION);
200
201 if (!info->is_static() && base_archive_name_size != 0) {
202 // copy base archive name
203 copy_base_archive_name(CDSConfig::static_archive_path());
204 }
205 _core_region_alignment = core_region_alignment;
206 _obj_alignment = ObjectAlignmentInBytes;
207 _compact_strings = CompactStrings;
208 _compact_headers = UseCompactObjectHeaders;
209 if (CDSConfig::is_dumping_heap()) {
210 _narrow_oop_mode = CompressedOops::mode();
211 _narrow_oop_base = CompressedOops::base();
212 _narrow_oop_shift = CompressedOops::shift();
213 }
214 _compressed_oops = UseCompressedOops;
215 _compressed_class_ptrs = UseCompressedClassPointers;
216 _use_secondary_supers_table = UseSecondarySupersTable;
217 if (UseCompressedClassPointers) {
218 #ifdef _LP64
219 _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
220 _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
221 #endif
222 } else {
223 _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
224 }
225 _max_heap_size = MaxHeapSize;
226 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
227 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
228
229 // The following fields are for sanity checks for whether this archive
230 // will function correctly with this JVM and the bootclasspath it's
231 // invoked with.
232
233 // JVM version string ... changes on each build.
234 get_header_version(_jvm_ident);
235
236 _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
237 _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
238 _max_used_path_index = ClassLoaderExt::max_used_path_index();
239 _num_module_paths = ClassLoader::num_module_path_entries();
240
241 _verify_local = BytecodeVerificationLocal;
242 _verify_remote = BytecodeVerificationRemote;
243 _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
244 _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
264 st->print_cr("- magic: 0x%08x", magic());
265 st->print_cr("- crc: 0x%08x", crc());
266 st->print_cr("- version: 0x%x", version());
267 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
268 st->print_cr("- common_app_classpath_size: " UINT32_FORMAT, common_app_classpath_prefix_size());
269 st->print_cr("- base_archive_name_offset: " UINT32_FORMAT, base_archive_name_offset());
270 st->print_cr("- base_archive_name_size: " UINT32_FORMAT, base_archive_name_size());
271
272 for (int i = 0; i < NUM_CDS_REGIONS; i++) {
273 FileMapRegion* r = region_at(i);
274 r->print(st, i);
275 }
276 st->print_cr("============ end regions ======== ");
277
278 st->print_cr("- core_region_alignment: " SIZE_FORMAT, _core_region_alignment);
279 st->print_cr("- obj_alignment: %d", _obj_alignment);
280 st->print_cr("- narrow_oop_base: " INTPTR_FORMAT, p2i(_narrow_oop_base));
281 st->print_cr("- narrow_oop_base: " INTPTR_FORMAT, p2i(_narrow_oop_base));
282 st->print_cr("- narrow_oop_shift %d", _narrow_oop_shift);
283 st->print_cr("- compact_strings: %d", _compact_strings);
284 st->print_cr("- compact_headers: %d", _compact_headers);
285 st->print_cr("- max_heap_size: " UINTX_FORMAT, _max_heap_size);
286 st->print_cr("- narrow_oop_mode: %d", _narrow_oop_mode);
287 st->print_cr("- compressed_oops: %d", _compressed_oops);
288 st->print_cr("- compressed_class_ptrs: %d", _compressed_class_ptrs);
289 st->print_cr("- use_secondary_supers_table: %d", _use_secondary_supers_table);
290 st->print_cr("- narrow_klass_pointer_bits: %d", _narrow_klass_pointer_bits);
291 st->print_cr("- narrow_klass_shift: %d", _narrow_klass_shift);
292 st->print_cr("- cloned_vtables_offset: " SIZE_FORMAT_X, _cloned_vtables_offset);
293 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_X, _serialized_data_offset);
294 st->print_cr("- jvm_ident: %s", _jvm_ident);
295 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_X, _shared_path_table_offset);
296 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
297 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
298 st->print_cr("- num_module_paths: %d", _num_module_paths);
299 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
300 st->print_cr("- verify_local: %d", _verify_local);
301 st->print_cr("- verify_remote: %d", _verify_remote);
302 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
303 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
304 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
305 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
306 st->print_cr("- heap_roots_offset: " SIZE_FORMAT, _heap_roots_offset);
307 st->print_cr("- _heap_oopmap_start_pos: " SIZE_FORMAT, _heap_oopmap_start_pos);
308 st->print_cr("- _heap_ptrmap_start_pos: " SIZE_FORMAT, _heap_ptrmap_start_pos);
309 st->print_cr("- _rw_ptrmap_start_pos: " SIZE_FORMAT, _rw_ptrmap_start_pos);
310 st->print_cr("- _ro_ptrmap_start_pos: " SIZE_FORMAT, _ro_ptrmap_start_pos);
311 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
2048 }
2049
2050 bool FileMapInfo::can_use_heap_region() {
2051 if (!has_heap_region()) {
2052 return false;
2053 }
2054 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
2055 ShouldNotReachHere(); // CDS should have been disabled.
2056 // The archived objects are mapped at JVM start-up, but we don't know if
2057 // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
2058 // which would make the archived String or mirror objects invalid. Let's be safe and not
2059 // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
2060 //
2061 // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
2062 // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
2063 // because we won't install an archived object subgraph if the klass of any of the
2064 // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
2065 }
2066
2067 // We pre-compute narrow Klass IDs with the runtime mapping start intended to be the base, and a shift of
2068 // ArchiveBuilder::precomputed_narrow_klass_shift. We enforce this encoding at runtime (see
2069 // CompressedKlassPointers::initialize_for_given_encoding()). Therefore, the following assertions must
2070 // hold:
2071 address archive_narrow_klass_base = (address)header()->mapped_base_address();
2072 const int archive_narrow_klass_pointer_bits = header()->narrow_klass_pointer_bits();
2073 const int archive_narrow_klass_shift = header()->narrow_klass_shift();
2074
2075 log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:",
2076 max_heap_size()/M);
2077 log_info(cds)(" narrow_klass_base at mapping start address, narrow_klass_pointer_bits = %d, narrow_klass_shift = %d",
2078 archive_narrow_klass_pointer_bits, archive_narrow_klass_shift);
2079 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2080 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
2081 log_info(cds)("The current max heap size = " SIZE_FORMAT "M, G1HeapRegion::GrainBytes = " SIZE_FORMAT,
2082 MaxHeapSize/M, G1HeapRegion::GrainBytes);
2083 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", arrow_klass_pointer_bits = %d, narrow_klass_shift = %d",
2084 p2i(CompressedKlassPointers::base()), CompressedKlassPointers::narrow_klass_pointer_bits(), CompressedKlassPointers::shift());
2085 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2086 CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift());
2087 log_info(cds)(" heap range = [" PTR_FORMAT " - " PTR_FORMAT "]",
2088 UseCompressedOops ? p2i(CompressedOops::begin()) :
2089 UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().start()) : 0L,
2090 UseCompressedOops ? p2i(CompressedOops::end()) :
2091 UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().end()) : 0L);
2092
2093 int err = 0;
2094 if ( archive_narrow_klass_base != CompressedKlassPointers::base() ||
2095 (err = 1, archive_narrow_klass_pointer_bits != CompressedKlassPointers::narrow_klass_pointer_bits()) ||
2096 (err = 2, archive_narrow_klass_shift != CompressedKlassPointers::shift()) ) {
2097 stringStream ss;
2098 switch (err) {
2099 case 0:
2100 ss.print("Unexpected encoding base encountered (" PTR_FORMAT ", expected " PTR_FORMAT ")",
2101 p2i(CompressedKlassPointers::base()), p2i(archive_narrow_klass_base));
2102 break;
2103 case 1:
2104 ss.print("Unexpected narrow Klass bit length encountered (%d, expected %d)",
2105 CompressedKlassPointers::narrow_klass_pointer_bits(), archive_narrow_klass_pointer_bits);
2106 break;
2107 case 2:
2108 ss.print("Unexpected narrow Klass shift encountered (%d, expected %d)",
2109 CompressedKlassPointers::shift(), archive_narrow_klass_shift);
2110 break;
2111 default:
2112 ShouldNotReachHere();
2113 };
2114 LogTarget(Info, cds) lt;
2115 if (lt.is_enabled()) {
2116 LogStream ls(lt);
2117 ls.print_raw(ss.base());
2118 header()->print(&ls);
2119 }
2120 assert(false, "%s", ss.base());
2121 }
2122
2123 return true;
2124 }
2125
2126 // The actual address of this region during dump time.
2127 address FileMapInfo::heap_region_dumptime_address() {
2128 FileMapRegion* r = region_at(MetaspaceShared::hp);
2129 assert(CDSConfig::is_using_archive(), "runtime only");
2130 assert(is_aligned(r->mapping_offset(), sizeof(HeapWord)), "must be");
2131 if (UseCompressedOops) {
2132 return /*dumptime*/ narrow_oop_base() + r->mapping_offset();
2133 } else {
2134 return heap_region_requested_address();
2135 }
2136 }
2137
2138 // The address where this region can be mapped into the runtime heap without
2139 // patching any of the pointers that are embedded in this region.
2140 address FileMapInfo::heap_region_requested_address() {
2141 assert(CDSConfig::is_using_archive(), "runtime only");
2472 }
2473
2474 if (_allow_archiving_with_java_agent) {
2475 log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2476 "for testing purposes only and should not be used in a production environment");
2477 }
2478
2479 log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2480 compressed_oops(), compressed_class_pointers());
2481 if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2482 log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2483 "different from runtime, CDS will be disabled.");
2484 return false;
2485 }
2486
2487 if (! _use_secondary_supers_table && UseSecondarySupersTable) {
2488 log_warning(cds)("The shared archive was created without UseSecondarySupersTable.");
2489 return false;
2490 }
2491
2492 if (compact_headers() != UseCompactObjectHeaders) {
2493 log_info(cds)("The shared archive file's UseCompactObjectHeaders setting (%s)"
2494 " does not equal the current UseCompactObjectHeaders setting (%s).",
2495 _compact_headers ? "enabled" : "disabled",
2496 UseCompactObjectHeaders ? "enabled" : "disabled");
2497 return false;
2498 }
2499
2500 if (!_use_optimized_module_handling) {
2501 CDSConfig::stop_using_optimized_module_handling();
2502 log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2503 }
2504
2505 if (is_static() && !_has_full_module_graph) {
2506 // Only the static archive can contain the full module graph.
2507 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2508 }
2509
2510 return true;
2511 }
2512
2513 bool FileMapInfo::validate_header() {
2514 if (!header()->validate()) {
2515 return false;
2516 }
2517 if (_is_static) {
2518 return true;
2519 } else {
|