Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/ClassStaticsIterator.hpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2018 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(CLASSSTATICSITERATOR_HPP_)
30
#define CLASSSTATICSITERATOR_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
#include "j9cp.h"
35
#include "util_api.h"
36
#include "modron.h"
37
38
#include "EnvironmentBase.hpp"
39
#include "GCExtensions.hpp"
40
41
/**
42
* Iterate over all static slots in a class which contain an object reference.
43
* @ingroup GC_Structs
44
*/
45
class GC_ClassStaticsIterator
46
{
47
U_32 _objectStaticCount;
48
j9object_t *_staticPtr;
49
50
public:
51
GC_ClassStaticsIterator(MM_EnvironmentBase *env, J9Class *clazz)
52
: _objectStaticCount(clazz->romClass->objectStaticCount)
53
, _staticPtr((j9object_t *)clazz->ramStatics)
54
{
55
/* check if the class's statics have been abandoned due to hot
56
* code replace. If so, this class has no statics of its own
57
*/
58
/*
59
* Note: we have no special recognition for J9ArrayClass here
60
* J9ArrayClass does not have a ramStatics field but something else at this place
61
* so direct check (NULL != clazz->ramStatics) would not be correct,
62
* however romClazz->objectStaticCount must be 0 for this case
63
* as well as J9ArrayClass can not be hot swapped.
64
*
65
* Classes which have been hotswapped by fast HCR still have the ramStatics field
66
* set. Statics must be walked only once, so only walk them for the most current
67
* version of the class.
68
*/
69
if ((NULL == _staticPtr) || (J9ClassReusedStatics == (J9CLASS_EXTENDED_FLAGS(clazz) & J9ClassReusedStatics))) {
70
_objectStaticCount = 0;
71
}
72
};
73
74
GC_ClassStaticsIterator(MM_GCExtensionsBase *extensions, J9Class *clazz)
75
: _objectStaticCount(clazz->romClass->objectStaticCount)
76
, _staticPtr((j9object_t *)clazz->ramStatics)
77
{
78
/* check if the class's statics have been abandoned due to hot
79
* code replace. If so, this class has no statics of its own
80
*/
81
/*
82
* Note: we have no special recognition for J9ArrayClass here
83
* J9ArrayClass does not have a ramStatics field but something else at this place
84
* so direct check (NULL != clazz->ramStatics) would not be correct,
85
* however romClazz->objectStaticCount must be 0 for this case
86
* as well as J9ArrayClass can not be hot swapped.
87
*
88
* Classes which have been hotswapped by fast HCR still have the ramStatics field
89
* set. Statics must be walked only once, so only walk them for the most current
90
* version of the class.
91
*/
92
if ((NULL == _staticPtr) || (J9ClassReusedStatics == (J9CLASS_EXTENDED_FLAGS(clazz) & J9ClassReusedStatics))) {
93
_objectStaticCount = 0;
94
}
95
};
96
97
/**
98
* Fetch the next static field in the class.
99
* Note that the pointer is volatile. In concurrent applications the mutator may
100
* change the value in the slot while iteration is in progress.
101
* @return the next static slot in the class containing an object reference
102
* @return NULL if there are no more such slots
103
*/
104
volatile j9object_t *
105
nextSlot()
106
{
107
j9object_t *slotPtr;
108
109
if (0 == _objectStaticCount) {
110
return NULL;
111
}
112
_objectStaticCount -= 1;
113
slotPtr = _staticPtr++;
114
115
return slotPtr;
116
}
117
};
118
#endif /* CLASSSTATICSITERATOR_HPP_ */
119
120