Path: blob/master/runtime/gc_realtime/EnvironmentRealtime.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#if !defined(ENVIRONMENTREALTIME_HPP_)23#define ENVIRONMENTREALTIME_HPP_2425#include "Base.hpp"26#include "EnvironmentBase.hpp"27#include "GCExtensionsBase.hpp"28#include "OSInterface.hpp"29#include "Scheduler.hpp"3031class MM_AllocationContextRealtime;32class MM_HeapRegionDescriptorRealtime;33class MM_RealtimeRootScanner;34class MM_Timer;3536class MM_EnvironmentRealtime : public MM_EnvironmentBase37{38/* Data section */39public:40volatile U_32 _monitorCacheCleared; /**< Flag field to indicate whether the monitor lookup cache has been cleared on the thread */4142protected:43private:44MM_Scheduler *_scheduler;45MM_RealtimeRootScanner *_rootScanner;4647MM_OSInterface *_osInterface;4849I_32 _yieldDisableDepth;5051uintptr_t _scannedObjects; /**< Number of objects scanned in current major GC */5253MM_HeapRegionDescriptorRealtime **_overflowCache; /**< Local cache of overflowed regions. Can only be manipulated by IncrementalOverflow */54uintptr_t _overflowCacheCount; /**< Count of used elements in the _overflowCache array. Can on be manipulated by IncrementalOverflow */55MM_Timer *_timer;5657U_32 _distanceToYieldTimeCheck; /**< Number of condYield that can be skipped before actual checking for yield, when the quanta time has been relaxed */58U_32 _currentDistanceToYieldTimeCheck; /**< The current remaining number of condYield calls to be skipped before the next actual yield check */5960/* Functionality Section */6162public:63static MM_EnvironmentRealtime *newInstance(MM_GCExtensionsBase *extensions, OMR_VMThread *omrVMThread);64virtual void kill();6566MMINLINE static MM_EnvironmentRealtime *getEnvironment(OMR_VMThread *omrVMThread) { return static_cast<MM_EnvironmentRealtime*>(omrVMThread->_gcOmrVMThreadExtensions); }67MMINLINE static MM_EnvironmentRealtime *getEnvironment(MM_EnvironmentBase *ptr) { return (MM_EnvironmentRealtime *)ptr; }6869MM_Scheduler *getScheduler() const { return _scheduler; }7071MM_AllocationContextRealtime *getAllocationContext() const { return (MM_AllocationContextRealtime *)MM_EnvironmentBase::getAllocationContext(); }72void setAllocationContext(MM_AllocationContextRealtime *allocContext) { MM_EnvironmentBase::setAllocationContext((MM_AllocationContext *)allocContext); }7374U_32 getMonitorCacheCleared() const { return _monitorCacheCleared; }75void setMonitorCacheCleared(U_32 monitorCacheCleared) { _monitorCacheCleared = monitorCacheCleared; }7677/* Maintains a recursive count of _not_ being able to yield.78* Initially the depth is zero indicating that it can yield.79*/80void disableYield();81void enableYield();82I_32 getYieldDisableDepth() const { return _yieldDisableDepth; }8384MMINLINE U_32 getCurrentDistanceToYieldTimeCheck() { return _currentDistanceToYieldTimeCheck; }85MMINLINE void resetCurrentDistanceToYieldTimeCheck()86{87if(0 != _distanceToYieldTimeCheck) {88_currentDistanceToYieldTimeCheck = _distanceToYieldTimeCheck;89}90}91MMINLINE bool hasDistanceToYieldTimeCheck()92{93bool shouldSkipTimeCheck = (0 != _currentDistanceToYieldTimeCheck);94if (shouldSkipTimeCheck) {95--_currentDistanceToYieldTimeCheck;96}97return shouldSkipTimeCheck;98}99100void reportScanningSuspended();101void reportScanningResumed();102103void setRootScanner(MM_RealtimeRootScanner *rootScanner) { _rootScanner = rootScanner; }104105uintptr_t getScannedObjects() const { return _scannedObjects; }106void incScannedObjects() { _scannedObjects++; }107void resetScannedCounters()108{109_scannedObjects = 0;110}111MM_Timer *getTimer() {return _timer;}112113MMINLINE uintptr_t getOverflowCacheUsedCount() {return _overflowCacheCount;}114MMINLINE void incrementOverflowCacheUsedCount() {_overflowCacheCount += 1;}115MMINLINE void resetOverflowCacheUsedCount() {_overflowCacheCount = 0;}116MMINLINE MM_HeapRegionDescriptorRealtime **getOverflowCache() {return _overflowCache;}117118MM_EnvironmentRealtime(OMR_VMThread *omrVMThread) :119MM_EnvironmentBase(omrVMThread),120_scheduler((MM_Scheduler *)MM_GCExtensionsBase::getExtensions(omrVMThread->_vm)->dispatcher),121_rootScanner(NULL),122_osInterface(_scheduler->_osInterface),123_overflowCache(NULL),124_overflowCacheCount(0),125_timer(NULL),126_distanceToYieldTimeCheck(0),127_currentDistanceToYieldTimeCheck(0)128{129_typeId = __FUNCTION__;130}131132MM_EnvironmentRealtime(OMR_VM *vm) :133MM_EnvironmentBase(vm),134_scheduler((MM_Scheduler *)MM_GCExtensionsBase::getExtensions(vm)->dispatcher),135_rootScanner(NULL),136_osInterface(_scheduler->_osInterface),137_overflowCache(NULL),138_overflowCacheCount(0),139_timer(NULL),140_distanceToYieldTimeCheck(0),141_currentDistanceToYieldTimeCheck(0)142{143_typeId = __FUNCTION__;144}145146protected:147virtual bool initialize(MM_GCExtensionsBase *extensions);148virtual void tearDown(MM_GCExtensionsBase *extensions);149150private:151152};153154#endif /* ENVIRONMENTREALTIME_HPP_ */155156157158