Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/ReferenceObjectScanner.hpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2016, 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
/**
24
* @file
25
* @ingroup GC_Structs
26
*/
27
28
#if !defined(REFERENCEOBJECTSCANNER_HPP_)
29
#define REFERENCEOBJECTSCANNER_HPP_
30
31
#include "MixedObjectScanner.hpp"
32
33
/**
34
* This class is used to iterate over the slots of a Java reference object.
35
*/
36
class GC_ReferenceObjectScanner : public GC_MixedObjectScanner
37
{
38
/* Data Members */
39
private:
40
fomrobject_t * _referentSlotAddress;
41
42
protected:
43
44
public:
45
46
/* Member Functions */
47
private:
48
/**
49
* The referent slot must be skipped unless the referent must be marked. So clear
50
* the corresponding bit in the scan map when the scan pointer is reset to contain
51
* the referent slot within its mapped range.
52
*/
53
MMINLINE uintptr_t skipReferentSlot(fomrobject_t *mapPtr, uintptr_t scanMap)
54
{
55
if (_referentSlotAddress > mapPtr) {
56
/* Skip over referent slot */
57
intptr_t referentSlotDistance = GC_SlotObject::subtractSlotAddresses(_referentSlotAddress, mapPtr, compressObjectReferences());
58
if (referentSlotDistance < _bitsPerScanMap) {
59
scanMap &= ~((uintptr_t)1 << referentSlotDistance);
60
}
61
}
62
return scanMap;
63
}
64
65
protected:
66
/**
67
* Instantiation constructor.
68
*
69
* @param[in] env pointer to the environment for the current thread
70
* @param[in] objectPtr pointer to the object to be processed
71
* @param[in] referentSlotAddress pointer to referent slot, if this slot is to be skipped; otherwise, specify NULL
72
* @param[in] flags Scanning context flags
73
*/
74
MMINLINE GC_ReferenceObjectScanner(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, fomrobject_t *referentSlotAddress, uintptr_t flags)
75
: GC_MixedObjectScanner(env, objectPtr, flags)
76
, _referentSlotAddress(referentSlotAddress)
77
{
78
_typeId = __FUNCTION__;
79
}
80
81
/**
82
* Subclasses must call this method to set up the instance description bits and description pointer.
83
*/
84
MMINLINE void
85
initialize(MM_EnvironmentBase *env, J9Class *clazzPtr)
86
{
87
GC_MixedObjectScanner::initialize(env, clazzPtr);
88
89
/* Skip over referent slot if required */
90
_scanMap = skipReferentSlot(_scanPtr, _scanMap);
91
}
92
93
public:
94
/**
95
* In-place instantiation and initialization for reference object scanner.
96
*
97
* @param[in] env The scanning thread environment
98
* @param[in] objectPtr The object to scan
99
* @param[in] referentSlotAddress pointer to referent slot, if this slot is to be skipped; otherwise, specify NULL
100
* @param[in] allocSpace Pointer to space for in-place instantiation (at least sizeof(GC_ReferenceObjectScanner) bytes)
101
* @param[in] flags Scanning context flags
102
* @return Pointer to GC_ReferenceObjectScanner instance in allocSpace
103
*/
104
MMINLINE static GC_ReferenceObjectScanner *
105
newInstance(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, fomrobject_t *referentSlotAddress, void *allocSpace, uintptr_t flags)
106
{
107
GC_ReferenceObjectScanner *objectScanner = (GC_ReferenceObjectScanner *)allocSpace;
108
new(objectScanner) GC_ReferenceObjectScanner(env, objectPtr, referentSlotAddress, flags);
109
objectScanner->initialize(env, J9GC_J9OBJECT_CLAZZ(objectPtr, env));
110
return objectScanner;
111
}
112
113
/**
114
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
115
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
116
* increasing significance, and the least significant bit maps to the slot at the returned
117
* base pointer.
118
*
119
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
120
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
121
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
122
*/
123
virtual fomrobject_t *
124
getNextSlotMap(uintptr_t *slotMap, bool *hasNextSlotMap)
125
{
126
fomrobject_t *mapPtr = GC_MixedObjectScanner::getNextSlotMap(slotMap, hasNextSlotMap);
127
128
/* Skip over referent slot */
129
*slotMap = skipReferentSlot(mapPtr, *slotMap);
130
131
return mapPtr;
132
}
133
134
#if defined(OMR_GC_LEAF_BITS)
135
/**
136
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
137
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
138
* increasing significance, and the least significant bit maps to the slot at the returned
139
* base pointer.
140
*
141
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
142
* @param[out] leafMap the leaf bit map for the slots contiguous with the returned base pointer
143
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
144
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
145
*/
146
virtual fomrobject_t *
147
getNextSlotMap(uintptr_t *slotMap, uintptr_t *leafMap, bool *hasNextSlotMap)
148
{
149
fomrobject_t *mapPtr = GC_MixedObjectScanner::getNextSlotMap(slotMap, leafMap, hasNextSlotMap);
150
151
/* Skip over referent slot */
152
*slotMap = skipReferentSlot(mapPtr, *slotMap);
153
154
return mapPtr;
155
}
156
#endif /* defined(OMR_GC_LEAF_BITS) */
157
};
158
#endif /* REFERENCEOBJECTSCANNER_HPP_ */
159
160