< prev index next >

src/hotspot/share/services/mallocTracker.hpp

Print this page




  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(sz, &_size);
  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()




  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()


< prev index next >