src/share/vm/memory/universe.cpp

Print this page
rev 6853 : 8046070: Class Data Sharing clean up and refactoring
Summary: Cleaned up CDS to be more configurable, maintainable and extensible
Reviewed-by: dholmes, coleenp, acorn, mchung


   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 "precompiled.hpp"
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/classLoaderData.hpp"
  28 #include "classfile/javaClasses.hpp"



  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "code/dependencies.hpp"
  34 #include "gc_interface/collectedHeap.inline.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "memory/cardTableModRefBS.hpp"

  37 #include "memory/gcLocker.inline.hpp"
  38 #include "memory/genCollectedHeap.hpp"
  39 #include "memory/genRemSet.hpp"
  40 #include "memory/generation.hpp"
  41 #include "memory/metadataFactory.hpp"
  42 #include "memory/metaspaceShared.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/space.hpp"
  45 #include "memory/universe.hpp"
  46 #include "memory/universe.inline.hpp"
  47 #include "oops/constantPool.hpp"
  48 #include "oops/instanceClassLoaderKlass.hpp"
  49 #include "oops/instanceKlass.hpp"
  50 #include "oops/instanceMirrorKlass.hpp"
  51 #include "oops/instanceRefKlass.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "oops/typeArrayKlass.hpp"
  54 #include "prims/jvmtiRedefineClassesTrace.hpp"
  55 #include "runtime/arguments.hpp"
  56 #include "runtime/atomic.inline.hpp"


 222   f->do_ptr((void**)&_the_array_interfaces_array);
 223   f->do_ptr((void**)&_the_empty_int_array);
 224   f->do_ptr((void**)&_the_empty_short_array);
 225   f->do_ptr((void**)&_the_empty_method_array);
 226   f->do_ptr((void**)&_the_empty_klass_array);
 227   _finalizer_register_cache->serialize(f);
 228   _loader_addClass_cache->serialize(f);
 229   _pd_implies_cache->serialize(f);
 230 }
 231 
 232 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 233   if (size < alignment || size % alignment != 0) {
 234     vm_exit_during_initialization(
 235       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 236   }
 237 }
 238 
 239 void initialize_basic_type_klass(Klass* k, TRAPS) {
 240   Klass* ok = SystemDictionary::Object_klass();
 241   if (UseSharedSpaces) {

 242     assert(k->super() == ok, "u3");
 243     k->restore_unshareable_info(CHECK);
 244   } else {
 245     k->initialize_supers(ok, CHECK);
 246   }
 247   k->append_to_sibling_list();
 248 }
 249 
 250 void Universe::genesis(TRAPS) {
 251   ResourceMark rm;
 252 
 253   { FlagSetting fs(_bootstrapping, true);
 254 
 255     { MutexLocker mc(Compile_lock);
 256 
 257       // determine base vtable size; without that we cannot create the array klasses
 258       compute_base_vtable_size();
 259 
 260       if (!UseSharedSpaces) {
 261         _boolArrayKlassObj      = TypeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK);
 262         _charArrayKlassObj      = TypeArrayKlass::create_klass(T_CHAR,    sizeof(jchar),    CHECK);
 263         _singleArrayKlassObj    = TypeArrayKlass::create_klass(T_FLOAT,   sizeof(jfloat),   CHECK);


 649   ClassLoaderData::init_null_class_loader_data();
 650 
 651   // We have a heap so create the Method* caches before
 652   // Metaspace::initialize_shared_spaces() tries to populate them.
 653   Universe::_finalizer_register_cache = new LatestMethodCache();
 654   Universe::_loader_addClass_cache    = new LatestMethodCache();
 655   Universe::_pd_implies_cache         = new LatestMethodCache();
 656 
 657   if (UseSharedSpaces) {
 658     // Read the data structures supporting the shared spaces (shared
 659     // system dictionary, symbol table, etc.).  After that, access to
 660     // the file (other than the mapped regions) is no longer needed, and
 661     // the file is closed. Closing the file does not affect the
 662     // currently mapped regions.
 663     MetaspaceShared::initialize_shared_spaces();
 664     StringTable::create_table();
 665   } else {
 666     SymbolTable::create_table();
 667     StringTable::create_table();
 668     ClassLoader::create_package_info_table();




 669   }
 670 
 671   return JNI_OK;
 672 }
 673 
 674 // Choose the heap base address and oop encoding mode
 675 // when compressed oops are used:
 676 // Unscaled  - Use 32-bits oops without encoding when
 677 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 678 // ZeroBased - Use zero based compressed oops with encoding when
 679 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 680 // HeapBased - Use compressed oops with heap base + encoding.
 681 
 682 // 4Gb
 683 static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
 684 // 32Gb
 685 // OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
 686 
 687 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
 688   assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");


1138       SystemDictionary::ProtectionDomain_klass(), m);;
1139   }
1140 
1141   // This needs to be done before the first scavenge/gc, since
1142   // it's an input to soft ref clearing policy.
1143   {
1144     MutexLocker x(Heap_lock);
1145     Universe::update_heap_info_at_gc();
1146   }
1147 
1148   // ("weak") refs processing infrastructure initialization
1149   Universe::heap()->post_initialize();
1150 
1151   // Initialize performance counters for metaspaces
1152   MetaspaceCounters::initialize_performance_counters();
1153   CompressedClassSpaceCounters::initialize_performance_counters();
1154 
1155   MemoryService::add_metaspace_memory_pools();
1156 
1157   MemoryService::set_universe_heap(Universe::_collectedHeap);





