< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahController.cpp

Print this page

24  */
25 
26 #include "gc/shared/allocTracer.hpp"
27 #include "gc/shared/gc_globals.hpp"
28 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
29 #include "gc/shenandoah/shenandoahController.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
32 
33 void ShenandoahController::update_gc_id() {
34   _gc_id.add_then_fetch((size_t)1);
35 }
36 
37 size_t ShenandoahController::get_gc_id() {
38   return _gc_id.load_relaxed();
39 }
40 
41 void ShenandoahController::handle_alloc_failure(const ShenandoahAllocRequest& req, bool block) {
42   assert(current()->is_Java_thread(), "expect Java thread here");
43 
44   const bool is_humongous = ShenandoahHeapRegion::requires_humongous(req.size());




45   const GCCause::Cause cause = is_humongous ? GCCause::_shenandoah_humongous_allocation_failure : GCCause::_allocation_failure;
46 
47   ShenandoahHeap* const heap = ShenandoahHeap::heap();
48   size_t req_byte = req.size() * HeapWordSize;
49   if (heap->cancel_gc(cause)) {
50     log_info(gc)("Failed to allocate %s, " PROPERFMT, req.type_string(), PROPERFMTARGS(req_byte));
51     request_gc(cause);
52   }
53   AllocTracer::send_allocation_requiring_gc_event(req_byte, checked_cast<uint>(get_gc_id()));
54 
55   if (block) {
56     MonitorLocker ml(&_alloc_failure_waiters_lock);
57     while (!should_terminate() && ShenandoahCollectorPolicy::is_allocation_failure(heap->cancelled_cause())) {
58       ml.wait();
59     }
60   }
61 }
62 
63 void ShenandoahController::handle_alloc_failure_evac(size_t words) {
64 
65   ShenandoahHeap* const heap = ShenandoahHeap::heap();
66   const bool is_humongous = ShenandoahHeapRegion::requires_humongous(words);
67   const GCCause::Cause cause = is_humongous ? GCCause::_shenandoah_humongous_allocation_failure : GCCause::_shenandoah_allocation_failure_evac;
68 
69   if (heap->cancel_gc(cause)) {
70     log_info(gc)("Failed to allocate " PROPERFMT " for evacuation", PROPERFMTARGS(words * HeapWordSize));
71   }
72 }
73 
74 void ShenandoahController::notify_alloc_failure_waiters() {
75   MonitorLocker ml(&_alloc_failure_waiters_lock);
76   ml.notify_all();
77 }

24  */
25 
26 #include "gc/shared/allocTracer.hpp"
27 #include "gc/shared/gc_globals.hpp"
28 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
29 #include "gc/shenandoah/shenandoahController.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
32 
33 void ShenandoahController::update_gc_id() {
34   _gc_id.add_then_fetch((size_t)1);
35 }
36 
37 size_t ShenandoahController::get_gc_id() {
38   return _gc_id.load_relaxed();
39 }
40 
41 void ShenandoahController::handle_alloc_failure(const ShenandoahAllocRequest& req, bool block) {
42   assert(current()->is_Java_thread(), "expect Java thread here");
43 
44   // Classify the failure consistently with how ShenandoahFreeSet::allocate would
45   // route this request: a fresh mutator object (_alloc_shared) may expand for an
46   // identity hash-code, every other request carries an already-final size.
47   const bool may_expand_for_hash = (req.type() == ShenandoahAllocRequest::_alloc_shared);
48   const bool is_humongous = ShenandoahHeapRegion::requires_humongous(req.size(), may_expand_for_hash);
49   const GCCause::Cause cause = is_humongous ? GCCause::_shenandoah_humongous_allocation_failure : GCCause::_allocation_failure;
50 
51   ShenandoahHeap* const heap = ShenandoahHeap::heap();
52   size_t req_byte = req.size() * HeapWordSize;
53   if (heap->cancel_gc(cause)) {
54     log_info(gc)("Failed to allocate %s, " PROPERFMT, req.type_string(), PROPERFMTARGS(req_byte));
55     request_gc(cause);
56   }
57   AllocTracer::send_allocation_requiring_gc_event(req_byte, checked_cast<uint>(get_gc_id()));
58 
59   if (block) {
60     MonitorLocker ml(&_alloc_failure_waiters_lock);
61     while (!should_terminate() && ShenandoahCollectorPolicy::is_allocation_failure(heap->cancelled_cause())) {
62       ml.wait();
63     }
64   }
65 }
66 
67 void ShenandoahController::handle_alloc_failure_evac(size_t words) {
68 
69   ShenandoahHeap* const heap = ShenandoahHeap::heap();
70   const bool is_humongous = ShenandoahHeapRegion::requires_humongous(words, false /* may_expand_for_hash */);
71   const GCCause::Cause cause = is_humongous ? GCCause::_shenandoah_humongous_allocation_failure : GCCause::_shenandoah_allocation_failure_evac;
72 
73   if (heap->cancel_gc(cause)) {
74     log_info(gc)("Failed to allocate " PROPERFMT " for evacuation", PROPERFMTARGS(words * HeapWordSize));
75   }
76 }
77 
78 void ShenandoahController::notify_alloc_failure_waiters() {
79   MonitorLocker ml(&_alloc_failure_waiters_lock);
80   ml.notify_all();
81 }
< prev index next >