8222182: ZGC: Use SoftMaxHeapSize to guide GC heuristics
authorpliden
Fri, 07 Jun 2019 11:19:34 +0200
changeset 55284 38006f020b94
parent 55283 4556dd808daa
child 55285 9a120214e732
8222182: ZGC: Use SoftMaxHeapSize to guide GC heuristics Reviewed-by: stefank, tschatzl
src/hotspot/share/gc/z/zDirector.cpp
src/hotspot/share/gc/z/zHeap.cpp
src/hotspot/share/gc/z/zHeap.hpp
src/hotspot/share/gc/z/zPageAllocator.cpp
src/hotspot/share/gc/z/zPageAllocator.hpp
--- a/src/hotspot/share/gc/z/zDirector.cpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/z/zDirector.cpp	Fri Jun 07 11:19:34 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -81,7 +81,7 @@
   // Perform GC if heap usage passes 10/20/30% and no other GC has been
   // performed yet. This allows us to get some early samples of the GC
   // duration, which is needed by the other rules.
-  const size_t max_capacity = ZHeap::heap()->current_max_capacity();
+  const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
   const size_t used = ZHeap::heap()->used();
   const double used_threshold_percent = (ZStatCycle::ncycles() + 1) * 0.1;
   const size_t used_threshold = max_capacity * used_threshold_percent;
@@ -107,10 +107,10 @@
   // Calculate amount of free memory available to Java threads. Note that
   // the heap reserve is not available to Java threads and is therefore not
   // considered part of the free memory.
-  const size_t max_capacity = ZHeap::heap()->current_max_capacity();
+  const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
   const size_t max_reserve = ZHeap::heap()->max_reserve();
   const size_t used = ZHeap::heap()->used();
-  const size_t free_with_reserve = max_capacity - used;
+  const size_t free_with_reserve = max_capacity - MIN2(max_capacity, used);
   const size_t free = free_with_reserve - MIN2(free_with_reserve, max_reserve);
 
   // Calculate time until OOM given the max allocation rate and the amount
@@ -155,7 +155,7 @@
   // passed since the previous GC. This helps avoid superfluous GCs when running
   // applications with very low allocation rate.
   const size_t used_after_last_gc = ZStatHeap::used_at_relocate_end();
-  const size_t used_increase_threshold = ZHeap::heap()->current_max_capacity() * 0.10; // 10%
+  const size_t used_increase_threshold = ZHeap::heap()->soft_max_capacity() * 0.10; // 10%
   const size_t used_threshold = used_after_last_gc + used_increase_threshold;
   const size_t used = ZHeap::heap()->used();
   const double time_since_last_gc = ZStatCycle::time_since_last();
@@ -191,7 +191,7 @@
   // Calculate amount of free memory available to Java threads. Note that
   // the heap reserve is not available to Java threads and is therefore not
   // considered part of the free memory.
-  const size_t max_capacity = ZHeap::heap()->current_max_capacity();
+  const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
   const size_t max_reserve = ZHeap::heap()->max_reserve();
   const size_t used = ZHeap::heap()->used();
   const size_t free_with_reserve = max_capacity - used;
--- a/src/hotspot/share/gc/z/zHeap.cpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Fri Jun 07 11:19:34 2019 +0200
@@ -113,8 +113,8 @@
   return _page_allocator.max_capacity();
 }
 
-size_t ZHeap::current_max_capacity() const {
-  return _page_allocator.current_max_capacity();
+size_t ZHeap::soft_max_capacity() const {
+  return _page_allocator.soft_max_capacity();
 }
 
 size_t ZHeap::capacity() const {
--- a/src/hotspot/share/gc/z/zHeap.hpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.hpp	Fri Jun 07 11:19:34 2019 +0200
@@ -89,7 +89,7 @@
   // Heap metrics
   size_t min_capacity() const;
   size_t max_capacity() const;
-  size_t current_max_capacity() const;
+  size_t soft_max_capacity() const;
   size_t capacity() const;
   size_t max_reserve() const;
   size_t used_high() const;
--- a/src/hotspot/share/gc/z/zPageAllocator.cpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/z/zPageAllocator.cpp	Fri Jun 07 11:19:34 2019 +0200
@@ -34,6 +34,7 @@
 #include "gc/z/zSafeDelete.inline.hpp"
 #include "gc/z/zStat.hpp"
 #include "gc/z/zTracer.inline.hpp"
+#include "runtime/globals.hpp"
 #include "runtime/init.hpp"
 #include "runtime/java.hpp"
 #include "utilities/debug.hpp"
@@ -181,8 +182,9 @@
   return _max_capacity;
 }
 
-size_t ZPageAllocator::current_max_capacity() const {
-  return _current_max_capacity;
+size_t ZPageAllocator::soft_max_capacity() const {
+  // Note that SoftMaxHeapSize is a manageable flag
+  return MIN2(SoftMaxHeapSize, _current_max_capacity);
 }
 
 size_t ZPageAllocator::capacity() const {
--- a/src/hotspot/share/gc/z/zPageAllocator.hpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/z/zPageAllocator.hpp	Fri Jun 07 11:19:34 2019 +0200
@@ -94,7 +94,7 @@
 
   size_t min_capacity() const;
   size_t max_capacity() const;
-  size_t current_max_capacity() const;
+  size_t soft_max_capacity() const;
   size_t capacity() const;
   size_t max_reserve() const;
   size_t used_high() const;