1 /*
  2  * Copyright (c) 2001, 2023, 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/classLoaderData.hpp"
 27 #include "classfile/vmClasses.hpp"
 28 #include "gc/shared/allocTracer.hpp"
 29 #include "gc/shared/barrierSet.hpp"
 30 #include "gc/shared/collectedHeap.hpp"
 31 #include "gc/shared/collectedHeap.inline.hpp"
 32 #include "gc/shared/gcLocker.inline.hpp"
 33 #include "gc/shared/gcHeapSummary.hpp"
 34 #include "gc/shared/stringdedup/stringDedup.hpp"
 35 #include "gc/shared/gcTrace.hpp"
 36 #include "gc/shared/gcTraceTime.inline.hpp"
 37 #include "gc/shared/gcVMOperations.hpp"
 38 #include "gc/shared/gcWhen.hpp"
 39 #include "gc/shared/gc_globals.hpp"
 40 #include "gc/shared/memAllocator.hpp"
 41 #include "gc/shared/tlab_globals.hpp"
 42 #include "logging/log.hpp"
 43 #include "logging/logStream.hpp"
 44 #include "memory/classLoaderMetaspace.hpp"
 45 #include "memory/metaspace.hpp"
 46 #include "memory/metaspaceUtils.hpp"
 47 #include "memory/resourceArea.hpp"
 48 #include "memory/universe.hpp"
 49 #include "oops/instanceMirrorKlass.hpp"
 50 #include "oops/oop.inline.hpp"
 51 #include "runtime/handles.inline.hpp"
 52 #include "runtime/init.hpp"
 53 #include "runtime/javaThread.hpp"
 54 #include "runtime/perfData.hpp"
 55 #include "runtime/threadSMR.hpp"
 56 #include "runtime/vmThread.hpp"
 57 #include "services/heapDumper.hpp"
 58 #include "utilities/align.hpp"
 59 #include "utilities/copy.hpp"
 60 #include "utilities/events.hpp"
 61 
 62 class ClassLoaderData;
 63 
 64 size_t CollectedHeap::_lab_alignment_reserve = SIZE_MAX;
 65 Klass* CollectedHeap::_filler_object_klass = nullptr;
 66 size_t CollectedHeap::_filler_array_max_size = 0;
 67 size_t CollectedHeap::_stack_chunk_max_size = 0;
 68 
 69 class GCMessage : public FormatBuffer<1024> {
 70  public:
 71   bool is_before;
 72 };
 73 
 74 template <>
 75 void EventLogBase<GCMessage>::print(outputStream* st, GCMessage& m) {
 76   st->print_cr("GC heap %s", m.is_before ? "before" : "after");
 77   st->print_raw(m);
 78 }
 79 
 80 class GCHeapLog : public EventLogBase<GCMessage> {
 81  private:
 82   void log_heap(CollectedHeap* heap, bool before);
 83 
 84  public:
 85   GCHeapLog() : EventLogBase<GCMessage>("GC Heap History", "gc") {}
 86 
 87   void log_heap_before(CollectedHeap* heap) {
 88     log_heap(heap, true);
 89   }
 90   void log_heap_after(CollectedHeap* heap) {
 91     log_heap(heap, false);
 92   }
 93 };
 94 
 95 void GCHeapLog::log_heap(CollectedHeap* heap, bool before) {
 96   if (!should_log()) {
 97     return;
 98   }
 99 
100   double timestamp = fetch_timestamp();
101   MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
102   int index = compute_log_index();
103   _records[index].thread = nullptr; // Its the GC thread so it's not that interesting.
104   _records[index].timestamp = timestamp;
105   _records[index].data.is_before = before;
106   stringStream st(_records[index].data.buffer(), _records[index].data.size());
107 
108   st.print_cr("{Heap %s GC invocations=%u (full %u):",
109                  before ? "before" : "after",
110                  heap->total_collections(),
111                  heap->total_full_collections());
112 
113   heap->print_on(&st);
114   st.print_cr("}");
115 }
116 
117 ParallelObjectIterator::ParallelObjectIterator(uint thread_num) :
118   _impl(Universe::heap()->parallel_object_iterator(thread_num))
119 {}
120 
121 ParallelObjectIterator::~ParallelObjectIterator() {
122   delete _impl;
123 }
124 
125 void ParallelObjectIterator::object_iterate(ObjectClosure* cl, uint worker_id) {
126   _impl->object_iterate(cl, worker_id);
127 }
128 
129 size_t CollectedHeap::unused() const {
130   MutexLocker ml(Heap_lock);
131   return capacity() - used();
132 }
133 
134 VirtualSpaceSummary CollectedHeap::create_heap_space_summary() {
135   size_t capacity_in_words = capacity() / HeapWordSize;
136 
137   return VirtualSpaceSummary(
138     _reserved.start(), _reserved.start() + capacity_in_words, _reserved.end());
139 }
140 
141 GCHeapSummary CollectedHeap::create_heap_summary() {
142   VirtualSpaceSummary heap_space = create_heap_space_summary();
143   return GCHeapSummary(heap_space, used());
144 }
145 
146 MetaspaceSummary CollectedHeap::create_metaspace_summary() {
147   const MetaspaceChunkFreeListSummary& ms_chunk_free_list_summary =
148     MetaspaceUtils::chunk_free_list_summary(Metaspace::NonClassType);
149   const MetaspaceChunkFreeListSummary& class_chunk_free_list_summary =
150     MetaspaceUtils::chunk_free_list_summary(Metaspace::ClassType);
151   return MetaspaceSummary(MetaspaceGC::capacity_until_GC(),
152                           MetaspaceUtils::get_combined_statistics(),
153                           ms_chunk_free_list_summary, class_chunk_free_list_summary);
154 }
155 
156 bool CollectedHeap::contains_null(const oop* p) const {
157   return *p == nullptr;
158 }
159 
160 void CollectedHeap::print_heap_before_gc() {
161   LogTarget(Debug, gc, heap) lt;
162   if (lt.is_enabled()) {
163     LogStream ls(lt);
164     ls.print_cr("Heap before GC invocations=%u (full %u):", total_collections(), total_full_collections());
165     ResourceMark rm;
166     print_on(&ls);
167   }
168 
169   if (_gc_heap_log != nullptr) {
170     _gc_heap_log->log_heap_before(this);
171   }
172 }
173 
174 void CollectedHeap::print_heap_after_gc() {
175   LogTarget(Debug, gc, heap) lt;
176   if (lt.is_enabled()) {
177     LogStream ls(lt);
178     ls.print_cr("Heap after GC invocations=%u (full %u):", total_collections(), total_full_collections());
179     ResourceMark rm;
180     print_on(&ls);
181   }
182 
183   if (_gc_heap_log != nullptr) {
184     _gc_heap_log->log_heap_after(this);
185   }
186 }
187 
188 void CollectedHeap::print() const { print_on(tty); }
189 
190 void CollectedHeap::print_on_error(outputStream* st) const {
191   st->print_cr("Heap:");
192   print_extended_on(st);
193   st->cr();
194 
195   BarrierSet* bs = BarrierSet::barrier_set();
196   if (bs != nullptr) {
197     bs->print_on(st);
198   }
199 }
200 
201 void CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
202   const GCHeapSummary& heap_summary = create_heap_summary();
203   gc_tracer->report_gc_heap_summary(when, heap_summary);
204 
205   const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
206   gc_tracer->report_metaspace_summary(when, metaspace_summary);
207 }
208 
209 void CollectedHeap::trace_heap_before_gc(const GCTracer* gc_tracer) {
210   trace_heap(GCWhen::BeforeGC, gc_tracer);
211 }
212 
213 void CollectedHeap::trace_heap_after_gc(const GCTracer* gc_tracer) {
214   trace_heap(GCWhen::AfterGC, gc_tracer);
215 }
216 
217 // Default implementation, for collectors that don't support the feature.
218 bool CollectedHeap::supports_concurrent_gc_breakpoints() const {
219   return false;
220 }
221 
222 bool CollectedHeap::is_oop(oop object) const {
223   if (!is_object_aligned(object)) {
224     return false;
225   }
226 
227   if (!is_in(object)) {
228     return false;
229   }
230 
231   // With compact headers, we can't safely access the class, due
232   // to possibly forwarded objects.
233   if (!UseCompactObjectHeaders && !Metaspace::contains(object->klass_raw())) {
234     return false;
235   }
236 
237   return true;
238 }
239 
240 // Memory state functions.
241 
242 
243 CollectedHeap::CollectedHeap() :
244   _capacity_at_last_gc(0),
245   _used_at_last_gc(0),
246   _is_stw_gc_active(false),
247   _last_whole_heap_examined_time_ns(os::javaTimeNanos()),
248   _total_collections(0),
249   _total_full_collections(0),
250   _gc_cause(GCCause::_no_gc),
251   _gc_lastcause(GCCause::_no_gc)
252 {
253   // If the minimum object size is greater than MinObjAlignment, we can
254   // end up with a shard at the end of the buffer that's smaller than
255   // the smallest object.  We can't allow that because the buffer must
256   // look like it's full of objects when we retire it, so we make
257   // sure we have enough space for a filler int array object.
258   size_t min_size = min_dummy_object_size();
259   _lab_alignment_reserve = min_size > (size_t)MinObjAlignment ? align_object_size(min_size) : 0;
260 
261   const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT));
262   const size_t elements_per_word = HeapWordSize / sizeof(jint);
263   _filler_array_max_size = align_object_size(filler_array_hdr_size() +
264                                              max_len / elements_per_word);
265 
266   NOT_PRODUCT(_promotion_failure_alot_count = 0;)
267   NOT_PRODUCT(_promotion_failure_alot_gc_number = 0;)
268 
269   if (UsePerfData) {
270     EXCEPTION_MARK;
271 
272     // create the gc cause jvmstat counters
273     _perf_gc_cause = PerfDataManager::create_string_variable(SUN_GC, "cause",
274                              80, GCCause::to_string(_gc_cause), CHECK);
275 
276     _perf_gc_lastcause =
277                 PerfDataManager::create_string_variable(SUN_GC, "lastCause",
278                              80, GCCause::to_string(_gc_lastcause), CHECK);
279   }
280 
281   // Create the ring log
282   if (LogEvents) {
283     _gc_heap_log = new GCHeapLog();
284   } else {
285     _gc_heap_log = nullptr;
286   }
287 }
288 
289 // This interface assumes that it's being called by the
290 // vm thread. It collects the heap assuming that the
291 // heap lock is already held and that we are executing in
292 // the context of the vm thread.
293 void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) {
294   Thread* thread = Thread::current();
295   assert(thread->is_VM_thread(), "Precondition#1");
296   assert(Heap_lock->is_locked(), "Precondition#2");
297   GCCauseSetter gcs(this, cause);
298   switch (cause) {
299     case GCCause::_codecache_GC_threshold:
300     case GCCause::_codecache_GC_aggressive:
301     case GCCause::_heap_inspection:
302     case GCCause::_heap_dump:
303     case GCCause::_metadata_GC_threshold: {
304       HandleMark hm(thread);
305       do_full_collection(false);        // don't clear all soft refs
306       break;
307     }
308     case GCCause::_metadata_GC_clear_soft_refs: {
309       HandleMark hm(thread);
310       do_full_collection(true);         // do clear all soft refs
311       break;
312     }
313     default:
314       ShouldNotReachHere(); // Unexpected use of this function
315   }
316 }
317 
318 MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
319                                                             size_t word_size,
320                                                             Metaspace::MetadataType mdtype) {
321   uint loop_count = 0;
322   uint gc_count = 0;
323   uint full_gc_count = 0;
324 
325   assert(!Heap_lock->owned_by_self(), "Should not be holding the Heap_lock");
326 
327   do {
328     MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
329     if (result != nullptr) {
330       return result;
331     }
332 
333     if (GCLocker::is_active_and_needs_gc()) {
334       // If the GCLocker is active, just expand and allocate.
335       // If that does not succeed, wait if this thread is not
336       // in a critical section itself.
337       result = loader_data->metaspace_non_null()->expand_and_allocate(word_size, mdtype);
338       if (result != nullptr) {
339         return result;
340       }
341       JavaThread* jthr = JavaThread::current();
342       if (!jthr->in_critical()) {
343         // Wait for JNI critical section to be exited
344         GCLocker::stall_until_clear();
345         // The GC invoked by the last thread leaving the critical
346         // section will be a young collection and a full collection
347         // is (currently) needed for unloading classes so continue
348         // to the next iteration to get a full GC.
349         continue;
350       } else {
351         if (CheckJNICalls) {
352           fatal("Possible deadlock due to allocating while"
353                 " in jni critical section");
354         }
355         return nullptr;
356       }
357     }
358 
359     {  // Need lock to get self consistent gc_count's
360       MutexLocker ml(Heap_lock);
361       gc_count      = Universe::heap()->total_collections();
362       full_gc_count = Universe::heap()->total_full_collections();
363     }
364 
365     // Generate a VM operation
366     VM_CollectForMetadataAllocation op(loader_data,
367                                        word_size,
368                                        mdtype,
369                                        gc_count,
370                                        full_gc_count,
371                                        GCCause::_metadata_GC_threshold);
372     VMThread::execute(&op);
373 
374     // If GC was locked out, try again. Check before checking success because the
375     // prologue could have succeeded and the GC still have been locked out.
376     if (op.gc_locked()) {
377       continue;
378     }
379 
380     if (op.prologue_succeeded()) {
381       return op.result();
382     }
383     loop_count++;
384     if ((QueuedAllocationWarningCount > 0) &&
385         (loop_count % QueuedAllocationWarningCount == 0)) {
386       log_warning(gc, ergo)("satisfy_failed_metadata_allocation() retries %d times,"
387                             " size=" SIZE_FORMAT, loop_count, word_size);
388     }
389   } while (true);  // Until a GC is done
390 }
391 
392 MemoryUsage CollectedHeap::memory_usage() {
393   return MemoryUsage(InitialHeapSize, used(), capacity(), max_capacity());
394 }
395 
396 void CollectedHeap::set_gc_cause(GCCause::Cause v) {
397   if (UsePerfData) {
398     _gc_lastcause = _gc_cause;
399     _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
400     _perf_gc_cause->set_value(GCCause::to_string(v));
401   }
402   _gc_cause = v;
403 }
404 
405 // Returns the header size in words aligned to the requirements of the
406 // array object type.
407 static int int_array_header_size() {
408   size_t typesize_in_bytes = arrayOopDesc::header_size_in_bytes();
409   return (int)align_up(typesize_in_bytes, HeapWordSize)/HeapWordSize;
410 }
411 
412 size_t CollectedHeap::max_tlab_size() const {
413   // TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE].
414   // This restriction could be removed by enabling filling with multiple arrays.
415   // If we compute that the reasonable way as
416   //    header_size + ((sizeof(jint) * max_jint) / HeapWordSize)
417   // we'll overflow on the multiply, so we do the divide first.
418   // We actually lose a little by dividing first,
419   // but that just makes the TLAB  somewhat smaller than the biggest array,
420   // which is fine, since we'll be able to fill that.
421   size_t max_int_size = int_array_header_size() +
422               sizeof(jint) *
423               ((juint) max_jint / (size_t) HeapWordSize);
424   return align_down(max_int_size, MinObjAlignment);
425 }
426 
427 size_t CollectedHeap::filler_array_hdr_size() {
428   return align_object_offset(int_array_header_size()); // align to Long
429 }
430 
431 size_t CollectedHeap::filler_array_min_size() {
432   return align_object_size(filler_array_hdr_size()); // align to MinObjAlignment
433 }
434 
435 void CollectedHeap::zap_filler_array_with(HeapWord* start, size_t words, juint value) {
436   Copy::fill_to_words(start + filler_array_hdr_size(),
437                       words - filler_array_hdr_size(), value);
438 }
439 
440 #ifdef ASSERT
441 void CollectedHeap::fill_args_check(HeapWord* start, size_t words)
442 {
443   assert(words >= min_fill_size(), "too small to fill");
444   assert(is_object_aligned(words), "unaligned size");
445 }
446 
447 void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap)
448 {
449   if (ZapFillerObjects && zap) {
450     zap_filler_array_with(start, words, 0XDEAFBABE);
451   }
452 }
453 #endif // ASSERT
454 
455 void
456 CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap)
457 {
458   assert(words >= filler_array_min_size(), "too small for an array");
459   assert(words <= filler_array_max_size(), "too big for a single object");
460 
461   const size_t payload_size = words - filler_array_hdr_size();
462   const size_t len = payload_size * HeapWordSize / sizeof(jint);
463   assert((int)len >= 0, "size too large " SIZE_FORMAT " becomes %d", words, (int)len);
464 
465   ObjArrayAllocator allocator(Universe::fillerArrayKlassObj(), words, (int)len, /* do_zero */ false);
466   allocator.initialize(start);
467   if (DumpSharedSpaces) {
468     // This array is written into the CDS archive. Make sure it
469     // has deterministic contents.
470     zap_filler_array_with(start, words, 0);
471   } else {
472     DEBUG_ONLY(zap_filler_array(start, words, zap);)
473   }
474 }
475 
476 void
477 CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap)
478 {
479   assert(words <= filler_array_max_size(), "too big for a single object");
480 
481   if (words >= filler_array_min_size()) {
482     fill_with_array(start, words, zap);
483   } else if (words > 0) {
484     assert(words == min_fill_size(), "unaligned size");
485     ObjAllocator allocator(CollectedHeap::filler_object_klass(), words);
486     allocator.initialize(start);
487   }
488 }
489 
490 void CollectedHeap::fill_with_object(HeapWord* start, size_t words, bool zap)
491 {
492   DEBUG_ONLY(fill_args_check(start, words);)
493   HandleMark hm(Thread::current());  // Free handles before leaving.
494   fill_with_object_impl(start, words, zap);
495 }
496 
497 void CollectedHeap::fill_with_objects(HeapWord* start, size_t words, bool zap)
498 {
499   DEBUG_ONLY(fill_args_check(start, words);)
500   HandleMark hm(Thread::current());  // Free handles before leaving.
501 
502   // Multiple objects may be required depending on the filler array maximum size. Fill
503   // the range up to that with objects that are filler_array_max_size sized. The
504   // remainder is filled with a single object.
505   const size_t min = min_fill_size();
506   const size_t max = filler_array_max_size();
507   while (words > max) {
508     const size_t cur = (words - max) >= min ? max : max - min;
509     fill_with_array(start, cur, zap);
510     start += cur;
511     words -= cur;
512   }
513 
514   fill_with_object_impl(start, words, zap);
515 }
516 
517 void CollectedHeap::fill_with_dummy_object(HeapWord* start, HeapWord* end, bool zap) {
518   CollectedHeap::fill_with_object(start, end, zap);
519 }
520 
521 HeapWord* CollectedHeap::allocate_new_tlab(size_t min_size,
522                                            size_t requested_size,
523                                            size_t* actual_size) {
524   guarantee(false, "thread-local allocation buffers not supported");
525   return nullptr;
526 }
527 
528 void CollectedHeap::ensure_parsability(bool retire_tlabs) {
529   assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(),
530          "Should only be called at a safepoint or at start-up");
531 
532   ThreadLocalAllocStats stats;
533 
534   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next();) {
535     BarrierSet::barrier_set()->make_parsable(thread);
536     if (UseTLAB) {
537       if (retire_tlabs) {
538         thread->tlab().retire(&stats);
539       } else {
540         thread->tlab().make_parsable();
541       }
542     }
543   }
544 
545   stats.publish();
546 }
547 
548 void CollectedHeap::resize_all_tlabs() {
549   assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(),
550          "Should only resize tlabs at safepoint");
551 
552   if (UseTLAB && ResizeTLAB) {
553     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
554       thread->tlab().resize();
555     }
556   }
557 }
558 
559 jlong CollectedHeap::millis_since_last_whole_heap_examined() {
560   return (os::javaTimeNanos() - _last_whole_heap_examined_time_ns) / NANOSECS_PER_MILLISEC;
561 }
562 
563 void CollectedHeap::record_whole_heap_examined_timestamp() {
564   _last_whole_heap_examined_time_ns = os::javaTimeNanos();
565 }
566 
567 void CollectedHeap::full_gc_dump(GCTimer* timer, bool before) {
568   assert(timer != nullptr, "timer is null");
569   if ((HeapDumpBeforeFullGC && before) || (HeapDumpAfterFullGC && !before)) {
570     GCTraceTime(Info, gc) tm(before ? "Heap Dump (before full gc)" : "Heap Dump (after full gc)", timer);
571     HeapDumper::dump_heap();
572   }
573 
574   LogTarget(Trace, gc, classhisto) lt;
575   if (lt.is_enabled()) {
576     GCTraceTime(Trace, gc, classhisto) tm(before ? "Class Histogram (before full gc)" : "Class Histogram (after full gc)", timer);
577     ResourceMark rm;
578     LogStream ls(lt);
579     VM_GC_HeapInspection inspector(&ls, false /* ! full gc */);
580     inspector.doit();
581   }
582 }
583 
584 void CollectedHeap::pre_full_gc_dump(GCTimer* timer) {
585   full_gc_dump(timer, true);
586 }
587 
588 void CollectedHeap::post_full_gc_dump(GCTimer* timer) {
589   full_gc_dump(timer, false);
590 }
591 
592 void CollectedHeap::initialize_reserved_region(const ReservedHeapSpace& rs) {
593   // It is important to do this in a way such that concurrent readers can't
594   // temporarily think something is in the heap.  (Seen this happen in asserts.)
595   _reserved.set_word_size(0);
596   _reserved.set_start((HeapWord*)rs.base());
597   _reserved.set_end((HeapWord*)rs.end());
598 }
599 
600 void CollectedHeap::post_initialize() {
601   StringDedup::initialize();
602   initialize_serviceability();
603 }
604 
605 #ifndef PRODUCT
606 
607 bool CollectedHeap::promotion_should_fail(volatile size_t* count) {
608   // Access to count is not atomic; the value does not have to be exact.
609   if (PromotionFailureALot) {
610     const size_t gc_num = total_collections();
611     const size_t elapsed_gcs = gc_num - _promotion_failure_alot_gc_number;
612     if (elapsed_gcs >= PromotionFailureALotInterval) {
613       // Test for unsigned arithmetic wrap-around.
614       if (++*count >= PromotionFailureALotCount) {
615         *count = 0;
616         return true;
617       }
618     }
619   }
620   return false;
621 }
622 
623 bool CollectedHeap::promotion_should_fail() {
624   return promotion_should_fail(&_promotion_failure_alot_count);
625 }
626 
627 void CollectedHeap::reset_promotion_should_fail(volatile size_t* count) {
628   if (PromotionFailureALot) {
629     _promotion_failure_alot_gc_number = total_collections();
630     *count = 0;
631   }
632 }
633 
634 void CollectedHeap::reset_promotion_should_fail() {
635   reset_promotion_should_fail(&_promotion_failure_alot_count);
636 }
637 
638 #endif  // #ifndef PRODUCT
639 
640 // It's the caller's responsibility to ensure glitch-freedom
641 // (if required).
642 void CollectedHeap::update_capacity_and_used_at_gc() {
643   _capacity_at_last_gc = capacity();
644   _used_at_last_gc     = used();
645 }