Path: blob/master/runtime/gc_vlhgc/GlobalAllocationManagerTarok.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2019 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*******************************************************************************/222324#if !defined(GLOBALALLOCATIONMANAGERTAROK_HPP_)25#define GLOBALALLOCATIONMANAGERTAROK_HPP_2627#include "j9.h"28#include "j9cfg.h"29#include "j9protos.h"30#include "j9consts.h"31#include "modronopt.h"3233#include "GlobalAllocationManager.hpp"3435#include "AllocationContextBalanced.hpp"36#include "AllocationContextTarok.hpp"37#include "GCExtensions.hpp"38#include "LightweightNonReentrantLock.hpp"39#include "MemoryPool.hpp"40#include "RuntimeExecManager.hpp"4142class MM_AllocationContextBalanced;43class MM_EnvironmentBase;44class MM_HeapRegionDescriptorVLHGC;45class MM_MemorySubSpaceTarok;46class MM_RegionListTarok;4748class MM_GlobalAllocationManagerTarok : public MM_GlobalAllocationManager49{50/* Data members & types */51public:52protected:53private:54MM_AllocationContextBalanced **_perNodeContextSets; /**< an array which is extensions->numaNodes elements long, containing the "first" AllocationContextVLHGC in each corresponding per-node circular list */5556MM_RuntimeExecManager _runtimeExecManager; /**< A helper object used to intercept Runtime.exec() and manage affinity to workaround limitations on Linux */575859friend class MM_RuntimeExecManager;6061/* Methods */62public:63static MM_GlobalAllocationManagerTarok *newInstance(MM_EnvironmentBase *env);64virtual void kill(MM_EnvironmentBase *env);65virtual bool acquireAllocationContext(MM_EnvironmentBase *env);66virtual void releaseAllocationContext(MM_EnvironmentBase *env);67virtual void printAllocationContextStats(MM_EnvironmentBase *env, UDATA eventNum, J9HookInterface** hookInterface);68/**69* Called after the receiver and the subspace have been initialized to request that the receiver build the allocation contexts70* it will manager over the course of the run. The subspace is required because the allocation contexts need to know which71* subspace logically "owns" its memory.72* @param env[in] The current thread (this is the thread bootstrapping the VM)73* @param subspace[in] The subspace which logically owns the memory managed by the contexts the receiver is called to create74* @return Whether or not all the contexts were successfully initialized75*/76bool initializeAllocationContexts(MM_EnvironmentBase *env, MM_MemorySubSpaceTarok *subspace);7778/**79* @return The actual free memory size of all the regions managed by the contexts under the receiver80*/81UDATA getActualFreeMemorySize();82/**83* @return The approximate free memory size of all the regions managed by the contexts under the receiver84*/85UDATA getApproximateFreeMemorySize();8687/**88* Return the number of free (empty) regions managed by the contexts under the receiver.89*90* @return The count of free regions managed by the contexts under the receiver.91*/92UDATA getFreeRegionCount();9394/**95* Forwarded to the all the MemoryPoolBumpPointer instances managed by the contexts under the receiver96*/97void resetLargestFreeEntry();98/**99* Expands into the given region by finding an AllocationContextTarok to manage it. Once this method returns, the given region will100* be managed by a context.101* @param env[in] The thread performing the expansion102* @param region[in] The region which was just expanded103*/104void expand(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region);105/**106* @return The largest free entry of all the regions managed by the contexts under the receiver107*/108UDATA getLargestFreeEntry();109110/**111* This helper merely forwards the resetHeapStatistics call on to all the AllocationContextTarok instances owned by the receiver.112* @param globalCollect[in] True if this was a global collect (blindly passed through)113*/114void resetHeapStatistics(bool globalCollect);115116/**117* This helper merely forwards the mergeHeapStats call on to all the AllocationContextTarok instances owned by the receiver.118* @param heapStats[in/out] The stats structure to receive the merged data (blindly passed through)119* @param includeMemoryType[in] The memory space type to use in the merge (blindly passed through)120*/121void mergeHeapStats(MM_HeapStats *heapStats, UDATA includeMemoryType);122123/**124* Get the total number of allocation contexts including the non-managed ones if any.125* @return the total allocation context count.126*/127MMINLINE UDATA getTotalAllocationContextCount()128{129UDATA totalCount = _managedAllocationContextCount;130return totalCount;131}132133/**134* Get the total number of managed allocation contexts, not including the non-managed ones if any.135* @return the managed allocation context count.136*/137MMINLINE UDATA getManagedAllocationContextCount()138{139return _managedAllocationContextCount;140}141142/**143* @param extensions[in] The global GC extensions144* @return The ideal number of total allocation contexts (managed + non-managed) with which the receiver assumes it is working145*/146static UDATA calculateIdealTotalContextCount(MM_GCExtensions *extensions);147148/**149* @param extensions[in] The global GC extensions150* @return The ideal number of managed allocation contexts with which the receiver assumes it is working151*/152static UDATA calculateIdealManagedContextCount(MM_GCExtensionsBase *extensions);153154virtual MM_AllocationContextTarok *getAllocationContextByIndex(UDATA index) {155156return (MM_AllocationContextTarok *)MM_GlobalAllocationManager::getAllocationContextByIndex(index);157}158159160161/**162* Find the allocation context for the specified NUMA node.163* @param numaNode the NUMA node to search for164* @return the associated context165*/166MM_AllocationContextBalanced *getAllocationContextForNumaNode(UDATA numaNode);167168169protected:170bool initialize(MM_EnvironmentBase *env);171virtual void tearDown(MM_EnvironmentBase *env);172MM_GlobalAllocationManagerTarok(MM_EnvironmentBase *env)173: MM_GlobalAllocationManager(env)174, _perNodeContextSets(NULL)175, _runtimeExecManager(env)176{177_typeId = __FUNCTION__;178};179private:180181/**182* Determine if the current thread should be a common thread (non-affinitized) .183*184* @param env[in] the current thread185* @return true if the thread should be treated as common, false otherwise186*/187bool shouldIdentifyThreadAsCommon(MM_EnvironmentBase *env);188189};190191#endif /* GLOBALALLOCATIONMANAGERTAROK_HPP_ */192193194