src/hotspot/share/memory/metaspaceShared.cpp
changeset 51491 187c84a5efe1
parent 51477 e77d7687c831
child 51554 5b0d86499960
equal deleted inserted replaced
51490:25048be67f4a 51491:187c84a5efe1
    37 #include "interpreter/bytecodeStream.hpp"
    37 #include "interpreter/bytecodeStream.hpp"
    38 #include "interpreter/bytecodes.hpp"
    38 #include "interpreter/bytecodes.hpp"
    39 #include "logging/log.hpp"
    39 #include "logging/log.hpp"
    40 #include "logging/logMessage.hpp"
    40 #include "logging/logMessage.hpp"
    41 #include "memory/filemap.hpp"
    41 #include "memory/filemap.hpp"
    42 #include "memory/heapShared.hpp"
    42 #include "memory/heapShared.inline.hpp"
    43 #include "memory/metaspace.hpp"
    43 #include "memory/metaspace.hpp"
    44 #include "memory/metaspaceClosure.hpp"
    44 #include "memory/metaspaceClosure.hpp"
    45 #include "memory/metaspaceShared.hpp"
    45 #include "memory/metaspaceShared.hpp"
    46 #include "memory/resourceArea.hpp"
    46 #include "memory/resourceArea.hpp"
    47 #include "oops/compressedOops.inline.hpp"
    47 #include "oops/compressedOops.inline.hpp"
    59 #include "runtime/signature.hpp"
    59 #include "runtime/signature.hpp"
    60 #include "runtime/timerTrace.hpp"
    60 #include "runtime/timerTrace.hpp"
    61 #include "runtime/vmThread.hpp"
    61 #include "runtime/vmThread.hpp"
    62 #include "runtime/vm_operations.hpp"
    62 #include "runtime/vm_operations.hpp"
    63 #include "utilities/align.hpp"
    63 #include "utilities/align.hpp"
       
    64 #include "utilities/bitMap.hpp"
    64 #include "utilities/defaultStream.hpp"
    65 #include "utilities/defaultStream.hpp"
    65 #include "utilities/hashtable.inline.hpp"
    66 #include "utilities/hashtable.inline.hpp"
    66 #if INCLUDE_G1GC
    67 #if INCLUDE_G1GC
    67 #include "gc/g1/g1Allocator.inline.hpp"
    68 #include "gc/g1/g1Allocator.inline.hpp"
    68 #include "gc/g1/g1CollectedHeap.hpp"
    69 #include "gc/g1/g1CollectedHeap.hpp"
   225   // initialization fails, shared spaces [UseSharedSpaces] are
   226   // initialization fails, shared spaces [UseSharedSpaces] are
   226   // disabled and the file is closed.
   227   // disabled and the file is closed.
   227   // Map in spaces now also
   228   // Map in spaces now also
   228   if (mapinfo->initialize() && map_shared_spaces(mapinfo)) {
   229   if (mapinfo->initialize() && map_shared_spaces(mapinfo)) {
   229     size_t cds_total = core_spaces_size();
   230     size_t cds_total = core_spaces_size();
   230     cds_address = (address)mapinfo->header()->region_addr(0);
   231     cds_address = (address)mapinfo->region_addr(0);
   231 #ifdef _LP64
   232 #ifdef _LP64
   232     if (Metaspace::using_class_space()) {
   233     if (Metaspace::using_class_space()) {
   233       char* cds_end = (char*)(cds_address + cds_total);
   234       char* cds_end = (char*)(cds_address + cds_total);
   234       cds_end = (char *)align_up(cds_end, Metaspace::reserve_alignment());
   235       cds_end = (char *)align_up(cds_end, Metaspace::reserve_alignment());
   235       // If UseCompressedClassPointers is set then allocate the metaspace area
   236       // If UseCompressedClassPointers is set then allocate the metaspace area
   307   Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
   308   Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
   308   // Set the range of klass addresses to 4GB.
   309   // Set the range of klass addresses to 4GB.
   309   Universe::set_narrow_klass_range(cds_total);
   310   Universe::set_narrow_klass_range(cds_total);
   310 
   311 
   311   Metaspace::initialize_class_space(tmp_class_space);
   312   Metaspace::initialize_class_space(tmp_class_space);
   312   tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
   313   log_info(cds)("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
   313                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
   314                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
   314 
   315 
   315   tty->print_cr("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
   316   log_info(cds)("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
   316                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
   317                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
   317 #endif
   318 #endif
   318 
   319 
   319   // Start with 0 committed bytes. The memory will be committed as needed by
   320   // Start with 0 committed bytes. The memory will be committed as needed by
   320   // MetaspaceShared::commit_shared_space_to().
   321   // MetaspaceShared::commit_shared_space_to().
   422   SymbolTable::serialize(soc);
   423   SymbolTable::serialize(soc);
   423   StringTable::serialize(soc);
   424   StringTable::serialize(soc);
   424   soc->do_tag(--tag);
   425   soc->do_tag(--tag);
   425 
   426 
   426   JavaClasses::serialize_offsets(soc);
   427   JavaClasses::serialize_offsets(soc);
       
   428   InstanceMirrorKlass::serialize_offsets(soc);
   427   soc->do_tag(--tag);
   429   soc->do_tag(--tag);
   428 
   430 
   429   soc->do_tag(666);
   431   soc->do_tag(666);
   430 }
   432 }
   431 
   433 
  1015 class VM_PopulateDumpSharedSpace: public VM_Operation {
  1017 class VM_PopulateDumpSharedSpace: public VM_Operation {
  1016 private:
  1018 private:
  1017   GrowableArray<MemRegion> *_closed_archive_heap_regions;
  1019   GrowableArray<MemRegion> *_closed_archive_heap_regions;
  1018   GrowableArray<MemRegion> *_open_archive_heap_regions;
  1020   GrowableArray<MemRegion> *_open_archive_heap_regions;
  1019 
  1021 
       
  1022   GrowableArray<ArchiveHeapOopmapInfo> *_closed_archive_heap_oopmaps;
       
  1023   GrowableArray<ArchiveHeapOopmapInfo> *_open_archive_heap_oopmaps;
       
  1024 
  1020   void dump_java_heap_objects() NOT_CDS_JAVA_HEAP_RETURN;
  1025   void dump_java_heap_objects() NOT_CDS_JAVA_HEAP_RETURN;
       
  1026   void dump_archive_heap_oopmaps() NOT_CDS_JAVA_HEAP_RETURN;
       
  1027   void dump_archive_heap_oopmaps(GrowableArray<MemRegion>* regions,
       
  1028                                  GrowableArray<ArchiveHeapOopmapInfo>* oopmaps);
  1021   void dump_symbols();
  1029   void dump_symbols();
  1022   char* dump_read_only_tables();
  1030   char* dump_read_only_tables();
  1023   void print_region_stats();
  1031   void print_region_stats();
  1024   void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
  1032   void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
  1025                                const char *name, const size_t total_size);
  1033                                const char *name, const size_t total_size);
  1326   HeapShared::write_archived_subgraph_infos();
  1334   HeapShared::write_archived_subgraph_infos();
  1327 
  1335 
  1328   // Write the other data to the output array.
  1336   // Write the other data to the output array.
  1329   WriteClosure wc(&_ro_region);
  1337   WriteClosure wc(&_ro_region);
  1330   MetaspaceShared::serialize(&wc);
  1338   MetaspaceShared::serialize(&wc);
       
  1339 
       
  1340   // Write the bitmaps for patching the archive heap regions
       
  1341   dump_archive_heap_oopmaps();
  1331 
  1342 
  1332   char* newtop = _ro_region.top();
  1343   char* newtop = _ro_region.top();
  1333   ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - oldtop), true);
  1344   ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - oldtop), true);
  1334   return buckets_top;
  1345   return buckets_top;
  1335 }
  1346 }
  1469     write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
  1480     write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
  1470     write_region(mapinfo, MetaspaceShared::od, &_od_region, /*read_only=*/true, /*allow_exec=*/false);
  1481     write_region(mapinfo, MetaspaceShared::od, &_od_region, /*read_only=*/true, /*allow_exec=*/false);
  1471 
  1482 
  1472     _total_string_region_size = mapinfo->write_archive_heap_regions(
  1483     _total_string_region_size = mapinfo->write_archive_heap_regions(
  1473                                         _closed_archive_heap_regions,
  1484                                         _closed_archive_heap_regions,
       
  1485                                         _closed_archive_heap_oopmaps,
  1474                                         MetaspaceShared::first_string,
  1486                                         MetaspaceShared::first_string,
  1475                                         MetaspaceShared::max_strings);
  1487                                         MetaspaceShared::max_strings);
  1476     _total_open_archive_region_size = mapinfo->write_archive_heap_regions(
  1488     _total_open_archive_region_size = mapinfo->write_archive_heap_regions(
  1477                                         _open_archive_heap_regions,
  1489                                         _open_archive_heap_regions,
       
  1490                                         _open_archive_heap_oopmaps,
  1478                                         MetaspaceShared::first_open_archive_heap_region,
  1491                                         MetaspaceShared::first_open_archive_heap_region,
  1479                                         MetaspaceShared::max_open_archive_heap_region);
  1492                                         MetaspaceShared::max_open_archive_heap_region);
  1480   }
  1493   }
  1481 
  1494 
  1482   mapinfo->close();
  1495   mapinfo->close();
  1808   }
  1821   }
  1809 
  1822 
  1810   G1HeapVerifier::verify_archive_regions();
  1823   G1HeapVerifier::verify_archive_regions();
  1811 }
  1824 }
  1812 
  1825 
       
  1826 void VM_PopulateDumpSharedSpace::dump_archive_heap_oopmaps() {
       
  1827   if (MetaspaceShared::is_heap_object_archiving_allowed()) {
       
  1828     _closed_archive_heap_oopmaps = new GrowableArray<ArchiveHeapOopmapInfo>(2);
       
  1829     dump_archive_heap_oopmaps(_closed_archive_heap_regions, _closed_archive_heap_oopmaps);
       
  1830 
       
  1831     _open_archive_heap_oopmaps = new GrowableArray<ArchiveHeapOopmapInfo>(2);
       
  1832     dump_archive_heap_oopmaps(_open_archive_heap_regions, _open_archive_heap_oopmaps);
       
  1833   }
       
  1834 }
       
  1835 
       
  1836 void VM_PopulateDumpSharedSpace::dump_archive_heap_oopmaps(GrowableArray<MemRegion>* regions,
       
  1837                                                            GrowableArray<ArchiveHeapOopmapInfo>* oopmaps) {
       
  1838   for (int i=0; i<regions->length(); i++) {
       
  1839     ResourceBitMap oopmap = HeapShared::calculate_oopmap(regions->at(i));
       
  1840     size_t size_in_bits = oopmap.size();
       
  1841     size_t size_in_bytes = oopmap.size_in_bytes();
       
  1842     uintptr_t* buffer = (uintptr_t*)_ro_region.allocate(size_in_bytes, sizeof(intptr_t));
       
  1843     oopmap.write_to(buffer, size_in_bytes);
       
  1844     log_info(cds)("Oopmap = " INTPTR_FORMAT " (" SIZE_FORMAT_W(6) " bytes) for heap region "
       
  1845                   INTPTR_FORMAT " (" SIZE_FORMAT_W(8) " bytes)",
       
  1846                   p2i(buffer), size_in_bytes,
       
  1847                   p2i(regions->at(i).start()), regions->at(i).byte_size());
       
  1848 
       
  1849     ArchiveHeapOopmapInfo info;
       
  1850     info._oopmap = (address)buffer;
       
  1851     info._oopmap_size_in_bits = size_in_bits;
       
  1852     oopmaps->append(info);
       
  1853   }
       
  1854 }
       
  1855 
  1813 void MetaspaceShared::dump_closed_archive_heap_objects(
  1856 void MetaspaceShared::dump_closed_archive_heap_objects(
  1814                                     GrowableArray<MemRegion> * closed_archive) {
  1857                                     GrowableArray<MemRegion> * closed_archive) {
  1815   assert(is_heap_object_archiving_allowed(), "Cannot dump java heap objects");
  1858   assert(is_heap_object_archiving_allowed(), "Cannot dump java heap objects");
  1816 
  1859 
  1817   Thread* THREAD = Thread::current();
  1860   Thread* THREAD = Thread::current();
  1894     vm_exit(1);
  1937     vm_exit(1);
  1895   }
  1938   }
  1896   return archived_oop;
  1939   return archived_oop;
  1897 }
  1940 }
  1898 
  1941 
  1899 oop MetaspaceShared::materialize_archived_object(oop obj) {
  1942 oop MetaspaceShared::materialize_archived_object(narrowOop v) {
  1900   if (obj != NULL) {
  1943   if (!CompressedOops::is_null(v)) {
       
  1944     oop obj = HeapShared::decode_with_archived_oop_encoding_mode(v);
  1901     return G1CollectedHeap::heap()->materialize_archived_object(obj);
  1945     return G1CollectedHeap::heap()->materialize_archived_object(obj);
  1902   }
  1946   }
  1903   return NULL;
  1947   return NULL;
  1904 }
  1948 }
  1905 
  1949 
  1971     } else {
  2015     } else {
  1972       assert(MetaspaceShared::is_heap_object_archiving_allowed(),
  2016       assert(MetaspaceShared::is_heap_object_archiving_allowed(),
  1973              "Archived heap object is not allowed");
  2017              "Archived heap object is not allowed");
  1974       assert(MetaspaceShared::open_archive_heap_region_mapped(),
  2018       assert(MetaspaceShared::open_archive_heap_region_mapped(),
  1975              "Open archive heap region is not mapped");
  2019              "Open archive heap region is not mapped");
  1976       *p = CompressedOops::decode_not_null(o);
  2020       *p = HeapShared::decode_with_archived_oop_encoding_mode(o);
  1977     }
  2021     }
  1978   }
  2022   }
  1979 
  2023 
  1980   void do_region(u_char* start, size_t size) {
  2024   void do_region(u_char* start, size_t size) {
  1981     assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
  2025     assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
  2000   if (UseSharedSpaces && is_in_shared_region(addr, MetaspaceShared::mc)) {
  2044   if (UseSharedSpaces && is_in_shared_region(addr, MetaspaceShared::mc)) {
  2001     return true;
  2045     return true;
  2002   }
  2046   }
  2003   return false;
  2047   return false;
  2004 }
  2048 }
  2005 
       
  2006 void MetaspaceShared::print_shared_spaces() {
       
  2007   if (UseSharedSpaces) {
       
  2008     FileMapInfo::current_info()->print_shared_spaces();
       
  2009   }
       
  2010 }
       
  2011 
       
  2012 
  2049 
  2013 // Map shared spaces at requested addresses and return if succeeded.
  2050 // Map shared spaces at requested addresses and return if succeeded.
  2014 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
  2051 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
  2015   size_t image_alignment = mapinfo->alignment();
  2052   size_t image_alignment = mapinfo->alignment();
  2016 
  2053 
  2118   serialize(&rc);
  2155   serialize(&rc);
  2119 
  2156 
  2120   // Initialize the run-time symbol table.
  2157   // Initialize the run-time symbol table.
  2121   SymbolTable::create_table();
  2158   SymbolTable::create_table();
  2122 
  2159 
       
  2160   mapinfo->patch_archived_heap_embedded_pointers();
       
  2161 
  2123   // Close the mapinfo file
  2162   // Close the mapinfo file
  2124   mapinfo->close();
  2163   mapinfo->close();
  2125 
  2164 
  2126   if (PrintSharedArchiveAndExit) {
  2165   if (PrintSharedArchiveAndExit) {
  2127     if (PrintSharedDictionary) {
  2166     if (PrintSharedDictionary) {