src/share/vm/services/memoryPool.cpp

Print this page
rev 4210 : 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;
  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;


 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 "runtime/os.hpp"
  33 #include "services/lowMemoryDetector.hpp"
  34 #include "services/management.hpp"
  35 #include "services/memoryManager.hpp"
  36 #include "services/memoryPool.hpp"
  37 #include "utilities/globalDefinitions.hpp"
  38 #include "utilities/macros.hpp"
  39 
  40 MemoryPool::MemoryPool(const char* name,
  41                        PoolType type,
  42                        size_t init_size,
  43                        size_t max_size,
  44                        bool support_usage_threshold,
  45                        bool support_gc_threshold) {
  46   _name = name;
  47   _initial_size = init_size;
  48   _max_size = max_size;
  49   _memory_pool_obj = NULL;
  50   _available_for_allocation = true;
  51   _num_managers = 0;
  52   _type = type;
  53 
  54   // initialize the max and init size of collection usage
  55   _after_gc_usage = MemoryUsage(_initial_size, 0, 0, _max_size);
  56 
  57   _usage_sensor = NULL;


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