src/share/vm/services/memoryPool.cpp

Print this page
rev 4801 : 8013590: NPG: Add a memory pool MXBean for Metaspace


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"

  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "runtime/javaCalls.hpp"
  31 #include "services/lowMemoryDetector.hpp"
  32 #include "services/management.hpp"
  33 #include "services/memoryManager.hpp"
  34 #include "services/memoryPool.hpp"
  35 #include "utilities/macros.hpp"

  36 
  37 MemoryPool::MemoryPool(const char* name,
  38                        PoolType type,
  39                        size_t init_size,
  40                        size_t max_size,
  41                        bool support_usage_threshold,
  42                        bool support_gc_threshold) {
  43   _name = name;
  44   _initial_size = init_size;
  45   _max_size = max_size;
  46   _memory_pool_obj = NULL;
  47   _available_for_allocation = true;
  48   _num_managers = 0;
  49   _type = type;
  50 
  51   // initialize the max and init size of collection usage
  52   _after_gc_usage = MemoryUsage(_initial_size, 0, 0, _max_size);
  53 
  54   _usage_sensor = NULL;
  55   _gc_usage_sensor = NULL;


 238 
 239 MemoryUsage GenerationPool::get_memory_usage() {
 240   size_t used      = used_in_bytes();
 241   size_t committed = _gen->capacity();
 242   size_t maxSize   = (available_for_allocation() ? max_size() : 0);
 243 
 244   return MemoryUsage(initial_size(), used, committed, maxSize);
 245 }
 246 
 247 CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold) :
 248   MemoryPool(name, NonHeap, codeHeap->capacity(), codeHeap->max_capacity(),
 249              support_usage_threshold, false), _codeHeap(codeHeap) {
 250 }
 251 
 252 MemoryUsage CodeHeapPool::get_memory_usage() {
 253   size_t used      = used_in_bytes();
 254   size_t committed = _codeHeap->capacity();
 255   size_t maxSize   = (available_for_allocation() ? max_size() : 0);
 256 
 257   return MemoryUsage(initial_size(), used, committed, maxSize);




































 258 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "memory/metaspace.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/handles.inline.hpp"
  31 #include "runtime/javaCalls.hpp"
  32 #include "services/lowMemoryDetector.hpp"
  33 #include "services/management.hpp"
  34 #include "services/memoryManager.hpp"
  35 #include "services/memoryPool.hpp"
  36 #include "utilities/macros.hpp"
  37 #include "utilities/globalDefinitions.hpp"
  38 
  39 MemoryPool::MemoryPool(const char* name,
  40                        PoolType type,
  41                        size_t init_size,
  42                        size_t max_size,
  43                        bool support_usage_threshold,
  44                        bool support_gc_threshold) {
  45   _name = name;
  46   _initial_size = init_size;
  47   _max_size = max_size;
  48   _memory_pool_obj = NULL;
  49   _available_for_allocation = true;
  50   _num_managers = 0;
  51   _type = type;
  52 
  53   // initialize the max and init size of collection usage
  54   _after_gc_usage = MemoryUsage(_initial_size, 0, 0, _max_size);
  55 
  56   _usage_sensor = NULL;
  57   _gc_usage_sensor = NULL;


 240 
 241 MemoryUsage GenerationPool::get_memory_usage() {
 242   size_t used      = used_in_bytes();
 243   size_t committed = _gen->capacity();
 244   size_t maxSize   = (available_for_allocation() ? max_size() : 0);
 245 
 246   return MemoryUsage(initial_size(), used, committed, maxSize);
 247 }
 248 
 249 CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold) :
 250   MemoryPool(name, NonHeap, codeHeap->capacity(), codeHeap->max_capacity(),
 251              support_usage_threshold, false), _codeHeap(codeHeap) {
 252 }
 253 
 254 MemoryUsage CodeHeapPool::get_memory_usage() {
 255   size_t used      = used_in_bytes();
 256   size_t committed = _codeHeap->capacity();
 257   size_t maxSize   = (available_for_allocation() ? max_size() : 0);
 258 
 259   return MemoryUsage(initial_size(), used, committed, maxSize);
 260 }
 261 
 262 MetaspacePool::MetaspacePool() :
 263   MemoryPool("Metaspace", NonHeap, capacity_in_bytes(), calculate_max_size(), true, false) { }
 264 
 265 MemoryUsage MetaspacePool::get_memory_usage() {
 266   size_t committed = align_size_down_(capacity_in_bytes(), os::vm_page_size());
 267   return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size());
 268 }
 269 
 270 size_t MetaspacePool::used_in_bytes() {
 271   return MetaspaceAux::allocated_used_bytes(Metaspace::NonClassType);
 272 }
 273 
 274 size_t MetaspacePool::capacity_in_bytes() const {
 275   return MetaspaceAux::allocated_capacity_bytes(Metaspace::NonClassType);
 276 }
 277 
 278 size_t MetaspacePool::calculate_max_size() const {
 279   return FLAG_IS_CMDLINE(MaxMetaspaceSize) ? MaxMetaspaceSize : max_uintx;
 280 }
 281 
 282 CompressedKlassSpacePool::CompressedKlassSpacePool() :
 283   MemoryPool("Compressed Class Space", NonHeap, capacity_in_bytes(), ClassMetaspaceSize, true, false) { }
 284 
 285 size_t CompressedKlassSpacePool::used_in_bytes() {
 286   return MetaspaceAux::allocated_used_bytes(Metaspace::ClassType);
 287 }
 288 
 289 size_t CompressedKlassSpacePool::capacity_in_bytes() const {
 290   return MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType);
 291 }
 292 
 293 MemoryUsage CompressedKlassSpacePool::get_memory_usage() {
 294   size_t committed = align_size_down_(capacity_in_bytes(), os::vm_page_size());
 295   return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size());
 296 }