src/share/vm/memory/universe.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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  *


  98 Klass* Universe::_objectArrayKlassObj               = NULL;
  99 oop Universe::_int_mirror                             = NULL;
 100 oop Universe::_float_mirror                           = NULL;
 101 oop Universe::_double_mirror                          = NULL;
 102 oop Universe::_byte_mirror                            = NULL;
 103 oop Universe::_bool_mirror                            = NULL;
 104 oop Universe::_char_mirror                            = NULL;
 105 oop Universe::_long_mirror                            = NULL;
 106 oop Universe::_short_mirror                           = NULL;
 107 oop Universe::_void_mirror                            = NULL;
 108 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 109 oop Universe::_main_thread_group                      = NULL;
 110 oop Universe::_system_thread_group                    = NULL;
 111 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 112 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 113 oop Universe::_the_null_string                        = NULL;
 114 oop Universe::_the_min_jint_string                   = NULL;
 115 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 116 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 117 LatestMethodCache* Universe::_pd_implies_cache         = NULL;

 118 oop Universe::_out_of_memory_error_java_heap          = NULL;
 119 oop Universe::_out_of_memory_error_metaspace          = NULL;
 120 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 121 oop Universe::_out_of_memory_error_array_size         = NULL;
 122 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 123 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 124 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 125 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 126 bool Universe::_verify_in_progress                    = false;
 127 oop Universe::_null_ptr_exception_instance            = NULL;
 128 oop Universe::_arithmetic_exception_instance          = NULL;
 129 oop Universe::_virtual_machine_error_instance         = NULL;
 130 oop Universe::_vm_exception                           = NULL;
 131 oop Universe::_allocation_context_notification_obj    = NULL;
 132 
 133 Method* Universe::_throw_illegal_access_error         = NULL;
 134 Array<int>* Universe::_the_empty_int_array            = NULL;
 135 Array<u2>* Universe::_the_empty_short_array           = NULL;
 136 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 137 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 138 
 139 // These variables are guarded by FullGCALot_lock.
 140 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 141 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 142 
 143 // Heap
 144 int             Universe::_verify_count = 0;
 145 
 146 int             Universe::_base_vtable_size = 0;
 147 bool            Universe::_bootstrapping = false;
 148 bool            Universe::_fully_initialized = false;
 149 
 150 size_t          Universe::_heap_capacity_at_last_gc;
 151 size_t          Universe::_heap_used_at_last_gc = 0;
 152 
 153 CollectedHeap*  Universe::_collectedHeap = NULL;


 219 
 220   {
 221     for (int i = 0; i < T_VOID+1; i++) {
 222       if (_typeArrayKlassObjs[i] != NULL) {
 223         assert(i >= T_BOOLEAN, "checking");
 224         f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 225       } else if (do_all) {
 226         f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 227       }
 228     }
 229   }
 230 
 231   f->do_ptr((void**)&_the_array_interfaces_array);
 232   f->do_ptr((void**)&_the_empty_int_array);
 233   f->do_ptr((void**)&_the_empty_short_array);
 234   f->do_ptr((void**)&_the_empty_method_array);
 235   f->do_ptr((void**)&_the_empty_klass_array);
 236   _finalizer_register_cache->serialize(f);
 237   _loader_addClass_cache->serialize(f);
 238   _pd_implies_cache->serialize(f);

 239 }
 240 
 241 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 242   if (size < alignment || size % alignment != 0) {
 243     vm_exit_during_initialization(
 244       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 245   }
 246 }
 247 
 248 void initialize_basic_type_klass(Klass* k, TRAPS) {
 249   Klass* ok = SystemDictionary::Object_klass();
 250   if (UseSharedSpaces) {
 251     ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 252     assert(k->super() == ok, "u3");
 253     k->restore_unshareable_info(loader_data, Handle(), CHECK);
 254   } else {
 255     k->initialize_supers(ok, CHECK);
 256   }
 257   k->append_to_sibling_list();
 258 }


 647             "oop size is not not a multiple of HeapWord size");
 648   TraceTime timer("Genesis", TraceStartupTime);
 649   JavaClasses::compute_hard_coded_offsets();
 650 
 651   jint status = Universe::initialize_heap();
 652   if (status != JNI_OK) {
 653     return status;
 654   }
 655 
 656   Metaspace::global_initialize();
 657 
 658   // Create memory for metadata.  Must be after initializing heap for
 659   // DumpSharedSpaces.
 660   ClassLoaderData::init_null_class_loader_data();
 661 
 662   // We have a heap so create the Method* caches before
 663   // Metaspace::initialize_shared_spaces() tries to populate them.
 664   Universe::_finalizer_register_cache = new LatestMethodCache();
 665   Universe::_loader_addClass_cache    = new LatestMethodCache();
 666   Universe::_pd_implies_cache         = new LatestMethodCache();

 667 
 668   if (UseSharedSpaces) {
 669     // Read the data structures supporting the shared spaces (shared
 670     // system dictionary, symbol table, etc.).  After that, access to
 671     // the file (other than the mapped regions) is no longer needed, and
 672     // the file is closed. Closing the file does not affect the
 673     // currently mapped regions.
 674     MetaspaceShared::initialize_shared_spaces();
 675     StringTable::create_table();
 676   } else {
 677     SymbolTable::create_table();
 678     StringTable::create_table();
 679     ClassLoader::create_package_info_table();
 680 
 681     if (DumpSharedSpaces) {
 682       MetaspaceShared::prepare_for_dumping();
 683     }
 684   }
 685 
 686   return JNI_OK;


