< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page


  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classListParser.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/dictionary.hpp"
  30 #include "classfile/loaderConstraints.hpp"
  31 #include "classfile/placeholders.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/stringTable.hpp"
  34 #include "classfile/systemDictionary.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "code/codeCache.hpp"
  37 #include "interpreter/bytecodeStream.hpp"
  38 #include "interpreter/bytecodes.hpp"
  39 #include "logging/log.hpp"
  40 #include "logging/logMessage.hpp"
  41 #include "memory/filemap.hpp"
  42 #include "memory/heapShared.hpp"
  43 #include "memory/metaspace.hpp"
  44 #include "memory/metaspaceClosure.hpp"
  45 #include "memory/metaspaceShared.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/compressedOops.inline.hpp"
  48 #include "oops/instanceClassLoaderKlass.hpp"
  49 #include "oops/instanceMirrorKlass.hpp"
  50 #include "oops/instanceRefKlass.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/typeArrayKlass.hpp"
  55 #include "prims/jvmtiRedefineClasses.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/os.hpp"
  58 #include "runtime/safepointVerifiers.hpp"
  59 #include "runtime/signature.hpp"
  60 #include "runtime/timerTrace.hpp"
  61 #include "runtime/vmThread.hpp"
  62 #include "runtime/vm_operations.hpp"


 292   //   ArchiveCompactor will copy the class metadata into this space, first the RW parts,
 293   //   then the RO parts.
 294 
 295   assert(UseCompressedOops && UseCompressedClassPointers,
 296       "UseCompressedOops and UseCompressedClassPointers must be set");
 297 
 298   size_t max_archive_size = align_down(cds_total * 3 / 4, reserve_alignment);
 299   ReservedSpace tmp_class_space = _shared_rs.last_part(max_archive_size);
 300   CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment);
 301   _shared_rs = _shared_rs.first_part(max_archive_size);
 302 
 303   // Set up compress class pointers.
 304   Universe::set_narrow_klass_base((address)_shared_rs.base());
 305   // Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent
 306   // with AOT.
 307   Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
 308   // Set the range of klass addresses to 4GB.
 309   Universe::set_narrow_klass_range(cds_total);
 310 
 311   Metaspace::initialize_class_space(tmp_class_space);
 312   tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
 313                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
 314 
 315   tty->print_cr("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 316                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
 317 #endif
 318 
 319   // Start with 0 committed bytes. The memory will be committed as needed by
 320   // MetaspaceShared::commit_shared_space_to().
 321   if (!_shared_vs.initialize(_shared_rs, 0)) {
 322     vm_exit_during_initialization("Unable to allocate memory for shared space");
 323   }
 324 
 325   _mc_region.init(&_shared_rs);
 326   tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 327                 _shared_rs.size(), p2i(_shared_rs.base()));
 328 }
 329 
 330 // Called by universe_post_init()
 331 void MetaspaceShared::post_initialize(TRAPS) {
 332   if (UseSharedSpaces) {
 333     int size = FileMapInfo::get_number_of_shared_paths();
 334     if (size > 0) {
 335       SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);


 445   java_lang_invoke_ResolvedMethodName::serialize(soc);
 446   java_lang_invoke_LambdaForm::serialize(soc);
 447   java_lang_invoke_MethodType::serialize(soc);
 448   java_lang_invoke_CallSite::serialize(soc);
 449   java_lang_invoke_MethodHandleNatives_CallSiteContext::serialize(soc);
 450   java_security_AccessControlContext::serialize(soc);
 451   java_lang_reflect_AccessibleObject::serialize(soc);
 452   java_lang_reflect_Method::serialize(soc);
 453   java_lang_reflect_Constructor::serialize(soc);
 454   java_lang_reflect_Field::serialize(soc);
 455   java_nio_Buffer::serialize(soc);
 456   reflect_ConstantPool::serialize(soc);
 457   reflect_UnsafeStaticFieldAccessorImpl::serialize(soc);
 458   java_lang_reflect_Parameter::serialize(soc);
 459   java_lang_Module::serialize(soc);
 460   java_lang_StackTraceElement::serialize(soc);
 461   java_lang_StackFrameInfo::serialize(soc);
 462   java_lang_LiveStackFrameInfo::serialize(soc);
 463   java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize(soc);
 464   jdk_internal_module_ArchivedModuleGraph::serialize(soc);

 465 }
 466 
 467 address MetaspaceShared::cds_i2i_entry_code_buffers(size_t total_size) {
 468   if (DumpSharedSpaces) {
 469     if (_cds_i2i_entry_code_buffers == NULL) {
 470       _cds_i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
 471       _cds_i2i_entry_code_buffers_size = total_size;
 472     }
 473   } else if (UseSharedSpaces) {
 474     assert(_cds_i2i_entry_code_buffers != NULL, "must already been initialized");
 475   } else {
 476     return NULL;
 477   }
 478 
 479   assert(_cds_i2i_entry_code_buffers_size == total_size, "must not change");
 480   return _cds_i2i_entry_code_buffers;
 481 }
 482 
 483 // CDS code for dumping shared archive.
 484 


1907   }
1908 
1909   int len = obj->size();
1910   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
1911     return NULL;
1912   }
1913 
1914   int hash = obj->identity_hash();
1915   oop archived_oop = (oop)G1CollectedHeap::heap()->archive_mem_allocate(len);
1916   if (archived_oop != NULL) {
1917     Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)archived_oop, len);
1918     relocate_klass_ptr(archived_oop);
1919     ArchivedObjectCache* cache = MetaspaceShared::archive_object_cache();
1920     cache->put(obj, archived_oop);
1921   }
1922   log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT,
1923                        p2i(obj), p2i(archived_oop));
1924   return archived_oop;
1925 }
1926 
1927 oop MetaspaceShared::materialize_archived_object(oop obj) {
1928   if (obj != NULL) {

1929     return G1CollectedHeap::heap()->materialize_archived_object(obj);
1930   }
1931   return NULL;
1932 }
1933 
1934 void MetaspaceShared::archive_klass_objects(Thread* THREAD) {
1935   int i;
1936   for (i = 0; i < _global_klass_objects->length(); i++) {
1937     Klass* k = _global_klass_objects->at(i);
1938 
1939     // archive mirror object
1940     java_lang_Class::archive_mirror(k, CHECK);
1941 
1942     // archive the resolved_referenes array
1943     if (k->is_instance_klass()) {
1944       InstanceKlass* ik = InstanceKlass::cast(k);
1945       ik->constants()->archive_resolved_references(THREAD);
1946     }
1947   }
1948 }


