Path: blob/master/runtime/gc_vlhgc/CopyScanCacheListVLHGC.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2014 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(COPYSCANCACHELISTVLHGC_HPP_)29#define COPYSCANCACHELISTVLHGC_HPP_3031#include "j9.h"32#include "j9consts.h"33#include "modronopt.h"3435#include "BaseVirtual.hpp"36#include "EnvironmentVLHGC.hpp"37#include "LightweightNonReentrantLock.hpp"3839class MM_CopyScanCacheVLHGC;40class MM_CopyScanCacheChunkVLHGC;4142/**43* @todo Provide class documentation44* @ingroup GC_Modron_Standard45*/46class MM_CopyScanCacheListVLHGC : public MM_BaseVirtual47{48public:49private:50struct CopyScanCacheSublist {51MM_CopyScanCacheVLHGC *_cacheHead;52MM_LightweightNonReentrantLock _cacheLock;53} *_sublists;54UDATA _sublistCount; /**< the number of lists (split for parallelism). Must be at least 1 */55MM_CopyScanCacheChunkVLHGC *_chunkHead;56UDATA _totalEntryCount;57bool _containsHeapAllocatedChunks; /**< True if there are heap-allocated scan cache chunks on the _chunkHead list */5859private:60bool appendCacheEntries(MM_EnvironmentVLHGC *env, UDATA cacheEntryCount);6162/**63* Determine the sublist index for the specified thread.64* @return the index (a valid index into _sublists)65*/66UDATA getSublistIndex(MM_EnvironmentVLHGC *env) { return env->getEnvironmentId() % _sublistCount; }6768/**69* Add the specified entry to this list. It is the caller's responsibility to provide synchronization.70* @param env[in] the current GC thread71* @param cacheEntry[in] the cache entry to add72* @param sublist[in] the sublist to push to73*/74void pushCacheInternal(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry, CopyScanCacheSublist* sublist);7576/**77* Pop a cache entry from this list. It is the caller's responsibility to provide synchronization.78* @param env[in] the current GC thread79* @param sublist[in] the sublist to pop from80* @return the cache entry, or NULL if the list is empty81*/82MM_CopyScanCacheVLHGC *popCacheInternal(MM_EnvironmentVLHGC *env, CopyScanCacheSublist* sublist);8384public:85bool initialize(MM_EnvironmentVLHGC *env);86virtual void tearDown(MM_EnvironmentVLHGC *env);8788/**89* Resizes the number of cache entries.90*91* @param env[in] A GC thread92* @param totalCacheEntryCount[in] The number of cache entries which this list should be resized to contain93*/94bool resizeCacheEntries(MM_EnvironmentVLHGC *env, UDATA totalCacheEntryCount);9596/**97* Removes any heap-allocated scan cache chunks from the receiver's chunk list (calls tearDown on them after removing them from the list).98* @param env[in] A GC thread99*/100void removeAllHeapAllocatedChunks(MM_EnvironmentVLHGC *env);101102/**103* Allocates an on-heap scan cache in the bufferLengthInBytes of memory starting at buffer.104* @param env[in] A GC thread105* @param buffer[in] The base address of the memory extent on which the receiver should allocate a scan cache chunk106* @param bufferLengthInBytes[in] The length, in bytes, of the memory extent starting at buffer107* @return A new cache entry if the chunk was successfully allocated and inserted into the receiver's chunk list, NULL if a failure occurred108*/109MM_CopyScanCacheVLHGC * allocateCacheEntriesInExistingMemory(MM_EnvironmentVLHGC *env, void *buffer, UDATA bufferLengthInBytes);110111/**112* Lock the receiver to prevent concurrent modification.113* @note that pushCache() and popCache() lock internally, so this is only required for heavyweight operations.114*/115void lock();116117/**118* Unlock the receiver from concurrent modification.119* @note that pushCache() and popCache() lock internally, so this is only required for heavy weight operations.120*/121void unlock();122123/**124* Add the specified entry to this list. It is the caller's responsibility to provide synchronization.125* @param env[in] the current GC thread126* @param cacheEntry[in] the cache entry to add127*/128void pushCacheNoLock(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry);129130/**131* Pop a cache entry from this list. It is the caller's responsibility to provide synchronization.132* @param env[in] the current GC thread133* @return the cache entry, or NULL if the list is empty134*/135MM_CopyScanCacheVLHGC *popCacheNoLock(MM_EnvironmentVLHGC *env);136137/**138* Add the specified entry to this list.139* @param env[in] the current GC thread140* @param cacheEntry[in] the cache entry to add141*/142void pushCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry);143144/**145* Pop a cache entry from this list.146* @param env[in] the current GC thread147* @return the cache entry, or NULL if the list is empty148*/149MM_CopyScanCacheVLHGC *popCache(MM_EnvironmentVLHGC *env);150151/**152* Determine if the list is empty.153* @return true if the list is empty, false otherwise154*/155bool isEmpty();156157/**158* Determine how many caches are in the receiver's lists.159* Note that this is not thread safe. The receiver must be locked.160* The implementation walks all caches, so this should only be used for debugging.161* @return the total number of caches in the receiver's lists162*/163UDATA countCaches();164165/**166* Answer the total number of caches owned by the receiver, whether or not they are currently in the receiver's lists.167* @return total number of caches168*/169UDATA getTotalCacheCount() { return _totalEntryCount; }170171/**172* Create a CopyScanCacheList object.173*/174MM_CopyScanCacheListVLHGC();175176};177178#endif /* COPYSCANCACHELISTVLHGC_HPP_ */179180181