1112   Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method(
1113                                   vmSymbols::register_method_name(),
1114                                   vmSymbols::register_method_signature());
1115   if (m == NULL || !m->is_static()) {
1116     tty->print_cr("Unable to link/verify Finalizer.register method");
1117     return false; // initialization failed (cannot throw exception yet)
1118   }
1119   Universe::_finalizer_register_cache->init(
1120     SystemDictionary::Finalizer_klass(), m);
1121 
1122   InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->link_class(CHECK_false);
1123   m = InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->find_method(
1124                                   vmSymbols::throwIllegalAccessError_name(),
1125                                   vmSymbols::void_method_signature());
1126   if (m != NULL && !m->is_static()) {
1127     // Note null is okay; this method is used in itables, and if it is null,
1128     // then AbstractMethodError is thrown instead.
1129     tty->print_cr("Unable to link/verify Unsafe.throwIllegalAccessError method");
1130     return false; // initialization failed (cannot throw exception yet)
1131   }
1132   Universe::_throw_illegal_access_error = m;

1133 
1134   // Setup method for registering loaded classes in class loader vector
1135   InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
1136   m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature());
1137   if (m == NULL || m->is_static()) {
1138     tty->print_cr("Unable to link/verify ClassLoader.addClass method");
1139     return false; // initialization failed (cannot throw exception yet)
1140   }
1141   Universe::_loader_addClass_cache->init(
1142     SystemDictionary::ClassLoader_klass(), m);
1143 
1144   // Setup method for checking protection domain
1145   InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false);
1146   m = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->
1147             find_method(vmSymbols::impliesCreateAccessControlContext_name(),
1148                         vmSymbols::void_boolean_signature());
1149   // Allow NULL which should only happen with bootstrapping.
1150   if (m != NULL) {
1151     if (m->is_static()) {
1152       // NoSuchMethodException doesn't actually work because it tries to run the
1153       // <init> function before java_lang_Class is linked. Print error and exit.
1154       tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage");
1155       return false; // initialization failed
1156     }
1157     Universe::_pd_implies_cache->init(
1158       SystemDictionary::ProtectionDomain_klass(), m);;
1159   }
1160 
1161   // This needs to be done before the first scavenge/gc, since
1162   // it's an input to soft ref clearing policy.
1163   {
1164     MutexLocker x(Heap_lock);
1165     Universe::update_heap_info_at_gc();
1166   }
1167 
1168   // ("weak") refs processing infrastructure initialization
1169   Universe::heap()->post_initialize();
1170 
1171   // Initialize performance counters for metaspaces
1172   MetaspaceCounters::initialize_performance_counters();
1173   CompressedClassSpaceCounters::initialize_performance_counters();
1174 
1175   MemoryService::add_metaspace_memory_pools();
1176 
1177   MemoryService::set_universe_heap(Universe::_collectedHeap);
1178 #if INCLUDE_CDS


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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  *


  98 Klass* Universe::_objectArrayKlassObj               = NULL;
  99 oop Universe::_int_mirror                             = NULL;
 100 oop Universe::_float_mirror                           = NULL;
 101 oop Universe::_double_mirror                          = NULL;
 102 oop Universe::_byte_mirror                            = NULL;
 103 oop Universe::_bool_mirror                            = NULL;
 104 oop Universe::_char_mirror                            = NULL;
 105 oop Universe::_long_mirror                            = NULL;
 106 oop Universe::_short_mirror                           = NULL;
 107 oop Universe::_void_mirror                            = NULL;
 108 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 109 oop Universe::_main_thread_group                      = NULL;
 110 oop Universe::_system_thread_group                    = NULL;
 111 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 112 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 113 oop Universe::_the_null_string                        = NULL;
 114 oop Universe::_the_min_jint_string                   = NULL;
 115 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 116 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 117 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 118 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 119 oop Universe::_out_of_memory_error_java_heap          = NULL;
 120 oop Universe::_out_of_memory_error_metaspace          = NULL;
 121 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 122 oop Universe::_out_of_memory_error_array_size         = NULL;
 123 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 124 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 125 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 126 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 127 bool Universe::_verify_in_progress                    = false;
 128 oop Universe::_null_ptr_exception_instance            = NULL;
 129 oop Universe::_arithmetic_exception_instance          = NULL;
 130 oop Universe::_virtual_machine_error_instance         = NULL;
 131 oop Universe::_vm_exception                           = NULL;
 132 oop Universe::_allocation_context_notification_obj    = NULL;
 133 

 134 Array<int>* Universe::_the_empty_int_array            = NULL;
 135 Array<u2>* Universe::_the_empty_short_array           = NULL;
 136 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 137 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 138 
 139 // These variables are guarded by FullGCALot_lock.
 140 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 141 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 142 
 143 // Heap
 144 int             Universe::_verify_count = 0;
 145 
 146 int             Universe::_base_vtable_size = 0;
 147 bool            Universe::_bootstrapping = false;
 148 bool            Universe::_fully_initialized = false;
 149 
 150 size_t          Universe::_heap_capacity_at_last_gc;
 151 size_t          Universe::_heap_used_at_last_gc = 0;
 152 
 153 CollectedHeap*  Universe::_collectedHeap = NULL;


 219 
 220   {
 221     for (int i = 0; i < T_VOID+1; i++) {
 222       if (_typeArrayKlassObjs[i] != NULL) {
 223         assert(i >= T_BOOLEAN, "checking");
 224         f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 225       } else if (do_all) {
 226         f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 227       }
 228     }
 229   }
 230 
 231   f->do_ptr((void**)&_the_array_interfaces_array);
 232   f->do_ptr((void**)&_the_empty_int_array);
 233   f->do_ptr((void**)&_the_empty_short_array);
 234   f->do_ptr((void**)&_the_empty_method_array);
 235   f->do_ptr((void**)&_the_empty_klass_array);
 236   _finalizer_register_cache->serialize(f);
 237   _loader_addClass_cache->serialize(f);
 238   _pd_implies_cache->serialize(f);
 239   _throw_illegal_access_error_cache->serialize(f);
 240 }
 241 
 242 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 243   if (size < alignment || size % alignment != 0) {
 244     vm_exit_during_initialization(
 245       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 246   }
 247 }
 248 
 249 void initialize_basic_type_klass(Klass* k, TRAPS) {
 250   Klass* ok = SystemDictionary::Object_klass();
 251   if (UseSharedSpaces) {
 252     ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 253     assert(k->super() == ok, "u3");
 254     k->restore_unshareable_info(loader_data, Handle(), CHECK);
 255   } else {
 256     k->initialize_supers(ok, CHECK);
 257   }
 258   k->append_to_sibling_list();
 259 }


 648             "oop size is not not a multiple of HeapWord size");
 649   TraceTime timer("Genesis", TraceStartupTime);
 650   JavaClasses::compute_hard_coded_offsets();
 651 
 652   jint status = Universe::initialize_heap();
 653   if (status != JNI_OK) {
 654     return status;
 655   }
 656 
 657   Metaspace::global_initialize();
 658 
 659   // Create memory for metadata.  Must be after initializing heap for
 660   // DumpSharedSpaces.
 661   ClassLoaderData::init_null_class_loader_data();
 662 
 663   // We have a heap so create the Method* caches before
 664   // Metaspace::initialize_shared_spaces() tries to populate them.
 665   Universe::_finalizer_register_cache = new LatestMethodCache();
 666   Universe::_loader_addClass_cache    = new LatestMethodCache();
 667   Universe::_pd_implies_cache         = new LatestMethodCache();
 668   Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
 669 
 670   if (UseSharedSpaces) {
 671     // Read the data structures supporting the shared spaces (shared
 672     // system dictionary, symbol table, etc.).  After that, access to
 673     // the file (other than the mapped regions) is no longer needed, and
 674     // the file is closed. Closing the file does not affect the
 675     // currently mapped regions.
 676     MetaspaceShared::initialize_shared_spaces();
 677     StringTable::create_table();
 678   } else {
 679     SymbolTable::create_table();
 680     StringTable::create_table();
 681     ClassLoader::create_package_info_table();
 682 
 683     if (DumpSharedSpaces) {
 684       MetaspaceShared::prepare_for_dumping();
 685     }
 686   }
 687 
 688   return JNI_OK;


