1 /* 2 * Copyright (c) 2001, 2017, 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 "classfile/systemDictionary.hpp" 27 #include "gc/shared/allocTracer.hpp" 28 #include "gc/shared/barrierSet.inline.hpp" 29 #include "gc/shared/collectedHeap.hpp" 30 #include "gc/shared/collectedHeap.inline.hpp" 31 #include "gc/shared/gcHeapSummary.hpp" 32 #include "gc/shared/gcTrace.hpp" 33 #include "gc/shared/gcTraceTime.inline.hpp" 34 #include "gc/shared/gcWhen.hpp" 35 #include "gc/shared/vmGCOperations.hpp" 36 #include "logging/log.hpp" 37 #include "memory/metaspace.hpp" 38 #include "memory/resourceArea.hpp" 39 #include "oops/instanceMirrorKlass.hpp" 40 #include "oops/oop.inline.hpp" 41 #include "runtime/init.hpp" 42 #include "runtime/thread.inline.hpp" 43 #include "services/heapDumper.hpp" 44 #include "utilities/align.hpp" 45 46 47 #ifdef ASSERT 48 int CollectedHeap::_fire_out_of_memory_count = 0; 49 #endif 50 51 size_t CollectedHeap::_filler_array_max_size = 0; 52 53 template <> 54 void EventLogBase<GCMessage>::print(outputStream* st, GCMessage& m) { 55 st->print_cr("GC heap %s", m.is_before ? "before" : "after"); 56 st->print_raw(m); 57 } 58 59 void GCHeapLog::log_heap(CollectedHeap* heap, bool before) { 60 if (!should_log()) { 61 return; 62 } 63 64 double timestamp = fetch_timestamp(); 65 MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag); 66 int index = compute_log_index(); 67 _records[index].thread = NULL; // Its the GC thread so it's not that interesting. 68 _records[index].timestamp = timestamp; 69 _records[index].data.is_before = before; 70 stringStream st(_records[index].data.buffer(), _records[index].data.size()); 71 72 st.print_cr("{Heap %s GC invocations=%u (full %u):", 73 before ? "before" : "after", 74 heap->total_collections(), 75 heap->total_full_collections()); 76 77 heap->print_on(&st); 78 st.print_cr("}"); 79 } 80 81 VirtualSpaceSummary CollectedHeap::create_heap_space_summary() { 82 size_t capacity_in_words = capacity() / HeapWordSize; 83 84 return VirtualSpaceSummary( 85 reserved_region().start(), reserved_region().start() + capacity_in_words, reserved_region().end()); 86 } 87 88 GCHeapSummary CollectedHeap::create_heap_summary() { 89 VirtualSpaceSummary heap_space = create_heap_space_summary(); 90 return GCHeapSummary(heap_space, used()); 91 } 92 93 MetaspaceSummary CollectedHeap::create_metaspace_summary() { 94 const MetaspaceSizes meta_space( 95 MetaspaceAux::committed_bytes(), 96 MetaspaceAux::used_bytes(), 97 MetaspaceAux::reserved_bytes()); 98 const MetaspaceSizes data_space( 99 MetaspaceAux::committed_bytes(Metaspace::NonClassType), 100 MetaspaceAux::used_bytes(Metaspace::NonClassType), 101 MetaspaceAux::reserved_bytes(Metaspace::NonClassType)); 102 const MetaspaceSizes class_space( 103 MetaspaceAux::committed_bytes(Metaspace::ClassType), 104 MetaspaceAux::used_bytes(Metaspace::ClassType), 105 MetaspaceAux::reserved_bytes(Metaspace::ClassType)); 106 107 const MetaspaceChunkFreeListSummary& ms_chunk_free_list_summary = 108 MetaspaceAux::chunk_free_list_summary(Metaspace::NonClassType); 109 const MetaspaceChunkFreeListSummary& class_chunk_free_list_summary = 110 MetaspaceAux::chunk_free_list_summary(Metaspace::ClassType); 111 112 return MetaspaceSummary(MetaspaceGC::capacity_until_GC(), meta_space, data_space, class_space, 113 ms_chunk_free_list_summary, class_chunk_free_list_summary); 114 } 115 116 void CollectedHeap::print_heap_before_gc() { 117 Universe::print_heap_before_gc(); 118 if (_gc_heap_log != NULL) { 119 _gc_heap_log->log_heap_before(this); 120 } 121 } 122 123 void CollectedHeap::print_heap_after_gc() { 124 Universe::print_heap_after_gc(); 125 if (_gc_heap_log != NULL) { 126 _gc_heap_log->log_heap_after(this); 127 } 128 } 129 130 void CollectedHeap::print_on_error(outputStream* st) const { 131 st->print_cr("Heap:"); 132 print_extended_on(st); 133 st->cr(); 134 135 _barrier_set->print_on(st); 136 } 137 138 void CollectedHeap::register_nmethod(nmethod* nm) { 139 assert_locked_or_safepoint(CodeCache_lock); 140 if (!nm->on_scavenge_root_list() && nm->detect_scavenge_root_oops()) { 141 CodeCache::add_scavenge_root_nmethod(nm); 142 } 143 } 144 145 void CollectedHeap::unregister_nmethod(nmethod* nm) { 146 assert_locked_or_safepoint(CodeCache_lock); 147 } 148 149 void CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) { 150 const GCHeapSummary& heap_summary = create_heap_summary(); 151 gc_tracer->report_gc_heap_summary(when, heap_summary); 152 153 const MetaspaceSummary& metaspace_summary = create_metaspace_summary(); 154 gc_tracer->report_metaspace_summary(when, metaspace_summary); 155 } 156 157 void CollectedHeap::trace_heap_before_gc(const GCTracer* gc_tracer) { 158 trace_heap(GCWhen::BeforeGC, gc_tracer); 159 } 160 161 void CollectedHeap::trace_heap_after_gc(const GCTracer* gc_tracer) { 162 trace_heap(GCWhen::AfterGC, gc_tracer); 163 } 164 165 // WhiteBox API support for concurrent collectors. These are the 166 // default implementations, for collectors which don't support this 167 // feature. 168 bool CollectedHeap::supports_concurrent_phase_control() const { 169 return false; 170 } 171 172 const char* const* CollectedHeap::concurrent_phases() const { 173 static const char* const result[] = { NULL }; 174 return result; 175 } 176 177 bool CollectedHeap::request_concurrent_phase(const char* phase) { 178 return false; 179 } 180 181 // Memory state functions. 182 183 184 CollectedHeap::CollectedHeap() : 185 _barrier_set(NULL), 186 _is_gc_active(false), 187 _total_collections(0), 188 _total_full_collections(0), 189 _gc_cause(GCCause::_no_gc), 190 _gc_lastcause(GCCause::_no_gc), 191 _defer_initial_card_mark(false) // strengthened by subclass in pre_initialize() below. 192 { 193 const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT)); 194 const size_t elements_per_word = HeapWordSize / sizeof(jint); 195 _filler_array_max_size = align_object_size(filler_array_hdr_size() + 196 max_len / elements_per_word); 197 198 NOT_PRODUCT(_promotion_failure_alot_count = 0;) 199 NOT_PRODUCT(_promotion_failure_alot_gc_number = 0;) 200 201 if (UsePerfData) { 202 EXCEPTION_MARK; 203 204 // create the gc cause jvmstat counters 205 _perf_gc_cause = PerfDataManager::create_string_variable(SUN_GC, "cause", 206 80, GCCause::to_string(_gc_cause), CHECK); 207 208 _perf_gc_lastcause = 209 PerfDataManager::create_string_variable(SUN_GC, "lastCause", 210 80, GCCause::to_string(_gc_lastcause), CHECK); 211 } 212 213 // Create the ring log 214 if (LogEvents) { 215 _gc_heap_log = new GCHeapLog(); 216 } else { 217 _gc_heap_log = NULL; 218 } 219 } 220 221 // This interface assumes that it's being called by the 222 // vm thread. It collects the heap assuming that the 223 // heap lock is already held and that we are executing in 224 // the context of the vm thread. 225 void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) { 226 assert(Thread::current()->is_VM_thread(), "Precondition#1"); 227 assert(Heap_lock->is_locked(), "Precondition#2"); 228 GCCauseSetter gcs(this, cause); 229 switch (cause) { 230 case GCCause::_heap_inspection: 231 case GCCause::_heap_dump: 232 case GCCause::_metadata_GC_threshold : { 233 HandleMark hm; 234 do_full_collection(false); // don't clear all soft refs 235 break; 236 } 237 case GCCause::_metadata_GC_clear_soft_refs: { 238 HandleMark hm; 239 do_full_collection(true); // do clear all soft refs 240 break; 241 } 242 default: 243 ShouldNotReachHere(); // Unexpected use of this function 244 } 245 } 246 247 void CollectedHeap::set_barrier_set(BarrierSet* barrier_set) { 248 _barrier_set = barrier_set; 249 oopDesc::set_bs(_barrier_set); 250 } 251 252 void CollectedHeap::pre_initialize() { 253 // Used for ReduceInitialCardMarks (when COMPILER2 is used); 254 // otherwise remains unused. 255 #if defined(COMPILER2) || INCLUDE_JVMCI 256 _defer_initial_card_mark = is_server_compilation_mode_vm() && ReduceInitialCardMarks && can_elide_tlab_store_barriers() 257 && (DeferInitialCardMark || card_mark_must_follow_store()); 258 #else 259 assert(_defer_initial_card_mark == false, "Who would set it?"); 260 #endif 261 } 262 263 #ifndef PRODUCT 264 void CollectedHeap::check_for_bad_heap_word_value(HeapWord* addr, size_t size) { 265 if (CheckMemoryInitialization && ZapUnusedHeapArea) { 266 for (size_t slot = 0; slot < size; slot += 1) { 267 assert((*(intptr_t*) (addr + slot)) != ((intptr_t) badHeapWordVal), 268 "Found badHeapWordValue in post-allocation check"); 269 } 270 } 271 } 272 273 void CollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, size_t size) { 274 if (CheckMemoryInitialization && ZapUnusedHeapArea) { 275 for (size_t slot = 0; slot < size; slot += 1) { 276 assert((*(intptr_t*) (addr + slot)) == ((intptr_t) badHeapWordVal), 277 "Found non badHeapWordValue in pre-allocation check"); 278 } 279 } 280 } 281 #endif // PRODUCT 282 283 #ifdef ASSERT 284 void CollectedHeap::check_for_valid_allocation_state() { 285 Thread *thread = Thread::current(); 286 // How to choose between a pending exception and a potential 287 // OutOfMemoryError? Don't allow pending exceptions. 288 // This is a VM policy failure, so how do we exhaustively test it? 289 assert(!thread->has_pending_exception(), 290 "shouldn't be allocating with pending exception"); 291 if (StrictSafepointChecks) { 292 assert(thread->allow_allocation(), 293 "Allocation done by thread for which allocation is blocked " 294 "by No_Allocation_Verifier!"); 295 // Allocation of an oop can always invoke a safepoint, 296 // hence, the true argument 297 thread->check_for_valid_safepoint_state(true); 298 } 299 } 300 #endif 301 302 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) { 303 304 // Retain tlab and allocate object in shared space if 305 // the amount free in the tlab is too large to discard. 306 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) { 307 thread->tlab().record_slow_allocation(size); 308 return NULL; 309 } 310 311 // Discard tlab and allocate a new one. 312 // To minimize fragmentation, the last TLAB may be smaller than the rest. 313 size_t new_tlab_size = thread->tlab().compute_size(size); 314 315 thread->tlab().clear_before_allocation(); 316 317 if (new_tlab_size == 0) { 318 return NULL; 319 } 320 321 // Allocate a new TLAB... 322 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size); 323 if (obj == NULL) { 324 return NULL; 325 } 326 327 AllocTracer::send_allocation_in_new_tlab_event(klass, new_tlab_size * HeapWordSize, size * HeapWordSize); 328 329 if (ZeroTLAB) { 330 // ..and clear it. 331 Copy::zero_to_words(obj, new_tlab_size); 332 } else { 333 // ...and zap just allocated object. 334 #ifdef ASSERT 335 // Skip mangling the space corresponding to the object header to 336 // ensure that the returned space is not considered parsable by 337 // any concurrent GC thread. 338 size_t hdr_size = oopDesc::header_size(); 339 Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal); 340 #endif // ASSERT 341 } 342 thread->tlab().fill(obj, obj + size, new_tlab_size); 343 return obj; 344 } 345 346 void CollectedHeap::flush_deferred_store_barrier(JavaThread* thread) { 347 MemRegion deferred = thread->deferred_card_mark(); 348 if (!deferred.is_empty()) { 349 assert(_defer_initial_card_mark, "Otherwise should be empty"); 350 { 351 // Verify that the storage points to a parsable object in heap 352 DEBUG_ONLY(oop old_obj = oop(deferred.start());) 353 assert(is_in(old_obj), "Not in allocated heap"); 354 assert(!can_elide_initializing_store_barrier(old_obj), 355 "Else should have been filtered in new_store_pre_barrier()"); 356 assert(old_obj->is_oop(true), "Not an oop"); 357 assert(deferred.word_size() == (size_t)(old_obj->size()), 358 "Mismatch: multiple objects?"); 359 } 360 BarrierSet* bs = barrier_set(); 361 assert(bs->has_write_region_opt(), "No write_region() on BarrierSet"); 362 bs->write_region(deferred); 363 // "Clear" the deferred_card_mark field 364 thread->set_deferred_card_mark(MemRegion()); 365 } 366 assert(thread->deferred_card_mark().is_empty(), "invariant"); 367 } 368 369 size_t CollectedHeap::max_tlab_size() const { 370 // TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE]. 371 // This restriction could be removed by enabling filling with multiple arrays. 372 // If we compute that the reasonable way as 373 // header_size + ((sizeof(jint) * max_jint) / HeapWordSize) 374 // we'll overflow on the multiply, so we do the divide first. 375 // We actually lose a little by dividing first, 376 // but that just makes the TLAB somewhat smaller than the biggest array, 377 // which is fine, since we'll be able to fill that. 378 size_t max_int_size = typeArrayOopDesc::header_size(T_INT) + 379 sizeof(jint) * 380 ((juint) max_jint / (size_t) HeapWordSize); 381 return align_down(max_int_size, MinObjAlignment); 382 } 383 384 // Helper for ReduceInitialCardMarks. For performance, 385 // compiled code may elide card-marks for initializing stores 386 // to a newly allocated object along the fast-path. We 387 // compensate for such elided card-marks as follows: 388 // (a) Generational, non-concurrent collectors, such as 389 // GenCollectedHeap(ParNew,DefNew,Tenured) and 390 // ParallelScavengeHeap(ParallelGC, ParallelOldGC) 391 // need the card-mark if and only if the region is 392 // in the old gen, and do not care if the card-mark 393 // succeeds or precedes the initializing stores themselves, 394 // so long as the card-mark is completed before the next 395 // scavenge. For all these cases, we can do a card mark 396 // at the point at which we do a slow path allocation 397 // in the old gen, i.e. in this call. 398 // (b) GenCollectedHeap(ConcurrentMarkSweepGeneration) requires 399 // in addition that the card-mark for an old gen allocated 400 // object strictly follow any associated initializing stores. 401 // In these cases, the memRegion remembered below is 402 // used to card-mark the entire region either just before the next 403 // slow-path allocation by this thread or just before the next scavenge or 404 // CMS-associated safepoint, whichever of these events happens first. 405 // (The implicit assumption is that the object has been fully 406 // initialized by this point, a fact that we assert when doing the 407 // card-mark.) 408 // (c) G1CollectedHeap(G1) uses two kinds of write barriers. When a 409 // G1 concurrent marking is in progress an SATB (pre-write-)barrier 410 // is used to remember the pre-value of any store. Initializing 411 // stores will not need this barrier, so we need not worry about 412 // compensating for the missing pre-barrier here. Turning now 413 // to the post-barrier, we note that G1 needs a RS update barrier 414 // which simply enqueues a (sequence of) dirty cards which may 415 // optionally be refined by the concurrent update threads. Note 416 // that this barrier need only be applied to a non-young write, 417 // but, like in CMS, because of the presence of concurrent refinement 418 // (much like CMS' precleaning), must strictly follow the oop-store. 419 // Thus, using the same protocol for maintaining the intended 420 // invariants turns out, serendepitously, to be the same for both 421 // G1 and CMS. 422 // 423 // For any future collector, this code should be reexamined with 424 // that specific collector in mind, and the documentation above suitably 425 // extended and updated. 426 oop CollectedHeap::new_store_pre_barrier(JavaThread* thread, oop new_obj) { 427 // If a previous card-mark was deferred, flush it now. 428 flush_deferred_store_barrier(thread); 429 if (can_elide_initializing_store_barrier(new_obj) || 430 new_obj->is_typeArray()) { 431 // Arrays of non-references don't need a pre-barrier. 432 // The deferred_card_mark region should be empty 433 // following the flush above. 434 assert(thread->deferred_card_mark().is_empty(), "Error"); 435 } else { 436 MemRegion mr((HeapWord*)new_obj, new_obj->size()); 437 assert(!mr.is_empty(), "Error"); 438 if (_defer_initial_card_mark) { 439 // Defer the card mark 440 thread->set_deferred_card_mark(mr); 441 } else { 442 // Do the card mark 443 BarrierSet* bs = barrier_set(); 444 assert(bs->has_write_region_opt(), "No write_region() on BarrierSet"); 445 bs->write_region(mr); 446 } 447 } 448 return new_obj; 449 } 450 451 size_t CollectedHeap::filler_array_hdr_size() { 452 return align_object_offset(arrayOopDesc::header_size(T_INT)); // align to Long 453 } 454 455 size_t CollectedHeap::filler_array_min_size() { 456 return align_object_size(filler_array_hdr_size()); // align to MinObjAlignment 457 } 458 459 #ifdef ASSERT 460 void CollectedHeap::fill_args_check(HeapWord* start, size_t words) 461 { 462 assert(words >= min_fill_size(), "too small to fill"); 463 assert(words % MinObjAlignment == 0, "unaligned size"); 464 assert(Universe::heap()->is_in_reserved(start), "not in heap"); 465 assert(Universe::heap()->is_in_reserved(start + words - 1), "not in heap"); 466 } 467 468 void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap) 469 { 470 if (ZapFillerObjects && zap) { 471 Copy::fill_to_words(start + filler_array_hdr_size(), 472 words - filler_array_hdr_size(), 0XDEAFBABE); 473 } 474 } 475 #endif // ASSERT 476 477 void 478 CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap) 479 { 480 assert(words >= filler_array_min_size(), "too small for an array"); 481 assert(words <= filler_array_max_size(), "too big for a single object"); 482 483 const size_t payload_size = words - filler_array_hdr_size(); 484 const size_t len = payload_size * HeapWordSize / sizeof(jint); 485 assert((int)len >= 0, "size too large " SIZE_FORMAT " becomes %d", words, (int)len); 486 487 // Set the length first for concurrent GC. 488 ((arrayOop)start)->set_length((int)len); 489 post_allocation_setup_common(Universe::intArrayKlassObj(), start); 490 DEBUG_ONLY(zap_filler_array(start, words, zap);) 491 } 492 493 void 494 CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap) 495 { 496 assert(words <= filler_array_max_size(), "too big for a single object"); 497 498 if (words >= filler_array_min_size()) { 499 fill_with_array(start, words, zap); 500 } else if (words > 0) { 501 assert(words == min_fill_size(), "unaligned size"); 502 post_allocation_setup_common(SystemDictionary::Object_klass(), start); 503 } 504 } 505 506 void CollectedHeap::fill_with_object(HeapWord* start, size_t words, bool zap) 507 { 508 DEBUG_ONLY(fill_args_check(start, words);) 509 HandleMark hm; // Free handles before leaving. 510 fill_with_object_impl(start, words, zap); 511 } 512 513 void CollectedHeap::fill_with_objects(HeapWord* start, size_t words, bool zap) 514 { 515 DEBUG_ONLY(fill_args_check(start, words);) 516 HandleMark hm; // Free handles before leaving. 517 518 // Multiple objects may be required depending on the filler array maximum size. Fill 519 // the range up to that with objects that are filler_array_max_size sized. The 520 // remainder is filled with a single object. 521 const size_t min = min_fill_size(); 522 const size_t max = filler_array_max_size(); 523 while (words > max) { 524 const size_t cur = (words - max) >= min ? max : max - min; 525 fill_with_array(start, cur, zap); 526 start += cur; 527 words -= cur; 528 } 529 530 fill_with_object_impl(start, words, zap); 531 } 532 533 HeapWord* CollectedHeap::allocate_new_tlab(size_t size) { 534 guarantee(false, "thread-local allocation buffers not supported"); 535 return NULL; 536 } 537 538 void CollectedHeap::ensure_parsability(bool retire_tlabs) { 539 // The second disjunct in the assertion below makes a concession 540 // for the start-up verification done while the VM is being 541 // created. Callers be careful that you know that mutators 542 // aren't going to interfere -- for instance, this is permissible 543 // if we are still single-threaded and have either not yet 544 // started allocating (nothing much to verify) or we have 545 // started allocating but are now a full-fledged JavaThread 546 // (and have thus made our TLAB's) available for filling. 547 assert(SafepointSynchronize::is_at_safepoint() || 548 !is_init_completed(), 549 "Should only be called at a safepoint or at start-up" 550 " otherwise concurrent mutator activity may make heap " 551 " unparsable again"); 552 const bool use_tlab = UseTLAB; 553 const bool deferred = _defer_initial_card_mark; 554 // The main thread starts allocating via a TLAB even before it 555 // has added itself to the threads list at vm boot-up. 556 assert(!use_tlab || Threads::first() != NULL, 557 "Attempt to fill tlabs before main thread has been added" 558 " to threads list is doomed to failure!"); 559 for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) { 560 if (use_tlab) thread->tlab().make_parsable(retire_tlabs); 561 #if defined(COMPILER2) || INCLUDE_JVMCI 562 // The deferred store barriers must all have been flushed to the 563 // card-table (or other remembered set structure) before GC starts 564 // processing the card-table (or other remembered set). 565 if (deferred) flush_deferred_store_barrier(thread); 566 #else 567 assert(!deferred, "Should be false"); 568 assert(thread->deferred_card_mark().is_empty(), "Should be empty"); 569 #endif 570 } 571 } 572 573 void CollectedHeap::accumulate_statistics_all_tlabs() { 574 if (UseTLAB) { 575 assert(SafepointSynchronize::is_at_safepoint() || 576 !is_init_completed(), 577 "should only accumulate statistics on tlabs at safepoint"); 578 579 ThreadLocalAllocBuffer::accumulate_statistics_before_gc(); 580 } 581 } 582 583 void CollectedHeap::resize_all_tlabs() { 584 if (UseTLAB) { 585 assert(SafepointSynchronize::is_at_safepoint() || 586 !is_init_completed(), 587 "should only resize tlabs at safepoint"); 588 589 ThreadLocalAllocBuffer::resize_all_tlabs(); 590 } 591 } 592 593 void CollectedHeap::full_gc_dump(GCTimer* timer, bool before) { 594 assert(timer != NULL, "timer is null"); 595 if ((HeapDumpBeforeFullGC && before) || (HeapDumpAfterFullGC && !before)) { 596 GCTraceTime(Info, gc) tm(before ? "Heap Dump (before full gc)" : "Heap Dump (after full gc)", timer); 597 HeapDumper::dump_heap(); 598 } 599 600 Log(gc, classhisto) log; 601 if (log.is_trace()) { 602 GCTraceTime(Trace, gc, classhisto) tm(before ? "Class Histogram (before full gc)" : "Class Histogram (after full gc)", timer); 603 ResourceMark rm; 604 VM_GC_HeapInspection inspector(log.trace_stream(), false /* ! full gc */); 605 inspector.doit(); 606 } 607 } 608 609 void CollectedHeap::pre_full_gc_dump(GCTimer* timer) { 610 full_gc_dump(timer, true); 611 } 612 613 void CollectedHeap::post_full_gc_dump(GCTimer* timer) { 614 full_gc_dump(timer, false); 615 } 616 617 void CollectedHeap::initialize_reserved_region(HeapWord *start, HeapWord *end) { 618 // It is important to do this in a way such that concurrent readers can't 619 // temporarily think something is in the heap. (Seen this happen in asserts.) 620 _reserved.set_word_size(0); 621 _reserved.set_start(start); 622 _reserved.set_end(end); 623 } 624 625 void CollectedHeap::verify_nmethod_roots(nmethod* nmethod) { 626 nmethod->verify_scavenge_root_oops(); 627 }