# HG changeset patch # User mdoerr # Date 1563185053 -7200 # Mon Jul 15 12:04:13 2019 +0200 # Node ID ecca61fb559db5b6bfc56cf7c9985ec621f38ba5 # Parent 4b1de39beda387d953075384e8b36186b6e73dfd 8227597: [fastdbg build] Arena::inc_bytes_allocated should get inlined Reviewed-by: mbaesken, goetz 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,16 +34,13 @@ // 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 +#ifdef _LP64 + *dest += add_value; +#else julong value = Atomic::load(dest); - value += add_value; - Atomic::store(value, dest); -#else - // possible word-tearing during load/store - *dest += add_value; + Atomic::store(value + add_value, dest); #endif } #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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2019, 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 @@ -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,25 @@ 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) { + // Only do it if needed. Otherwise avoid contention. + if (PrintMallocStatistics) { +#ifdef _LP64 + _bytes_allocated += x; +#else + julong value = Atomic::load(&_bytes_allocated); + Atomic::store(value + x, &_bytes_allocated); +#endif + } + } +#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;