Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch32/vm/c1_CodeStubs_aarch32.cpp
32285 views
1
/*
2
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
// This file is a derivative work resulting from (and including) modifications
26
// made by Azul Systems, Inc. The dates of such changes are 2013-2016.
27
// Copyright 2013-2016 Azul Systems, Inc. All Rights Reserved.
28
//
29
// Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale,
30
// CA 94089 USA or visit www.azul.com if you need additional information or
31
// have any questions.
32
33
#include "precompiled.hpp"
34
#include "c1/c1_CodeStubs.hpp"
35
#include "c1/c1_FrameMap.hpp"
36
#include "c1/c1_LIRAssembler.hpp"
37
#include "c1/c1_MacroAssembler.hpp"
38
#include "c1/c1_Runtime1.hpp"
39
#include "nativeInst_aarch32.hpp"
40
#include "runtime/sharedRuntime.hpp"
41
#include "vmreg_aarch32.inline.hpp"
42
#if INCLUDE_ALL_GCS
43
#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
44
#endif
45
46
#define __ ce->masm()->
47
48
#define should_not_reach_here() should_not_reach_here_line(__FILE__, __LINE__)
49
50
void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
51
__ bind(_entry);
52
ce->store_parameter(_method->as_register(), 1);
53
ce->store_parameter(_bci, 0);
54
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));
55
ce->add_call_info_here(_info);
56
ce->verify_oop_map(_info);
57
__ b(_continuation);
58
}
59
60
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
61
bool throw_index_out_of_bounds_exception)
62
: _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
63
, _index(index)
64
{
65
assert(info != NULL, "must have info");
66
_info = new CodeEmitInfo(info);
67
}
68
69
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
70
__ bind(_entry);
71
if (_info->deoptimize_on_exception()) {
72
address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
73
__ far_call(RuntimeAddress(a));
74
ce->add_call_info_here(_info);
75
ce->verify_oop_map(_info);
76
debug_only(__ should_not_reach_here());
77
return;
78
}
79
80
if (_index->is_cpu_register()) {
81
__ mov(rscratch1, _index->as_register());
82
} else {
83
__ mov(rscratch1, _index->as_jint());
84
}
85
Runtime1::StubID stub_id;
86
if (_throw_index_out_of_bounds_exception) {
87
stub_id = Runtime1::throw_index_exception_id;
88
} else {
89
stub_id = Runtime1::throw_range_check_failed_id;
90
}
91
__ far_call(RuntimeAddress(Runtime1::entry_for(stub_id)), NULL, rscratch2);
92
ce->add_call_info_here(_info);
93
ce->verify_oop_map(_info);
94
debug_only(__ should_not_reach_here());
95
}
96
97
PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {
98
_info = new CodeEmitInfo(info);
99
}
100
101
void PredicateFailedStub::emit_code(LIR_Assembler* ce) {
102
__ bind(_entry);
103
address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
104
__ far_call(RuntimeAddress(a));
105
ce->add_call_info_here(_info);
106
ce->verify_oop_map(_info);
107
debug_only(__ should_not_reach_here());
108
}
109
110
void DivByZeroStub::emit_code(LIR_Assembler* ce) {
111
if (_offset != -1) {
112
ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
113
}
114
__ bind(_entry);
115
__ far_call(Address(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type));
116
ce->add_call_info_here(_info);
117
ce->verify_oop_map(_info);
118
#ifdef ASSERT
119
__ should_not_reach_here();
120
#endif
121
}
122
123
124
125
// Implementation of NewInstanceStub
126
127
NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
128
_result = result;
129
_klass = klass;
130
_klass_reg = klass_reg;
131
_info = new CodeEmitInfo(info);
132
assert(stub_id == Runtime1::new_instance_id ||
133
stub_id == Runtime1::fast_new_instance_id ||
134
stub_id == Runtime1::fast_new_instance_init_check_id,
135
"need new_instance id");
136
_stub_id = stub_id;
137
}
138
139
140
141
void NewInstanceStub::emit_code(LIR_Assembler* ce) {
142
assert(__ rsp_offset() == 0, "frame size should be fixed");
143
__ bind(_entry);
144
__ mov(r3, _klass_reg->as_register());
145
__ far_call(RuntimeAddress(Runtime1::entry_for(_stub_id)));
146
ce->add_call_info_here(_info);
147
ce->verify_oop_map(_info);
148
assert(_result->as_register() == r0, "result must in r0,");
149
__ b(_continuation);
150
}
151
152
153
// Implementation of NewTypeArrayStub
154
155
// Implementation of NewTypeArrayStub
156
157
NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
158
_klass_reg = klass_reg;
159
_length = length;
160
_result = result;
161
_info = new CodeEmitInfo(info);
162
}
163
164
165
void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
166
assert(__ rsp_offset() == 0, "frame size should be fixed");
167
__ bind(_entry);
168
assert(_length->as_register() == r6, "length must in r6,");
169
assert(_klass_reg->as_register() == r3, "klass_reg must in r3");
170
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));
171
ce->add_call_info_here(_info);
172
ce->verify_oop_map(_info);
173
assert(_result->as_register() == r0, "result must in r0");
174
__ b(_continuation);
175
}
176
177
178
// Implementation of NewObjectArrayStub
179
180
NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
181
_klass_reg = klass_reg;
182
_result = result;
183
_length = length;
184
_info = new CodeEmitInfo(info);
185
}
186
187
188
void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
189
assert(__ rsp_offset() == 0, "frame size should be fixed");
190
__ bind(_entry);
191
assert(_length->as_register() == r6, "length must in r6");
192
assert(_klass_reg->as_register() == r3, "klass_reg must in r3");
193
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));
194
ce->add_call_info_here(_info);
195
ce->verify_oop_map(_info);
196
assert(_result->as_register() == r0, "result must in r0");
197
__ b(_continuation);
198
}
199
// Implementation of MonitorAccessStubs
200
201
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
202
: MonitorAccessStub(obj_reg, lock_reg)
203
{
204
_info = new CodeEmitInfo(info);
205
}
206
207
208
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
209
assert(__ rsp_offset() == 0, "frame size should be fixed");
210
__ bind(_entry);
211
ce->store_parameter(_obj_reg->as_register(), 1);
212
ce->store_parameter(_lock_reg->as_register(), 0);
213
Runtime1::StubID enter_id;
214
if (ce->compilation()->has_fpu_code()) {
215
enter_id = Runtime1::monitorenter_id;
216
} else {
217
enter_id = Runtime1::monitorenter_nofpu_id;
218
}
219
__ far_call(RuntimeAddress(Runtime1::entry_for(enter_id)));
220
ce->add_call_info_here(_info);
221
ce->verify_oop_map(_info);
222
__ b(_continuation);
223
}
224
225
226
void MonitorExitStub::emit_code(LIR_Assembler* ce) {
227
__ bind(_entry);
228
if (_compute_lock) {
229
// lock_reg was destroyed by fast unlocking attempt => recompute it
230
ce->monitor_address(_monitor_ix, _lock_reg);
231
}
232
ce->store_parameter(_lock_reg->as_register(), 0);
233
// note: non-blocking leaf routine => no call info needed
234
Runtime1::StubID exit_id;
235
if (ce->compilation()->has_fpu_code()) {
236
exit_id = Runtime1::monitorexit_id;
237
} else {
238
exit_id = Runtime1::monitorexit_nofpu_id;
239
}
240
__ adr(lr, _continuation);
241
__ far_jump(RuntimeAddress(Runtime1::entry_for(exit_id)));
242
}
243
244
245
// Implementation of patching:
246
// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)
247
// - Replace original code with a call to the stub
248
// At Runtime:
249
// - call to stub, jump to runtime
250
// - in runtime: preserve all registers (rspecially objects, i.e., source and destination object)
251
// - in runtime: after initializing class, restore original code, reexecute instruction
252
253
int PatchingStub::_patch_info_offset = 0;
254
255
void PatchingStub::align_patch_site(MacroAssembler* masm) {
256
}
257
258
void PatchingStub::emit_code(LIR_Assembler* ce) {
259
// NativeCall::instruction_size is dynamically calculated based on CPU,
260
// armv7 -> 3 instructions, armv6 -> 5 instructions. Initialize _patch_info_offset
261
// here, when CPU is determined already.
262
if (!_patch_info_offset)
263
_patch_info_offset = -NativeCall::instruction_size;
264
assert(_patch_info_offset == -NativeCall::instruction_size, "must not change");
265
assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, "not enough room for call");
266
267
Label call_patch;
268
269
// static field accesses have special semantics while the class
270
// initializer is being run so we emit a test which can be used to
271
// check that this code is being executed by the initializing
272
// thread.
273
address being_initialized_entry = __ pc();
274
if (CommentedAssembly) {
275
__ block_comment(" patch template");
276
}
277
address start = __ pc();
278
if (_id == load_klass_id) {
279
// produce a copy of the load klass instruction for use by the being initialized case
280
int metadata_index = -1;
281
CodeSection* cs = __ code_section();
282
RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);
283
while (iter.next()) {
284
if (iter.type() == relocInfo::metadata_type) {
285
metadata_Relocation* r = iter.metadata_reloc();
286
assert(metadata_index == -1, "uninitalized yet");
287
metadata_index = r->metadata_index();
288
break;
289
}
290
}
291
assert(metadata_index != -1, "initialized");
292
__ relocate(metadata_Relocation::spec(metadata_index));
293
__ patchable_load(_obj, __ pc());
294
while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {
295
__ nop();
296
}
297
#ifdef ASSERT
298
for (int i = 0; i < _bytes_to_copy; i++) {
299
assert(*(_pc_start + i) == *(start + i), "should be the same code");
300
}
301
#endif
302
} else if (_id == load_mirror_id || _id == load_appendix_id) {
303
// produce a copy of the load mirror instruction for use by the being
304
// initialized case
305
int oop_index = -1;
306
CodeSection* cs = __ code_section();
307
RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);
308
while (iter.next()) {
309
if (iter.type() == relocInfo::oop_type) {
310
oop_Relocation* r = iter.oop_reloc();
311
assert(oop_index == -1, "uninitalized yet");
312
oop_index = r->oop_index();
313
break;
314
}
315
}
316
assert(oop_index != -1, "initialized");
317
__ relocate(oop_Relocation::spec(oop_index));
318
__ patchable_load(_obj, __ pc());
319
while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {
320
__ nop();
321
}
322
#ifdef ASSERT
323
for (int i = 0; i < _bytes_to_copy; i++) {
324
assert(*(_pc_start + i) == *(start + i), "should be the same code");
325
}
326
#endif
327
} else if (_id == access_field_id) {
328
// make a copy the code which is going to be patched.
329
address const_addr = (address) -1;
330
CodeSection* cs = __ code_section();
331
RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);
332
while (iter.next()) {
333
if (iter.type() == relocInfo::section_word_type) {
334
section_word_Relocation* r = iter.section_word_reloc();
335
assert(const_addr == (address) -1, "uninitalized yet");
336
const_addr = r->target();
337
break;
338
}
339
}
340
assert(const_addr != (address) -1, "initialized");
341
__ relocate(section_word_Relocation::spec(const_addr, CodeBuffer::SECT_CONSTS));
342
__ patchable_load(rscratch1, const_addr);
343
while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {
344
__ nop();
345
}
346
#ifdef ASSERT
347
intptr_t* from = (intptr_t*) start;
348
intptr_t* to = (intptr_t*) _pc_start;
349
350
assert(NativeFarLdr::from((address) (from))->data_addr()
351
== NativeFarLdr::from((address) (to))->data_addr(),
352
"should load from one addr)");
353
354
address next_from = NativeFarLdr::from(start)->next_instruction_address();
355
address next_to = NativeFarLdr::from(_pc_start)->next_instruction_address();
356
357
assert(sizeof(*start) == sizeof(char), "Correct below");
358
address end = start + _bytes_to_copy;
359
while (next_from < end) {
360
assert(*next_from == *next_to, "should be the same code");
361
next_from++;
362
next_to++;
363
}
364
#endif
365
} else {
366
ShouldNotReachHere();
367
}
368
369
int bytes_to_skip = _bytes_to_copy;
370
371
if (_id == load_mirror_id) {
372
int offset = __ offset();
373
if (CommentedAssembly) {
374
__ block_comment(" being_initialized check");
375
}
376
assert(_obj != noreg, "must be a valid register");
377
// Load without verification to keep code size small. We need it because
378
// begin_initialized_entry_offset has to fit in a byte. Also, we know it's not null.
379
__ ldr(rscratch1, Address(_obj, java_lang_Class::klass_offset_in_bytes()));
380
__ ldr(rscratch1, Address(rscratch1, InstanceKlass::init_thread_offset()));
381
__ cmp(rthread, rscratch1);
382
__ b(call_patch, Assembler::NE);
383
384
// access_field patches may execute the patched code before it's
385
// copied back into place so we need to jump back into the main
386
// code of the nmethod to continue execution.
387
__ b(_patch_site_continuation);
388
// make sure this extra code gets skipped
389
bytes_to_skip += __ offset() - offset;
390
}
391
392
// Now emit the patch record telling the runtime how to find the
393
// pieces of the patch. We only need 3 bytes but it has to be
394
// aligned as an instruction so emit 4 bytes.
395
int sizeof_patch_record = 4;
396
bytes_to_skip += sizeof_patch_record;
397
398
// emit the offsets needed to find the code to patch
399
int being_initialized_entry_offset = __ pc() - being_initialized_entry + sizeof_patch_record;
400
401
__ emit_int8(0);
402
__ emit_int8(being_initialized_entry_offset);
403
__ emit_int8(bytes_to_skip);
404
__ emit_int8(0);
405
406
address patch_info_pc = __ pc();
407
408
address entry = __ pc();
409
NativeGeneralJump::insert_unconditional((address)_pc_start, entry);
410
address target = NULL;
411
relocInfo::relocType reloc_type = relocInfo::none;
412
switch (_id) {
413
case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); reloc_type = relocInfo::section_word_type; break;
414
case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;
415
case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;
416
case load_appendix_id: target = Runtime1::entry_for(Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;
417
default: ShouldNotReachHere();
418
}
419
__ bind(call_patch);
420
421
if (CommentedAssembly) {
422
__ block_comment("patch entry point");
423
}
424
__ mov(rscratch1, RuntimeAddress(target));
425
__ bl(rscratch1);
426
// pad with nops to globally known upper bound of patch site size
427
while (patch_info_pc - __ pc() < _patch_info_offset)
428
__ nop();
429
assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change, required by shared code");
430
ce->add_call_info_here(_info);
431
int jmp_off = __ offset();
432
__ b(_patch_site_entry);
433
// Add enough nops so deoptimization can overwrite the jmp above with a call
434
// and not destroy the world.
435
for (int j = __ offset() ; j < jmp_off + NativeCall::instruction_size; j += NativeInstruction::arm_insn_sz) {
436
__ nop();
437
}
438
439
CodeSection* cs = __ code_section();
440
RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);
441
relocInfo::change_reloc_info_for_address(&iter, (address)_pc_start, reloc_type, relocInfo::none);
442
}
443
444
445
void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
446
__ bind(_entry);
447
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));
448
ce->add_call_info_here(_info);
449
DEBUG_ONLY(__ should_not_reach_here());
450
}
451
452
453
void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
454
address a;
455
if (_info->deoptimize_on_exception()) {
456
// Deoptimize, do not throw the exception, because it is probably wrong to do it here.
457
a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
458
} else {
459
a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);
460
}
461
462
ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
463
__ bind(_entry);
464
__ far_call(RuntimeAddress(a));
465
ce->add_call_info_here(_info);
466
ce->verify_oop_map(_info);
467
debug_only(__ should_not_reach_here());
468
}
469
470
471
void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
472
assert(__ rsp_offset() == 0, "frame size should be fixed");
473
474
__ bind(_entry);
475
// pass the object in a scratch register because all other registers
476
// must be preserved
477
if (_obj->is_cpu_register()) {
478
__ mov(rscratch1, _obj->as_register());
479
}
480
__ far_call(RuntimeAddress(Runtime1::entry_for(_stub)), NULL, rscratch2);
481
ce->add_call_info_here(_info);
482
debug_only(__ should_not_reach_here());
483
}
484
485
486
void ArrayCopyStub::emit_code(LIR_Assembler* ce) {
487
//---------------slow case: call to native-----------------
488
__ bind(_entry);
489
// Figure out where the args should go
490
// This should really convert the IntrinsicID to the Method* and signature
491
// but I don't know how to do that.
492
//
493
VMRegPair args[5];
494
BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};
495
SharedRuntime::java_calling_convention(signature, args, 5, true);
496
497
// push parameters
498
// (src, src_pos, dest, destPos, length)
499
Register r[5];
500
r[0] = src()->as_register();
501
r[1] = src_pos()->as_register();
502
r[2] = dst()->as_register();
503
r[3] = dst_pos()->as_register();
504
r[4] = length()->as_register();
505
506
// next registers will get stored on the stack
507
for (int i = 0; i < 5 ; i++ ) {
508
VMReg r_1 = args[i].first();
509
if (r_1->is_stack()) {
510
int st_off = r_1->reg2stack() * wordSize;
511
__ str (r[i], Address(sp, st_off));
512
} else {
513
assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");
514
}
515
}
516
517
ce->align_call(lir_static_call);
518
519
ce->emit_static_call_stub();
520
Address resolve(SharedRuntime::get_resolve_static_call_stub(),
521
relocInfo::static_call_type);
522
__ trampoline_call(resolve);
523
ce->add_call_info_here(info());
524
525
#ifndef PRODUCT
526
__ lea(rscratch2, ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));
527
__ increment(Address(rscratch2));
528
#endif
529
530
__ b(_continuation);
531
}
532
533
534
/////////////////////////////////////////////////////////////////////////////
535
#if INCLUDE_ALL_GCS
536
537
void G1PreBarrierStub::emit_code(LIR_Assembler* ce) {
538
// At this point we know that marking is in progress.
539
// If do_load() is true then we have to emit the
540
// load of the previous value; otherwise it has already
541
// been loaded into _pre_val.
542
543
__ bind(_entry);
544
assert(pre_val()->is_register(), "Precondition.");
545
546
Register pre_val_reg = pre_val()->as_register();
547
548
if (do_load()) {
549
ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false /*wide*/, false /*unaligned*/);
550
}
551
__ cbz(pre_val_reg, _continuation);
552
ce->store_parameter(pre_val()->as_register(), 0);
553
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_pre_barrier_slow_id)));
554
__ b(_continuation);
555
}
556
557
void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
558
__ bind(_entry);
559
assert(addr()->is_register(), "Precondition.");
560
assert(new_val()->is_register(), "Precondition.");
561
Register new_val_reg = new_val()->as_register();
562
__ cbz(new_val_reg, _continuation);
563
ce->store_parameter(addr()->as_pointer_register(), 0);
564
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_post_barrier_slow_id)));
565
__ b(_continuation);
566
}
567
568
#endif // INCLUDE_ALL_GCS
569
/////////////////////////////////////////////////////////////////////////////
570
571
#undef __
572
573