Path: blob/master/runtime/gc_base/GCExtensions.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_Base26*/2728#if !defined(GCEXTENSIONS_HPP_)29#define GCEXTENSIONS_HPP_3031#include <string.h>3233#include "arrayCopyInterface.h"34#include "j9cfg.h"35#include "j9comp.h"36#include "omrhookable.h"37#include "mmhook_internal.h"38#include "modronbase.h"39#include "omr.h"40#include "omrmodroncore.h"4142#include "EnvironmentBase.hpp"43#include "GCExtensionsBase.hpp"44#include "MarkJavaStats.hpp"45#include "OMRVMThreadListIterator.hpp"46#include "VMThreadListIterator.hpp"47#include "VerboseGCInterface.h"4849#if defined(J9VM_GC_MODRON_SCAVENGER)50#include "ScavengerJavaStats.hpp"51#endif /* J9VM_GC_MODRON_SCAVENGER */5253class MM_ClassLoaderManager;54class MM_EnvironmentBase;55class MM_HeapMap;56class MM_MemorySubSpace;57class MM_ObjectAccessBarrier;58class MM_OwnableSynchronizerObjectList;59class MM_StringTable;60class MM_UnfinalizedObjectList;61class MM_Wildcard;6263#if defined(J9VM_GC_FINALIZATION)64class GC_FinalizeListManager;65#endif /* J9VM_GC_FINALIZATION */6667#if defined(J9VM_GC_REALTIME)68class MM_ReferenceObjectList;69#endif /* J9VM_GC_REALTIME */7071#if defined(OMR_GC_IDLE_HEAP_MANAGER)72class MM_IdleGCManager;73#endif7475#define DEFAULT_SURVIVOR_MINIMUM_FREESIZE 204876#define DEFAULT_SURVIVOR_THRESHOLD 51277#define MAXIMUM_SURVIVOR_MINIMUM_FREESIZE 52428878#define MAXIMUM_SURVIVOR_THRESHOLD 819279#define MINIMUM_SURVIVOR_MINIMUM_FREESIZE 51280#define MINIMUM_SURVIVOR_THRESHOLD 5128182/**83* @todo Provide class documentation84* @ingroup GC_Base85*/86class MM_GCExtensions : public MM_GCExtensionsBase {87private:88MM_OwnableSynchronizerObjectList* ownableSynchronizerObjectLists; /**< The global linked list of ownable synchronizer object lists. */89public:90MM_StringTable* stringTable; /**< top level String Table structure (internally organized as a set of hash sub-tables */9192void* gcchkExtensions;9394void* tgcExtensions;95J9MemoryManagerVerboseInterface verboseFunctionTable;9697#if defined(J9VM_GC_FINALIZATION)98IDATA finalizeCycleInterval;99IDATA finalizeCycleLimit;100#endif /* J9VM_GC_FINALIZATION */101102MM_HookInterface hookInterface;103104bool collectStringConstants;105106MM_MarkJavaStats markJavaStats;107#if defined(J9VM_GC_MODRON_SCAVENGER)108MM_ScavengerJavaStats scavengerJavaStats;109#endif /* J9VM_GC_MODRON_SCAVENGER */110111#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)112enum DynamicClassUnloading {113DYNAMIC_CLASS_UNLOADING_NEVER,114DYNAMIC_CLASS_UNLOADING_ON_CLASS_LOADER_CHANGES,115DYNAMIC_CLASS_UNLOADING_ALWAYS116};117DynamicClassUnloading dynamicClassUnloading;118119bool dynamicClassUnloadingSet; /**< is true if value for dynamicClassUnloading was specified in command line */120121UDATA runtimeCheckDynamicClassUnloading;122bool dynamicClassUnloadingKickoffThresholdForced; /**< true if classUnloadingKickoffThreshold is specified in java options. */123bool dynamicClassUnloadingThresholdForced; /**< true if classUnloadingThresholdForced is specified in java options. */124UDATA dynamicClassUnloadingKickoffThreshold; /**< the threshold to kickoff a concurrent global GC from a scavenge */125UDATA dynamicClassUnloadingThreshold; /**< the threshold to trigger class unloading during a global GC */126double classUnloadingAnonymousClassWeight; /**< The weight factor to apply to anonymous classes for threshold comparisons */127#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */128129U_32 _stringTableListToTreeThreshold; /**< Threshold at which we start using trees instead of lists for collision resolution in the String table */130131#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)132bool fvtest_forceFinalizeClassLoaders;133#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */134135UDATA maxSoftReferenceAge; /**< The fixed age specified as the soft reference threshold which acts as our baseline for the dynamicMaxSoftReferenceAge */136UDATA dynamicMaxSoftReferenceAge; /**< The age which represents the clearing age of soft references for a globalGC cycle. At the end of a GC cycle, it will be updated for the following cycle by taking the percentage of free heap in the oldest generation as a fraction of the maxSoftReferenceAge */137#if defined(J9VM_GC_FINALIZATION)138GC_FinalizeListManager* finalizeListManager;139#endif /* J9VM_GC_FINALIZATION */140141J9ReferenceArrayCopyTable referenceArrayCopyTable;142143#if defined(J9VM_GC_REALTIME)144MM_ReferenceObjectList* referenceObjectLists; /**< A global array of lists of reference objects (i.e. weak/soft/phantom) */145#endif /* J9VM_GC_REALTIME */146MM_ObjectAccessBarrier* accessBarrier;147148#if defined(J9VM_GC_FINALIZATION)149UDATA finalizeMainPriority; /**< cmd line option to set finalize main thread priority */150UDATA finalizeWorkerPriority; /**< cmd line option to set finalize worker thread priority */151#endif /* J9VM_GC_FINALIZATION */152153MM_ClassLoaderManager* classLoaderManager; /**< Pointer to the gc's classloader manager to process classloaders/classes */154#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)155UDATA deadClassLoaderCacheSize;156#endif /*defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */157158MM_UnfinalizedObjectList* unfinalizedObjectLists; /**< The global linked list of unfinalized object lists. */159160UDATA objectListFragmentCount; /**< the size of Local Object Buffer(per gc thread), used by referenceObjectBuffer, UnfinalizedObjectBuffer and OwnableSynchronizerObjectBuffer */161162MM_Wildcard* numaCommonThreadClassNamePatterns; /**< A linked list of thread class names which should be associated with the common context */163164struct {165MM_UserSpecifiedParameterUDATA _Xmn; /**< Initial value of -Xmn specified by the user */166MM_UserSpecifiedParameterUDATA _Xmns; /**< Initial value of -Xmns specified by the user */167MM_UserSpecifiedParameterUDATA _Xmnx; /**< Initial value of -Xmnx specified by the user */168} userSpecifiedParameters;169170/**171* Values for com.ibm.oti.vm.VM.J9_JIT_STRING_DEDUP_POLICY172* must hava the same values as J9_JIT_STRING_DEDUP_POLICY_DISABLED, J9_JIT_STRING_DEDUP_POLICY_FAVOUR_LOWER and J9_JIT_STRING_DEDUP_POLICY_FAVOUR_HIGHER.173*/174enum JitStringDeDupPolicy {175J9_JIT_STRING_DEDUP_POLICY_DISABLED = 0,176J9_JIT_STRING_DEDUP_POLICY_FAVOUR_LOWER = 1,177J9_JIT_STRING_DEDUP_POLICY_FAVOUR_HIGHER = 2,178J9_JIT_STRING_DEDUP_POLICY_UNDEFINED = 3,179};180JitStringDeDupPolicy stringDedupPolicy;181182IDATA _asyncCallbackKey;183IDATA _TLHAsyncCallbackKey;184185bool _HeapManagementMXBeanBackCompatibilityEnabled;186187#if defined(OMR_GC_IDLE_HEAP_MANAGER)188MM_IdleGCManager* idleGCManager; /**< Manager which registers for VM Runtime State notification & manages free heap on notification */189#endif190191double maxRAMPercent; /**< Value of -XX:MaxRAMPercentage specified by the user */192double initialRAMPercent; /**< Value of -XX:InitialRAMPercentage specified by the user */193UDATA minimumFreeSizeForSurvivor; /**< minimum free size can be reused by collector as survivor, for balanced GC only */194UDATA freeSizeThresholdForSurvivor; /**< if average freeSize(freeSize/freeCount) of the region is smaller than the Threshold, the region would not be reused by collector as survivor, for balanced GC only */195bool recycleRemainders; /**< true if need to recycle TLHRemainders at the end of PGC, for balanced GC only */196197protected:198private:199protected:200virtual bool initialize(MM_EnvironmentBase* env);201virtual void tearDown(MM_EnvironmentBase* env);202203public:204static MM_GCExtensions* newInstance(MM_EnvironmentBase* env);205virtual void kill(MM_EnvironmentBase* env);206207void computeDefaultMaxHeapForJava(bool enableOriginalJDK8HeapSizeCompatibilityOption);208209MMINLINE J9HookInterface** getHookInterface() { return J9_HOOK_INTERFACE(hookInterface); };210211/**212* Fetch the global string table instance.213* @return the string table214*/215MMINLINE MM_StringTable* getStringTable() { return stringTable; }216217MMINLINE UDATA getDynamicMaxSoftReferenceAge()218{219return dynamicMaxSoftReferenceAge;220}221222MMINLINE UDATA getMaxSoftReferenceAge()223{224return maxSoftReferenceAge;225}226227virtual void identityHashDataAddRange(MM_EnvironmentBase* env, MM_MemorySubSpace* subspace, UDATA size, void* lowAddress, void* highAddress);228virtual void identityHashDataRemoveRange(MM_EnvironmentBase* env, MM_MemorySubSpace* subspace, UDATA size, void* lowAddress, void* highAddress);229230void updateIdentityHashDataForSaltIndex(UDATA index);231232/**233* Set Tenure address range234* @param base low address of Old subspace range235* @param size size of Old subspace in bytes236*/237virtual void setTenureAddressRange(void* base, UDATA size)238{239_tenureBase = base;240_tenureSize = size;241242/* todo: dagar move back to MemorySubSpaceGeneric addTenureRange() and removeTenureRange() once243* heapBaseForBarrierRange0 heapSizeForBarrierRange0 can be removed from J9VMThread244*245* setTenureAddressRange() can be removed fromo GCExtensions.hpp and made inline again246*/247GC_OMRVMThreadListIterator omrVMThreadListIterator(_omrVM);248while (OMR_VMThread* walkThread = omrVMThreadListIterator.nextOMRVMThread()) {249walkThread->lowTenureAddress = heapBaseForBarrierRange0;250walkThread->highTenureAddress = (void*)((UDATA)heapBaseForBarrierRange0 + heapSizeForBarrierRange0);251walkThread->heapBaseForBarrierRange0 = heapBaseForBarrierRange0;252walkThread->heapSizeForBarrierRange0 = heapSizeForBarrierRange0;253}254255GC_VMThreadListIterator vmThreadListIterator((J9JavaVM*)_omrVM->_language_vm);256while (J9VMThread* walkThread = vmThreadListIterator.nextVMThread()) {257walkThread->lowTenureAddress = heapBaseForBarrierRange0;258walkThread->highTenureAddress = (void*)((UDATA)heapBaseForBarrierRange0 + heapSizeForBarrierRange0);259walkThread->heapBaseForBarrierRange0 = heapBaseForBarrierRange0;260walkThread->heapSizeForBarrierRange0 = heapSizeForBarrierRange0;261}262}263264265static MM_GCExtensions* getExtensions(OMR_VM* omrVM) { return static_cast<MM_GCExtensions*>(MM_GCExtensionsBase::getExtensions(omrVM)); }266static MM_GCExtensions* getExtensions(OMR_VMThread* omrVMThread) { return static_cast<MM_GCExtensions*>(MM_GCExtensionsBase::getExtensions(omrVMThread->_vm)); }267static MM_GCExtensions* getExtensions(J9JavaVM* javaVM) { return static_cast<MM_GCExtensions*>(MM_GCExtensionsBase::getExtensions(javaVM->omrVM)); }268static MM_GCExtensions* getExtensions(J9VMThread* vmThread) { return getExtensions(vmThread->javaVM); }269static MM_GCExtensions* getExtensions(MM_GCExtensionsBase* ext) { return static_cast<MM_GCExtensions*>(ext); }270static MM_GCExtensions* getExtensions(MM_EnvironmentBase* env) { return getExtensions(env->getExtensions()); }271272MMINLINE J9JavaVM* getJavaVM() {return static_cast<J9JavaVM*>(_omrVM->_language_vm);}273274/**275* Return ownable synchronizer object lists by first ensuring that the lists are in a consistent state (e.g., during concurrent gc).276* This should be used by any external consumer (non-GC consuming the list)277* @param vmThread The current J9VMThread thread (used to invoke j9gc apis if required)278* @return Linked list of ownable synchronizer objects279*/280MM_OwnableSynchronizerObjectList* getOwnableSynchronizerObjectListsExternal(J9VMThread *vmThread);281MMINLINE MM_OwnableSynchronizerObjectList* getOwnableSynchronizerObjectLists() { return ownableSynchronizerObjectLists; }282MMINLINE void setOwnableSynchronizerObjectLists(MM_OwnableSynchronizerObjectList* newOwnableSynchronizerObjectLists) { ownableSynchronizerObjectLists = newOwnableSynchronizerObjectLists; }283284/**285* Create a GCExtensions object286*/287MM_GCExtensions()288: MM_GCExtensionsBase()289, ownableSynchronizerObjectLists(NULL)290, stringTable(NULL)291, gcchkExtensions(NULL)292, tgcExtensions(NULL)293#if defined(J9VM_GC_FINALIZATION)294, finalizeCycleInterval(J9_FINALIZABLE_INTERVAL) /* 1/2 second */295, finalizeCycleLimit(0) /* 0 seconds (i.e. no time limit) */296#endif /* J9VM_GC_FINALIZATION */297#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)298, dynamicClassUnloadingSet(false)299, dynamicClassUnloadingKickoffThresholdForced(false)300, dynamicClassUnloadingThresholdForced(false)301, dynamicClassUnloadingKickoffThreshold(0)302, dynamicClassUnloadingThreshold(0)303, classUnloadingAnonymousClassWeight(1.0)304#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */305, _stringTableListToTreeThreshold(1024)306, maxSoftReferenceAge(32)307#if defined(J9VM_GC_FINALIZATION)308, finalizeMainPriority(J9THREAD_PRIORITY_NORMAL)309, finalizeWorkerPriority(J9THREAD_PRIORITY_NORMAL)310#endif /* J9VM_GC_FINALIZATION */311, classLoaderManager(NULL)312#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)313, deadClassLoaderCacheSize(1024 * 1024) /* default is one MiB */314#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */315, unfinalizedObjectLists(NULL)316, objectListFragmentCount(0)317, numaCommonThreadClassNamePatterns(NULL)318, stringDedupPolicy(J9_JIT_STRING_DEDUP_POLICY_UNDEFINED)319, _asyncCallbackKey(-1)320, _TLHAsyncCallbackKey(-1)321, _HeapManagementMXBeanBackCompatibilityEnabled(false)322#if defined(OMR_GC_IDLE_HEAP_MANAGER)323, idleGCManager(NULL)324#endif325, maxRAMPercent(0.0) /* this would get overwritten by user specified value */326, initialRAMPercent(0.0) /* this would get overwritten by user specified value */327, minimumFreeSizeForSurvivor(DEFAULT_SURVIVOR_MINIMUM_FREESIZE)328, freeSizeThresholdForSurvivor(DEFAULT_SURVIVOR_THRESHOLD)329, recycleRemainders(true)330{331_typeId = __FUNCTION__;332}333};334335#endif /* GCEXTENSIONS_HPP_ */336337338