1114   Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method(
1115                                   vmSymbols::register_method_name(),
1116                                   vmSymbols::register_method_signature());
1117   if (m == NULL || !m->is_static()) {
1118     tty->print_cr("Unable to link/verify Finalizer.register method");
1119     return false; // initialization failed (cannot throw exception yet)
1120   }
1121   Universe::_finalizer_register_cache->init(
1122     SystemDictionary::Finalizer_klass(), m);
1123 
1124   InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->link_class(CHECK_false);
1125   m = InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->find_method(
1126                                   vmSymbols::throwIllegalAccessError_name(),
1127                                   vmSymbols::void_method_signature());
1128   if (m != NULL && !m->is_static()) {
1129     // Note null is okay; this method is used in itables, and if it is null,
1130     // then AbstractMethodError is thrown instead.
1131     tty->print_cr("Unable to link/verify Unsafe.throwIllegalAccessError method");
1132     return false; // initialization failed (cannot throw exception yet)
1133   }
1134   Universe::_throw_illegal_access_error_cache->init(
1135     SystemDictionary::misc_Unsafe_klass(), m);
1136 
1137   // Setup method for registering loaded classes in class loader vector
1138   InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
1139   m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature());
1140   if (m == NULL || m->is_static()) {
1141     tty->print_cr("Unable to link/verify ClassLoader.addClass method");
1142     return false; // initialization failed (cannot throw exception yet)
1143   }
1144   Universe::_loader_addClass_cache->init(
1145     SystemDictionary::ClassLoader_klass(), m);
1146 
1147   // Setup method for checking protection domain
1148   InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false);
1149   m = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->
1150             find_method(vmSymbols::impliesCreateAccessControlContext_name(),
1151                         vmSymbols::void_boolean_signature());
1152   // Allow NULL which should only happen with bootstrapping.
1153   if (m != NULL) {
1154     if (m->is_static()) {
1155       // NoSuchMethodException doesn't actually work because it tries to run the
1156       // <init> function before java_lang_Class is linked. Print error and exit.
1157       tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage");
1158       return false; // initialization failed
1159     }
1160     Universe::_pd_implies_cache->init(
1161       SystemDictionary::ProtectionDomain_klass(), m);
1162   }
1163 
1164   // This needs to be done before the first scavenge/gc, since
1165   // it's an input to soft ref clearing policy.
1166   {
1167     MutexLocker x(Heap_lock);
1168     Universe::update_heap_info_at_gc();
1169   }
1170 
1171   // ("weak") refs processing infrastructure initialization
1172   Universe::heap()->post_initialize();
1173 
1174   // Initialize performance counters for metaspaces
1175   MetaspaceCounters::initialize_performance_counters();
1176   CompressedClassSpaceCounters::initialize_performance_counters();
1177 
1178   MemoryService::add_metaspace_memory_pools();
1179 
1180   MemoryService::set_universe_heap(Universe::_collectedHeap);
1181 #if INCLUDE_CDS