# HG changeset patch # User mdoerr # Date 1562858615 -7200 # Thu Jul 11 17:23:35 2019 +0200 # Node ID ea0e02a1e75cd0d50c31e9fc1f0f489c2d48ddb1 # Parent 107ebf94ddccd9ad4507d64b8ba5cd319b85814e 8227597: [fastdbg build] Arena::inc_bytes_allocated should get inlined Reviewed-by: diff --git a/src/hotspot/share/memory/allocation.inline.hpp b/src/hotspot/share/memory/allocation.inline.hpp --- a/src/hotspot/share/memory/allocation.inline.hpp +++ b/src/hotspot/share/memory/allocation.inline.hpp @@ -34,17 +34,10 @@ // Explicit C-heap memory management #ifndef PRODUCT -// Increments unsigned long value for statistics (not atomic on MP). +// Increments unsigned long value for statistics (not atomic on MP, but avoids word-tearing on 32 bit). inline void inc_stat_counter(volatile julong* dest, julong add_value) { -#if defined(SPARC) || defined(X86) - // Sparc and X86 have atomic jlong (8 bytes) instructions julong value = Atomic::load(dest); - value += add_value; - Atomic::store(value, dest); -#else - // possible word-tearing during load/store - *dest += add_value; -#endif + Atomic::store(value + add_value, dest); } #endif diff --git a/src/hotspot/share/memory/arena.cpp b/src/hotspot/share/memory/arena.cpp --- a/src/hotspot/share/memory/arena.cpp +++ b/src/hotspot/share/memory/arena.cpp @@ -477,8 +477,6 @@ julong Arena::_bytes_allocated = 0; -void Arena::inc_bytes_allocated(size_t x) { inc_stat_counter(&_bytes_allocated, x); } - // debugging code inline void Arena::free_all(char** start, char** end) { for (char** p = start; p < end; p++) if (*p) os::free(*p); diff --git a/src/hotspot/share/memory/arena.hpp b/src/hotspot/share/memory/arena.hpp --- a/src/hotspot/share/memory/arena.hpp +++ b/src/hotspot/share/memory/arena.hpp @@ -26,6 +26,7 @@ #define SHARE_MEMORY_ARENA_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "runtime/globals.hpp" #include "utilities/globalDefinitions.hpp" @@ -106,11 +107,18 @@ void* grow(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); size_t _size_in_bytes; // Size of arena (used for native memory tracking) - NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start +#ifndef PRODUCT + static julong _bytes_allocated; // total #bytes allocated since start + // Inlinable increment function (not atomic on MP, but avoids word-tearing on 32 bit) + void inc_bytes_allocated(size_t x) { + julong value = Atomic::load(&_bytes_allocated); + Atomic::store(value + x, &_bytes_allocated); + } +#endif + friend class AllocStats; debug_only(void* malloc(size_t size);) debug_only(void* internal_malloc_4(size_t x);) - NOT_PRODUCT(void inc_bytes_allocated(size_t x);) void signal_out_of_memory(size_t request, const char* whence) const;