--- 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