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