Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/bytecodeAssembler.cpp
32285 views
1
/*
2
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
27
#include "classfile/bytecodeAssembler.hpp"
28
#include "interpreter/bytecodes.hpp"
29
#include "memory/oopFactory.hpp"
30
#include "oops/constantPool.hpp"
31
32
#ifdef TARGET_ARCH_x86
33
# include "bytes_x86.hpp"
34
#endif
35
#ifdef TARGET_ARCH_sparc
36
# include "bytes_sparc.hpp"
37
#endif
38
#ifdef TARGET_ARCH_zero
39
# include "bytes_zero.hpp"
40
#endif
41
#ifdef TARGET_ARCH_arm
42
# include "bytes_arm.hpp"
43
#endif
44
#ifdef TARGET_ARCH_ppc
45
# include "bytes_ppc.hpp"
46
#endif
47
#ifdef TARGET_ARCH_aarch32
48
# include "bytes_aarch32.hpp"
49
#endif
50
#ifdef TARGET_ARCH_aarch64
51
# include "bytes_aarch64.hpp"
52
#endif
53
54
u2 BytecodeConstantPool::find_or_add(BytecodeCPEntry const& bcpe) {
55
u2 index;
56
u2* probe = _indices.get(bcpe);
57
if (probe == NULL) {
58
index = _entries.length();
59
_entries.append(bcpe);
60
_indices.put(bcpe, index);
61
} else {
62
index = *probe;
63
}
64
return index + _orig->length();
65
}
66
67
ConstantPool* BytecodeConstantPool::create_constant_pool(TRAPS) const {
68
if (_entries.length() == 0) {
69
return _orig;
70
}
71
72
ConstantPool* cp = ConstantPool::allocate(
73
_orig->pool_holder()->class_loader_data(),
74
_orig->length() + _entries.length(), CHECK_NULL);
75
76
cp->set_pool_holder(_orig->pool_holder());
77
_orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL);
78
79
for (int i = 0; i < _entries.length(); ++i) {
80
BytecodeCPEntry entry = _entries.at(i);
81
int idx = i + _orig->length();
82
switch (entry._tag) {
83
case BytecodeCPEntry::UTF8:
84
entry._u.utf8->increment_refcount();
85
cp->symbol_at_put(idx, entry._u.utf8);
86
break;
87
case BytecodeCPEntry::KLASS:
88
cp->unresolved_klass_at_put(
89
idx, cp->symbol_at(entry._u.klass));
90
break;
91
case BytecodeCPEntry::STRING:
92
cp->unresolved_string_at_put(
93
idx, cp->symbol_at(entry._u.string));
94
break;
95
case BytecodeCPEntry::NAME_AND_TYPE:
96
cp->name_and_type_at_put(idx,
97
entry._u.name_and_type.name_index,
98
entry._u.name_and_type.type_index);
99
break;
100
case BytecodeCPEntry::METHODREF:
101
cp->method_at_put(idx,
102
entry._u.methodref.class_index,
103
entry._u.methodref.name_and_type_index);
104
break;
105
default:
106
ShouldNotReachHere();
107
}
108
}
109
return cp;
110
}
111
112
void BytecodeAssembler::append(u1 imm_u1) {
113
_code->append(imm_u1);
114
}
115
116
void BytecodeAssembler::append(u2 imm_u2) {
117
_code->append(0);
118
_code->append(0);
119
Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2);
120
}
121
122
void BytecodeAssembler::append(u4 imm_u4) {
123
_code->append(0);
124
_code->append(0);
125
_code->append(0);
126
_code->append(0);
127
Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4);
128
}
129
130
void BytecodeAssembler::xload(u4 index, u1 onebyteop, u1 twobyteop) {
131
if (index < 4) {
132
_code->append(onebyteop + index);
133
} else {
134
_code->append(twobyteop);
135
_code->append((u2)index);
136
}
137
}
138
139
void BytecodeAssembler::dup() {
140
_code->append(Bytecodes::_dup);
141
}
142
143
void BytecodeAssembler::_new(Symbol* sym) {
144
u2 cpool_index = _cp->klass(sym);
145
_code->append(Bytecodes::_new);
146
append(cpool_index);
147
}
148
149
void BytecodeAssembler::load_string(Symbol* sym) {
150
u2 cpool_index = _cp->string(sym);
151
if (cpool_index < 0x100) {
152
ldc(cpool_index);
153
} else {
154
ldc_w(cpool_index);
155
}
156
}
157
158
void BytecodeAssembler::ldc(u1 index) {
159
_code->append(Bytecodes::_ldc);
160
append(index);
161
}
162
163
void BytecodeAssembler::ldc_w(u2 index) {
164
_code->append(Bytecodes::_ldc_w);
165
append(index);
166
}
167
168
void BytecodeAssembler::athrow() {
169
_code->append(Bytecodes::_athrow);
170
}
171
172
void BytecodeAssembler::iload(u4 index) {
173
xload(index, Bytecodes::_iload_0, Bytecodes::_iload);
174
}
175
176
void BytecodeAssembler::lload(u4 index) {
177
xload(index, Bytecodes::_lload_0, Bytecodes::_lload);
178
}
179
180
void BytecodeAssembler::fload(u4 index) {
181
xload(index, Bytecodes::_fload_0, Bytecodes::_fload);
182
}
183
184
void BytecodeAssembler::dload(u4 index) {
185
xload(index, Bytecodes::_dload_0, Bytecodes::_dload);
186
}
187
188
void BytecodeAssembler::aload(u4 index) {
189
xload(index, Bytecodes::_aload_0, Bytecodes::_aload);
190
}
191
192
void BytecodeAssembler::load(BasicType bt, u4 index) {
193
switch (bt) {
194
case T_BOOLEAN:
195
case T_CHAR:
196
case T_BYTE:
197
case T_SHORT:
198
case T_INT: iload(index); break;
199
case T_FLOAT: fload(index); break;
200
case T_DOUBLE: dload(index); break;
201
case T_LONG: lload(index); break;
202
case T_OBJECT:
203
case T_ARRAY: aload(index); break;
204
default:
205
ShouldNotReachHere();
206
}
207
}
208
209
void BytecodeAssembler::checkcast(Symbol* sym) {
210
u2 cpool_index = _cp->klass(sym);
211
_code->append(Bytecodes::_checkcast);
212
append(cpool_index);
213
}
214
215
void BytecodeAssembler::invokespecial(Method* method) {
216
invokespecial(method->klass_name(), method->name(), method->signature());
217
}
218
219
void BytecodeAssembler::invokespecial(Symbol* klss, Symbol* name, Symbol* sig) {
220
u2 methodref_index = _cp->methodref(klss, name, sig);
221
_code->append(Bytecodes::_invokespecial);
222
append(methodref_index);
223
}
224
225
void BytecodeAssembler::invokevirtual(Method* method) {
226
invokevirtual(method->klass_name(), method->name(), method->signature());
227
}
228
229
void BytecodeAssembler::invokevirtual(Symbol* klss, Symbol* name, Symbol* sig) {
230
u2 methodref_index = _cp->methodref(klss, name, sig);
231
_code->append(Bytecodes::_invokevirtual);
232
append(methodref_index);
233
}
234
235
void BytecodeAssembler::ireturn() {
236
_code->append(Bytecodes::_ireturn);
237
}
238
239
void BytecodeAssembler::lreturn() {
240
_code->append(Bytecodes::_lreturn);
241
}
242
243
void BytecodeAssembler::freturn() {
244
_code->append(Bytecodes::_freturn);
245
}
246
247
void BytecodeAssembler::dreturn() {
248
_code->append(Bytecodes::_dreturn);
249
}
250
251
void BytecodeAssembler::areturn() {
252
_code->append(Bytecodes::_areturn);
253
}
254
255
void BytecodeAssembler::_return() {
256
_code->append(Bytecodes::_return);
257
}
258
259
void BytecodeAssembler::_return(BasicType bt) {
260
switch (bt) {
261
case T_BOOLEAN:
262
case T_CHAR:
263
case T_BYTE:
264
case T_SHORT:
265
case T_INT: ireturn(); break;
266
case T_FLOAT: freturn(); break;
267
case T_DOUBLE: dreturn(); break;
268
case T_LONG: lreturn(); break;
269
case T_OBJECT:
270
case T_ARRAY: areturn(); break;
271
case T_VOID: _return(); break;
272
default:
273
ShouldNotReachHere();
274
}
275
}
276
277