src/share/vm/services/memoryPool.cpp

Print this page
rev 4165 : 8000754: NPG: Implement a MemoryPool MXBean for Metaspace


   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;


 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 }


   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/globals.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 
  38 MemoryPool::MemoryPool(const char* name,
  39                        PoolType type,
  40                        size_t init_size,
  41                        size_t max_size,
  42                        bool support_usage_threshold,
  43                        bool support_gc_threshold) {
  44   _name = name;
  45   _initial_size = init_size;
  46   _max_size = max_size;
  47   _memory_pool_obj = NULL;
  48   _available_for_allocation = true;
  49   _num_managers = 0;


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