1158   return true;
1159 }
1160 
1161 
1162 void Universe::compute_base_vtable_size() {
1163   _base_vtable_size = ClassLoader::compute_Object_vtable();
1164 }
1165 
1166 
1167 // %%% The Universe::flush_foo methods belong in CodeCache.
1168 
1169 // Flushes compiled methods dependent on dependee.
1170 void Universe::flush_dependents_on(instanceKlassHandle dependee) {
1171   assert_lock_strong(Compile_lock);
1172 
1173   if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
1174 
1175   // CodeCache can only be updated by a thread_in_VM and they will all be
1176   // stopped during the safepoint so CodeCache will be safe to update without
1177   // holding the CodeCache_lock.




   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 "precompiled.hpp"
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/classLoaderData.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #if INCLUDE_CDS
  30 #include "classfile/sharedClassUtil.hpp"
  31 #endif
  32 #include "classfile/stringTable.hpp"
  33 #include "classfile/systemDictionary.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "code/codeCache.hpp"
  36 #include "code/dependencies.hpp"
  37 #include "gc_interface/collectedHeap.inline.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "memory/cardTableModRefBS.hpp"
  40 #include "memory/filemap.hpp"
  41 #include "memory/gcLocker.inline.hpp"
  42 #include "memory/genCollectedHeap.hpp"
  43 #include "memory/genRemSet.hpp"
  44 #include "memory/generation.hpp"
  45 #include "memory/metadataFactory.hpp"
  46 #include "memory/metaspaceShared.hpp"
  47 #include "memory/oopFactory.hpp"
  48 #include "memory/space.hpp"
  49 #include "memory/universe.hpp"
  50 #include "memory/universe.inline.hpp"
  51 #include "oops/constantPool.hpp"
  52 #include "oops/instanceClassLoaderKlass.hpp"
  53 #include "oops/instanceKlass.hpp"
  54 #include "oops/instanceMirrorKlass.hpp"
  55 #include "oops/instanceRefKlass.hpp"
  56 #include "oops/oop.inline.hpp"
  57 #include "oops/typeArrayKlass.hpp"
  58 #include "prims/jvmtiRedefineClassesTrace.hpp"
  59 #include "runtime/arguments.hpp"
  60 #include "runtime/atomic.inline.hpp"


 226   f->do_ptr((void**)&_the_array_interfaces_array);
 227   f->do_ptr((void**)&_the_empty_int_array);
 228   f->do_ptr((void**)&_the_empty_short_array);
 229   f->do_ptr((void**)&_the_empty_method_array);
 230   f->do_ptr((void**)&_the_empty_klass_array);
 231   _finalizer_register_cache->serialize(f);
 232   _loader_addClass_cache->serialize(f);
 233   _pd_implies_cache->serialize(f);
 234 }
 235 
 236 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 237   if (size < alignment || size % alignment != 0) {
 238     vm_exit_during_initialization(
 239       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 240   }
 241 }
 242 
 243 void initialize_basic_type_klass(Klass* k, TRAPS) {
 244   Klass* ok = SystemDictionary::Object_klass();
 245   if (UseSharedSpaces) {
 246     ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 247     assert(k->super() == ok, "u3");
 248     k->restore_unshareable_info(loader_data, Handle(), CHECK);
 249   } else {
 250     k->initialize_supers(ok, CHECK);
 251   }
 252   k->append_to_sibling_list();
 253 }
 254 
 255 void Universe::genesis(TRAPS) {
 256   ResourceMark rm;
 257 
 258   { FlagSetting fs(_bootstrapping, true);
 259 
 260     { MutexLocker mc(Compile_lock);
 261 
 262       // determine base vtable size; without that we cannot create the array klasses
 263       compute_base_vtable_size();
 264 
 265       if (!UseSharedSpaces) {
 266         _boolArrayKlassObj      = TypeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK);
 267         _charArrayKlassObj      = TypeArrayKlass::create_klass(T_CHAR,    sizeof(jchar),    CHECK);
 268         _singleArrayKlassObj    = TypeArrayKlass::create_klass(T_FLOAT,   sizeof(jfloat),   CHECK);


 654   ClassLoaderData::init_null_class_loader_data();
 655 
 656   // We have a heap so create the Method* caches before
 657   // Metaspace::initialize_shared_spaces() tries to populate them.
 658   Universe::_finalizer_register_cache = new LatestMethodCache();
 659   Universe::_loader_addClass_cache    = new LatestMethodCache();
 660   Universe::_pd_implies_cache         = new LatestMethodCache();
 661 
 662   if (UseSharedSpaces) {
 663     // Read the data structures supporting the shared spaces (shared
 664     // system dictionary, symbol table, etc.).  After that, access to
 665     // the file (other than the mapped regions) is no longer needed, and
 666     // the file is closed. Closing the file does not affect the
 667     // currently mapped regions.
 668     MetaspaceShared::initialize_shared_spaces();
 669     StringTable::create_table();
 670   } else {
 671     SymbolTable::create_table();
 672     StringTable::create_table();
 673     ClassLoader::create_package_info_table();
 674 
 675     if (DumpSharedSpaces) {
 676       MetaspaceShared::prepare_for_dumping();
 677     }
 678   }
 679 
 680   return JNI_OK;
 681 }
 682 
 683 // Choose the heap base address and oop encoding mode
 684 // when compressed oops are used:
 685 // Unscaled  - Use 32-bits oops without encoding when
 686 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 687 // ZeroBased - Use zero based compressed oops with encoding when
 688 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 689 // HeapBased - Use compressed oops with heap base + encoding.
 690 
 691 // 4Gb
 692 static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
 693 // 32Gb
 694 // OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
 695 
 696 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
 697   assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");


1147       SystemDictionary::ProtectionDomain_klass(), m);;
1148   }
1149 
1150   // This needs to be done before the first scavenge/gc, since
1151   // it's an input to soft ref clearing policy.
1152   {
1153     MutexLocker x(Heap_lock);
1154     Universe::update_heap_info_at_gc();
1155   }
1156 
1157   // ("weak") refs processing infrastructure initialization
1158   Universe::heap()->post_initialize();
1159 
1160   // Initialize performance counters for metaspaces
1161   MetaspaceCounters::initialize_performance_counters();
1162   CompressedClassSpaceCounters::initialize_performance_counters();
1163 
1164   MemoryService::add_metaspace_memory_pools();
1165 
1166   MemoryService::set_universe_heap(Universe::_collectedHeap);
1167 #if INCLUDE_CDS
1168   if (UseSharedSpaces) {
1169     SharedClassUtil::initialize(CHECK_false);
1170   }
1171 #endif
1172   return true;
1173 }
1174 
1175 
1176 void Universe::compute_base_vtable_size() {
1177   _base_vtable_size = ClassLoader::compute_Object_vtable();
1178 }
1179 
1180 
1181 // %%% The Universe::flush_foo methods belong in CodeCache.
1182 
1183 // Flushes compiled methods dependent on dependee.
1184 void Universe::flush_dependents_on(instanceKlassHandle dependee) {
1185   assert_lock_strong(Compile_lock);
1186 
1187   if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
1188 
1189   // CodeCache can only be updated by a thread_in_VM and they will all be
1190   // stopped during the safepoint so CodeCache will be safe to update without
1191   // holding the CodeCache_lock.