Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/ilgen/J9ByteCodeIterator.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 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
#ifndef J9BYTECODEITERATOR_INCL
24
#define J9BYTECODEITERATOR_INCL
25
26
#include "env/jittypes.h"
27
#include "il/LabelSymbol.hpp"
28
#include "il/MethodSymbol.hpp"
29
#include "il/RegisterMappedSymbol.hpp"
30
#include "il/ResolvedMethodSymbol.hpp"
31
#include "il/StaticSymbol.hpp"
32
#include "il/Symbol.hpp"
33
#include "ilgen/ByteCodeIterator.hpp"
34
#include "infra/Link.hpp"
35
#include "env/j9method.h"
36
#include "env/VMJ9.h"
37
#include "ilgen/J9ByteCode.hpp"
38
39
class TR_J9ByteCodeIterator : public TR_ByteCodeIterator<TR_J9ByteCode, TR_ResolvedJ9Method>
40
{
41
typedef TR_ByteCodeIterator<TR_J9ByteCode, TR_ResolvedJ9Method> Base;
42
43
public:
44
TR_ALLOC(TR_Memory::ByteCodeIterator);
45
46
enum TR_ByteCodeFlags
47
{
48
SizeMask = 0x07,
49
Branch = 0x08,
50
ToHandler = 0x10,
51
Absolute = 0x20,
52
TwoByteOffset = 0x40,
53
FourByteOffset = 0x80,
54
55
TwoByteRelativeBranch = (Branch | TwoByteOffset),
56
FourByteRelativeBranch = (Branch | FourByteOffset),
57
TwoByteAbsoluteBranch = (Branch | Absolute | TwoByteOffset),
58
FourByteAbsoluteBranch = (Branch | Absolute | FourByteOffset),
59
TwoByteRelativeToHandler = (ToHandler | TwoByteOffset),
60
FourByteRelativeToHandler = (ToHandler | FourByteOffset),
61
TwoByteAbsoluteToHandler = (ToHandler | Absolute | TwoByteOffset),
62
FourByteAbsoluteToHandler = (ToHandler | Absolute | FourByteOffset),
63
64
};
65
66
TR_J9ByteCodeIterator(TR::ResolvedMethodSymbol *methodSymbol, TR::Compilation *comp)
67
: Base(methodSymbol, static_cast<TR_ResolvedJ9Method*>(methodSymbol->getResolvedMethod()), comp)
68
{}
69
70
TR_J9ByteCodeIterator(TR::ResolvedMethodSymbol *methodSymbol, TR_ResolvedJ9Method *method, TR_J9VMBase * fe, TR::Compilation * comp) :
71
Base(methodSymbol, method, comp)
72
{
73
initialize(method, fe);
74
}
75
76
void initialize(TR_ResolvedJ9Method *, TR_J9VMBase *);
77
78
int32_t defaultTargetIndex() { return (int32_t)(_bcIndex + 1 + ((4 - ((intptr_t)&_code[_bcIndex+1] & 3)) & 3)); }
79
80
bool isThisChanged();
81
82
int32_t findFloatingPointInstruction();
83
84
int32_t nextSwitchValue(int32_t & bcIndex);
85
86
static int32_t size(TR_J9ByteCode bc)
87
{
88
return _byteCodeFlags[bc] & SizeMask;
89
}
90
91
TR_J9ByteCode first()
92
{
93
_bcIndex = 0;
94
return current();
95
}
96
97
TR_J9ByteCode next()
98
{
99
int32_t size = _byteCodeFlags[_bc] & SizeMask;
100
if (size)
101
_bcIndex += size;
102
else
103
stepOverVariableSizeBC();
104
return current();
105
}
106
107
int32_t currentByteCodeIndex()
108
{
109
return _bcIndex;
110
}
111
112
TR_J9ByteCode current()
113
{
114
_bc = (_bcIndex >= _maxByteCodeIndex ? J9BCunknown : convertOpCodeToByteCodeEnum(_code[_bcIndex]));
115
TR_ASSERT_FATAL(_bcIndex >= _maxByteCodeIndex || _bc != J9BCunknown, "Unknown bytecode to JIT %d \n", _code[_bcIndex]);
116
return _bc;
117
}
118
119
static TR_J9ByteCode convertOpCodeToByteCodeEnum(uint8_t opcode)
120
{
121
return _opCodeToByteCodeEnum[opcode];
122
}
123
uint32_t estimatedCodeSize() { return estimatedCodeSize(current()); }
124
static uint32_t estimatedCodeSize(TR_J9ByteCode bc) { return _estimatedCodeSize[bc]; }
125
126
127
bool isBranch() { return (_byteCodeFlags[_bc] & Branch) != 0; }
128
int32_t relativeBranch() { TR_ASSERT((_byteCodeFlags[_bc] & Absolute) == 0, "assertion failure"); return (_byteCodeFlags[_bc] & TwoByteOffset) ? next2BytesSigned() : next4BytesSigned(); }
129
int32_t absoluteBranch() { TR_ASSERT((_byteCodeFlags[_bc] & Absolute) != 0, "assertion failure"); return (_byteCodeFlags[_bc] & TwoByteOffset) ? next2Bytes() : next4Bytes(); }
130
int32_t branchDestination(int32_t base) { TR_ASSERT((_byteCodeFlags[_bc] & Branch) != 0, "assertion failure"); return ((_byteCodeFlags[_bc] & Absolute) != 0) ? absoluteBranch() : base + relativeBranch(); }
131
132
uint8_t nextByte(int32_t o = 1) { return _code[_bcIndex + o]; }
133
int8_t nextByteSigned(int32_t o = 1) { return nextByte(o); }
134
135
#if defined(NETWORK_ORDER_BYTECODE)
136
uint16_t next2Bytes(int32_t o = 1) { return nextByte(o) << 8 | nextByte(o + 1); }
137
uint32_t next4Bytes(int32_t o = 1) { return nextByte(o) << 24 | nextByte(o + 1) << 16 |
138
nextByte(o + 2) << 8 |
139
nextByte(o + 3); }
140
int16_t next2BytesSigned(int32_t o = 1) { return next2Bytes(o); }
141
int32_t next4BytesSigned(int32_t o = 1) { return next4Bytes(o); }
142
#else
143
uint16_t next2Bytes(int32_t o = 1) { return *((uint16_t*)&_code[_bcIndex + o]); }
144
uint32_t next4Bytes(int32_t o = 1) { return *((uint32_t*)&_code[_bcIndex + o]); }
145
int16_t next2BytesSigned(int32_t o = 1) { return next2Bytes(o); }
146
int32_t next4BytesSigned(int32_t o = 1) { return next4Bytes(o); }
147
#endif
148
149
protected:
150
void stepOverVariableSizeBC();
151
152
void printFirst(int32_t i);
153
void printCPIndex(int32_t i);
154
void printConstant(int32_t i);
155
void printConstant(double d);
156
void printFirstAndConstant(int32_t i, int32_t j);
157
void printJumpIndex(int32_t offset);
158
159
void printByteCodePrologue();
160
void printByteCode();
161
void printByteCodeEpilogue();
162
163
TR_J9VMBase *fe() { return _fe; }
164
//TR_ResolvedJ9Method *method() { return _method; }
165
//TR_ResolvedJ9Method * _method;
166
TR_J9VMBase * _fe;
167
const uint8_t * _code;
168
TR_J9ByteCode _bc; // TODO: remove this field, Replace uses with call to current()
169
170
static const uint8_t _byteCodeFlags[];
171
static const TR_J9ByteCode _opCodeToByteCodeEnum[256];
172
static const uint8_t _estimatedCodeSize[];
173
174
static TR::ILOpCodes _lcmpOps[];
175
static TR::ILOpCodes _fcmplOps[];
176
static TR::ILOpCodes _fcmpgOps[];
177
static TR::ILOpCodes _dcmplOps[];
178
static TR::ILOpCodes _dcmpgOps[];
179
};
180
181
#endif
182
183
184