Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/ROMClassBuilder.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
* ROMClassBuilder.hpp
25
*
26
*/
27
28
#ifndef ROMCLASSBUILDER_HPP_
29
#define ROMCLASSBUILDER_HPP_
30
31
/* @ddr_namespace: default */
32
#include "j9comp.h"
33
#include "j9.h"
34
#include "j2sever.h"
35
36
#include "BuildResult.hpp"
37
#include "ClassFileParser.hpp" /* included to obtain definition of VerifyClassFunction */
38
#include "StringInternTable.hpp"
39
40
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
41
#define MAX_INTERFACE_INJECTION 1
42
typedef struct InterfaceInjectionInfo {
43
J9UTF8 *interfaces[MAX_INTERFACE_INJECTION];
44
U_16 numOfInterfaces;
45
} InterfaceInjectionInfo;
46
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
47
48
class BufferManager;
49
class ClassFileOracle;
50
class ConstantPoolMap;
51
class ROMClassCreationContext;
52
class ROMClassStringInternManager;
53
class ROMClassWriter;
54
class SRPOffsetTable;
55
class SRPKeyProducer;
56
57
class ROMClassBuilder
58
{
59
public:
60
static ROMClassBuilder *getROMClassBuilder(J9PortLibrary *portLibrary, J9JavaVM *vm);
61
62
ROMClassBuilder(J9JavaVM *javaVM, J9PortLibrary *portLibrary, UDATA maxStringInternTableSize, U_8 * verifyExcludeAttribute, VerifyClassFunction verifyClassFunction);
63
~ROMClassBuilder();
64
65
bool isOK() { return _stringInternTable.isOK(); }
66
67
/**
68
* Returns the current class file buffer - setting it to NULL in the ROMClassBuilder,
69
* thereby transferring its ownership to the caller. The caller is responsible for
70
* freeing the buffer using the port library.
71
*/
72
U_8 * releaseClassFileBuffer();
73
74
BuildResult buildROMClass(ROMClassCreationContext *context);
75
76
protected:
77
void *operator new(size_t size, void *memoryPtr) { return memoryPtr; };
78
79
private:
80
81
/*
82
* Cursor Tags are used to identify what
83
* type of data is being written.
84
* These values must be linear from 0 as the max
85
* is used inside SRPOffsetTable to create an array.
86
*/
87
enum CursorTag
88
{
89
// Generic/main ROMClass data
90
RC_TAG = 0,
91
/* The header structure J9MethodDebugInfo and
92
* the J9LineNumber table are stored in this section */
93
LINE_NUMBER_TAG = 1,
94
// J9VariableInfo Table
95
VARIABLE_INFO_TAG = 2,
96
// UTF8s section of the ROMClass
97
UTF8_TAG = 3,
98
// 'Original' or intermediate class file bytes
99
INTERMEDIATE_TAG = 4,
100
//
101
MAX_TAG = INTERMEDIATE_TAG
102
};
103
104
/*
105
* A helper structure to pass around the predicted and
106
* updated size of various parts of the ROMClass.
107
*/
108
struct SizeInformation
109
{
110
UDATA rcWithOutUTF8sSize;
111
UDATA lineNumberSize;
112
UDATA variableInfoSize;
113
UDATA utf8sSize;
114
UDATA rawClassDataSize;
115
};
116
117
/* NOTE: Be sure to update J9DbgROMClassBuilder in j9nonbuilder.h when changing the state variables below. */
118
J9JavaVM *_javaVM;
119
J9PortLibrary * _portLibrary;
120
U_8 * _verifyExcludeAttribute;
121
VerifyClassFunction _verifyClassFunction;
122
UDATA _classFileParserBufferSize;
123
UDATA _bufferManagerSize;
124
U_8 *_classFileBuffer;
125
U_8 *_anonClassNameBuffer;
126
UDATA _anonClassNameBufferSize;
127
U_8 *_bufferManagerBuffer;
128
StringInternTable _stringInternTable;
129
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
130
InterfaceInjectionInfo _interfaceInjectionInfo;
131
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
132
133
BuildResult handleAnonClassName(J9CfrClassFile *classfile, bool *isLambda, ROMClassCreationContext *context);
134
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
135
BuildResult injectInterfaces(ClassFileOracle *classFileOracle);
136
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
137
U_32 computeExtraModifiers(ClassFileOracle *classFileOracle, ROMClassCreationContext *context);
138
U_32 computeOptionalFlags(ClassFileOracle *classFileOracle, ROMClassCreationContext *context);
139
BuildResult prepareAndLaydown( BufferManager *bufferManager, ClassFileParser *classFileParser, ROMClassCreationContext *context );
140
void checkDebugInfoCompression(J9ROMClass *romClass, ClassFileOracle classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, SRPOffsetTable *srpOffsetTable);
141
U_32 finishPrepareAndLaydown(
142
U_8 *romClassBuffer,
143
U_8 *lineNumberBuffer,
144
U_8 *variableInfoBuffer,
145
SizeInformation *sizeInformation,
146
U_32 modifiers,
147
U_32 extraModifiers,
148
U_32 optionalFlags,
149
bool sharingROMClass,
150
bool hasStringTableLock,
151
ClassFileOracle *classFileOracle,
152
SRPOffsetTable *srpOffsetTable,
153
SRPKeyProducer *srpKeyProducer,
154
ROMClassWriter *romClassWriter,
155
ROMClassCreationContext *context,
156
ConstantPoolMap *constantPoolMap);
157
158
void layDownROMClass(
159
ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, U_32 romSize, U_32 modifiers, U_32 extraModifiers, U_32 optionalFlags,
160
ROMClassStringInternManager *internManager, ROMClassCreationContext *context, SizeInformation *sizeInformation);
161
162
bool compareROMClassForEquality(U_8 *romClass, bool romClassIsShared,
163
ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, SRPKeyProducer *srpKeyProducer, ClassFileOracle *classFileOracle,
164
U_32 modifiers, U_32 extraModifiers, U_32 optionalFlags, ROMClassCreationContext * context, U_32 sizeToCompareForLambda, bool isLambda);
165
SharedCacheRangeInfo getSharedCacheSRPRangeInfo(void *address);
166
void getSizeInfo(ROMClassCreationContext *context, ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, bool *countDebugDataOutOfLine, SizeInformation *sizeInformation);
167
};
168
169
#endif /* ROMCLASSBUILDER_HPP_ */
170
171