Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_realtime/EnvironmentRealtime.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
#if !defined(ENVIRONMENTREALTIME_HPP_)
24
#define ENVIRONMENTREALTIME_HPP_
25
26
#include "Base.hpp"
27
#include "EnvironmentBase.hpp"
28
#include "GCExtensionsBase.hpp"
29
#include "OSInterface.hpp"
30
#include "Scheduler.hpp"
31
32
class MM_AllocationContextRealtime;
33
class MM_HeapRegionDescriptorRealtime;
34
class MM_RealtimeRootScanner;
35
class MM_Timer;
36
37
class MM_EnvironmentRealtime : public MM_EnvironmentBase
38
{
39
/* Data section */
40
public:
41
volatile U_32 _monitorCacheCleared; /**< Flag field to indicate whether the monitor lookup cache has been cleared on the thread */
42
43
protected:
44
private:
45
MM_Scheduler *_scheduler;
46
MM_RealtimeRootScanner *_rootScanner;
47
48
MM_OSInterface *_osInterface;
49
50
I_32 _yieldDisableDepth;
51
52
uintptr_t _scannedObjects; /**< Number of objects scanned in current major GC */
53
54
MM_HeapRegionDescriptorRealtime **_overflowCache; /**< Local cache of overflowed regions. Can only be manipulated by IncrementalOverflow */
55
uintptr_t _overflowCacheCount; /**< Count of used elements in the _overflowCache array. Can on be manipulated by IncrementalOverflow */
56
MM_Timer *_timer;
57
58
U_32 _distanceToYieldTimeCheck; /**< Number of condYield that can be skipped before actual checking for yield, when the quanta time has been relaxed */
59
U_32 _currentDistanceToYieldTimeCheck; /**< The current remaining number of condYield calls to be skipped before the next actual yield check */
60
61
/* Functionality Section */
62
63
public:
64
static MM_EnvironmentRealtime *newInstance(MM_GCExtensionsBase *extensions, OMR_VMThread *omrVMThread);
65
virtual void kill();
66
67
MMINLINE static MM_EnvironmentRealtime *getEnvironment(OMR_VMThread *omrVMThread) { return static_cast<MM_EnvironmentRealtime*>(omrVMThread->_gcOmrVMThreadExtensions); }
68
MMINLINE static MM_EnvironmentRealtime *getEnvironment(MM_EnvironmentBase *ptr) { return (MM_EnvironmentRealtime *)ptr; }
69
70
MM_Scheduler *getScheduler() const { return _scheduler; }
71
72
MM_AllocationContextRealtime *getAllocationContext() const { return (MM_AllocationContextRealtime *)MM_EnvironmentBase::getAllocationContext(); }
73
void setAllocationContext(MM_AllocationContextRealtime *allocContext) { MM_EnvironmentBase::setAllocationContext((MM_AllocationContext *)allocContext); }
74
75
U_32 getMonitorCacheCleared() const { return _monitorCacheCleared; }
76
void setMonitorCacheCleared(U_32 monitorCacheCleared) { _monitorCacheCleared = monitorCacheCleared; }
77
78
/* Maintains a recursive count of _not_ being able to yield.
79
* Initially the depth is zero indicating that it can yield.
80
*/
81
void disableYield();
82
void enableYield();
83
I_32 getYieldDisableDepth() const { return _yieldDisableDepth; }
84
85
MMINLINE U_32 getCurrentDistanceToYieldTimeCheck() { return _currentDistanceToYieldTimeCheck; }
86
MMINLINE void resetCurrentDistanceToYieldTimeCheck()
87
{
88
if(0 != _distanceToYieldTimeCheck) {
89
_currentDistanceToYieldTimeCheck = _distanceToYieldTimeCheck;
90
}
91
}
92
MMINLINE bool hasDistanceToYieldTimeCheck()
93
{
94
bool shouldSkipTimeCheck = (0 != _currentDistanceToYieldTimeCheck);
95
if (shouldSkipTimeCheck) {
96
--_currentDistanceToYieldTimeCheck;
97
}
98
return shouldSkipTimeCheck;
99
}
100
101
void reportScanningSuspended();
102
void reportScanningResumed();
103
104
void setRootScanner(MM_RealtimeRootScanner *rootScanner) { _rootScanner = rootScanner; }
105
106
uintptr_t getScannedObjects() const { return _scannedObjects; }
107
void incScannedObjects() { _scannedObjects++; }
108
void resetScannedCounters()
109
{
110
_scannedObjects = 0;
111
}
112
MM_Timer *getTimer() {return _timer;}
113
114
MMINLINE uintptr_t getOverflowCacheUsedCount() {return _overflowCacheCount;}
115
MMINLINE void incrementOverflowCacheUsedCount() {_overflowCacheCount += 1;}
116
MMINLINE void resetOverflowCacheUsedCount() {_overflowCacheCount = 0;}
117
MMINLINE MM_HeapRegionDescriptorRealtime **getOverflowCache() {return _overflowCache;}
118
119
MM_EnvironmentRealtime(OMR_VMThread *omrVMThread) :
120
MM_EnvironmentBase(omrVMThread),
121
_scheduler((MM_Scheduler *)MM_GCExtensionsBase::getExtensions(omrVMThread->_vm)->dispatcher),
122
_rootScanner(NULL),
123
_osInterface(_scheduler->_osInterface),
124
_overflowCache(NULL),
125
_overflowCacheCount(0),
126
_timer(NULL),
127
_distanceToYieldTimeCheck(0),
128
_currentDistanceToYieldTimeCheck(0)
129
{
130
_typeId = __FUNCTION__;
131
}
132
133
MM_EnvironmentRealtime(OMR_VM *vm) :
134
MM_EnvironmentBase(vm),
135
_scheduler((MM_Scheduler *)MM_GCExtensionsBase::getExtensions(vm)->dispatcher),
136
_rootScanner(NULL),
137
_osInterface(_scheduler->_osInterface),
138
_overflowCache(NULL),
139
_overflowCacheCount(0),
140
_timer(NULL),
141
_distanceToYieldTimeCheck(0),
142
_currentDistanceToYieldTimeCheck(0)
143
{
144
_typeId = __FUNCTION__;
145
}
146
147
protected:
148
virtual bool initialize(MM_GCExtensionsBase *extensions);
149
virtual void tearDown(MM_GCExtensionsBase *extensions);
150
151
private:
152
153
};
154
155
#endif /* ENVIRONMENTREALTIME_HPP_ */
156
157
158