< prev index next >

src/hotspot/share/memory/dynamicArchive.cpp

Print this page


 950 
 951     return true; // keep iterating
 952   }
 953 };
 954 
 955 void DynamicArchiveBuilder::relocate_buffer_to_target() {
 956   RelocateBufferToTarget patcher(this, (address*)_alloc_bottom, _buffer_to_target_delta);
 957   ArchivePtrMarker::ptrmap()->iterate(&patcher);
 958 
 959   Array<u8>* table = FileMapInfo::saved_shared_path_table().table();
 960   SharedPathTable runtime_table(to_target(table), FileMapInfo::shared_path_table().size());
 961   _header->set_shared_path_table(runtime_table);
 962 
 963   address relocatable_base = (address)SharedBaseAddress;
 964   address relocatable_end = (address)(current_dump_space()->top()) + _buffer_to_target_delta;
 965 
 966   intx addr_delta = MetaspaceShared::final_delta();
 967   if (addr_delta == 0) {
 968     ArchivePtrMarker::compact(relocatable_base, relocatable_end);
 969   } else {
 970     // The base archive is NOT mapped at Arguments::default_SharedBaseAddress() (due to ASLR).
 971     // This means that the current content of the dynamic archive is based on a random
 972     // address. Let's relocate all the pointers, so that it can be mapped to
 973     // Arguments::default_SharedBaseAddress() without runtime relocation.
 974     //
 975     // Note: both the base and dynamic archive are written with
 976     // FileMapHeader::_shared_base_address == Arguments::default_SharedBaseAddress()
 977 
 978     // Patch all pointers that are marked by ptrmap within this region,
 979     // where we have just dumped all the metaspace data.
 980     address patch_base = (address)_alloc_bottom;
 981     address patch_end  = (address)current_dump_space()->top();
 982 
 983     // the current value of the pointers to be patched must be within this
 984     // range (i.e., must point to either the top archive (as currently mapped), or to the
 985     // (targeted address of) the top archive)
 986     address valid_old_base = relocatable_base;
 987     address valid_old_end  = relocatable_end;
 988     size_t base_plus_top_size = valid_old_end - valid_old_base;
 989     size_t top_size = patch_end - patch_base;
 990     size_t base_size = base_plus_top_size - top_size;
 991     assert(base_plus_top_size > base_size, "no overflow");
 992     assert(base_plus_top_size > top_size, "no overflow");
 993 
 994     // after patching, the pointers must point inside this range
 995     // (the requested location of the archive, as mapped at runtime).
 996     address valid_new_base = (address)Arguments::default_SharedBaseAddress();
 997     address valid_new_end  = valid_new_base + base_plus_top_size;
 998 
 999     log_debug(cds)("Relocating archive from [" INTPTR_FORMAT " - " INTPTR_FORMAT "] to "
1000                    "[" INTPTR_FORMAT " - " INTPTR_FORMAT "], delta = " INTX_FORMAT " bytes",
1001                    p2i(patch_base + base_size), p2i(patch_end),
1002                    p2i(valid_new_base + base_size), p2i(valid_new_end), addr_delta);
1003 
1004     SharedDataRelocator<true> patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end,
1005                                       valid_new_base, valid_new_end, addr_delta, ArchivePtrMarker::ptrmap());
1006     ArchivePtrMarker::ptrmap()->iterate(&patcher);
1007     ArchivePtrMarker::compact(patcher.max_non_null_offset());
1008   }
1009 }
1010 
1011 void DynamicArchiveBuilder::write_archive(char* serialized_data) {
1012   int num_klasses = _klasses->length();
1013   int num_symbols = _symbols->length();
1014 
1015   _header->set_serialized_data(to_target(serialized_data));
1016 
1017   FileMapInfo* dynamic_info = FileMapInfo::dynamic_info();
1018   assert(dynamic_info != NULL, "Sanity");
1019 
1020   // Now write the archived data including the file offsets.
1021   const char* archive_name = Arguments::GetSharedDynamicArchivePath();
1022   dynamic_info->open_for_write(archive_name);
1023   MetaspaceShared::write_core_archive_regions(dynamic_info, NULL, NULL);
1024   dynamic_info->set_final_requested_base((char*)Arguments::default_SharedBaseAddress());
1025   dynamic_info->set_header_crc(dynamic_info->compute_header_crc());
1026   dynamic_info->write_header();
1027   dynamic_info->close();
1028 
1029   address base = to_target(_alloc_bottom);
1030   address top  = address(current_dump_space()->top()) + _buffer_to_target_delta;
1031   size_t file_size = pointer_delta(top, base, sizeof(char));
1032 
1033   base += MetaspaceShared::final_delta();
1034   top += MetaspaceShared::final_delta();
1035   log_info(cds, dynamic)("Written dynamic archive " PTR_FORMAT " - " PTR_FORMAT
1036                          " [" SIZE_FORMAT " bytes header, " SIZE_FORMAT " bytes total]",
1037                          p2i(base), p2i(top), _header->header_size(), file_size);
1038   log_info(cds, dynamic)("%d klasses; %d symbols", num_klasses, num_symbols);
1039 }
1040 
1041 
1042 class VM_PopulateDynamicDumpSharedSpace: public VM_Operation {
1043   DynamicArchiveBuilder* _builder;
1044 public:




 950 
 951     return true; // keep iterating
 952   }
 953 };
 954 
 955 void DynamicArchiveBuilder::relocate_buffer_to_target() {
 956   RelocateBufferToTarget patcher(this, (address*)_alloc_bottom, _buffer_to_target_delta);
 957   ArchivePtrMarker::ptrmap()->iterate(&patcher);
 958 
 959   Array<u8>* table = FileMapInfo::saved_shared_path_table().table();
 960   SharedPathTable runtime_table(to_target(table), FileMapInfo::shared_path_table().size());
 961   _header->set_shared_path_table(runtime_table);
 962 
 963   address relocatable_base = (address)SharedBaseAddress;
 964   address relocatable_end = (address)(current_dump_space()->top()) + _buffer_to_target_delta;
 965 
 966   intx addr_delta = MetaspaceShared::final_delta();
 967   if (addr_delta == 0) {
 968     ArchivePtrMarker::compact(relocatable_base, relocatable_end);
 969   } else {
 970     // The base archive is NOT mapped at MetaspaceShared::default_base_address() (due to ASLR).
 971     // This means that the current content of the dynamic archive is based on a random
 972     // address. Let's relocate all the pointers, so that it can be mapped to
 973     // MetaspaceShared::default_base_address() without runtime relocation.
 974     //
 975     // Note: both the base and dynamic archive are written with
 976     // FileMapHeader::_shared_base_address == MetaspaceShared::default_base_address()
 977 
 978     // Patch all pointers that are marked by ptrmap within this region,
 979     // where we have just dumped all the metaspace data.
 980     address patch_base = (address)_alloc_bottom;
 981     address patch_end  = (address)current_dump_space()->top();
 982 
 983     // the current value of the pointers to be patched must be within this
 984     // range (i.e., must point to either the top archive (as currently mapped), or to the
 985     // (targeted address of) the top archive)
 986     address valid_old_base = relocatable_base;
 987     address valid_old_end  = relocatable_end;
 988     size_t base_plus_top_size = valid_old_end - valid_old_base;
 989     size_t top_size = patch_end - patch_base;
 990     size_t base_size = base_plus_top_size - top_size;
 991     assert(base_plus_top_size > base_size, "no overflow");
 992     assert(base_plus_top_size > top_size, "no overflow");
 993 
 994     // after patching, the pointers must point inside this range
 995     // (the requested location of the archive, as mapped at runtime).
 996     address valid_new_base = (address)MetaspaceShared::default_base_address();
 997     address valid_new_end  = valid_new_base + base_plus_top_size;
 998 
 999     log_debug(cds)("Relocating archive from [" INTPTR_FORMAT " - " INTPTR_FORMAT "] to "
1000                    "[" INTPTR_FORMAT " - " INTPTR_FORMAT "], delta = " INTX_FORMAT " bytes",
1001                    p2i(patch_base + base_size), p2i(patch_end),
1002                    p2i(valid_new_base + base_size), p2i(valid_new_end), addr_delta);
1003 
1004     SharedDataRelocator<true> patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end,
1005                                       valid_new_base, valid_new_end, addr_delta, ArchivePtrMarker::ptrmap());
1006     ArchivePtrMarker::ptrmap()->iterate(&patcher);
1007     ArchivePtrMarker::compact(patcher.max_non_null_offset());
1008   }
1009 }
1010 
1011 void DynamicArchiveBuilder::write_archive(char* serialized_data) {
1012   int num_klasses = _klasses->length();
1013   int num_symbols = _symbols->length();
1014 
1015   _header->set_serialized_data(to_target(serialized_data));
1016 
1017   FileMapInfo* dynamic_info = FileMapInfo::dynamic_info();
1018   assert(dynamic_info != NULL, "Sanity");
1019 
1020   // Now write the archived data including the file offsets.
1021   const char* archive_name = Arguments::GetSharedDynamicArchivePath();
1022   dynamic_info->open_for_write(archive_name);
1023   MetaspaceShared::write_core_archive_regions(dynamic_info, NULL, NULL);
1024   dynamic_info->set_final_requested_base((char*)MetaspaceShared::default_base_address());
1025   dynamic_info->set_header_crc(dynamic_info->compute_header_crc());
1026   dynamic_info->write_header();
1027   dynamic_info->close();
1028 
1029   address base = to_target(_alloc_bottom);
1030   address top  = address(current_dump_space()->top()) + _buffer_to_target_delta;
1031   size_t file_size = pointer_delta(top, base, sizeof(char));
1032 
1033   base += MetaspaceShared::final_delta();
1034   top += MetaspaceShared::final_delta();
1035   log_info(cds, dynamic)("Written dynamic archive " PTR_FORMAT " - " PTR_FORMAT
1036                          " [" SIZE_FORMAT " bytes header, " SIZE_FORMAT " bytes total]",
1037                          p2i(base), p2i(top), _header->header_size(), file_size);
1038   log_info(cds, dynamic)("%d klasses; %d symbols", num_klasses, num_symbols);
1039 }
1040 
1041 
1042 class VM_PopulateDynamicDumpSharedSpace: public VM_Operation {
1043   DynamicArchiveBuilder* _builder;
1044 public:


< prev index next >