8157709: NMT should use size_t version of Atomic::add
Reviewed-by: kbarrett, sspitsyn
--- a/hotspot/src/share/vm/runtime/atomic.hpp Mon Feb 13 17:26:26 2017 +0000
+++ b/hotspot/src/share/vm/runtime/atomic.hpp Mon Feb 13 19:10:55 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -81,8 +81,6 @@
inline static size_t add (size_t add_value, volatile size_t* dest);
inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest);
inline static void* add_ptr(intptr_t add_value, volatile void* dest);
- // See comment above about using jlong atomics on 32-bit platforms
- inline static jlong add (jlong add_value, volatile jlong* dest);
// Atomically increment location. inc*() provide:
// <fence> increment-dest <membar StoreLoad|StoreStore>
@@ -199,16 +197,6 @@
(jint)compare_value, order);
}
-inline jlong Atomic::add(jlong add_value, volatile jlong* dest) {
- jlong old = load(dest);
- jlong new_value = old + add_value;
- while (old != cmpxchg(new_value, dest, old)) {
- old = load(dest);
- new_value = old + add_value;
- }
- return old;
-}
-
inline jshort Atomic::add(jshort add_value, volatile jshort* dest) {
// Most platforms do not support atomic add on a 2-byte value. However,
// if the value occupies the most significant 16 bits of an aligned 32-bit
--- a/hotspot/src/share/vm/services/mallocTracker.hpp Mon Feb 13 17:26:26 2017 +0000
+++ b/hotspot/src/share/vm/services/mallocTracker.hpp Mon Feb 13 19:10:55 2017 -0500
@@ -1,5 +1,5 @@
/*
- * 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
@@ -40,8 +40,8 @@
*/
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; )
@@ -53,26 +53,28 @@
}
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);)
}
}
--- a/hotspot/src/share/vm/services/nmtCommon.hpp Mon Feb 13 17:26:26 2017 +0000
+++ b/hotspot/src/share/vm/services/nmtCommon.hpp Mon Feb 13 19:10:55 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -30,13 +30,6 @@
#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_size_up_(sizeof(obj), sizeof(type))/sizeof(type))
-// Data type for memory counters
-#ifdef _LP64
- typedef jlong MemoryCounterType;
-#else
- typedef jint MemoryCounterType;
-#endif
-
// Native memory tracking level
enum NMT_TrackingLevel {
NMT_unknown = 0xFF,