# HG changeset patch # User pliden # Date 1571644603 -7200 # Node ID f5662bdbee4a3f8100ae2fa6dc997989c17928e5 # Parent 8b16701b4636a803e10dba7f4f6fb2fd611f7fd3 8232235: ZGC: Move ZValue inline funtions to zValue.inline.hpp Reviewed-by: tschatzl diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zObjectAllocator.cpp --- a/src/hotspot/share/gc/z/zObjectAllocator.cpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zObjectAllocator.cpp Mon Oct 21 09:56:43 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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,6 +30,7 @@ #include "gc/z/zStat.hpp" #include "gc/z/zThread.hpp" #include "gc/z/zUtils.inline.hpp" +#include "gc/z/zValue.inline.hpp" #include "logging/log.hpp" #include "runtime/atomic.hpp" #include "runtime/safepoint.hpp" diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zObjectAllocator.hpp --- a/src/hotspot/share/gc/z/zObjectAllocator.hpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zObjectAllocator.hpp Mon Oct 21 09:56:43 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zPageCache.cpp --- a/src/hotspot/share/gc/z/zPageCache.cpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zPageCache.cpp Mon Oct 21 09:56:43 2019 +0200 @@ -27,6 +27,7 @@ #include "gc/z/zPage.inline.hpp" #include "gc/z/zPageCache.hpp" #include "gc/z/zStat.hpp" +#include "gc/z/zValue.inline.hpp" #include "logging/log.hpp" static const ZStatCounter ZCounterPageCacheHitL1("Memory", "Page Cache Hit L1", ZStatUnitOpsPerSecond); diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zPageCache.inline.hpp --- a/src/hotspot/share/gc/z/zPageCache.inline.hpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zPageCache.inline.hpp Mon Oct 21 09:56:43 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -26,6 +26,7 @@ #include "gc/z/zList.inline.hpp" #include "gc/z/zPageCache.hpp" +#include "gc/z/zValue.inline.hpp" inline size_t ZPageCache::available() const { return _available; diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zReferenceProcessor.cpp --- a/src/hotspot/share/gc/z/zReferenceProcessor.cpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zReferenceProcessor.cpp Mon Oct 21 09:56:43 2019 +0200 @@ -32,6 +32,7 @@ #include "gc/z/zTask.hpp" #include "gc/z/zTracer.inline.hpp" #include "gc/z/zUtils.inline.hpp" +#include "gc/z/zValue.inline.hpp" #include "memory/universe.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/os.hpp" diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zRelocate.cpp --- a/src/hotspot/share/gc/z/zRelocate.cpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zRelocate.cpp Mon Oct 21 09:56:43 2019 +0200 @@ -33,6 +33,7 @@ #include "gc/z/zRootsIterator.hpp" #include "gc/z/zStat.hpp" #include "gc/z/zTask.hpp" +#include "gc/z/zThread.hpp" #include "gc/z/zThreadLocalAllocBuffer.hpp" #include "gc/z/zWorkers.hpp" #include "logging/log.hpp" diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zThreadLocalAllocBuffer.cpp --- a/src/hotspot/share/gc/z/zThreadLocalAllocBuffer.cpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zThreadLocalAllocBuffer.cpp Mon Oct 21 09:56:43 2019 +0200 @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "gc/z/zAddress.inline.hpp" #include "gc/z/zThreadLocalAllocBuffer.hpp" +#include "gc/z/zValue.inline.hpp" #include "runtime/globals.hpp" #include "runtime/thread.hpp" diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zValue.hpp --- a/src/hotspot/share/gc/z/zValue.hpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zValue.hpp Mon Oct 21 09:56:43 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -25,13 +25,11 @@ #define SHARE_GC_Z_ZVALUE_HPP #include "memory/allocation.hpp" -#include "gc/z/zCPU.hpp" -#include "gc/z/zGlobals.hpp" -#include "gc/z/zNUMA.hpp" -#include "gc/z/zThread.hpp" -#include "gc/z/zUtils.hpp" -#include "runtime/globals.hpp" -#include "utilities/align.hpp" +#include "utilities/globalDefinitions.hpp" + +// +// Storage +// template class ZValueStorage : public AllStatic { @@ -42,202 +40,93 @@ public: static const size_t offset = 4 * K; - static uintptr_t alloc(size_t size) { - guarantee(size <= offset, "Allocation too large"); - - // Allocate entry in existing memory block - const uintptr_t addr = align_up(_top, S::alignment()); - _top = addr + size; - - if (_top < _end) { - // Success - return addr; - } - - // Allocate new block of memory - const size_t block_alignment = offset; - const size_t block_size = offset * S::count(); - _top = ZUtils::alloc_aligned(block_alignment, block_size); - _end = _top + offset; - - // Retry allocation - return alloc(size); - } + static uintptr_t alloc(size_t size); }; -template uintptr_t ZValueStorage::_end = 0; -template uintptr_t ZValueStorage::_top = 0; - class ZContendedStorage : public ZValueStorage { public: - static size_t alignment() { - return ZCacheLineSize; - } - - static uint32_t count() { - return 1; - } - - static uint32_t id() { - return 0; - } + static size_t alignment(); + static uint32_t count(); + static uint32_t id(); }; class ZPerCPUStorage : public ZValueStorage { public: - static size_t alignment() { - return sizeof(uintptr_t); - } - - static uint32_t count() { - return ZCPU::count(); - } - - static uint32_t id() { - return ZCPU::id(); - } + static size_t alignment(); + static uint32_t count(); + static uint32_t id(); }; class ZPerNUMAStorage : public ZValueStorage { public: - static size_t alignment() { - return sizeof(uintptr_t); - } - - static uint32_t count() { - return ZNUMA::count(); - } - - static uint32_t id() { - return ZNUMA::id(); - } + static size_t alignment(); + static uint32_t count(); + static uint32_t id(); }; class ZPerWorkerStorage : public ZValueStorage { public: - static size_t alignment() { - return sizeof(uintptr_t); - } - - static uint32_t count() { - return MAX2(ParallelGCThreads, ConcGCThreads); - } - - static uint32_t id() { - return ZThread::worker_id(); - } + static size_t alignment(); + static uint32_t count(); + static uint32_t id(); }; -template -class ZValueIterator; +// +// Value +// template class ZValue : public CHeapObj { private: const uintptr_t _addr; - uintptr_t value_addr(uint32_t value_id) const { - return _addr + (value_id * S::offset); - } + uintptr_t value_addr(uint32_t value_id) const; public: - ZValue() : - _addr(S::alloc(sizeof(T))) { - // Initialize all instances - ZValueIterator iter(this); - for (T* addr; iter.next(&addr);) { - ::new (addr) T; - } - } + ZValue(); + ZValue(const T& value); - ZValue(const T& value) : - _addr(S::alloc(sizeof(T))) { - // Initialize all instances - ZValueIterator iter(this); - for (T* addr; iter.next(&addr);) { - ::new (addr) T(value); - } - } - - // Not implemented - ZValue(const ZValue& value); - ZValue& operator=(const ZValue& value); + const T* addr(uint32_t value_id = S::id()) const; + T* addr(uint32_t value_id = S::id()); - const T* addr(uint32_t value_id = S::id()) const { - return reinterpret_cast(value_addr(value_id)); - } - - T* addr(uint32_t value_id = S::id()) { - return reinterpret_cast(value_addr(value_id)); - } - - const T& get(uint32_t value_id = S::id()) const { - return *addr(value_id); - } + const T& get(uint32_t value_id = S::id()) const; + T& get(uint32_t value_id = S::id()); - T& get(uint32_t value_id = S::id()) { - return *addr(value_id); - } - - void set(const T& value, uint32_t value_id = S::id()) { - get(value_id) = value; - } - - void set_all(const T& value) { - ZValueIterator iter(this); - for (T* addr; iter.next(&addr);) { - *addr = value; - } - } + void set(const T& value, uint32_t value_id = S::id()); + void set_all(const T& value); }; template class ZContended : public ZValue { public: - ZContended() : - ZValue() {} - - ZContended(const T& value) : - ZValue(value) {} - - using ZValue::operator=; + ZContended(); + ZContended(const T& value); }; template class ZPerCPU : public ZValue { public: - ZPerCPU() : - ZValue() {} - - ZPerCPU(const T& value) : - ZValue(value) {} - - using ZValue::operator=; + ZPerCPU(); + ZPerCPU(const T& value); }; template class ZPerNUMA : public ZValue { public: - ZPerNUMA() : - ZValue() {} - - ZPerNUMA(const T& value) : - ZValue(value) {} - - using ZValue::operator=; + ZPerNUMA(); + ZPerNUMA(const T& value); }; template class ZPerWorker : public ZValue { public: - ZPerWorker() : - ZValue() {} + ZPerWorker(); + ZPerWorker(const T& value); +}; - ZPerWorker(const T& value) : - ZValue(value) {} - - using ZValue::operator=; -}; +// +// Iterator +// template class ZValueIterator { @@ -246,38 +135,27 @@ uint32_t _value_id; public: - ZValueIterator(ZValue* value) : - _value(value), - _value_id(0) {} + ZValueIterator(ZValue* value); - bool next(T** value) { - if (_value_id < S::count()) { - *value = _value->addr(_value_id++); - return true; - } - return false; - } + bool next(T** value); }; template class ZPerCPUIterator : public ZValueIterator { public: - ZPerCPUIterator(ZPerCPU* value) : - ZValueIterator(value) {} + ZPerCPUIterator(ZPerCPU* value); }; template class ZPerNUMAIterator : public ZValueIterator { public: - ZPerNUMAIterator(ZPerNUMA* value) : - ZValueIterator(value) {} + ZPerNUMAIterator(ZPerNUMA* value); }; template class ZPerWorkerIterator : public ZValueIterator { public: - ZPerWorkerIterator(ZPerWorker* value) : - ZValueIterator(value) {} + ZPerWorkerIterator(ZPerWorker* value); }; template @@ -287,38 +165,27 @@ uint32_t _value_id; public: - ZValueConstIterator(const ZValue* value) : - _value(value), - _value_id(0) {} + ZValueConstIterator(const ZValue* value); - bool next(const T** value) { - if (_value_id < S::count()) { - *value = _value->addr(_value_id++); - return true; - } - return false; - } + bool next(const T** value); }; template class ZPerCPUConstIterator : public ZValueConstIterator { public: - ZPerCPUConstIterator(const ZPerCPU* value) : - ZValueConstIterator(value) {} + ZPerCPUConstIterator(const ZPerCPU* value); }; template class ZPerNUMAConstIterator : public ZValueConstIterator { public: - ZPerNUMAConstIterator(const ZPerNUMA* value) : - ZValueConstIterator(value) {} + ZPerNUMAConstIterator(const ZPerNUMA* value); }; template class ZPerWorkerConstIterator : public ZValueConstIterator { public: - ZPerWorkerConstIterator(const ZPerWorker* value) : - ZValueConstIterator(value) {} + ZPerWorkerConstIterator(const ZPerWorker* value); }; #endif // SHARE_GC_Z_ZVALUE_HPP diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zValue.inline.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hotspot/share/gc/z/zValue.inline.hpp Mon Oct 21 09:56:43 2019 +0200 @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2015, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef SHARE_GC_Z_ZVALUE_INLINE_HPP +#define SHARE_GC_Z_ZVALUE_INLINE_HPP + +#include "gc/z/zCPU.hpp" +#include "gc/z/zGlobals.hpp" +#include "gc/z/zNUMA.hpp" +#include "gc/z/zThread.hpp" +#include "gc/z/zUtils.hpp" +#include "gc/z/zValue.hpp" +#include "runtime/globals.hpp" +#include "utilities/align.hpp" + +// +// Storage +// + +template uintptr_t ZValueStorage::_end = 0; +template uintptr_t ZValueStorage::_top = 0; + +template +uintptr_t ZValueStorage::alloc(size_t size) { + assert(size <= offset, "Allocation too large"); + + // Allocate entry in existing memory block + const uintptr_t addr = align_up(_top, S::alignment()); + _top = addr + size; + + if (_top < _end) { + // Success + return addr; + } + + // Allocate new block of memory + const size_t block_alignment = offset; + const size_t block_size = offset * S::count(); + _top = ZUtils::alloc_aligned(block_alignment, block_size); + _end = _top + offset; + + // Retry allocation + return alloc(size); +} + +inline size_t ZContendedStorage::alignment() { + return ZCacheLineSize; +} + +inline uint32_t ZContendedStorage::count() { + return 1; +} + +inline uint32_t ZContendedStorage::id() { + return 0; +} + +inline size_t ZPerCPUStorage::alignment() { + return sizeof(uintptr_t); +} + +inline uint32_t ZPerCPUStorage::count() { + return ZCPU::count(); +} + +inline uint32_t ZPerCPUStorage::id() { + return ZCPU::id(); +} + +inline size_t ZPerNUMAStorage::alignment() { + return sizeof(uintptr_t); +} + +inline uint32_t ZPerNUMAStorage::count() { + return ZNUMA::count(); +} + +inline uint32_t ZPerNUMAStorage::id() { + return ZNUMA::id(); +} + +inline size_t ZPerWorkerStorage::alignment() { + return sizeof(uintptr_t); +} + +inline uint32_t ZPerWorkerStorage::count() { + return MAX2(ParallelGCThreads, ConcGCThreads); +} + +inline uint32_t ZPerWorkerStorage::id() { + return ZThread::worker_id(); +} + +// +// Value +// + +template +inline uintptr_t ZValue::value_addr(uint32_t value_id) const { + return _addr + (value_id * S::offset); +} + +template +inline ZValue::ZValue() : + _addr(S::alloc(sizeof(T))) { + // Initialize all instances + ZValueIterator iter(this); + for (T* addr; iter.next(&addr);) { + ::new (addr) T; + } +} + +template +inline ZValue::ZValue(const T& value) : + _addr(S::alloc(sizeof(T))) { + // Initialize all instances + ZValueIterator iter(this); + for (T* addr; iter.next(&addr);) { + ::new (addr) T(value); + } +} + +template +inline const T* ZValue::addr(uint32_t value_id) const { + return reinterpret_cast(value_addr(value_id)); +} + +template +inline T* ZValue::addr(uint32_t value_id) { + return reinterpret_cast(value_addr(value_id)); +} + +template +inline const T& ZValue::get(uint32_t value_id) const { + return *addr(value_id); +} + +template +inline T& ZValue::get(uint32_t value_id) { + return *addr(value_id); +} + +template +inline void ZValue::set(const T& value, uint32_t value_id) { + get(value_id) = value; +} + +template +inline void ZValue::set_all(const T& value) { + ZValueIterator iter(this); + for (T* addr; iter.next(&addr);) { + *addr = value; + } +} + +template +inline ZContended::ZContended() : + ZValue() {} + +template +inline ZContended::ZContended(const T& value) : + ZValue(value) {} + +template +inline ZPerCPU::ZPerCPU() : + ZValue() {} + +template +inline ZPerCPU::ZPerCPU(const T& value) : + ZValue(value) {} + +template +inline ZPerNUMA::ZPerNUMA() : + ZValue() {} + +template +inline ZPerNUMA::ZPerNUMA(const T& value) : + ZValue(value) {} + +template +inline ZPerWorker::ZPerWorker() : + ZValue() {} + +template +inline ZPerWorker::ZPerWorker(const T& value) : + ZValue(value) {} + +// +// Iterator +// + +template +inline ZValueIterator::ZValueIterator(ZValue* value) : + _value(value), + _value_id(0) {} + +template +inline bool ZValueIterator::next(T** value) { + if (_value_id < S::count()) { + *value = _value->addr(_value_id++); + return true; + } + return false; +} + +template +inline ZPerCPUIterator::ZPerCPUIterator(ZPerCPU* value) : + ZValueIterator(value) {} + +template +inline ZPerNUMAIterator::ZPerNUMAIterator(ZPerNUMA* value) : + ZValueIterator(value) {} + +template +inline ZPerWorkerIterator::ZPerWorkerIterator(ZPerWorker* value) : + ZValueIterator(value) {} + +template +inline ZValueConstIterator::ZValueConstIterator(const ZValue* value) : + _value(value), + _value_id(0) {} + +template +inline bool ZValueConstIterator::next(const T** value) { + if (_value_id < S::count()) { + *value = _value->addr(_value_id++); + return true; + } + return false; +} + +template +inline ZPerCPUConstIterator::ZPerCPUConstIterator(const ZPerCPU* value) : + ZValueConstIterator(value) {} + +template +inline ZPerNUMAConstIterator::ZPerNUMAConstIterator(const ZPerNUMA* value) : + ZValueConstIterator(value) {} + +template +inline ZPerWorkerConstIterator::ZPerWorkerConstIterator(const ZPerWorker* value) : + ZValueConstIterator(value) {} + +#endif // SHARE_GC_Z_ZVALUE_INLINE_HPP diff -r 8b16701b4636 -r f5662bdbee4a src/hotspot/share/gc/z/zWeakRootsProcessor.hpp --- a/src/hotspot/share/gc/z/zWeakRootsProcessor.hpp Mon Oct 21 09:55:58 2019 +0200 +++ b/src/hotspot/share/gc/z/zWeakRootsProcessor.hpp Mon Oct 21 09:56:43 2019 +0200 @@ -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 @@ -24,8 +24,6 @@ #ifndef SHARE_GC_Z_ZWEAKROOTSPROCESSOR_HPP #define SHARE_GC_Z_ZWEAKROOTSPROCESSOR_HPP -#include "gc/z/zValue.hpp" - class ZWorkers; class ZWeakRootsProcessor {