Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_realtime/SweepSchemeRealtime.cpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 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
#include "GCExtensionsBase.hpp"
24
#include "MarkMap.hpp"
25
#include "MemoryPoolSegregated.hpp"
26
#include "RealtimeGC.hpp"
27
28
#include "SweepSchemeRealtime.hpp"
29
30
/**
31
* Allocate and initialize a new instance of the receiver.
32
* @return a new instance of the receiver, or NULL on failure.
33
*/
34
MM_SweepSchemeRealtime *
35
MM_SweepSchemeRealtime::newInstance(MM_EnvironmentBase *env, MM_RealtimeGC *realtimeGC, MM_Scheduler *scheduler, MM_MarkMap *markMap)
36
{
37
MM_SweepSchemeRealtime *instance;
38
39
instance = (MM_SweepSchemeRealtime *)env->getForge()->allocate(sizeof(MM_SweepSchemeRealtime), MM_AllocationCategory::FIXED, OMR_GET_CALLSITE());
40
if (NULL != instance) {
41
new(instance) MM_SweepSchemeRealtime(env, realtimeGC, scheduler, markMap);
42
if (!instance->initialize(env)) {
43
instance->kill(env);
44
instance = NULL;
45
}
46
}
47
48
return instance;
49
}
50
51
/**
52
* Free the receiver and all associated resources.
53
*/
54
void
55
MM_SweepSchemeRealtime::kill(MM_EnvironmentBase *env)
56
{
57
tearDown(env);
58
env->getForge()->free(this);
59
}
60
61
void
62
MM_SweepSchemeRealtime::preSweep(MM_EnvironmentBase *env)
63
{
64
_realtimeGC->setCollectorSweeping();
65
_scheduler->condYieldFromGC(env, _scheduler->beatNanos);
66
67
MM_GCExtensionsBase *ext = env->getExtensions();
68
MM_SweepSchemeSegregated::preSweep(env);
69
70
_realtimeGC->allThreadsAllocateUnmarked(env);
71
if (ext->isConcurrentSweepEnabled()) {
72
_realtimeGC->setCollectorConcurrentSweeping();
73
_realtimeGC->getRealtimeDelegate()->releaseExclusiveVMAccess(env, _scheduler->_exclusiveVMAccessRequired);
74
}
75
}
76
77
void
78
MM_SweepSchemeRealtime::postSweep(MM_EnvironmentBase *env)
79
{
80
MM_GCExtensionsBase *ext = env->getExtensions();
81
if (ext->isConcurrentSweepEnabled()) {
82
_realtimeGC->getRealtimeDelegate()->acquireExclusiveVMAccess(env, _scheduler->_exclusiveVMAccessRequired);
83
_realtimeGC->setCollectorSweeping(); /* It might have been in ConcurrentSweep mode before. */
84
}
85
86
MM_SweepSchemeSegregated::postSweep(env);
87
88
MM_MemoryPoolSegregated *memoryPool = _realtimeGC->_memoryPool;
89
ext->gcTrigger = OMR_MAX(ext->gcInitialTrigger, ext->headRoom + memoryPool->getBytesInUse());
90
}
91
92
void
93
MM_SweepSchemeRealtime::incrementalSweepArraylet(MM_EnvironmentBase *env)
94
{
95
_realtimeGC->setCollectorSweepingArraylets(true);
96
97
MM_SweepSchemeSegregated::incrementalSweepArraylet(env);
98
99
_realtimeGC->setCollectorSweepingArraylets(false);
100
}
101
102
103
void
104
MM_SweepSchemeRealtime::yieldFromSweep(MM_EnvironmentBase *env, uintptr_t yieldSlackTime)
105
{
106
_scheduler->condYieldFromGC(env, yieldSlackTime);
107
}
108
109
uintptr_t
110
MM_SweepSchemeRealtime::resetCoalesceFreeRegionCount(MM_EnvironmentBase *env)
111
{
112
_coalesceFreeRegionCount = 0;
113
return 100000;
114
}
115
116
bool
117
MM_SweepSchemeRealtime::updateCoalesceFreeRegionCount(uintptr_t range)
118
{
119
bool mustYield = false;
120
_coalesceFreeRegionCount += range;
121
if (_coalesceFreeRegionCount > MAX_REGION_COALESCE) {
122
_coalesceFreeRegionCount = 0;
123
mustYield = true;
124
}
125
return mustYield;
126
}
127
128
uintptr_t
129
MM_SweepSchemeRealtime::resetSweepSmallRegionCount(MM_EnvironmentBase *env, uintptr_t sweepSmallRegionsPerIteration)
130
{
131
_sweepSmallRegionCount = 0;
132
_yieldSmallRegionCount = sweepSmallRegionsPerIteration >> 3;
133
return 50000;
134
}
135
136
bool
137
MM_SweepSchemeRealtime::updateSweepSmallRegionCount()
138
{
139
bool mustYield = false;
140
_sweepSmallRegionCount += 1;
141
if (_sweepSmallRegionCount >= _yieldSmallRegionCount) {
142
_sweepSmallRegionCount = 0;
143
mustYield = true;
144
}
145
return mustYield;
146
}
147
148
149