1984     *p = (u4)(uintx(obj));
1985   }
1986 
1987   void do_tag(int tag) {
1988     int old_tag;
1989     old_tag = (int)(intptr_t)nextPtr();
1990     // do_int(&old_tag);
1991     assert(tag == old_tag, "old tag doesn't match");
1992     FileMapInfo::assert_mark(tag == old_tag);
1993   }
1994 
1995   void do_oop(oop *p) {
1996     narrowOop o = (narrowOop)nextPtr();
1997     if (o == 0 || !MetaspaceShared::open_archive_heap_region_mapped()) {
1998       p = NULL;
1999     } else {
2000       assert(MetaspaceShared::is_heap_object_archiving_allowed(),
2001              "Archived heap object is not allowed");
2002       assert(MetaspaceShared::open_archive_heap_region_mapped(),
2003              "Open archive heap region is not mapped");
2004       *p = CompressedOops::decode_not_null(o);
2005     }
2006   }
2007 
2008   void do_region(u_char* start, size_t size) {
2009     assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
2010     assert(size % sizeof(intptr_t) == 0, "bad size");
2011     do_tag((int)size);
2012     while (size > 0) {
2013       *(intptr_t*)start = nextPtr();
2014       start += sizeof(intptr_t);
2015       size -= sizeof(intptr_t);
2016     }
2017   }
2018 
2019   bool reading() const { return true; }
2020 };
2021 
2022 // Return true if given address is in the misc data region
2023 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) {
2024   return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx);


2130   buffer += sharedDictionaryLen;
2131 
2132   // The following data are the linked list elements
2133   // (HashtableEntry objects) for the shared dictionary table.
2134 
2135   int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
2136   buffer += sizeof(intptr_t);
2137   buffer += len;
2138 
2139   // The table of archived java heap object sub-graph infos
2140   buffer = HeapShared::read_archived_subgraph_infos(buffer);
2141 
2142   // Verify various attributes of the archive, plus initialize the
2143   // shared string/symbol tables
2144   intptr_t* array = (intptr_t*)buffer;
2145   ReadClosure rc(&array);
2146   serialize(&rc);
2147 
2148   // Initialize the run-time symbol table.
2149   SymbolTable::create_table();


