< prev index next >

src/hotspot/share/services/mallocTracker.hpp

Print this page




  38  * records total memory allocation size and number of allocations.
  39  * The counters are updated atomically.
  40  */
  41 class MemoryCounter {
  42  private:
  43   volatile size_t   _count;
  44   volatile size_t   _size;
  45 
  46   DEBUG_ONLY(size_t   _peak_count;)
  47   DEBUG_ONLY(size_t   _peak_size; )
  48 
  49  public:
  50   MemoryCounter() : _count(0), _size(0) {
  51     DEBUG_ONLY(_peak_count = 0;)
  52     DEBUG_ONLY(_peak_size  = 0;)
  53   }
  54 
  55   inline void allocate(size_t sz) {
  56     Atomic::inc(&_count);
  57     if (sz > 0) {
  58       Atomic::add(sz, &_size);
  59       DEBUG_ONLY(_peak_size = MAX2(_peak_size, _size));
  60     }
  61     DEBUG_ONLY(_peak_count = MAX2(_peak_count, _count);)
  62   }
  63 
  64   inline void deallocate(size_t sz) {
  65     assert(_count > 0, "Nothing allocated yet");
  66     assert(_size >= sz, "deallocation > allocated");
  67     Atomic::dec(&_count);
  68     if (sz > 0) {
  69       Atomic::sub(sz, &_size);
  70     }
  71   }
  72 
  73   inline void resize(long sz) {
  74     if (sz != 0) {
  75       Atomic::add(size_t(sz), &_size);
  76       DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
  77     }
  78   }
  79 
  80   inline size_t count() const { return _count; }
  81   inline size_t size()  const { return _size;  }
  82   DEBUG_ONLY(inline size_t peak_count() const { return _peak_count; })
  83   DEBUG_ONLY(inline size_t peak_size()  const { return _peak_size; })
  84 
  85 };
  86 
  87 /*
  88  * Malloc memory used by a particular subsystem.
  89  * It includes the memory acquired through os::malloc()
  90  * call and arena's backing memory.
  91  */
  92 class MallocMemory {
  93  private:
  94   MemoryCounter _malloc;
  95   MemoryCounter _arena;




  38  * records total memory allocation size and number of allocations.
  39  * The counters are updated atomically.
  40  */
  41 class MemoryCounter {
  42  private:
  43   volatile size_t   _count;
  44   volatile size_t   _size;
  45 
  46   DEBUG_ONLY(size_t   _peak_count;)
  47   DEBUG_ONLY(size_t   _peak_size; )
  48 
  49  public:
  50   MemoryCounter() : _count(0), _size(0) {
  51     DEBUG_ONLY(_peak_count = 0;)
  52     DEBUG_ONLY(_peak_size  = 0;)
  53   }
  54 
  55   inline void allocate(size_t sz) {
  56     Atomic::inc(&_count);
  57     if (sz > 0) {
  58       Atomic::add(&_size, sz);
  59       DEBUG_ONLY(_peak_size = MAX2(_peak_size, _size));
  60     }
  61     DEBUG_ONLY(_peak_count = MAX2(_peak_count, _count);)
  62   }
  63 
  64   inline void deallocate(size_t sz) {
  65     assert(_count > 0, "Nothing allocated yet");
  66     assert(_size >= sz, "deallocation > allocated");
  67     Atomic::dec(&_count);
  68     if (sz > 0) {
  69       Atomic::sub(&_size, sz);
  70     }
  71   }
  72 
  73   inline void resize(long sz) {
  74     if (sz != 0) {
  75       Atomic::add(&_size, size_t(sz));
  76       DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
  77     }
  78   }
  79 
  80   inline size_t count() const { return _count; }
  81   inline size_t size()  const { return _size;  }
  82   DEBUG_ONLY(inline size_t peak_count() const { return _peak_count; })
  83   DEBUG_ONLY(inline size_t peak_size()  const { return _peak_size; })
  84 
  85 };
  86 
  87 /*
  88  * Malloc memory used by a particular subsystem.
  89  * It includes the memory acquired through os::malloc()
  90  * call and arena's backing memory.
  91  */
  92 class MallocMemory {
  93  private:
  94   MemoryCounter _malloc;
  95   MemoryCounter _arena;


< prev index next >