Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CompressedCardTable.hpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2021 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
/**
25
* @file
26
* @ingroup gc_vlhgc
27
*/
28
29
#if !defined(COMPRESSEDCARDTABLE_HPP_)
30
#define COMPRESSEDCARDTABLE_HPP_
31
32
33
#include "j9.h"
34
#include "j9cfg.h"
35
36
#include "AtomicOperations.hpp"
37
#include "Base.hpp"
38
#include "CardTable.hpp"
39
40
class MM_CardCleaner;
41
class MM_EnvironmentBase;
42
class MM_Heap;
43
class MM_HeapRegionDescriptor;
44
45
#define BITS_PER_BYTE 8
46
#define COMPRESSED_CARDS_PER_WORD (sizeof(UDATA) * BITS_PER_BYTE)
47
48
class MM_CompressedCardTable : public MM_BaseNonVirtual
49
{
50
public:
51
protected:
52
private:
53
UDATA *_compressedCardTable; /**< start address of compressed card table */
54
UDATA _heapBase; /**< Store heap base locally. Use UDATA type because need it for arithmetic only */
55
volatile UDATA _totalRegions; /**< total number of regions discovered at table rebuild time */
56
volatile UDATA _regionsProcessed; /**< number of regions completed while table is being rebuilt */
57
58
public:
59
/**
60
* Create new instance of class
61
* @param env current thread environment
62
* @param heap current heap
63
*/
64
static MM_CompressedCardTable *newInstance(MM_EnvironmentBase *env, MM_Heap *heap);
65
66
/**
67
* Set all Compressed Cards correspondent with given heap range dirty for partial collect
68
* @param startHeapAddress start heap address
69
* @param endHeapAddress end heap address
70
*/
71
void setCompressedCardsDirtyForPartialCollect(void *startHeapAddress, void *endHeapAddress);
72
73
/**
74
* Rebuild Compressed Cards for given heap range
75
* Card is going to be marked dirty if original card is dirty for partial collect
76
* @param env current thread environment
77
* @param startHeapAddress start heap address
78
* @param endHeapAddress end heap address
79
*/
80
void rebuildCompressedCardTableForPartialCollect(MM_EnvironmentBase *env, void *startHeapAddress, void *endHeapAddress);
81
82
/**
83
* Check is Compressed Card correspondent with heap address dirty for partial collect
84
* @param env current thread environment
85
* @param heapAddress heap address
86
* @return true if fast card is set dirty
87
*/
88
bool isCompressedCardDirtyForPartialCollect(MM_EnvironmentBase *env, void *heapAddr);
89
90
/**
91
* Cleaning cards for range
92
* Iterate Compressed Cards and clean marked dirty
93
* It is important that set of card states treated 'dirty' in given Card Cleaner must be the same or narrower then
94
* was used for in Compressed Card Table rebuild. If it is not correct some dirty cards might be missed
95
* @param env current thread environment
96
* @param cardCleaner given Card Cleaner
97
* @param region region card cleaning should be done
98
*/
99
void cleanCardsInRegion(MM_EnvironmentBase *env, MM_CardCleaner *cardCleaner, MM_HeapRegionDescriptor *region);
100
101
/**
102
* Check is Card Table Summary rebuild is completed
103
* @return true if rebuild is completed
104
*/
105
bool isReady();
106
107
/**
108
* Clear processed regions counter
109
*/
110
MMINLINE void clearRegionsProcessedCounter()
111
{
112
_regionsProcessed = 0;
113
}
114
115
/**
116
* Atomically increment processed regions counter
117
* @param total total number of discovered regions
118
* @param processed number of processed regions
119
*/
120
MMINLINE void incrementProcessedRegionsCounter(UDATA total, UDATA processed)
121
{
122
_totalRegions = total;
123
124
if (processed > 0) {
125
MM_AtomicOperations::storeSync();
126
MM_AtomicOperations::add(&_regionsProcessed, processed);
127
}
128
}
129
130
/**
131
* General class kill
132
* @param env current thread environment
133
*/
134
void kill(MM_EnvironmentBase *env);
135
136
protected:
137
/**
138
* General class initialization
139
* @param env current thread environment
140
* @param heap heap
141
*/
142
bool initialize(MM_EnvironmentBase *env, MM_Heap *heap);
143
144
/**
145
* General class tear down
146
* @param env current thread environment
147
*/
148
void tearDown(MM_EnvironmentBase *env);
149
150
/**
151
* Create a compressedCardTable object.
152
*/
153
MM_CompressedCardTable()
154
: MM_BaseNonVirtual()
155
, _compressedCardTable(NULL)
156
, _heapBase(0)
157
, _totalRegions(1)
158
, _regionsProcessed(0)
159
{
160
_typeId = __FUNCTION__;
161
}
162
163
private:
164
/**
165
* Check should card be treated as dirty for partial collect
166
* @param state current card state
167
*/
168
bool isDirtyCardForPartialCollect(Card state);
169
170
/**
171
* Cleaning cards for range
172
* Iterate Compressed Cards and clean marked dirty
173
* It is important that set of card states treated 'dirty' in given Card Cleaner must be the same or narrower then
174
* was used for in Compressed Card Table rebuild. If it is not correct some dirty cards might be missed
175
* @param env current thread environment
176
* @param cardCleaner given Card Cleaner
177
* @param startHeapAddress start heap address
178
* @param endHeapAddress end heap address
179
*/
180
void cleanCardsInRange(MM_EnvironmentBase *env, MM_CardCleaner *cardCleaner, void *startHeapAddress, void *endHeapAddress);
181
};
182
183
#endif /* COMPRESSEDCARDTABLE_HPP_ */
184
185