Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/ClassModel.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 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_Base
26
*/
27
28
#if !defined(CLASSMODEL_HPP_)
29
#define CLASSMODEL_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "j9consts.h"
34
#include "modron.h"
35
36
#include "Bits.hpp"
37
38
/**
39
* Provides information for a given class.
40
* @ingroup GC_Base
41
*/
42
class GC_ClassModel
43
{
44
public:
45
#if !defined(J9VM_OPT_FRAGMENT_RAM_CLASSES)
46
/**
47
* Returns the size of a class, in bytes.
48
* @param clazzPtr Pointer to the class whose size is required
49
* @return Size of class in bytes
50
*/
51
MMINLINE static UDATA getSizeInBytes(J9Class *clazzPtr)
52
{
53
return clazzPtr->size;
54
}
55
56
/**
57
* Returns the size of a class, in slots.
58
* @param clazzPtr Pointer to the class whose size is required
59
* @return Size of class in slots
60
*/
61
MMINLINE static UDATA getSizeInSlots(J9Class *clazzPtr)
62
{
63
return MM_Bits::convertBytesToSlots(getSizeInBytes(clazzPtr));
64
}
65
#endif
66
67
/**
68
* Returns the depth of a class.
69
* @param clazzPtr Pointer to the class whose depth is required
70
* @return Depth of class
71
*/
72
MMINLINE static UDATA getClassDepth(J9Class *clazzPtr)
73
{
74
return J9CLASS_DEPTH(clazzPtr);
75
}
76
77
/**
78
* Returns the superclass of a class.
79
* @param clazzPtr Pointer to the class whose superclass is required
80
* @return superclass of class
81
*/
82
MMINLINE static J9Class *getSuperclass(J9Class *clazzPtr)
83
{
84
UDATA classDepth = J9CLASS_DEPTH(clazzPtr);
85
return clazzPtr->superclasses[classDepth - 1];
86
}
87
88
/**
89
* Returns TRUE if the class is an array class, FALSE otherwise.
90
* @param clazzPtr Pointer to the class
91
* @return TRUE if the class is an array class, FALSE otherwise
92
*/
93
MMINLINE static bool usesSharedITable(J9JavaVM *javaVM, J9Class *clazzPtr)
94
{
95
return (clazzPtr->romClass->modifiers & J9AccClassArray) && (clazzPtr != javaVM->booleanArrayClass);
96
}
97
98
/**
99
* Returns the size, in bytes, of an instance of a class.
100
* @param clazzPtr Pointer to the class whose instance size is required
101
* @return The size of and instance of the class in bytes
102
*/
103
MMINLINE static UDATA getInstanceSizeInBytes(J9Class *clazzPtr)
104
{
105
return clazzPtr->totalInstanceSize;
106
}
107
108
/**
109
* Calculate the number of object slots in the class.
110
* @param[in] clazz Pointer to the class
111
* @param[in] vm The J9JavaVM
112
* @return number of object slots.
113
*/
114
MMINLINE static UDATA
115
getNumberOfObjectSlots(J9Class *clazz, J9JavaVM *vm)
116
{
117
UDATA totalInstanceSize = clazz->totalInstanceSize;
118
IDATA scanLimit = (IDATA) (totalInstanceSize / J9JAVAVM_REFERENCE_SIZE(vm));
119
UDATA tempDescription = (UDATA)clazz->instanceDescription;
120
121
UDATA slotCount = 0;
122
if (scanLimit > 0) {
123
if (tempDescription & 1) {
124
/* immediate */
125
UDATA description = (tempDescription >> 1);
126
slotCount = MM_Bits::populationCount(description);
127
} else {
128
UDATA *descriptionPtr = (UDATA *) tempDescription;
129
while (scanLimit > 0) {
130
UDATA description = *descriptionPtr;
131
descriptionPtr += 1;
132
slotCount += MM_Bits::populationCount(description);
133
scanLimit = scanLimit - J9_OBJECT_DESCRIPTION_SIZE;
134
}
135
}
136
}
137
return slotCount;
138
}
139
};
140
141
#endif /* CLASSMODEL_HPP_ */
142
143