Path: blob/master/runtime/gc_vlhgc/AllocationContextTarok.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122/**23* @file24* @ingroup GC_Modron_Base25*/2627#if !defined(ALLOCATIONCONTEXTTAROK_HPP_)28#define ALLOCATIONCONTEXTTAROK_HPP_2930#include "j9.h"31#include "j9cfg.h"32#include "j9protos.h"33#include "modronopt.h"3435#include "AllocationContext.hpp"36#include "LightweightNonReentrantLock.hpp"37#include "MemorySubSpace.hpp"38#include "RegionListTarok.hpp"3940class MM_EnvironmentBase;41class MM_HeapRegionDescriptorVLHGC;42class MM_HeapRegionManager;43class MM_MemorySubSpaceTarok;4445class MM_AllocationContextTarok : public MM_AllocationContext46{4748/* Data members / Types */49public:50enum AllocationContextType {51BALANCED = 0 /**< Represents a regular balanced AC */52, MULTI_TENANT = 1 /**< Represents a multi-tenant AC */53};54protected:55private:56const UDATA _allocationContextNumber; /**< A unique 0-indexed number assigned to this context instance (to be used for indexing into meta-data arrays, etc) */57const AllocationContextType _allocationContextType; /**< The type of this AC, set during instantiation and used for instanceof checks **/5859/* Methods */60public:6162/**63* @return The context number with which this instance was initialized64*/65UDATA getAllocationContextNumber() { return _allocationContextNumber; }6667/**68* @return The type of this allocation context.69*/70MMINLINE AllocationContextType getAllocationContextType() { return _allocationContextType; }7172/**73* Acquire a new region to be placed in the active set of regions from which to allocate.74* @param env GC thread.75* @return A region descriptor that has been acquired and put into the active to be consumed from rotation.76* @note This will immediately move the acquired region from _ownedRegions to _flushedRegions77*/78virtual MM_HeapRegionDescriptorVLHGC *collectorAcquireRegion(MM_EnvironmentBase *env) = 0;7980/**81* Perform an allocate of the given allocationType and return it. Note that the receiver can assume that either the context is locked or the calling thread has exclusive.82*83* @param[in] env The calling thread84* @param[in] objectAllocationInterface The allocation interface through which the original allocation call was initiated (only used by TLH allocations, can be NULL in other cases)85* @param[in] allocateDescription The description of the requested allocation86* @param[in] allocationType The type of allocation to perform87*88* @return The result of the allocation (NULL on failure)89*/90virtual void *lockedAllocate(MM_EnvironmentBase *env, MM_ObjectAllocationInterface *objectAllocationInterface, MM_AllocateDescription *allocateDescription, MM_MemorySubSpace::AllocationType allocationType) = 0;9192/**93* Called when the given region has been deemed empty, but is not a FREE region. The receiver is responsible for changing the region type and ensuring that it is appropriately stored.94* @param env[in] The calling thread (typically the main GC thread)95* @param region[in] The region to recycle96*/97virtual void recycleRegion(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC *region) = 0;9899/**100* Called during tear down of a subspace to discard any regions which comprise the subspace.101* The region should be FREE (not IDLE!) on completion of this call.102* @param env[in] The calling thread (typically the main GC thread)103* @param region[in] The region to tear down104*/105virtual void tearDownRegion(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region) = 0;106107/**108* Called during both expansion and during region recycling (if the region was owned by this context, it will come through this path when109* recycled). This method can only accept FREE regions.110* @param env[in] The thread which expanded the region or recycled it111* @param region[in] The region which should be added to our free list112*/113virtual void addRegionToFreeList(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region) = 0;114115/**116* Reset region count, used by TGC117* @param regionType type of the region that we reset the count for118*/119virtual void resetRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;120/**121* Increment region count, used by TGC122* @param regionType type of the region that we update the count for123*/124virtual void incRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;125126/**127* Return the region count associated with this AC, used by TGC128* @param regionType type of the region that we get the count for129* @return region count130*/131virtual UDATA getRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;132133/**134* Reset mutator count, used by TGC135*/136virtual void resetThreadCount() = 0;137138/**139* Increment mutator count, used by TGC140*/141virtual void incThreadCount() = 0;142143/**144* Return the mutator count associated with this AC, used by TGC145*146* @return mutator count147*/148virtual UDATA getThreadCount() = 0;149150/**151* Return the NUMA node with which this AC is associated, or 0 if none152*153* @return associated NUMA node154*/155virtual UDATA getNumaNode() = 0;156157/**158* Return the amount of free memory currently managed by the context. This value is always accurate (that is, there is no time when it becomes159* out of sync with the actual amount of free memory managed by the context).160*161* @return The free memory managed by the receiver, in bytes.162*/163virtual UDATA getFreeMemorySize() = 0;164165/**166* Return the number of free (empty) regions currently managed by the context. This value is always accurate (that is, there is no time when it becomes167* out of sync with the actual number of regions managed by the context).168*169* @return The count of free regions managed by the receiver.170*/171virtual UDATA getFreeRegionCount() = 0;172173/**174* Called to reset the largest free entry in all the MemoryPoolBumpPointer instances in the regions managed by the receiver.175*/176virtual void resetLargestFreeEntry() = 0;177178/**179* @return The largest free entry out of all the pools managed by the receiver.180*/181virtual UDATA getLargestFreeEntry() = 0;182183/**184* Called to move the given region directly from the receiver and into the target context instance. Note that this method can only185* be called in one thread on any instance since it directly manipulates lists across contexts. The caller is responsible for186* ensuring that these threading semantics are preserved.187* @param region[in] The region to migrate from the receiver188* @param newOwner[in] The context to which the given region is being migrated189*/190virtual void migrateRegionToAllocationContext(MM_HeapRegionDescriptorVLHGC *region, MM_AllocationContextTarok *newOwner) = 0;191192/**193* Called by migrateRegionToAllocationContext on the target context receiving the migrated region.194* The receiver will insert the migrated context in its list.195*196* @param region[in] The region to accept197*/198virtual void acceptMigratingRegion(MM_HeapRegionDescriptorVLHGC *region) = 0;199200/**201* This helper merely forwards the resetHeapStatistics call on to all the memory pools owned by the receiver.202* @param globalCollect[in] True if this was a global collect (blindly passed through)203*/204virtual void resetHeapStatistics(bool globalCollect) = 0;205206/**207* This helper merely forwards the mergeHeapStats call on to all the memory pools owned by the receiver.208* @param heapStats[in/out] The stats structure to receive the merged data (blindly passed through)209* @param includeMemoryType[in] The memory space type to use in the merge (blindly passed through)210*/211virtual void mergeHeapStats(MM_HeapStats *heapStats, UDATA includeMemoryType) = 0;212213/**214* Used by TGC to get the count of regions owned by this context. Differentiates between regions node-local to the context and node-foreign.215* @param localCount[out] The number of regions owned by the receiver which are bound to the node in which the receiver logically operates216* @param foreignCount[out] The number of regions owned by the receiver which are NOT bound to the node in which the receiver logically operates217*/218virtual void getRegionCount(UDATA *localCount, UDATA *foreignCount) = 0;219220/**221* Remove the specified region from the flushed regions list.222*223* @param region[in] The region to remove from the list224*/225virtual void removeRegionFromFlushedList(MM_HeapRegionDescriptorVLHGC *region) = 0;226227/**228* Set the NUMA affinity for the current thread.229* @param env[in] the current thread230* @return true upon success, false otherwise231*/232virtual bool setNumaAffinityForThread(MM_EnvironmentBase *env) = 0;233234/**235* Clear the NUMA affinity of the current thread.236* Call the thread library to bind the thread to all eligible CPUs.237* @param env[in] the current thread238* @see MM_RuntimeExecManager239*/240MMINLINE void clearNumaAffinityForThread(MM_EnvironmentBase *env) { env->setNumaAffinity(NULL, 0); }241242/**243* Determines whether or not a region should be migrated to the common context.244*245* @param env[in] The current GC thread246* @param region[in] The VLHGC region247*/248virtual bool shouldMigrateRegionToCommonContext(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region);249250protected:251MM_AllocationContextTarok(UDATA allocationContextNumber, AllocationContextType allocationContextType)252: MM_AllocationContext()253, _allocationContextNumber(allocationContextNumber)254, _allocationContextType(allocationContextType)255{256_typeId = __FUNCTION__;257}258259/**260* Replenish the receiver to satisfy the given allocation description and type and then re-attempt the allocation, returning the result.261* @note The calling env must own the receiver's _contextLock or have exclusive VM access262*263* @param env[in] A GC thread (must own either _contextLock or have exclusive access)264* @param objectAllocationInterface[in] If this is a TLH allocation request, this will be the interface used to initialize the TLH (is NULL in non-TLH allocations)265* @param allocateDescription[in] A description of the allocate266* @param allocationType[in] The type of the allocation267* @return The base address of the allocation or NULL in the case of failure268*/269virtual void *lockedReplenishAndAllocate(MM_EnvironmentBase *env, MM_ObjectAllocationInterface *objectAllocationInterface, MM_AllocateDescription *allocateDescription, MM_MemorySubSpace::AllocationType allocationType) = 0;270271/**272* Select a region for contraction from the receiver.273* The returned region will be region type FREE.274* @param env the environment275* @return the region to contract, or NULL if none available276*/277virtual MM_HeapRegionDescriptorVLHGC * selectRegionForContraction(MM_EnvironmentBase *env) = 0;278279private:280281/*282* Friends283*/284/* the MSST is currently responsible for replenishing the ACT so let it reach in to update the regions in the cache */285friend class MM_MemorySubSpaceTarok;286287};288289#endif /* ALLOCATIONCONTEXTTAROK_HPP */290291292