Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/ROMClassWriter.hpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2021 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
* ROMClassWriter.hpp
25
*/
26
27
#ifndef ROMCLASSWRITER_HPP_
28
#define ROMCLASSWRITER_HPP_
29
30
/* @ddr_namespace: default */
31
#include "j9comp.h"
32
33
#include "ClassFileOracle.hpp"
34
#include "ConstantPoolMap.hpp"
35
#include "SRPOffsetTable.hpp"
36
#include "ROMClassCreationContext.hpp"
37
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
38
#include "ROMClassBuilder.hpp" /* included to obtain definition of InterfaceInjectionInfo */
39
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
40
41
class Cursor;
42
class SRPKeyProducer;
43
class BufferManager;
44
45
class ROMClassWriter
46
{
47
public:
48
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
49
ROMClassWriter(BufferManager *bufferManager, ClassFileOracle *classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, ROMClassCreationContext *context, InterfaceInjectionInfo *interfaceInjectionInfo);
50
#else /* J9VM_OPT_VALHALLA_VALUE_TYPES */
51
ROMClassWriter(BufferManager *bufferManager, ClassFileOracle *classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, ROMClassCreationContext *context);
52
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
53
~ROMClassWriter();
54
55
void setSRPOffsetTable(SRPOffsetTable *srpOffsetTable)
56
{
57
_srpOffsetTable = srpOffsetTable;
58
59
if (_context->isIntermediateDataAClassfile()) {
60
/* Check if intermediateClassData can be re-used. It is re-usable when class is being re-transformed.
61
* However, do not re-use intermediateClassData from previous ROMClass if
62
* previous ROMClass is in private memory and the new class is share-able,
63
* otherwise we would end up with intermediateClassData of shared ROMClass pointing to private memory of the JVM.
64
*
65
* Do not re-use intermediateClassData if class is an anonClass. AnonClasses can be unloaded separately which would cause a
66
* problem if romClasses reference each other
67
*/
68
if ((false == _context->isClassAnon())
69
&& ((false == _context->isROMClassShareable())
70
|| (true == _context->isIntermediateClassDataShareable()))
71
) {
72
reuseIntermediateClassData();
73
}
74
}
75
}
76
77
void reuseIntermediateClassData()
78
{
79
if ((false == _context->isReusingIntermediateClassData())
80
&& (true == _context->isRetransformAllowed())
81
&& (true == _context->isRetransforming())
82
) {
83
_srpOffsetTable->setInternedAt(_intermediateClassDataSRPKey, _context->getIntermediateClassDataFromPreviousROMClass());
84
_context->setReusingIntermediateClassData();
85
}
86
}
87
88
enum MarkOrWrite {
89
MARK_AND_COUNT_ONLY,
90
WRITE
91
};
92
93
/*
94
* write out the entire ROMClass, including UTF8s
95
*/
96
void writeROMClass(Cursor *cursor,
97
Cursor *lineNumberCursor,
98
Cursor *variableInfoCursor,
99
Cursor *utf8Cursor,
100
Cursor *classDataCursor,
101
U_32 romSize,
102
U_32 modifiers,
103
U_32 extraModifiers,
104
U_32 optionalFlags,
105
MarkOrWrite markOrWrite );
106
107
/*
108
* writes out only UTF8s
109
*/
110
void writeUTF8s(Cursor *cursor);
111
112
bool isOK() const { return OK == _buildResult; }
113
BuildResult getBuildResult() const { return _buildResult; }
114
115
private:
116
class AnnotationWriter;
117
class AnnotationElementWriter;
118
class NamedAnnotationElementWriter;
119
class ConstantPoolWriter;
120
class ConstantPoolShapeDescriptionWriter;
121
class CheckSize;
122
class Helper;
123
class CallSiteWriter;
124
125
struct MethodNotes {
126
U_32 debugInfoSize;
127
U_32 stackMapSize;
128
};
129
130
void writeConstantPool(Cursor *cursor, bool markAndCountOnly);
131
void writeFields(Cursor *cursor, bool markAndCountOnly);
132
void writeInterfaces(Cursor *cursor, bool markAndCountOnly);
133
void writeInnerClasses(Cursor *cursor, bool markAndCountOnly);
134
void writeEnclosedInnerClasses(Cursor *cursor, bool markAndCountOnly);
135
void writeNestMembers(Cursor *cursor, bool markAndCountOnly);
136
void writeNameAndSignatureBlock(Cursor *cursor);
137
void writeMethods(Cursor *cursor, Cursor *lineNumberCursor, Cursor *variableInfoCursor, bool markAndCountOnly);
138
void writeMethodDebugInfo(ClassFileOracle::MethodIterator *methodIterator, Cursor *lineNumberCursor, Cursor *variableInfoCursor, bool markAndCountOnly, bool existHasDebugInformation);
139
void writeConstantPoolShapeDescriptions(Cursor *cursor, bool markAndCountOnly);
140
void writeAnnotationInfo(Cursor *cursor);
141
void writeSourceDebugExtension(Cursor *cursor);
142
void writeRecordComponents(Cursor *cursor, bool markAndCountOnly);
143
void writeStackMaps(Cursor *cursor);
144
void writeOptionalInfo(Cursor *cursor);
145
void writeCallSiteData(Cursor *cursor, bool markAndCountOnly);
146
#if defined(J9VM_OPT_METHOD_HANDLE)
147
void writeVarHandleMethodTypeLookupTable(Cursor *cursor, bool markAndCountOnly);
148
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
149
void writeStaticSplitTable(Cursor *cursor, bool markAndCountOnly);
150
void writeSpecialSplitTable(Cursor *cursor, bool markAndCountOnly);
151
void writeByteCodes(Cursor *cursor, ClassFileOracle::MethodIterator *methodIterator);
152
U_32 computeNativeSignatureSize(U_8 *methodDescriptor);
153
void writeNativeSignature(Cursor *cursor, U_8 *methodDescriptor, U_8 nativeArgCount);
154
void writePermittedSubclasses(Cursor *cursor, bool markAndCountOnly);
155
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
156
void writeInjectedInterfaces(Cursor *cursor, bool markAndCountOnly);
157
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
158
159
BufferManager *_bufferManager;
160
ClassFileOracle *_classFileOracle;
161
SRPKeyProducer *_srpKeyProducer;
162
ConstantPoolMap *_constantPoolMap;
163
SRPOffsetTable *_srpOffsetTable;
164
ROMClassCreationContext *_context;
165
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
166
InterfaceInjectionInfo *_interfaceInjectionInfo;
167
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
168
MethodNotes *_methodNotes;
169
BuildResult _buildResult;
170
UDATA _interfacesSRPKey;
171
UDATA _methodsSRPKey;
172
UDATA _fieldsSRPKey;
173
UDATA _cpDescriptionShapeSRPKey;
174
UDATA _innerClassesSRPKey;
175
UDATA _enclosedInnerClassesSRPKey;
176
#if JAVA_SPEC_VERSION >= 11
177
UDATA _nestMembersSRPKey;
178
#endif /* JAVA_SPEC_VERSION >= 11 */
179
UDATA _optionalInfoSRPKey;
180
UDATA _stackMapsSRPKey;
181
UDATA _enclosingMethodSRPKey;
182
UDATA _sourceDebugExtensionSRPKey;
183
UDATA _intermediateClassDataSRPKey;
184
UDATA _annotationInfoClassSRPKey;
185
UDATA _typeAnnotationInfoSRPKey;
186
UDATA _callSiteDataSRPKey;
187
#if defined(J9VM_OPT_METHOD_HANDLE)
188
UDATA _varHandleMethodTypeLookupTableSRPKey;
189
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
190
UDATA _staticSplitTableSRPKey;
191
UDATA _specialSplitTableSRPKey;
192
UDATA _recordInfoSRPKey;
193
UDATA _permittedSubclassesInfoSRPKey;
194
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
195
UDATA _injectedInterfaceInfoSRPKey;
196
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
197
};
198
199
#endif /* ROMCLASSWRITER_HPP_ */
200
201