changeset 55969:3ab77d8dc60a

8222462: Introduce CollectedHeap::unused() Reviewed-by: stefank, eosterlund
author pliden
date Thu, 25 Apr 2019 08:55:49 +0200
parents 9afd2868c18b
children 24f6b0e413a0
files src/hotspot/share/gc/shared/collectedHeap.cpp src/hotspot/share/gc/shared/collectedHeap.hpp src/hotspot/share/gc/z/zCollectedHeap.cpp src/hotspot/share/gc/z/zCollectedHeap.hpp 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 src/hotspot/share/prims/jvm.cpp
diffstat 9 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
@@ -81,6 +81,11 @@
   st.print_cr("}");
 }
 
+size_t CollectedHeap::unused() const {
+  MutexLocker ml(Heap_lock);
+  return capacity() - used();
+}
+
 VirtualSpaceSummary CollectedHeap::create_heap_space_summary() {
   size_t capacity_in_words = capacity() / HeapWordSize;
 
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
@@ -210,6 +210,9 @@
   virtual size_t capacity() const = 0;
   virtual size_t used() const = 0;
 
+  // Returns unused capacity.
+  virtual size_t unused() const;
+
   // Return "true" if the part of the heap that allocates Java
   // objects has reached the maximal committed limit that it can
   // reach, without a garbage collection.
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
@@ -100,6 +100,10 @@
   return _heap.used();
 }
 
+size_t ZCollectedHeap::unused() const {
+  return _heap.unused();
+}
+
 bool ZCollectedHeap::is_maximal_no_gc() const {
   // Not supported
   ShouldNotReachHere();
--- a/src/hotspot/share/gc/z/zCollectedHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
@@ -69,6 +69,7 @@
   virtual size_t max_capacity() const;
   virtual size_t capacity() const;
   virtual size_t used() const;
+  virtual size_t unused() const;
 
   virtual bool is_maximal_no_gc() const;
   virtual bool is_in(const void* p) const;
--- a/src/hotspot/share/gc/z/zHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Thu Apr 25 08:55:49 2019 +0200
@@ -133,6 +133,10 @@
   return _page_allocator.used();
 }
 
+size_t ZHeap::unused() const {
+  return _page_allocator.unused();
+}
+
 size_t ZHeap::allocated() const {
   return _page_allocator.allocated();
 }
--- a/src/hotspot/share/gc/z/zHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.hpp	Thu Apr 25 08:55:49 2019 +0200
@@ -94,6 +94,7 @@
   size_t used_high() const;
   size_t used_low() const;
   size_t used() const;
+  size_t unused() const;
   size_t allocated() const;
   size_t reclaimed() const;
 
--- a/src/hotspot/share/gc/z/zPageAllocator.cpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zPageAllocator.cpp	Thu Apr 25 08:55:49 2019 +0200
@@ -133,6 +133,11 @@
   return _used;
 }
 
+size_t ZPageAllocator::unused() const {
+  const ssize_t unused = (ssize_t)_physical.capacity() - (ssize_t)_used - (ssize_t)_max_reserve;
+  return unused > 0 ? (size_t)unused : 0;
+}
+
 size_t ZPageAllocator::allocated() const {
   return _allocated;
 }
--- a/src/hotspot/share/gc/z/zPageAllocator.hpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/gc/z/zPageAllocator.hpp	Thu Apr 25 08:55:49 2019 +0200
@@ -92,6 +92,7 @@
   size_t used_high() const;
   size_t used_low() const;
   size_t used() const;
+  size_t unused() const;
   size_t allocated() const;
   size_t reclaimed() const;
 
--- a/src/hotspot/share/prims/jvm.cpp	Thu Apr 25 08:55:49 2019 +0200
+++ b/src/hotspot/share/prims/jvm.cpp	Thu Apr 25 08:55:49 2019 +0200
@@ -508,12 +508,7 @@
 
 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
   JVMWrapper("JVM_FreeMemory");
-  CollectedHeap* ch = Universe::heap();
-  size_t n;
-  {
-     MutexLocker x(Heap_lock);
-     n = ch->capacity() - ch->used();
-  }
+  size_t n = Universe::heap()->unused();
   return convert_size_t_to_jlong(n);
 JVM_END