--- a/src/hotspot/share/gc/z/zDriver.cpp Fri Jun 15 13:31:20 2018 +0200
+++ b/src/hotspot/share/gc/z/zDriver.cpp Fri Jun 15 13:31:27 2018 +0200
@@ -126,6 +126,26 @@
}
};
+static bool should_clear_soft_references() {
+ // Clear if one or more allocations have stalled
+ const bool stalled = ZHeap::heap()->is_alloc_stalled();
+ if (stalled) {
+ // Clear
+ return true;
+ }
+
+ // Clear if implied by the GC cause
+ const GCCause::Cause cause = ZCollectedHeap::heap()->gc_cause();
+ if (cause == GCCause::_wb_full_gc ||
+ cause == GCCause::_metadata_GC_clear_soft_refs) {
+ // Clear
+ return true;
+ }
+
+ // Don't clear
+ return false;
+}
+
class ZMarkStartClosure : public ZOperationClosure {
public:
virtual const char* name() const {
@@ -140,6 +160,10 @@
ZStatTimer timer(ZPhasePauseMarkStart);
ZServiceabilityMarkStartTracer tracer;
+ // Setup soft reference policy
+ const bool clear = should_clear_soft_references();
+ ZHeap::heap()->set_soft_reference_policy(clear);
+
ZCollectedHeap::heap()->increment_total_collections(true /* full */);
ZHeap::heap()->mark_start();
@@ -247,40 +271,11 @@
return _gc_cycle_port.receive();
}
-class ZSoftReferencePolicyScope : public StackObj {
-private:
- bool should_clear_soft_reference(GCCause::Cause cause) const {
- const bool clear = ZCollectedHeap::heap()->soft_ref_policy()->should_clear_all_soft_refs();
-
- // Clear all soft reference if the policy says so, or if
- // the GC cause indicates that we're running low on memory.
- return clear ||
- cause == GCCause::_z_allocation_stall ||
- cause == GCCause::_metadata_GC_clear_soft_refs;
- }
-
- void clear_should_clear_soft_reference() const {
- ZCollectedHeap::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
- }
-
-public:
- ZSoftReferencePolicyScope(GCCause::Cause cause) {
- const bool clear = should_clear_soft_reference(cause);
- ZHeap::heap()->set_soft_reference_policy(clear);
- clear_should_clear_soft_reference();
- }
-
- ~ZSoftReferencePolicyScope() {
- Universe::update_heap_info_at_gc();
- }
-};
-
class ZDriverCycleScope : public StackObj {
private:
- GCIdMark _gc_id;
- GCCauseSetter _gc_cause_setter;
- ZSoftReferencePolicyScope _soft_ref_policy;
- ZStatTimer _timer;
+ GCIdMark _gc_id;
+ GCCauseSetter _gc_cause_setter;
+ ZStatTimer _timer;
bool should_boost_worker_threads(GCCause::Cause cause) const {
return cause == GCCause::_java_lang_system_gc ||
@@ -291,7 +286,6 @@
ZDriverCycleScope(GCCause::Cause cause) :
_gc_id(),
_gc_cause_setter(ZCollectedHeap::heap(), cause),
- _soft_ref_policy(cause),
_timer(ZPhaseCycle) {
// Update statistics
ZStatCycle::at_start();
@@ -308,6 +302,9 @@
// Update statistics
ZStatCycle::at_end(boost_factor);
+
+ // Update data used by soft reference policy
+ Universe::update_heap_info_at_gc();
}
};