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