Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/J9ClassEnv.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2022 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
#ifndef J9_CLASSENV_INCL
24
#define J9_CLASSENV_INCL
25
26
/*
27
* The following #define and typedef must appear before any #includes in this file
28
*/
29
#ifndef J9_CLASSENV_CONNECTOR
30
#define J9_CLASSENV_CONNECTOR
31
namespace J9 { class ClassEnv; }
32
namespace J9 { typedef J9::ClassEnv ClassEnvConnector; }
33
#endif
34
35
#if defined(J9VM_OPT_JITSERVER)
36
#include <vector>
37
#endif /* defined(J9VM_OPT_JITSERVER) */
38
#include "env/jittypes.h"
39
#include "env/OMRClassEnv.hpp"
40
#include "infra/Annotations.hpp"
41
#include "j9.h"
42
43
namespace TR { class SymbolReference; }
44
namespace TR { class TypeLayout; }
45
namespace TR { class Region; }
46
class TR_PersistentClassInfo;
47
template <typename ListKind> class List;
48
49
namespace J9
50
{
51
52
class OMR_EXTENSIBLE ClassEnv : public OMR::ClassEnvConnector
53
{
54
public:
55
56
TR::ClassEnv *self();
57
58
bool classesOnHeap() { return true; }
59
60
bool classObjectsMayBeCollected() { return false; }
61
62
bool romClassObjectsMayBeCollected() { return false; }
63
64
TR_OpaqueClassBlock *getClassFromJavaLangClass(uintptr_t objectPointer);
65
66
J9Class *convertClassOffsetToClassPtr(TR_OpaqueClassBlock *clazzOffset);
67
TR_OpaqueClassBlock *convertClassPtrToClassOffset(J9Class *clazzPtr);
68
69
uintptr_t classFlagsValue(TR_OpaqueClassBlock * classPointer);
70
uintptr_t classFlagReservableWordInitValue(TR_OpaqueClassBlock * classPointer);
71
uintptr_t classDepthOf(TR_OpaqueClassBlock *clazzPointer);
72
uintptr_t classInstanceSize(TR_OpaqueClassBlock * clazzPointer);
73
74
J9ROMClass *romClassOf(TR_OpaqueClassBlock * clazz);
75
J9ROMClass *romClassOfSuperClass(TR_OpaqueClassBlock * clazz, size_t index);
76
77
J9ITable *iTableOf(TR_OpaqueClassBlock * clazz);
78
J9ITable *iTableNext(J9ITable *current);
79
J9ROMClass *iTableRomClass(J9ITable *current);
80
#if defined(J9VM_OPT_JITSERVER)
81
std::vector<TR_OpaqueClassBlock *> getITable(TR_OpaqueClassBlock *clazz);
82
#endif /* defined(J9VM_OPT_JITSERVER) */
83
84
J9Class **superClassesOf(TR_OpaqueClassBlock * clazz);
85
86
bool isStringClass(TR_OpaqueClassBlock *clazz);
87
88
bool classHasIllegalStaticFinalFieldModification(TR_OpaqueClassBlock * clazzPointer);
89
bool isAbstractClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer);
90
bool isInterfaceClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer);
91
bool isConcreteClass(TR::Compilation *comp, TR_OpaqueClassBlock * clazzPointer);
92
bool isValueTypeClass(TR_OpaqueClassBlock *);
93
bool isValueTypeClassFlattened(TR_OpaqueClassBlock *clazz);
94
bool isValueBasedOrValueTypeClass(TR_OpaqueClassBlock *);
95
96
/** \brief
97
* Returns the size of the flattened array element
98
*
99
* \param comp
100
* The compilation object
101
*
102
* \param arrayClass
103
* The array class that is to be checked
104
*
105
* \return
106
* Size of the flattened array element
107
*/
108
int32_t flattenedArrayElementSize(TR::Compilation *comp, TR_OpaqueClassBlock *arrayClass);
109
110
/** \brief
111
* Checks whether a class implements `IdentityObject`/`IdentityInterface`
112
*
113
* \param clazz
114
* The class that is to be checked
115
*
116
* \return
117
* `true` if the class implements `IdentityObject`/`IdentityInterface`;
118
* `false` otherwise (that is, if the class could be a value type,
119
* or some abstract class, interface, or java/lang/Object)
120
*/
121
bool classHasIdentity(TR_OpaqueClassBlock *clazz);
122
123
/**
124
* \brief
125
* Checks whether instances of the specified class can be trivially initialized by
126
* "zeroing" their fields.
127
* In the case of OpenJ9, this tests whether any field is of a value type that has not been
128
* "flattened" (that is, had the value type's fields inlined into this class). Such a value
129
* type field must be initialized with the default value of the type.
130
*
131
* \param clazz
132
* The class that is to be checked
133
*
134
* \return
135
* `true` if instances of the specified class can be initialized by zeroing their fields;
136
* `false` otherwise (that is, if the class has value type fields whose fields have not
137
* been inlined)
138
*/
139
bool isZeroInitializable(TR_OpaqueClassBlock *clazz);
140
bool isEnumClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer, TR_ResolvedMethod *method);
141
bool isPrimitiveClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
142
bool isAnonymousClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
143
bool isPrimitiveArray(TR::Compilation *comp, TR_OpaqueClassBlock *);
144
bool isReferenceArray(TR::Compilation *comp, TR_OpaqueClassBlock *);
145
bool isClassArray(TR::Compilation *comp, TR_OpaqueClassBlock *);
146
bool isClassFinal(TR::Compilation *comp, TR_OpaqueClassBlock *);
147
bool hasFinalizer(TR::Compilation *comp, TR_OpaqueClassBlock *classPointer);
148
bool isClassInitialized(TR::Compilation *comp, TR_OpaqueClassBlock *);
149
bool hasFinalFieldsInClass(TR::Compilation *comp, TR_OpaqueClassBlock *classPointer);
150
bool sameClassLoaders(TR::Compilation *comp, TR_OpaqueClassBlock *, TR_OpaqueClassBlock *);
151
bool isString(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
152
bool jitStaticsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2);
153
bool jitFieldsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2, int32_t isStatic);
154
/*
155
* \brief
156
* Tells whether a class reference entry in the constant pool represents a value type class.
157
*
158
* \param cpContextClass
159
* The class whose constant pool contains the class reference entry being looked at. In another words,
160
* it's the class of the method referring to the class reference entry.
161
*
162
* \param cpIndex
163
* The constant pool index of the class reference entry.
164
*
165
* \note
166
* The class reference entry doesn't need to be resolved because the information is encoded in class name string
167
*/
168
bool isClassRefValueType(TR::Compilation *comp, TR_OpaqueClassBlock *cpContextClass, int32_t cpIndex);
169
170
/** \brief
171
* Populates a TypeLayout object.
172
*
173
* \param region
174
* The region used to allocate TypeLayout.
175
*
176
* \param opaqueClazz
177
* Class of the type whose layout needs to be populated.
178
*
179
* \return
180
* Returns a pointer to the TypeLayout object populated.
181
*/
182
const TR::TypeLayout* enumerateFields(TR::Region& region, TR_OpaqueClassBlock * clazz, TR::Compilation *comp);
183
184
uintptr_t getArrayElementWidthInBytes(TR::Compilation *comp, TR_OpaqueClassBlock* arrayClass);
185
186
uintptr_t persistentClassPointerFromClassPointer(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
187
TR_OpaqueClassBlock *objectClass(TR::Compilation *comp, uintptr_t objectPointer);
188
TR_OpaqueClassBlock *classFromJavaLangClass(TR::Compilation *comp, uintptr_t objectPointer);
189
190
uint16_t getStringCharacter(TR::Compilation *comp, uintptr_t objectPointer, int32_t index);
191
bool getStringFieldByName(TR::Compilation *, TR::SymbolReference *stringRef, TR::SymbolReference *fieldRef, void* &pResult);
192
193
using OMR::ClassEnv::classNameChars;
194
char *classNameChars(TR::Compilation *, TR::SymbolReference *symRef, int32_t & length);
195
char *classNameChars(TR::Compilation *, TR_OpaqueClassBlock * clazz, int32_t & length);
196
197
char *classSignature_DEPRECATED(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, int32_t & length, TR_Memory *);
198
char *classSignature(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, TR_Memory *);
199
200
/**
201
* \brief
202
* Constructs a class signature char string based on the class name
203
*
204
* \param[in] name
205
* The class name
206
*
207
* \param[in,out] len
208
* The input is the length of the class name. Returns the length of the signature
209
*
210
* \param[in] comp
211
* The compilation object
212
*
213
* \param[in] allocKind
214
* The type of the memory allocation
215
*
216
* \param[in] clazz
217
* The class that the class name belongs to
218
*
219
* \return
220
* A class signature char string
221
*/
222
char *classNameToSignature(const char *name, int32_t &len, TR::Compilation *comp, TR_AllocationKind allocKind = stackAlloc, TR_OpaqueClassBlock *clazz = NULL);
223
224
int32_t vTableSlot(TR::Compilation *comp, TR_OpaqueMethodBlock *, TR_OpaqueClassBlock *);
225
int32_t flagValueForPrimitiveTypeCheck(TR::Compilation *comp);
226
int32_t flagValueForArrayCheck(TR::Compilation *comp);
227
int32_t flagValueForFinalizerCheck(TR::Compilation *comp);
228
229
bool isClassSpecialForStackAllocation(TR_OpaqueClassBlock * classPointer);
230
/**
231
* Get the virtual function table entry at a specific offset from the class
232
*
233
* @param clazz The RAM class pointer to read from
234
* @param offset An offset into the virtual function table (VFT) of clazz
235
* @return The entry point of the method at the given offset
236
*/
237
intptr_t getVFTEntry(TR::Compilation *comp, TR_OpaqueClassBlock* clazz, int32_t offset);
238
uint8_t *getROMClassRefName(TR::Compilation *comp, TR_OpaqueClassBlock *clazz, uint32_t cpIndex, int &classRefLen);
239
J9ROMConstantPoolItem *getROMConstantPool(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
240
241
/**
242
* @brief Determine if a list of classes contains less than two concrete classes.
243
* A class is considered concrete if it is not an interface or an abstract class
244
* @param subClasses List of subclasses to be checked.
245
* @return Returns 'true' if the given list of classes contains less than
246
* 2 concrete classses and false otherwise.
247
*/
248
bool containsZeroOrOneConcreteClass(TR::Compilation *comp, List<TR_PersistentClassInfo>* subClasses);
249
};
250
251
}
252
253
#endif
254
255