Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/ClassIterator.hpp
5985 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_Structs
27
*/
28
29
#if !defined(CLASSITERATOR_HPP_)
30
#define CLASSITERATOR_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
35
#include "CallSitesIterator.hpp"
36
#include "ClassStaticsIterator.hpp"
37
#include "ConstantPoolObjectSlotIterator.hpp"
38
#include "EnvironmentBase.hpp"
39
#include "GCExtensionsBase.hpp"
40
#include "MethodTypesIterator.hpp"
41
#include "ValueTypesIterator.hpp"
42
43
/**
44
* State constants representing the current stage of the iteration process
45
* @anchor ClassIteratorState
46
*/
47
enum {
48
classiterator_state_start = 0,
49
classiterator_state_statics,
50
classiterator_state_constant_pool,
51
classiterator_state_slots,
52
classiterator_state_callsites,
53
classiterator_state_methodtypes,
54
#if defined(J9VM_OPT_METHOD_HANDLE)
55
classiterator_state_varhandlemethodtypes,
56
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
57
classiterator_state_valuetypes,
58
classiterator_state_end
59
};
60
61
/**
62
* Iterate over all slots in a class which contain an object reference
63
*
64
* @see GC_ClassIteratorClassSlots
65
*
66
* @ingroup GC_Structs
67
*/
68
class GC_ClassIterator {
69
protected:
70
J9Class *_clazzPtr;
71
int _state;
72
UDATA _scanIndex;
73
74
GC_ClassStaticsIterator _classStaticsIterator;
75
GC_ConstantPoolObjectSlotIterator _constantPoolObjectSlotIterator;
76
GC_CallSitesIterator _callSitesIterator;
77
GC_MethodTypesIterator _methodTypesIterator;
78
#if defined(J9VM_OPT_METHOD_HANDLE)
79
GC_MethodTypesIterator _varHandlesMethodTypesIterator;
80
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
81
GC_ValueTypesIterator _valueTypesIterator;
82
const bool _shouldScanClassObject; /**< Boolean needed for balanced GC to prevent ClassObject from being scanned twice */
83
84
public:
85
GC_ClassIterator(MM_EnvironmentBase *env, J9Class *clazz, bool shouldScanClassObject = true)
86
: _clazzPtr(clazz)
87
, _state(classiterator_state_start)
88
, _scanIndex(0)
89
, _classStaticsIterator(env, clazz)
90
, _constantPoolObjectSlotIterator((J9JavaVM *)env->getLanguageVM(), clazz)
91
, _callSitesIterator(clazz)
92
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
93
, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)
94
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
95
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
96
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
97
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
98
, _valueTypesIterator(clazz)
99
, _shouldScanClassObject(shouldScanClassObject)
100
{}
101
102
GC_ClassIterator(MM_GCExtensionsBase *extensions, J9Class *clazz)
103
: _clazzPtr(clazz)
104
, _state(classiterator_state_start)
105
, _scanIndex(0)
106
, _classStaticsIterator(extensions, clazz)
107
, _constantPoolObjectSlotIterator((J9JavaVM *)extensions->getOmrVM()->_language_vm, clazz)
108
, _callSitesIterator(clazz)
109
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
110
, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)
111
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
112
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
113
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
114
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
115
, _valueTypesIterator(clazz)
116
, _shouldScanClassObject(true)
117
{}
118
119
MMINLINE int getState()
120
{
121
return _state;
122
}
123
124
/**
125
* Fetch the next slot in the class.
126
* Note that the pointer is volatile. In concurrent applications the mutator may
127
* change the value in the slot while iteration is in progress.
128
* @return the next static slot in the class containing an object reference
129
* @return NULL if there are no more such slots
130
*/
131
virtual volatile j9object_t *nextSlot();
132
};
133
134
#endif /* CLASSITERATOR_HPP_ */
135
136
137