26
#include "precompiled.hpp"
27
#include "asm/macroAssembler.inline.hpp"
28
#include "c1/c1_CodeStubs.hpp"
29
#include "c1/c1_FrameMap.hpp"
30
#include "c1/c1_LIRAssembler.hpp"
31
#include "c1/c1_MacroAssembler.hpp"
32
#include "c1/c1_Runtime1.hpp"
33
#include "classfile/javaClasses.hpp"
34
#include "nativeInst_aarch64.hpp"
35
#include "runtime/sharedRuntime.hpp"
36
#include "vmreg_aarch64.inline.hpp"
39
#define __ ce->masm()->
41
void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {
43
InternalAddress safepoint_pc(ce->masm()->pc() - ce->masm()->offset() + safepoint_offset());
44
__ adr(rscratch1, safepoint_pc);
45
__ str(rscratch1, Address(rthread, JavaThread::saved_exception_pc_offset()));
47
assert(SharedRuntime::polling_page_return_handler_blob() != nullptr,
48
"polling page return stub not created yet");
49
address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
51
__ far_jump(RuntimeAddress(stub));
54
void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
56
Metadata *m = _method->as_constant_ptr()->as_metadata();
57
__ mov_metadata(rscratch1, m);
58
ce->store_parameter(rscratch1, 1);
59
ce->store_parameter(_bci, 0);
60
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));
61
ce->add_call_info_here(_info);
62
ce->verify_oop_map(_info);
66
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
68
if (_info->deoptimize_on_exception()) {
69
address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
70
__ far_call(RuntimeAddress(a));
71
ce->add_call_info_here(_info);
72
ce->verify_oop_map(_info);
73
debug_only(__ should_not_reach_here());
77
if (_index->is_cpu_register()) {
78
__ mov(rscratch1, _index->as_register());
80
__ mov(rscratch1, _index->as_jint());
82
Runtime1::StubID stub_id;
83
if (_throw_index_out_of_bounds_exception) {
84
stub_id = Runtime1::throw_index_exception_id;
86
assert(_array != LIR_Opr::nullOpr(), "sanity");
87
__ mov(rscratch2, _array->as_pointer_register());
88
stub_id = Runtime1::throw_range_check_failed_id;
90
__ lea(lr, RuntimeAddress(Runtime1::entry_for(stub_id)));
92
ce->add_call_info_here(_info);
93
ce->verify_oop_map(_info);
94
debug_only(__ should_not_reach_here());
97
PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {
98
_info = new CodeEmitInfo(info);
101
void PredicateFailedStub::emit_code(LIR_Assembler* ce) {
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());
110
void DivByZeroStub::emit_code(LIR_Assembler* ce) {
112
ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
115
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::throw_div0_exception_id)));
116
ce->add_call_info_here(_info);
117
ce->verify_oop_map(_info);
119
__ should_not_reach_here();
127
NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
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");
141
void NewInstanceStub::emit_code(LIR_Assembler* ce) {
142
assert(__ rsp_offset() == 0, "frame size should be fixed");
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,");
157
NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
158
_klass_reg = klass_reg;
161
_info = new CodeEmitInfo(info);
165
void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
166
assert(__ rsp_offset() == 0, "frame size should be fixed");
168
assert(_length->as_register() == r19, "length must in r19,");
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");
180
NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
181
_klass_reg = klass_reg;
184
_info = new CodeEmitInfo(info);
188
void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
189
assert(__ rsp_offset() == 0, "frame size should be fixed");
191
assert(_length->as_register() == r19, "length must in r19,");
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");
200
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
201
assert(__ rsp_offset() == 0, "frame size should be fixed");
203
ce->store_parameter(_obj_reg->as_register(), 1);
204
ce->store_parameter(_lock_reg->as_register(), 0);
205
Runtime1::StubID enter_id;
206
if (ce->compilation()->has_fpu_code()) {
207
enter_id = Runtime1::monitorenter_id;
209
enter_id = Runtime1::monitorenter_nofpu_id;
211
__ far_call(RuntimeAddress(Runtime1::entry_for(enter_id)));
212
ce->add_call_info_here(_info);
213
ce->verify_oop_map(_info);
218
void MonitorExitStub::emit_code(LIR_Assembler* ce) {
222
ce->monitor_address(_monitor_ix, _lock_reg);
224
ce->store_parameter(_lock_reg->as_register(), 0);
226
Runtime1::StubID exit_id;
227
if (ce->compilation()->has_fpu_code()) {
228
exit_id = Runtime1::monitorexit_id;
230
exit_id = Runtime1::monitorexit_nofpu_id;
232
__ adr(lr, _continuation);
233
__ far_jump(RuntimeAddress(Runtime1::entry_for(exit_id)));
245
int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;
247
void PatchingStub::align_patch_site(MacroAssembler* masm) {
250
void PatchingStub::emit_code(LIR_Assembler* ce) {
251
assert(false, "AArch64 should not use C1 runtime patching");
255
void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
257
ce->store_parameter(_trap_request, 0);
258
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));
259
ce->add_call_info_here(_info);
260
DEBUG_ONLY(__ should_not_reach_here());
264
void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
266
if (_info->deoptimize_on_exception()) {
268
a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
270
a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);
273
ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
275
__ far_call(RuntimeAddress(a));
276
ce->add_call_info_here(_info);
277
ce->verify_oop_map(_info);
278
debug_only(__ should_not_reach_here());
282
void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
283
assert(__ rsp_offset() == 0, "frame size should be fixed");
288
if (_obj->is_cpu_register()) {
289
__ mov(rscratch1, _obj->as_register());
291
__ far_call(RuntimeAddress(Runtime1::entry_for(_stub)), rscratch2);
292
ce->add_call_info_here(_info);
293
debug_only(__ should_not_reach_here());
297
void ArrayCopyStub::emit_code(LIR_Assembler* ce) {
305
BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};
306
SharedRuntime::java_calling_convention(signature, args, 5);
311
r[0] = src()->as_register();
312
r[1] = src_pos()->as_register();
313
r[2] = dst()->as_register();
314
r[3] = dst_pos()->as_register();
315
r[4] = length()->as_register();
318
for (int i = 0; i < 5 ; i++ ) {
319
VMReg r_1 = args[i].first();
320
if (r_1->is_stack()) {
321
int st_off = r_1->reg2stack() * wordSize;
322
__ str (r[i], Address(sp, st_off));
324
assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");
328
ce->align_call(lir_static_call);
330
ce->emit_static_call_stub();
331
if (ce->compilation()->bailed_out()) {
334
Address resolve(SharedRuntime::get_resolve_static_call_stub(),
335
relocInfo::static_call_type);
336
address call = __ trampoline_call(resolve);
337
if (call == nullptr) {
338
ce->bailout("trampoline stub overflow");
341
ce->add_call_info_here(info());
344
if (PrintC1Statistics) {
345
__ lea(rscratch2, ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));
346
__ incrementw(Address(rscratch2));