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