2150 
2151   // Close the mapinfo file
2152   mapinfo->close();
2153 
2154   if (PrintSharedArchiveAndExit) {
2155     if (PrintSharedDictionary) {
2156       tty->print_cr("\nShared classes:\n");
2157       SystemDictionary::print_shared(tty);
2158     }
2159     if (_archive_loading_failed) {
2160       tty->print_cr("archive is invalid");
2161       vm_exit(1);
2162     } else {
2163       tty->print_cr("archive is valid");
2164       vm_exit(0);
2165     }
2166   }
2167 }
2168 
2169 // JVM/TI RedefineClasses() support:




  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classListParser.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/dictionary.hpp"
  30 #include "classfile/loaderConstraints.hpp"
  31 #include "classfile/placeholders.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/stringTable.hpp"
  34 #include "classfile/systemDictionary.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "code/codeCache.hpp"
  37 #include "interpreter/bytecodeStream.hpp"
  38 #include "interpreter/bytecodes.hpp"
  39 #include "logging/log.hpp"
  40 #include "logging/logMessage.hpp"
  41 #include "memory/filemap.hpp"
  42 #include "memory/heapShared.inline.hpp"
  43 #include "memory/metaspace.hpp"
  44 #include "memory/metaspaceClosure.hpp"
  45 #include "memory/metaspaceShared.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/compressedOops.inline.hpp"
  48 #include "oops/instanceClassLoaderKlass.hpp"
  49 #include "oops/instanceMirrorKlass.hpp"
  50 #include "oops/instanceRefKlass.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/typeArrayKlass.hpp"
  55 #include "prims/jvmtiRedefineClasses.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/os.hpp"
  58 #include "runtime/safepointVerifiers.hpp"
  59 #include "runtime/signature.hpp"
  60 #include "runtime/timerTrace.hpp"
  61 #include "runtime/vmThread.hpp"
  62 #include "runtime/vm_operations.hpp"


 292   //   ArchiveCompactor will copy the class metadata into this space, first the RW parts,
 293   //   then the RO parts.
 294 
 295   assert(UseCompressedOops && UseCompressedClassPointers,
 296       "UseCompressedOops and UseCompressedClassPointers must be set");
 297 
 298   size_t max_archive_size = align_down(cds_total * 3 / 4, reserve_alignment);
 299   ReservedSpace tmp_class_space = _shared_rs.last_part(max_archive_size);
 300   CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment);
 301   _shared_rs = _shared_rs.first_part(max_archive_size);
 302 
 303   // Set up compress class pointers.
 304   Universe::set_narrow_klass_base((address)_shared_rs.base());
 305   // Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent
 306   // with AOT.
 307   Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
 308   // Set the range of klass addresses to 4GB.
 309   Universe::set_narrow_klass_range(cds_total);
 310 
 311   Metaspace::initialize_class_space(tmp_class_space);
 312   log_info(cds)("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
 313                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
 314 
 315   log_info(cds)("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 316                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
 317 #endif
 318 
 319   // Start with 0 committed bytes. The memory will be committed as needed by
 320   // MetaspaceShared::commit_shared_space_to().
 321   if (!_shared_vs.initialize(_shared_rs, 0)) {
 322     vm_exit_during_initialization("Unable to allocate memory for shared space");
 323   }
 324 
 325   _mc_region.init(&_shared_rs);
 326   tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 327                 _shared_rs.size(), p2i(_shared_rs.base()));
 328 }
 329 
 330 // Called by universe_post_init()
 331 void MetaspaceShared::post_initialize(TRAPS) {
 332   if (UseSharedSpaces) {
 333     int size = FileMapInfo::get_number_of_shared_paths();
 334     if (size > 0) {
 335       SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);


 445   java_lang_invoke_ResolvedMethodName::serialize(soc);
 446   java_lang_invoke_LambdaForm::serialize(soc);
 447   java_lang_invoke_MethodType::serialize(soc);
 448   java_lang_invoke_CallSite::serialize(soc);
 449   java_lang_invoke_MethodHandleNatives_CallSiteContext::serialize(soc);
 450   java_security_AccessControlContext::serialize(soc);
 451   java_lang_reflect_AccessibleObject::serialize(soc);
 452   java_lang_reflect_Method::serialize(soc);
 453   java_lang_reflect_Constructor::serialize(soc);
 454   java_lang_reflect_Field::serialize(soc);
 455   java_nio_Buffer::serialize(soc);
 456   reflect_ConstantPool::serialize(soc);
 457   reflect_UnsafeStaticFieldAccessorImpl::serialize(soc);
 458   java_lang_reflect_Parameter::serialize(soc);
 459   java_lang_Module::serialize(soc);
 460   java_lang_StackTraceElement::serialize(soc);
 461   java_lang_StackFrameInfo::serialize(soc);
 462   java_lang_LiveStackFrameInfo::serialize(soc);
 463   java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize(soc);
 464   jdk_internal_module_ArchivedModuleGraph::serialize(soc);
 465   InstanceMirrorKlass::serialize(soc);
 466 }
 467 
 468 address MetaspaceShared::cds_i2i_entry_code_buffers(size_t total_size) {
 469   if (DumpSharedSpaces) {
 470     if (_cds_i2i_entry_code_buffers == NULL) {
 471       _cds_i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
 472       _cds_i2i_entry_code_buffers_size = total_size;
 473     }
 474   } else if (UseSharedSpaces) {
 475     assert(_cds_i2i_entry_code_buffers != NULL, "must already been initialized");
 476   } else {
 477     return NULL;
 478   }
 479 
 480   assert(_cds_i2i_entry_code_buffers_size == total_size, "must not change");
 481   return _cds_i2i_entry_code_buffers;
 482 }
 483 
 484 // CDS code for dumping shared archive.
 485 


1908   }
1909 
1910   int len = obj->size();
1911   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
1912     return NULL;
1913   }
1914 
1915   int hash = obj->identity_hash();
1916   oop archived_oop = (oop)G1CollectedHeap::heap()->archive_mem_allocate(len);
1917   if (archived_oop != NULL) {
1918     Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)archived_oop, len);
1919     relocate_klass_ptr(archived_oop);
1920     ArchivedObjectCache* cache = MetaspaceShared::archive_object_cache();
1921     cache->put(obj, archived_oop);
1922   }
1923   log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT,
1924                        p2i(obj), p2i(archived_oop));
1925   return archived_oop;
1926 }
1927 
1928 oop MetaspaceShared::materialize_archived_object(narrowOop v) {
1929   if (!CompressedOops::is_null(v)) {
1930     oop obj = HeapShared::decode_not_null(v);
1931     return G1CollectedHeap::heap()->materialize_archived_object(obj);
1932   }
1933   return NULL;
1934 }
1935 
1936 void MetaspaceShared::archive_klass_objects(Thread* THREAD) {
1937   int i;
1938   for (i = 0; i < _global_klass_objects->length(); i++) {
1939     Klass* k = _global_klass_objects->at(i);
1940 
1941     // archive mirror object
1942     java_lang_Class::archive_mirror(k, CHECK);
1943 
1944     // archive the resolved_referenes array
1945     if (k->is_instance_klass()) {
1946       InstanceKlass* ik = InstanceKlass::cast(k);
1947       ik->constants()->archive_resolved_references(THREAD);
1948     }
1949   }
1950 }


