changeset 1166:ed52bcc32739

6880903: G1: G1 reports incorrect Runtime.maxMemory() Summary: G1 reports committed memory instead of reserved memory from the Runtime.maxMemory() method Reviewed-by: ysr, jmasa
author tonyp
date Fri, 04 Dec 2009 07:44:35 -0500
parents 6aa7255741f3
children afc30fccf324
files src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp src/share/vm/services/g1MemoryPool.cpp src/share/vm/services/g1MemoryPool.hpp
diffstat 4 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Thu Dec 03 15:01:57 2009 -0800
+++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Fri Dec 04 07:44:35 2009 -0500
@@ -2130,7 +2130,7 @@
 }
 
 size_t G1CollectedHeap::max_capacity() const {
-  return _g1_committed.byte_size();
+  return g1_reserved_obj_bytes();
 }
 
 jlong G1CollectedHeap::millis_since_last_gc() {
--- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp	Thu Dec 03 15:01:57 2009 -0800
+++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp	Fri Dec 04 07:44:35 2009 -0500
@@ -692,7 +692,7 @@
 
   // Reserved (g1 only; super method includes perm), capacity and the used
   // portion in bytes.
-  size_t g1_reserved_obj_bytes() { return _g1_reserved.byte_size(); }
+  size_t g1_reserved_obj_bytes() const { return _g1_reserved.byte_size(); }
   virtual size_t capacity() const;
   virtual size_t used() const;
   // This should be called when we're not holding the heap lock. The
--- a/src/share/vm/services/g1MemoryPool.cpp	Thu Dec 03 15:01:57 2009 -0800
+++ b/src/share/vm/services/g1MemoryPool.cpp	Fri Dec 04 07:44:35 2009 -0500
@@ -96,7 +96,7 @@
 
 // See the comment at the top of g1MemoryPool.hpp
 size_t G1MemoryPoolSuper::old_space_max(G1CollectedHeap* g1h) {
-  size_t max = g1h->g1_reserved_obj_bytes();
+  size_t max = overall_max(g1h);
   size_t eden_max = eden_space_max(g1h);
   size_t survivor_max = survivor_space_max(g1h);
   max = subtract_up_to_zero(max, eden_max);
@@ -113,11 +113,12 @@
 }
 
 MemoryUsage G1EdenPool::get_memory_usage() {
-  size_t maxSize   = max_size();
-  size_t used      = used_in_bytes();
-  size_t committed = eden_space_committed();
+  size_t initial_sz = initial_size();
+  size_t max_sz     = max_size();
+  size_t used       = used_in_bytes();
+  size_t committed  = eden_space_committed();
 
-  return MemoryUsage(initial_size(), used, committed, maxSize);
+  return MemoryUsage(initial_sz, used, committed, max_sz);
 }
 
 G1SurvivorPool::G1SurvivorPool(G1CollectedHeap* g1h) :
@@ -129,11 +130,12 @@
 }
 
 MemoryUsage G1SurvivorPool::get_memory_usage() {
-  size_t maxSize   = max_size();
-  size_t used      = used_in_bytes();
-  size_t committed = survivor_space_committed();
+  size_t initial_sz = initial_size();
+  size_t max_sz     = max_size();
+  size_t used       = used_in_bytes();
+  size_t committed  = survivor_space_committed();
 
-  return MemoryUsage(initial_size(), used, committed, maxSize);
+  return MemoryUsage(initial_sz, used, committed, max_sz);
 }
 
 G1OldGenPool::G1OldGenPool(G1CollectedHeap* g1h) :
@@ -145,9 +147,10 @@
 }
 
 MemoryUsage G1OldGenPool::get_memory_usage() {
-  size_t maxSize   = max_size();
-  size_t used      = used_in_bytes();
-  size_t committed = old_space_committed();
+  size_t initial_sz = initial_size();
+  size_t max_sz     = max_size();
+  size_t used       = used_in_bytes();
+  size_t committed  = old_space_committed();
 
-  return MemoryUsage(initial_size(), used, committed, maxSize);
+  return MemoryUsage(initial_sz, used, committed, max_sz);
 }
--- a/src/share/vm/services/g1MemoryPool.hpp	Thu Dec 03 15:01:57 2009 -0800
+++ b/src/share/vm/services/g1MemoryPool.hpp	Fri Dec 04 07:44:35 2009 -0500
@@ -137,6 +137,9 @@
   static size_t overall_used(G1CollectedHeap* g1h) {
     return g1h->used_unlocked();
   }
+  static size_t overall_max(G1CollectedHeap* g1h) {
+    return g1h->g1_reserved_obj_bytes();
+  }
 
   static size_t eden_space_committed(G1CollectedHeap* g1h);
   static size_t eden_space_used(G1CollectedHeap* g1h);