1 /* 2 * Copyright (c) 2008, 2018, 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 #ifndef CPU_ARM_VM_MACROASSEMBLER_ARM_HPP 26 #define CPU_ARM_VM_MACROASSEMBLER_ARM_HPP 27 28 #include "code/relocInfo.hpp" 29 #include "code/relocInfo_ext.hpp" 30 31 class BiasedLockingCounters; 32 33 // Introduced AddressLiteral and its subclasses to ease portability from 34 // x86 and avoid relocation issues 35 class AddressLiteral { 36 RelocationHolder _rspec; 37 // Typically we use AddressLiterals we want to use their rval 38 // However in some situations we want the lval (effect address) of the item. 39 // We provide a special factory for making those lvals. 40 bool _is_lval; 41 42 address _target; 43 44 private: 45 static relocInfo::relocType reloc_for_target(address target) { 46 // Used for ExternalAddress or when the type is not specified 47 // Sometimes ExternalAddress is used for values which aren't 48 // exactly addresses, like the card table base. 49 // external_word_type can't be used for values in the first page 50 // so just skip the reloc in that case. 51 return external_word_Relocation::can_be_relocated(target) ? relocInfo::external_word_type : relocInfo::none; 52 } 53 54 void set_rspec(relocInfo::relocType rtype); 55 56 protected: 57 // creation 58 AddressLiteral() 59 : _is_lval(false), 60 _target(NULL) 61 {} 62 63 public: 64 65 AddressLiteral(address target, relocInfo::relocType rtype) { 66 _is_lval = false; 67 _target = target; 68 set_rspec(rtype); 69 } 70 71 AddressLiteral(address target, RelocationHolder const& rspec) 72 : _rspec(rspec), 73 _is_lval(false), 74 _target(target) 75 {} 76 77 AddressLiteral(address target) { 78 _is_lval = false; 79 _target = target; 80 set_rspec(reloc_for_target(target)); 81 } 82 83 AddressLiteral addr() { 84 AddressLiteral ret = *this; 85 ret._is_lval = true; 86 return ret; 87 } 88 89 private: 90 91 address target() { return _target; } 92 bool is_lval() { return _is_lval; } 93 94 relocInfo::relocType reloc() const { return _rspec.type(); } 95 const RelocationHolder& rspec() const { return _rspec; } 96 97 friend class Assembler; 98 friend class MacroAssembler; 99 friend class Address; 100 friend class LIR_Assembler; 101 friend class InlinedAddress; 102 }; 103 104 class ExternalAddress: public AddressLiteral { 105 106 public: 107 108 ExternalAddress(address target) : AddressLiteral(target) {} 109 110 }; 111 112 class InternalAddress: public AddressLiteral { 113 114 public: 115 116 InternalAddress(address target) : AddressLiteral(target, relocInfo::internal_word_type) {} 117 118 }; 119 120 // Inlined constants, for use with ldr_literal / bind_literal 121 // Note: InlinedInteger not supported (use move_slow(Register,int[,cond])) 122 class InlinedLiteral: StackObj { 123 public: 124 Label label; // need to be public for direct access with & 125 InlinedLiteral() { 126 } 127 }; 128 129 class InlinedMetadata: public InlinedLiteral { 130 private: 131 Metadata *_data; 132 133 public: 134 InlinedMetadata(Metadata *data): InlinedLiteral() { 135 _data = data; 136 } 137 Metadata *data() { return _data; } 138 }; 139 140 // Currently unused 141 // class InlinedOop: public InlinedLiteral { 142 // private: 143 // jobject _jobject; 144 // 145 // public: 146 // InlinedOop(jobject target): InlinedLiteral() { 147 // _jobject = target; 148 // } 149 // jobject jobject() { return _jobject; } 150 // }; 151 152 class InlinedAddress: public InlinedLiteral { 153 private: 154 AddressLiteral _literal; 155 156 public: 157 158 InlinedAddress(jobject object): InlinedLiteral(), _literal((address)object, relocInfo::oop_type) { 159 ShouldNotReachHere(); // use mov_oop (or implement InlinedOop) 160 } 161 162 InlinedAddress(Metadata *data): InlinedLiteral(), _literal((address)data, relocInfo::metadata_type) { 163 ShouldNotReachHere(); // use InlinedMetadata or mov_metadata 164 } 165 166 InlinedAddress(address target, const RelocationHolder &rspec): InlinedLiteral(), _literal(target, rspec) { 167 assert(rspec.type() != relocInfo::oop_type, "Do not use InlinedAddress for oops"); 168 assert(rspec.type() != relocInfo::metadata_type, "Do not use InlinedAddress for metadatas"); 169 } 170 171 InlinedAddress(address target, relocInfo::relocType rtype): InlinedLiteral(), _literal(target, rtype) { 172 assert(rtype != relocInfo::oop_type, "Do not use InlinedAddress for oops"); 173 assert(rtype != relocInfo::metadata_type, "Do not use InlinedAddress for metadatas"); 174 } 175 176 // Note: default is relocInfo::none for InlinedAddress 177 InlinedAddress(address target): InlinedLiteral(), _literal(target, relocInfo::none) { 178 } 179 180 address target() { return _literal.target(); } 181 182 const RelocationHolder& rspec() const { return _literal.rspec(); } 183 }; 184 185 class InlinedString: public InlinedLiteral { 186 private: 187 const char* _msg; 188 189 public: 190 InlinedString(const char* msg): InlinedLiteral() { 191 _msg = msg; 192 } 193 const char* msg() { return _msg; } 194 }; 195 196 class MacroAssembler: public Assembler { 197 protected: 198 199 // Support for VM calls 200 // 201 202 // This is the base routine called by the different versions of call_VM_leaf. 203 void call_VM_leaf_helper(address entry_point, int number_of_arguments); 204 205 // This is the base routine called by the different versions of call_VM. The interpreter 206 // may customize this version by overriding it for its purposes (e.g., to save/restore 207 // additional registers when doing a VM call). 208 virtual void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions); 209 public: 210 211 MacroAssembler(CodeBuffer* code) : Assembler(code) {} 212 213 // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code. 214 // The implementation is only non-empty for the InterpreterMacroAssembler, 215 // as only the interpreter handles PopFrame and ForceEarlyReturn requests. 216 virtual void check_and_handle_popframe() {} 217 virtual void check_and_handle_earlyret() {} 218 219 // By default, we do not need relocation information for non 220 // patchable absolute addresses. However, when needed by some 221 // extensions, ignore_non_patchable_relocations can be modified, 222 // returning false to preserve all relocation information. 223 inline bool ignore_non_patchable_relocations() { return true; } 224 225 // Initially added to the Assembler interface as a pure virtual: 226 // RegisterConstant delayed_value(..) 227 // for: 228 // 6812678 macro assembler needs delayed binding of a few constants (for 6655638) 229 // this was subsequently modified to its present name and return type 230 virtual RegisterOrConstant delayed_value_impl(intptr_t* delayed_value_addr, Register tmp, int offset); 231 232 #ifdef AARCH64 233 # define NOT_IMPLEMENTED() unimplemented("NYI at " __FILE__ ":" XSTR(__LINE__)) 234 # define NOT_TESTED() warn("Not tested at " __FILE__ ":" XSTR(__LINE__)) 235 #endif 236 237 void align(int modulus); 238 239 // Support for VM calls 240 // 241 // It is imperative that all calls into the VM are handled via the call_VM methods. 242 // They make sure that the stack linkage is setup correctly. call_VM's correspond 243 // to ENTRY/ENTRY_X entry points while call_VM_leaf's correspond to LEAF entry points. 244 245 void call_VM(Register oop_result, address entry_point, bool check_exceptions = true); 246 void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true); 247 void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true); 248 void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true); 249 250 // The following methods are required by templateTable.cpp, 251 // but not used on ARM. 252 void call_VM(Register oop_result, Register last_java_sp, address entry_point, int number_of_arguments = 0, bool check_exceptions = true); 253 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions = true); 254 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true); 255 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true); 256 257 // Note: The super_call_VM calls are not used on ARM 258 259 // Raw call, without saving/restoring registers, exception handling, etc. 260 // Mainly used from various stubs. 261 // Note: if 'save_R9_if_scratched' is true, call_VM may on some 262 // platforms save values on the stack. Set it to false (and handle 263 // R9 in the callers) if the top of the stack must not be modified 264 // by call_VM. 265 void call_VM(address entry_point, bool save_R9_if_scratched); 266 267 void call_VM_leaf(address entry_point); 268 void call_VM_leaf(address entry_point, Register arg_1); 269 void call_VM_leaf(address entry_point, Register arg_1, Register arg_2); 270 void call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3); 271 void call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3, Register arg_4); 272 273 void get_vm_result(Register oop_result, Register tmp); 274 void get_vm_result_2(Register metadata_result, Register tmp); 275 276 // Always sets/resets sp, which default to SP if (last_sp == noreg) 277 // Optionally sets/resets fp (use noreg to avoid setting it) 278 // Always sets/resets pc on AArch64; optionally sets/resets pc on 32-bit ARM depending on save_last_java_pc flag 279 // Note: when saving PC, set_last_Java_frame returns PC's offset in the code section 280 // (for oop_maps offset computation) 281 int set_last_Java_frame(Register last_sp, Register last_fp, bool save_last_java_pc, Register tmp); 282 void reset_last_Java_frame(Register tmp); 283 // status set in set_last_Java_frame for reset_last_Java_frame 284 bool _fp_saved; 285 bool _pc_saved; 286 287 #ifdef PRODUCT 288 #define BLOCK_COMMENT(str) /* nothing */ 289 #define STOP(error) __ stop(error) 290 #else 291 #define BLOCK_COMMENT(str) __ block_comment(str) 292 #define STOP(error) __ block_comment(error); __ stop(error) 293 #endif 294 295 void lookup_virtual_method(Register recv_klass, 296 Register vtable_index, 297 Register method_result); 298 299 // Test sub_klass against super_klass, with fast and slow paths. 300 301 // The fast path produces a tri-state answer: yes / no / maybe-slow. 302 // One of the three labels can be NULL, meaning take the fall-through. 303 // No registers are killed, except temp_regs. 304 void check_klass_subtype_fast_path(Register sub_klass, 305 Register super_klass, 306 Register temp_reg, 307 Register temp_reg2, 308 Label* L_success, 309 Label* L_failure, 310 Label* L_slow_path); 311 312 // The rest of the type check; must be wired to a corresponding fast path. 313 // It does not repeat the fast path logic, so don't use it standalone. 314 // temp_reg3 can be noreg, if no temps are available. 315 // Updates the sub's secondary super cache as necessary. 316 // If set_cond_codes: 317 // - condition codes will be Z on success, NZ on failure. 318 // - temp_reg will be 0 on success, non-0 on failure 319 void check_klass_subtype_slow_path(Register sub_klass, 320 Register super_klass, 321 Register temp_reg, 322 Register temp_reg2, 323 Register temp_reg3, // auto assigned if noreg 324 Label* L_success, 325 Label* L_failure, 326 bool set_cond_codes = false); 327 328 // Simplified, combined version, good for typical uses. 329 // temp_reg3 can be noreg, if no temps are available. It is used only on slow path. 330 // Falls through on failure. 331 void check_klass_subtype(Register sub_klass, 332 Register super_klass, 333 Register temp_reg, 334 Register temp_reg2, 335 Register temp_reg3, // auto assigned on slow path if noreg 336 Label& L_success); 337 338 // Returns address of receiver parameter, using tmp as base register. tmp and params_count can be the same. 339 Address receiver_argument_address(Register params_base, Register params_count, Register tmp); 340 341 void _verify_oop(Register reg, const char* s, const char* file, int line); 342 void _verify_oop_addr(Address addr, const char * s, const char* file, int line); 343 344 // TODO: verify method and klass metadata (compare against vptr?) 345 void _verify_method_ptr(Register reg, const char * msg, const char * file, int line) {} 346 void _verify_klass_ptr(Register reg, const char * msg, const char * file, int line) {} 347 348 #define verify_oop(reg) _verify_oop(reg, "broken oop " #reg, __FILE__, __LINE__) 349 #define verify_oop_addr(addr) _verify_oop_addr(addr, "broken oop ", __FILE__, __LINE__) 350 #define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__) 351 #define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__) 352 353 void null_check(Register reg, Register tmp, int offset = -1); 354 inline void null_check(Register reg) { null_check(reg, noreg, -1); } // for C1 lir_null_check 355 356 // Puts address of allocated object into register `obj` and end of allocated object into register `obj_end`. 357 void eden_allocate(Register obj, Register obj_end, Register tmp1, Register tmp2, 358 RegisterOrConstant size_expression, Label& slow_case); 359 void tlab_allocate(Register obj, Register obj_end, Register tmp1, 360 RegisterOrConstant size_expression, Label& slow_case); 361 362 void zero_memory(Register start, Register end, Register tmp); 363 364 static bool needs_explicit_null_check(intptr_t offset); 365 366 void arm_stack_overflow_check(int frame_size_in_bytes, Register tmp); 367 void arm_stack_overflow_check(Register Rsize, Register tmp); 368 369 void bang_stack_with_offset(int offset) { 370 ShouldNotReachHere(); 371 } 372 373 // Biased locking support 374 // lock_reg and obj_reg must be loaded up with the appropriate values. 375 // swap_reg must be supplied. 376 // tmp_reg must be supplied. 377 // Optional slow case is for implementations (interpreter and C1) which branch to 378 // slow case directly. If slow_case is NULL, then leaves condition 379 // codes set (for C2's Fast_Lock node) and jumps to done label. 380 // Falls through for the fast locking attempt. 381 // Returns offset of first potentially-faulting instruction for null 382 // check info (currently consumed only by C1). If 383 // swap_reg_contains_mark is true then returns -1 as it is assumed 384 // the calling code has already passed any potential faults. 385 // Notes: 386 // - swap_reg and tmp_reg are scratched 387 // - Rtemp was (implicitly) scratched and can now be specified as the tmp2 388 int biased_locking_enter(Register obj_reg, Register swap_reg, Register tmp_reg, 389 bool swap_reg_contains_mark, 390 Register tmp2, 391 Label& done, Label& slow_case, 392 BiasedLockingCounters* counters = NULL); 393 void biased_locking_exit(Register obj_reg, Register temp_reg, Label& done); 394 395 // Building block for CAS cases of biased locking: makes CAS and records statistics. 396 // Optional slow_case label is used to transfer control if CAS fails. Otherwise leaves condition codes set. 397 void biased_locking_enter_with_cas(Register obj_reg, Register old_mark_reg, Register new_mark_reg, 398 Register tmp, Label& slow_case, int* counter_addr); 399 400 void resolve_jobject(Register value, Register tmp1, Register tmp2); 401 402 #ifndef AARCH64 403 void nop() { 404 mov(R0, R0); 405 } 406 407 void push(Register rd, AsmCondition cond = al) { 408 assert(rd != SP, "unpredictable instruction"); 409 str(rd, Address(SP, -wordSize, pre_indexed), cond); 410 } 411 412 void push(RegisterSet reg_set, AsmCondition cond = al) { 413 assert(!reg_set.contains(SP), "unpredictable instruction"); 414 stmdb(SP, reg_set, writeback, cond); 415 } 416 417 void pop(Register rd, AsmCondition cond = al) { 418 assert(rd != SP, "unpredictable instruction"); 419 ldr(rd, Address(SP, wordSize, post_indexed), cond); 420 } 421 422 void pop(RegisterSet reg_set, AsmCondition cond = al) { 423 assert(!reg_set.contains(SP), "unpredictable instruction"); 424 ldmia(SP, reg_set, writeback, cond); 425 } 426 427 void fpushd(FloatRegister fd, AsmCondition cond = al) { 428 fstmdbd(SP, FloatRegisterSet(fd), writeback, cond); 429 } 430 431 void fpushs(FloatRegister fd, AsmCondition cond = al) { 432 fstmdbs(SP, FloatRegisterSet(fd), writeback, cond); 433 } 434 435 void fpopd(FloatRegister fd, AsmCondition cond = al) { 436 fldmiad(SP, FloatRegisterSet(fd), writeback, cond); 437 } 438 439 void fpops(FloatRegister fd, AsmCondition cond = al) { 440 fldmias(SP, FloatRegisterSet(fd), writeback, cond); 441 } 442 #endif // !AARCH64 443 444 // Order access primitives 445 enum Membar_mask_bits { 446 StoreStore = 1 << 3, 447 LoadStore = 1 << 2, 448 StoreLoad = 1 << 1, 449 LoadLoad = 1 << 0 450 }; 451 452 #ifdef AARCH64 453 // tmp register is not used on AArch64, this parameter is provided solely for better compatibility with 32-bit ARM 454 void membar(Membar_mask_bits order_constraint, Register tmp = noreg); 455 #else 456 void membar(Membar_mask_bits mask, 457 Register tmp, 458 bool preserve_flags = true, 459 Register load_tgt = noreg); 460 #endif 461 462 void breakpoint(AsmCondition cond = al); 463 void stop(const char* msg); 464 // prints msg and continues 465 void warn(const char* msg); 466 void unimplemented(const char* what = ""); 467 void should_not_reach_here() { stop("should not reach here"); } 468 static void debug(const char* msg, const intx* registers); 469 470 // Create a walkable frame to help tracking down who called this code. 471 // Returns the frame size in words. 472 int should_not_call_this() { 473 raw_push(FP, LR); 474 should_not_reach_here(); 475 flush(); 476 return 2; // frame_size_in_words (FP+LR) 477 } 478 479 int save_all_registers(); 480 void restore_all_registers(); 481 int save_caller_save_registers(); 482 void restore_caller_save_registers(); 483 484 void add_rc(Register dst, Register arg1, RegisterOrConstant arg2); 485 486 // add_slow and mov_slow are used to manipulate offsets larger than 1024, 487 // these functions are not expected to handle all possible constants, 488 // only those that can really occur during compilation 489 void add_slow(Register rd, Register rn, int c); 490 void sub_slow(Register rd, Register rn, int c); 491 492 #ifdef AARCH64 493 static int mov_slow_helper(Register rd, intptr_t c, MacroAssembler* masm /* optional */); 494 #endif 495 496 void mov_slow(Register rd, intptr_t c NOT_AARCH64_ARG(AsmCondition cond = al)); 497 void mov_slow(Register rd, const char *string); 498 void mov_slow(Register rd, address addr); 499 500 void patchable_mov_oop(Register rd, jobject o, int oop_index) { 501 mov_oop(rd, o, oop_index AARCH64_ONLY_ARG(true)); 502 } 503 void mov_oop(Register rd, jobject o, int index = 0 504 AARCH64_ONLY_ARG(bool patchable = false) 505 NOT_AARCH64_ARG(AsmCondition cond = al)); 506 507 508 void patchable_mov_metadata(Register rd, Metadata* o, int index) { 509 mov_metadata(rd, o, index AARCH64_ONLY_ARG(true)); 510 } 511 void mov_metadata(Register rd, Metadata* o, int index = 0 AARCH64_ONLY_ARG(bool patchable = false)); 512 513 void mov_float(FloatRegister fd, jfloat c NOT_AARCH64_ARG(AsmCondition cond = al)); 514 void mov_double(FloatRegister fd, jdouble c NOT_AARCH64_ARG(AsmCondition cond = al)); 515 516 #ifdef AARCH64 517 int mov_pc_to(Register rd) { 518 Label L; 519 adr(rd, L); 520 bind(L); 521 return offset(); 522 } 523 #endif 524 525 // Note: this variant of mov_address assumes the address moves with 526 // the code. Do *not* implement it with non-relocated instructions, 527 // unless PC-relative. 528 #ifdef AARCH64 529 void mov_relative_address(Register rd, address addr) { 530 adr(rd, addr); 531 } 532 #else 533 void mov_relative_address(Register rd, address addr, AsmCondition cond = al) { 534 int offset = addr - pc() - 8; 535 assert((offset & 3) == 0, "bad alignment"); 536 if (offset >= 0) { 537 assert(AsmOperand::is_rotated_imm(offset), "addr too far"); 538 add(rd, PC, offset, cond); 539 } else { 540 assert(AsmOperand::is_rotated_imm(-offset), "addr too far"); 541 sub(rd, PC, -offset, cond); 542 } 543 } 544 #endif // AARCH64 545 546 // Runtime address that may vary from one execution to another. The 547 // symbolic_reference describes what the address is, allowing 548 // the address to be resolved in a different execution context. 549 // Warning: do not implement as a PC relative address. 550 void mov_address(Register rd, address addr, symbolic_Relocation::symbolic_reference t) { 551 mov_address(rd, addr, RelocationHolder::none); 552 } 553 554 // rspec can be RelocationHolder::none (for ignored symbolic_Relocation). 555 // In that case, the address is absolute and the generated code need 556 // not be relocable. 557 void mov_address(Register rd, address addr, RelocationHolder const& rspec) { 558 assert(rspec.type() != relocInfo::runtime_call_type, "do not use mov_address for runtime calls"); 559 assert(rspec.type() != relocInfo::static_call_type, "do not use mov_address for relocable calls"); 560 if (rspec.type() == relocInfo::none) { 561 // absolute address, relocation not needed 562 mov_slow(rd, (intptr_t)addr); 563 return; 564 } 565 #ifndef AARCH64 566 if (VM_Version::supports_movw()) { 567 relocate(rspec); 568 int c = (int)addr; 569 movw(rd, c & 0xffff); 570 if ((unsigned int)c >> 16) { 571 movt(rd, (unsigned int)c >> 16); 572 } 573 return; 574 } 575 #endif 576 Label skip_literal; 577 InlinedAddress addr_literal(addr, rspec); 578 ldr_literal(rd, addr_literal); 579 b(skip_literal); 580 bind_literal(addr_literal); 581 // AARCH64 WARNING: because of alignment padding, extra padding 582 // may be required to get a consistent size for C2, or rules must 583 // overestimate size see MachEpilogNode::size 584 bind(skip_literal); 585 } 586 587 // Note: Do not define mov_address for a Label 588 // 589 // Load from addresses potentially within the code are now handled 590 // InlinedLiteral subclasses (to allow more flexibility on how the 591 // ldr_literal is performed). 592 593 void ldr_literal(Register rd, InlinedAddress& L) { 594 assert(L.rspec().type() != relocInfo::runtime_call_type, "avoid ldr_literal for calls"); 595 assert(L.rspec().type() != relocInfo::static_call_type, "avoid ldr_literal for calls"); 596 relocate(L.rspec()); 597 #ifdef AARCH64 598 ldr(rd, target(L.label)); 599 #else 600 ldr(rd, Address(PC, target(L.label) - pc() - 8)); 601 #endif 602 } 603 604 void ldr_literal(Register rd, InlinedString& L) { 605 const char* msg = L.msg(); 606 if (code()->consts()->contains((address)msg)) { 607 // string address moves with the code 608 #ifdef AARCH64 609 ldr(rd, (address)msg); 610 #else 611 ldr(rd, Address(PC, ((address)msg) - pc() - 8)); 612 #endif 613 return; 614 } 615 // Warning: use external strings with care. They are not relocated 616 // if the code moves. If needed, use code_string to move them 617 // to the consts section. 618 #ifdef AARCH64 619 ldr(rd, target(L.label)); 620 #else 621 ldr(rd, Address(PC, target(L.label) - pc() - 8)); 622 #endif 623 } 624 625 void ldr_literal(Register rd, InlinedMetadata& L) { 626 // relocation done in the bind_literal for metadatas 627 #ifdef AARCH64 628 ldr(rd, target(L.label)); 629 #else 630 ldr(rd, Address(PC, target(L.label) - pc() - 8)); 631 #endif 632 } 633 634 void bind_literal(InlinedAddress& L) { 635 AARCH64_ONLY(align(wordSize)); 636 bind(L.label); 637 assert(L.rspec().type() != relocInfo::metadata_type, "Must use InlinedMetadata"); 638 // We currently do not use oop 'bound' literals. 639 // If the code evolves and the following assert is triggered, 640 // we need to implement InlinedOop (see InlinedMetadata). 641 assert(L.rspec().type() != relocInfo::oop_type, "Inlined oops not supported"); 642 // Note: relocation is handled by relocate calls in ldr_literal 643 AbstractAssembler::emit_address((address)L.target()); 644 } 645 646 void bind_literal(InlinedString& L) { 647 const char* msg = L.msg(); 648 if (code()->consts()->contains((address)msg)) { 649 // The Label should not be used; avoid binding it 650 // to detect errors. 651 return; 652 } 653 AARCH64_ONLY(align(wordSize)); 654 bind(L.label); 655 AbstractAssembler::emit_address((address)L.msg()); 656 } 657 658 void bind_literal(InlinedMetadata& L) { 659 AARCH64_ONLY(align(wordSize)); 660 bind(L.label); 661 relocate(metadata_Relocation::spec_for_immediate()); 662 AbstractAssembler::emit_address((address)L.data()); 663 } 664 665 void resolve_oop_handle(Register result); 666 void load_mirror(Register mirror, Register method, Register tmp); 667 668 // Porting layer between 32-bit ARM and AArch64 669 670 #define COMMON_INSTR_1(common_mnemonic, aarch64_mnemonic, arm32_mnemonic, arg_type) \ 671 void common_mnemonic(arg_type arg) { \ 672 AARCH64_ONLY(aarch64_mnemonic) NOT_AARCH64(arm32_mnemonic) (arg); \ 673 } 674 675 #define COMMON_INSTR_2(common_mnemonic, aarch64_mnemonic, arm32_mnemonic, arg1_type, arg2_type) \ 676 void common_mnemonic(arg1_type arg1, arg2_type arg2) { \ 677 AARCH64_ONLY(aarch64_mnemonic) NOT_AARCH64(arm32_mnemonic) (arg1, arg2); \ 678 } 679 680 #define COMMON_INSTR_3(common_mnemonic, aarch64_mnemonic, arm32_mnemonic, arg1_type, arg2_type, arg3_type) \ 681 void common_mnemonic(arg1_type arg1, arg2_type arg2, arg3_type arg3) { \ 682 AARCH64_ONLY(aarch64_mnemonic) NOT_AARCH64(arm32_mnemonic) (arg1, arg2, arg3); \ 683 } 684 685 COMMON_INSTR_1(jump, br, bx, Register) 686 COMMON_INSTR_1(call, blr, blx, Register) 687 688 COMMON_INSTR_2(cbz_32, cbz_w, cbz, Register, Label&) 689 COMMON_INSTR_2(cbnz_32, cbnz_w, cbnz, Register, Label&) 690 691 COMMON_INSTR_2(ldr_u32, ldr_w, ldr, Register, Address) 692 COMMON_INSTR_2(ldr_s32, ldrsw, ldr, Register, Address) 693 COMMON_INSTR_2(str_32, str_w, str, Register, Address) 694 695 COMMON_INSTR_2(mvn_32, mvn_w, mvn, Register, Register) 696 COMMON_INSTR_2(cmp_32, cmp_w, cmp, Register, Register) 697 COMMON_INSTR_2(neg_32, neg_w, neg, Register, Register) 698 COMMON_INSTR_2(clz_32, clz_w, clz, Register, Register) 699 COMMON_INSTR_2(rbit_32, rbit_w, rbit, Register, Register) 700 701 COMMON_INSTR_2(cmp_32, cmp_w, cmp, Register, int) 702 COMMON_INSTR_2(cmn_32, cmn_w, cmn, Register, int) 703 704 COMMON_INSTR_3(add_32, add_w, add, Register, Register, Register) 705 COMMON_INSTR_3(sub_32, sub_w, sub, Register, Register, Register) 706 COMMON_INSTR_3(subs_32, subs_w, subs, Register, Register, Register) 707 COMMON_INSTR_3(mul_32, mul_w, mul, Register, Register, Register) 708 COMMON_INSTR_3(and_32, andr_w, andr, Register, Register, Register) 709 COMMON_INSTR_3(orr_32, orr_w, orr, Register, Register, Register) 710 COMMON_INSTR_3(eor_32, eor_w, eor, Register, Register, Register) 711 712 COMMON_INSTR_3(add_32, add_w, add, Register, Register, AsmOperand) 713 COMMON_INSTR_3(sub_32, sub_w, sub, Register, Register, AsmOperand) 714 COMMON_INSTR_3(orr_32, orr_w, orr, Register, Register, AsmOperand) 715 COMMON_INSTR_3(eor_32, eor_w, eor, Register, Register, AsmOperand) 716 COMMON_INSTR_3(and_32, andr_w, andr, Register, Register, AsmOperand) 717 718 719 COMMON_INSTR_3(add_32, add_w, add, Register, Register, int) 720 COMMON_INSTR_3(adds_32, adds_w, adds, Register, Register, int) 721 COMMON_INSTR_3(sub_32, sub_w, sub, Register, Register, int) 722 COMMON_INSTR_3(subs_32, subs_w, subs, Register, Register, int) 723 724 COMMON_INSTR_2(tst_32, tst_w, tst, Register, unsigned int) 725 COMMON_INSTR_2(tst_32, tst_w, tst, Register, AsmOperand) 726 727 COMMON_INSTR_3(and_32, andr_w, andr, Register, Register, uint) 728 COMMON_INSTR_3(orr_32, orr_w, orr, Register, Register, uint) 729 COMMON_INSTR_3(eor_32, eor_w, eor, Register, Register, uint) 730 731 COMMON_INSTR_1(cmp_zero_float, fcmp0_s, fcmpzs, FloatRegister) 732 COMMON_INSTR_1(cmp_zero_double, fcmp0_d, fcmpzd, FloatRegister) 733 734 COMMON_INSTR_2(ldr_float, ldr_s, flds, FloatRegister, Address) 735 COMMON_INSTR_2(str_float, str_s, fsts, FloatRegister, Address) 736 COMMON_INSTR_2(mov_float, fmov_s, fcpys, FloatRegister, FloatRegister) 737 COMMON_INSTR_2(neg_float, fneg_s, fnegs, FloatRegister, FloatRegister) 738 COMMON_INSTR_2(abs_float, fabs_s, fabss, FloatRegister, FloatRegister) 739 COMMON_INSTR_2(sqrt_float, fsqrt_s, fsqrts, FloatRegister, FloatRegister) 740 COMMON_INSTR_2(cmp_float, fcmp_s, fcmps, FloatRegister, FloatRegister) 741 742 COMMON_INSTR_3(add_float, fadd_s, fadds, FloatRegister, FloatRegister, FloatRegister) 743 COMMON_INSTR_3(sub_float, fsub_s, fsubs, FloatRegister, FloatRegister, FloatRegister) 744 COMMON_INSTR_3(mul_float, fmul_s, fmuls, FloatRegister, FloatRegister, FloatRegister) 745 COMMON_INSTR_3(div_float, fdiv_s, fdivs, FloatRegister, FloatRegister, FloatRegister) 746 747 COMMON_INSTR_2(ldr_double, ldr_d, fldd, FloatRegister, Address) 748 COMMON_INSTR_2(str_double, str_d, fstd, FloatRegister, Address) 749 COMMON_INSTR_2(mov_double, fmov_d, fcpyd, FloatRegister, FloatRegister) 750 COMMON_INSTR_2(neg_double, fneg_d, fnegd, FloatRegister, FloatRegister) 751 COMMON_INSTR_2(cmp_double, fcmp_d, fcmpd, FloatRegister, FloatRegister) 752 COMMON_INSTR_2(abs_double, fabs_d, fabsd, FloatRegister, FloatRegister) 753 COMMON_INSTR_2(sqrt_double, fsqrt_d, fsqrtd, FloatRegister, FloatRegister) 754 755 COMMON_INSTR_3(add_double, fadd_d, faddd, FloatRegister, FloatRegister, FloatRegister) 756 COMMON_INSTR_3(sub_double, fsub_d, fsubd, FloatRegister, FloatRegister, FloatRegister) 757 COMMON_INSTR_3(mul_double, fmul_d, fmuld, FloatRegister, FloatRegister, FloatRegister) 758 COMMON_INSTR_3(div_double, fdiv_d, fdivd, FloatRegister, FloatRegister, FloatRegister) 759 760 COMMON_INSTR_2(convert_f2d, fcvt_ds, fcvtds, FloatRegister, FloatRegister) 761 COMMON_INSTR_2(convert_d2f, fcvt_sd, fcvtsd, FloatRegister, FloatRegister) 762 763 COMMON_INSTR_2(mov_fpr2gpr_float, fmov_ws, fmrs, Register, FloatRegister) 764 765 #undef COMMON_INSTR_1 766 #undef COMMON_INSTR_2 767 #undef COMMON_INSTR_3 768 769 770 #ifdef AARCH64 771 772 void mov(Register dst, Register src, AsmCondition cond) { 773 if (cond == al) { 774 mov(dst, src); 775 } else { 776 csel(dst, src, dst, cond); 777 } 778 } 779 780 // Propagate other overloaded "mov" methods from Assembler. 781 void mov(Register dst, Register src) { Assembler::mov(dst, src); } 782 void mov(Register rd, int imm) { Assembler::mov(rd, imm); } 783 784 void mov(Register dst, int imm, AsmCondition cond) { 785 assert(imm == 0 || imm == 1, ""); 786 if (imm == 0) { 787 mov(dst, ZR, cond); 788 } else if (imm == 1) { 789 csinc(dst, dst, ZR, inverse(cond)); 790 } else if (imm == -1) { 791 csinv(dst, dst, ZR, inverse(cond)); 792 } else { 793 fatal("illegal mov(R%d,%d,cond)", dst->encoding(), imm); 794 } 795 } 796 797 void movs(Register dst, Register src) { adds(dst, src, 0); } 798 799 #else // AARCH64 800 801 void tbz(Register rt, int bit, Label& L) { 802 assert(0 <= bit && bit < BitsPerWord, "bit number is out of range"); 803 tst(rt, 1 << bit); 804 b(L, eq); 805 } 806 807 void tbnz(Register rt, int bit, Label& L) { 808 assert(0 <= bit && bit < BitsPerWord, "bit number is out of range"); 809 tst(rt, 1 << bit); 810 b(L, ne); 811 } 812 813 void cbz(Register rt, Label& L) { 814 cmp(rt, 0); 815 b(L, eq); 816 } 817 818 void cbz(Register rt, address target) { 819 cmp(rt, 0); 820 b(target, eq); 821 } 822 823 void cbnz(Register rt, Label& L) { 824 cmp(rt, 0); 825 b(L, ne); 826 } 827 828 void ret(Register dst = LR) { 829 bx(dst); 830 } 831 832 #endif // AARCH64 833 834 Register zero_register(Register tmp) { 835 #ifdef AARCH64 836 return ZR; 837 #else 838 mov(tmp, 0); 839 return tmp; 840 #endif 841 } 842 843 void logical_shift_left(Register dst, Register src, int shift) { 844 #ifdef AARCH64 845 _lsl(dst, src, shift); 846 #else 847 mov(dst, AsmOperand(src, lsl, shift)); 848 #endif 849 } 850 851 void logical_shift_left_32(Register dst, Register src, int shift) { 852 #ifdef AARCH64 853 _lsl_w(dst, src, shift); 854 #else 855 mov(dst, AsmOperand(src, lsl, shift)); 856 #endif 857 } 858 859 void logical_shift_right(Register dst, Register src, int shift) { 860 #ifdef AARCH64 861 _lsr(dst, src, shift); 862 #else 863 mov(dst, AsmOperand(src, lsr, shift)); 864 #endif 865 } 866 867 void arith_shift_right(Register dst, Register src, int shift) { 868 #ifdef AARCH64 869 _asr(dst, src, shift); 870 #else 871 mov(dst, AsmOperand(src, asr, shift)); 872 #endif 873 } 874 875 void asr_32(Register dst, Register src, int shift) { 876 #ifdef AARCH64 877 _asr_w(dst, src, shift); 878 #else 879 mov(dst, AsmOperand(src, asr, shift)); 880 #endif 881 } 882 883 // If <cond> holds, compares r1 and r2. Otherwise, flags are set so that <cond> does not hold. 884 void cond_cmp(Register r1, Register r2, AsmCondition cond) { 885 #ifdef AARCH64 886 ccmp(r1, r2, flags_for_condition(inverse(cond)), cond); 887 #else 888 cmp(r1, r2, cond); 889 #endif 890 } 891 892 // If <cond> holds, compares r and imm. Otherwise, flags are set so that <cond> does not hold. 893 void cond_cmp(Register r, int imm, AsmCondition cond) { 894 #ifdef AARCH64 895 ccmp(r, imm, flags_for_condition(inverse(cond)), cond); 896 #else 897 cmp(r, imm, cond); 898 #endif 899 } 900 901 void align_reg(Register dst, Register src, int align) { 902 assert (is_power_of_2(align), "should be"); 903 #ifdef AARCH64 904 andr(dst, src, ~(uintx)(align-1)); 905 #else 906 bic(dst, src, align-1); 907 #endif 908 } 909 910 void prefetch_read(Address addr) { 911 #ifdef AARCH64 912 prfm(pldl1keep, addr); 913 #else 914 pld(addr); 915 #endif 916 } 917 918 void raw_push(Register r1, Register r2) { 919 #ifdef AARCH64 920 stp(r1, r2, Address(SP, -2*wordSize, pre_indexed)); 921 #else 922 assert(r1->encoding() < r2->encoding(), "should be ordered"); 923 push(RegisterSet(r1) | RegisterSet(r2)); 924 #endif 925 } 926 927 void raw_pop(Register r1, Register r2) { 928 #ifdef AARCH64 929 ldp(r1, r2, Address(SP, 2*wordSize, post_indexed)); 930 #else 931 assert(r1->encoding() < r2->encoding(), "should be ordered"); 932 pop(RegisterSet(r1) | RegisterSet(r2)); 933 #endif 934 } 935 936 void raw_push(Register r1, Register r2, Register r3) { 937 #ifdef AARCH64 938 raw_push(r1, r2); 939 raw_push(r3, ZR); 940 #else 941 assert(r1->encoding() < r2->encoding() && r2->encoding() < r3->encoding(), "should be ordered"); 942 push(RegisterSet(r1) | RegisterSet(r2) | RegisterSet(r3)); 943 #endif 944 } 945 946 void raw_pop(Register r1, Register r2, Register r3) { 947 #ifdef AARCH64 948 raw_pop(r3, ZR); 949 raw_pop(r1, r2); 950 #else 951 assert(r1->encoding() < r2->encoding() && r2->encoding() < r3->encoding(), "should be ordered"); 952 pop(RegisterSet(r1) | RegisterSet(r2) | RegisterSet(r3)); 953 #endif 954 } 955 956 // Restores registers r1 and r2 previously saved by raw_push(r1, r2, ret_addr) and returns by ret_addr. Clobbers LR. 957 void raw_pop_and_ret(Register r1, Register r2) { 958 #ifdef AARCH64 959 raw_pop(r1, r2, LR); 960 ret(); 961 #else 962 raw_pop(r1, r2, PC); 963 #endif 964 } 965 966 void indirect_jump(Address addr, Register scratch) { 967 #ifdef AARCH64 968 ldr(scratch, addr); 969 br(scratch); 970 #else 971 ldr(PC, addr); 972 #endif 973 } 974 975 void indirect_jump(InlinedAddress& literal, Register scratch) { 976 #ifdef AARCH64 977 ldr_literal(scratch, literal); 978 br(scratch); 979 #else 980 ldr_literal(PC, literal); 981 #endif 982 } 983 984 #ifndef AARCH64 985 void neg(Register dst, Register src) { 986 rsb(dst, src, 0); 987 } 988 #endif 989 990 void branch_if_negative_32(Register r, Label& L) { 991 // Note about branch_if_negative_32() / branch_if_any_negative_32() implementation for AArch64: 992 // tbnz is not used instead of tst & b.mi because destination may be out of tbnz range (+-32KB) 993 // since these methods are used in LIR_Assembler::emit_arraycopy() to jump to stub entry. 994 tst_32(r, r); 995 b(L, mi); 996 } 997 998 void branch_if_any_negative_32(Register r1, Register r2, Register tmp, Label& L) { 999 #ifdef AARCH64 1000 orr_32(tmp, r1, r2); 1001 tst_32(tmp, tmp); 1002 #else 1003 orrs(tmp, r1, r2); 1004 #endif 1005 b(L, mi); 1006 } 1007 1008 void branch_if_any_negative_32(Register r1, Register r2, Register r3, Register tmp, Label& L) { 1009 orr_32(tmp, r1, r2); 1010 #ifdef AARCH64 1011 orr_32(tmp, tmp, r3); 1012 tst_32(tmp, tmp); 1013 #else 1014 orrs(tmp, tmp, r3); 1015 #endif 1016 b(L, mi); 1017 } 1018 1019 void add_ptr_scaled_int32(Register dst, Register r1, Register r2, int shift) { 1020 #ifdef AARCH64 1021 add(dst, r1, r2, ex_sxtw, shift); 1022 #else 1023 add(dst, r1, AsmOperand(r2, lsl, shift)); 1024 #endif 1025 } 1026 1027 void sub_ptr_scaled_int32(Register dst, Register r1, Register r2, int shift) { 1028 #ifdef AARCH64 1029 sub(dst, r1, r2, ex_sxtw, shift); 1030 #else 1031 sub(dst, r1, AsmOperand(r2, lsl, shift)); 1032 #endif 1033 } 1034 1035 1036 // klass oop manipulations if compressed 1037 1038 #ifdef AARCH64 1039 void load_klass(Register dst_klass, Register src_oop); 1040 #else 1041 void load_klass(Register dst_klass, Register src_oop, AsmCondition cond = al); 1042 #endif // AARCH64 1043 1044 void store_klass(Register src_klass, Register dst_oop); 1045 1046 #ifdef AARCH64 1047 void store_klass_gap(Register dst); 1048 #endif // AARCH64 1049 1050 // oop manipulations 1051 1052 void load_heap_oop(Register dst, Address src, Register tmp1 = noreg, Register tmp2 = noreg, Register tmp3 = noreg, DecoratorSet decorators = 0); 1053 void store_heap_oop(Address obj, Register new_val, Register tmp1 = noreg, Register tmp2 = noreg, Register tmp3 = noreg, DecoratorSet decorators = 0); 1054 void store_heap_oop_null(Address obj, Register new_val, Register tmp1 = noreg, Register tmp2 = noreg, Register tmp3 = noreg, DecoratorSet decorators = 0); 1055 1056 void access_load_at(BasicType type, DecoratorSet decorators, Address src, Register dst, Register tmp1, Register tmp2, Register tmp3); 1057 void access_store_at(BasicType type, DecoratorSet decorators, Address obj, Register new_val, Register tmp1, Register tmp2, Register tmp3, bool is_null); 1058 1059 #ifdef AARCH64 1060 void encode_heap_oop(Register dst, Register src); 1061 void encode_heap_oop(Register r) { 1062 encode_heap_oop(r, r); 1063 } 1064 void decode_heap_oop(Register dst, Register src); 1065 void decode_heap_oop(Register r) { 1066 decode_heap_oop(r, r); 1067 } 1068 1069 #ifdef COMPILER2 1070 void encode_heap_oop_not_null(Register dst, Register src); 1071 void decode_heap_oop_not_null(Register dst, Register src); 1072 1073 void set_narrow_klass(Register dst, Klass* k); 1074 void set_narrow_oop(Register dst, jobject obj); 1075 #endif 1076 1077 void encode_klass_not_null(Register r); 1078 void encode_klass_not_null(Register dst, Register src); 1079 void decode_klass_not_null(Register r); 1080 void decode_klass_not_null(Register dst, Register src); 1081 1082 void reinit_heapbase(); 1083 1084 #ifdef ASSERT 1085 void verify_heapbase(const char* msg); 1086 #endif // ASSERT 1087 1088 static int instr_count_for_mov_slow(intptr_t c); 1089 static int instr_count_for_mov_slow(address addr); 1090 static int instr_count_for_decode_klass_not_null(); 1091 #endif // AARCH64 1092 1093 void ldr_global_ptr(Register reg, address address_of_global); 1094 void ldr_global_s32(Register reg, address address_of_global); 1095 void ldrb_global(Register reg, address address_of_global); 1096 1097 // address_placeholder_instruction is invalid instruction and is used 1098 // as placeholder in code for address of label 1099 enum { address_placeholder_instruction = 0xFFFFFFFF }; 1100 1101 void emit_address(Label& L) { 1102 assert(!L.is_bound(), "otherwise address will not be patched"); 1103 target(L); // creates relocation which will be patched later 1104 1105 assert ((offset() & (wordSize-1)) == 0, "should be aligned by word size"); 1106 1107 #ifdef AARCH64 1108 emit_int32(address_placeholder_instruction); 1109 emit_int32(address_placeholder_instruction); 1110 #else 1111 AbstractAssembler::emit_address((address)address_placeholder_instruction); 1112 #endif 1113 } 1114 1115 void b(address target, AsmCondition cond = al) { 1116 Assembler::b(target, cond); \ 1117 } 1118 void b(Label& L, AsmCondition cond = al) { 1119 // internal jumps 1120 Assembler::b(target(L), cond); 1121 } 1122 1123 void bl(address target NOT_AARCH64_ARG(AsmCondition cond = al)) { 1124 Assembler::bl(target NOT_AARCH64_ARG(cond)); 1125 } 1126 void bl(Label& L NOT_AARCH64_ARG(AsmCondition cond = al)) { 1127 // internal calls 1128 Assembler::bl(target(L) NOT_AARCH64_ARG(cond)); 1129 } 1130 1131 #ifndef AARCH64 1132 void adr(Register dest, Label& L, AsmCondition cond = al) { 1133 int delta = target(L) - pc() - 8; 1134 if (delta >= 0) { 1135 add(dest, PC, delta, cond); 1136 } else { 1137 sub(dest, PC, -delta, cond); 1138 } 1139 } 1140 #endif // !AARCH64 1141 1142 // Variable-length jump and calls. We now distinguish only the 1143 // patchable case from the other cases. Patchable must be 1144 // distinguised from relocable. Relocable means the generated code 1145 // containing the jump/call may move. Patchable means that the 1146 // targeted address may be changed later. 1147 1148 // Non patchable versions. 1149 // - used only for relocInfo::runtime_call_type and relocInfo::none 1150 // - may use relative or absolute format (do not use relocInfo::none 1151 // if the generated code may move) 1152 // - the implementation takes into account switch to THUMB mode if the 1153 // destination is a THUMB address 1154 // - the implementation supports far targets 1155 // 1156 // To reduce regression risk, scratch still defaults to noreg on 1157 // arm32. This results in patchable instructions. However, if 1158 // patching really matters, the call sites should be modified and 1159 // use patchable_call or patchable_jump. If patching is not required 1160 // and if a register can be cloberred, it should be explicitly 1161 // specified to allow future optimizations. 1162 void jump(address target, 1163 relocInfo::relocType rtype = relocInfo::runtime_call_type, 1164 Register scratch = AARCH64_ONLY(Rtemp) NOT_AARCH64(noreg) 1165 #ifndef AARCH64 1166 , AsmCondition cond = al 1167 #endif 1168 ); 1169 1170 void call(address target, 1171 RelocationHolder rspec 1172 NOT_AARCH64_ARG(AsmCondition cond = al)); 1173 1174 void call(address target, 1175 relocInfo::relocType rtype = relocInfo::runtime_call_type 1176 NOT_AARCH64_ARG(AsmCondition cond = al)) { 1177 call(target, Relocation::spec_simple(rtype) NOT_AARCH64_ARG(cond)); 1178 } 1179 1180 void jump(AddressLiteral dest) { 1181 jump(dest.target(), dest.reloc()); 1182 } 1183 #ifndef AARCH64 1184 void jump(address dest, relocInfo::relocType rtype, AsmCondition cond) { 1185 jump(dest, rtype, Rtemp, cond); 1186 } 1187 #endif 1188 1189 void call(AddressLiteral dest) { 1190 call(dest.target(), dest.reloc()); 1191 } 1192 1193 // Patchable version: 1194 // - set_destination can be used to atomically change the target 1195 // 1196 // The targets for patchable_jump and patchable_call must be in the 1197 // code cache. 1198 // [ including possible extensions of the code cache, like AOT code ] 1199 // 1200 // To reduce regression risk, scratch still defaults to noreg on 1201 // arm32. If a register can be cloberred, it should be explicitly 1202 // specified to allow future optimizations. 1203 void patchable_jump(address target, 1204 relocInfo::relocType rtype = relocInfo::runtime_call_type, 1205 Register scratch = AARCH64_ONLY(Rtemp) NOT_AARCH64(noreg) 1206 #ifndef AARCH64 1207 , AsmCondition cond = al 1208 #endif 1209 ); 1210 1211 // patchable_call may scratch Rtemp 1212 int patchable_call(address target, 1213 RelocationHolder const& rspec, 1214 bool c2 = false); 1215 1216 int patchable_call(address target, 1217 relocInfo::relocType rtype, 1218 bool c2 = false) { 1219 return patchable_call(target, Relocation::spec_simple(rtype), c2); 1220 } 1221 1222 #if defined(AARCH64) && defined(COMPILER2) 1223 static int call_size(address target, bool far, bool patchable); 1224 #endif 1225 1226 #ifdef AARCH64 1227 static bool page_reachable_from_cache(address target); 1228 #endif 1229 static bool _reachable_from_cache(address target); 1230 static bool _cache_fully_reachable(); 1231 bool cache_fully_reachable(); 1232 bool reachable_from_cache(address target); 1233 1234 void zero_extend(Register rd, Register rn, int bits); 1235 void sign_extend(Register rd, Register rn, int bits); 1236 1237 inline void zap_high_non_significant_bits(Register r) { 1238 #ifdef AARCH64 1239 if(ZapHighNonSignificantBits) { 1240 movk(r, 0xBAAD, 48); 1241 movk(r, 0xF00D, 32); 1242 } 1243 #endif 1244 } 1245 1246 #ifndef AARCH64 1247 void cmpoop(Register obj1, Register obj2); 1248 1249 void long_move(Register rd_lo, Register rd_hi, 1250 Register rn_lo, Register rn_hi, 1251 AsmCondition cond = al); 1252 void long_shift(Register rd_lo, Register rd_hi, 1253 Register rn_lo, Register rn_hi, 1254 AsmShift shift, Register count); 1255 void long_shift(Register rd_lo, Register rd_hi, 1256 Register rn_lo, Register rn_hi, 1257 AsmShift shift, int count); 1258 1259 void atomic_cas(Register tmpreg1, Register tmpreg2, Register oldval, Register newval, Register base, int offset); 1260 void atomic_cas_bool(Register oldval, Register newval, Register base, int offset, Register tmpreg); 1261 void atomic_cas64(Register temp_lo, Register temp_hi, Register temp_result, Register oldval_lo, Register oldval_hi, Register newval_lo, Register newval_hi, Register base, int offset); 1262 #endif // !AARCH64 1263 1264 void cas_for_lock_acquire(Register oldval, Register newval, Register base, Register tmp, Label &slow_case, bool allow_fallthrough_on_failure = false, bool one_shot = false); 1265 void cas_for_lock_release(Register oldval, Register newval, Register base, Register tmp, Label &slow_case, bool allow_fallthrough_on_failure = false, bool one_shot = false); 1266 1267 #ifndef PRODUCT 1268 // Preserves flags and all registers. 1269 // On SMP the updated value might not be visible to external observers without a sychronization barrier 1270 void cond_atomic_inc32(AsmCondition cond, int* counter_addr); 1271 #endif // !PRODUCT 1272 1273 // unconditional non-atomic increment 1274 void inc_counter(address counter_addr, Register tmpreg1, Register tmpreg2); 1275 void inc_counter(int* counter_addr, Register tmpreg1, Register tmpreg2) { 1276 inc_counter((address) counter_addr, tmpreg1, tmpreg2); 1277 } 1278 1279 void pd_patch_instruction(address branch, address target, const char* file, int line); 1280 1281 // Loading and storing values by size and signed-ness; 1282 // size must not exceed wordSize (i.e. 8-byte values are not supported on 32-bit ARM); 1283 // each of these calls generates exactly one load or store instruction, 1284 // so src can be pre- or post-indexed address. 1285 #ifdef AARCH64 1286 void load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed); 1287 void store_sized_value(Register src, Address dst, size_t size_in_bytes); 1288 #else 1289 // 32-bit ARM variants also support conditional execution 1290 void load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed, AsmCondition cond = al); 1291 void store_sized_value(Register src, Address dst, size_t size_in_bytes, AsmCondition cond = al); 1292 #endif 1293 1294 void lookup_interface_method(Register recv_klass, 1295 Register intf_klass, 1296 RegisterOrConstant itable_index, 1297 Register method_result, 1298 Register temp_reg1, 1299 Register temp_reg2, 1300 Label& L_no_such_interface); 1301 1302 // Compare char[] arrays aligned to 4 bytes. 1303 void char_arrays_equals(Register ary1, Register ary2, 1304 Register limit, Register result, 1305 Register chr1, Register chr2, Label& Ldone); 1306 1307 1308 void floating_cmp(Register dst); 1309 1310 // improved x86 portability (minimizing source code changes) 1311 1312 void ldr_literal(Register rd, AddressLiteral addr) { 1313 relocate(addr.rspec()); 1314 #ifdef AARCH64 1315 ldr(rd, addr.target()); 1316 #else 1317 ldr(rd, Address(PC, addr.target() - pc() - 8)); 1318 #endif 1319 } 1320 1321 void lea(Register Rd, AddressLiteral addr) { 1322 // Never dereferenced, as on x86 (lval status ignored) 1323 mov_address(Rd, addr.target(), addr.rspec()); 1324 } 1325 1326 void restore_default_fp_mode(); 1327 1328 #ifdef COMPILER2 1329 #ifdef AARCH64 1330 // Code used by cmpFastLock and cmpFastUnlock mach instructions in .ad file. 1331 void fast_lock(Register obj, Register box, Register scratch, Register scratch2, Register scratch3); 1332 void fast_unlock(Register obj, Register box, Register scratch, Register scratch2, Register scratch3); 1333 #else 1334 void fast_lock(Register obj, Register box, Register scratch, Register scratch2); 1335 void fast_unlock(Register obj, Register box, Register scratch, Register scratch2); 1336 #endif 1337 #endif 1338 1339 #ifdef AARCH64 1340 1341 #define F(mnemonic) \ 1342 void mnemonic(Register rt, address target) { \ 1343 Assembler::mnemonic(rt, target); \ 1344 } \ 1345 void mnemonic(Register rt, Label& L) { \ 1346 Assembler::mnemonic(rt, target(L)); \ 1347 } 1348 1349 F(cbz_w); 1350 F(cbnz_w); 1351 F(cbz); 1352 F(cbnz); 1353 1354 #undef F 1355 1356 #define F(mnemonic) \ 1357 void mnemonic(Register rt, int bit, address target) { \ 1358 Assembler::mnemonic(rt, bit, target); \ 1359 } \ 1360 void mnemonic(Register rt, int bit, Label& L) { \ 1361 Assembler::mnemonic(rt, bit, target(L)); \ 1362 } 1363 1364 F(tbz); 1365 F(tbnz); 1366 #undef F 1367 1368 #endif // AARCH64 1369 1370 }; 1371 1372 1373 // The purpose of this class is to build several code fragments of the same size 1374 // in order to allow fast table branch. 1375 1376 class FixedSizeCodeBlock { 1377 public: 1378 FixedSizeCodeBlock(MacroAssembler* masm, int size_in_instrs, bool enabled); 1379 ~FixedSizeCodeBlock(); 1380 1381 private: 1382 MacroAssembler* _masm; 1383 address _start; 1384 int _size_in_instrs; 1385 bool _enabled; 1386 }; 1387 1388 1389 #endif // CPU_ARM_VM_MACROASSEMBLER_ARM_HPP 1390