< prev index next >
src/share/vm/services/mallocTracker.hpp
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -38,12 +38,12 @@
* records total memory allocation size and number of allocations.
* The counters are updated atomically.
*/
class MemoryCounter VALUE_OBJ_CLASS_SPEC {
private:
- size_t _count;
- size_t _size;
+ volatile size_t _count;
+ volatile size_t _size;
DEBUG_ONLY(size_t _peak_count;)
DEBUG_ONLY(size_t _peak_size; )
public:
@@ -51,30 +51,32 @@
DEBUG_ONLY(_peak_count = 0;)
DEBUG_ONLY(_peak_size = 0;)
}
inline void allocate(size_t sz) {
- Atomic::add(1, (volatile MemoryCounterType*)&_count);
+ Atomic::add(1, &_count);
if (sz > 0) {
- Atomic::add((MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+ Atomic::add(sz, &_size);
DEBUG_ONLY(_peak_size = MAX2(_peak_size, _size));
}
DEBUG_ONLY(_peak_count = MAX2(_peak_count, _count);)
}
inline void deallocate(size_t sz) {
- assert(_count > 0, "Negative counter");
- assert(_size >= sz, "Negative size");
- Atomic::add(-1, (volatile MemoryCounterType*)&_count);
+ assert(_count > 0, "Nothing allocated yet");
+ assert(_size >= sz, "deallocation > allocated");
+ Atomic::add(-1, &_count);
if (sz > 0) {
- Atomic::add(-(MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+ // unary minus operator applied to unsigned type, result still unsigned
+ #pragma warning(suppress: 4146)
+ Atomic::add(-sz, &_size);
}
}
inline void resize(long sz) {
if (sz != 0) {
- Atomic::add((MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+ Atomic::add(sz, &_size);
DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
}
}
inline size_t count() const { return _count; }
< prev index next >