Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/c1/c1_FrameMap.cpp
83404 views
1
/*
2
* Copyright (c) 2000, 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
#include "c1/c1_FrameMap.hpp"
27
#include "c1/c1_LIR.hpp"
28
#include "runtime/sharedRuntime.hpp"
29
#ifdef TARGET_ARCH_x86
30
# include "vmreg_x86.inline.hpp"
31
#endif
32
#ifdef TARGET_ARCH_aarch64
33
# include "vmreg_aarch64.inline.hpp"
34
#endif
35
#ifdef TARGET_ARCH_sparc
36
# include "vmreg_sparc.inline.hpp"
37
#endif
38
#ifdef TARGET_ARCH_zero
39
# include "vmreg_zero.inline.hpp"
40
#endif
41
#ifdef TARGET_ARCH_arm
42
# include "vmreg_arm.inline.hpp"
43
#endif
44
#ifdef TARGET_ARCH_ppc
45
# include "vmreg_ppc.inline.hpp"
46
#endif
47
#ifdef TARGET_ARCH_aarch32
48
# include "vmreg_aarch32.inline.hpp"
49
#endif
50
51
52
53
//-----------------------------------------------------
54
55
// Convert method signature into an array of BasicTypes for the arguments
56
BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
57
ciSignature* sig = method->signature();
58
BasicTypeList* sta = new BasicTypeList(method->arg_size());
59
// add receiver, if any
60
if (!method->is_static()) sta->append(T_OBJECT);
61
// add remaining arguments
62
for (int i = 0; i < sig->count(); i++) {
63
ciType* type = sig->type_at(i);
64
BasicType t = type->basic_type();
65
if (t == T_ARRAY) {
66
t = T_OBJECT;
67
}
68
sta->append(t);
69
}
70
// done
71
return sta;
72
}
73
74
75
CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
76
// compute the size of the arguments first. The signature array
77
// that java_calling_convention takes includes a T_VOID after double
78
// work items but our signatures do not.
79
int i;
80
int sizeargs = 0;
81
for (i = 0; i < signature->length(); i++) {
82
sizeargs += type2size[signature->at(i)];
83
}
84
85
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
86
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
87
int sig_index = 0;
88
for (i = 0; i < sizeargs; i++, sig_index++) {
89
sig_bt[i] = signature->at(sig_index);
90
if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
91
sig_bt[i + 1] = T_VOID;
92
i++;
93
}
94
}
95
96
intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
97
LIR_OprList* args = new LIR_OprList(signature->length());
98
for (i = 0; i < sizeargs;) {
99
BasicType t = sig_bt[i];
100
assert(t != T_VOID, "should be skipping these");
101
LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
102
args->append(opr);
103
if (opr->is_address()) {
104
LIR_Address* addr = opr->as_address_ptr();
105
assert(addr->disp() == (int)addr->disp(), "out of range value");
106
out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
107
}
108
i += type2size[t];
109
}
110
assert(args->length() == signature->length(), "size mismatch");
111
out_preserve += SharedRuntime::out_preserve_stack_slots();
112
113
if (outgoing) {
114
// update the space reserved for arguments.
115
update_reserved_argument_area_size(out_preserve * BytesPerWord);
116
}
117
return new CallingConvention(args, out_preserve);
118
}
119
120
121
CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
122
// compute the size of the arguments first. The signature array
123
// that java_calling_convention takes includes a T_VOID after double
124
// work items but our signatures do not.
125
int i;
126
int sizeargs = 0;
127
for (i = 0; i < signature->length(); i++) {
128
sizeargs += type2size[signature->at(i)];
129
}
130
131
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
132
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
133
int sig_index = 0;
134
for (i = 0; i < sizeargs; i++, sig_index++) {
135
sig_bt[i] = signature->at(sig_index);
136
if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
137
sig_bt[i + 1] = T_VOID;
138
i++;
139
}
140
}
141
142
intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);
143
LIR_OprList* args = new LIR_OprList(signature->length());
144
for (i = 0; i < sizeargs;) {
145
BasicType t = sig_bt[i];
146
assert(t != T_VOID, "should be skipping these");
147
148
// C calls are always outgoing
149
bool outgoing = true;
150
LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
151
// they might be of different types if for instance floating point
152
// values are passed in cpu registers, but the sizes must match.
153
assert(type2size[opr->type()] == type2size[t], "type mismatch");
154
args->append(opr);
155
if (opr->is_address()) {
156
LIR_Address* addr = opr->as_address_ptr();
157
out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
158
}
159
i += type2size[t];
160
}
161
assert(args->length() == signature->length(), "size mismatch");
162
out_preserve += SharedRuntime::out_preserve_stack_slots();
163
update_reserved_argument_area_size(out_preserve * BytesPerWord);
164
return new CallingConvention(args, out_preserve);
165
}
166
167
168
//--------------------------------------------------------
169
// FrameMap
170
//--------------------------------------------------------
171
172
bool FrameMap::_init_done = false;
173
Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
174
int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
175
176
177
FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
178
assert(_init_done, "should already be completed");
179
180
_framesize = -1;
181
_num_spills = -1;
182
183
assert(monitors >= 0, "not set");
184
_num_monitors = monitors;
185
assert(reserved_argument_area_size >= 0, "not set");
186
_reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
187
188
_argcount = method->arg_size();
189
_argument_locations = new intArray(_argcount, -1);
190
_incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
191
_oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
192
193
int java_index = 0;
194
for (int i = 0; i < _incoming_arguments->length(); i++) {
195
LIR_Opr opr = _incoming_arguments->at(i);
196
if (opr->is_address()) {
197
LIR_Address* address = opr->as_address_ptr();
198
_argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
199
_incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
200
}
201
java_index += type2size[opr->type()];
202
}
203
204
}
205
206
207
bool FrameMap::finalize_frame(int nof_slots) {
208
assert(nof_slots >= 0, "must be positive");
209
assert(_num_spills == -1, "can only be set once");
210
_num_spills = nof_slots;
211
assert(_framesize == -1, "should only be calculated once");
212
_framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +
213
_num_monitors * sizeof(BasicObjectLock) +
214
sizeof(intptr_t) + // offset of deopt orig pc
215
frame_pad_in_bytes,
216
StackAlignmentInBytes) / 4;
217
int java_index = 0;
218
for (int i = 0; i < _incoming_arguments->length(); i++) {
219
LIR_Opr opr = _incoming_arguments->at(i);
220
if (opr->is_stack()) {
221
_argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
222
_argument_locations->at(java_index));
223
}
224
java_index += type2size[opr->type()];
225
}
226
// make sure it's expressible on the platform
227
return validate_frame();
228
}
229
230
VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
231
int offset_in_bytes = in_bytes(offset);
232
assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
233
assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
234
return VMRegImpl::stack2reg(offset_in_bytes / 4);
235
}
236
237
238
bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
239
Location::Type loc_type,
240
Location* loc) const {
241
int offset = in_bytes(byte_offset_from_sp);
242
assert(offset >= 0, "incorrect offset");
243
if (!Location::legal_offset_in_bytes(offset)) {
244
return false;
245
}
246
Location tmp_loc = Location::new_stk_loc(loc_type, offset);
247
*loc = tmp_loc;
248
return true;
249
}
250
251
252
bool FrameMap::locations_for_slot (int index, Location::Type loc_type,
253
Location* loc, Location* second) const {
254
ByteSize offset_from_sp = sp_offset_for_slot(index);
255
if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
256
return false;
257
}
258
if (second != NULL) {
259
// two word item
260
offset_from_sp = offset_from_sp + in_ByteSize(4);
261
return location_for_sp_offset(offset_from_sp, loc_type, second);
262
}
263
return true;
264
}
265
266
//////////////////////
267
// Public accessors //
268
//////////////////////
269
270
271
ByteSize FrameMap::sp_offset_for_slot(const int index) const {
272
if (index < argcount()) {
273
int offset = _argument_locations->at(index);
274
assert(offset != -1, "not a memory argument");
275
assert(offset >= framesize() * 4, "argument inside of frame");
276
return in_ByteSize(offset);
277
}
278
ByteSize offset = sp_offset_for_spill(index - argcount());
279
assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
280
return offset;
281
}
282
283
284
ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
285
ByteSize offset = sp_offset_for_slot(index);
286
if (index >= argcount()) {
287
assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
288
}
289
return offset;
290
}
291
292
293
ByteSize FrameMap::sp_offset_for_spill(const int index) const {
294
assert(index >= 0 && index < _num_spills, "out of range");
295
int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
296
index * spill_slot_size_in_bytes;
297
return in_ByteSize(offset);
298
}
299
300
ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
301
int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
302
_num_spills * spill_slot_size_in_bytes;
303
int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
304
return in_ByteSize(offset);
305
}
306
307
ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
308
check_monitor_index(index);
309
return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
310
}
311
312
ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
313
check_monitor_index(index);
314
return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
315
}
316
317
318
// For OopMaps, map a local variable or spill index to an VMReg.
319
// This is the offset from sp() in the frame of the slot for the index,
320
// skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
321
//
322
// C ABI size +
323
// framesize + framesize +
324
// stack0 stack0 stack0 0 <- VMReg->value()
325
// | | | <registers> |
326
// ..........|..............|..............|.............|
327
// 0 1 2 3 | <C ABI area> | 4 5 6 ...... | <- local indices
328
// ^ ^ sp()
329
// | |
330
// arguments non-argument locals
331
332
333
VMReg FrameMap::regname(LIR_Opr opr) const {
334
if (opr->is_single_cpu()) {
335
assert(!opr->is_virtual(), "should not see virtual registers here");
336
return opr->as_register()->as_VMReg();
337
} else if (opr->is_single_stack()) {
338
return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
339
} else if (opr->is_address()) {
340
LIR_Address* addr = opr->as_address_ptr();
341
assert(addr->base() == stack_pointer(), "sp based addressing only");
342
return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
343
}
344
ShouldNotReachHere();
345
return VMRegImpl::Bad();
346
}
347
348
349
350
351
// ------------ extra spill slots ---------------
352
353