1986     *p = (u4)(uintx(obj));
1987   }
1988 
1989   void do_tag(int tag) {
1990     int old_tag;
1991     old_tag = (int)(intptr_t)nextPtr();
1992     // do_int(&old_tag);
1993     assert(tag == old_tag, "old tag doesn't match");
1994     FileMapInfo::assert_mark(tag == old_tag);
1995   }
1996 
1997   void do_oop(oop *p) {
1998     narrowOop o = (narrowOop)nextPtr();
1999     if (o == 0 || !MetaspaceShared::open_archive_heap_region_mapped()) {
2000       p = NULL;
2001     } else {
2002       assert(MetaspaceShared::is_heap_object_archiving_allowed(),
2003              "Archived heap object is not allowed");
2004       assert(MetaspaceShared::open_archive_heap_region_mapped(),
2005              "Open archive heap region is not mapped");
2006       *p = HeapShared::decode_not_null(o);
2007     }
2008   }
2009 
2010   void do_region(u_char* start, size_t size) {
2011     assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
2012     assert(size % sizeof(intptr_t) == 0, "bad size");
2013     do_tag((int)size);
2014     while (size > 0) {
2015       *(intptr_t*)start = nextPtr();
2016       start += sizeof(intptr_t);
2017       size -= sizeof(intptr_t);
2018     }
2019   }
2020 
2021   bool reading() const { return true; }
2022 };
2023 
2024 // Return true if given address is in the misc data region
2025 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) {
2026   return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx);


2132   buffer += sharedDictionaryLen;
2133 
2134   // The following data are the linked list elements
2135   // (HashtableEntry objects) for the shared dictionary table.
2136 
2137   int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
2138   buffer += sizeof(intptr_t);
2139   buffer += len;
2140 
2141   // The table of archived java heap object sub-graph infos
2142   buffer = HeapShared::read_archived_subgraph_infos(buffer);
2143 
2144   // Verify various attributes of the archive, plus initialize the
2145   // shared string/symbol tables
2146   intptr_t* array = (intptr_t*)buffer;
2147   ReadClosure rc(&array);
2148   serialize(&rc);
2149 
2150   // Initialize the run-time symbol table.
2151   SymbolTable::create_table();
2152 
2153   mapinfo->relocate_archived_heap_embedded_pointers();
2154 
2155   // Close the mapinfo file
2156   mapinfo->close();
2157 
2158   if (PrintSharedArchiveAndExit) {
2159     if (PrintSharedDictionary) {
2160       tty->print_cr("\nShared classes:\n");
2161       SystemDictionary::print_shared(tty);
2162     }
2163     if (_archive_loading_failed) {
2164       tty->print_cr("archive is invalid");
2165       vm_exit(1);
2166     } else {
2167       tty->print_cr("archive is valid");
2168       vm_exit(0);
2169     }
2170   }
2171 }
2172 
2173 // JVM/TI RedefineClasses() support:


< prev index next >