Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CopyScanCacheListVLHGC.hpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2014 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_Modron_Standard
27
*/
28
29
#if !defined(COPYSCANCACHELISTVLHGC_HPP_)
30
#define COPYSCANCACHELISTVLHGC_HPP_
31
32
#include "j9.h"
33
#include "j9consts.h"
34
#include "modronopt.h"
35
36
#include "BaseVirtual.hpp"
37
#include "EnvironmentVLHGC.hpp"
38
#include "LightweightNonReentrantLock.hpp"
39
40
class MM_CopyScanCacheVLHGC;
41
class MM_CopyScanCacheChunkVLHGC;
42
43
/**
44
* @todo Provide class documentation
45
* @ingroup GC_Modron_Standard
46
*/
47
class MM_CopyScanCacheListVLHGC : public MM_BaseVirtual
48
{
49
public:
50
private:
51
struct CopyScanCacheSublist {
52
MM_CopyScanCacheVLHGC *_cacheHead;
53
MM_LightweightNonReentrantLock _cacheLock;
54
} *_sublists;
55
UDATA _sublistCount; /**< the number of lists (split for parallelism). Must be at least 1 */
56
MM_CopyScanCacheChunkVLHGC *_chunkHead;
57
UDATA _totalEntryCount;
58
bool _containsHeapAllocatedChunks; /**< True if there are heap-allocated scan cache chunks on the _chunkHead list */
59
60
private:
61
bool appendCacheEntries(MM_EnvironmentVLHGC *env, UDATA cacheEntryCount);
62
63
/**
64
* Determine the sublist index for the specified thread.
65
* @return the index (a valid index into _sublists)
66
*/
67
UDATA getSublistIndex(MM_EnvironmentVLHGC *env) { return env->getEnvironmentId() % _sublistCount; }
68
69
/**
70
* Add the specified entry to this list. It is the caller's responsibility to provide synchronization.
71
* @param env[in] the current GC thread
72
* @param cacheEntry[in] the cache entry to add
73
* @param sublist[in] the sublist to push to
74
*/
75
void pushCacheInternal(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry, CopyScanCacheSublist* sublist);
76
77
/**
78
* Pop a cache entry from this list. It is the caller's responsibility to provide synchronization.
79
* @param env[in] the current GC thread
80
* @param sublist[in] the sublist to pop from
81
* @return the cache entry, or NULL if the list is empty
82
*/
83
MM_CopyScanCacheVLHGC *popCacheInternal(MM_EnvironmentVLHGC *env, CopyScanCacheSublist* sublist);
84
85
public:
86
bool initialize(MM_EnvironmentVLHGC *env);
87
virtual void tearDown(MM_EnvironmentVLHGC *env);
88
89
/**
90
* Resizes the number of cache entries.
91
*
92
* @param env[in] A GC thread
93
* @param totalCacheEntryCount[in] The number of cache entries which this list should be resized to contain
94
*/
95
bool resizeCacheEntries(MM_EnvironmentVLHGC *env, UDATA totalCacheEntryCount);
96
97
/**
98
* Removes any heap-allocated scan cache chunks from the receiver's chunk list (calls tearDown on them after removing them from the list).
99
* @param env[in] A GC thread
100
*/
101
void removeAllHeapAllocatedChunks(MM_EnvironmentVLHGC *env);
102
103
/**
104
* Allocates an on-heap scan cache in the bufferLengthInBytes of memory starting at buffer.
105
* @param env[in] A GC thread
106
* @param buffer[in] The base address of the memory extent on which the receiver should allocate a scan cache chunk
107
* @param bufferLengthInBytes[in] The length, in bytes, of the memory extent starting at buffer
108
* @return A new cache entry if the chunk was successfully allocated and inserted into the receiver's chunk list, NULL if a failure occurred
109
*/
110
MM_CopyScanCacheVLHGC * allocateCacheEntriesInExistingMemory(MM_EnvironmentVLHGC *env, void *buffer, UDATA bufferLengthInBytes);
111
112
/**
113
* Lock the receiver to prevent concurrent modification.
114
* @note that pushCache() and popCache() lock internally, so this is only required for heavyweight operations.
115
*/
116
void lock();
117
118
/**
119
* Unlock the receiver from concurrent modification.
120
* @note that pushCache() and popCache() lock internally, so this is only required for heavy weight operations.
121
*/
122
void unlock();
123
124
/**
125
* Add the specified entry to this list. It is the caller's responsibility to provide synchronization.
126
* @param env[in] the current GC thread
127
* @param cacheEntry[in] the cache entry to add
128
*/
129
void pushCacheNoLock(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry);
130
131
/**
132
* Pop a cache entry from this list. It is the caller's responsibility to provide synchronization.
133
* @param env[in] the current GC thread
134
* @return the cache entry, or NULL if the list is empty
135
*/
136
MM_CopyScanCacheVLHGC *popCacheNoLock(MM_EnvironmentVLHGC *env);
137
138
/**
139
* Add the specified entry to this list.
140
* @param env[in] the current GC thread
141
* @param cacheEntry[in] the cache entry to add
142
*/
143
void pushCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cacheEntry);
144
145
/**
146
* Pop a cache entry from this list.
147
* @param env[in] the current GC thread
148
* @return the cache entry, or NULL if the list is empty
149
*/
150
MM_CopyScanCacheVLHGC *popCache(MM_EnvironmentVLHGC *env);
151
152
/**
153
* Determine if the list is empty.
154
* @return true if the list is empty, false otherwise
155
*/
156
bool isEmpty();
157
158
/**
159
* Determine how many caches are in the receiver's lists.
160
* Note that this is not thread safe. The receiver must be locked.
161
* The implementation walks all caches, so this should only be used for debugging.
162
* @return the total number of caches in the receiver's lists
163
*/
164
UDATA countCaches();
165
166
/**
167
* Answer the total number of caches owned by the receiver, whether or not they are currently in the receiver's lists.
168
* @return total number of caches
169
*/
170
UDATA getTotalCacheCount() { return _totalEntryCount; }
171
172
/**
173
* Create a CopyScanCacheList object.
174
*/
175
MM_CopyScanCacheListVLHGC();
176
177
};
178
179
#endif /* COPYSCANCACHELISTVLHGC_HPP_ */
180
181