< prev index next >

src/share/vm/services/mallocTracker.hpp

Print this page
rev 13453 : imported patch Atomic_add


  36 /*
  37  * This counter class counts memory allocation and deallocation,
  38  * records total memory allocation size and number of allocations.
  39  * The counters are updated atomically.
  40  */
  41 class MemoryCounter VALUE_OBJ_CLASS_SPEC {
  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::add(1, &_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::add(-1, &_count);
  68     if (sz > 0) {
  69       // unary minus operator applied to unsigned type, result still unsigned
  70       #pragma warning(suppress: 4146)
  71       Atomic::add(-sz, &_size);
  72     }
  73   }
  74 
  75   inline void resize(long sz) {
  76     if (sz != 0) {
  77       Atomic::add(sz, &_size);
  78       DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
  79     }
  80   }
  81 
  82   inline size_t count() const { return _count; }
  83   inline size_t size()  const { return _size;  }
  84   DEBUG_ONLY(inline size_t peak_count() const { return _peak_count; })
  85   DEBUG_ONLY(inline size_t peak_size()  const { return _peak_size; })
  86 
  87 };
  88 
  89 /*
  90  * Malloc memory used by a particular subsystem.
  91  * It includes the memory acquired through os::malloc()
  92  * call and arena's backing memory.
  93  */
  94 class MallocMemory VALUE_OBJ_CLASS_SPEC {
  95  private:
  96   MemoryCounter _malloc;
  97   MemoryCounter _arena;




  36 /*
  37  * This counter class counts memory allocation and deallocation,
  38  * records total memory allocation size and number of allocations.
  39  * The counters are updated atomically.
  40  */
  41 class MemoryCounter VALUE_OBJ_CLASS_SPEC {
  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       // unary minus operator applied to unsigned type, result still unsigned
  70       #pragma warning(suppress: 4146)
  71       Atomic::add(-sz, &_size);
  72     }
  73   }
  74 
  75   inline void resize(long sz) {
  76     if (sz != 0) {
  77       Atomic::add(size_t(sz), &_size);
  78       DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
  79     }
  80   }
  81 
  82   inline size_t count() const { return _count; }
  83   inline size_t size()  const { return _size;  }
  84   DEBUG_ONLY(inline size_t peak_count() const { return _peak_count; })
  85   DEBUG_ONLY(inline size_t peak_size()  const { return _peak_size; })
  86 
  87 };
  88 
  89 /*
  90  * Malloc memory used by a particular subsystem.
  91  * It includes the memory acquired through os::malloc()
  92  * call and arena's backing memory.
  93  */
  94 class MallocMemory VALUE_OBJ_CLASS_SPEC {
  95  private:
  96   MemoryCounter _malloc;
  97   MemoryCounter _arena;


< prev index next >