Path: blob/master/runtime/gc_vlhgc/CopyForwardCompactGroup.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2022 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/2223/**24* @file25* @ingroup GC_Modron_Standard26*/2728#if !defined(COPYFORWARDCOMPACTGROUP_HPP_)29#define COPYFORWARDCOMPACTGROUP_HPP_3031#include "j9.h"32#include "j9cfg.h"33#include "modronopt.h"3435#include "GCExtensions.hpp"36#include "MemoryPool.hpp"37#include "EnvironmentVLHGC.hpp"38#include "HeapRegionDescriptorVLHGC.hpp"39#include "HeapRegionManager.hpp"4041class MM_CopyScanCacheVLHGC;42class MM_LightweightNonReentrantLock;4344/**45* Structure used to record per-thread data for each compact group in CopyForwardScheme.46* @ingroup GC_Modron_Standard47*/48class MM_CopyForwardCompactGroup49{50/* data members */51private:52MM_HeapRegionManager *_regionManager; /**< Region manager for the heap instance */53protected:54public:55MM_CopyScanCacheVLHGC *_copyCache; /**< The copy cache in this compact group for the owning thread */56MM_LightweightNonReentrantLock *_copyCacheLock; /**< The lock associated with the list this copy cache belongs to */57void *_TLHRemainderBase; /**< base pointers of the last unused TLH copy cache, that might be reused on next copy refresh */58void *_TLHRemainderTop; /**< top pointers of the last unused TLH copy cache, that might be reused on next copy refresh */59void *_DFCopyBase; /**< The base address of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */60void *_DFCopyAlloc; /**< The alloc pointer of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */61void *_DFCopyTop; /**< The top address of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */62UDATA _failedAllocateSize; /**< Smallest size of allocate request that we failed in this compact group */6364/* statistics */65struct MM_CopyForwardCompactGroupStats {66UDATA _copiedObjects; /**< The number of objects copied into survivor regions for this compact group by the owning thread (i.e. objects copied TO or WITHIN this compact group) */67UDATA _copiedBytes; /**< The number of bytes copied into survivor regions for this compact group by the owning thread */68UDATA _liveObjects; /**< The number of live objects found in evacuate regions for this compact group by the owning thread (i.e. objects copied FROM or WITHIN this compact group) */69UDATA _liveBytes; /**< The number of live bytes found in evacuate regions for this compact group by the owning thread */70UDATA _scannedObjects; /**< The number of objects scanned in abort recovery/nonEvacuated regions in this compact group */71UDATA _scannedBytes; /**< The number of objects scanned in abort recovery/nonEvacuated regions in this compact group */72};7374MM_CopyForwardCompactGroupStats _edenStats; /**< Data about objects from Eden regions */75MM_CopyForwardCompactGroupStats _nonEdenStats; /**< Data about objects from non-Eden regions */7677UDATA _failedCopiedObjects; /**< The number of objects which the owning thread failed to copy in this compact group */78UDATA _failedCopiedBytes; /**< The number of bytes which the owning thread failed to copy in this compact group */79UDATA _freeMemoryMeasured; /**< The number of bytes which were wasted while this thread was working with the given _copyCache (due to alignment, etc) which is needs to save back into the pool when giving up the cache */80UDATA _discardedBytes; /**< The number of bytes discarded in survivor regions for this compact group by the owning thread due to incompletely filled copy caches and other inefficiencies */81UDATA _TLHRemainderCount; /**< number of TLHRemainders has been created for the compact group during the copyforward */82U_64 _allocationAge; /**< Average allocation age for this compact group */8384/* Mark map rebuilding cache values for the active MM_CopyScanCacheVLHGC associated with this group */85UDATA _markMapAtomicHeadSlotIndex; /**< Slot index of head which requires atomic update into the mark map (if any) */86UDATA _markMapAtomicTailSlotIndex; /**< Slot index of tail which requires atomic update into the mark map (if any) */87UDATA _markMapPGCSlotIndex; /**< Cached slot index for previous (PGC) mark map */88UDATA _markMapPGCBitMask; /**< Cached bit map mask being build for previous (PGC) mark map */89UDATA _markMapGMPSlotIndex; /**< Cached slot index for next (GMP) mark map */90UDATA _markMapGMPBitMask; /**< Cached bit map mask being build for previous (GMP) mark map */9192void initialize(MM_EnvironmentVLHGC *env) {93_copyCache = NULL;94_copyCacheLock = NULL;95_TLHRemainderBase = NULL;96_TLHRemainderTop = NULL;97_DFCopyBase = NULL;98_DFCopyAlloc = NULL;99_DFCopyTop = NULL;100_failedAllocateSize = UDATA_MAX;101_edenStats._copiedObjects = 0;102_edenStats._copiedBytes = 0;103_edenStats._liveObjects = 0;104_edenStats._liveBytes = 0;105_edenStats._scannedObjects = 0;106_edenStats._scannedBytes = 0;107_nonEdenStats._copiedObjects = 0;108_nonEdenStats._copiedBytes = 0;109_nonEdenStats._liveObjects = 0;110_nonEdenStats._liveBytes = 0;111_nonEdenStats._scannedObjects = 0;112_nonEdenStats._scannedBytes = 0;113_failedCopiedObjects = 0;114_failedCopiedBytes = 0;115_freeMemoryMeasured = 0;116_discardedBytes = 0;117_TLHRemainderCount = 0;118_allocationAge = 0;119_markMapAtomicHeadSlotIndex = 0;120_markMapAtomicTailSlotIndex = 0;121_markMapPGCSlotIndex = 0;122_markMapPGCBitMask = 0;123_markMapGMPSlotIndex = 0;124_markMapGMPBitMask = 0;125_regionManager = MM_GCExtensions::getExtensions(env)->heapRegionManager;126}127128/* function members */129private:130protected:131public:132MMINLINE void resetTLHRemainder()133{134_TLHRemainderBase = NULL;135_TLHRemainderTop = NULL;136}137138MMINLINE void setTLHRemainder(void* base, void* top)139{140_TLHRemainderBase = base;141_TLHRemainderTop = top;142_TLHRemainderCount += 1;143}144145MMINLINE uintptr_t getTLHRemainderSize()146{147return ((uintptr_t)_TLHRemainderTop - (uintptr_t)_TLHRemainderBase);148}149150MMINLINE void discardTLHRemainder(MM_EnvironmentVLHGC* env)151{152if (NULL != _TLHRemainderBase) {153discardTLHRemainder(env, _TLHRemainderBase, _TLHRemainderTop);154resetTLHRemainder();155} else {156Assert_MM_true(NULL == _TLHRemainderTop);157}158}159160MMINLINE void discardTLHRemainder(MM_EnvironmentVLHGC* env, void* base, void* top)161{162/* make it a walkable hole */163env->_cycleState->_activeSubSpace->abandonHeapChunk(base, top);164MM_HeapRegionDescriptorVLHGC *region = (MM_HeapRegionDescriptorVLHGC*)_regionManager->tableDescriptorForAddress(base);165discardHeapChunk(base, top, region);166}167168MMINLINE void recycleTLHRemainder(MM_EnvironmentVLHGC* env)169{170if (NULL != _TLHRemainderBase) {171/* make it a walkable hole */172env->_cycleState->_activeSubSpace->abandonHeapChunk(_TLHRemainderBase, _TLHRemainderTop);173MM_HeapRegionDescriptorVLHGC *region = (MM_HeapRegionDescriptorVLHGC*)_regionManager->tableDescriptorForAddress(_TLHRemainderBase);174region->getMemoryPool()->recycleHeapChunk(env, _TLHRemainderBase, _TLHRemainderTop);175resetTLHRemainder();176} else {177Assert_MM_true(NULL == _TLHRemainderTop);178}179}180181MMINLINE void discardHeapChunk(void* base, void* top, MM_HeapRegionDescriptorVLHGC* region)182{183uintptr_t discardSize = ((uintptr_t)top - (uintptr_t)base);184_discardedBytes += discardSize;185region->getMemoryPool()->incrementDarkMatterBytesAtomic(discardSize);186}187};188189#endif /* COPYFORWARDCOMPACTGROUP_HPP_ */190191192