src/cpu/ppc/vm/macroAssembler_ppc.inline.hpp

Wed, 27 Nov 2013 16:16:21 -0800

author
goetz
date
Wed, 27 Nov 2013 16:16:21 -0800
changeset 6490
41b780b43b74
parent 6486
b0133e4187d3
child 6495
67fa91961822
permissions
-rw-r--r--

8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn

goetz@6458 1 /*
goetz@6458 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
goetz@6458 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
goetz@6458 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@6458 5 *
goetz@6458 6 * This code is free software; you can redistribute it and/or modify it
goetz@6458 7 * under the terms of the GNU General Public License version 2 only, as
goetz@6458 8 * published by the Free Software Foundation.
goetz@6458 9 *
goetz@6458 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@6458 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@6458 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@6458 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@6458 14 * accompanied this code).
goetz@6458 15 *
goetz@6458 16 * You should have received a copy of the GNU General Public License version
goetz@6458 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@6458 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@6458 19 *
goetz@6458 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@6458 21 * or visit www.oracle.com if you need additional information or have any
goetz@6458 22 * questions.
goetz@6458 23 *
goetz@6458 24 */
goetz@6458 25
goetz@6458 26 #ifndef CPU_PPC_VM_MACROASSEMBLER_PPC_INLINE_HPP
goetz@6458 27 #define CPU_PPC_VM_MACROASSEMBLER_PPC_INLINE_HPP
goetz@6458 28
goetz@6458 29 #include "asm/assembler.inline.hpp"
goetz@6458 30 #include "asm/macroAssembler.hpp"
goetz@6458 31 #include "asm/codeBuffer.hpp"
goetz@6458 32 #include "code/codeCache.hpp"
goetz@6458 33
goetz@6458 34 inline bool MacroAssembler::is_ld_largeoffset(address a) {
goetz@6458 35 const int inst1 = *(int *)a;
goetz@6458 36 const int inst2 = *(int *)(a+4);
goetz@6458 37 return (is_ld(inst1)) ||
goetz@6458 38 (is_addis(inst1) && is_ld(inst2) && inv_ra_field(inst2) == inv_rt_field(inst1));
goetz@6458 39 }
goetz@6458 40
goetz@6458 41 inline int MacroAssembler::get_ld_largeoffset_offset(address a) {
goetz@6458 42 assert(MacroAssembler::is_ld_largeoffset(a), "must be ld with large offset");
goetz@6458 43
goetz@6458 44 const int inst1 = *(int *)a;
goetz@6458 45 if (is_ld(inst1)) {
goetz@6458 46 return inv_d1_field(inst1);
goetz@6458 47 } else {
goetz@6458 48 const int inst2 = *(int *)(a+4);
goetz@6458 49 return (inv_d1_field(inst1) << 16) + inv_d1_field(inst2);
goetz@6458 50 }
goetz@6458 51 }
goetz@6458 52
goetz@6458 53 inline void MacroAssembler::round_to(Register r, int modulus) {
goetz@6458 54 assert(is_power_of_2_long((jlong)modulus), "must be power of 2");
goetz@6458 55 addi(r, r, modulus-1);
goetz@6458 56 clrrdi(r, r, log2_long((jlong)modulus));
goetz@6458 57 }
goetz@6458 58
goetz@6458 59 // Move register if destination register and target register are different.
goetz@6458 60 inline void MacroAssembler::mr_if_needed(Register rd, Register rs) {
goetz@6458 61 if(rs !=rd) mr(rd, rs);
goetz@6458 62 }
goetz@6458 63
goetz@6458 64 // Address of the global TOC.
goetz@6458 65 inline address MacroAssembler::global_toc() {
goetz@6458 66 return CodeCache::low_bound();
goetz@6458 67 }
goetz@6458 68
goetz@6458 69 // Offset of given address to the global TOC.
goetz@6458 70 inline int MacroAssembler::offset_to_global_toc(const address addr) {
goetz@6458 71 intptr_t offset = (intptr_t)addr - (intptr_t)MacroAssembler::global_toc();
goetz@6458 72 assert(Assembler::is_simm((long)offset, 31) && offset >= 0, "must be in range");
goetz@6458 73 return (int)offset;
goetz@6458 74 }
goetz@6458 75
goetz@6458 76 // Address of current method's TOC.
goetz@6458 77 inline address MacroAssembler::method_toc() {
goetz@6458 78 return code()->consts()->start();
goetz@6458 79 }
goetz@6458 80
goetz@6458 81 // Offset of given address to current method's TOC.
goetz@6458 82 inline int MacroAssembler::offset_to_method_toc(address addr) {
goetz@6458 83 intptr_t offset = (intptr_t)addr - (intptr_t)method_toc();
goetz@6458 84 assert(is_simm((long)offset, 31) && offset >= 0, "must be in range");
goetz@6458 85 return (int)offset;
goetz@6458 86 }
goetz@6458 87
goetz@6458 88 inline bool MacroAssembler::is_calculate_address_from_global_toc_at(address a, address bound) {
goetz@6458 89 const address inst2_addr = a;
goetz@6458 90 const int inst2 = *(int *) a;
goetz@6458 91
goetz@6458 92 // The relocation points to the second instruction, the addi.
goetz@6458 93 if (!is_addi(inst2)) return false;
goetz@6458 94
goetz@6458 95 // The addi reads and writes the same register dst.
goetz@6458 96 const int dst = inv_rt_field(inst2);
goetz@6458 97 if (inv_ra_field(inst2) != dst) return false;
goetz@6458 98
goetz@6458 99 // Now, find the preceding addis which writes to dst.
goetz@6458 100 int inst1 = 0;
goetz@6458 101 address inst1_addr = inst2_addr - BytesPerInstWord;
goetz@6458 102 while (inst1_addr >= bound) {
goetz@6458 103 inst1 = *(int *) inst1_addr;
goetz@6458 104 if (is_addis(inst1) && inv_rt_field(inst1) == dst) {
goetz@6458 105 // stop, found the addis which writes dst
goetz@6458 106 break;
goetz@6458 107 }
goetz@6458 108 inst1_addr -= BytesPerInstWord;
goetz@6458 109 }
goetz@6458 110
goetz@6458 111 if (!(inst1 == 0 || inv_ra_field(inst1) == 29 /* R29 */)) return false;
goetz@6458 112 return is_addis(inst1);
goetz@6458 113 }
goetz@6458 114
goetz@6458 115 #ifdef _LP64
goetz@6458 116 // Detect narrow oop constants.
goetz@6458 117 inline bool MacroAssembler::is_set_narrow_oop(address a, address bound) {
goetz@6458 118 const address inst2_addr = a;
goetz@6458 119 const int inst2 = *(int *)a;
goetz@6458 120
goetz@6458 121 // The relocation points to the second instruction, the addi.
goetz@6458 122 if (!is_addi(inst2)) return false;
goetz@6458 123
goetz@6458 124 // The addi reads and writes the same register dst.
goetz@6458 125 const int dst = inv_rt_field(inst2);
goetz@6458 126 if (inv_ra_field(inst2) != dst) return false;
goetz@6458 127
goetz@6458 128 // Now, find the preceding addis which writes to dst.
goetz@6458 129 int inst1 = 0;
goetz@6458 130 address inst1_addr = inst2_addr - BytesPerInstWord;
goetz@6458 131 while (inst1_addr >= bound) {
goetz@6458 132 inst1 = *(int *) inst1_addr;
goetz@6458 133 if (is_lis(inst1) && inv_rs_field(inst1) == dst) return true;
goetz@6458 134 inst1_addr -= BytesPerInstWord;
goetz@6458 135 }
goetz@6458 136 return false;
goetz@6458 137 }
goetz@6458 138 #endif
goetz@6458 139
goetz@6458 140
goetz@6458 141 inline bool MacroAssembler::is_load_const_at(address a) {
goetz@6458 142 const int* p_inst = (int *) a;
goetz@6458 143 bool b = is_lis(*p_inst++);
goetz@6458 144 if (is_ori(*p_inst)) {
goetz@6458 145 p_inst++;
goetz@6458 146 b = b && is_rldicr(*p_inst++); // TODO: could be made more precise: `sldi'!
goetz@6458 147 b = b && is_oris(*p_inst++);
goetz@6458 148 b = b && is_ori(*p_inst);
goetz@6458 149 } else if (is_lis(*p_inst)) {
goetz@6458 150 p_inst++;
goetz@6458 151 b = b && is_ori(*p_inst++);
goetz@6458 152 b = b && is_ori(*p_inst);
goetz@6458 153 // TODO: could enhance reliability by adding is_insrdi
goetz@6458 154 } else return false;
goetz@6458 155 return b;
goetz@6458 156 }
goetz@6458 157
goetz@6458 158 inline void MacroAssembler::set_oop_constant(jobject obj, Register d) {
goetz@6458 159 set_oop(constant_oop_address(obj), d);
goetz@6458 160 }
goetz@6458 161
goetz@6458 162 inline void MacroAssembler::set_oop(AddressLiteral obj_addr, Register d) {
goetz@6458 163 assert(obj_addr.rspec().type() == relocInfo::oop_type, "must be an oop reloc");
goetz@6458 164 load_const(d, obj_addr);
goetz@6458 165 }
goetz@6458 166
goetz@6458 167 inline void MacroAssembler::pd_patch_instruction(address branch, address target) {
goetz@6458 168 jint& stub_inst = *(jint*) branch;
goetz@6458 169 stub_inst = patched_branch(target - branch, stub_inst, 0);
goetz@6458 170 }
goetz@6458 171
goetz@6458 172 // Relocation of conditional far branches.
goetz@6458 173 inline bool MacroAssembler::is_bc_far_variant1_at(address instruction_addr) {
goetz@6458 174 // Variant 1, the 1st instruction contains the destination address:
goetz@6458 175 //
goetz@6458 176 // bcxx DEST
goetz@6458 177 // endgroup
goetz@6458 178 //
goetz@6458 179 const int instruction_1 = *(int*)(instruction_addr);
goetz@6458 180 const int instruction_2 = *(int*)(instruction_addr + 4);
goetz@6458 181 return is_bcxx(instruction_1) &&
goetz@6458 182 (inv_bd_field(instruction_1, (intptr_t)instruction_addr) != (intptr_t)(instruction_addr + 2*4)) &&
goetz@6458 183 is_endgroup(instruction_2);
goetz@6458 184 }
goetz@6458 185
goetz@6458 186 // Relocation of conditional far branches.
goetz@6458 187 inline bool MacroAssembler::is_bc_far_variant2_at(address instruction_addr) {
goetz@6458 188 // Variant 2, the 2nd instruction contains the destination address:
goetz@6458 189 //
goetz@6458 190 // b!cxx SKIP
goetz@6458 191 // bxx DEST
goetz@6458 192 // SKIP:
goetz@6458 193 //
goetz@6458 194 const int instruction_1 = *(int*)(instruction_addr);
goetz@6458 195 const int instruction_2 = *(int*)(instruction_addr + 4);
goetz@6458 196 return is_bcxx(instruction_1) &&
goetz@6458 197 (inv_bd_field(instruction_1, (intptr_t)instruction_addr) == (intptr_t)(instruction_addr + 2*4)) &&
goetz@6458 198 is_bxx(instruction_2);
goetz@6458 199 }
goetz@6458 200
goetz@6458 201 // Relocation for conditional branches
goetz@6458 202 inline bool MacroAssembler::is_bc_far_variant3_at(address instruction_addr) {
goetz@6458 203 // Variant 3, far cond branch to the next instruction, already patched to nops:
goetz@6458 204 //
goetz@6458 205 // nop
goetz@6458 206 // endgroup
goetz@6458 207 // SKIP/DEST:
goetz@6458 208 //
goetz@6458 209 const int instruction_1 = *(int*)(instruction_addr);
goetz@6458 210 const int instruction_2 = *(int*)(instruction_addr + 4);
goetz@6458 211 return is_nop(instruction_1) &&
goetz@6458 212 is_endgroup(instruction_2);
goetz@6458 213 }
goetz@6458 214
goetz@6458 215
goetz@6458 216 // Convenience bc_far versions
goetz@6458 217 inline void MacroAssembler::blt_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs1, bi0(crx, less), L, optimize); }
goetz@6458 218 inline void MacroAssembler::bgt_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs1, bi0(crx, greater), L, optimize); }
goetz@6458 219 inline void MacroAssembler::beq_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs1, bi0(crx, equal), L, optimize); }
goetz@6458 220 inline void MacroAssembler::bso_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs1, bi0(crx, summary_overflow), L, optimize); }
goetz@6458 221 inline void MacroAssembler::bge_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs0, bi0(crx, less), L, optimize); }
goetz@6458 222 inline void MacroAssembler::ble_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs0, bi0(crx, greater), L, optimize); }
goetz@6458 223 inline void MacroAssembler::bne_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs0, bi0(crx, equal), L, optimize); }
goetz@6458 224 inline void MacroAssembler::bns_far(ConditionRegister crx, Label& L, int optimize) { MacroAssembler::bc_far(bcondCRbiIs0, bi0(crx, summary_overflow), L, optimize); }
goetz@6458 225
goetz@6458 226 inline address MacroAssembler::call_stub(Register function_entry) {
goetz@6458 227 mtctr(function_entry);
goetz@6458 228 bctrl();
goetz@6458 229 return pc();
goetz@6458 230 }
goetz@6458 231
goetz@6458 232 inline void MacroAssembler::call_stub_and_return_to(Register function_entry, Register return_pc) {
goetz@6458 233 assert_different_registers(function_entry, return_pc);
goetz@6458 234 mtlr(return_pc);
goetz@6458 235 mtctr(function_entry);
goetz@6458 236 bctr();
goetz@6458 237 }
goetz@6458 238
goetz@6458 239 // Get the pc where the last emitted call will return to.
goetz@6458 240 inline address MacroAssembler::last_calls_return_pc() {
goetz@6458 241 return _last_calls_return_pc;
goetz@6458 242 }
goetz@6458 243
goetz@6458 244 // Read from the polling page, its address is already in a register.
goetz@6458 245 inline void MacroAssembler::load_from_polling_page(Register polling_page_address, int offset) {
goetz@6458 246 ld(R0, offset, polling_page_address);
goetz@6458 247 }
goetz@6458 248
goetz@6458 249 // Trap-instruction-based checks.
goetz@6458 250
goetz@6458 251 inline void MacroAssembler::trap_null_check(Register a, trap_to_bits cmp) {
goetz@6458 252 assert(TrapBasedNullChecks, "sanity");
goetz@6458 253 tdi(cmp, a/*reg a*/, 0);
goetz@6458 254 }
goetz@6458 255 inline void MacroAssembler::trap_zombie_not_entrant() {
goetz@6458 256 tdi(traptoUnconditional, 0/*reg 0*/, 1);
goetz@6458 257 }
goetz@6458 258 inline void MacroAssembler::trap_should_not_reach_here() {
goetz@6458 259 tdi_unchecked(traptoUnconditional, 0/*reg 0*/, 2);
goetz@6458 260 }
goetz@6458 261
goetz@6458 262 inline void MacroAssembler::trap_ic_miss_check(Register a, Register b) {
goetz@6458 263 td(traptoGreaterThanUnsigned | traptoLessThanUnsigned, a, b);
goetz@6458 264 }
goetz@6458 265
goetz@6458 266 // Do an explicit null check if access to a+offset will not raise a SIGSEGV.
goetz@6458 267 // Either issue a trap instruction that raises SIGTRAP, or do a compare that
goetz@6458 268 // branches to exception_entry.
goetz@6458 269 // No support for compressed oops (base page of heap). Does not distinguish
goetz@6458 270 // loads and stores.
goetz@6458 271 inline void MacroAssembler::null_check_throw(Register a, int offset, Register temp_reg, address exception_entry) {
goetz@6486 272 if (!ImplicitNullChecks || needs_explicit_null_check(offset) || !os::zero_page_read_protected()) {
goetz@6458 273 if (TrapBasedNullChecks) {
goetz@6458 274 assert(UseSIGTRAP, "sanity");
goetz@6458 275 trap_null_check(a);
goetz@6458 276 } else {
goetz@6458 277 Label ok;
goetz@6458 278 cmpdi(CCR0, a, 0);
goetz@6458 279 bne(CCR0, ok);
goetz@6458 280 load_const_optimized(temp_reg, exception_entry);
goetz@6458 281 mtctr(temp_reg);
goetz@6458 282 bctr();
goetz@6458 283 bind(ok);
goetz@6458 284 }
goetz@6458 285 }
goetz@6458 286 }
goetz@6458 287
goetz@6458 288 inline void MacroAssembler::ld_with_trap_null_check(Register d, int si16, Register s1) {
goetz@6486 289 if (!os::zero_page_read_protected()) {
goetz@6458 290 if (TrapBasedNullChecks) {
goetz@6458 291 trap_null_check(s1);
goetz@6458 292 }
goetz@6458 293 }
goetz@6458 294 ld(d, si16, s1);
goetz@6458 295 }
goetz@6458 296
goetz@6458 297 // Attention: No null check for loaded uncompressed OOP. Can be used for loading klass field.
goetz@6458 298 inline void MacroAssembler::load_heap_oop_with_trap_null_check(Register d, RegisterOrConstant si16,
goetz@6458 299 Register s1) {
goetz@6486 300 if ( !os::zero_page_read_protected()) {
goetz@6458 301 if (TrapBasedNullChecks) {
goetz@6458 302 trap_null_check(s1);
goetz@6458 303 }
goetz@6458 304 }
goetz@6458 305 load_heap_oop_not_null(d, si16, s1);
goetz@6458 306 }
goetz@6458 307
goetz@6458 308 inline void MacroAssembler::load_heap_oop_not_null(Register d, RegisterOrConstant offs, Register s1) {
goetz@6458 309 if (UseCompressedOops) {
goetz@6458 310 lwz(d, offs, s1);
goetz@6458 311 // Attention: no null check here!
goetz@6458 312 decode_heap_oop_not_null(d);
goetz@6458 313 } else {
goetz@6458 314 ld(d, offs, s1);
goetz@6458 315 }
goetz@6458 316 }
goetz@6458 317
goetz@6458 318 inline void MacroAssembler::load_heap_oop(Register d, RegisterOrConstant offs, Register s1) {
goetz@6458 319 if (UseCompressedOops) {
goetz@6458 320 lwz(d, offs, s1);
goetz@6458 321 decode_heap_oop(d);
goetz@6458 322 } else {
goetz@6458 323 ld(d, offs, s1);
goetz@6458 324 }
goetz@6458 325 }
goetz@6458 326
goetz@6458 327 inline void MacroAssembler::encode_heap_oop_not_null(Register d) {
goetz@6458 328 if (Universe::narrow_oop_base() != NULL) {
goetz@6458 329 sub(d, d, R30);
goetz@6458 330 }
goetz@6458 331 if (Universe::narrow_oop_shift() != 0) {
goetz@6458 332 srdi(d, d, LogMinObjAlignmentInBytes);
goetz@6458 333 }
goetz@6458 334 }
goetz@6458 335
goetz@6458 336 inline void MacroAssembler::decode_heap_oop_not_null(Register d) {
goetz@6458 337 if (Universe::narrow_oop_shift() != 0) {
goetz@6458 338 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
goetz@6458 339 sldi(d, d, LogMinObjAlignmentInBytes);
goetz@6458 340 }
goetz@6458 341 if (Universe::narrow_oop_base() != NULL) {
goetz@6458 342 add(d, d, R30);
goetz@6458 343 }
goetz@6458 344 }
goetz@6458 345
goetz@6458 346 inline void MacroAssembler::decode_heap_oop(Register d) {
goetz@6458 347 Label isNull;
goetz@6458 348 if (Universe::narrow_oop_base() != NULL) {
goetz@6458 349 cmpwi(CCR0, d, 0);
goetz@6458 350 beq(CCR0, isNull);
goetz@6458 351 }
goetz@6458 352 if (Universe::narrow_oop_shift() != 0) {
goetz@6458 353 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
goetz@6458 354 sldi(d, d, LogMinObjAlignmentInBytes);
goetz@6458 355 }
goetz@6458 356 if (Universe::narrow_oop_base() != NULL) {
goetz@6458 357 add(d, d, R30);
goetz@6458 358 }
goetz@6458 359 bind(isNull);
goetz@6458 360 }
goetz@6458 361
goetz@6458 362 // SIGTRAP-based range checks for arrays.
goetz@6458 363 inline void MacroAssembler::trap_range_check_l(Register a, Register b) {
goetz@6458 364 tw (traptoLessThanUnsigned, a/*reg a*/, b/*reg b*/);
goetz@6458 365 }
goetz@6458 366 inline void MacroAssembler::trap_range_check_l(Register a, int si16) {
goetz@6458 367 twi(traptoLessThanUnsigned, a/*reg a*/, si16);
goetz@6458 368 }
goetz@6458 369 inline void MacroAssembler::trap_range_check_le(Register a, int si16) {
goetz@6458 370 twi(traptoEqual | traptoLessThanUnsigned, a/*reg a*/, si16);
goetz@6458 371 }
goetz@6458 372 inline void MacroAssembler::trap_range_check_g(Register a, int si16) {
goetz@6458 373 twi(traptoGreaterThanUnsigned, a/*reg a*/, si16);
goetz@6458 374 }
goetz@6458 375 inline void MacroAssembler::trap_range_check_ge(Register a, Register b) {
goetz@6458 376 tw (traptoEqual | traptoGreaterThanUnsigned, a/*reg a*/, b/*reg b*/);
goetz@6458 377 }
goetz@6458 378 inline void MacroAssembler::trap_range_check_ge(Register a, int si16) {
goetz@6458 379 twi(traptoEqual | traptoGreaterThanUnsigned, a/*reg a*/, si16);
goetz@6458 380 }
goetz@6458 381
goetz@6458 382 #endif // CPU_PPC_VM_MACROASSEMBLER_PPC_INLINE_HPP

mercurial