110 OopHandle Universe::_preallocated_out_of_memory_error_array;
111 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
112
113 // Message details for OOME objects, preallocate these objects since they could be
114 // used when throwing OOME, we should try to avoid further allocation in such case
115 OopHandle Universe::_msg_metaspace;
116 OopHandle Universe::_msg_class_metaspace;
117
118 OopHandle Universe::_null_ptr_exception_instance;
119 OopHandle Universe::_arithmetic_exception_instance;
120 OopHandle Universe::_virtual_machine_error_instance;
121
122 OopHandle Universe::_reference_pending_list;
123
124 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
125 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
126 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
127 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
128 LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL;
129 LatestMethodCache* Universe::_do_stack_walk_cache = NULL;
130
131 long Universe::verify_flags = Universe::Verify_All;
132
133 Array<int>* Universe::_the_empty_int_array = NULL;
134 Array<u2>* Universe::_the_empty_short_array = NULL;
135 Array<Klass*>* Universe::_the_empty_klass_array = NULL;
136 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL;
137 Array<Method*>* Universe::_the_empty_method_array = NULL;
138
139 // These variables are guarded by FullGCALot_lock.
140 debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
141 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
142
143 // Heap
144 int Universe::_verify_count = 0;
145
146 // Oop verification (see MacroAssembler::verify_oop)
147 uintptr_t Universe::_verify_oop_mask = 0;
148 uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1;
149
207 }
208
209 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
210 for (int i = 0; i < T_LONG+1; i++) {
211 it->push(&_typeArrayKlassObjs[i]);
212 }
213 it->push(&_objectArrayKlassObj);
214
215 it->push(&_the_empty_int_array);
216 it->push(&_the_empty_short_array);
217 it->push(&_the_empty_klass_array);
218 it->push(&_the_empty_instance_klass_array);
219 it->push(&_the_empty_method_array);
220 it->push(&_the_array_interfaces_array);
221
222 _finalizer_register_cache->metaspace_pointers_do(it);
223 _loader_addClass_cache->metaspace_pointers_do(it);
224 _throw_illegal_access_error_cache->metaspace_pointers_do(it);
225 _throw_no_such_method_error_cache->metaspace_pointers_do(it);
226 _do_stack_walk_cache->metaspace_pointers_do(it);
227 }
228
229 // Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
230 void Universe::serialize(SerializeClosure* f) {
231
232 #if INCLUDE_CDS_JAVA_HEAP
233 {
234 oop mirror_oop;
235 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
236 if (f->reading()) {
237 f->do_oop(&mirror_oop); // read from archive
238 assert(oopDesc::is_oop_or_null(mirror_oop), "is oop");
239 // Only create an OopHandle for non-null mirrors
240 if (mirror_oop != NULL) {
241 _mirrors[i] = OopHandle(vm_global(), mirror_oop);
242 }
243 } else {
244 if (HeapShared::can_write()) {
245 mirror_oop = _mirrors[i].resolve();
246 } else {
254 }
255 }
256 #endif
257
258 for (int i = 0; i < T_LONG+1; i++) {
259 f->do_ptr((void**)&_typeArrayKlassObjs[i]);
260 }
261
262 f->do_ptr((void**)&_objectArrayKlassObj);
263 f->do_ptr((void**)&_the_array_interfaces_array);
264 f->do_ptr((void**)&_the_empty_int_array);
265 f->do_ptr((void**)&_the_empty_short_array);
266 f->do_ptr((void**)&_the_empty_method_array);
267 f->do_ptr((void**)&_the_empty_klass_array);
268 f->do_ptr((void**)&_the_empty_instance_klass_array);
269 _finalizer_register_cache->serialize(f);
270 _loader_addClass_cache->serialize(f);
271 _throw_illegal_access_error_cache->serialize(f);
272 _throw_no_such_method_error_cache->serialize(f);
273 _do_stack_walk_cache->serialize(f);
274 }
275
276
277 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
278 if (size < alignment || size % alignment != 0) {
279 vm_exit_during_initialization(
280 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
281 }
282 }
283
284 void initialize_basic_type_klass(Klass* k, TRAPS) {
285 Klass* ok = vmClasses::Object_klass();
286 #if INCLUDE_CDS
287 if (UseSharedSpaces) {
288 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
289 assert(k->super() == ok, "u3");
290 if (k->is_instance_klass()) {
291 InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), NULL, CHECK);
292 } else {
293 ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK);
330 }
331
332 vmSymbols::initialize();
333
334 SystemDictionary::initialize(CHECK);
335
336 // Create string constants
337 oop s = StringTable::intern("null", CHECK);
338 _the_null_string = OopHandle(vm_global(), s);
339 s = StringTable::intern("-2147483648", CHECK);
340 _the_min_jint_string = OopHandle(vm_global(), s);
341
342
343 #if INCLUDE_CDS
344 if (UseSharedSpaces) {
345 // Verify shared interfaces array.
346 assert(_the_array_interfaces_array->at(0) ==
347 vmClasses::Cloneable_klass(), "u3");
348 assert(_the_array_interfaces_array->at(1) ==
349 vmClasses::Serializable_klass(), "u3");
350 } else
351 #endif
352 {
353 // Set up shared interfaces array. (Do this before supers are set up.)
354 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
355 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
356 }
357
358 initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
359 initialize_basic_type_klass(charArrayKlassObj(), CHECK);
360 initialize_basic_type_klass(floatArrayKlassObj(), CHECK);
361 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
362 initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
363 initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
364 initialize_basic_type_klass(intArrayKlassObj(), CHECK);
365 initialize_basic_type_klass(longArrayKlassObj(), CHECK);
366 } // end of core bootstrapping
367
368 {
369 Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK);
739 TraceTime timer("Genesis", TRACETIME_LOG(Info, startuptime));
740
741 initialize_global_behaviours();
742
743 GCLogPrecious::initialize();
744
745 #ifdef _LP64
746 MetaspaceShared::adjust_heap_sizes_for_dumping();
747 #endif // _LP64
748
749 GCConfig::arguments()->initialize_heap_sizes();
750
751 jint status = Universe::initialize_heap();
752 if (status != JNI_OK) {
753 return status;
754 }
755
756 Universe::initialize_tlab();
757
758 Metaspace::global_initialize();
759
760 // Initialize performance counters for metaspaces
761 MetaspaceCounters::initialize_performance_counters();
762
763 // Checks 'AfterMemoryInit' constraints.
764 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
765 return JNI_EINVAL;
766 }
767
768 // Create memory for metadata. Must be after initializing heap for
769 // DumpSharedSpaces.
770 ClassLoaderData::init_null_class_loader_data();
771
772 // We have a heap so create the Method* caches before
773 // Metaspace::initialize_shared_spaces() tries to populate them.
774 Universe::_finalizer_register_cache = new LatestMethodCache();
775 Universe::_loader_addClass_cache = new LatestMethodCache();
776 Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
777 Universe::_throw_no_such_method_error_cache = new LatestMethodCache();
778 Universe::_do_stack_walk_cache = new LatestMethodCache();
779
780 #if INCLUDE_CDS
781 DynamicArchive::check_for_dynamic_dump();
782 if (UseSharedSpaces) {
783 // Read the data structures supporting the shared spaces (shared
784 // system dictionary, symbol table, etc.). After that, access to
785 // the file (other than the mapped regions) is no longer needed, and
786 // the file is closed. Closing the file does not affect the
787 // currently mapped regions.
788 MetaspaceShared::initialize_shared_spaces();
789 StringTable::create_table();
790 if (HeapShared::is_loaded()) {
791 StringTable::transfer_shared_strings_to_local_table();
792 }
793 } else
794 #endif
795 {
796 SymbolTable::create_table();
797 StringTable::create_table();
798 }
925 vmClasses::internal_Unsafe_klass(),
926 "throwIllegalAccessError",
927 vmSymbols::void_method_signature(), true, CHECK);
928
929 initialize_known_method(_throw_no_such_method_error_cache,
930 vmClasses::internal_Unsafe_klass(),
931 "throwNoSuchMethodError",
932 vmSymbols::void_method_signature(), true, CHECK);
933
934 // Set up method for registering loaded classes in class loader vector
935 initialize_known_method(_loader_addClass_cache,
936 vmClasses::ClassLoader_klass(),
937 "addClass",
938 vmSymbols::class_void_signature(), false, CHECK);
939
940 // Set up method for stack walking
941 initialize_known_method(_do_stack_walk_cache,
942 vmClasses::AbstractStackWalker_klass(),
943 "doStackWalk",
944 vmSymbols::doStackWalk_signature(), false, CHECK);
945 }
946
947 void universe2_init() {
948 EXCEPTION_MARK;
949 Universe::genesis(CATCH);
950 }
951
952 // Set after initialization of the module runtime, call_initModuleRuntime
953 void universe_post_module_init() {
954 Universe::_module_initialized = true;
955 }
956
957 bool universe_post_init() {
958 assert(!is_init_completed(), "Error: initialization not yet completed!");
959 Universe::_fully_initialized = true;
960 EXCEPTION_MARK;
961 if (!UseSharedSpaces) {
962 reinitialize_vtables();
963 reinitialize_itables();
964 }
|
110 OopHandle Universe::_preallocated_out_of_memory_error_array;
111 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
112
113 // Message details for OOME objects, preallocate these objects since they could be
114 // used when throwing OOME, we should try to avoid further allocation in such case
115 OopHandle Universe::_msg_metaspace;
116 OopHandle Universe::_msg_class_metaspace;
117
118 OopHandle Universe::_null_ptr_exception_instance;
119 OopHandle Universe::_arithmetic_exception_instance;
120 OopHandle Universe::_virtual_machine_error_instance;
121
122 OopHandle Universe::_reference_pending_list;
123
124 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
125 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
126 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
127 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
128 LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL;
129 LatestMethodCache* Universe::_do_stack_walk_cache = NULL;
130 LatestMethodCache* Universe::_is_substitutable_cache = NULL;
131 LatestMethodCache* Universe::_primitive_type_hash_code_cache = NULL;
132
133 long Universe::verify_flags = Universe::Verify_All;
134
135 Array<int>* Universe::_the_empty_int_array = NULL;
136 Array<u2>* Universe::_the_empty_short_array = NULL;
137 Array<Klass*>* Universe::_the_empty_klass_array = NULL;
138 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL;
139 Array<Method*>* Universe::_the_empty_method_array = NULL;
140
141 // These variables are guarded by FullGCALot_lock.
142 debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
143 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
144
145 // Heap
146 int Universe::_verify_count = 0;
147
148 // Oop verification (see MacroAssembler::verify_oop)
149 uintptr_t Universe::_verify_oop_mask = 0;
150 uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1;
151
209 }
210
211 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
212 for (int i = 0; i < T_LONG+1; i++) {
213 it->push(&_typeArrayKlassObjs[i]);
214 }
215 it->push(&_objectArrayKlassObj);
216
217 it->push(&_the_empty_int_array);
218 it->push(&_the_empty_short_array);
219 it->push(&_the_empty_klass_array);
220 it->push(&_the_empty_instance_klass_array);
221 it->push(&_the_empty_method_array);
222 it->push(&_the_array_interfaces_array);
223
224 _finalizer_register_cache->metaspace_pointers_do(it);
225 _loader_addClass_cache->metaspace_pointers_do(it);
226 _throw_illegal_access_error_cache->metaspace_pointers_do(it);
227 _throw_no_such_method_error_cache->metaspace_pointers_do(it);
228 _do_stack_walk_cache->metaspace_pointers_do(it);
229 _is_substitutable_cache->metaspace_pointers_do(it);
230 _primitive_type_hash_code_cache->metaspace_pointers_do(it);
231 }
232
233 // Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
234 void Universe::serialize(SerializeClosure* f) {
235
236 #if INCLUDE_CDS_JAVA_HEAP
237 {
238 oop mirror_oop;
239 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
240 if (f->reading()) {
241 f->do_oop(&mirror_oop); // read from archive
242 assert(oopDesc::is_oop_or_null(mirror_oop), "is oop");
243 // Only create an OopHandle for non-null mirrors
244 if (mirror_oop != NULL) {
245 _mirrors[i] = OopHandle(vm_global(), mirror_oop);
246 }
247 } else {
248 if (HeapShared::can_write()) {
249 mirror_oop = _mirrors[i].resolve();
250 } else {
258 }
259 }
260 #endif
261
262 for (int i = 0; i < T_LONG+1; i++) {
263 f->do_ptr((void**)&_typeArrayKlassObjs[i]);
264 }
265
266 f->do_ptr((void**)&_objectArrayKlassObj);
267 f->do_ptr((void**)&_the_array_interfaces_array);
268 f->do_ptr((void**)&_the_empty_int_array);
269 f->do_ptr((void**)&_the_empty_short_array);
270 f->do_ptr((void**)&_the_empty_method_array);
271 f->do_ptr((void**)&_the_empty_klass_array);
272 f->do_ptr((void**)&_the_empty_instance_klass_array);
273 _finalizer_register_cache->serialize(f);
274 _loader_addClass_cache->serialize(f);
275 _throw_illegal_access_error_cache->serialize(f);
276 _throw_no_such_method_error_cache->serialize(f);
277 _do_stack_walk_cache->serialize(f);
278 _is_substitutable_cache->serialize(f);
279 _primitive_type_hash_code_cache->serialize(f);
280 }
281
282
283 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
284 if (size < alignment || size % alignment != 0) {
285 vm_exit_during_initialization(
286 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
287 }
288 }
289
290 void initialize_basic_type_klass(Klass* k, TRAPS) {
291 Klass* ok = vmClasses::Object_klass();
292 #if INCLUDE_CDS
293 if (UseSharedSpaces) {
294 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
295 assert(k->super() == ok, "u3");
296 if (k->is_instance_klass()) {
297 InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), NULL, CHECK);
298 } else {
299 ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK);
336 }
337
338 vmSymbols::initialize();
339
340 SystemDictionary::initialize(CHECK);
341
342 // Create string constants
343 oop s = StringTable::intern("null", CHECK);
344 _the_null_string = OopHandle(vm_global(), s);
345 s = StringTable::intern("-2147483648", CHECK);
346 _the_min_jint_string = OopHandle(vm_global(), s);
347
348
349 #if INCLUDE_CDS
350 if (UseSharedSpaces) {
351 // Verify shared interfaces array.
352 assert(_the_array_interfaces_array->at(0) ==
353 vmClasses::Cloneable_klass(), "u3");
354 assert(_the_array_interfaces_array->at(1) ==
355 vmClasses::Serializable_klass(), "u3");
356
357 } else
358 #endif
359 {
360 // Set up shared interfaces array. (Do this before supers are set up.)
361 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
362 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
363 }
364
365 initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
366 initialize_basic_type_klass(charArrayKlassObj(), CHECK);
367 initialize_basic_type_klass(floatArrayKlassObj(), CHECK);
368 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
369 initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
370 initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
371 initialize_basic_type_klass(intArrayKlassObj(), CHECK);
372 initialize_basic_type_klass(longArrayKlassObj(), CHECK);
373 } // end of core bootstrapping
374
375 {
376 Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK);
746 TraceTime timer("Genesis", TRACETIME_LOG(Info, startuptime));
747
748 initialize_global_behaviours();
749
750 GCLogPrecious::initialize();
751
752 #ifdef _LP64
753 MetaspaceShared::adjust_heap_sizes_for_dumping();
754 #endif // _LP64
755
756 GCConfig::arguments()->initialize_heap_sizes();
757
758 jint status = Universe::initialize_heap();
759 if (status != JNI_OK) {
760 return status;
761 }
762
763 Universe::initialize_tlab();
764
765 Metaspace::global_initialize();
766 // Initialize performance counters for metaspaces
767 MetaspaceCounters::initialize_performance_counters();
768
769 // Checks 'AfterMemoryInit' constraints.
770 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
771 return JNI_EINVAL;
772 }
773
774 // Create memory for metadata. Must be after initializing heap for
775 // DumpSharedSpaces.
776 ClassLoaderData::init_null_class_loader_data();
777
778 // We have a heap so create the Method* caches before
779 // Metaspace::initialize_shared_spaces() tries to populate them.
780 Universe::_finalizer_register_cache = new LatestMethodCache();
781 Universe::_loader_addClass_cache = new LatestMethodCache();
782 Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
783 Universe::_throw_no_such_method_error_cache = new LatestMethodCache();
784 Universe::_do_stack_walk_cache = new LatestMethodCache();
785 Universe::_is_substitutable_cache = new LatestMethodCache();
786 Universe::_primitive_type_hash_code_cache = new LatestMethodCache();
787
788 #if INCLUDE_CDS
789 DynamicArchive::check_for_dynamic_dump();
790 if (UseSharedSpaces) {
791 // Read the data structures supporting the shared spaces (shared
792 // system dictionary, symbol table, etc.). After that, access to
793 // the file (other than the mapped regions) is no longer needed, and
794 // the file is closed. Closing the file does not affect the
795 // currently mapped regions.
796 MetaspaceShared::initialize_shared_spaces();
797 StringTable::create_table();
798 if (HeapShared::is_loaded()) {
799 StringTable::transfer_shared_strings_to_local_table();
800 }
801 } else
802 #endif
803 {
804 SymbolTable::create_table();
805 StringTable::create_table();
806 }
933 vmClasses::internal_Unsafe_klass(),
934 "throwIllegalAccessError",
935 vmSymbols::void_method_signature(), true, CHECK);
936
937 initialize_known_method(_throw_no_such_method_error_cache,
938 vmClasses::internal_Unsafe_klass(),
939 "throwNoSuchMethodError",
940 vmSymbols::void_method_signature(), true, CHECK);
941
942 // Set up method for registering loaded classes in class loader vector
943 initialize_known_method(_loader_addClass_cache,
944 vmClasses::ClassLoader_klass(),
945 "addClass",
946 vmSymbols::class_void_signature(), false, CHECK);
947
948 // Set up method for stack walking
949 initialize_known_method(_do_stack_walk_cache,
950 vmClasses::AbstractStackWalker_klass(),
951 "doStackWalk",
952 vmSymbols::doStackWalk_signature(), false, CHECK);
953
954 // Set up substitutability testing
955 ResourceMark rm;
956 initialize_known_method(_is_substitutable_cache,
957 vmClasses::PrimitiveObjectMethods_klass(),
958 vmSymbols::isSubstitutable_name()->as_C_string(),
959 vmSymbols::object_object_boolean_signature(), true, CHECK);
960 initialize_known_method(_primitive_type_hash_code_cache,
961 vmClasses::PrimitiveObjectMethods_klass(),
962 vmSymbols::primitiveObjectHashCode_name()->as_C_string(),
963 vmSymbols::object_int_signature(), true, CHECK);
964 }
965
966 void universe2_init() {
967 EXCEPTION_MARK;
968 Universe::genesis(CATCH);
969 }
970
971 // Set after initialization of the module runtime, call_initModuleRuntime
972 void universe_post_module_init() {
973 Universe::_module_initialized = true;
974 }
975
976 bool universe_post_init() {
977 assert(!is_init_completed(), "Error: initialization not yet completed!");
978 Universe::_fully_initialized = true;
979 EXCEPTION_MARK;
980 if (!UseSharedSpaces) {
981 reinitialize_vtables();
982 reinitialize_itables();
983 }
|