1 /* 2 * Copyright (c) 1997, 2020, 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 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "aot/aotLoader.hpp" 27 #include "classfile/classLoader.hpp" 28 #include "classfile/classLoaderDataGraph.hpp" 29 #include "classfile/javaClasses.hpp" 30 #include "classfile/stringTable.hpp" 31 #include "classfile/symbolTable.hpp" 32 #include "classfile/systemDictionary.hpp" 33 #include "classfile/vmSymbols.hpp" 34 #include "code/codeBehaviours.hpp" 35 #include "code/codeCache.hpp" 36 #include "code/dependencies.hpp" 37 #include "gc/shared/collectedHeap.inline.hpp" 38 #include "gc/shared/gcArguments.hpp" 39 #include "gc/shared/gcConfig.hpp" 40 #include "gc/shared/gcTraceTime.inline.hpp" 41 #include "interpreter/interpreter.hpp" 42 #include "logging/log.hpp" 43 #include "logging/logStream.hpp" 44 #include "memory/heapShared.hpp" 45 #include "memory/filemap.hpp" 46 #include "memory/metadataFactory.hpp" 47 #include "memory/metaspaceClosure.hpp" 48 #include "memory/metaspaceCounters.hpp" 49 #include "memory/metaspaceShared.hpp" 50 #include "memory/oopFactory.hpp" 51 #include "memory/resourceArea.hpp" 52 #include "memory/universe.hpp" 53 #include "oops/compressedOops.hpp" 54 #include "oops/constantPool.hpp" 55 #include "oops/instanceClassLoaderKlass.hpp" 56 #include "oops/instanceKlass.hpp" 57 #include "oops/instanceMirrorKlass.hpp" 58 #include "oops/instanceRefKlass.hpp" 59 #include "oops/objArrayOop.inline.hpp" 60 #include "oops/oop.inline.hpp" 61 #include "oops/typeArrayKlass.hpp" 62 #include "prims/resolvedMethodTable.hpp" 63 #include "runtime/arguments.hpp" 64 #include "runtime/atomic.hpp" 65 #include "runtime/deoptimization.hpp" 66 #include "runtime/flags/flagSetting.hpp" 67 #include "runtime/flags/jvmFlagConstraintList.hpp" 68 #include "runtime/handles.inline.hpp" 69 #include "runtime/init.hpp" 70 #include "runtime/java.hpp" 71 #include "runtime/javaCalls.hpp" 72 #include "runtime/sharedRuntime.hpp" 73 #include "runtime/synchronizer.hpp" 74 #include "runtime/thread.inline.hpp" 75 #include "runtime/timerTrace.hpp" 76 #include "runtime/vmOperations.hpp" 77 #include "services/memoryService.hpp" 78 #include "utilities/align.hpp" 79 #include "utilities/copy.hpp" 80 #include "utilities/debug.hpp" 81 #include "utilities/events.hpp" 82 #include "utilities/formatBuffer.hpp" 83 #include "utilities/hashtable.inline.hpp" 84 #include "utilities/macros.hpp" 85 #include "utilities/ostream.hpp" 86 #include "utilities/preserveException.hpp" 87 88 #define PRIMITIVE_MIRRORS_DO(func) \ 89 func(_int_mirror) \ 90 func(_float_mirror) \ 91 func(_double_mirror) \ 92 func(_byte_mirror) \ 93 func(_bool_mirror) \ 94 func(_char_mirror) \ 95 func(_long_mirror) \ 96 func(_short_mirror) \ 97 func(_void_mirror) 98 99 #define DEFINE_PRIMITIVE_MIRROR(m) \ 100 oop Universe::m = NULL; 101 102 // Known objects 103 PRIMITIVE_MIRRORS_DO(DEFINE_PRIMITIVE_MIRROR) 104 Klass* Universe::_typeArrayKlassObjs[T_LONG+1] = { NULL /*, NULL...*/ }; 105 Klass* Universe::_objectArrayKlassObj = NULL; 106 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ }; 107 oop Universe::_main_thread_group = NULL; 108 oop Universe::_system_thread_group = NULL; 109 objArrayOop Universe::_the_empty_class_klass_array = NULL; 110 Array<Klass*>* Universe::_the_array_interfaces_array = NULL; 111 oop Universe::_the_null_sentinel = NULL; 112 oop Universe::_the_null_string = NULL; 113 oop Universe::_the_min_jint_string = NULL; 114 LatestMethodCache* Universe::_finalizer_register_cache = NULL; 115 LatestMethodCache* Universe::_loader_addClass_cache = NULL; 116 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL; 117 LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL; 118 LatestMethodCache* Universe::_do_stack_walk_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 oop Universe::_out_of_memory_error_retry = NULL; 126 oop Universe::_delayed_stack_overflow_error_message = NULL; 127 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL; 128 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0; 129 bool Universe::_verify_in_progress = false; 130 long Universe::verify_flags = Universe::Verify_All; 131 oop Universe::_null_ptr_exception_instance = NULL; 132 oop Universe::_arithmetic_exception_instance = NULL; 133 oop Universe::_virtual_machine_error_instance = NULL; 134 oop Universe::_vm_exception = NULL; 135 oop Universe::_reference_pending_list = NULL; 136 137 Array<int>* Universe::_the_empty_int_array = NULL; 138 Array<u2>* Universe::_the_empty_short_array = NULL; 139 Array<Klass*>* Universe::_the_empty_klass_array = NULL; 140 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL; 141 Array<Method*>* Universe::_the_empty_method_array = NULL; 142 143 // These variables are guarded by FullGCALot_lock. 144 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;) 145 debug_only(int Universe::_fullgc_alot_dummy_next = 0;) 146 147 // Heap 148 int Universe::_verify_count = 0; 149 150 // Oop verification (see MacroAssembler::verify_oop) 151 uintptr_t Universe::_verify_oop_mask = 0; 152 uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1; 153 154 int Universe::_base_vtable_size = 0; 155 bool Universe::_bootstrapping = false; 156 bool Universe::_module_initialized = false; 157 bool Universe::_fully_initialized = false; 158 159 size_t Universe::_heap_capacity_at_last_gc; 160 size_t Universe::_heap_used_at_last_gc = 0; 161 162 CollectedHeap* Universe::_collectedHeap = NULL; 163 164 void Universe::basic_type_classes_do(void f(Klass*)) { 165 for (int i = T_BOOLEAN; i < T_LONG+1; i++) { 166 f(_typeArrayKlassObjs[i]); 167 } 168 } 169 170 void Universe::basic_type_classes_do(KlassClosure *closure) { 171 for (int i = T_BOOLEAN; i < T_LONG+1; i++) { 172 closure->do_klass(_typeArrayKlassObjs[i]); 173 } 174 } 175 176 #define DO_PRIMITIVE_MIRROR(m) \ 177 f->do_oop((oop*) &m); 178 179 void Universe::oops_do(OopClosure* f) { 180 PRIMITIVE_MIRRORS_DO(DO_PRIMITIVE_MIRROR); 181 182 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { 183 f->do_oop((oop*) &_mirrors[i]); 184 } 185 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking"); 186 187 f->do_oop((oop*)&_the_empty_class_klass_array); 188 f->do_oop((oop*)&_the_null_sentinel); 189 f->do_oop((oop*)&_the_null_string); 190 f->do_oop((oop*)&_the_min_jint_string); 191 f->do_oop((oop*)&_out_of_memory_error_java_heap); 192 f->do_oop((oop*)&_out_of_memory_error_metaspace); 193 f->do_oop((oop*)&_out_of_memory_error_class_metaspace); 194 f->do_oop((oop*)&_out_of_memory_error_array_size); 195 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit); 196 f->do_oop((oop*)&_out_of_memory_error_realloc_objects); 197 f->do_oop((oop*)&_out_of_memory_error_retry); 198 f->do_oop((oop*)&_delayed_stack_overflow_error_message); 199 f->do_oop((oop*)&_preallocated_out_of_memory_error_array); 200 f->do_oop((oop*)&_null_ptr_exception_instance); 201 f->do_oop((oop*)&_arithmetic_exception_instance); 202 f->do_oop((oop*)&_virtual_machine_error_instance); 203 f->do_oop((oop*)&_main_thread_group); 204 f->do_oop((oop*)&_system_thread_group); 205 f->do_oop((oop*)&_vm_exception); 206 f->do_oop((oop*)&_reference_pending_list); 207 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);) 208 } 209 210 void LatestMethodCache::metaspace_pointers_do(MetaspaceClosure* it) { 211 it->push(&_klass); 212 } 213 214 void Universe::metaspace_pointers_do(MetaspaceClosure* it) { 215 for (int i = 0; i < T_LONG+1; i++) { 216 it->push(&_typeArrayKlassObjs[i]); 217 } 218 it->push(&_objectArrayKlassObj); 219 220 it->push(&_the_empty_int_array); 221 it->push(&_the_empty_short_array); 222 it->push(&_the_empty_klass_array); 223 it->push(&_the_empty_instance_klass_array); 224 it->push(&_the_empty_method_array); 225 it->push(&_the_array_interfaces_array); 226 227 _finalizer_register_cache->metaspace_pointers_do(it); 228 _loader_addClass_cache->metaspace_pointers_do(it); 229 _throw_illegal_access_error_cache->metaspace_pointers_do(it); 230 _throw_no_such_method_error_cache->metaspace_pointers_do(it); 231 _do_stack_walk_cache->metaspace_pointers_do(it); 232 } 233 234 #define ASSERT_MIRROR_NULL(m) \ 235 assert(m == NULL, "archived mirrors should be NULL"); 236 237 #define SERIALIZE_MIRROR(m) \ 238 f->do_oop(&m); \ 239 if (m != NULL) { java_lang_Class::update_archived_primitive_mirror_native_pointers(m); } 240 241 // Serialize metadata and pointers to primitive type mirrors in and out of CDS archive 242 void Universe::serialize(SerializeClosure* f) { 243 244 for (int i = 0; i < T_LONG+1; i++) { 245 f->do_ptr((void**)&_typeArrayKlassObjs[i]); 246 } 247 248 f->do_ptr((void**)&_objectArrayKlassObj); 249 250 #if INCLUDE_CDS_JAVA_HEAP 251 DEBUG_ONLY(if (DumpSharedSpaces && !HeapShared::is_heap_object_archiving_allowed()) { 252 PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NULL); 253 }); 254 PRIMITIVE_MIRRORS_DO(SERIALIZE_MIRROR); 255 #endif 256 257 f->do_ptr((void**)&_the_array_interfaces_array); 258 f->do_ptr((void**)&_the_empty_int_array); 259 f->do_ptr((void**)&_the_empty_short_array); 260 f->do_ptr((void**)&_the_empty_method_array); 261 f->do_ptr((void**)&_the_empty_klass_array); 262 f->do_ptr((void**)&_the_empty_instance_klass_array); 263 _finalizer_register_cache->serialize(f); 264 _loader_addClass_cache->serialize(f); 265 _throw_illegal_access_error_cache->serialize(f); 266 _throw_no_such_method_error_cache->serialize(f); 267 _do_stack_walk_cache->serialize(f); 268 } 269 270 void Universe::check_alignment(uintx size, uintx alignment, const char* name) { 271 if (size < alignment || size % alignment != 0) { 272 vm_exit_during_initialization( 273 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment)); 274 } 275 } 276 277 void initialize_basic_type_klass(Klass* k, TRAPS) { 278 Klass* ok = SystemDictionary::Object_klass(); 279 #if INCLUDE_CDS 280 if (UseSharedSpaces) { 281 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); 282 assert(k->super() == ok, "u3"); 283 if (k->is_instance_klass()) { 284 InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), NULL, CHECK); 285 } else { 286 ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK); 287 } 288 } else 289 #endif 290 { 291 k->initialize_supers(ok, NULL, CHECK); 292 } 293 k->append_to_sibling_list(); 294 } 295 296 void Universe::genesis(TRAPS) { 297 ResourceMark rm(THREAD); 298 299 { FlagSetting fs(_bootstrapping, true); 300 301 { MutexLocker mc(THREAD, Compile_lock); 302 303 java_lang_Class::allocate_fixup_lists(); 304 305 // determine base vtable size; without that we cannot create the array klasses 306 compute_base_vtable_size(); 307 308 if (!UseSharedSpaces) { 309 for (int i = T_BOOLEAN; i < T_LONG+1; i++) { 310 _typeArrayKlassObjs[i] = TypeArrayKlass::create_klass((BasicType)i, CHECK); 311 } 312 313 ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data(); 314 315 _the_array_interfaces_array = MetadataFactory::new_array<Klass*>(null_cld, 2, NULL, CHECK); 316 _the_empty_int_array = MetadataFactory::new_array<int>(null_cld, 0, CHECK); 317 _the_empty_short_array = MetadataFactory::new_array<u2>(null_cld, 0, CHECK); 318 _the_empty_method_array = MetadataFactory::new_array<Method*>(null_cld, 0, CHECK); 319 _the_empty_klass_array = MetadataFactory::new_array<Klass*>(null_cld, 0, CHECK); 320 _the_empty_instance_klass_array = MetadataFactory::new_array<InstanceKlass*>(null_cld, 0, CHECK); 321 } 322 } 323 324 vmSymbols::initialize(CHECK); 325 326 SystemDictionary::initialize(CHECK); 327 328 Klass* ok = SystemDictionary::Object_klass(); 329 330 _the_null_string = StringTable::intern("null", CHECK); 331 _the_min_jint_string = StringTable::intern("-2147483648", CHECK); 332 333 #if INCLUDE_CDS 334 if (UseSharedSpaces) { 335 // Verify shared interfaces array. 336 assert(_the_array_interfaces_array->at(0) == 337 SystemDictionary::Cloneable_klass(), "u3"); 338 assert(_the_array_interfaces_array->at(1) == 339 SystemDictionary::Serializable_klass(), "u3"); 340 } else 341 #endif 342 { 343 // Set up shared interfaces array. (Do this before supers are set up.) 344 _the_array_interfaces_array->at_put(0, SystemDictionary::Cloneable_klass()); 345 _the_array_interfaces_array->at_put(1, SystemDictionary::Serializable_klass()); 346 } 347 348 initialize_basic_type_klass(boolArrayKlassObj(), CHECK); 349 initialize_basic_type_klass(charArrayKlassObj(), CHECK); 350 initialize_basic_type_klass(floatArrayKlassObj(), CHECK); 351 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK); 352 initialize_basic_type_klass(byteArrayKlassObj(), CHECK); 353 initialize_basic_type_klass(shortArrayKlassObj(), CHECK); 354 initialize_basic_type_klass(intArrayKlassObj(), CHECK); 355 initialize_basic_type_klass(longArrayKlassObj(), CHECK); 356 } // end of core bootstrapping 357 358 { 359 Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK); 360 _the_null_sentinel = tns(); 361 } 362 363 // Maybe this could be lifted up now that object array can be initialized 364 // during the bootstrapping. 365 366 // OLD 367 // Initialize _objectArrayKlass after core bootstraping to make 368 // sure the super class is set up properly for _objectArrayKlass. 369 // --- 370 // NEW 371 // Since some of the old system object arrays have been converted to 372 // ordinary object arrays, _objectArrayKlass will be loaded when 373 // SystemDictionary::initialize(CHECK); is run. See the extra check 374 // for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl. 375 _objectArrayKlassObj = InstanceKlass:: 376 cast(SystemDictionary::Object_klass())->array_klass(1, CHECK); 377 // OLD 378 // Add the class to the class hierarchy manually to make sure that 379 // its vtable is initialized after core bootstrapping is completed. 380 // --- 381 // New 382 // Have already been initialized. 383 _objectArrayKlassObj->append_to_sibling_list(); 384 385 #ifdef ASSERT 386 if (FullGCALot) { 387 // Allocate an array of dummy objects. 388 // We'd like these to be at the bottom of the old generation, 389 // so that when we free one and then collect, 390 // (almost) the whole heap moves 391 // and we find out if we actually update all the oops correctly. 392 // But we can't allocate directly in the old generation, 393 // so we allocate wherever, and hope that the first collection 394 // moves these objects to the bottom of the old generation. 395 // We can allocate directly in the permanent generation, so we do. 396 int size = FullGCALotDummies * 2; 397 398 objArrayOop naked_array = oopFactory::new_objArray(SystemDictionary::Object_klass(), size, CHECK); 399 objArrayHandle dummy_array(THREAD, naked_array); 400 int i = 0; 401 while (i < size) { 402 // Allocate dummy in old generation 403 oop dummy = SystemDictionary::Object_klass()->allocate_instance(CHECK); 404 dummy_array->obj_at_put(i++, dummy); 405 } 406 { 407 // Only modify the global variable inside the mutex. 408 // If we had a race to here, the other dummy_array instances 409 // and their elements just get dropped on the floor, which is fine. 410 MutexLocker ml(THREAD, FullGCALot_lock); 411 if (_fullgc_alot_dummy_array == NULL) { 412 _fullgc_alot_dummy_array = dummy_array(); 413 } 414 } 415 assert(i == _fullgc_alot_dummy_array->length(), "just checking"); 416 } 417 #endif 418 } 419 420 #define ASSERT_MIRROR_NOT_NULL(m) \ 421 assert(m != NULL, "archived mirrors should not be NULL"); 422 423 void Universe::initialize_basic_type_mirrors(TRAPS) { 424 #if INCLUDE_CDS_JAVA_HEAP 425 if (UseSharedSpaces && 426 HeapShared::open_archive_heap_region_mapped() && 427 _int_mirror != NULL) { 428 assert(HeapShared::is_heap_object_archiving_allowed(), "Sanity"); 429 PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NOT_NULL); 430 } else 431 // _int_mirror could be NULL if archived heap is not mapped. 432 #endif 433 { 434 _int_mirror = 435 java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK); 436 _float_mirror = 437 java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK); 438 _double_mirror = 439 java_lang_Class::create_basic_type_mirror("double", T_DOUBLE, CHECK); 440 _byte_mirror = 441 java_lang_Class::create_basic_type_mirror("byte", T_BYTE, CHECK); 442 _bool_mirror = 443 java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK); 444 _char_mirror = 445 java_lang_Class::create_basic_type_mirror("char", T_CHAR, CHECK); 446 _long_mirror = 447 java_lang_Class::create_basic_type_mirror("long", T_LONG, CHECK); 448 _short_mirror = 449 java_lang_Class::create_basic_type_mirror("short", T_SHORT, CHECK); 450 _void_mirror = 451 java_lang_Class::create_basic_type_mirror("void", T_VOID, CHECK); 452 } 453 454 _mirrors[T_INT] = _int_mirror; 455 _mirrors[T_FLOAT] = _float_mirror; 456 _mirrors[T_DOUBLE] = _double_mirror; 457 _mirrors[T_BYTE] = _byte_mirror; 458 _mirrors[T_BOOLEAN] = _bool_mirror; 459 _mirrors[T_CHAR] = _char_mirror; 460 _mirrors[T_LONG] = _long_mirror; 461 _mirrors[T_SHORT] = _short_mirror; 462 _mirrors[T_VOID] = _void_mirror; 463 //_mirrors[T_OBJECT] = _object_klass->java_mirror(); 464 //_mirrors[T_ARRAY] = _object_klass->java_mirror(); 465 } 466 467 void Universe::fixup_mirrors(TRAPS) { 468 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, 469 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply 470 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note 471 // that the number of objects allocated at this point is very small. 472 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); 473 HandleMark hm(THREAD); 474 475 if (!UseSharedSpaces) { 476 // Cache the start of the static fields 477 InstanceMirrorKlass::init_offset_of_static_fields(); 478 } 479 480 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list(); 481 int list_length = list->length(); 482 for (int i = 0; i < list_length; i++) { 483 Klass* k = list->at(i); 484 assert(k->is_klass(), "List should only hold classes"); 485 EXCEPTION_MARK; 486 java_lang_Class::fixup_mirror(k, CATCH); 487 } 488 delete java_lang_Class::fixup_mirror_list(); 489 java_lang_Class::set_fixup_mirror_list(NULL); 490 } 491 492 #define assert_pll_locked(test) \ 493 assert(Heap_lock->test(), "Reference pending list access requires lock") 494 495 #define assert_pll_ownership() assert_pll_locked(owned_by_self) 496 497 oop Universe::reference_pending_list() { 498 if (Thread::current()->is_VM_thread()) { 499 assert_pll_locked(is_locked); 500 } else { 501 assert_pll_ownership(); 502 } 503 return _reference_pending_list; 504 } 505 506 void Universe::set_reference_pending_list(oop list) { 507 assert_pll_ownership(); 508 _reference_pending_list = list; 509 } 510 511 bool Universe::has_reference_pending_list() { 512 assert_pll_ownership(); 513 return _reference_pending_list != NULL; 514 } 515 516 oop Universe::swap_reference_pending_list(oop list) { 517 assert_pll_locked(is_locked); 518 return Atomic::xchg(&_reference_pending_list, list); 519 } 520 521 #undef assert_pll_locked 522 #undef assert_pll_ownership 523 524 void Universe::reinitialize_vtable_of(Klass* ko, TRAPS) { 525 // init vtable of k and all subclasses 526 ko->vtable().initialize_vtable(false, CHECK); 527 if (ko->is_instance_klass()) { 528 for (Klass* sk = ko->subklass(); 529 sk != NULL; 530 sk = sk->next_sibling()) { 531 reinitialize_vtable_of(sk, CHECK); 532 } 533 } 534 } 535 536 void Universe::reinitialize_vtables(TRAPS) { 537 // The vtables are initialized by starting at java.lang.Object and 538 // initializing through the subclass links, so that the super 539 // classes are always initialized first. 540 Klass* ok = SystemDictionary::Object_klass(); 541 Universe::reinitialize_vtable_of(ok, THREAD); 542 } 543 544 545 void initialize_itable_for_klass(InstanceKlass* k, TRAPS) { 546 k->itable().initialize_itable(false, CHECK); 547 } 548 549 550 void Universe::reinitialize_itables(TRAPS) { 551 MutexLocker mcld(THREAD, ClassLoaderDataGraph_lock); 552 ClassLoaderDataGraph::dictionary_classes_do(initialize_itable_for_klass, CHECK); 553 } 554 555 556 bool Universe::on_page_boundary(void* addr) { 557 return is_aligned(addr, os::vm_page_size()); 558 } 559 560 561 bool Universe::should_fill_in_stack_trace(Handle throwable) { 562 // never attempt to fill in the stack trace of preallocated errors that do not have 563 // backtrace. These errors are kept alive forever and may be "re-used" when all 564 // preallocated errors with backtrace have been consumed. Also need to avoid 565 // a potential loop which could happen if an out of memory occurs when attempting 566 // to allocate the backtrace. 567 return ((throwable() != Universe::_out_of_memory_error_java_heap) && 568 (throwable() != Universe::_out_of_memory_error_metaspace) && 569 (throwable() != Universe::_out_of_memory_error_class_metaspace) && 570 (throwable() != Universe::_out_of_memory_error_array_size) && 571 (throwable() != Universe::_out_of_memory_error_gc_overhead_limit) && 572 (throwable() != Universe::_out_of_memory_error_realloc_objects) && 573 (throwable() != Universe::_out_of_memory_error_retry)); 574 } 575 576 577 oop Universe::gen_out_of_memory_error(oop default_err) { 578 // generate an out of memory error: 579 // - if there is a preallocated error and stack traces are available 580 // (j.l.Throwable is initialized), then return the preallocated 581 // error with a filled in stack trace, and with the message 582 // provided by the default error. 583 // - otherwise, return the default error, without a stack trace. 584 int next; 585 if ((_preallocated_out_of_memory_error_avail_count > 0) && 586 SystemDictionary::Throwable_klass()->is_initialized()) { 587 next = (int)Atomic::add(&_preallocated_out_of_memory_error_avail_count, -1); 588 assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt"); 589 } else { 590 next = -1; 591 } 592 if (next < 0) { 593 // all preallocated errors have been used. 594 // return default 595 return default_err; 596 } else { 597 Thread* THREAD = Thread::current(); 598 Handle default_err_h(THREAD, default_err); 599 // get the error object at the slot and set set it to NULL so that the 600 // array isn't keeping it alive anymore. 601 Handle exc(THREAD, preallocated_out_of_memory_errors()->obj_at(next)); 602 assert(exc() != NULL, "slot has been used already"); 603 preallocated_out_of_memory_errors()->obj_at_put(next, NULL); 604 605 // use the message from the default error 606 oop msg = java_lang_Throwable::message(default_err_h()); 607 assert(msg != NULL, "no message"); 608 java_lang_Throwable::set_message(exc(), msg); 609 610 // populate the stack trace and return it. 611 java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc); 612 return exc(); 613 } 614 } 615 616 intptr_t Universe::_non_oop_bits = 0; 617 618 void* Universe::non_oop_word() { 619 // Neither the high bits nor the low bits of this value is allowed 620 // to look like (respectively) the high or low bits of a real oop. 621 // 622 // High and low are CPU-specific notions, but low always includes 623 // the low-order bit. Since oops are always aligned at least mod 4, 624 // setting the low-order bit will ensure that the low half of the 625 // word will never look like that of a real oop. 626 // 627 // Using the OS-supplied non-memory-address word (usually 0 or -1) 628 // will take care of the high bits, however many there are. 629 630 if (_non_oop_bits == 0) { 631 _non_oop_bits = (intptr_t)os::non_memory_address_word() | 1; 632 } 633 634 return (void*)_non_oop_bits; 635 } 636 637 static void initialize_global_behaviours() { 638 CompiledICProtectionBehaviour::set_current(new DefaultICProtectionBehaviour()); 639 } 640 641 jint universe_init() { 642 assert(!Universe::_fully_initialized, "called after initialize_vtables"); 643 guarantee(1 << LogHeapWordSize == sizeof(HeapWord), 644 "LogHeapWordSize is incorrect."); 645 guarantee(sizeof(oop) >= sizeof(HeapWord), "HeapWord larger than oop?"); 646 guarantee(sizeof(oop) % sizeof(HeapWord) == 0, 647 "oop size is not not a multiple of HeapWord size"); 648 649 TraceTime timer("Genesis", TRACETIME_LOG(Info, startuptime)); 650 651 JavaClasses::compute_hard_coded_offsets(); 652 653 initialize_global_behaviours(); 654 655 GCConfig::arguments()->initialize_heap_sizes(); 656 657 jint status = Universe::initialize_heap(); 658 if (status != JNI_OK) { 659 return status; 660 } 661 662 Universe::initialize_tlab(); 663 664 Metaspace::global_initialize(); 665 666 // Initialize performance counters for metaspaces 667 MetaspaceCounters::initialize_performance_counters(); 668 CompressedClassSpaceCounters::initialize_performance_counters(); 669 670 AOTLoader::universe_init(); 671 672 // Checks 'AfterMemoryInit' constraints. 673 if (!JVMFlagConstraintList::check_constraints(JVMFlagConstraint::AfterMemoryInit)) { 674 return JNI_EINVAL; 675 } 676 677 // Create memory for metadata. Must be after initializing heap for 678 // DumpSharedSpaces. 679 ClassLoaderData::init_null_class_loader_data(); 680 681 // We have a heap so create the Method* caches before 682 // Metaspace::initialize_shared_spaces() tries to populate them. 683 Universe::_finalizer_register_cache = new LatestMethodCache(); 684 Universe::_loader_addClass_cache = new LatestMethodCache(); 685 Universe::_throw_illegal_access_error_cache = new LatestMethodCache(); 686 Universe::_throw_no_such_method_error_cache = new LatestMethodCache(); 687 Universe::_do_stack_walk_cache = new LatestMethodCache(); 688 689 #if INCLUDE_CDS 690 if (UseSharedSpaces) { 691 // Read the data structures supporting the shared spaces (shared 692 // system dictionary, symbol table, etc.). After that, access to 693 // the file (other than the mapped regions) is no longer needed, and 694 // the file is closed. Closing the file does not affect the 695 // currently mapped regions. 696 MetaspaceShared::initialize_shared_spaces(); 697 StringTable::create_table(); 698 } else 699 #endif 700 { 701 SymbolTable::create_table(); 702 StringTable::create_table(); 703 } 704 705 #if INCLUDE_CDS 706 if (Arguments::is_dumping_archive()) { 707 MetaspaceShared::prepare_for_dumping(); 708 } 709 #endif 710 711 if (strlen(VerifySubSet) > 0) { 712 Universe::initialize_verify_flags(); 713 } 714 715 ResolvedMethodTable::create_table(); 716 717 return JNI_OK; 718 } 719 720 jint Universe::initialize_heap() { 721 assert(_collectedHeap == NULL, "Heap already created"); 722 _collectedHeap = GCConfig::arguments()->create_heap(); 723 jint status = _collectedHeap->initialize(); 724 725 if (status == JNI_OK) { 726 log_info(gc)("Using %s", _collectedHeap->name()); 727 } 728 729 return status; 730 } 731 732 void Universe::initialize_tlab() { 733 ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size()); 734 if (UseTLAB) { 735 assert(Universe::heap()->supports_tlab_allocation(), 736 "Should support thread-local allocation buffers"); 737 ThreadLocalAllocBuffer::startup_initialization(); 738 } 739 } 740 741 ReservedHeapSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { 742 743 assert(alignment <= Arguments::conservative_max_heap_alignment(), 744 "actual alignment " SIZE_FORMAT " must be within maximum heap alignment " SIZE_FORMAT, 745 alignment, Arguments::conservative_max_heap_alignment()); 746 747 size_t total_reserved = align_up(heap_size, alignment); 748 assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), 749 "heap size is too big for compressed oops"); 750 751 bool use_large_pages = UseLargePages && is_aligned(alignment, os::large_page_size()); 752 assert(!UseLargePages 753 || UseParallelGC 754 || use_large_pages, "Wrong alignment to use large pages"); 755 756 // Now create the space. 757 ReservedHeapSpace total_rs(total_reserved, alignment, use_large_pages, AllocateHeapAt); 758 759 if (total_rs.is_reserved()) { 760 assert((total_reserved == total_rs.size()) && ((uintptr_t)total_rs.base() % alignment == 0), 761 "must be exactly of required size and alignment"); 762 // We are good. 763 764 if (AllocateHeapAt != NULL) { 765 log_info(gc,heap)("Successfully allocated Java heap at location %s", AllocateHeapAt); 766 } 767 768 if (UseCompressedOops) { 769 CompressedOops::initialize(total_rs); 770 } 771 772 Universe::calculate_verify_data((HeapWord*)total_rs.base(), (HeapWord*)total_rs.end()); 773 774 return total_rs; 775 } 776 777 vm_exit_during_initialization( 778 err_msg("Could not reserve enough space for " SIZE_FORMAT "KB object heap", 779 total_reserved/K)); 780 781 // satisfy compiler 782 ShouldNotReachHere(); 783 return ReservedHeapSpace(0, 0, false); 784 } 785 786 787 // It's the caller's responsibility to ensure glitch-freedom 788 // (if required). 789 void Universe::update_heap_info_at_gc() { 790 _heap_capacity_at_last_gc = heap()->capacity(); 791 _heap_used_at_last_gc = heap()->used(); 792 } 793 794 void initialize_known_method(LatestMethodCache* method_cache, 795 InstanceKlass* ik, 796 const char* method, 797 Symbol* signature, 798 bool is_static, TRAPS) 799 { 800 TempNewSymbol name = SymbolTable::new_symbol(method); 801 Method* m = NULL; 802 // The klass must be linked before looking up the method. 803 if (!ik->link_class_or_fail(THREAD) || 804 ((m = ik->find_method(name, signature)) == NULL) || 805 is_static != m->is_static()) { 806 ResourceMark rm(THREAD); 807 // NoSuchMethodException doesn't actually work because it tries to run the 808 // <init> function before java_lang_Class is linked. Print error and exit. 809 vm_exit_during_initialization(err_msg("Unable to link/verify %s.%s method", 810 ik->name()->as_C_string(), method)); 811 } 812 method_cache->init(ik, m); 813 } 814 815 void Universe::initialize_known_methods(TRAPS) { 816 // Set up static method for registering finalizers 817 initialize_known_method(_finalizer_register_cache, 818 SystemDictionary::Finalizer_klass(), 819 "register", 820 vmSymbols::object_void_signature(), true, CHECK); 821 822 initialize_known_method(_throw_illegal_access_error_cache, 823 SystemDictionary::internal_Unsafe_klass(), 824 "throwIllegalAccessError", 825 vmSymbols::void_method_signature(), true, CHECK); 826 827 initialize_known_method(_throw_no_such_method_error_cache, 828 SystemDictionary::internal_Unsafe_klass(), 829 "throwNoSuchMethodError", 830 vmSymbols::void_method_signature(), true, CHECK); 831 832 // Set up method for registering loaded classes in class loader vector 833 initialize_known_method(_loader_addClass_cache, 834 SystemDictionary::ClassLoader_klass(), 835 "addClass", 836 vmSymbols::class_void_signature(), false, CHECK); 837 838 // Set up method for stack walking 839 initialize_known_method(_do_stack_walk_cache, 840 SystemDictionary::AbstractStackWalker_klass(), 841 "doStackWalk", 842 vmSymbols::doStackWalk_signature(), false, CHECK); 843 } 844 845 void universe2_init() { 846 EXCEPTION_MARK; 847 Universe::genesis(CATCH); 848 } 849 850 // Set after initialization of the module runtime, call_initModuleRuntime 851 void universe_post_module_init() { 852 Universe::_module_initialized = true; 853 } 854 855 bool universe_post_init() { 856 assert(!is_init_completed(), "Error: initialization not yet completed!"); 857 Universe::_fully_initialized = true; 858 EXCEPTION_MARK; 859 if (!UseSharedSpaces) { 860 ResourceMark rm; 861 Universe::reinitialize_vtables(CHECK_false); 862 Universe::reinitialize_itables(CHECK_false); 863 } 864 865 HandleMark hm(THREAD); 866 // Setup preallocated empty java.lang.Class array 867 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false); 868 869 // Setup preallocated OutOfMemoryError errors 870 Klass* k = SystemDictionary::OutOfMemoryError_klass(); 871 InstanceKlass* ik = InstanceKlass::cast(k); 872 Universe::_out_of_memory_error_java_heap = ik->allocate_instance(CHECK_false); 873 Universe::_out_of_memory_error_metaspace = ik->allocate_instance(CHECK_false); 874 Universe::_out_of_memory_error_class_metaspace = ik->allocate_instance(CHECK_false); 875 Universe::_out_of_memory_error_array_size = ik->allocate_instance(CHECK_false); 876 Universe::_out_of_memory_error_gc_overhead_limit = 877 ik->allocate_instance(CHECK_false); 878 Universe::_out_of_memory_error_realloc_objects = ik->allocate_instance(CHECK_false); 879 Universe::_out_of_memory_error_retry = ik->allocate_instance(CHECK_false); 880 881 // Setup preallocated cause message for delayed StackOverflowError 882 if (StackReservedPages > 0) { 883 Universe::_delayed_stack_overflow_error_message = 884 java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false); 885 } 886 887 // Setup preallocated NullPointerException 888 // (this is currently used for a cheap & dirty solution in compiler exception handling) 889 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false); 890 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 891 // Setup preallocated ArithmeticException 892 // (this is currently used for a cheap & dirty solution in compiler exception handling) 893 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false); 894 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 895 // Virtual Machine Error for when we get into a situation we can't resolve 896 k = SystemDictionary::VirtualMachineError_klass(); 897 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false); 898 if (!linked) { 899 tty->print_cr("Unable to link/verify VirtualMachineError class"); 900 return false; // initialization failed 901 } 902 Universe::_virtual_machine_error_instance = 903 InstanceKlass::cast(k)->allocate_instance(CHECK_false); 904 905 Universe::_vm_exception = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 906 907 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false); 908 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg()); 909 910 msg = java_lang_String::create_from_str("Metaspace", CHECK_false); 911 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg()); 912 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false); 913 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg()); 914 915 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); 916 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); 917 918 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false); 919 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg()); 920 921 msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK_false); 922 java_lang_Throwable::set_message(Universe::_out_of_memory_error_realloc_objects, msg()); 923 924 msg = java_lang_String::create_from_str("Java heap space: failed retryable allocation", CHECK_false); 925 java_lang_Throwable::set_message(Universe::_out_of_memory_error_retry, msg()); 926 927 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); 928 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); 929 930 // Setup the array of errors that have preallocated backtrace 931 k = Universe::_out_of_memory_error_java_heap->klass(); 932 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); 933 ik = InstanceKlass::cast(k); 934 935 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; 936 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(ik, len, CHECK_false); 937 for (int i=0; i<len; i++) { 938 oop err = ik->allocate_instance(CHECK_false); 939 Handle err_h = Handle(THREAD, err); 940 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); 941 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); 942 } 943 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; 944 945 Universe::initialize_known_methods(CHECK_false); 946 947 // This needs to be done before the first scavenge/gc, since 948 // it's an input to soft ref clearing policy. 949 { 950 MutexLocker x(THREAD, Heap_lock); 951 Universe::update_heap_info_at_gc(); 952 } 953 954 // ("weak") refs processing infrastructure initialization 955 Universe::heap()->post_initialize(); 956 957 MemoryService::add_metaspace_memory_pools(); 958 959 MemoryService::set_universe_heap(Universe::heap()); 960 #if INCLUDE_CDS 961 MetaspaceShared::post_initialize(CHECK_false); 962 #endif 963 return true; 964 } 965 966 967 void Universe::compute_base_vtable_size() { 968 _base_vtable_size = ClassLoader::compute_Object_vtable(); 969 } 970 971 void Universe::print_on(outputStream* st) { 972 GCMutexLocker hl(Heap_lock); // Heap_lock might be locked by caller thread. 973 st->print_cr("Heap"); 974 heap()->print_on(st); 975 } 976 977 void Universe::print_heap_at_SIGBREAK() { 978 if (PrintHeapAtSIGBREAK) { 979 print_on(tty); 980 tty->cr(); 981 tty->flush(); 982 } 983 } 984 985 void Universe::print_heap_before_gc() { 986 LogTarget(Debug, gc, heap) lt; 987 if (lt.is_enabled()) { 988 LogStream ls(lt); 989 ls.print("Heap before GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections()); 990 ResourceMark rm; 991 heap()->print_on(&ls); 992 } 993 } 994 995 void Universe::print_heap_after_gc() { 996 LogTarget(Debug, gc, heap) lt; 997 if (lt.is_enabled()) { 998 LogStream ls(lt); 999 ls.print("Heap after GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections()); 1000 ResourceMark rm; 1001 heap()->print_on(&ls); 1002 } 1003 } 1004 1005 void Universe::initialize_verify_flags() { 1006 verify_flags = 0; 1007 const char delimiter[] = " ,"; 1008 1009 size_t length = strlen(VerifySubSet); 1010 char* subset_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal); 1011 strncpy(subset_list, VerifySubSet, length + 1); 1012 char* save_ptr; 1013 1014 char* token = strtok_r(subset_list, delimiter, &save_ptr); 1015 while (token != NULL) { 1016 if (strcmp(token, "threads") == 0) { 1017 verify_flags |= Verify_Threads; 1018 } else if (strcmp(token, "heap") == 0) { 1019 verify_flags |= Verify_Heap; 1020 } else if (strcmp(token, "symbol_table") == 0) { 1021 verify_flags |= Verify_SymbolTable; 1022 } else if (strcmp(token, "string_table") == 0) { 1023 verify_flags |= Verify_StringTable; 1024 } else if (strcmp(token, "codecache") == 0) { 1025 verify_flags |= Verify_CodeCache; 1026 } else if (strcmp(token, "dictionary") == 0) { 1027 verify_flags |= Verify_SystemDictionary; 1028 } else if (strcmp(token, "classloader_data_graph") == 0) { 1029 verify_flags |= Verify_ClassLoaderDataGraph; 1030 } else if (strcmp(token, "metaspace") == 0) { 1031 verify_flags |= Verify_MetaspaceUtils; 1032 } else if (strcmp(token, "jni_handles") == 0) { 1033 verify_flags |= Verify_JNIHandles; 1034 } else if (strcmp(token, "codecache_oops") == 0) { 1035 verify_flags |= Verify_CodeCacheOops; 1036 } else if (strcmp(token, "resolved_method_table") == 0) { 1037 verify_flags |= Verify_ResolvedMethodTable; 1038 } else { 1039 vm_exit_during_initialization(err_msg("VerifySubSet: \'%s\' memory sub-system is unknown, please correct it", token)); 1040 } 1041 token = strtok_r(NULL, delimiter, &save_ptr); 1042 } 1043 FREE_C_HEAP_ARRAY(char, subset_list); 1044 } 1045 1046 bool Universe::should_verify_subset(uint subset) { 1047 if (verify_flags & subset) { 1048 return true; 1049 } 1050 return false; 1051 } 1052 1053 void Universe::verify(VerifyOption option, const char* prefix) { 1054 // The use of _verify_in_progress is a temporary work around for 1055 // 6320749. Don't bother with a creating a class to set and clear 1056 // it since it is only used in this method and the control flow is 1057 // straight forward. 1058 _verify_in_progress = true; 1059 1060 COMPILER2_PRESENT( 1061 assert(!DerivedPointerTable::is_active(), 1062 "DPT should not be active during verification " 1063 "(of thread stacks below)"); 1064 ) 1065 1066 ResourceMark rm; 1067 HandleMark hm; // Handles created during verification can be zapped 1068 _verify_count++; 1069 1070 FormatBuffer<> title("Verifying %s", prefix); 1071 GCTraceTime(Info, gc, verify) tm(title.buffer()); 1072 if (should_verify_subset(Verify_Threads)) { 1073 log_debug(gc, verify)("Threads"); 1074 Threads::verify(); 1075 } 1076 if (should_verify_subset(Verify_Heap)) { 1077 log_debug(gc, verify)("Heap"); 1078 heap()->verify(option); 1079 } 1080 if (should_verify_subset(Verify_SymbolTable)) { 1081 log_debug(gc, verify)("SymbolTable"); 1082 SymbolTable::verify(); 1083 } 1084 if (should_verify_subset(Verify_StringTable)) { 1085 log_debug(gc, verify)("StringTable"); 1086 StringTable::verify(); 1087 } 1088 if (should_verify_subset(Verify_CodeCache)) { 1089 { 1090 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1091 log_debug(gc, verify)("CodeCache"); 1092 CodeCache::verify(); 1093 } 1094 } 1095 if (should_verify_subset(Verify_SystemDictionary)) { 1096 log_debug(gc, verify)("SystemDictionary"); 1097 SystemDictionary::verify(); 1098 } 1099 #ifndef PRODUCT 1100 if (should_verify_subset(Verify_ClassLoaderDataGraph)) { 1101 log_debug(gc, verify)("ClassLoaderDataGraph"); 1102 ClassLoaderDataGraph::verify(); 1103 } 1104 #endif 1105 if (should_verify_subset(Verify_MetaspaceUtils)) { 1106 log_debug(gc, verify)("MetaspaceUtils"); 1107 MetaspaceUtils::verify_free_chunks(); 1108 } 1109 if (should_verify_subset(Verify_JNIHandles)) { 1110 log_debug(gc, verify)("JNIHandles"); 1111 JNIHandles::verify(); 1112 } 1113 if (should_verify_subset(Verify_CodeCacheOops)) { 1114 log_debug(gc, verify)("CodeCache Oops"); 1115 CodeCache::verify_oops(); 1116 } 1117 if (should_verify_subset(Verify_ResolvedMethodTable)) { 1118 log_debug(gc, verify)("ResolvedMethodTable Oops"); 1119 ResolvedMethodTable::verify(); 1120 } 1121 1122 _verify_in_progress = false; 1123 } 1124 1125 1126 #ifndef PRODUCT 1127 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) { 1128 assert(low_boundary < high_boundary, "bad interval"); 1129 1130 // decide which low-order bits we require to be clear: 1131 size_t alignSize = MinObjAlignmentInBytes; 1132 size_t min_object_size = CollectedHeap::min_fill_size(); 1133 1134 // make an inclusive limit: 1135 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize; 1136 uintptr_t min = (uintptr_t)low_boundary; 1137 assert(min < max, "bad interval"); 1138 uintptr_t diff = max ^ min; 1139 1140 // throw away enough low-order bits to make the diff vanish 1141 uintptr_t mask = (uintptr_t)(-1); 1142 while ((mask & diff) != 0) 1143 mask <<= 1; 1144 uintptr_t bits = (min & mask); 1145 assert(bits == (max & mask), "correct mask"); 1146 // check an intermediate value between min and max, just to make sure: 1147 assert(bits == ((min + (max-min)/2) & mask), "correct mask"); 1148 1149 // require address alignment, too: 1150 mask |= (alignSize - 1); 1151 1152 if (!(_verify_oop_mask == 0 && _verify_oop_bits == (uintptr_t)-1)) { 1153 assert(_verify_oop_mask == mask && _verify_oop_bits == bits, "mask stability"); 1154 } 1155 _verify_oop_mask = mask; 1156 _verify_oop_bits = bits; 1157 } 1158 1159 // Oop verification (see MacroAssembler::verify_oop) 1160 1161 uintptr_t Universe::verify_oop_mask() { 1162 return _verify_oop_mask; 1163 } 1164 1165 uintptr_t Universe::verify_oop_bits() { 1166 return _verify_oop_bits; 1167 } 1168 1169 uintptr_t Universe::verify_mark_mask() { 1170 return markWord::lock_mask_in_place; 1171 } 1172 1173 uintptr_t Universe::verify_mark_bits() { 1174 intptr_t mask = verify_mark_mask(); 1175 intptr_t bits = (intptr_t)markWord::prototype().value(); 1176 assert((bits & ~mask) == 0, "no stray header bits"); 1177 return bits; 1178 } 1179 #endif // PRODUCT 1180 1181 1182 void LatestMethodCache::init(Klass* k, Method* m) { 1183 if (!UseSharedSpaces) { 1184 _klass = k; 1185 } 1186 #ifndef PRODUCT 1187 else { 1188 // sharing initilization should have already set up _klass 1189 assert(_klass != NULL, "just checking"); 1190 } 1191 #endif 1192 1193 _method_idnum = m->method_idnum(); 1194 assert(_method_idnum >= 0, "sanity check"); 1195 } 1196 1197 1198 Method* LatestMethodCache::get_method() { 1199 if (klass() == NULL) return NULL; 1200 InstanceKlass* ik = InstanceKlass::cast(klass()); 1201 Method* m = ik->method_with_idnum(method_idnum()); 1202 assert(m != NULL, "sanity check"); 1203 return m; 1204 } 1205 1206 1207 #ifdef ASSERT 1208 // Release dummy object(s) at bottom of heap 1209 bool Universe::release_fullgc_alot_dummy() { 1210 MutexLocker ml(FullGCALot_lock); 1211 if (_fullgc_alot_dummy_array != NULL) { 1212 if (_fullgc_alot_dummy_next >= _fullgc_alot_dummy_array->length()) { 1213 // No more dummies to release, release entire array instead 1214 _fullgc_alot_dummy_array = NULL; 1215 return false; 1216 } 1217 1218 // Release dummy at bottom of old generation 1219 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL); 1220 1221 // Release dummy at bottom of permanent generation 1222 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL); 1223 } 1224 return true; 1225 } 1226 1227 #endif // ASSERT