Tue, 26 Jul 2016 11:15:09 +0800
Instruction decoding support: add movn and movz in MIPS disassembler.
aoqi@1 | 1 | /* |
aoqi@1 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@1 | 3 | * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. |
aoqi@1 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@1 | 5 | * |
aoqi@1 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@1 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@1 | 8 | * published by the Free Software Foundation. |
aoqi@1 | 9 | * |
aoqi@1 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@1 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@1 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@1 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@1 | 14 | * accompanied this code). |
aoqi@1 | 15 | * |
aoqi@1 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@1 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@1 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@1 | 19 | * |
aoqi@1 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@1 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@1 | 22 | * questions. |
aoqi@1 | 23 | * |
aoqi@1 | 24 | */ |
aoqi@1 | 25 | |
aoqi@1 | 26 | #include "precompiled.hpp" |
aoqi@1 | 27 | #include "asm/assembler.hpp" |
aoqi@1 | 28 | #include "asm/assembler.inline.hpp" |
aoqi@1 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
aoqi@1 | 30 | #include "interpreter/interpreter.hpp" |
aoqi@1 | 31 | #include "memory/cardTableModRefBS.hpp" |
aoqi@1 | 32 | #include "memory/resourceArea.hpp" |
aoqi@1 | 33 | #include "prims/methodHandles.hpp" |
aoqi@1 | 34 | #include "runtime/biasedLocking.hpp" |
aoqi@1 | 35 | #include "runtime/interfaceSupport.hpp" |
aoqi@1 | 36 | #include "runtime/objectMonitor.hpp" |
aoqi@1 | 37 | #include "runtime/os.hpp" |
aoqi@1 | 38 | #include "runtime/sharedRuntime.hpp" |
aoqi@1 | 39 | #include "runtime/stubRoutines.hpp" |
aoqi@1 | 40 | #ifndef SERIALGC |
aoqi@1 | 41 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
aoqi@1 | 42 | #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
aoqi@1 | 43 | #include "gc_implementation/g1/heapRegion.hpp" |
aoqi@1 | 44 | #endif |
aoqi@1 | 45 | #ifdef PRODUCT |
aoqi@1 | 46 | #define BLOCK_COMMENT(str) /* nothing */ |
aoqi@1 | 47 | #define STOP(error) stop(error) |
aoqi@1 | 48 | #else |
aoqi@1 | 49 | #define BLOCK_COMMENT(str) block_comment(str) |
aoqi@1 | 50 | #define STOP(error) block_comment(error); stop(error) |
aoqi@1 | 51 | #endif |
aoqi@1 | 52 | |
aoqi@1 | 53 | #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") |
aoqi@1 | 54 | |
aoqi@1 | 55 | intptr_t MacroAssembler::i[32] = {0}; |
aoqi@1 | 56 | float MacroAssembler::f[32] = {0.0}; |
aoqi@1 | 57 | |
aoqi@1 | 58 | void MacroAssembler::print(outputStream *s) { |
aoqi@1 | 59 | unsigned int k; |
aoqi@1 | 60 | for(k=0; k<sizeof(i)/sizeof(i[0]); k++) { |
aoqi@1 | 61 | s->print_cr("i%d = 0x%.16lx", k, i[k]); |
aoqi@1 | 62 | } |
aoqi@1 | 63 | s->cr(); |
aoqi@1 | 64 | |
aoqi@1 | 65 | for(k=0; k<sizeof(f)/sizeof(f[0]); k++) { |
aoqi@1 | 66 | s->print_cr("f%d = %f", k, f[k]); |
aoqi@1 | 67 | } |
aoqi@1 | 68 | s->cr(); |
aoqi@1 | 69 | } |
aoqi@1 | 70 | |
aoqi@1 | 71 | |
aoqi@1 | 72 | int MacroAssembler::i_offset(unsigned int k) { return (intptr_t)&((MacroAssembler*)0)->i[k]; } |
aoqi@1 | 73 | int MacroAssembler::f_offset(unsigned int k) { return (intptr_t)&((MacroAssembler*)0)->f[k]; } |
aoqi@1 | 74 | |
aoqi@1 | 75 | void MacroAssembler::save_registers(MacroAssembler *masm) { |
aoqi@1 | 76 | #define __ masm-> |
aoqi@1 | 77 | for(int k=0; k<32; k++) { |
aoqi@1 | 78 | __ sw (as_Register(k), A0, i_offset(k)); |
aoqi@1 | 79 | } |
aoqi@1 | 80 | |
aoqi@1 | 81 | for(int k=0; k<32; k++) { |
aoqi@1 | 82 | __ swc1 (as_FloatRegister(k), A0, f_offset(k)); |
aoqi@1 | 83 | } |
aoqi@1 | 84 | #undef __ |
aoqi@1 | 85 | } |
aoqi@1 | 86 | |
aoqi@1 | 87 | void MacroAssembler::restore_registers(MacroAssembler *masm) { |
aoqi@1 | 88 | #define __ masm-> |
aoqi@1 | 89 | for(int k=0; k<32; k++) { |
aoqi@1 | 90 | __ lw (as_Register(k), A0, i_offset(k)); |
aoqi@1 | 91 | } |
aoqi@1 | 92 | |
aoqi@1 | 93 | for(int k=0; k<32; k++) { |
aoqi@1 | 94 | __ lwc1 (as_FloatRegister(k), A0, f_offset(k)); |
aoqi@1 | 95 | } |
aoqi@1 | 96 | #undef __ |
aoqi@1 | 97 | } |
aoqi@1 | 98 | |
aoqi@1 | 99 | |
aoqi@1 | 100 | // Implementation of AddressLiteral |
aoqi@1 | 101 | |
aoqi@1 | 102 | AddressLiteral::AddressLiteral(address target, relocInfo::relocType rtype) { |
aoqi@1 | 103 | _is_lval = false; |
aoqi@1 | 104 | _target = target; |
aoqi@1 | 105 | _rspec = rspec_from_rtype(rtype, target); |
aoqi@1 | 106 | } |
aoqi@1 | 107 | |
aoqi@1 | 108 | // Implementation of Address |
aoqi@1 | 109 | |
aoqi@1 | 110 | //FIXME aoqi |
aoqi@1 | 111 | //#ifdef _LP64 |
aoqi@1 | 112 | #if 0 |
aoqi@1 | 113 | |
aoqi@1 | 114 | Address Address::make_array(ArrayAddress adr) { |
aoqi@1 | 115 | // Not implementable on 64bit machines |
aoqi@1 | 116 | // Should have been handled higher up the call chain. |
aoqi@1 | 117 | ShouldNotReachHere(); |
aoqi@1 | 118 | return Address(); |
aoqi@1 | 119 | } |
aoqi@1 | 120 | |
aoqi@1 | 121 | // exceedingly dangerous constructor |
aoqi@1 | 122 | Address::Address(int disp, address loc, relocInfo::relocType rtype) { |
aoqi@1 | 123 | _base = noreg; |
aoqi@1 | 124 | _index = noreg; |
aoqi@1 | 125 | _scale = no_scale; |
aoqi@1 | 126 | _disp = disp; |
aoqi@1 | 127 | switch (rtype) { |
aoqi@1 | 128 | case relocInfo::external_word_type: |
aoqi@1 | 129 | _rspec = external_word_Relocation::spec(loc); |
aoqi@1 | 130 | break; |
aoqi@1 | 131 | case relocInfo::internal_word_type: |
aoqi@1 | 132 | _rspec = internal_word_Relocation::spec(loc); |
aoqi@1 | 133 | break; |
aoqi@1 | 134 | case relocInfo::runtime_call_type: |
aoqi@1 | 135 | // HMM |
aoqi@1 | 136 | _rspec = runtime_call_Relocation::spec(); |
aoqi@1 | 137 | break; |
aoqi@1 | 138 | case relocInfo::poll_type: |
aoqi@1 | 139 | case relocInfo::poll_return_type: |
aoqi@1 | 140 | _rspec = Relocation::spec_simple(rtype); |
aoqi@1 | 141 | break; |
aoqi@1 | 142 | case relocInfo::none: |
aoqi@1 | 143 | break; |
aoqi@1 | 144 | default: |
aoqi@1 | 145 | ShouldNotReachHere(); |
aoqi@1 | 146 | } |
aoqi@1 | 147 | } |
aoqi@1 | 148 | #else // LP64 |
aoqi@1 | 149 | |
aoqi@1 | 150 | Address Address::make_array(ArrayAddress adr) { |
aoqi@1 | 151 | AddressLiteral base = adr.base(); |
aoqi@1 | 152 | Address index = adr.index(); |
aoqi@1 | 153 | assert(index._disp == 0, "must not have disp"); // maybe it can? |
aoqi@1 | 154 | Address array(index._base, index._index, index._scale, (intptr_t) base.target()); |
aoqi@1 | 155 | array._rspec = base._rspec; |
aoqi@1 | 156 | return array; |
aoqi@1 | 157 | } |
aoqi@1 | 158 | |
aoqi@1 | 159 | // exceedingly dangerous constructor |
aoqi@1 | 160 | Address::Address(address loc, RelocationHolder spec) { |
aoqi@1 | 161 | _base = noreg; |
aoqi@1 | 162 | _index = noreg; |
aoqi@1 | 163 | _scale = no_scale; |
aoqi@1 | 164 | _disp = (intptr_t) loc; |
aoqi@1 | 165 | _rspec = spec; |
aoqi@1 | 166 | } |
aoqi@1 | 167 | |
aoqi@1 | 168 | #endif // _LP64 |
aoqi@1 | 169 | |
aoqi@1 | 170 | |
aoqi@1 | 171 | /* |
aoqi@1 | 172 | // Convert the raw encoding form into the form expected by the constructor for |
aoqi@1 | 173 | // Address. An index of 4 (rsp) corresponds to having no index, so convert |
aoqi@1 | 174 | // that to noreg for the Address constructor. |
aoqi@1 | 175 | Address Address::make_raw(int base, int index, int scale, int disp) { |
aoqi@1 | 176 | bool valid_index = index != rsp->encoding(); |
aoqi@1 | 177 | if (valid_index) { |
aoqi@1 | 178 | Address madr(as_Register(base), as_Register(index), (Address::ScaleFactor)scale, in_ByteSize(disp)); |
aoqi@1 | 179 | return madr; |
aoqi@1 | 180 | } else { |
aoqi@1 | 181 | Address madr(as_Register(base), noreg, Address::no_scale, in_ByteSize(disp)); |
aoqi@1 | 182 | return madr; |
aoqi@1 | 183 | } |
aoqi@1 | 184 | } |
aoqi@1 | 185 | */ |
aoqi@1 | 186 | |
aoqi@1 | 187 | // Implementation of Assembler |
aoqi@1 | 188 | const char *Assembler::ops_name[] = { |
aoqi@1 | 189 | "special", "regimm", "j", "jal", "beq", "bne", "blez", "bgtz", |
aoqi@1 | 190 | "addi", "addiu", "slti", "sltiu", "andi", "ori", "xori", "lui", |
aoqi@1 | 191 | "cop0", "cop1", "cop2", "cop3", "beql", "bnel", "bleql", "bgtzl", |
aoqi@1 | 192 | "daddi", "daddiu", "ldl", "ldr", "", "", "", "", |
aoqi@1 | 193 | "lb", "lh", "lwl", "lw", "lbu", "lhu", "lwr", "lwu", |
aoqi@1 | 194 | "sb", "sh", "swl", "sw", "sdl", "sdr", "swr", "cache", |
aoqi@1 | 195 | "ll", "lwc1", "", "", "lld", "ldc1", "", "ld", |
aoqi@1 | 196 | "sc", "swc1", "", "", "scd", "sdc1", "", "sd" |
aoqi@1 | 197 | }; |
aoqi@1 | 198 | |
aoqi@1 | 199 | const char* Assembler::special_name[] = { |
aoqi@1 | 200 | "sll", "", "srl", "sra", "sllv", "", "srlv", "srav", |
fujie@38 | 201 | "jr", "jalr", "movz", "movn", "syscall", "break", "", "sync", |
aoqi@1 | 202 | "mfhi", "mthi", "mflo", "mtlo", "dsll", "", "dsrl", "dsra", |
aoqi@1 | 203 | "mult", "multu", "div", "divu", "dmult", "dmultu", "ddiv", "ddivu", |
aoqi@1 | 204 | "add", "addu", "sub", "subu", "and", "or", "xor", "nor", |
aoqi@1 | 205 | "", "", "slt", "sltu", "dadd", "daddu", "dsub", "dsubu", |
aoqi@1 | 206 | "tge", "tgeu", "tlt", "tltu", "teq", "", "tne", "", |
aoqi@1 | 207 | "dsll", "", "dsrl", "dsra", "dsll32", "", "dsrl32", "dsra32" |
aoqi@1 | 208 | }; |
aoqi@1 | 209 | |
aoqi@1 | 210 | const char* Assembler::regimm_name[] = { |
aoqi@1 | 211 | "bltz", "bgez", "bltzl", "bgezl", "", "", "", "", |
aoqi@1 | 212 | "tgei", "tgeiu", "tlti", "tltiu", "teqi", "", "tnei", "", |
aoqi@1 | 213 | "bltzal", "bgezal", "bltzall", "bgezall" |
aoqi@1 | 214 | }; |
aoqi@1 | 215 | |
aoqi@1 | 216 | const char* Assembler::float_name[] = { |
aoqi@1 | 217 | "add", "sub", "mul", "div", "sqrt", "abs", "mov", "neg", |
aoqi@1 | 218 | "round.l", "trunc.l", "ceil.l", "floor.l", "round.w", "trunc.w", "ceil.w", "floor.w" |
aoqi@1 | 219 | }; |
aoqi@1 | 220 | |
aoqi@1 | 221 | //misleading name, print only branch/jump instruction |
aoqi@1 | 222 | void Assembler::print_instruction(int inst) { |
aoqi@1 | 223 | const char *s; |
aoqi@1 | 224 | switch( opcode(inst) ) { |
aoqi@1 | 225 | default: |
aoqi@1 | 226 | s = ops_name[opcode(inst)]; |
aoqi@1 | 227 | break; |
aoqi@1 | 228 | case special_op: |
aoqi@1 | 229 | s = special_name[special(inst)]; |
aoqi@1 | 230 | break; |
aoqi@1 | 231 | case regimm_op: |
aoqi@1 | 232 | s = special_name[rt(inst)]; |
aoqi@1 | 233 | break; |
aoqi@1 | 234 | } |
aoqi@1 | 235 | |
aoqi@1 | 236 | ::tty->print("%s", s); |
aoqi@1 | 237 | } |
aoqi@1 | 238 | |
aoqi@1 | 239 | void MacroAssembler::pd_patch_instruction(address branch, address target) { |
aoqi@1 | 240 | jint& stub_inst = *(jint*) branch; |
aoqi@1 | 241 | |
aoqi@1 | 242 | /* * |
aoqi@1 | 243 | move(AT, RA); // dadd |
aoqi@1 | 244 | emit_long(insn_ORRI(regimm_op, 0, bgezal_op, 1)); |
aoqi@1 | 245 | nop(); |
aoqi@1 | 246 | lui(T9, 0); // to be patched |
aoqi@1 | 247 | ori(T9, 0); |
aoqi@1 | 248 | daddu(T9, T9, RA); |
aoqi@1 | 249 | move(RA, AT); |
aoqi@1 | 250 | jr(T9); |
aoqi@1 | 251 | */ |
aoqi@1 | 252 | if(special(stub_inst) == dadd_op) { |
aoqi@1 | 253 | jint *pc = (jint *)branch; |
aoqi@1 | 254 | |
aoqi@1 | 255 | assert(opcode(pc[3]) == lui_op |
aoqi@1 | 256 | && opcode(pc[4]) == ori_op |
aoqi@1 | 257 | && special(pc[5]) == daddu_op, "Not a branch label patch"); |
aoqi@1 | 258 | if(!(opcode(pc[3]) == lui_op |
aoqi@1 | 259 | && opcode(pc[4]) == ori_op |
aoqi@1 | 260 | && special(pc[5]) == daddu_op)) { tty->print_cr("Not a branch label patch"); } |
aoqi@1 | 261 | |
aoqi@1 | 262 | int offset = target - branch; |
aoqi@1 | 263 | if (!is_simm16(offset)) |
aoqi@1 | 264 | { |
aoqi@1 | 265 | pc[3] = (pc[3] & 0xffff0000) | high16(offset - 12); |
aoqi@1 | 266 | pc[4] = (pc[4] & 0xffff0000) | low16(offset - 12); |
aoqi@1 | 267 | } |
aoqi@1 | 268 | else |
aoqi@1 | 269 | { |
aoqi@1 | 270 | /* revert to "beq + nop" */ |
aoqi@1 | 271 | CodeBuffer cb(branch, 4 * 10); |
aoqi@1 | 272 | MacroAssembler masm(&cb); |
aoqi@1 | 273 | #define __ masm. |
aoqi@1 | 274 | __ b(target); |
aoqi@1 | 275 | __ nop(); |
aoqi@1 | 276 | __ nop(); |
aoqi@1 | 277 | __ nop(); |
aoqi@1 | 278 | __ nop(); |
aoqi@1 | 279 | __ nop(); |
aoqi@1 | 280 | __ nop(); |
aoqi@1 | 281 | __ nop(); |
aoqi@1 | 282 | } |
aoqi@1 | 283 | return; |
aoqi@1 | 284 | } |
aoqi@1 | 285 | |
aoqi@1 | 286 | #ifndef PRODUCT |
aoqi@1 | 287 | if (!is_simm16((target - branch - 4) >> 2)) |
aoqi@1 | 288 | { |
aoqi@1 | 289 | tty->print_cr("Illegal patching: target=0x%lx", target); |
aoqi@1 | 290 | int *p = (int *)branch; |
aoqi@1 | 291 | for (int i = -10; i < 10; i++) |
aoqi@1 | 292 | { |
aoqi@1 | 293 | tty->print("0x%lx, ", p[i]); |
aoqi@1 | 294 | } |
aoqi@1 | 295 | tty->print_cr(""); |
aoqi@1 | 296 | } |
aoqi@1 | 297 | #endif |
aoqi@1 | 298 | |
aoqi@1 | 299 | stub_inst = patched_branch(target - branch, stub_inst, 0); |
aoqi@1 | 300 | } |
aoqi@1 | 301 | |
aoqi@1 | 302 | //without check, maybe fixed |
aoqi@1 | 303 | int Assembler::patched_branch(int dest_pos, int inst, int inst_pos) { |
aoqi@1 | 304 | int v = (dest_pos - inst_pos - 4)>>2; |
aoqi@1 | 305 | switch(opcode(inst)) { |
aoqi@1 | 306 | case j_op: |
aoqi@1 | 307 | case jal_op: |
aoqi@1 | 308 | assert(false, "should not use j/jal here"); |
aoqi@1 | 309 | break; |
aoqi@1 | 310 | default: |
aoqi@1 | 311 | assert(is_simm16(v), "must be simm16"); |
aoqi@1 | 312 | #ifndef PRODUCT |
aoqi@1 | 313 | if(!is_simm16(v)) |
aoqi@1 | 314 | { |
aoqi@1 | 315 | tty->print_cr("must be simm16"); |
aoqi@1 | 316 | tty->print_cr("Inst: %lx", inst); |
aoqi@1 | 317 | } |
aoqi@1 | 318 | #endif |
aoqi@1 | 319 | |
aoqi@1 | 320 | v = low16(v); |
aoqi@1 | 321 | inst &= 0xffff0000; |
aoqi@1 | 322 | break; |
aoqi@1 | 323 | } |
aoqi@1 | 324 | |
aoqi@1 | 325 | return inst | v; |
aoqi@1 | 326 | } |
aoqi@1 | 327 | |
aoqi@1 | 328 | int Assembler::branch_destination(int inst, int pos) { |
aoqi@1 | 329 | int off; |
aoqi@1 | 330 | |
aoqi@1 | 331 | switch(opcode(inst)) { |
aoqi@1 | 332 | case j_op: |
aoqi@1 | 333 | case jal_op: |
aoqi@1 | 334 | assert(false, "should not use j/jal here"); |
aoqi@1 | 335 | break; |
aoqi@1 | 336 | default: |
aoqi@1 | 337 | off = expand(low16(inst), 15); |
aoqi@1 | 338 | break; |
aoqi@1 | 339 | } |
aoqi@1 | 340 | |
aoqi@1 | 341 | return off ? pos + 4 + (off<<2) : 0; |
aoqi@1 | 342 | } |
aoqi@1 | 343 | |
aoqi@1 | 344 | int AbstractAssembler::code_fill_byte() { |
aoqi@1 | 345 | return 0x00; // illegal instruction 0x00000000 |
aoqi@1 | 346 | } |
aoqi@1 | 347 | |
aoqi@1 | 348 | // Now the Assembler instruction (identical for 32/64 bits) |
aoqi@1 | 349 | |
aoqi@1 | 350 | void Assembler::lb(Register rt, Address src) { |
aoqi@1 | 351 | lb(rt, src.base(), src.disp()); |
aoqi@1 | 352 | } |
aoqi@1 | 353 | |
aoqi@1 | 354 | void Assembler::lbu(Register rt, Address src) { |
aoqi@1 | 355 | lbu(rt, src.base(), src.disp()); |
aoqi@1 | 356 | } |
aoqi@1 | 357 | |
aoqi@1 | 358 | void Assembler::ld(Register rt, Address src){ |
aoqi@1 | 359 | ld(rt, src.base(), src.disp()); |
aoqi@1 | 360 | } |
aoqi@1 | 361 | |
aoqi@1 | 362 | void Assembler::ldl(Register rt, Address src){ |
aoqi@1 | 363 | ldl(rt, src.base(), src.disp()); |
aoqi@1 | 364 | } |
aoqi@1 | 365 | |
aoqi@1 | 366 | void Assembler::ldr(Register rt, Address src){ |
aoqi@1 | 367 | ldr(rt, src.base(), src.disp()); |
aoqi@1 | 368 | } |
aoqi@1 | 369 | |
aoqi@1 | 370 | void Assembler::lh(Register rt, Address src){ |
aoqi@1 | 371 | lh(rt, src.base(), src.disp()); |
aoqi@1 | 372 | } |
aoqi@1 | 373 | |
aoqi@1 | 374 | void Assembler::lhu(Register rt, Address src){ |
aoqi@1 | 375 | lhu(rt, src.base(), src.disp()); |
aoqi@1 | 376 | } |
aoqi@1 | 377 | |
aoqi@1 | 378 | void Assembler::ll(Register rt, Address src){ |
aoqi@1 | 379 | ll(rt, src.base(), src.disp()); |
aoqi@1 | 380 | } |
aoqi@1 | 381 | |
aoqi@1 | 382 | void Assembler::lld(Register rt, Address src){ |
aoqi@1 | 383 | lld(rt, src.base(), src.disp()); |
aoqi@1 | 384 | } |
aoqi@1 | 385 | |
aoqi@1 | 386 | void Assembler::lw(Register rt, Address src){ |
aoqi@1 | 387 | lw(rt, src.base(), src.disp()); |
aoqi@1 | 388 | } |
aoqi@1 | 389 | void Assembler::lea(Register rt, Address src) { |
aoqi@1 | 390 | #ifdef _LP64 |
aoqi@1 | 391 | daddi(rt, src.base(), src.disp()); |
aoqi@1 | 392 | #else |
aoqi@1 | 393 | addi(rt, src.base(), src.disp()); |
aoqi@1 | 394 | #endif |
aoqi@1 | 395 | } |
aoqi@1 | 396 | |
aoqi@1 | 397 | void Assembler::lwl(Register rt, Address src){ |
aoqi@1 | 398 | lwl(rt, src.base(), src.disp()); |
aoqi@1 | 399 | } |
aoqi@1 | 400 | |
aoqi@1 | 401 | void Assembler::lwr(Register rt, Address src){ |
aoqi@1 | 402 | lwr(rt, src.base(), src.disp()); |
aoqi@1 | 403 | } |
aoqi@1 | 404 | |
aoqi@1 | 405 | void Assembler::lwu(Register rt, Address src){ |
aoqi@1 | 406 | lwu(rt, src.base(), src.disp()); |
aoqi@1 | 407 | } |
aoqi@1 | 408 | |
aoqi@1 | 409 | void Assembler::sb(Register rt, Address dst) { |
aoqi@1 | 410 | sb(rt, dst.base(), dst.disp()); |
aoqi@1 | 411 | } |
aoqi@1 | 412 | |
aoqi@1 | 413 | void Assembler::sc(Register rt, Address dst) { |
aoqi@1 | 414 | sc(rt, dst.base(), dst.disp()); |
aoqi@1 | 415 | } |
aoqi@1 | 416 | |
aoqi@1 | 417 | void Assembler::scd(Register rt, Address dst) { |
aoqi@1 | 418 | scd(rt, dst.base(), dst.disp()); |
aoqi@1 | 419 | } |
aoqi@1 | 420 | |
aoqi@1 | 421 | void Assembler::sd(Register rt, Address dst) { |
aoqi@1 | 422 | sd(rt, dst.base(), dst.disp()); |
aoqi@1 | 423 | } |
aoqi@1 | 424 | |
aoqi@1 | 425 | void Assembler::sdl(Register rt, Address dst) { |
aoqi@1 | 426 | sdl(rt, dst.base(), dst.disp()); |
aoqi@1 | 427 | } |
aoqi@1 | 428 | |
aoqi@1 | 429 | void Assembler::sdr(Register rt, Address dst) { |
aoqi@1 | 430 | sdr(rt, dst.base(), dst.disp()); |
aoqi@1 | 431 | } |
aoqi@1 | 432 | |
aoqi@1 | 433 | void Assembler::sh(Register rt, Address dst) { |
aoqi@1 | 434 | sh(rt, dst.base(), dst.disp()); |
aoqi@1 | 435 | } |
aoqi@1 | 436 | |
aoqi@1 | 437 | void Assembler::sw(Register rt, Address dst) { |
aoqi@1 | 438 | sw(rt, dst.base(), dst.disp()); |
aoqi@1 | 439 | } |
aoqi@1 | 440 | |
aoqi@1 | 441 | void Assembler::swl(Register rt, Address dst) { |
aoqi@1 | 442 | swl(rt, dst.base(), dst.disp()); |
aoqi@1 | 443 | } |
aoqi@1 | 444 | |
aoqi@1 | 445 | void Assembler::swr(Register rt, Address dst) { |
aoqi@1 | 446 | swr(rt, dst.base(), dst.disp()); |
aoqi@1 | 447 | } |
aoqi@1 | 448 | |
aoqi@1 | 449 | void Assembler::lwc1(FloatRegister rt, Address src) { |
aoqi@1 | 450 | lwc1(rt, src.base(), src.disp()); |
aoqi@1 | 451 | } |
aoqi@1 | 452 | |
aoqi@1 | 453 | void Assembler::ldc1(FloatRegister rt, Address src) { |
aoqi@1 | 454 | ldc1(rt, src.base(), src.disp()); |
aoqi@1 | 455 | } |
aoqi@1 | 456 | |
aoqi@1 | 457 | void Assembler::swc1(FloatRegister rt, Address dst) { |
aoqi@1 | 458 | swc1(rt, dst.base(), dst.disp()); |
aoqi@1 | 459 | } |
aoqi@1 | 460 | |
aoqi@1 | 461 | void Assembler::sdc1(FloatRegister rt, Address dst) { |
aoqi@1 | 462 | sdc1(rt, dst.base(), dst.disp()); |
aoqi@1 | 463 | } |
aoqi@1 | 464 | |
aoqi@1 | 465 | void Assembler::j(address entry) { |
aoqi@1 | 466 | int dest = ((intptr_t)entry - (((intptr_t)pc() + 4) & 0xf0000000))>>2; |
aoqi@1 | 467 | emit_long((j_op<<26) | dest); |
aoqi@1 | 468 | has_delay_slot(); |
aoqi@1 | 469 | } |
aoqi@1 | 470 | |
aoqi@1 | 471 | void Assembler::jal(address entry) { |
aoqi@1 | 472 | int dest = ((intptr_t)entry - (((intptr_t)pc() + 4) & 0xf0000000))>>2; |
aoqi@1 | 473 | emit_long((jal_op<<26) | dest); |
aoqi@1 | 474 | has_delay_slot(); |
aoqi@1 | 475 | } |
aoqi@1 | 476 | |
aoqi@1 | 477 | void MacroAssembler::beq_far(Register rs, Register rt, address entry) |
aoqi@1 | 478 | { |
aoqi@1 | 479 | u_char * cur_pc = pc(); |
aoqi@1 | 480 | |
aoqi@1 | 481 | /* Jin: Near/Far jump */ |
aoqi@1 | 482 | if(is_simm16((entry - pc() - 4) / 4)) |
aoqi@1 | 483 | { |
aoqi@1 | 484 | Assembler::beq(rs, rt, offset(entry)); |
aoqi@1 | 485 | } |
aoqi@1 | 486 | else |
aoqi@1 | 487 | { |
aoqi@1 | 488 | Label not_jump; |
aoqi@1 | 489 | bne(rs, rt, not_jump); |
aoqi@1 | 490 | delayed()->nop(); |
aoqi@1 | 491 | |
aoqi@1 | 492 | b_far(entry); |
aoqi@1 | 493 | delayed()->nop(); |
aoqi@1 | 494 | |
aoqi@1 | 495 | bind(not_jump); |
aoqi@1 | 496 | has_delay_slot(); |
aoqi@1 | 497 | } |
aoqi@1 | 498 | } |
aoqi@1 | 499 | |
aoqi@1 | 500 | void MacroAssembler::beq_far(Register rs, Register rt, Label& L) |
aoqi@1 | 501 | { |
aoqi@1 | 502 | if (L.is_bound()) { |
aoqi@1 | 503 | beq_far(rs, rt, target(L)); |
aoqi@1 | 504 | } else { |
aoqi@1 | 505 | u_char * cur_pc = pc(); |
aoqi@1 | 506 | Label not_jump; |
aoqi@1 | 507 | bne(rs, rt, not_jump); |
aoqi@1 | 508 | delayed()->nop(); |
aoqi@1 | 509 | |
aoqi@1 | 510 | b_far(L); |
aoqi@1 | 511 | delayed()->nop(); |
aoqi@1 | 512 | |
aoqi@1 | 513 | bind(not_jump); |
aoqi@1 | 514 | has_delay_slot(); |
aoqi@1 | 515 | } |
aoqi@1 | 516 | } |
aoqi@1 | 517 | |
aoqi@1 | 518 | void MacroAssembler::bne_far(Register rs, Register rt, address entry) |
aoqi@1 | 519 | { |
aoqi@1 | 520 | u_char * cur_pc = pc(); |
aoqi@1 | 521 | |
aoqi@1 | 522 | /* Jin: Near/Far jump */ |
aoqi@1 | 523 | if(is_simm16((entry - pc() - 4) / 4)) |
aoqi@1 | 524 | { |
aoqi@1 | 525 | Assembler::bne(rs, rt, offset(entry)); |
aoqi@1 | 526 | } |
aoqi@1 | 527 | else |
aoqi@1 | 528 | { |
aoqi@1 | 529 | Label not_jump; |
aoqi@1 | 530 | beq(rs, rt, not_jump); |
aoqi@1 | 531 | delayed()->nop(); |
aoqi@1 | 532 | |
aoqi@1 | 533 | b_far(entry); |
aoqi@1 | 534 | delayed()->nop(); |
aoqi@1 | 535 | |
aoqi@1 | 536 | bind(not_jump); |
aoqi@1 | 537 | has_delay_slot(); |
aoqi@1 | 538 | } |
aoqi@1 | 539 | } |
aoqi@1 | 540 | |
aoqi@1 | 541 | void MacroAssembler::bne_far(Register rs, Register rt, Label& L) |
aoqi@1 | 542 | { |
aoqi@1 | 543 | if (L.is_bound()) { |
aoqi@1 | 544 | bne_far(rs, rt, target(L)); |
aoqi@1 | 545 | } else { |
aoqi@1 | 546 | u_char * cur_pc = pc(); |
aoqi@1 | 547 | Label not_jump; |
aoqi@1 | 548 | beq(rs, rt, not_jump); |
aoqi@1 | 549 | delayed()->nop(); |
aoqi@1 | 550 | |
aoqi@1 | 551 | b_far(L); |
aoqi@1 | 552 | delayed()->nop(); |
aoqi@1 | 553 | |
aoqi@1 | 554 | bind(not_jump); |
aoqi@1 | 555 | has_delay_slot(); |
aoqi@1 | 556 | } |
aoqi@1 | 557 | } |
aoqi@1 | 558 | |
aoqi@1 | 559 | void MacroAssembler::b_far(Label& L) |
aoqi@1 | 560 | { |
aoqi@1 | 561 | if (L.is_bound()) { |
aoqi@1 | 562 | b_far(target(L)); |
aoqi@1 | 563 | } else { |
aoqi@1 | 564 | volatile address dest = target(L); |
aoqi@1 | 565 | /* |
aoqi@1 | 566 | MacroAssembler::pd_patch_instruction branch=55651ed514, target=55651ef6d8 |
aoqi@1 | 567 | 0x00000055651ed514: dadd at, ra, zero |
aoqi@1 | 568 | 0x00000055651ed518: [4110001]bgezal zero, 0x00000055651ed520 |
aoqi@1 | 569 | |
aoqi@1 | 570 | 0x00000055651ed51c: sll zero, zero, 0 |
aoqi@1 | 571 | 0x00000055651ed520: lui t9, 0x0 |
aoqi@1 | 572 | 0x00000055651ed524: ori t9, t9, 0x21b8 |
aoqi@1 | 573 | 0x00000055651ed528: daddu t9, t9, ra |
aoqi@1 | 574 | 0x00000055651ed52c: dadd ra, at, zero |
aoqi@1 | 575 | 0x00000055651ed530: jr t9 |
aoqi@1 | 576 | 0x00000055651ed534: sll zero, zero, 0 |
aoqi@1 | 577 | */ |
aoqi@1 | 578 | move(AT, RA); |
aoqi@1 | 579 | emit_long(insn_ORRI(regimm_op, 0, bgezal_op, 1)); |
aoqi@1 | 580 | nop(); |
aoqi@1 | 581 | lui(T9, 0); // to be patched |
aoqi@1 | 582 | ori(T9, T9, 0); |
aoqi@1 | 583 | daddu(T9, T9, RA); |
aoqi@1 | 584 | move(RA, AT); |
aoqi@1 | 585 | jr(T9); |
aoqi@1 | 586 | } |
aoqi@1 | 587 | } |
aoqi@1 | 588 | |
aoqi@1 | 589 | void MacroAssembler::b_far(address entry) |
aoqi@1 | 590 | { |
aoqi@1 | 591 | u_char * cur_pc = pc(); |
aoqi@1 | 592 | |
aoqi@1 | 593 | /* Jin: Near/Far jump */ |
aoqi@1 | 594 | if(is_simm16((entry - pc() - 4) / 4)) |
aoqi@1 | 595 | { |
aoqi@1 | 596 | b(offset(entry)); |
aoqi@1 | 597 | } |
aoqi@1 | 598 | else |
aoqi@1 | 599 | { |
aoqi@1 | 600 | /* address must be bounded */ |
aoqi@1 | 601 | move(AT, RA); |
aoqi@1 | 602 | emit_long(insn_ORRI(regimm_op, 0, bgezal_op, 1)); |
aoqi@1 | 603 | nop(); |
aoqi@1 | 604 | li32(T9, entry - pc()); |
aoqi@1 | 605 | daddu(T9, T9, RA); |
aoqi@1 | 606 | move(RA, AT); |
aoqi@1 | 607 | jr(T9); |
aoqi@1 | 608 | } |
aoqi@1 | 609 | } |
aoqi@1 | 610 | |
aoqi@1 | 611 | // Implementation of MacroAssembler |
aoqi@1 | 612 | |
aoqi@1 | 613 | // First all the versions that have distinct versions depending on 32/64 bit |
aoqi@1 | 614 | // Unless the difference is trivial (1 line or so). |
aoqi@1 | 615 | |
aoqi@1 | 616 | //#ifndef _LP64 |
aoqi@1 | 617 | |
aoqi@1 | 618 | // 32bit versions |
aoqi@1 | 619 | |
aoqi@1 | 620 | void MacroAssembler::ld_ptr(Register rt, Register offset, Register base) { |
aoqi@1 | 621 | addu_long(AT, base, offset); |
aoqi@1 | 622 | ld_ptr(rt, 0, AT); |
aoqi@1 | 623 | } |
aoqi@1 | 624 | |
aoqi@1 | 625 | void MacroAssembler::st_ptr(Register rt, Register offset, Register base) { |
aoqi@1 | 626 | addu_long(AT, base, offset); |
aoqi@1 | 627 | st_ptr(rt, 0, AT); |
aoqi@1 | 628 | } |
aoqi@1 | 629 | |
aoqi@1 | 630 | void MacroAssembler::ld_long(Register rt, Register offset, Register base) { |
aoqi@1 | 631 | addu_long(AT, base, offset); |
aoqi@1 | 632 | ld_long(rt, 0, AT); |
aoqi@1 | 633 | } |
aoqi@1 | 634 | |
aoqi@1 | 635 | void MacroAssembler::st_long(Register rt, Register offset, Register base) { |
aoqi@1 | 636 | addu_long(AT, base, offset); |
aoqi@1 | 637 | st_long(rt, 0, AT); |
aoqi@1 | 638 | } |
aoqi@1 | 639 | |
aoqi@1 | 640 | Address MacroAssembler::as_Address(AddressLiteral adr) { |
aoqi@1 | 641 | return Address(adr.target(), adr.rspec()); |
aoqi@1 | 642 | } |
aoqi@1 | 643 | |
aoqi@1 | 644 | Address MacroAssembler::as_Address(ArrayAddress adr) { |
aoqi@1 | 645 | return Address::make_array(adr); |
aoqi@1 | 646 | } |
aoqi@1 | 647 | |
aoqi@29 | 648 | // tmp_reg1 and tmp_reg2 should be saved outside of atomic_inc32 (caller saved). |
aoqi@29 | 649 | void MacroAssembler::atomic_inc32(address counter_addr, int inc, Register tmp_reg1, Register tmp_reg2) { |
aoqi@29 | 650 | Label again; |
aoqi@29 | 651 | |
aoqi@29 | 652 | bind(again); |
aoqi@29 | 653 | sync(); |
aoqi@29 | 654 | li(tmp_reg1, counter_addr); |
aoqi@29 | 655 | ll(tmp_reg2, tmp_reg1, 0); |
aoqi@29 | 656 | addi(tmp_reg2, tmp_reg2, inc); |
aoqi@29 | 657 | sc(tmp_reg2, tmp_reg1, 0); |
aoqi@29 | 658 | beq(tmp_reg2, R0, again); |
aoqi@29 | 659 | delayed()->nop(); |
aoqi@29 | 660 | } |
aoqi@1 | 661 | int MacroAssembler::biased_locking_enter(Register lock_reg, |
aoqi@1 | 662 | Register obj_reg, |
aoqi@1 | 663 | Register swap_reg, |
aoqi@1 | 664 | Register tmp_reg, |
aoqi@1 | 665 | bool swap_reg_contains_mark, |
aoqi@1 | 666 | Label& done, |
aoqi@1 | 667 | Label* slow_case, |
aoqi@1 | 668 | BiasedLockingCounters* counters) { |
aoqi@1 | 669 | assert(UseBiasedLocking, "why call this otherwise?"); |
aoqi@1 | 670 | bool need_tmp_reg = false; |
aoqi@1 | 671 | if (tmp_reg == noreg) { |
aoqi@1 | 672 | need_tmp_reg = true; |
aoqi@18 | 673 | tmp_reg = T9; |
aoqi@1 | 674 | } |
aoqi@18 | 675 | assert_different_registers(lock_reg, obj_reg, swap_reg, tmp_reg, AT); |
aoqi@1 | 676 | assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout"); |
aoqi@1 | 677 | Address mark_addr (obj_reg, oopDesc::mark_offset_in_bytes()); |
aoqi@1 | 678 | Address saved_mark_addr(lock_reg, 0); |
aoqi@1 | 679 | |
aoqi@1 | 680 | // Biased locking |
aoqi@1 | 681 | // See whether the lock is currently biased toward our thread and |
aoqi@1 | 682 | // whether the epoch is still valid |
aoqi@1 | 683 | // Note that the runtime guarantees sufficient alignment of JavaThread |
aoqi@1 | 684 | // pointers to allow age to be placed into low bits |
aoqi@1 | 685 | // First check to see whether biasing is even enabled for this object |
aoqi@1 | 686 | Label cas_label; |
aoqi@1 | 687 | int null_check_offset = -1; |
aoqi@1 | 688 | if (!swap_reg_contains_mark) { |
aoqi@1 | 689 | null_check_offset = offset(); |
aoqi@1 | 690 | ld_ptr(swap_reg, mark_addr); |
aoqi@1 | 691 | } |
aoqi@1 | 692 | |
aoqi@1 | 693 | if (need_tmp_reg) { |
aoqi@1 | 694 | push(tmp_reg); |
aoqi@1 | 695 | } |
aoqi@1 | 696 | move(tmp_reg, swap_reg); |
aoqi@1 | 697 | andi(tmp_reg, tmp_reg, markOopDesc::biased_lock_mask_in_place); |
aoqi@1 | 698 | #ifdef _LP64 |
aoqi@31 | 699 | daddi(AT, R0, markOopDesc::biased_lock_pattern); |
aoqi@1 | 700 | dsub(AT, AT, tmp_reg); |
aoqi@1 | 701 | #else |
aoqi@31 | 702 | addi(AT, R0, markOopDesc::biased_lock_pattern); |
aoqi@1 | 703 | sub(AT, AT, tmp_reg); |
aoqi@1 | 704 | #endif |
aoqi@1 | 705 | if (need_tmp_reg) { |
aoqi@1 | 706 | pop(tmp_reg); |
aoqi@1 | 707 | } |
aoqi@1 | 708 | |
aoqi@1 | 709 | bne(AT, R0, cas_label); |
aoqi@1 | 710 | delayed()->nop(); |
aoqi@1 | 711 | |
aoqi@1 | 712 | |
aoqi@1 | 713 | // The bias pattern is present in the object's header. Need to check |
aoqi@1 | 714 | // whether the bias owner and the epoch are both still current. |
aoqi@31 | 715 | // Note that because there is no current thread register on MIPS we |
aoqi@1 | 716 | // need to store off the mark word we read out of the object to |
aoqi@1 | 717 | // avoid reloading it and needing to recheck invariants below. This |
aoqi@1 | 718 | // store is unfortunate but it makes the overall code shorter and |
aoqi@1 | 719 | // simpler. |
aoqi@31 | 720 | st_ptr(swap_reg, saved_mark_addr); |
aoqi@1 | 721 | if (need_tmp_reg) { |
aoqi@1 | 722 | push(tmp_reg); |
aoqi@1 | 723 | } |
aoqi@1 | 724 | if (swap_reg_contains_mark) { |
aoqi@1 | 725 | null_check_offset = offset(); |
aoqi@1 | 726 | } |
aoqi@1 | 727 | load_prototype_header(tmp_reg, obj_reg); |
aoqi@31 | 728 | xorr(tmp_reg, tmp_reg, swap_reg); |
aoqi@31 | 729 | get_thread(swap_reg); |
aoqi@31 | 730 | xorr(swap_reg, swap_reg, tmp_reg); |
aoqi@31 | 731 | |
aoqi@31 | 732 | move(AT, ~((int) markOopDesc::age_mask_in_place)); |
aoqi@31 | 733 | andr(swap_reg, swap_reg, AT); |
aoqi@1 | 734 | |
aoqi@29 | 735 | if (PrintBiasedLockingStatistics) { |
aoqi@29 | 736 | Label L; |
aoqi@29 | 737 | bne(swap_reg, R0, L); |
aoqi@29 | 738 | delayed()->nop(); |
aoqi@29 | 739 | atomic_inc32((address)BiasedLocking::biased_lock_entry_count_addr(), 1, AT, tmp_reg); |
aoqi@29 | 740 | bind(L); |
aoqi@29 | 741 | } |
aoqi@1 | 742 | if (need_tmp_reg) { |
aoqi@1 | 743 | pop(tmp_reg); |
aoqi@1 | 744 | } |
aoqi@31 | 745 | beq(swap_reg, R0, done); |
aoqi@1 | 746 | delayed()->nop(); |
aoqi@1 | 747 | Label try_revoke_bias; |
aoqi@1 | 748 | Label try_rebias; |
aoqi@1 | 749 | |
aoqi@1 | 750 | // At this point we know that the header has the bias pattern and |
aoqi@1 | 751 | // that we are not the bias owner in the current epoch. We need to |
aoqi@1 | 752 | // figure out more details about the state of the header in order to |
aoqi@1 | 753 | // know what operations can be legally performed on the object's |
aoqi@1 | 754 | // header. |
aoqi@1 | 755 | |
aoqi@1 | 756 | // If the low three bits in the xor result aren't clear, that means |
aoqi@1 | 757 | // the prototype header is no longer biased and we have to revoke |
aoqi@1 | 758 | // the bias on this object. |
aoqi@1 | 759 | |
aoqi@31 | 760 | move(AT, markOopDesc::biased_lock_mask_in_place); |
aoqi@31 | 761 | andr(AT, swap_reg, AT); |
aoqi@31 | 762 | bne(AT, R0, try_revoke_bias); |
aoqi@1 | 763 | delayed()->nop(); |
aoqi@1 | 764 | // Biasing is still enabled for this data type. See whether the |
aoqi@1 | 765 | // epoch of the current bias is still valid, meaning that the epoch |
aoqi@1 | 766 | // bits of the mark word are equal to the epoch bits of the |
aoqi@1 | 767 | // prototype header. (Note that the prototype header's epoch bits |
aoqi@1 | 768 | // only change at a safepoint.) If not, attempt to rebias the object |
aoqi@1 | 769 | // toward the current thread. Note that we must be absolutely sure |
aoqi@1 | 770 | // that the current epoch is invalid in order to do this because |
aoqi@1 | 771 | // otherwise the manipulations it performs on the mark word are |
aoqi@1 | 772 | // illegal. |
aoqi@1 | 773 | |
aoqi@1 | 774 | move(AT, markOopDesc::epoch_mask_in_place); |
aoqi@31 | 775 | andr(AT,swap_reg, AT); |
aoqi@31 | 776 | bne(AT, R0, try_rebias); |
aoqi@1 | 777 | delayed()->nop(); |
aoqi@1 | 778 | // The epoch of the current bias is still valid but we know nothing |
aoqi@1 | 779 | // about the owner; it might be set or it might be clear. Try to |
aoqi@1 | 780 | // acquire the bias of the object using an atomic operation. If this |
aoqi@1 | 781 | // fails we will go in to the runtime to revoke the object's bias. |
aoqi@1 | 782 | // Note that we first construct the presumed unbiased header so we |
aoqi@1 | 783 | // don't accidentally blow away another thread's valid bias. |
aoqi@1 | 784 | |
aoqi@1 | 785 | ld_ptr(swap_reg, saved_mark_addr); |
aoqi@1 | 786 | |
aoqi@1 | 787 | move(AT, markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place); |
aoqi@31 | 788 | andr(swap_reg, swap_reg, AT); |
aoqi@1 | 789 | |
aoqi@1 | 790 | if (need_tmp_reg) { |
aoqi@1 | 791 | push(tmp_reg); |
aoqi@1 | 792 | } |
aoqi@1 | 793 | get_thread(tmp_reg); |
aoqi@31 | 794 | orr(tmp_reg, tmp_reg, swap_reg); |
aoqi@1 | 795 | //if (os::is_MP()) { |
aoqi@1 | 796 | // lock(); |
aoqi@31 | 797 | //} |
aoqi@31 | 798 | cmpxchg(tmp_reg, Address(obj_reg, 0), swap_reg); |
aoqi@1 | 799 | if (need_tmp_reg) { |
aoqi@1 | 800 | pop(tmp_reg); |
aoqi@1 | 801 | } |
aoqi@1 | 802 | // If the biasing toward our thread failed, this means that |
aoqi@1 | 803 | // another thread succeeded in biasing it toward itself and we |
aoqi@1 | 804 | // need to revoke that bias. The revocation will occur in the |
aoqi@1 | 805 | // interpreter runtime in the slow case. |
aoqi@1 | 806 | if (PrintBiasedLockingStatistics) { |
aoqi@29 | 807 | Label L; |
aoqi@29 | 808 | bne(AT, R0, L); |
aoqi@29 | 809 | delayed()->nop(); |
aoqi@29 | 810 | push(tmp_reg); |
aoqi@29 | 811 | push(A0); |
aoqi@29 | 812 | atomic_inc32((address)BiasedLocking::anonymously_biased_lock_entry_count_addr(), 1, A0, tmp_reg); |
aoqi@29 | 813 | pop(A0); |
aoqi@29 | 814 | pop(tmp_reg); |
aoqi@29 | 815 | bind(L); |
aoqi@1 | 816 | } |
aoqi@1 | 817 | if (slow_case != NULL) { |
aoqi@31 | 818 | beq_far(AT, R0, *slow_case); |
aoqi@1 | 819 | delayed()->nop(); |
aoqi@1 | 820 | } |
aoqi@1 | 821 | b(done); |
aoqi@1 | 822 | delayed()->nop(); |
aoqi@1 | 823 | |
aoqi@1 | 824 | bind(try_rebias); |
aoqi@1 | 825 | // At this point we know the epoch has expired, meaning that the |
aoqi@1 | 826 | // current "bias owner", if any, is actually invalid. Under these |
aoqi@1 | 827 | // circumstances _only_, we are allowed to use the current header's |
aoqi@1 | 828 | // value as the comparison value when doing the cas to acquire the |
aoqi@1 | 829 | // bias in the current epoch. In other words, we allow transfer of |
aoqi@1 | 830 | // the bias from one thread to another directly in this situation. |
aoqi@1 | 831 | // |
aoqi@1 | 832 | // FIXME: due to a lack of registers we currently blow away the age |
aoqi@1 | 833 | // bits in this situation. Should attempt to preserve them. |
aoqi@1 | 834 | if (need_tmp_reg) { |
aoqi@1 | 835 | push(tmp_reg); |
aoqi@1 | 836 | } |
aoqi@31 | 837 | load_prototype_header(tmp_reg, obj_reg); |
aoqi@31 | 838 | get_thread(swap_reg); |
aoqi@31 | 839 | orr(tmp_reg, tmp_reg, swap_reg); |
aoqi@1 | 840 | ld_ptr(swap_reg, saved_mark_addr); |
aoqi@1 | 841 | |
aoqi@1 | 842 | // if (os::is_MP()) { |
aoqi@1 | 843 | // lock(); |
aoqi@31 | 844 | //} |
aoqi@31 | 845 | cmpxchg(tmp_reg, Address(obj_reg, 0), swap_reg); |
aoqi@1 | 846 | if (need_tmp_reg) { |
aoqi@1 | 847 | pop(tmp_reg); |
aoqi@1 | 848 | } |
aoqi@1 | 849 | // If the biasing toward our thread failed, then another thread |
aoqi@1 | 850 | // succeeded in biasing it toward itself and we need to revoke that |
aoqi@1 | 851 | // bias. The revocation will occur in the runtime in the slow case. |
aoqi@1 | 852 | if (PrintBiasedLockingStatistics) { |
aoqi@29 | 853 | Label L; |
aoqi@29 | 854 | bne(AT, R0, L); |
aoqi@29 | 855 | delayed()->nop(); |
aoqi@29 | 856 | push(AT); |
aoqi@29 | 857 | push(tmp_reg); |
aoqi@29 | 858 | atomic_inc32((address)BiasedLocking::rebiased_lock_entry_count_addr(), 1, AT, tmp_reg); |
aoqi@29 | 859 | pop(tmp_reg); |
aoqi@29 | 860 | pop(AT); |
aoqi@29 | 861 | bind(L); |
aoqi@1 | 862 | } |
aoqi@1 | 863 | if (slow_case != NULL) { |
aoqi@31 | 864 | beq_far(AT, R0, *slow_case); |
aoqi@1 | 865 | delayed()->nop(); |
aoqi@1 | 866 | } |
aoqi@1 | 867 | |
aoqi@1 | 868 | b(done); |
aoqi@1 | 869 | delayed()->nop(); |
aoqi@1 | 870 | bind(try_revoke_bias); |
aoqi@1 | 871 | // The prototype mark in the klass doesn't have the bias bit set any |
aoqi@1 | 872 | // more, indicating that objects of this data type are not supposed |
aoqi@1 | 873 | // to be biased any more. We are going to try to reset the mark of |
aoqi@1 | 874 | // this object to the prototype value and fall through to the |
aoqi@1 | 875 | // CAS-based locking scheme. Note that if our CAS fails, it means |
aoqi@1 | 876 | // that another thread raced us for the privilege of revoking the |
aoqi@1 | 877 | // bias of this particular object, so it's okay to continue in the |
aoqi@1 | 878 | // normal locking code. |
aoqi@1 | 879 | // |
aoqi@1 | 880 | // FIXME: due to a lack of registers we currently blow away the age |
aoqi@1 | 881 | // bits in this situation. Should attempt to preserve them. |
aoqi@1 | 882 | ld_ptr(swap_reg, saved_mark_addr); |
aoqi@1 | 883 | |
aoqi@1 | 884 | if (need_tmp_reg) { |
aoqi@1 | 885 | push(tmp_reg); |
aoqi@1 | 886 | } |
aoqi@1 | 887 | load_prototype_header(tmp_reg, obj_reg); |
aoqi@1 | 888 | //if (os::is_MP()) { |
aoqi@1 | 889 | // lock(); |
aoqi@1 | 890 | //} |
aoqi@31 | 891 | cmpxchg(tmp_reg, Address(obj_reg, 0), swap_reg); |
aoqi@1 | 892 | if (need_tmp_reg) { |
aoqi@1 | 893 | pop(tmp_reg); |
aoqi@1 | 894 | } |
aoqi@1 | 895 | // Fall through to the normal CAS-based lock, because no matter what |
aoqi@1 | 896 | // the result of the above CAS, some thread must have succeeded in |
aoqi@1 | 897 | // removing the bias bit from the object's header. |
aoqi@1 | 898 | if (PrintBiasedLockingStatistics) { |
aoqi@29 | 899 | Label L; |
aoqi@29 | 900 | bne(AT, R0, L); |
aoqi@29 | 901 | delayed()->nop(); |
aoqi@29 | 902 | push(AT); |
aoqi@29 | 903 | push(tmp_reg); |
aoqi@29 | 904 | atomic_inc32((address)BiasedLocking::revoked_lock_entry_count_addr(), 1, AT, tmp_reg); |
aoqi@29 | 905 | pop(tmp_reg); |
aoqi@29 | 906 | pop(AT); |
aoqi@29 | 907 | bind(L); |
aoqi@1 | 908 | } |
aoqi@1 | 909 | |
aoqi@1 | 910 | bind(cas_label); |
aoqi@1 | 911 | return null_check_offset; |
aoqi@1 | 912 | } |
aoqi@1 | 913 | |
aoqi@1 | 914 | void MacroAssembler::biased_locking_exit(Register obj_reg, Register temp_reg, Label& done) { |
aoqi@1 | 915 | assert(UseBiasedLocking, "why call this otherwise?"); |
aoqi@1 | 916 | |
aoqi@1 | 917 | // Check for biased locking unlock case, which is a no-op |
aoqi@1 | 918 | // Note: we do not have to check the thread ID for two reasons. |
aoqi@1 | 919 | // First, the interpreter checks for IllegalMonitorStateException at |
aoqi@1 | 920 | // a higher level. Second, if the bias was revoked while we held the |
aoqi@1 | 921 | // lock, the object could not be rebiased toward another thread, so |
aoqi@1 | 922 | // the bias bit would be clear. |
aoqi@1 | 923 | #ifdef _LP64 |
aoqi@1 | 924 | ld(temp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes())); |
aoqi@1 | 925 | andi(temp_reg, temp_reg, markOopDesc::biased_lock_mask_in_place); |
aoqi@1 | 926 | daddi(AT, R0, markOopDesc::biased_lock_pattern); |
aoqi@1 | 927 | #else |
aoqi@1 | 928 | lw(temp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes())); |
aoqi@1 | 929 | andi(temp_reg, temp_reg, markOopDesc::biased_lock_mask_in_place); |
aoqi@1 | 930 | addi(AT, R0, markOopDesc::biased_lock_pattern); |
aoqi@1 | 931 | #endif |
aoqi@1 | 932 | |
aoqi@1 | 933 | beq(AT, temp_reg, done); |
aoqi@1 | 934 | delayed()->nop(); |
aoqi@1 | 935 | } |
aoqi@1 | 936 | |
aoqi@1 | 937 | // NOTE: we dont increment the SP after call like the x86 version, maybe this is a problem, FIXME. |
aoqi@1 | 938 | // by yjl 6/27/2005 |
aoqi@1 | 939 | // the stack pointer adjustment is needed. see InterpreterMacroAssembler::super_call_VM_leaf |
aoqi@1 | 940 | // by yjl 7/11/2005 |
aoqi@1 | 941 | // this method will handle the stack problem, you need not to preserve the stack space for the argument now |
aoqi@1 | 942 | // by yjl 8/1/2005 |
aoqi@1 | 943 | void MacroAssembler::call_VM_leaf_base(address entry_point, |
aoqi@1 | 944 | int number_of_arguments) { |
aoqi@1 | 945 | //call(RuntimeAddress(entry_point)); |
aoqi@1 | 946 | //increment(rsp, number_of_arguments * wordSize); |
aoqi@1 | 947 | Label L, E; |
aoqi@1 | 948 | |
aoqi@1 | 949 | assert(number_of_arguments <= 4, "just check"); |
aoqi@1 | 950 | |
aoqi@1 | 951 | andi(AT, SP, 0xf); |
aoqi@1 | 952 | beq(AT, R0, L); |
aoqi@1 | 953 | delayed()->nop(); |
aoqi@1 | 954 | daddi(SP, SP, -8); |
aoqi@1 | 955 | { |
aoqi@1 | 956 | call(entry_point, relocInfo::runtime_call_type); |
aoqi@1 | 957 | delayed()->nop(); |
aoqi@1 | 958 | } |
aoqi@1 | 959 | daddi(SP, SP, 8); |
aoqi@1 | 960 | b(E); |
aoqi@1 | 961 | delayed()->nop(); |
aoqi@1 | 962 | |
aoqi@1 | 963 | bind(L); |
aoqi@1 | 964 | { |
aoqi@1 | 965 | call(entry_point, relocInfo::runtime_call_type); |
aoqi@1 | 966 | delayed()->nop(); |
aoqi@1 | 967 | } |
aoqi@1 | 968 | bind(E); |
aoqi@1 | 969 | } |
aoqi@1 | 970 | |
aoqi@1 | 971 | |
aoqi@1 | 972 | void MacroAssembler::jmp(address entry) { |
aoqi@1 | 973 | li48(T9, (long)entry); |
aoqi@1 | 974 | jr(T9); |
aoqi@1 | 975 | } |
aoqi@1 | 976 | |
aoqi@1 | 977 | void MacroAssembler::jmp(address entry, relocInfo::relocType rtype) { |
aoqi@1 | 978 | switch (rtype) { |
aoqi@1 | 979 | case relocInfo::runtime_call_type: |
aoqi@1 | 980 | case relocInfo::none: |
aoqi@1 | 981 | jmp(entry); |
aoqi@1 | 982 | break; |
aoqi@1 | 983 | default: |
aoqi@1 | 984 | { |
aoqi@1 | 985 | InstructionMark im(this); |
aoqi@1 | 986 | relocate(rtype); |
aoqi@1 | 987 | li48(T9, (long)entry); |
aoqi@1 | 988 | jr(T9); |
aoqi@1 | 989 | } |
aoqi@1 | 990 | break; |
aoqi@1 | 991 | } |
aoqi@1 | 992 | } |
aoqi@1 | 993 | |
aoqi@1 | 994 | void MacroAssembler::call(address entry) { |
aoqi@1 | 995 | // c/c++ code assume T9 is entry point, so we just always move entry to t9 |
aoqi@1 | 996 | // maybe there is some more graceful method to handle this. FIXME |
aoqi@1 | 997 | // by yjl 6/27/2005 |
aoqi@1 | 998 | // For more info, see class NativeCall. |
aoqi@1 | 999 | #ifndef _LP64 |
aoqi@1 | 1000 | move(T9, (int)entry); |
aoqi@1 | 1001 | #else |
aoqi@1 | 1002 | li48(T9, (long)entry); |
aoqi@1 | 1003 | #endif |
aoqi@1 | 1004 | jalr(T9); |
aoqi@1 | 1005 | } |
aoqi@1 | 1006 | |
aoqi@1 | 1007 | void MacroAssembler::call(address entry, relocInfo::relocType rtype) { |
aoqi@1 | 1008 | switch (rtype) { |
aoqi@1 | 1009 | case relocInfo::runtime_call_type: |
aoqi@1 | 1010 | case relocInfo::none: |
aoqi@1 | 1011 | call(entry); |
aoqi@1 | 1012 | break; |
aoqi@1 | 1013 | default: |
aoqi@1 | 1014 | { |
aoqi@1 | 1015 | InstructionMark im(this); |
aoqi@1 | 1016 | relocate(rtype); |
aoqi@1 | 1017 | call(entry); |
aoqi@1 | 1018 | } |
aoqi@1 | 1019 | break; |
aoqi@1 | 1020 | } |
aoqi@1 | 1021 | } |
aoqi@1 | 1022 | |
aoqi@1 | 1023 | void MacroAssembler::call(address entry, RelocationHolder& rh) |
aoqi@1 | 1024 | { |
aoqi@1 | 1025 | switch (rh.type()) { |
aoqi@1 | 1026 | case relocInfo::runtime_call_type: |
aoqi@1 | 1027 | case relocInfo::none: |
aoqi@1 | 1028 | call(entry); |
aoqi@1 | 1029 | break; |
aoqi@1 | 1030 | default: |
aoqi@1 | 1031 | { |
aoqi@1 | 1032 | InstructionMark im(this); |
aoqi@1 | 1033 | relocate(rh); |
aoqi@1 | 1034 | call(entry); |
aoqi@1 | 1035 | } |
aoqi@1 | 1036 | break; |
aoqi@1 | 1037 | } |
aoqi@1 | 1038 | } |
aoqi@1 | 1039 | |
aoqi@1 | 1040 | void MacroAssembler::ic_call(address entry) { |
aoqi@1 | 1041 | RelocationHolder rh = virtual_call_Relocation::spec(pc()); |
aoqi@1 | 1042 | li64(IC_Klass, (long)Universe::non_oop_word()); |
aoqi@1 | 1043 | assert(entry != NULL, "call most probably wrong"); |
aoqi@1 | 1044 | InstructionMark im(this); |
aoqi@1 | 1045 | relocate(rh); |
aoqi@1 | 1046 | li48(T9, (long)entry); |
aoqi@1 | 1047 | jalr(T9); |
aoqi@1 | 1048 | delayed()->nop(); |
aoqi@1 | 1049 | } |
aoqi@1 | 1050 | |
aoqi@1 | 1051 | void MacroAssembler::c2bool(Register r) { |
aoqi@1 | 1052 | Label L; |
aoqi@1 | 1053 | Assembler::beq(r, R0, L); |
aoqi@1 | 1054 | delayed()->nop(); |
aoqi@1 | 1055 | move(r, 1); |
aoqi@1 | 1056 | bind(L); |
aoqi@1 | 1057 | } |
aoqi@1 | 1058 | |
aoqi@1 | 1059 | #ifndef PRODUCT |
aoqi@1 | 1060 | extern "C" void findpc(intptr_t x); |
aoqi@1 | 1061 | #endif |
aoqi@1 | 1062 | |
aoqi@1 | 1063 | void MacroAssembler::debug32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg) { |
aoqi@1 | 1064 | // In order to get locks to work, we need to fake a in_VM state |
aoqi@1 | 1065 | JavaThread* thread = JavaThread::current(); |
aoqi@1 | 1066 | JavaThreadState saved_state = thread->thread_state(); |
aoqi@1 | 1067 | thread->set_thread_state(_thread_in_vm); |
aoqi@1 | 1068 | if (ShowMessageBoxOnError) { |
aoqi@1 | 1069 | JavaThread* thread = JavaThread::current(); |
aoqi@1 | 1070 | JavaThreadState saved_state = thread->thread_state(); |
aoqi@1 | 1071 | thread->set_thread_state(_thread_in_vm); |
aoqi@1 | 1072 | if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { |
aoqi@1 | 1073 | ttyLocker ttyl; |
aoqi@1 | 1074 | BytecodeCounter::print(); |
aoqi@1 | 1075 | } |
aoqi@1 | 1076 | // To see where a verify_oop failed, get $ebx+40/X for this frame. |
aoqi@1 | 1077 | // This is the value of eip which points to where verify_oop will return. |
aoqi@1 | 1078 | if (os::message_box(msg, "Execution stopped, print registers?")) { |
aoqi@1 | 1079 | ttyLocker ttyl; |
aoqi@1 | 1080 | tty->print_cr("eip = 0x%08x", eip); |
aoqi@1 | 1081 | #ifndef PRODUCT |
aoqi@1 | 1082 | tty->cr(); |
aoqi@1 | 1083 | findpc(eip); |
aoqi@1 | 1084 | tty->cr(); |
aoqi@1 | 1085 | #endif |
aoqi@1 | 1086 | tty->print_cr("rax, = 0x%08x", rax); |
aoqi@1 | 1087 | tty->print_cr("rbx, = 0x%08x", rbx); |
aoqi@1 | 1088 | tty->print_cr("rcx = 0x%08x", rcx); |
aoqi@1 | 1089 | tty->print_cr("rdx = 0x%08x", rdx); |
aoqi@1 | 1090 | tty->print_cr("rdi = 0x%08x", rdi); |
aoqi@1 | 1091 | tty->print_cr("rsi = 0x%08x", rsi); |
aoqi@1 | 1092 | tty->print_cr("rbp, = 0x%08x", rbp); |
aoqi@1 | 1093 | tty->print_cr("rsp = 0x%08x", rsp); |
aoqi@1 | 1094 | BREAKPOINT; |
aoqi@1 | 1095 | } |
aoqi@1 | 1096 | } else { |
aoqi@1 | 1097 | ttyLocker ttyl; |
aoqi@1 | 1098 | ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg); |
aoqi@1 | 1099 | assert(false, "DEBUG MESSAGE"); |
aoqi@1 | 1100 | } |
aoqi@1 | 1101 | ThreadStateTransition::transition(thread, _thread_in_vm, saved_state); |
aoqi@1 | 1102 | } |
aoqi@1 | 1103 | |
aoqi@1 | 1104 | void MacroAssembler::debug(char* msg/*, RegistersForDebugging* regs*/) { |
aoqi@1 | 1105 | if ( ShowMessageBoxOnError ) { |
aoqi@1 | 1106 | JavaThreadState saved_state = JavaThread::current()->thread_state(); |
aoqi@1 | 1107 | JavaThread::current()->set_thread_state(_thread_in_vm); |
aoqi@1 | 1108 | { |
aoqi@1 | 1109 | // In order to get locks work, we need to fake a in_VM state |
aoqi@1 | 1110 | ttyLocker ttyl; |
aoqi@1 | 1111 | ::tty->print_cr("EXECUTION STOPPED: %s\n", msg); |
aoqi@1 | 1112 | if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { |
aoqi@1 | 1113 | BytecodeCounter::print(); |
aoqi@1 | 1114 | } |
aoqi@1 | 1115 | |
aoqi@1 | 1116 | // if (os::message_box(msg, "Execution stopped, print registers?")) |
aoqi@1 | 1117 | // regs->print(::tty); |
aoqi@1 | 1118 | } |
aoqi@1 | 1119 | ThreadStateTransition::transition(JavaThread::current(), _thread_in_vm, saved_state); |
aoqi@1 | 1120 | } |
aoqi@1 | 1121 | else |
aoqi@1 | 1122 | ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg); |
aoqi@1 | 1123 | } |
aoqi@1 | 1124 | |
aoqi@1 | 1125 | |
aoqi@1 | 1126 | void MacroAssembler::stop(const char* msg) { |
aoqi@1 | 1127 | li(A0, (long)msg); |
aoqi@1 | 1128 | #ifndef _LP64 |
aoqi@1 | 1129 | //reserver space for argument. added by yjl 7/10/2005 |
aoqi@1 | 1130 | addiu(SP, SP, - 1 * wordSize); |
aoqi@1 | 1131 | #endif |
aoqi@1 | 1132 | call(CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); |
aoqi@1 | 1133 | delayed()->nop(); |
aoqi@1 | 1134 | #ifndef _LP64 |
aoqi@1 | 1135 | //restore space for argument |
aoqi@1 | 1136 | addiu(SP, SP, 1 * wordSize); |
aoqi@1 | 1137 | #endif |
aoqi@1 | 1138 | brk(17); |
aoqi@1 | 1139 | } |
aoqi@1 | 1140 | |
aoqi@1 | 1141 | void MacroAssembler::warn(const char* msg) { |
aoqi@1 | 1142 | #ifdef _LP64 |
aoqi@1 | 1143 | pushad(); |
aoqi@1 | 1144 | li(A0, (long)msg); |
aoqi@1 | 1145 | call(CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); |
aoqi@1 | 1146 | delayed()->nop(); |
aoqi@1 | 1147 | popad(); |
aoqi@1 | 1148 | #else |
aoqi@1 | 1149 | pushad(); |
aoqi@1 | 1150 | addi(SP, SP, -4); |
aoqi@1 | 1151 | sw(A0, SP, -1 * wordSize); |
aoqi@1 | 1152 | li(A0, (long)msg); |
aoqi@1 | 1153 | addi(SP, SP, -1 * wordSize); |
aoqi@1 | 1154 | call(CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); |
aoqi@1 | 1155 | delayed()->nop(); |
aoqi@1 | 1156 | addi(SP, SP, 1 * wordSize); |
aoqi@1 | 1157 | lw(A0, SP, -1 * wordSize); |
aoqi@1 | 1158 | addi(SP, SP, 4); |
aoqi@1 | 1159 | popad(); |
aoqi@1 | 1160 | #endif |
aoqi@1 | 1161 | } |
aoqi@1 | 1162 | |
aoqi@1 | 1163 | void MacroAssembler::print_reg(Register reg) { |
aoqi@1 | 1164 | /* |
aoqi@1 | 1165 | char *s = getenv("PRINT_REG"); |
aoqi@1 | 1166 | if (s == NULL) |
aoqi@1 | 1167 | return; |
aoqi@1 | 1168 | if (strcmp(s, "1") != 0) |
aoqi@1 | 1169 | return; |
aoqi@1 | 1170 | */ |
aoqi@1 | 1171 | void * cur_pc = pc(); |
aoqi@1 | 1172 | pushad(); |
aoqi@1 | 1173 | NOT_LP64(push(FP);) |
aoqi@1 | 1174 | |
aoqi@1 | 1175 | li(A0, (long)reg->name()); |
aoqi@1 | 1176 | if (reg == SP) |
aoqi@1 | 1177 | addiu(A1, SP, wordSize * 23); //23 registers saved in pushad() |
aoqi@9 | 1178 | else if (reg == A0) |
aoqi@9 | 1179 | ld(A1, SP, wordSize * 19); //A0 has been modified by li(A0, (long)reg->name()). Ugly Code! |
aoqi@1 | 1180 | else |
aoqi@1 | 1181 | move(A1, reg); |
aoqi@1 | 1182 | li(A2, (long)cur_pc); |
aoqi@1 | 1183 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_reg_with_pc),relocInfo::runtime_call_type); |
aoqi@1 | 1184 | delayed()->nop(); |
aoqi@1 | 1185 | NOT_LP64(pop(FP);) |
aoqi@1 | 1186 | popad(); |
aoqi@1 | 1187 | |
aoqi@1 | 1188 | /* |
aoqi@1 | 1189 | pushad(); |
aoqi@1 | 1190 | #ifdef _LP64 |
aoqi@1 | 1191 | if (reg == SP) |
aoqi@1 | 1192 | addiu(A0, SP, wordSize * 23); //23 registers saved in pushad() |
aoqi@1 | 1193 | else |
aoqi@1 | 1194 | move(A0, reg); |
aoqi@1 | 1195 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_long),relocInfo::runtime_call_type); |
aoqi@1 | 1196 | delayed()->nop(); |
aoqi@1 | 1197 | #else |
aoqi@1 | 1198 | push(FP); |
aoqi@1 | 1199 | move(A0, reg); |
aoqi@1 | 1200 | dsrl32(A1, reg, 0); |
aoqi@1 | 1201 | //call(CAST_FROM_FN_PTR(address, SharedRuntime::print_int),relocInfo::runtime_call_type); |
aoqi@1 | 1202 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_long),relocInfo::runtime_call_type); |
aoqi@1 | 1203 | delayed()->nop(); |
aoqi@1 | 1204 | pop(FP); |
aoqi@1 | 1205 | #endif |
aoqi@1 | 1206 | popad(); |
aoqi@1 | 1207 | pushad(); |
aoqi@1 | 1208 | NOT_LP64(push(FP);) |
aoqi@1 | 1209 | char b[50]; |
aoqi@1 | 1210 | sprintf((char *)b, " pc: %p\n",cur_pc); |
aoqi@1 | 1211 | li(A0, (long)(char *)b); |
aoqi@1 | 1212 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_str),relocInfo::runtime_call_type); |
aoqi@1 | 1213 | delayed()->nop(); |
aoqi@1 | 1214 | NOT_LP64(pop(FP);) |
aoqi@1 | 1215 | popad(); |
aoqi@1 | 1216 | */ |
aoqi@1 | 1217 | } |
aoqi@1 | 1218 | |
aoqi@1 | 1219 | void MacroAssembler::print_reg(FloatRegister reg) { |
aoqi@1 | 1220 | void * cur_pc = pc(); |
aoqi@1 | 1221 | pushad(); |
aoqi@1 | 1222 | NOT_LP64(push(FP);) |
aoqi@1 | 1223 | li(A0, (long)reg->name()); |
aoqi@1 | 1224 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_str),relocInfo::runtime_call_type); |
aoqi@1 | 1225 | delayed()->nop(); |
aoqi@1 | 1226 | NOT_LP64(pop(FP);) |
aoqi@1 | 1227 | popad(); |
aoqi@1 | 1228 | |
aoqi@1 | 1229 | pushad(); |
aoqi@1 | 1230 | NOT_LP64(push(FP);) |
aoqi@1 | 1231 | #if 1 |
aoqi@1 | 1232 | move(FP, SP); |
aoqi@1 | 1233 | move(AT, -(StackAlignmentInBytes)); |
aoqi@1 | 1234 | andr(SP , SP , AT); |
aoqi@1 | 1235 | mov_d(F12, reg); |
aoqi@1 | 1236 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_double),relocInfo::runtime_call_type); |
aoqi@1 | 1237 | delayed()->nop(); |
aoqi@1 | 1238 | move(SP, FP); |
aoqi@1 | 1239 | #else |
aoqi@1 | 1240 | mov_s(F12, reg); |
aoqi@1 | 1241 | //call(CAST_FROM_FN_PTR(address, SharedRuntime::print_float),relocInfo::runtime_call_type); |
aoqi@1 | 1242 | //delayed()->nop(); |
aoqi@1 | 1243 | #endif |
aoqi@1 | 1244 | NOT_LP64(pop(FP);) |
aoqi@1 | 1245 | popad(); |
aoqi@1 | 1246 | |
aoqi@1 | 1247 | #if 0 |
aoqi@1 | 1248 | pushad(); |
aoqi@1 | 1249 | NOT_LP64(push(FP);) |
aoqi@1 | 1250 | char* b = new char[50]; |
aoqi@1 | 1251 | sprintf(b, " pc: %p\n", cur_pc); |
aoqi@1 | 1252 | li(A0, (long)b); |
aoqi@1 | 1253 | call(CAST_FROM_FN_PTR(address, SharedRuntime::print_str),relocInfo::runtime_call_type); |
aoqi@1 | 1254 | delayed()->nop(); |
aoqi@1 | 1255 | NOT_LP64(pop(FP);) |
aoqi@1 | 1256 | popad(); |
aoqi@1 | 1257 | #endif |
aoqi@1 | 1258 | } |
aoqi@1 | 1259 | |
aoqi@1 | 1260 | void MacroAssembler::increment(Register reg, int imm) { |
aoqi@1 | 1261 | if (!imm) return; |
aoqi@1 | 1262 | if (is_simm16(imm)) { |
aoqi@1 | 1263 | #ifdef _LP64 |
aoqi@1 | 1264 | daddiu(reg, reg, imm); |
aoqi@1 | 1265 | #else |
aoqi@1 | 1266 | addiu(reg, reg, imm); |
aoqi@1 | 1267 | #endif |
aoqi@1 | 1268 | } else { |
aoqi@1 | 1269 | move(AT, imm); |
aoqi@1 | 1270 | #ifdef _LP64 |
aoqi@1 | 1271 | daddu(reg, reg, AT); |
aoqi@1 | 1272 | #else |
aoqi@1 | 1273 | addu(reg, reg, AT); |
aoqi@1 | 1274 | #endif |
aoqi@1 | 1275 | } |
aoqi@1 | 1276 | } |
aoqi@1 | 1277 | |
aoqi@1 | 1278 | void MacroAssembler::decrement(Register reg, int imm) { |
aoqi@1 | 1279 | increment(reg, -imm); |
aoqi@1 | 1280 | } |
aoqi@1 | 1281 | |
aoqi@1 | 1282 | |
aoqi@1 | 1283 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1284 | address entry_point, |
aoqi@1 | 1285 | bool check_exceptions) { |
aoqi@1 | 1286 | call_VM_helper(oop_result, entry_point, 0, check_exceptions); |
aoqi@1 | 1287 | } |
aoqi@1 | 1288 | |
aoqi@1 | 1289 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1290 | address entry_point, |
aoqi@1 | 1291 | Register arg_1, |
aoqi@1 | 1292 | bool check_exceptions) { |
aoqi@1 | 1293 | if (arg_1!=A1) move(A1, arg_1); |
aoqi@1 | 1294 | call_VM_helper(oop_result, entry_point, 1, check_exceptions); |
aoqi@1 | 1295 | } |
aoqi@1 | 1296 | |
aoqi@1 | 1297 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1298 | address entry_point, |
aoqi@1 | 1299 | Register arg_1, |
aoqi@1 | 1300 | Register arg_2, |
aoqi@1 | 1301 | bool check_exceptions) { |
aoqi@1 | 1302 | if (arg_1!=A1) move(A1, arg_1); |
aoqi@1 | 1303 | if (arg_2!=A2) move(A2, arg_2); |
aoqi@1 | 1304 | assert(arg_2 != A1, "smashed argument"); |
aoqi@1 | 1305 | call_VM_helper(oop_result, entry_point, 2, check_exceptions); |
aoqi@1 | 1306 | } |
aoqi@1 | 1307 | |
aoqi@1 | 1308 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1309 | address entry_point, |
aoqi@1 | 1310 | Register arg_1, |
aoqi@1 | 1311 | Register arg_2, |
aoqi@1 | 1312 | Register arg_3, |
aoqi@1 | 1313 | bool check_exceptions) { |
aoqi@1 | 1314 | if (arg_1!=A1) move(A1, arg_1); |
aoqi@1 | 1315 | if (arg_2!=A2) move(A2, arg_2); assert(arg_2 != A1, "smashed argument"); |
aoqi@1 | 1316 | if (arg_3!=A3) move(A3, arg_3); assert(arg_3 != A1 && arg_3 != A2, "smashed argument"); |
aoqi@1 | 1317 | call_VM_helper(oop_result, entry_point, 3, check_exceptions); |
aoqi@1 | 1318 | } |
aoqi@1 | 1319 | |
aoqi@1 | 1320 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1321 | Register last_java_sp, |
aoqi@1 | 1322 | address entry_point, |
aoqi@1 | 1323 | int number_of_arguments, |
aoqi@1 | 1324 | bool check_exceptions) { |
aoqi@1 | 1325 | call_VM_base(oop_result, NOREG, last_java_sp, entry_point, number_of_arguments, check_exceptions); |
aoqi@1 | 1326 | } |
aoqi@1 | 1327 | |
aoqi@1 | 1328 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1329 | Register last_java_sp, |
aoqi@1 | 1330 | address entry_point, |
aoqi@1 | 1331 | Register arg_1, |
aoqi@1 | 1332 | bool check_exceptions) { |
aoqi@1 | 1333 | if (arg_1 != A1) move(A1, arg_1); |
aoqi@1 | 1334 | call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions); |
aoqi@1 | 1335 | } |
aoqi@1 | 1336 | |
aoqi@1 | 1337 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1338 | Register last_java_sp, |
aoqi@1 | 1339 | address entry_point, |
aoqi@1 | 1340 | Register arg_1, |
aoqi@1 | 1341 | Register arg_2, |
aoqi@1 | 1342 | bool check_exceptions) { |
aoqi@1 | 1343 | if (arg_1 != A1) move(A1, arg_1); |
aoqi@1 | 1344 | if (arg_2 != A2) move(A2, arg_2); assert(arg_2 != A1, "smashed argument"); |
aoqi@1 | 1345 | call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions); |
aoqi@1 | 1346 | } |
aoqi@1 | 1347 | |
aoqi@1 | 1348 | void MacroAssembler::call_VM(Register oop_result, |
aoqi@1 | 1349 | Register last_java_sp, |
aoqi@1 | 1350 | address entry_point, |
aoqi@1 | 1351 | Register arg_1, |
aoqi@1 | 1352 | Register arg_2, |
aoqi@1 | 1353 | Register arg_3, |
aoqi@1 | 1354 | bool check_exceptions) { |
aoqi@1 | 1355 | if (arg_1 != A1) move(A1, arg_1); |
aoqi@1 | 1356 | if (arg_2 != A2) move(A2, arg_2); assert(arg_2 != A1, "smashed argument"); |
aoqi@1 | 1357 | if (arg_3 != A3) move(A3, arg_3); assert(arg_3 != A1 && arg_3 != A2, "smashed argument"); |
aoqi@1 | 1358 | call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions); |
aoqi@1 | 1359 | } |
aoqi@1 | 1360 | |
aoqi@1 | 1361 | void MacroAssembler::call_VM_base(Register oop_result, |
aoqi@1 | 1362 | Register java_thread, |
aoqi@1 | 1363 | Register last_java_sp, |
aoqi@1 | 1364 | address entry_point, |
aoqi@1 | 1365 | int number_of_arguments, |
aoqi@1 | 1366 | bool check_exceptions) { |
aoqi@1 | 1367 | |
aoqi@1 | 1368 | address before_call_pc; |
aoqi@1 | 1369 | // determine java_thread register |
aoqi@1 | 1370 | if (!java_thread->is_valid()) { |
aoqi@1 | 1371 | #ifndef OPT_THREAD |
aoqi@1 | 1372 | java_thread = T2; |
aoqi@1 | 1373 | get_thread(java_thread); |
aoqi@1 | 1374 | #else |
aoqi@1 | 1375 | java_thread = TREG; |
aoqi@1 | 1376 | #endif |
aoqi@1 | 1377 | } |
aoqi@1 | 1378 | // determine last_java_sp register |
aoqi@1 | 1379 | if (!last_java_sp->is_valid()) { |
aoqi@1 | 1380 | last_java_sp = SP; |
aoqi@1 | 1381 | } |
aoqi@1 | 1382 | // debugging support |
aoqi@1 | 1383 | assert(number_of_arguments >= 0 , "cannot have negative number of arguments"); |
aoqi@1 | 1384 | assert(number_of_arguments <= 4 , "cannot have negative number of arguments"); |
aoqi@1 | 1385 | assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result"); |
aoqi@1 | 1386 | assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp"); |
aoqi@1 | 1387 | |
aoqi@1 | 1388 | assert(last_java_sp != FP, "this code doesn't work for last_java_sp == fp, which currently can't portably work anyway since C2 doesn't save ebp"); |
aoqi@1 | 1389 | |
aoqi@1 | 1390 | // set last Java frame before call |
aoqi@1 | 1391 | before_call_pc = (address)pc(); |
aoqi@1 | 1392 | set_last_Java_frame(java_thread, last_java_sp, FP, before_call_pc); |
aoqi@1 | 1393 | |
aoqi@1 | 1394 | // do the call |
aoqi@1 | 1395 | move(A0, java_thread); |
aoqi@1 | 1396 | call(entry_point, relocInfo::runtime_call_type); |
aoqi@1 | 1397 | delayed()->nop(); |
aoqi@1 | 1398 | |
aoqi@1 | 1399 | // restore the thread (cannot use the pushed argument since arguments |
aoqi@1 | 1400 | // may be overwritten by C code generated by an optimizing compiler); |
aoqi@1 | 1401 | // however can use the register value directly if it is callee saved. |
aoqi@1 | 1402 | #ifndef OPT_THREAD |
aoqi@1 | 1403 | if (java_thread >=S0 && java_thread <=S7) { |
aoqi@1 | 1404 | #ifdef ASSERT |
aoqi@1 | 1405 | { Label L; |
aoqi@1 | 1406 | get_thread(AT); |
aoqi@1 | 1407 | beq(java_thread, AT, L); |
aoqi@1 | 1408 | delayed()->nop(); |
aoqi@1 | 1409 | stop("MacroAssembler::call_VM_base: edi not callee saved?"); |
aoqi@1 | 1410 | bind(L); |
aoqi@1 | 1411 | } |
aoqi@1 | 1412 | #endif |
aoqi@1 | 1413 | } else { |
aoqi@1 | 1414 | get_thread(java_thread); |
aoqi@1 | 1415 | } |
aoqi@1 | 1416 | #endif |
aoqi@1 | 1417 | |
aoqi@1 | 1418 | // discard thread and arguments |
aoqi@1 | 1419 | ld_ptr(SP, java_thread, in_bytes(JavaThread::last_Java_sp_offset())); |
aoqi@1 | 1420 | // reset last Java frame |
aoqi@1 | 1421 | reset_last_Java_frame(java_thread, false, true); |
aoqi@1 | 1422 | |
aoqi@1 | 1423 | check_and_handle_popframe(java_thread); |
aoqi@1 | 1424 | check_and_handle_earlyret(java_thread); |
aoqi@1 | 1425 | if (check_exceptions) { |
aoqi@1 | 1426 | // check for pending exceptions (java_thread is set upon return) |
aoqi@1 | 1427 | Label L; |
aoqi@1 | 1428 | #ifdef _LP64 |
aoqi@1 | 1429 | ld(AT, java_thread, in_bytes(Thread::pending_exception_offset())); |
aoqi@1 | 1430 | #else |
aoqi@1 | 1431 | lw(AT, java_thread, in_bytes(Thread::pending_exception_offset())); |
aoqi@1 | 1432 | #endif |
aoqi@1 | 1433 | beq(AT, R0, L); |
aoqi@1 | 1434 | delayed()->nop(); |
aoqi@1 | 1435 | li(AT, before_call_pc); |
aoqi@1 | 1436 | push(AT); |
aoqi@1 | 1437 | jmp(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); |
aoqi@1 | 1438 | delayed()->nop(); |
aoqi@1 | 1439 | bind(L); |
aoqi@1 | 1440 | } |
aoqi@1 | 1441 | |
aoqi@1 | 1442 | // get oop result if there is one and reset the value in the thread |
aoqi@1 | 1443 | if (oop_result->is_valid()) { |
aoqi@1 | 1444 | #ifdef _LP64 |
aoqi@1 | 1445 | ld(oop_result, java_thread, in_bytes(JavaThread::vm_result_offset())); |
aoqi@1 | 1446 | sd(R0, java_thread, in_bytes(JavaThread::vm_result_offset())); |
aoqi@1 | 1447 | #else |
aoqi@1 | 1448 | lw(oop_result, java_thread, in_bytes(JavaThread::vm_result_offset())); |
aoqi@1 | 1449 | sw(R0, java_thread, in_bytes(JavaThread::vm_result_offset())); |
aoqi@1 | 1450 | #endif |
aoqi@1 | 1451 | verify_oop(oop_result); |
aoqi@1 | 1452 | } |
aoqi@1 | 1453 | } |
aoqi@1 | 1454 | |
aoqi@1 | 1455 | void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) { |
aoqi@1 | 1456 | |
aoqi@1 | 1457 | move(V0, SP); |
aoqi@1 | 1458 | //we also reserve space for java_thread here |
aoqi@1 | 1459 | #ifndef _LP64 |
aoqi@1 | 1460 | daddi(SP, SP, (1 + number_of_arguments) * (- wordSize)); |
aoqi@1 | 1461 | #endif |
aoqi@1 | 1462 | move(AT, -(StackAlignmentInBytes)); |
aoqi@1 | 1463 | andr(SP, SP, AT); |
aoqi@1 | 1464 | call_VM_base(oop_result, NOREG, V0, entry_point, number_of_arguments, check_exceptions); |
aoqi@1 | 1465 | |
aoqi@1 | 1466 | } |
aoqi@1 | 1467 | |
aoqi@1 | 1468 | void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) { |
aoqi@1 | 1469 | call_VM_leaf_base(entry_point, number_of_arguments); |
aoqi@1 | 1470 | } |
aoqi@1 | 1471 | |
aoqi@1 | 1472 | void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0) { |
aoqi@1 | 1473 | if (arg_0 != A0) move(A0, arg_0); |
aoqi@1 | 1474 | call_VM_leaf(entry_point, 1); |
aoqi@1 | 1475 | } |
aoqi@1 | 1476 | |
aoqi@1 | 1477 | void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1) { |
aoqi@1 | 1478 | if (arg_0 != A0) move(A0, arg_0); |
aoqi@1 | 1479 | if (arg_1 != A1) move(A1, arg_1); assert(arg_1 != A0, "smashed argument"); |
aoqi@1 | 1480 | call_VM_leaf(entry_point, 2); |
aoqi@1 | 1481 | } |
aoqi@1 | 1482 | |
aoqi@1 | 1483 | void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) { |
aoqi@1 | 1484 | if (arg_0 != A0) move(A0, arg_0); |
aoqi@1 | 1485 | if (arg_1 != A1) move(A1, arg_1); assert(arg_1 != A0, "smashed argument"); |
aoqi@1 | 1486 | if (arg_2 != A2) move(A2, arg_2); assert(arg_2 != A0 && arg_2 != A1, "smashed argument"); |
aoqi@1 | 1487 | call_VM_leaf(entry_point, 3); |
aoqi@1 | 1488 | } |
aoqi@1 | 1489 | void MacroAssembler::super_call_VM_leaf(address entry_point) { |
aoqi@1 | 1490 | MacroAssembler::call_VM_leaf_base(entry_point, 0); |
aoqi@1 | 1491 | } |
aoqi@1 | 1492 | |
aoqi@1 | 1493 | |
aoqi@1 | 1494 | void MacroAssembler::super_call_VM_leaf(address entry_point, |
aoqi@1 | 1495 | Register arg_1) { |
aoqi@1 | 1496 | if (arg_1 != A0) move(A0, arg_1); |
aoqi@1 | 1497 | MacroAssembler::call_VM_leaf_base(entry_point, 1); |
aoqi@1 | 1498 | } |
aoqi@1 | 1499 | |
aoqi@1 | 1500 | |
aoqi@1 | 1501 | void MacroAssembler::super_call_VM_leaf(address entry_point, |
aoqi@1 | 1502 | Register arg_1, |
aoqi@1 | 1503 | Register arg_2) { |
aoqi@1 | 1504 | if (arg_1 != A0) move(A0, arg_1); |
aoqi@1 | 1505 | if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument"); |
aoqi@1 | 1506 | MacroAssembler::call_VM_leaf_base(entry_point, 2); |
aoqi@1 | 1507 | } |
aoqi@1 | 1508 | void MacroAssembler::super_call_VM_leaf(address entry_point, |
aoqi@1 | 1509 | Register arg_1, |
aoqi@1 | 1510 | Register arg_2, |
aoqi@1 | 1511 | Register arg_3) { |
aoqi@1 | 1512 | if (arg_1 != A0) move(A0, arg_1); |
aoqi@1 | 1513 | if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument"); |
aoqi@1 | 1514 | if (arg_3 != A2) move(A2, arg_3); assert(arg_3 != A0 && arg_3 != A1, "smashed argument"); |
aoqi@1 | 1515 | MacroAssembler::call_VM_leaf_base(entry_point, 3); |
aoqi@1 | 1516 | } |
aoqi@1 | 1517 | |
aoqi@1 | 1518 | void MacroAssembler::check_and_handle_earlyret(Register java_thread) { |
aoqi@1 | 1519 | } |
aoqi@1 | 1520 | |
aoqi@1 | 1521 | void MacroAssembler::check_and_handle_popframe(Register java_thread) { |
aoqi@1 | 1522 | } |
aoqi@1 | 1523 | |
aoqi@1 | 1524 | void MacroAssembler::null_check(Register reg, int offset) { |
aoqi@1 | 1525 | if (needs_explicit_null_check(offset)) { |
aoqi@1 | 1526 | // provoke OS NULL exception if reg = NULL by |
aoqi@1 | 1527 | // accessing M[reg] w/o changing any (non-CC) registers |
aoqi@1 | 1528 | // NOTE: cmpl is plenty here to provoke a segv |
aoqi@1 | 1529 | lw(AT, reg, 0); |
aoqi@1 | 1530 | /* Jin |
aoqi@1 | 1531 | nop(); |
aoqi@1 | 1532 | nop(); |
aoqi@1 | 1533 | nop(); |
aoqi@1 | 1534 | */ |
aoqi@1 | 1535 | // Note: should probably use testl(rax, Address(reg, 0)); |
aoqi@1 | 1536 | // may be shorter code (however, this version of |
aoqi@1 | 1537 | // testl needs to be implemented first) |
aoqi@1 | 1538 | } else { |
aoqi@1 | 1539 | // nothing to do, (later) access of M[reg + offset] |
aoqi@1 | 1540 | // will provoke OS NULL exception if reg = NULL |
aoqi@1 | 1541 | } |
aoqi@1 | 1542 | } |
aoqi@1 | 1543 | |
aoqi@1 | 1544 | void MacroAssembler::enter() { |
aoqi@1 | 1545 | push2(RA, FP); |
aoqi@1 | 1546 | move(FP, SP); |
aoqi@1 | 1547 | } |
aoqi@1 | 1548 | |
aoqi@1 | 1549 | void MacroAssembler::leave() { |
aoqi@1 | 1550 | #ifndef _LP64 |
aoqi@1 | 1551 | //move(SP, FP); |
aoqi@1 | 1552 | //pop2(FP, RA); |
aoqi@1 | 1553 | addi(SP, FP, 2 * wordSize); |
aoqi@1 | 1554 | lw(RA, SP, - 1 * wordSize); |
aoqi@1 | 1555 | lw(FP, SP, - 2 * wordSize); |
aoqi@1 | 1556 | #else |
aoqi@1 | 1557 | daddi(SP, FP, 2 * wordSize); |
aoqi@1 | 1558 | ld(RA, SP, - 1 * wordSize); |
aoqi@1 | 1559 | ld(FP, SP, - 2 * wordSize); |
aoqi@1 | 1560 | #endif |
aoqi@1 | 1561 | } |
aoqi@1 | 1562 | /* |
aoqi@1 | 1563 | void MacroAssembler::os_breakpoint() { |
aoqi@1 | 1564 | // instead of directly emitting a breakpoint, call os:breakpoint for better debugability |
aoqi@1 | 1565 | // (e.g., MSVC can't call ps() otherwise) |
aoqi@1 | 1566 | call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint))); |
aoqi@1 | 1567 | } |
aoqi@1 | 1568 | */ |
aoqi@1 | 1569 | void MacroAssembler::reset_last_Java_frame(Register java_thread, bool clear_fp, bool clear_pc) { |
aoqi@1 | 1570 | // determine java_thread register |
aoqi@1 | 1571 | if (!java_thread->is_valid()) { |
aoqi@1 | 1572 | #ifndef OPT_THREAD |
aoqi@1 | 1573 | java_thread = T1; |
aoqi@1 | 1574 | get_thread(java_thread); |
aoqi@1 | 1575 | #else |
aoqi@1 | 1576 | java_thread = TREG; |
aoqi@1 | 1577 | #endif |
aoqi@1 | 1578 | } |
aoqi@1 | 1579 | // we must set sp to zero to clear frame |
aoqi@1 | 1580 | st_ptr(R0, java_thread, in_bytes(JavaThread::last_Java_sp_offset())); |
aoqi@1 | 1581 | // must clear fp, so that compiled frames are not confused; it is possible |
aoqi@1 | 1582 | // that we need it only for debugging |
aoqi@1 | 1583 | if(clear_fp) |
aoqi@1 | 1584 | st_ptr(R0, java_thread, in_bytes(JavaThread::last_Java_fp_offset())); |
aoqi@1 | 1585 | |
aoqi@1 | 1586 | if (clear_pc) |
aoqi@1 | 1587 | st_ptr(R0, java_thread, in_bytes(JavaThread::last_Java_pc_offset())); |
aoqi@1 | 1588 | } |
aoqi@1 | 1589 | |
aoqi@1 | 1590 | void MacroAssembler::reset_last_Java_frame(bool clear_fp, |
aoqi@1 | 1591 | bool clear_pc) { |
aoqi@1 | 1592 | Register thread = TREG; |
aoqi@1 | 1593 | #ifndef OPT_THREAD |
aoqi@1 | 1594 | get_thread(thread); |
aoqi@1 | 1595 | #endif |
aoqi@1 | 1596 | // we must set sp to zero to clear frame |
aoqi@1 | 1597 | sd(R0, Address(thread, JavaThread::last_Java_sp_offset())); |
aoqi@1 | 1598 | // must clear fp, so that compiled frames are not confused; it is |
aoqi@1 | 1599 | // possible that we need it only for debugging |
aoqi@1 | 1600 | if (clear_fp) { |
aoqi@1 | 1601 | sd(R0, Address(thread, JavaThread::last_Java_fp_offset())); |
aoqi@1 | 1602 | } |
aoqi@1 | 1603 | |
aoqi@1 | 1604 | if (clear_pc) { |
aoqi@1 | 1605 | sd(R0, Address(thread, JavaThread::last_Java_pc_offset())); |
aoqi@1 | 1606 | } |
aoqi@1 | 1607 | } |
aoqi@1 | 1608 | |
aoqi@1 | 1609 | // Write serialization page so VM thread can do a pseudo remote membar. |
aoqi@1 | 1610 | // We use the current thread pointer to calculate a thread specific |
aoqi@1 | 1611 | // offset to write to within the page. This minimizes bus traffic |
aoqi@1 | 1612 | // due to cache line collision. |
aoqi@1 | 1613 | void MacroAssembler::serialize_memory(Register thread, Register tmp) { |
aoqi@1 | 1614 | move(tmp, thread); |
aoqi@1 | 1615 | srl(tmp, tmp,os::get_serialize_page_shift_count()); |
aoqi@1 | 1616 | move(AT, (os::vm_page_size() - sizeof(int))); |
aoqi@1 | 1617 | andr(tmp, tmp,AT); |
aoqi@1 | 1618 | sw(tmp,Address(tmp, (intptr_t)os::get_memory_serialize_page())); |
aoqi@1 | 1619 | } |
aoqi@1 | 1620 | |
aoqi@1 | 1621 | // Calls to C land |
aoqi@1 | 1622 | // |
aoqi@1 | 1623 | // When entering C land, the rbp, & rsp of the last Java frame have to be recorded |
aoqi@1 | 1624 | // in the (thread-local) JavaThread object. When leaving C land, the last Java fp |
aoqi@1 | 1625 | // has to be reset to 0. This is required to allow proper stack traversal. |
aoqi@1 | 1626 | void MacroAssembler::set_last_Java_frame(Register java_thread, |
aoqi@1 | 1627 | Register last_java_sp, |
aoqi@1 | 1628 | Register last_java_fp, |
aoqi@1 | 1629 | address last_java_pc) { |
aoqi@1 | 1630 | // determine java_thread register |
aoqi@1 | 1631 | if (!java_thread->is_valid()) { |
aoqi@1 | 1632 | #ifndef OPT_THREAD |
aoqi@1 | 1633 | java_thread = T2; |
aoqi@1 | 1634 | get_thread(java_thread); |
aoqi@1 | 1635 | #else |
aoqi@1 | 1636 | java_thread = TREG; |
aoqi@1 | 1637 | #endif |
aoqi@1 | 1638 | } |
aoqi@1 | 1639 | // determine last_java_sp register |
aoqi@1 | 1640 | if (!last_java_sp->is_valid()) { |
aoqi@1 | 1641 | last_java_sp = SP; |
aoqi@1 | 1642 | } |
aoqi@1 | 1643 | |
aoqi@1 | 1644 | // last_java_fp is optional |
aoqi@1 | 1645 | |
aoqi@1 | 1646 | if (last_java_fp->is_valid()) { |
aoqi@1 | 1647 | st_ptr(last_java_fp, java_thread, in_bytes(JavaThread::last_Java_fp_offset())); |
aoqi@1 | 1648 | } |
aoqi@1 | 1649 | |
aoqi@1 | 1650 | // last_java_pc is optional |
aoqi@1 | 1651 | |
aoqi@1 | 1652 | if (last_java_pc != NULL) { |
aoqi@1 | 1653 | relocate(relocInfo::internal_pc_type); |
aoqi@1 | 1654 | li48(AT, (long)last_java_pc); |
aoqi@1 | 1655 | st_ptr(AT, java_thread, in_bytes(JavaThread::last_Java_pc_offset())); |
aoqi@1 | 1656 | } |
aoqi@1 | 1657 | st_ptr(last_java_sp, java_thread, in_bytes(JavaThread::last_Java_sp_offset())); |
aoqi@1 | 1658 | } |
aoqi@1 | 1659 | |
aoqi@1 | 1660 | void MacroAssembler::set_last_Java_frame(Register last_java_sp, |
aoqi@1 | 1661 | Register last_java_fp, |
aoqi@1 | 1662 | address last_java_pc) { |
aoqi@1 | 1663 | // determine last_java_sp register |
aoqi@1 | 1664 | if (!last_java_sp->is_valid()) { |
aoqi@1 | 1665 | last_java_sp = SP; |
aoqi@1 | 1666 | } |
aoqi@1 | 1667 | |
aoqi@1 | 1668 | Register thread = TREG; |
aoqi@1 | 1669 | #ifndef OPT_THREAD |
aoqi@1 | 1670 | get_thread(thread); |
aoqi@1 | 1671 | #endif |
aoqi@1 | 1672 | // last_java_fp is optional |
aoqi@1 | 1673 | if (last_java_fp->is_valid()) { |
aoqi@1 | 1674 | sd(last_java_fp, Address(thread, JavaThread::last_Java_fp_offset())); |
aoqi@1 | 1675 | } |
aoqi@1 | 1676 | |
aoqi@1 | 1677 | // last_java_pc is optional |
aoqi@1 | 1678 | if (last_java_pc != NULL) { |
aoqi@1 | 1679 | Address java_pc(thread, |
aoqi@1 | 1680 | JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()); |
aoqi@1 | 1681 | li(AT, (intptr_t)(last_java_pc)); |
aoqi@1 | 1682 | sd(AT, java_pc); |
aoqi@1 | 1683 | } |
aoqi@1 | 1684 | |
aoqi@1 | 1685 | sd(last_java_sp, Address(thread, JavaThread::last_Java_sp_offset())); |
aoqi@1 | 1686 | } |
aoqi@1 | 1687 | |
aoqi@1 | 1688 | ////////////////////////////////////////////////////////////////////////////////// |
aoqi@1 | 1689 | #ifndef SERIALGC |
aoqi@1 | 1690 | |
aoqi@1 | 1691 | void MacroAssembler::g1_write_barrier_pre(Register obj, |
aoqi@1 | 1692 | #ifndef _LP64 |
aoqi@1 | 1693 | Register thread, |
aoqi@1 | 1694 | #endif |
aoqi@1 | 1695 | Register tmp, |
aoqi@1 | 1696 | Register tmp2, |
aoqi@1 | 1697 | bool tosca_live) { |
aoqi@1 | 1698 | /* LP64_ONLY(Register thread = r15_thread;) |
aoqi@1 | 1699 | Address in_progress(thread, in_bytes(JavaThread::satb_mark_queue_offset() + |
aoqi@1 | 1700 | PtrQueue::byte_offset_of_active())); |
aoqi@1 | 1701 | |
aoqi@1 | 1702 | Address index(thread, in_bytes(JavaThread::satb_mark_queue_offset() + |
aoqi@1 | 1703 | PtrQueue::byte_offset_of_index())); |
aoqi@1 | 1704 | Address buffer(thread, in_bytes(JavaThread::satb_mark_queue_offset() + |
aoqi@1 | 1705 | PtrQueue::byte_offset_of_buf())); |
aoqi@1 | 1706 | |
aoqi@1 | 1707 | |
aoqi@1 | 1708 | Label done; |
aoqi@1 | 1709 | Label runtime; |
aoqi@1 | 1710 | |
aoqi@1 | 1711 | // if (!marking_in_progress) goto done; |
aoqi@1 | 1712 | if (in_bytes(PtrQueue::byte_width_of_active()) == 4) { |
aoqi@1 | 1713 | cmpl(in_progress, 0); |
aoqi@1 | 1714 | } else { |
aoqi@1 | 1715 | assert(in_bytes(PtrQueue::byte_width_of_active()) == 1, "Assumption"); |
aoqi@1 | 1716 | cmpb(in_progress, 0); |
aoqi@1 | 1717 | } |
aoqi@1 | 1718 | jcc(Assembler::equal, done); |
aoqi@1 | 1719 | |
aoqi@1 | 1720 | // if (x.f == NULL) goto done; |
aoqi@1 | 1721 | cmpptr(Address(obj, 0), NULL_WORD); |
aoqi@1 | 1722 | jcc(Assembler::equal, done); |
aoqi@1 | 1723 | |
aoqi@1 | 1724 | // Can we store original value in the thread's buffer? |
aoqi@1 | 1725 | |
aoqi@1 | 1726 | LP64_ONLY(movslq(tmp, index);) |
aoqi@1 | 1727 | movptr(tmp2, Address(obj, 0)); |
aoqi@1 | 1728 | #ifdef _LP64 |
aoqi@1 | 1729 | cmpq(tmp, 0); |
aoqi@1 | 1730 | #else |
aoqi@1 | 1731 | cmpl(index, 0); |
aoqi@1 | 1732 | #endif |
aoqi@1 | 1733 | jcc(Assembler::equal, runtime); |
aoqi@1 | 1734 | #ifdef _LP64 |
aoqi@1 | 1735 | subq(tmp, wordSize); |
aoqi@1 | 1736 | movl(index, tmp); |
aoqi@1 | 1737 | addq(tmp, buffer); |
aoqi@1 | 1738 | #else |
aoqi@1 | 1739 | subl(index, wordSize); |
aoqi@1 | 1740 | movl(tmp, buffer); |
aoqi@1 | 1741 | addl(tmp, index); |
aoqi@1 | 1742 | #endif |
aoqi@1 | 1743 | movptr(Address(tmp, 0), tmp2); |
aoqi@1 | 1744 | jmp(done); |
aoqi@1 | 1745 | bind(runtime); |
aoqi@1 | 1746 | // save the live input values |
aoqi@1 | 1747 | if(tosca_live) push(rax); |
aoqi@1 | 1748 | push(obj); |
aoqi@1 | 1749 | #ifdef _LP64 |
aoqi@1 | 1750 | movq(c_rarg0, Address(obj, 0)); |
aoqi@1 | 1751 | call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), c_rarg0, r15_thread); |
aoqi@1 | 1752 | #else |
aoqi@1 | 1753 | push(thread); |
aoqi@1 | 1754 | call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), tmp2, thread); |
aoqi@1 | 1755 | pop(thread); |
aoqi@1 | 1756 | #endif |
aoqi@1 | 1757 | pop(obj); |
aoqi@1 | 1758 | if(tosca_live) pop(rax); |
aoqi@1 | 1759 | bind(done); |
aoqi@1 | 1760 | */ |
aoqi@1 | 1761 | } |
aoqi@1 | 1762 | |
aoqi@1 | 1763 | void MacroAssembler::g1_write_barrier_post(Register store_addr, |
aoqi@1 | 1764 | Register new_val, |
aoqi@1 | 1765 | #ifndef _LP64 |
aoqi@1 | 1766 | Register thread, |
aoqi@1 | 1767 | #endif |
aoqi@1 | 1768 | Register tmp, |
aoqi@1 | 1769 | Register tmp2) { |
aoqi@1 | 1770 | |
aoqi@1 | 1771 | /*LP64_ONLY(Register thread = r15_thread;) |
aoqi@1 | 1772 | Address queue_index(thread, in_bytes(JavaThread::dirty_card_queue_offset() + |
aoqi@1 | 1773 | PtrQueue::byte_offset_of_index())); |
aoqi@1 | 1774 | Address buffer(thread, in_bytes(JavaThread::dirty_card_queue_offset() + |
aoqi@1 | 1775 | PtrQueue::byte_offset_of_buf())); |
aoqi@1 | 1776 | BarrierSet* bs = Universe::heap()->barrier_set(); |
aoqi@1 | 1777 | CardTableModRefBS* ct = (CardTableModRefBS*)bs; |
aoqi@1 | 1778 | Label done; |
aoqi@1 | 1779 | Label runtime; |
aoqi@1 | 1780 | |
aoqi@1 | 1781 | // Does store cross heap regions? |
aoqi@1 | 1782 | |
aoqi@1 | 1783 | movptr(tmp, store_addr); |
aoqi@1 | 1784 | xorptr(tmp, new_val); |
aoqi@1 | 1785 | shrptr(tmp, HeapRegion::LogOfHRGrainBytes); |
aoqi@1 | 1786 | jcc(Assembler::equal, done); |
aoqi@1 | 1787 | |
aoqi@1 | 1788 | // crosses regions, storing NULL? |
aoqi@1 | 1789 | |
aoqi@1 | 1790 | cmpptr(new_val, (int32_t) NULL_WORD); |
aoqi@1 | 1791 | jcc(Assembler::equal, done); |
aoqi@1 | 1792 | |
aoqi@1 | 1793 | // storing region crossing non-NULL, is card already dirty? |
aoqi@1 | 1794 | |
aoqi@1 | 1795 | ExternalAddress cardtable((address) ct->byte_map_base); |
aoqi@1 | 1796 | assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); |
aoqi@1 | 1797 | #ifdef _LP64 |
aoqi@1 | 1798 | const Register card_addr = tmp; |
aoqi@1 | 1799 | |
aoqi@1 | 1800 | movq(card_addr, store_addr); |
aoqi@1 | 1801 | shrq(card_addr, CardTableModRefBS::card_shift); |
aoqi@1 | 1802 | |
aoqi@1 | 1803 | lea(tmp2, cardtable); |
aoqi@1 | 1804 | |
aoqi@1 | 1805 | // get the address of the card |
aoqi@1 | 1806 | addq(card_addr, tmp2); |
aoqi@1 | 1807 | #else |
aoqi@1 | 1808 | const Register card_index = tmp; |
aoqi@1 | 1809 | |
aoqi@1 | 1810 | movl(card_index, store_addr); |
aoqi@1 | 1811 | shrl(card_index, CardTableModRefBS::card_shift); |
aoqi@1 | 1812 | |
aoqi@1 | 1813 | Address index(noreg, card_index, Address::times_1); |
aoqi@1 | 1814 | const Register card_addr = tmp; |
aoqi@1 | 1815 | lea(card_addr, as_Address(ArrayAddress(cardtable, index))); |
aoqi@1 | 1816 | #endif |
aoqi@1 | 1817 | cmpb(Address(card_addr, 0), 0); |
aoqi@1 | 1818 | jcc(Assembler::equal, done); |
aoqi@1 | 1819 | |
aoqi@1 | 1820 | // storing a region crossing, non-NULL oop, card is clean. |
aoqi@1 | 1821 | // dirty card and log. |
aoqi@1 | 1822 | |
aoqi@1 | 1823 | movb(Address(card_addr, 0), 0); |
aoqi@1 | 1824 | |
aoqi@1 | 1825 | cmpl(queue_index, 0); |
aoqi@1 | 1826 | jcc(Assembler::equal, runtime); |
aoqi@1 | 1827 | subl(queue_index, wordSize); |
aoqi@1 | 1828 | movptr(tmp2, buffer); |
aoqi@1 | 1829 | #ifdef _LP64 |
aoqi@1 | 1830 | movslq(rscratch1, queue_index); |
aoqi@1 | 1831 | addq(tmp2, rscratch1); |
aoqi@1 | 1832 | movq(Address(tmp2, 0), card_addr); |
aoqi@1 | 1833 | #else |
aoqi@1 | 1834 | addl(tmp2, queue_index); |
aoqi@1 | 1835 | movl(Address(tmp2, 0), card_index); |
aoqi@1 | 1836 | #endif |
aoqi@1 | 1837 | jmp(done); |
aoqi@1 | 1838 | |
aoqi@1 | 1839 | bind(runtime); |
aoqi@1 | 1840 | // save the live input values |
aoqi@1 | 1841 | push(store_addr); |
aoqi@1 | 1842 | push(new_val); |
aoqi@1 | 1843 | #ifdef _LP64 |
aoqi@1 | 1844 | call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, r15_thread); |
aoqi@1 | 1845 | #else |
aoqi@1 | 1846 | push(thread); |
aoqi@1 | 1847 | call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread); |
aoqi@1 | 1848 | pop(thread); |
aoqi@1 | 1849 | #endif |
aoqi@1 | 1850 | pop(new_val); |
aoqi@1 | 1851 | pop(store_addr); |
aoqi@1 | 1852 | |
aoqi@1 | 1853 | bind(done); |
aoqi@1 | 1854 | */ |
aoqi@1 | 1855 | } |
aoqi@1 | 1856 | |
aoqi@1 | 1857 | #endif // SERIALGC |
aoqi@1 | 1858 | ////////////////////////////////////////////////////////////////////////////////// |
aoqi@1 | 1859 | |
aoqi@1 | 1860 | |
aoqi@1 | 1861 | void MacroAssembler::store_check(Register obj) { |
aoqi@1 | 1862 | // Does a store check for the oop in register obj. The content of |
aoqi@1 | 1863 | // register obj is destroyed afterwards. |
aoqi@1 | 1864 | store_check_part_1(obj); |
aoqi@1 | 1865 | store_check_part_2(obj); |
aoqi@1 | 1866 | } |
aoqi@1 | 1867 | |
aoqi@1 | 1868 | void MacroAssembler::store_check(Register obj, Address dst) { |
aoqi@1 | 1869 | store_check(obj); |
aoqi@1 | 1870 | } |
aoqi@1 | 1871 | |
aoqi@1 | 1872 | |
aoqi@1 | 1873 | // split the store check operation so that other instructions can be scheduled inbetween |
aoqi@1 | 1874 | void MacroAssembler::store_check_part_1(Register obj) { |
aoqi@1 | 1875 | BarrierSet* bs = Universe::heap()->barrier_set(); |
aoqi@1 | 1876 | assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind"); |
aoqi@1 | 1877 | #ifdef _LP64 |
aoqi@1 | 1878 | dsrl(obj, obj, CardTableModRefBS::card_shift); |
aoqi@1 | 1879 | #else |
aoqi@1 | 1880 | shr(obj, CardTableModRefBS::card_shift); |
aoqi@1 | 1881 | #endif |
aoqi@1 | 1882 | } |
aoqi@1 | 1883 | |
aoqi@1 | 1884 | void MacroAssembler::store_check_part_2(Register obj) { |
aoqi@1 | 1885 | BarrierSet* bs = Universe::heap()->barrier_set(); |
aoqi@1 | 1886 | assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind"); |
aoqi@1 | 1887 | CardTableModRefBS* ct = (CardTableModRefBS*)bs; |
aoqi@1 | 1888 | assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); |
aoqi@1 | 1889 | |
aoqi@1 | 1890 | li(AT, (long)ct->byte_map_base); |
aoqi@1 | 1891 | #ifdef _LP64 |
aoqi@1 | 1892 | dadd(AT, AT, obj); |
aoqi@1 | 1893 | #else |
aoqi@1 | 1894 | add(AT, AT, obj); |
aoqi@1 | 1895 | #endif |
aoqi@1 | 1896 | sb(R0, AT, 0); |
aoqi@1 | 1897 | } |
aoqi@1 | 1898 | /* |
aoqi@1 | 1899 | void MacroAssembler::subptr(Register dst, int32_t imm32) { |
aoqi@1 | 1900 | LP64_ONLY(subq(dst, imm32)) NOT_LP64(subl(dst, imm32)); |
aoqi@1 | 1901 | } |
aoqi@1 | 1902 | |
aoqi@1 | 1903 | void MacroAssembler::subptr(Register dst, Register src) { |
aoqi@1 | 1904 | LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src)); |
aoqi@1 | 1905 | } |
aoqi@1 | 1906 | |
aoqi@1 | 1907 | void MacroAssembler::test32(Register src1, AddressLiteral src2) { |
aoqi@1 | 1908 | // src2 must be rval |
aoqi@1 | 1909 | |
aoqi@1 | 1910 | if (reachable(src2)) { |
aoqi@1 | 1911 | testl(src1, as_Address(src2)); |
aoqi@1 | 1912 | } else { |
aoqi@1 | 1913 | lea(rscratch1, src2); |
aoqi@1 | 1914 | testl(src1, Address(rscratch1, 0)); |
aoqi@1 | 1915 | } |
aoqi@1 | 1916 | } |
aoqi@1 | 1917 | |
aoqi@1 | 1918 | // C++ bool manipulation |
aoqi@1 | 1919 | void MacroAssembler::testbool(Register dst) { |
aoqi@1 | 1920 | if(sizeof(bool) == 1) |
aoqi@1 | 1921 | testb(dst, 0xff); |
aoqi@1 | 1922 | else if(sizeof(bool) == 2) { |
aoqi@1 | 1923 | // testw implementation needed for two byte bools |
aoqi@1 | 1924 | ShouldNotReachHere(); |
aoqi@1 | 1925 | } else if(sizeof(bool) == 4) |
aoqi@1 | 1926 | testl(dst, dst); |
aoqi@1 | 1927 | else |
aoqi@1 | 1928 | // unsupported |
aoqi@1 | 1929 | ShouldNotReachHere(); |
aoqi@1 | 1930 | } |
aoqi@1 | 1931 | |
aoqi@1 | 1932 | void MacroAssembler::testptr(Register dst, Register src) { |
aoqi@1 | 1933 | LP64_ONLY(testq(dst, src)) NOT_LP64(testl(dst, src)); |
aoqi@1 | 1934 | } |
aoqi@1 | 1935 | |
aoqi@1 | 1936 | |
aoqi@1 | 1937 | */ |
aoqi@1 | 1938 | |
aoqi@1 | 1939 | // Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes. |
aoqi@1 | 1940 | void MacroAssembler::tlab_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, |
aoqi@1 | 1941 | Register t1, Register t2, Label& slow_case) { |
aoqi@1 | 1942 | assert_different_registers(obj, var_size_in_bytes, t1, t2, AT); |
aoqi@1 | 1943 | |
aoqi@1 | 1944 | Register end = t2; |
aoqi@1 | 1945 | #ifndef OPT_THREAD |
aoqi@1 | 1946 | Register thread = t1; |
aoqi@1 | 1947 | get_thread(thread); |
aoqi@1 | 1948 | #else |
aoqi@1 | 1949 | Register thread = TREG; |
aoqi@1 | 1950 | #endif |
aoqi@1 | 1951 | verify_tlab(t1, t2);//blows t1&t2 |
aoqi@1 | 1952 | |
aoqi@1 | 1953 | ld_ptr(obj, thread, in_bytes(JavaThread::tlab_top_offset())); |
aoqi@1 | 1954 | |
aoqi@1 | 1955 | if (var_size_in_bytes == NOREG) { |
aoqi@1 | 1956 | // i dont think we need move con_size_in_bytes to a register first. |
aoqi@1 | 1957 | // by yjl 8/17/2005 |
aoqi@1 | 1958 | assert(is_simm16(con_size_in_bytes), "fixme by moving imm to a register first"); |
aoqi@1 | 1959 | addi(end, obj, con_size_in_bytes); |
aoqi@1 | 1960 | } else { |
aoqi@1 | 1961 | add(end, obj, var_size_in_bytes); |
aoqi@1 | 1962 | } |
aoqi@1 | 1963 | |
aoqi@1 | 1964 | ld_ptr(AT, thread, in_bytes(JavaThread::tlab_end_offset())); |
aoqi@1 | 1965 | sltu(AT, AT, end); |
aoqi@1 | 1966 | bne_far(AT, R0, slow_case); |
aoqi@1 | 1967 | delayed()->nop(); |
aoqi@1 | 1968 | |
aoqi@1 | 1969 | |
aoqi@1 | 1970 | // update the tlab top pointer |
aoqi@1 | 1971 | st_ptr(end, thread, in_bytes(JavaThread::tlab_top_offset())); |
aoqi@1 | 1972 | |
aoqi@1 | 1973 | // recover var_size_in_bytes if necessary |
aoqi@1 | 1974 | /*if (var_size_in_bytes == end) { |
aoqi@1 | 1975 | sub(var_size_in_bytes, end, obj); |
aoqi@1 | 1976 | }*/ |
aoqi@1 | 1977 | |
aoqi@1 | 1978 | verify_tlab(t1, t2); |
aoqi@1 | 1979 | } |
aoqi@1 | 1980 | |
aoqi@1 | 1981 | // Defines obj, preserves var_size_in_bytes |
aoqi@1 | 1982 | void MacroAssembler::eden_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, |
aoqi@1 | 1983 | Register t1, Register t2, Label& slow_case) { |
aoqi@1 | 1984 | assert_different_registers(obj, var_size_in_bytes, t1, AT); |
aoqi@1 | 1985 | if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) { //by yyq |
aoqi@1 | 1986 | // No allocation in the shared eden. |
aoqi@1 | 1987 | b_far(slow_case); |
aoqi@1 | 1988 | delayed()->nop(); |
aoqi@1 | 1989 | } else { |
aoqi@1 | 1990 | |
aoqi@1 | 1991 | #ifndef _LP64 |
aoqi@1 | 1992 | Address heap_top(t1, Assembler::split_low((intptr_t)Universe::heap()->top_addr())); |
aoqi@1 | 1993 | lui(t1, split_high((intptr_t)Universe::heap()->top_addr())); |
aoqi@1 | 1994 | #else |
aoqi@1 | 1995 | Address heap_top(t1); |
aoqi@1 | 1996 | li(t1, (long)Universe::heap()->top_addr()); |
aoqi@1 | 1997 | #endif |
aoqi@1 | 1998 | ld_ptr(obj, heap_top); |
aoqi@1 | 1999 | |
aoqi@1 | 2000 | Register end = t2; |
aoqi@1 | 2001 | Label retry; |
aoqi@1 | 2002 | |
aoqi@1 | 2003 | bind(retry); |
aoqi@1 | 2004 | if (var_size_in_bytes == NOREG) { |
aoqi@1 | 2005 | // i dont think we need move con_size_in_bytes to a register first. |
aoqi@1 | 2006 | // by yjl 8/17/2005 |
aoqi@1 | 2007 | assert(is_simm16(con_size_in_bytes), "fixme by moving imm to a register first"); |
aoqi@1 | 2008 | addi(end, obj, con_size_in_bytes); |
aoqi@1 | 2009 | } else { |
aoqi@1 | 2010 | add(end, obj, var_size_in_bytes); |
aoqi@1 | 2011 | } |
aoqi@1 | 2012 | // if end < obj then we wrapped around => object too long => slow case |
aoqi@1 | 2013 | sltu(AT, end, obj); |
aoqi@1 | 2014 | bne_far(AT, R0, slow_case); |
aoqi@1 | 2015 | delayed()->nop(); |
aoqi@1 | 2016 | |
aoqi@1 | 2017 | //lui(AT, split_high((int)Universe::heap()->end_addr())); |
aoqi@1 | 2018 | //lw(AT, AT, split_low((int)Universe::heap()->end_addr())); |
aoqi@1 | 2019 | li(AT, (long)Universe::heap()->end_addr()); |
aoqi@1 | 2020 | sltu(AT, AT, end); |
aoqi@1 | 2021 | bne_far(AT, R0, slow_case); |
aoqi@1 | 2022 | delayed()->nop(); |
aoqi@1 | 2023 | // Compare obj with the top addr, and if still equal, store the new top addr in |
aoqi@1 | 2024 | // end at the address of the top addr pointer. Sets ZF if was equal, and clears |
aoqi@1 | 2025 | // it otherwise. Use lock prefix for atomicity on MPs. |
aoqi@1 | 2026 | if (os::is_MP()) { |
aoqi@1 | 2027 | ///lock(); |
aoqi@1 | 2028 | } |
aoqi@1 | 2029 | |
aoqi@1 | 2030 | // if someone beat us on the allocation, try again, otherwise continue |
aoqi@1 | 2031 | cmpxchg(end, heap_top, obj); |
aoqi@1 | 2032 | beq_far(AT, R0, retry); //by yyq |
aoqi@1 | 2033 | delayed()->nop(); |
aoqi@1 | 2034 | |
aoqi@1 | 2035 | } |
aoqi@1 | 2036 | } |
aoqi@1 | 2037 | |
aoqi@1 | 2038 | void MacroAssembler::tlab_refill(Label& retry, Label& try_eden, Label& slow_case) { |
aoqi@1 | 2039 | Register top = T0; |
aoqi@1 | 2040 | Register t1 = T1; |
aoqi@1 | 2041 | /* Jin: tlab_refill() is called in |
aoqi@1 | 2042 | |
aoqi@1 | 2043 | [c1_Runtime1_mips.cpp] Runtime1::generate_code_for(new_type_array_id); |
aoqi@1 | 2044 | |
aoqi@1 | 2045 | In generate_code_for(), T2 has been assigned as a register(length), which is used |
aoqi@1 | 2046 | after calling tlab_refill(); |
aoqi@1 | 2047 | Therefore, tlab_refill() should not use T2. |
aoqi@1 | 2048 | |
aoqi@1 | 2049 | Source: |
aoqi@1 | 2050 | |
aoqi@1 | 2051 | Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException |
aoqi@1 | 2052 | at java.lang.System.arraycopy(Native Method) |
aoqi@1 | 2053 | at java.util.Arrays.copyOf(Arrays.java:2799) <-- alloc_array |
aoqi@1 | 2054 | at sun.misc.Resource.getBytes(Resource.java:117) |
aoqi@1 | 2055 | at java.net.URLClassLoader.defineClass(URLClassLoader.java:273) |
aoqi@1 | 2056 | at java.net.URLClassLoader.findClass(URLClassLoader.java:205) |
aoqi@1 | 2057 | at java.lang.ClassLoader.loadClass(ClassLoader.java:321) |
aoqi@1 | 2058 | */ |
aoqi@1 | 2059 | Register t2 = T9; |
aoqi@1 | 2060 | Register t3 = T3; |
aoqi@1 | 2061 | Register thread_reg = T8; |
aoqi@1 | 2062 | Label do_refill, discard_tlab; |
aoqi@1 | 2063 | if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) { //by yyq |
aoqi@1 | 2064 | // No allocation in the shared eden. |
aoqi@1 | 2065 | b(slow_case); |
aoqi@1 | 2066 | delayed()->nop(); |
aoqi@1 | 2067 | } |
aoqi@1 | 2068 | |
aoqi@1 | 2069 | get_thread(thread_reg); |
aoqi@1 | 2070 | |
aoqi@1 | 2071 | ld_ptr(top, thread_reg, in_bytes(JavaThread::tlab_top_offset())); |
aoqi@1 | 2072 | ld_ptr(t1, thread_reg, in_bytes(JavaThread::tlab_end_offset())); |
aoqi@1 | 2073 | |
aoqi@1 | 2074 | // calculate amount of free space |
aoqi@1 | 2075 | sub(t1, t1, top); |
aoqi@1 | 2076 | shr(t1, LogHeapWordSize); |
aoqi@1 | 2077 | |
aoqi@1 | 2078 | // Retain tlab and allocate object in shared space if |
aoqi@1 | 2079 | // the amount free in the tlab is too large to discard. |
aoqi@1 | 2080 | ld_ptr(t2, thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())); |
aoqi@1 | 2081 | slt(AT, t2, t1); |
aoqi@1 | 2082 | beq(AT, R0, discard_tlab); |
aoqi@1 | 2083 | delayed()->nop(); |
aoqi@1 | 2084 | |
aoqi@1 | 2085 | // Retain |
aoqi@1 | 2086 | |
aoqi@1 | 2087 | #ifndef _LP64 |
aoqi@1 | 2088 | move(AT, ThreadLocalAllocBuffer::refill_waste_limit_increment()); |
aoqi@1 | 2089 | #else |
aoqi@1 | 2090 | li(AT, ThreadLocalAllocBuffer::refill_waste_limit_increment()); |
aoqi@1 | 2091 | #endif |
aoqi@1 | 2092 | add(t2, t2, AT); |
aoqi@1 | 2093 | st_ptr(t2, thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())); |
aoqi@1 | 2094 | |
aoqi@1 | 2095 | if (TLABStats) { |
aoqi@1 | 2096 | // increment number of slow_allocations |
aoqi@1 | 2097 | lw(AT, thread_reg, in_bytes(JavaThread::tlab_slow_allocations_offset())); |
aoqi@1 | 2098 | addiu(AT, AT, 1); |
aoqi@1 | 2099 | sw(AT, thread_reg, in_bytes(JavaThread::tlab_slow_allocations_offset())); |
aoqi@1 | 2100 | } |
aoqi@1 | 2101 | b(try_eden); |
aoqi@1 | 2102 | delayed()->nop(); |
aoqi@1 | 2103 | |
aoqi@1 | 2104 | bind(discard_tlab); |
aoqi@1 | 2105 | if (TLABStats) { |
aoqi@1 | 2106 | // increment number of refills |
aoqi@1 | 2107 | lw(AT, thread_reg, in_bytes(JavaThread::tlab_number_of_refills_offset())); |
aoqi@1 | 2108 | addi(AT, AT, 1); |
aoqi@1 | 2109 | sw(AT, thread_reg, in_bytes(JavaThread::tlab_number_of_refills_offset())); |
aoqi@1 | 2110 | // accumulate wastage -- t1 is amount free in tlab |
aoqi@1 | 2111 | lw(AT, thread_reg, in_bytes(JavaThread::tlab_fast_refill_waste_offset())); |
aoqi@1 | 2112 | add(AT, AT, t1); |
aoqi@1 | 2113 | sw(AT, thread_reg, in_bytes(JavaThread::tlab_fast_refill_waste_offset())); |
aoqi@1 | 2114 | } |
aoqi@1 | 2115 | |
aoqi@1 | 2116 | // if tlab is currently allocated (top or end != null) then |
aoqi@1 | 2117 | // fill [top, end + alignment_reserve) with array object |
aoqi@1 | 2118 | beq(top, R0, do_refill); |
aoqi@1 | 2119 | delayed()->nop(); |
aoqi@1 | 2120 | |
aoqi@1 | 2121 | // set up the mark word |
aoqi@1 | 2122 | li(AT, (long)markOopDesc::prototype()->copy_set_hash(0x2)); |
aoqi@1 | 2123 | st_ptr(AT, top, oopDesc::mark_offset_in_bytes()); |
aoqi@1 | 2124 | |
aoqi@1 | 2125 | // set the length to the remaining space |
aoqi@1 | 2126 | addi(t1, t1, - typeArrayOopDesc::header_size(T_INT)); |
aoqi@1 | 2127 | addi(t1, t1, ThreadLocalAllocBuffer::alignment_reserve()); |
aoqi@1 | 2128 | shl(t1, log2_intptr(HeapWordSize/sizeof(jint))); |
aoqi@1 | 2129 | sw(t1, top, arrayOopDesc::length_offset_in_bytes()); |
aoqi@1 | 2130 | |
aoqi@1 | 2131 | // set klass to intArrayKlass |
aoqi@1 | 2132 | #ifndef _LP64 |
aoqi@1 | 2133 | lui(AT, split_high((intptr_t)Universe::intArrayKlassObj_addr())); |
aoqi@1 | 2134 | lw(t1, AT, split_low((intptr_t)Universe::intArrayKlassObj_addr())); |
aoqi@1 | 2135 | #else |
aoqi@1 | 2136 | li(AT, (intptr_t)Universe::intArrayKlassObj_addr()); |
aoqi@1 | 2137 | ld_ptr(t1, AT, 0); |
aoqi@1 | 2138 | #endif |
aoqi@1 | 2139 | //st_ptr(t1, top, oopDesc::klass_offset_in_bytes()); |
aoqi@1 | 2140 | store_klass(top, t1); |
aoqi@1 | 2141 | |
aoqi@1 | 2142 | // refill the tlab with an eden allocation |
aoqi@1 | 2143 | bind(do_refill); |
aoqi@1 | 2144 | ld_ptr(t1, thread_reg, in_bytes(JavaThread::tlab_size_offset())); |
aoqi@1 | 2145 | shl(t1, LogHeapWordSize); |
aoqi@1 | 2146 | // add object_size ?? |
aoqi@1 | 2147 | eden_allocate(top, t1, 0, t2, t3, slow_case); |
aoqi@1 | 2148 | |
aoqi@1 | 2149 | // Check that t1 was preserved in eden_allocate. |
aoqi@1 | 2150 | #ifdef ASSERT |
aoqi@1 | 2151 | if (UseTLAB) { |
aoqi@1 | 2152 | Label ok; |
aoqi@1 | 2153 | assert_different_registers(thread_reg, t1); |
aoqi@1 | 2154 | ld_ptr(AT, thread_reg, in_bytes(JavaThread::tlab_size_offset())); |
aoqi@1 | 2155 | shl(AT, LogHeapWordSize); |
aoqi@1 | 2156 | beq(AT, t1, ok); |
aoqi@1 | 2157 | delayed()->nop(); |
aoqi@1 | 2158 | stop("assert(t1 != tlab size)"); |
aoqi@1 | 2159 | should_not_reach_here(); |
aoqi@1 | 2160 | |
aoqi@1 | 2161 | bind(ok); |
aoqi@1 | 2162 | } |
aoqi@1 | 2163 | #endif |
aoqi@1 | 2164 | st_ptr(top, thread_reg, in_bytes(JavaThread::tlab_start_offset())); |
aoqi@1 | 2165 | st_ptr(top, thread_reg, in_bytes(JavaThread::tlab_top_offset())); |
aoqi@1 | 2166 | add(top, top, t1); |
aoqi@1 | 2167 | addi(top, top, - ThreadLocalAllocBuffer::alignment_reserve_in_bytes()); |
aoqi@1 | 2168 | st_ptr(top, thread_reg, in_bytes(JavaThread::tlab_end_offset())); |
aoqi@1 | 2169 | verify_tlab(t1, t2); |
aoqi@1 | 2170 | b(retry); |
aoqi@1 | 2171 | delayed()->nop(); |
aoqi@1 | 2172 | } |
aoqi@1 | 2173 | |
aoqi@1 | 2174 | static const double pi_4 = 0.7853981633974483; |
aoqi@1 | 2175 | |
aoqi@1 | 2176 | // the x86 version is to clumsy, i dont think we need that fuss. maybe i'm wrong, FIXME |
aoqi@1 | 2177 | // must get argument(a double) in F12/F13 |
aoqi@1 | 2178 | //void MacroAssembler::trigfunc(char trig, bool preserve_cpu_regs, int num_fpu_regs_in_use) { |
aoqi@1 | 2179 | //We need to preseve the register which maybe modified during the Call @Jerome |
aoqi@1 | 2180 | void MacroAssembler::trigfunc(char trig, int num_fpu_regs_in_use) { |
aoqi@1 | 2181 | //save all modified register here |
aoqi@1 | 2182 | // if (preserve_cpu_regs) { |
aoqi@1 | 2183 | // } |
aoqi@1 | 2184 | //FIXME, in the disassembly of tirgfunc, only used V0,V1,T9, SP,RA,so we ony save V0,V1,T9 |
aoqi@1 | 2185 | pushad(); |
aoqi@1 | 2186 | //we should preserve the stack space before we call |
aoqi@1 | 2187 | addi(SP, SP, -wordSize * 2); |
aoqi@1 | 2188 | switch (trig){ |
aoqi@1 | 2189 | case 's' : |
aoqi@1 | 2190 | call( CAST_FROM_FN_PTR(address, SharedRuntime::dsin), relocInfo::runtime_call_type ); |
aoqi@1 | 2191 | delayed()->nop(); |
aoqi@1 | 2192 | break; |
aoqi@1 | 2193 | case 'c': |
aoqi@1 | 2194 | call( CAST_FROM_FN_PTR(address, SharedRuntime::dcos), relocInfo::runtime_call_type ); |
aoqi@1 | 2195 | delayed()->nop(); |
aoqi@1 | 2196 | break; |
aoqi@1 | 2197 | case 't': |
aoqi@1 | 2198 | call( CAST_FROM_FN_PTR(address, SharedRuntime::dtan), relocInfo::runtime_call_type ); |
aoqi@1 | 2199 | delayed()->nop(); |
aoqi@1 | 2200 | break; |
aoqi@1 | 2201 | default:assert (false, "bad intrinsic"); |
aoqi@1 | 2202 | break; |
aoqi@1 | 2203 | |
aoqi@1 | 2204 | } |
aoqi@1 | 2205 | |
aoqi@1 | 2206 | addi(SP, SP, wordSize * 2); |
aoqi@1 | 2207 | popad(); |
aoqi@1 | 2208 | // if (preserve_cpu_regs) { |
aoqi@1 | 2209 | // } |
aoqi@1 | 2210 | } |
aoqi@1 | 2211 | /* |
aoqi@1 | 2212 | |
aoqi@1 | 2213 | void MacroAssembler::ucomisd(XMMRegister dst, AddressLiteral src) { |
aoqi@1 | 2214 | ucomisd(dst, as_Address(src)); |
aoqi@1 | 2215 | } |
aoqi@1 | 2216 | |
aoqi@1 | 2217 | void MacroAssembler::ucomiss(XMMRegister dst, AddressLiteral src) { |
aoqi@1 | 2218 | ucomiss(dst, as_Address(src)); |
aoqi@1 | 2219 | } |
aoqi@1 | 2220 | |
aoqi@1 | 2221 | void MacroAssembler::xorpd(XMMRegister dst, AddressLiteral src) { |
aoqi@1 | 2222 | if (reachable(src)) { |
aoqi@1 | 2223 | xorpd(dst, as_Address(src)); |
aoqi@1 | 2224 | } else { |
aoqi@1 | 2225 | lea(rscratch1, src); |
aoqi@1 | 2226 | xorpd(dst, Address(rscratch1, 0)); |
aoqi@1 | 2227 | } |
aoqi@1 | 2228 | } |
aoqi@1 | 2229 | |
aoqi@1 | 2230 | void MacroAssembler::xorps(XMMRegister dst, AddressLiteral src) { |
aoqi@1 | 2231 | if (reachable(src)) { |
aoqi@1 | 2232 | xorps(dst, as_Address(src)); |
aoqi@1 | 2233 | } else { |
aoqi@1 | 2234 | lea(rscratch1, src); |
aoqi@1 | 2235 | xorps(dst, Address(rscratch1, 0)); |
aoqi@1 | 2236 | } |
aoqi@1 | 2237 | } |
aoqi@1 | 2238 | */ |
aoqi@1 | 2239 | |
aoqi@1 | 2240 | #ifdef _LP64 |
aoqi@1 | 2241 | void MacroAssembler::li(Register rd, long imm) { |
aoqi@1 | 2242 | if (imm <= max_jint && imm >= min_jint) { |
aoqi@1 | 2243 | li32(rd, (int)imm); |
aoqi@1 | 2244 | } else if (julong(imm) <= 0xFFFFFFFF) { |
aoqi@1 | 2245 | assert_not_delayed(); |
aoqi@1 | 2246 | // lui sign-extends, so we can't use that. |
aoqi@1 | 2247 | ori(rd, R0, julong(imm) >> 16); |
aoqi@1 | 2248 | dsll(rd, rd, 16); |
aoqi@1 | 2249 | ori(rd, rd, split_low(imm)); |
aoqi@1 | 2250 | //aoqi_test |
aoqi@1 | 2251 | //} else if ((imm > 0) && ((imm >> 48) == 0)) { |
aoqi@1 | 2252 | } else if ((imm > 0) && is_simm16(imm >> 32)) { |
aoqi@1 | 2253 | /* A 48-bit address */ |
aoqi@1 | 2254 | li48(rd, imm); |
aoqi@1 | 2255 | } else { |
aoqi@1 | 2256 | li64(rd, imm); |
aoqi@1 | 2257 | } |
aoqi@1 | 2258 | } |
aoqi@1 | 2259 | #else |
aoqi@1 | 2260 | void MacroAssembler::li(Register rd, long imm) { |
aoqi@1 | 2261 | li32(rd, (int)imm); |
aoqi@1 | 2262 | } |
aoqi@1 | 2263 | #endif |
aoqi@1 | 2264 | |
aoqi@1 | 2265 | void MacroAssembler::li32(Register reg, int imm) { |
aoqi@1 | 2266 | if (is_simm16(imm)) { |
aoqi@1 | 2267 | /* Jin: for imm < 0, we should use addi instead of addiu. |
aoqi@1 | 2268 | * |
aoqi@1 | 2269 | * java.lang.StringCoding$StringDecoder.decode(jobject, jint, jint) |
aoqi@1 | 2270 | * |
aoqi@1 | 2271 | * 78 move [int:-1|I] [a0|I] |
aoqi@1 | 2272 | * : daddi a0, zero, 0xffffffff (correct) |
aoqi@1 | 2273 | * : daddiu a0, zero, 0xffffffff (incorrect) |
aoqi@1 | 2274 | */ |
aoqi@1 | 2275 | if (imm >= 0) |
aoqi@1 | 2276 | addiu(reg, R0, imm); |
aoqi@1 | 2277 | else |
aoqi@1 | 2278 | addi(reg, R0, imm); |
aoqi@1 | 2279 | } else { |
aoqi@1 | 2280 | lui(reg, split_low(imm >> 16)); |
aoqi@1 | 2281 | if (split_low(imm)) |
aoqi@1 | 2282 | ori(reg, reg, split_low(imm)); |
aoqi@1 | 2283 | } |
aoqi@1 | 2284 | } |
aoqi@1 | 2285 | |
aoqi@1 | 2286 | #ifdef _LP64 |
aoqi@1 | 2287 | void MacroAssembler::li64(Register rd, long imm) { |
aoqi@1 | 2288 | assert_not_delayed(); |
aoqi@1 | 2289 | lui(rd, imm >> 48); |
aoqi@1 | 2290 | ori(rd, rd, split_low(imm >> 32)); |
aoqi@1 | 2291 | dsll(rd, rd, 16); |
aoqi@1 | 2292 | ori(rd, rd, split_low(imm >> 16)); |
aoqi@1 | 2293 | dsll(rd, rd, 16); |
aoqi@1 | 2294 | ori(rd, rd, split_low(imm)); |
aoqi@1 | 2295 | } |
aoqi@1 | 2296 | |
aoqi@1 | 2297 | void MacroAssembler::li48(Register rd, long imm) { |
aoqi@1 | 2298 | assert(is_simm16(imm >> 32), "Not a 48-bit address"); |
aoqi@1 | 2299 | lui(rd, imm >> 32); |
aoqi@1 | 2300 | ori(rd, rd, split_low(imm >> 16)); |
aoqi@1 | 2301 | dsll(rd, rd, 16); |
aoqi@1 | 2302 | ori(rd, rd, split_low(imm)); |
aoqi@1 | 2303 | } |
aoqi@1 | 2304 | #endif |
aoqi@1 | 2305 | // NOTE: i dont push eax as i486. |
aoqi@1 | 2306 | // the x86 save eax for it use eax as the jump register |
aoqi@1 | 2307 | void MacroAssembler::verify_oop(Register reg, const char* s) { |
aoqi@1 | 2308 | /* |
aoqi@1 | 2309 | if (!VerifyOops) return; |
aoqi@1 | 2310 | |
aoqi@1 | 2311 | // Pass register number to verify_oop_subroutine |
aoqi@1 | 2312 | char* b = new char[strlen(s) + 50]; |
aoqi@1 | 2313 | sprintf(b, "verify_oop: %s: %s", reg->name(), s); |
aoqi@1 | 2314 | push(rax); // save rax, |
aoqi@1 | 2315 | push(reg); // pass register argument |
aoqi@1 | 2316 | ExternalAddress buffer((address) b); |
aoqi@1 | 2317 | // avoid using pushptr, as it modifies scratch registers |
aoqi@1 | 2318 | // and our contract is not to modify anything |
aoqi@1 | 2319 | movptr(rax, buffer.addr()); |
aoqi@1 | 2320 | push(rax); |
aoqi@1 | 2321 | // call indirectly to solve generation ordering problem |
aoqi@1 | 2322 | movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address())); |
aoqi@1 | 2323 | call(rax); |
aoqi@1 | 2324 | */ |
aoqi@1 | 2325 | if (!VerifyOops) return; |
aoqi@1 | 2326 | const char * b = NULL; |
aoqi@1 | 2327 | stringStream ss; |
aoqi@1 | 2328 | ss.print("verify_oop: %s: %s", reg->name(), s); |
aoqi@1 | 2329 | b = code_string(ss.as_string()); |
aoqi@1 | 2330 | #ifdef _LP64 |
aoqi@1 | 2331 | pushad(); |
aoqi@1 | 2332 | move(A1, reg); |
aoqi@1 | 2333 | li(A0, (long)b); |
aoqi@1 | 2334 | li(AT, (long)StubRoutines::verify_oop_subroutine_entry_address()); |
aoqi@1 | 2335 | ld(T9, AT, 0); |
aoqi@1 | 2336 | jalr(T9); |
aoqi@1 | 2337 | delayed()->nop(); |
aoqi@1 | 2338 | popad(); |
aoqi@1 | 2339 | #else |
aoqi@1 | 2340 | // Pass register number to verify_oop_subroutine |
aoqi@1 | 2341 | sw(T0, SP, - wordSize); |
aoqi@1 | 2342 | sw(T1, SP, - 2*wordSize); |
aoqi@1 | 2343 | sw(RA, SP, - 3*wordSize); |
aoqi@1 | 2344 | sw(A0, SP ,- 4*wordSize); |
aoqi@1 | 2345 | sw(A1, SP ,- 5*wordSize); |
aoqi@1 | 2346 | sw(AT, SP ,- 6*wordSize); |
aoqi@1 | 2347 | sw(T9, SP ,- 7*wordSize); |
aoqi@1 | 2348 | addiu(SP, SP, - 7 * wordSize); |
aoqi@1 | 2349 | move(A1, reg); |
aoqi@1 | 2350 | li(A0, (long)b); |
aoqi@1 | 2351 | // call indirectly to solve generation ordering problem |
aoqi@1 | 2352 | li(AT, (long)StubRoutines::verify_oop_subroutine_entry_address()); |
aoqi@1 | 2353 | lw(T9, AT, 0); |
aoqi@1 | 2354 | jalr(T9); |
aoqi@1 | 2355 | delayed()->nop(); |
aoqi@1 | 2356 | lw(T0, SP, 6* wordSize); |
aoqi@1 | 2357 | lw(T1, SP, 5* wordSize); |
aoqi@1 | 2358 | lw(RA, SP, 4* wordSize); |
aoqi@1 | 2359 | lw(A0, SP, 3* wordSize); |
aoqi@1 | 2360 | lw(A1, SP, 2* wordSize); |
aoqi@1 | 2361 | lw(AT, SP, 1* wordSize); |
aoqi@1 | 2362 | lw(T9, SP, 0* wordSize); |
aoqi@1 | 2363 | addiu(SP, SP, 7 * wordSize); |
aoqi@1 | 2364 | #endif |
aoqi@1 | 2365 | } |
aoqi@1 | 2366 | |
aoqi@1 | 2367 | |
aoqi@1 | 2368 | void MacroAssembler::verify_oop_addr(Address addr, const char* s) { |
aoqi@1 | 2369 | if (!VerifyOops) { |
aoqi@1 | 2370 | nop(); |
aoqi@1 | 2371 | return; |
aoqi@1 | 2372 | } |
aoqi@1 | 2373 | // Pass register number to verify_oop_subroutine |
aoqi@1 | 2374 | const char * b = NULL; |
aoqi@1 | 2375 | stringStream ss; |
aoqi@1 | 2376 | ss.print("verify_oop_addr: %s", s); |
aoqi@1 | 2377 | b = code_string(ss.as_string()); |
aoqi@1 | 2378 | |
aoqi@1 | 2379 | st_ptr(T0, SP, - wordSize); |
aoqi@1 | 2380 | st_ptr(T1, SP, - 2*wordSize); |
aoqi@1 | 2381 | st_ptr(RA, SP, - 3*wordSize); |
aoqi@1 | 2382 | st_ptr(A0, SP, - 4*wordSize); |
aoqi@1 | 2383 | st_ptr(A1, SP, - 5*wordSize); |
aoqi@1 | 2384 | st_ptr(AT, SP, - 6*wordSize); |
aoqi@1 | 2385 | st_ptr(T9, SP, - 7*wordSize); |
aoqi@1 | 2386 | ld_ptr(A1, addr); // addr may use SP, so load from it before change SP |
aoqi@1 | 2387 | addiu(SP, SP, - 7 * wordSize); |
aoqi@1 | 2388 | |
aoqi@1 | 2389 | li(A0, (long)b); |
aoqi@1 | 2390 | // call indirectly to solve generation ordering problem |
aoqi@1 | 2391 | li(AT, (long)StubRoutines::verify_oop_subroutine_entry_address()); |
aoqi@1 | 2392 | ld_ptr(T9, AT, 0); |
aoqi@1 | 2393 | jalr(T9); |
aoqi@1 | 2394 | delayed()->nop(); |
aoqi@1 | 2395 | ld_ptr(T0, SP, 6* wordSize); |
aoqi@1 | 2396 | ld_ptr(T1, SP, 5* wordSize); |
aoqi@1 | 2397 | ld_ptr(RA, SP, 4* wordSize); |
aoqi@1 | 2398 | ld_ptr(A0, SP, 3* wordSize); |
aoqi@1 | 2399 | ld_ptr(A1, SP, 2* wordSize); |
aoqi@1 | 2400 | ld_ptr(AT, SP, 1* wordSize); |
aoqi@1 | 2401 | ld_ptr(T9, SP, 0* wordSize); |
aoqi@1 | 2402 | addiu(SP, SP, 7 * wordSize); |
aoqi@1 | 2403 | } |
aoqi@1 | 2404 | |
aoqi@1 | 2405 | // used registers : T0, T1 |
aoqi@1 | 2406 | void MacroAssembler::verify_oop_subroutine() { |
aoqi@1 | 2407 | // RA: ra |
aoqi@1 | 2408 | // A0: char* error message |
aoqi@1 | 2409 | // A1: oop object to verify |
aoqi@1 | 2410 | |
aoqi@1 | 2411 | Label exit, error; |
aoqi@1 | 2412 | // increment counter |
aoqi@1 | 2413 | li(T0, (long)StubRoutines::verify_oop_count_addr()); |
aoqi@1 | 2414 | lw(AT, T0, 0); |
aoqi@1 | 2415 | #ifdef _LP64 |
aoqi@1 | 2416 | //FIXME, aoqi: rewrite addi, addu, etc in 64bits mode. |
aoqi@1 | 2417 | daddi(AT, AT, 1); |
aoqi@1 | 2418 | #else |
aoqi@1 | 2419 | addi(AT, AT, 1); |
aoqi@1 | 2420 | #endif |
aoqi@1 | 2421 | sw(AT, T0, 0); |
aoqi@1 | 2422 | |
aoqi@1 | 2423 | // make sure object is 'reasonable' |
aoqi@1 | 2424 | beq(A1, R0, exit); // if obj is NULL it is ok |
aoqi@1 | 2425 | delayed()->nop(); |
aoqi@1 | 2426 | |
aoqi@1 | 2427 | // Check if the oop is in the right area of memory |
aoqi@1 | 2428 | //const int oop_mask = Universe::verify_oop_mask(); |
aoqi@1 | 2429 | //const int oop_bits = Universe::verify_oop_bits(); |
aoqi@1 | 2430 | const uintptr_t oop_mask = Universe::verify_oop_mask(); |
aoqi@1 | 2431 | const uintptr_t oop_bits = Universe::verify_oop_bits(); |
aoqi@1 | 2432 | li(AT, oop_mask); |
aoqi@1 | 2433 | andr(T0, A1, AT); |
aoqi@1 | 2434 | li(AT, oop_bits); |
aoqi@1 | 2435 | bne(T0, AT, error); |
aoqi@1 | 2436 | delayed()->nop(); |
aoqi@1 | 2437 | |
aoqi@1 | 2438 | // make sure klass is 'reasonable' |
aoqi@1 | 2439 | //add for compressedoops |
aoqi@1 | 2440 | reinit_heapbase(); |
aoqi@1 | 2441 | //add for compressedoops |
aoqi@1 | 2442 | load_klass(T0, A1); |
aoqi@1 | 2443 | beq(T0, R0, error); // if klass is NULL it is broken |
aoqi@1 | 2444 | delayed()->nop(); |
aoqi@1 | 2445 | #if 0 |
aoqi@1 | 2446 | //FIXME:wuhui. |
aoqi@1 | 2447 | // Check if the klass is in the right area of memory |
aoqi@1 | 2448 | //const int klass_mask = Universe::verify_klass_mask(); |
aoqi@1 | 2449 | //const int klass_bits = Universe::verify_klass_bits(); |
aoqi@1 | 2450 | const uintptr_t klass_mask = Universe::verify_klass_mask(); |
aoqi@1 | 2451 | const uintptr_t klass_bits = Universe::verify_klass_bits(); |
aoqi@1 | 2452 | |
aoqi@1 | 2453 | li(AT, klass_mask); |
aoqi@1 | 2454 | andr(T1, T0, AT); |
aoqi@1 | 2455 | li(AT, klass_bits); |
aoqi@1 | 2456 | bne(T1, AT, error); |
aoqi@1 | 2457 | delayed()->nop(); |
aoqi@1 | 2458 | // make sure klass' klass is 'reasonable' |
aoqi@1 | 2459 | //add for compressedoops |
aoqi@1 | 2460 | load_klass(T0, T0); |
aoqi@1 | 2461 | beq(T0, R0, error); // if klass' klass is NULL it is broken |
aoqi@1 | 2462 | delayed()->nop(); |
aoqi@1 | 2463 | |
aoqi@1 | 2464 | li(AT, klass_mask); |
aoqi@1 | 2465 | andr(T1, T0, AT); |
aoqi@1 | 2466 | li(AT, klass_bits); |
aoqi@1 | 2467 | bne(T1, AT, error); |
aoqi@1 | 2468 | delayed()->nop(); // if klass not in right area of memory it is broken too. |
aoqi@1 | 2469 | #endif |
aoqi@1 | 2470 | // return if everything seems ok |
aoqi@1 | 2471 | bind(exit); |
aoqi@1 | 2472 | |
aoqi@1 | 2473 | jr(RA); |
aoqi@1 | 2474 | delayed()->nop(); |
aoqi@1 | 2475 | |
aoqi@1 | 2476 | // handle errors |
aoqi@1 | 2477 | bind(error); |
aoqi@1 | 2478 | pushad(); |
aoqi@1 | 2479 | #ifndef _LP64 |
aoqi@1 | 2480 | addi(SP, SP, (-1) * wordSize); |
aoqi@1 | 2481 | #endif |
aoqi@1 | 2482 | call(CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); |
aoqi@1 | 2483 | delayed()->nop(); |
aoqi@1 | 2484 | #ifndef _LP64 |
aoqi@1 | 2485 | addiu(SP, SP, 1 * wordSize); |
aoqi@1 | 2486 | #endif |
aoqi@1 | 2487 | popad(); |
aoqi@1 | 2488 | jr(RA); |
aoqi@1 | 2489 | delayed()->nop(); |
aoqi@1 | 2490 | } |
aoqi@1 | 2491 | |
aoqi@1 | 2492 | void MacroAssembler::verify_tlab(Register t1, Register t2) { |
aoqi@1 | 2493 | #ifdef ASSERT |
aoqi@1 | 2494 | assert_different_registers(t1, t2, AT); |
aoqi@1 | 2495 | if (UseTLAB && VerifyOops) { |
aoqi@1 | 2496 | Label next, ok; |
aoqi@1 | 2497 | |
aoqi@1 | 2498 | get_thread(t1); |
aoqi@1 | 2499 | |
aoqi@1 | 2500 | ld_ptr(t2, t1, in_bytes(JavaThread::tlab_top_offset())); |
aoqi@1 | 2501 | ld_ptr(AT, t1, in_bytes(JavaThread::tlab_start_offset())); |
aoqi@1 | 2502 | sltu(AT, t2, AT); |
aoqi@1 | 2503 | beq(AT, R0, next); |
aoqi@1 | 2504 | delayed()->nop(); |
aoqi@1 | 2505 | |
aoqi@1 | 2506 | stop("assert(top >= start)"); |
aoqi@1 | 2507 | |
aoqi@1 | 2508 | bind(next); |
aoqi@1 | 2509 | ld_ptr(AT, t1, in_bytes(JavaThread::tlab_end_offset())); |
aoqi@1 | 2510 | sltu(AT, AT, t2); |
aoqi@1 | 2511 | beq(AT, R0, ok); |
aoqi@1 | 2512 | delayed()->nop(); |
aoqi@1 | 2513 | |
aoqi@1 | 2514 | stop("assert(top <= end)"); |
aoqi@1 | 2515 | |
aoqi@1 | 2516 | bind(ok); |
aoqi@1 | 2517 | |
aoqi@1 | 2518 | /* |
aoqi@1 | 2519 | Label next, ok; |
aoqi@1 | 2520 | Register t1 = rsi; |
aoqi@1 | 2521 | Register thread_reg = NOT_LP64(rbx) LP64_ONLY(r15_thread); |
aoqi@1 | 2522 | |
aoqi@1 | 2523 | push(t1); |
aoqi@1 | 2524 | NOT_LP64(push(thread_reg)); |
aoqi@1 | 2525 | NOT_LP64(get_thread(thread_reg)); |
aoqi@1 | 2526 | |
aoqi@1 | 2527 | movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset()))); |
aoqi@1 | 2528 | cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset()))); |
aoqi@1 | 2529 | jcc(Assembler::aboveEqual, next); |
aoqi@1 | 2530 | stop("assert(top >= start)"); |
aoqi@1 | 2531 | should_not_reach_here(); |
aoqi@1 | 2532 | |
aoqi@1 | 2533 | bind(next); |
aoqi@1 | 2534 | movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset()))); |
aoqi@1 | 2535 | cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset()))); |
aoqi@1 | 2536 | jcc(Assembler::aboveEqual, ok); |
aoqi@1 | 2537 | stop("assert(top <= end)"); |
aoqi@1 | 2538 | should_not_reach_here(); |
aoqi@1 | 2539 | |
aoqi@1 | 2540 | bind(ok); |
aoqi@1 | 2541 | NOT_LP64(pop(thread_reg)); |
aoqi@1 | 2542 | pop(t1); |
aoqi@1 | 2543 | */ |
aoqi@1 | 2544 | } |
aoqi@1 | 2545 | #endif |
aoqi@1 | 2546 | } |
aoqi@1 | 2547 | RegisterOrConstant MacroAssembler::delayed_value_impl(intptr_t* delayed_value_addr, |
aoqi@1 | 2548 | Register tmp, |
aoqi@1 | 2549 | int offset) { |
aoqi@1 | 2550 | intptr_t value = *delayed_value_addr; |
aoqi@1 | 2551 | if (value != 0) |
aoqi@1 | 2552 | return RegisterOrConstant(value + offset); |
aoqi@1 | 2553 | AddressLiteral a(delayed_value_addr); |
aoqi@1 | 2554 | // load indirectly to solve generation ordering problem |
aoqi@1 | 2555 | //movptr(tmp, ExternalAddress((address) delayed_value_addr)); |
aoqi@1 | 2556 | //ld(tmp, a); |
aoqi@1 | 2557 | /* #ifdef ASSERT |
aoqi@1 | 2558 | { Label L; |
aoqi@1 | 2559 | testptr(tmp, tmp); |
aoqi@1 | 2560 | if (WizardMode) { |
aoqi@1 | 2561 | jcc(Assembler::notZero, L); |
aoqi@1 | 2562 | char* buf = new char[40]; |
aoqi@1 | 2563 | sprintf(buf, "DelayedValue="INTPTR_FORMAT, delayed_value_addr[1]); |
aoqi@1 | 2564 | STOP(buf); |
aoqi@1 | 2565 | } else { |
aoqi@1 | 2566 | jccb(Assembler::notZero, L); |
aoqi@1 | 2567 | hlt(); |
aoqi@1 | 2568 | } |
aoqi@1 | 2569 | bind(L); |
aoqi@1 | 2570 | } |
aoqi@1 | 2571 | #endif*/ |
aoqi@1 | 2572 | if (offset != 0) |
aoqi@1 | 2573 | daddi(tmp,tmp, offset); |
aoqi@1 | 2574 | |
aoqi@1 | 2575 | return RegisterOrConstant(tmp); |
aoqi@1 | 2576 | } |
aoqi@1 | 2577 | |
aoqi@1 | 2578 | void MacroAssembler::hswap(Register reg) { |
aoqi@1 | 2579 | //andi(reg, reg, 0xffff); |
aoqi@1 | 2580 | srl(AT, reg, 8); |
aoqi@1 | 2581 | sll(reg, reg, 24); |
aoqi@1 | 2582 | sra(reg, reg, 16); |
aoqi@1 | 2583 | orr(reg, reg, AT); |
aoqi@1 | 2584 | } |
aoqi@1 | 2585 | |
aoqi@1 | 2586 | void MacroAssembler::huswap(Register reg) { |
aoqi@1 | 2587 | #ifdef _LP64 |
aoqi@1 | 2588 | dsrl(AT, reg, 8); |
aoqi@1 | 2589 | dsll(reg, reg, 24); |
aoqi@1 | 2590 | dsrl(reg, reg, 16); |
aoqi@1 | 2591 | orr(reg, reg, AT); |
aoqi@1 | 2592 | andi(reg, reg, 0xffff); |
aoqi@1 | 2593 | #else |
aoqi@1 | 2594 | //andi(reg, reg, 0xffff); |
aoqi@1 | 2595 | srl(AT, reg, 8); |
aoqi@1 | 2596 | sll(reg, reg, 24); |
aoqi@1 | 2597 | srl(reg, reg, 16); |
aoqi@1 | 2598 | orr(reg, reg, AT); |
aoqi@1 | 2599 | #endif |
aoqi@1 | 2600 | } |
aoqi@1 | 2601 | |
aoqi@1 | 2602 | // something funny to do this will only one more register AT |
aoqi@1 | 2603 | // by yjl 6/29/2005 |
aoqi@1 | 2604 | void MacroAssembler::swap(Register reg) { |
aoqi@1 | 2605 | srl(AT, reg, 8); |
aoqi@1 | 2606 | sll(reg, reg, 24); |
aoqi@1 | 2607 | orr(reg, reg, AT); |
aoqi@1 | 2608 | //reg : 4 1 2 3 |
aoqi@1 | 2609 | srl(AT, AT, 16); |
aoqi@1 | 2610 | xorr(AT, AT, reg); |
aoqi@1 | 2611 | andi(AT, AT, 0xff); |
aoqi@1 | 2612 | //AT : 0 0 0 1^3); |
aoqi@1 | 2613 | xorr(reg, reg, AT); |
aoqi@1 | 2614 | //reg : 4 1 2 1 |
aoqi@1 | 2615 | sll(AT, AT, 16); |
aoqi@1 | 2616 | xorr(reg, reg, AT); |
aoqi@1 | 2617 | //reg : 4 3 2 1 |
aoqi@1 | 2618 | } |
aoqi@1 | 2619 | |
aoqi@1 | 2620 | #ifdef _LP64 |
aoqi@1 | 2621 | |
aoqi@1 | 2622 | /* do 32-bit CAS using MIPS64 lld/scd |
aoqi@1 | 2623 | |
aoqi@1 | 2624 | Jin: cas_int should only compare 32-bits of the memory value. |
aoqi@1 | 2625 | However, lld/scd will do 64-bit operation, which violates the intention of cas_int. |
aoqi@1 | 2626 | To simulate a 32-bit atomic operation, the value loaded with LLD should be split into |
aoqi@1 | 2627 | tow halves, and only the low-32 bits is compared. If equals, the low-32 bits of newval, |
aoqi@1 | 2628 | plus the high-32 bits or memory value, are stored togethor with SCD. |
aoqi@1 | 2629 | |
aoqi@1 | 2630 | Example: |
aoqi@1 | 2631 | |
aoqi@1 | 2632 | double d = 3.1415926; |
aoqi@1 | 2633 | System.err.println("hello" + d); |
aoqi@1 | 2634 | |
aoqi@1 | 2635 | sun.misc.FloatingDecimal$1.<init>() |
aoqi@1 | 2636 | | |
aoqi@1 | 2637 | `- java.util.concurrent.atomic.AtomicInteger::compareAndSet() |
aoqi@1 | 2638 | |
aoqi@1 | 2639 | 38 cas_int [a7a7|J] [a0|I] [a6|I] |
aoqi@1 | 2640 | // a0: 0xffffffffe8ea9f63 pc: 0x55647f3354 |
aoqi@1 | 2641 | // a6: 0x4ab325aa |
aoqi@1 | 2642 | |
aoqi@1 | 2643 | again: |
aoqi@1 | 2644 | 0x00000055647f3c5c: lld at, 0x0(a7) ; 64-bit load, "0xe8ea9f63" |
aoqi@1 | 2645 | |
aoqi@1 | 2646 | 0x00000055647f3c60: sll t9, at, 0 ; t9: low-32 bits (sign extended) |
aoqi@1 | 2647 | 0x00000055647f3c64: dsrl32 t8, at, 0 ; t8: high-32 bits |
aoqi@1 | 2648 | 0x00000055647f3c68: dsll32 t8, t8, 0 |
aoqi@1 | 2649 | 0x00000055647f3c6c: bne t9, a0, 0x00000055647f3c9c ; goto nequal |
aoqi@1 | 2650 | 0x00000055647f3c70: sll zero, zero, 0 |
aoqi@1 | 2651 | |
aoqi@1 | 2652 | 0x00000055647f3c74: ori v1, zero, 0xffffffff ; v1: low-32 bits of newval (sign unextended) |
aoqi@1 | 2653 | 0x00000055647f3c78: dsll v1, v1, 16 ; v1 = a6 & 0xFFFFFFFF; |
aoqi@1 | 2654 | 0x00000055647f3c7c: ori v1, v1, 0xffffffff |
aoqi@1 | 2655 | 0x00000055647f3c80: and v1, a6, v1 |
aoqi@1 | 2656 | 0x00000055647f3c84: or at, t8, v1 |
aoqi@1 | 2657 | 0x00000055647f3c88: scd at, 0x0(a7) |
aoqi@1 | 2658 | 0x00000055647f3c8c: beq at, zero, 0x00000055647f3c5c ; goto again |
aoqi@1 | 2659 | 0x00000055647f3c90: sll zero, zero, 0 |
aoqi@1 | 2660 | 0x00000055647f3c94: beq zero, zero, 0x00000055647f45ac ; goto done |
aoqi@1 | 2661 | 0x00000055647f3c98: sll zero, zero, 0 |
aoqi@1 | 2662 | nequal: |
aoqi@1 | 2663 | 0x00000055647f45a4: dadd a0, t9, zero |
aoqi@1 | 2664 | 0x00000055647f45a8: dadd at, zero, zero |
aoqi@1 | 2665 | done: |
aoqi@1 | 2666 | */ |
aoqi@1 | 2667 | |
aoqi@1 | 2668 | void MacroAssembler::cmpxchg32(Register x_reg, Address dest, Register c_reg) { |
aoqi@1 | 2669 | #if 0 |
aoqi@1 | 2670 | Label done, again, nequal; |
aoqi@1 | 2671 | bind(again); |
aoqi@1 | 2672 | |
aoqi@1 | 2673 | sync(); |
aoqi@1 | 2674 | lld(AT, dest); |
aoqi@1 | 2675 | |
aoqi@1 | 2676 | /* T9: 32 bits, sign extended |
aoqi@1 | 2677 | * V1: low 32 bits, sign unextended |
aoqi@1 | 2678 | * T8: high 32 bits (may be another variables's space) |
aoqi@1 | 2679 | */ |
aoqi@1 | 2680 | sll(T9, AT, 0); // Use 32-bit sll to extend bit 31 |
aoqi@1 | 2681 | dsrl32(T8, AT, 0); |
aoqi@1 | 2682 | dsll32(T8, T8, 0); |
aoqi@1 | 2683 | |
aoqi@1 | 2684 | bne(T9, c_reg, nequal); |
aoqi@1 | 2685 | delayed()->nop(); |
aoqi@1 | 2686 | |
aoqi@1 | 2687 | ori(V1, R0, 0xFFFF); |
aoqi@1 | 2688 | dsll(V1, V1, 16); |
aoqi@1 | 2689 | ori(V1, V1, 0xFFFF); |
aoqi@1 | 2690 | andr(V1, x_reg, V1); |
aoqi@1 | 2691 | orr(AT, T8, V1); |
aoqi@1 | 2692 | scd(AT, dest); |
aoqi@1 | 2693 | beq(AT, R0, again); |
aoqi@1 | 2694 | delayed()->nop(); |
aoqi@1 | 2695 | b(done); |
aoqi@1 | 2696 | delayed()->nop(); |
aoqi@1 | 2697 | |
aoqi@1 | 2698 | // not xchged |
aoqi@1 | 2699 | bind(nequal); |
aoqi@1 | 2700 | move(c_reg, T9); |
aoqi@1 | 2701 | move(AT, R0); |
aoqi@1 | 2702 | |
aoqi@1 | 2703 | bind(done); |
aoqi@1 | 2704 | #else |
aoqi@1 | 2705 | |
aoqi@1 | 2706 | /* 2012/11/11 Jin: MIPS64 can use ll/sc for 32-bit atomic memory access */ |
aoqi@1 | 2707 | Label done, again, nequal; |
aoqi@1 | 2708 | |
aoqi@1 | 2709 | bind(again); |
aoqi@1 | 2710 | |
aoqi@1 | 2711 | sync(); |
aoqi@1 | 2712 | ll(AT, dest); |
aoqi@1 | 2713 | bne(AT, c_reg, nequal); |
aoqi@1 | 2714 | delayed()->nop(); |
aoqi@1 | 2715 | |
aoqi@1 | 2716 | move(AT, x_reg); |
aoqi@1 | 2717 | sc(AT, dest); |
aoqi@1 | 2718 | beq(AT, R0, again); |
aoqi@1 | 2719 | delayed()->nop(); |
aoqi@1 | 2720 | b(done); |
aoqi@1 | 2721 | delayed()->nop(); |
aoqi@1 | 2722 | |
aoqi@1 | 2723 | // not xchged |
aoqi@1 | 2724 | bind(nequal); |
aoqi@1 | 2725 | sync(); |
aoqi@1 | 2726 | move(c_reg, AT); |
aoqi@1 | 2727 | move(AT, R0); |
aoqi@1 | 2728 | |
aoqi@1 | 2729 | bind(done); |
aoqi@1 | 2730 | #endif |
aoqi@1 | 2731 | } |
aoqi@1 | 2732 | #endif // cmpxchg32 |
aoqi@1 | 2733 | |
aoqi@1 | 2734 | void MacroAssembler::cmpxchg(Register x_reg, Address dest, Register c_reg) { |
aoqi@1 | 2735 | Label done, again, nequal; |
aoqi@1 | 2736 | |
aoqi@1 | 2737 | bind(again); |
aoqi@1 | 2738 | #ifdef _LP64 |
aoqi@1 | 2739 | sync(); |
aoqi@1 | 2740 | lld(AT, dest); |
aoqi@1 | 2741 | #else |
aoqi@1 | 2742 | sync(); |
aoqi@1 | 2743 | ll(AT, dest); |
aoqi@1 | 2744 | #endif |
aoqi@1 | 2745 | bne(AT, c_reg, nequal); |
aoqi@1 | 2746 | delayed()->nop(); |
aoqi@1 | 2747 | |
aoqi@1 | 2748 | move(AT, x_reg); |
aoqi@1 | 2749 | #ifdef _LP64 |
aoqi@1 | 2750 | scd(AT, dest); |
aoqi@1 | 2751 | #else |
aoqi@1 | 2752 | sc(AT, dest); |
aoqi@1 | 2753 | #endif |
aoqi@1 | 2754 | beq(AT, R0, again); |
aoqi@1 | 2755 | delayed()->nop(); |
aoqi@1 | 2756 | b(done); |
aoqi@1 | 2757 | delayed()->nop(); |
aoqi@1 | 2758 | |
aoqi@1 | 2759 | // not xchged |
aoqi@1 | 2760 | bind(nequal); |
aoqi@1 | 2761 | sync(); |
aoqi@1 | 2762 | move(c_reg, AT); |
aoqi@1 | 2763 | move(AT, R0); |
aoqi@1 | 2764 | |
aoqi@1 | 2765 | bind(done); |
aoqi@1 | 2766 | } |
aoqi@1 | 2767 | |
aoqi@1 | 2768 | void MacroAssembler::cmpxchg8(Register x_regLo, Register x_regHi, Address dest, Register c_regLo, Register c_regHi) { |
aoqi@1 | 2769 | Label done, again, nequal; |
aoqi@1 | 2770 | |
aoqi@1 | 2771 | Register x_reg = x_regLo; |
aoqi@1 | 2772 | dsll32(x_regHi, x_regHi, 0); |
aoqi@1 | 2773 | dsll32(x_regLo, x_regLo, 0); |
aoqi@1 | 2774 | dsrl32(x_regLo, x_regLo, 0); |
aoqi@1 | 2775 | orr(x_reg, x_regLo, x_regHi); |
aoqi@1 | 2776 | |
aoqi@1 | 2777 | Register c_reg = c_regLo; |
aoqi@1 | 2778 | dsll32(c_regHi, c_regHi, 0); |
aoqi@1 | 2779 | dsll32(c_regLo, c_regLo, 0); |
aoqi@1 | 2780 | dsrl32(c_regLo, c_regLo, 0); |
aoqi@1 | 2781 | orr(c_reg, c_regLo, c_regHi); |
aoqi@1 | 2782 | |
aoqi@1 | 2783 | bind(again); |
aoqi@1 | 2784 | |
aoqi@1 | 2785 | sync(); |
aoqi@1 | 2786 | lld(AT, dest); |
aoqi@1 | 2787 | bne(AT, c_reg, nequal); |
aoqi@1 | 2788 | delayed()->nop(); |
aoqi@1 | 2789 | |
aoqi@1 | 2790 | //move(AT, x_reg); |
aoqi@1 | 2791 | dadd(AT, x_reg, R0); |
aoqi@1 | 2792 | scd(AT, dest); |
aoqi@1 | 2793 | beq(AT, R0, again); |
aoqi@1 | 2794 | delayed()->nop(); |
aoqi@1 | 2795 | b(done); |
aoqi@1 | 2796 | delayed()->nop(); |
aoqi@1 | 2797 | |
aoqi@1 | 2798 | // not xchged |
aoqi@1 | 2799 | bind(nequal); |
aoqi@1 | 2800 | sync(); |
aoqi@1 | 2801 | //move(c_reg, AT); |
aoqi@1 | 2802 | //move(AT, R0); |
aoqi@1 | 2803 | dadd(c_reg, AT, R0); |
aoqi@1 | 2804 | dadd(AT, R0, R0); |
aoqi@1 | 2805 | bind(done); |
aoqi@1 | 2806 | } |
aoqi@1 | 2807 | |
aoqi@1 | 2808 | // be sure the three register is different |
aoqi@1 | 2809 | void MacroAssembler::rem_s(FloatRegister fd, FloatRegister fs, FloatRegister ft, FloatRegister tmp) { |
aoqi@1 | 2810 | assert_different_registers(tmp, fs, ft); |
aoqi@1 | 2811 | div_s(tmp, fs, ft); |
aoqi@1 | 2812 | trunc_l_s(tmp, tmp); |
aoqi@1 | 2813 | cvt_s_l(tmp, tmp); |
aoqi@1 | 2814 | mul_s(tmp, tmp, ft); |
aoqi@1 | 2815 | sub_s(fd, fs, tmp); |
aoqi@1 | 2816 | } |
aoqi@1 | 2817 | |
aoqi@1 | 2818 | // be sure the three register is different |
aoqi@1 | 2819 | void MacroAssembler::rem_d(FloatRegister fd, FloatRegister fs, FloatRegister ft, FloatRegister tmp) { |
aoqi@1 | 2820 | assert_different_registers(tmp, fs, ft); |
aoqi@1 | 2821 | div_d(tmp, fs, ft); |
aoqi@1 | 2822 | trunc_l_d(tmp, tmp); |
aoqi@1 | 2823 | cvt_d_l(tmp, tmp); |
aoqi@1 | 2824 | mul_d(tmp, tmp, ft); |
aoqi@1 | 2825 | sub_d(fd, fs, tmp); |
aoqi@1 | 2826 | } |
aoqi@1 | 2827 | |
aoqi@30 | 2828 | // Fast_Lock and Fast_Unlock used by C2 |
aoqi@30 | 2829 | |
aoqi@30 | 2830 | // Because the transitions from emitted code to the runtime |
aoqi@30 | 2831 | // monitorenter/exit helper stubs are so slow it's critical that |
aoqi@30 | 2832 | // we inline both the stack-locking fast-path and the inflated fast path. |
aoqi@30 | 2833 | // |
aoqi@30 | 2834 | // See also: cmpFastLock and cmpFastUnlock. |
aoqi@30 | 2835 | // |
aoqi@30 | 2836 | // What follows is a specialized inline transliteration of the code |
aoqi@30 | 2837 | // in slow_enter() and slow_exit(). If we're concerned about I$ bloat |
aoqi@30 | 2838 | // another option would be to emit TrySlowEnter and TrySlowExit methods |
aoqi@30 | 2839 | // at startup-time. These methods would accept arguments as |
aoqi@30 | 2840 | // (rax,=Obj, rbx=Self, rcx=box, rdx=Scratch) and return success-failure |
aoqi@30 | 2841 | // indications in the icc.ZFlag. Fast_Lock and Fast_Unlock would simply |
aoqi@30 | 2842 | // marshal the arguments and emit calls to TrySlowEnter and TrySlowExit. |
aoqi@30 | 2843 | // In practice, however, the # of lock sites is bounded and is usually small. |
aoqi@30 | 2844 | // Besides the call overhead, TrySlowEnter and TrySlowExit might suffer |
aoqi@30 | 2845 | // if the processor uses simple bimodal branch predictors keyed by EIP |
aoqi@30 | 2846 | // Since the helper routines would be called from multiple synchronization |
aoqi@30 | 2847 | // sites. |
aoqi@30 | 2848 | // |
aoqi@30 | 2849 | // An even better approach would be write "MonitorEnter()" and "MonitorExit()" |
aoqi@30 | 2850 | // in java - using j.u.c and unsafe - and just bind the lock and unlock sites |
aoqi@30 | 2851 | // to those specialized methods. That'd give us a mostly platform-independent |
aoqi@30 | 2852 | // implementation that the JITs could optimize and inline at their pleasure. |
aoqi@30 | 2853 | // Done correctly, the only time we'd need to cross to native could would be |
aoqi@30 | 2854 | // to park() or unpark() threads. We'd also need a few more unsafe operators |
aoqi@30 | 2855 | // to (a) prevent compiler-JIT reordering of non-volatile accesses, and |
aoqi@30 | 2856 | // (b) explicit barriers or fence operations. |
aoqi@30 | 2857 | // |
aoqi@30 | 2858 | // TODO: |
aoqi@30 | 2859 | // |
aoqi@30 | 2860 | // * Arrange for C2 to pass "Self" into Fast_Lock and Fast_Unlock in one of the registers (scr). |
aoqi@30 | 2861 | // This avoids manifesting the Self pointer in the Fast_Lock and Fast_Unlock terminals. |
aoqi@30 | 2862 | // Given TLAB allocation, Self is usually manifested in a register, so passing it into |
aoqi@30 | 2863 | // the lock operators would typically be faster than reifying Self. |
aoqi@30 | 2864 | // |
aoqi@30 | 2865 | // * Ideally I'd define the primitives as: |
aoqi@30 | 2866 | // fast_lock (nax Obj, nax box, EAX tmp, nax scr) where box, tmp and scr are KILLED. |
aoqi@30 | 2867 | // fast_unlock (nax Obj, EAX box, nax tmp) where box and tmp are KILLED |
aoqi@30 | 2868 | // Unfortunately ADLC bugs prevent us from expressing the ideal form. |
aoqi@30 | 2869 | // Instead, we're stuck with a rather awkward and brittle register assignments below. |
aoqi@30 | 2870 | // Furthermore the register assignments are overconstrained, possibly resulting in |
aoqi@30 | 2871 | // sub-optimal code near the synchronization site. |
aoqi@30 | 2872 | // |
aoqi@30 | 2873 | // * Eliminate the sp-proximity tests and just use "== Self" tests instead. |
aoqi@30 | 2874 | // Alternately, use a better sp-proximity test. |
aoqi@30 | 2875 | // |
aoqi@30 | 2876 | // * Currently ObjectMonitor._Owner can hold either an sp value or a (THREAD *) value. |
aoqi@30 | 2877 | // Either one is sufficient to uniquely identify a thread. |
aoqi@30 | 2878 | // TODO: eliminate use of sp in _owner and use get_thread(tr) instead. |
aoqi@30 | 2879 | // |
aoqi@30 | 2880 | // * Intrinsify notify() and notifyAll() for the common cases where the |
aoqi@30 | 2881 | // object is locked by the calling thread but the waitlist is empty. |
aoqi@30 | 2882 | // avoid the expensive JNI call to JVM_Notify() and JVM_NotifyAll(). |
aoqi@30 | 2883 | // |
aoqi@30 | 2884 | // * use jccb and jmpb instead of jcc and jmp to improve code density. |
aoqi@30 | 2885 | // But beware of excessive branch density on AMD Opterons. |
aoqi@30 | 2886 | // |
aoqi@30 | 2887 | // * Both Fast_Lock and Fast_Unlock set the ICC.ZF to indicate success |
aoqi@30 | 2888 | // or failure of the fast-path. If the fast-path fails then we pass |
aoqi@30 | 2889 | // control to the slow-path, typically in C. In Fast_Lock and |
aoqi@30 | 2890 | // Fast_Unlock we often branch to DONE_LABEL, just to find that C2 |
aoqi@30 | 2891 | // will emit a conditional branch immediately after the node. |
aoqi@30 | 2892 | // So we have branches to branches and lots of ICC.ZF games. |
aoqi@30 | 2893 | // Instead, it might be better to have C2 pass a "FailureLabel" |
aoqi@30 | 2894 | // into Fast_Lock and Fast_Unlock. In the case of success, control |
aoqi@30 | 2895 | // will drop through the node. ICC.ZF is undefined at exit. |
aoqi@30 | 2896 | // In the case of failure, the node will branch directly to the |
aoqi@30 | 2897 | // FailureLabel |
aoqi@30 | 2898 | |
aoqi@30 | 2899 | |
aoqi@30 | 2900 | // obj: object to lock |
aoqi@30 | 2901 | // box: on-stack box address (displaced header location) - KILLED |
aoqi@30 | 2902 | // rax,: tmp -- KILLED |
aoqi@30 | 2903 | // scr: tmp -- KILLED |
aoqi@30 | 2904 | void MacroAssembler::fast_lock(Register objReg, Register boxReg, Register tmpReg, Register scrReg) { |
aoqi@30 | 2905 | |
aoqi@30 | 2906 | tmpReg = T8; |
aoqi@30 | 2907 | scrReg = S7; |
aoqi@30 | 2908 | |
aoqi@30 | 2909 | // Ensure the register assignents are disjoint |
aoqi@30 | 2910 | guarantee (objReg != boxReg, "") ; |
aoqi@30 | 2911 | guarantee (objReg != tmpReg, "") ; |
aoqi@30 | 2912 | guarantee (objReg != scrReg, "") ; |
aoqi@30 | 2913 | guarantee (boxReg != tmpReg, "") ; |
aoqi@30 | 2914 | guarantee (boxReg != scrReg, "") ; |
aoqi@30 | 2915 | |
aoqi@30 | 2916 | |
aoqi@30 | 2917 | block_comment("FastLock"); |
aoqi@30 | 2918 | /* |
aoqi@30 | 2919 | __ move(AT, 0x0); |
aoqi@30 | 2920 | return; |
aoqi@30 | 2921 | */ |
aoqi@30 | 2922 | if (PrintBiasedLockingStatistics) { |
aoqi@30 | 2923 | push(tmpReg); |
aoqi@30 | 2924 | atomic_inc32((address)BiasedLocking::total_entry_count_addr(), 1, AT, tmpReg); |
aoqi@30 | 2925 | pop(tmpReg); |
aoqi@30 | 2926 | } |
aoqi@30 | 2927 | |
aoqi@30 | 2928 | if (EmitSync & 1) { |
aoqi@30 | 2929 | // set box->dhw = unused_mark (3) |
aoqi@30 | 2930 | // Force all sync thru slow-path: slow_enter() and slow_exit() |
aoqi@30 | 2931 | move (AT, (int32_t)intptr_t(markOopDesc::unused_mark())); |
aoqi@30 | 2932 | sd(AT, Address(boxReg, 0)); |
aoqi@30 | 2933 | move (AT, (int32_t)0) ; // Eflags.ZF = 0 |
aoqi@30 | 2934 | } else |
aoqi@30 | 2935 | if (EmitSync & 2) { |
aoqi@30 | 2936 | Label DONE_LABEL ; |
aoqi@30 | 2937 | if (UseBiasedLocking) { |
aoqi@30 | 2938 | // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument. |
aoqi@30 | 2939 | biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL); |
aoqi@30 | 2940 | } |
aoqi@30 | 2941 | |
aoqi@30 | 2942 | ld(tmpReg, Address(objReg, 0)) ; // fetch markword |
aoqi@30 | 2943 | ori(tmpReg, tmpReg, 0x1); |
aoqi@30 | 2944 | sd(tmpReg, Address(boxReg, 0)); // Anticipate successful CAS |
aoqi@30 | 2945 | |
aoqi@30 | 2946 | cmpxchg(boxReg, Address(objReg, 0), tmpReg); // Updates tmpReg |
aoqi@30 | 2947 | bne(AT, R0, DONE_LABEL); |
aoqi@30 | 2948 | delayed()->nop(); |
aoqi@30 | 2949 | |
aoqi@30 | 2950 | // Recursive locking |
aoqi@30 | 2951 | dsubu(tmpReg, tmpReg, SP); |
aoqi@30 | 2952 | li(AT, (7 - os::vm_page_size() )); |
aoqi@30 | 2953 | andr(tmpReg, tmpReg, AT); |
aoqi@30 | 2954 | sd(tmpReg, Address(boxReg, 0)); |
aoqi@30 | 2955 | bind(DONE_LABEL) ; |
aoqi@30 | 2956 | } else { |
aoqi@30 | 2957 | // Possible cases that we'll encounter in fast_lock |
aoqi@30 | 2958 | // ------------------------------------------------ |
aoqi@30 | 2959 | // * Inflated |
aoqi@30 | 2960 | // -- unlocked |
aoqi@30 | 2961 | // -- Locked |
aoqi@30 | 2962 | // = by self |
aoqi@30 | 2963 | // = by other |
aoqi@30 | 2964 | // * biased |
aoqi@30 | 2965 | // -- by Self |
aoqi@30 | 2966 | // -- by other |
aoqi@30 | 2967 | // * neutral |
aoqi@30 | 2968 | // * stack-locked |
aoqi@30 | 2969 | // -- by self |
aoqi@30 | 2970 | // = sp-proximity test hits |
aoqi@30 | 2971 | // = sp-proximity test generates false-negative |
aoqi@30 | 2972 | // -- by other |
aoqi@30 | 2973 | // |
aoqi@30 | 2974 | |
aoqi@30 | 2975 | Label IsInflated, DONE_LABEL, PopDone ; |
aoqi@30 | 2976 | |
aoqi@30 | 2977 | // TODO: optimize away redundant LDs of obj->mark and improve the markword triage |
aoqi@30 | 2978 | // order to reduce the number of conditional branches in the most common cases. |
aoqi@30 | 2979 | // Beware -- there's a subtle invariant that fetch of the markword |
aoqi@30 | 2980 | // at [FETCH], below, will never observe a biased encoding (*101b). |
aoqi@30 | 2981 | // If this invariant is not held we risk exclusion (safety) failure. |
aoqi@30 | 2982 | if (UseBiasedLocking && !UseOptoBiasInlining) { |
aoqi@30 | 2983 | biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL); |
aoqi@30 | 2984 | } |
aoqi@30 | 2985 | |
aoqi@30 | 2986 | ld(tmpReg, Address(objReg, 0)) ; //Fetch the markword of the object. |
aoqi@30 | 2987 | andi(AT, tmpReg, 0x02); //If AT == 0x02 ==> the object is inflated, will not use the fast lock method. |
aoqi@30 | 2988 | bne(AT, R0, IsInflated); // Inflated v (Stack-locked or neutral) |
aoqi@30 | 2989 | delayed()->nop(); |
aoqi@30 | 2990 | |
aoqi@30 | 2991 | // Attempt stack-locking ... |
aoqi@30 | 2992 | ori (tmpReg, tmpReg, 0x1); |
aoqi@30 | 2993 | sd(tmpReg, Address(boxReg, 0)); // Anticipate successful CAS |
aoqi@30 | 2994 | |
aoqi@30 | 2995 | cmpxchg(boxReg, Address(objReg, 0), tmpReg); // Updates tmpReg |
aoqi@30 | 2996 | |
aoqi@30 | 2997 | if (PrintBiasedLockingStatistics) { |
aoqi@30 | 2998 | Label L; |
aoqi@30 | 2999 | beq(AT, R0, L); |
aoqi@30 | 3000 | delayed()->nop(); |
aoqi@30 | 3001 | push(T0); |
aoqi@30 | 3002 | push(T1); |
aoqi@30 | 3003 | atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1); |
aoqi@30 | 3004 | pop(T1); |
aoqi@30 | 3005 | pop(T0); |
aoqi@30 | 3006 | bind(L); |
aoqi@30 | 3007 | } |
aoqi@30 | 3008 | bne(AT, R0, DONE_LABEL); |
aoqi@30 | 3009 | delayed()->nop(); |
aoqi@30 | 3010 | |
aoqi@30 | 3011 | // Recursive locking |
aoqi@30 | 3012 | dsubu(tmpReg, tmpReg, SP); |
aoqi@30 | 3013 | li(AT, 7 - os::vm_page_size() ); |
aoqi@30 | 3014 | andr(tmpReg, tmpReg, AT); |
aoqi@30 | 3015 | sd(tmpReg, Address(boxReg, 0)); |
aoqi@30 | 3016 | if (PrintBiasedLockingStatistics) { |
aoqi@30 | 3017 | Label L; |
aoqi@30 | 3018 | // tmpReg == 0 => BiasedLocking::_fast_path_entry_count++ |
aoqi@30 | 3019 | bne(tmpReg, R0, L); |
aoqi@30 | 3020 | delayed()->nop(); |
aoqi@30 | 3021 | push(T0); |
aoqi@30 | 3022 | push(T1); |
aoqi@30 | 3023 | atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1); |
aoqi@30 | 3024 | pop(T1); |
aoqi@30 | 3025 | pop(T0); |
aoqi@30 | 3026 | bind(L); |
aoqi@30 | 3027 | } |
aoqi@30 | 3028 | sltiu(AT, tmpReg, 1); /* AT = (tmpReg == 0) ? 1 : 0 */ |
aoqi@30 | 3029 | |
aoqi@30 | 3030 | b(DONE_LABEL) ; |
aoqi@30 | 3031 | delayed()->nop(); |
aoqi@30 | 3032 | |
aoqi@30 | 3033 | bind(IsInflated) ; |
aoqi@30 | 3034 | |
aoqi@30 | 3035 | // TODO: someday avoid the ST-before-CAS penalty by |
aoqi@30 | 3036 | // relocating (deferring) the following ST. |
aoqi@30 | 3037 | // We should also think about trying a CAS without having |
aoqi@30 | 3038 | // fetched _owner. If the CAS is successful we may |
aoqi@30 | 3039 | // avoid an RTO->RTS upgrade on the $line. |
aoqi@30 | 3040 | // Without cast to int32_t a movptr will destroy r10 which is typically obj |
aoqi@30 | 3041 | li(AT, (int32_t)intptr_t(markOopDesc::unused_mark())); |
aoqi@30 | 3042 | sd(AT, Address(boxReg, 0)); |
aoqi@30 | 3043 | |
aoqi@30 | 3044 | move(boxReg, tmpReg) ; |
aoqi@30 | 3045 | ld(tmpReg, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3046 | sltiu(AT, tmpReg, 1); /* Jin: AT = !tmpReg; */ |
aoqi@30 | 3047 | bne(tmpReg, R0, DONE_LABEL); |
aoqi@30 | 3048 | delayed()->nop(); |
aoqi@30 | 3049 | |
aoqi@30 | 3050 | cmpxchg(TREG, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2), tmpReg) ; |
aoqi@30 | 3051 | // Intentional fall-through into DONE_LABEL ... |
aoqi@30 | 3052 | |
aoqi@30 | 3053 | |
aoqi@30 | 3054 | // DONE_LABEL is a hot target - we'd really like to place it at the |
aoqi@30 | 3055 | // start of cache line by padding with NOPs. |
aoqi@30 | 3056 | // See the AMD and Intel software optimization manuals for the |
aoqi@30 | 3057 | // most efficient "long" NOP encodings. |
aoqi@30 | 3058 | // Unfortunately none of our alignment mechanisms suffice. |
aoqi@30 | 3059 | bind(DONE_LABEL); |
aoqi@30 | 3060 | |
aoqi@30 | 3061 | // Avoid branch-to-branch on AMD processors |
aoqi@30 | 3062 | // This appears to be superstition. |
aoqi@30 | 3063 | if (EmitSync & 32) nop() ; |
aoqi@30 | 3064 | |
aoqi@30 | 3065 | |
aoqi@30 | 3066 | // At DONE_LABEL the icc ZFlag is set as follows ... |
aoqi@30 | 3067 | // Fast_Unlock uses the same protocol. |
aoqi@30 | 3068 | // ZFlag == 1 -> Success |
aoqi@30 | 3069 | // ZFlag == 0 -> Failure - force control through the slow-path |
aoqi@30 | 3070 | } |
aoqi@30 | 3071 | } |
aoqi@30 | 3072 | |
aoqi@30 | 3073 | // obj: object to unlock |
aoqi@30 | 3074 | // box: box address (displaced header location), killed. Must be EAX. |
aoqi@30 | 3075 | // rbx,: killed tmp; cannot be obj nor box. |
aoqi@30 | 3076 | // |
aoqi@30 | 3077 | // Some commentary on balanced locking: |
aoqi@30 | 3078 | // |
aoqi@30 | 3079 | // Fast_Lock and Fast_Unlock are emitted only for provably balanced lock sites. |
aoqi@30 | 3080 | // Methods that don't have provably balanced locking are forced to run in the |
aoqi@30 | 3081 | // interpreter - such methods won't be compiled to use fast_lock and fast_unlock. |
aoqi@30 | 3082 | // The interpreter provides two properties: |
aoqi@30 | 3083 | // I1: At return-time the interpreter automatically and quietly unlocks any |
aoqi@30 | 3084 | // objects acquired the current activation (frame). Recall that the |
aoqi@30 | 3085 | // interpreter maintains an on-stack list of locks currently held by |
aoqi@30 | 3086 | // a frame. |
aoqi@30 | 3087 | // I2: If a method attempts to unlock an object that is not held by the |
aoqi@30 | 3088 | // the frame the interpreter throws IMSX. |
aoqi@30 | 3089 | // |
aoqi@30 | 3090 | // Lets say A(), which has provably balanced locking, acquires O and then calls B(). |
aoqi@30 | 3091 | // B() doesn't have provably balanced locking so it runs in the interpreter. |
aoqi@30 | 3092 | // Control returns to A() and A() unlocks O. By I1 and I2, above, we know that O |
aoqi@30 | 3093 | // is still locked by A(). |
aoqi@30 | 3094 | // |
aoqi@30 | 3095 | // The only other source of unbalanced locking would be JNI. The "Java Native Interface: |
aoqi@30 | 3096 | // Programmer's Guide and Specification" claims that an object locked by jni_monitorenter |
aoqi@30 | 3097 | // should not be unlocked by "normal" java-level locking and vice-versa. The specification |
aoqi@30 | 3098 | // doesn't specify what will occur if a program engages in such mixed-mode locking, however. |
aoqi@30 | 3099 | |
aoqi@30 | 3100 | void MacroAssembler::fast_unlock(Register objReg, Register boxReg, Register tmpReg) { |
aoqi@30 | 3101 | |
aoqi@30 | 3102 | tmpReg = T8; |
aoqi@30 | 3103 | |
aoqi@30 | 3104 | guarantee (objReg != boxReg, "") ; |
aoqi@30 | 3105 | guarantee (objReg != tmpReg, "") ; |
aoqi@30 | 3106 | guarantee (boxReg != tmpReg, "") ; |
aoqi@30 | 3107 | |
aoqi@30 | 3108 | |
aoqi@30 | 3109 | |
aoqi@30 | 3110 | block_comment("FastUnlock"); |
aoqi@30 | 3111 | |
aoqi@30 | 3112 | /* |
aoqi@30 | 3113 | move(AT, 0x0); |
aoqi@30 | 3114 | return; |
aoqi@30 | 3115 | */ |
aoqi@30 | 3116 | |
aoqi@30 | 3117 | if (EmitSync & 4) { |
aoqi@30 | 3118 | // Disable - inhibit all inlining. Force control through the slow-path |
aoqi@30 | 3119 | move(AT, R0); |
aoqi@30 | 3120 | } else |
aoqi@30 | 3121 | if (EmitSync & 8) { |
aoqi@30 | 3122 | Label DONE_LABEL ; |
aoqi@30 | 3123 | if (UseBiasedLocking) { |
aoqi@30 | 3124 | biased_locking_exit(objReg, tmpReg, DONE_LABEL); |
aoqi@30 | 3125 | } |
aoqi@30 | 3126 | // classic stack-locking code ... |
aoqi@30 | 3127 | ld(tmpReg, Address(boxReg, 0)) ; |
aoqi@30 | 3128 | beq(tmpReg, R0, DONE_LABEL) ; |
aoqi@30 | 3129 | move(AT, 0x1); // delay slot |
aoqi@30 | 3130 | |
aoqi@30 | 3131 | cmpxchg(tmpReg, Address(objReg, 0), boxReg); // Uses EAX which is box |
aoqi@30 | 3132 | bind(DONE_LABEL); |
aoqi@30 | 3133 | } else { |
aoqi@30 | 3134 | Label DONE_LABEL, Stacked, CheckSucc, Inflated ; |
aoqi@30 | 3135 | |
aoqi@30 | 3136 | // Critically, the biased locking test must have precedence over |
aoqi@30 | 3137 | // and appear before the (box->dhw == 0) recursive stack-lock test. |
aoqi@30 | 3138 | if (UseBiasedLocking && !UseOptoBiasInlining) { |
aoqi@30 | 3139 | biased_locking_exit(objReg, tmpReg, DONE_LABEL); |
aoqi@30 | 3140 | } |
aoqi@30 | 3141 | |
aoqi@30 | 3142 | ld(tmpReg, Address(objReg, 0)) ; // Examine the object's markword |
aoqi@30 | 3143 | ld(AT, Address(boxReg, 0)) ; // Examine the displaced header |
aoqi@30 | 3144 | beq(AT, R0, DONE_LABEL) ; // 0 indicates recursive stack-lock |
aoqi@30 | 3145 | //move(AT, 0x1); |
aoqi@30 | 3146 | //delayed()->nop(); |
aoqi@30 | 3147 | delayed()->daddiu(AT, R0, 0x1); |
aoqi@30 | 3148 | |
aoqi@30 | 3149 | andi(AT, tmpReg, markOopDesc::monitor_value) ; // Inflated? |
aoqi@30 | 3150 | beq(AT, R0, Stacked) ; // Inflated? |
aoqi@30 | 3151 | delayed()->nop(); |
aoqi@30 | 3152 | |
aoqi@30 | 3153 | bind(Inflated) ; |
aoqi@30 | 3154 | // It's inflated. |
aoqi@30 | 3155 | // Despite our balanced locking property we still check that m->_owner == Self |
aoqi@30 | 3156 | // as java routines or native JNI code called by this thread might |
aoqi@30 | 3157 | // have released the lock. |
aoqi@30 | 3158 | // Refer to the comments in synchronizer.cpp for how we might encode extra |
aoqi@30 | 3159 | // state in _succ so we can avoid fetching EntryList|cxq. |
aoqi@30 | 3160 | // |
aoqi@30 | 3161 | // I'd like to add more cases in fast_lock() and fast_unlock() -- |
aoqi@30 | 3162 | // such as recursive enter and exit -- but we have to be wary of |
aoqi@30 | 3163 | // I$ bloat, T$ effects and BP$ effects. |
aoqi@30 | 3164 | // |
aoqi@30 | 3165 | // If there's no contention try a 1-0 exit. That is, exit without |
aoqi@30 | 3166 | // a costly MEMBAR or CAS. See synchronizer.cpp for details on how |
aoqi@30 | 3167 | // we detect and recover from the race that the 1-0 exit admits. |
aoqi@30 | 3168 | // |
aoqi@30 | 3169 | // Conceptually Fast_Unlock() must execute a STST|LDST "release" barrier |
aoqi@30 | 3170 | // before it STs null into _owner, releasing the lock. Updates |
aoqi@30 | 3171 | // to data protected by the critical section must be visible before |
aoqi@30 | 3172 | // we drop the lock (and thus before any other thread could acquire |
aoqi@30 | 3173 | // the lock and observe the fields protected by the lock). |
aoqi@30 | 3174 | // IA32's memory-model is SPO, so STs are ordered with respect to |
aoqi@30 | 3175 | // each other and there's no need for an explicit barrier (fence). |
aoqi@30 | 3176 | // See also http://gee.cs.oswego.edu/dl/jmm/cookbook.html. |
aoqi@30 | 3177 | #ifdef OPT_THREAD |
aoqi@30 | 3178 | move(boxReg, TREG); |
aoqi@30 | 3179 | #else |
aoqi@30 | 3180 | get_thread (boxReg) ; |
aoqi@30 | 3181 | #endif |
aoqi@30 | 3182 | |
aoqi@30 | 3183 | #ifndef _LP64 |
aoqi@30 | 3184 | |
aoqi@30 | 3185 | // Note that we could employ various encoding schemes to reduce |
aoqi@30 | 3186 | // the number of loads below (currently 4) to just 2 or 3. |
aoqi@30 | 3187 | // Refer to the comments in synchronizer.cpp. |
aoqi@30 | 3188 | // In practice the chain of fetches doesn't seem to impact performance, however. |
aoqi@30 | 3189 | if ((EmitSync & 65536) == 0 && (EmitSync & 256)) { |
aoqi@30 | 3190 | // Attempt to reduce branch density - AMD's branch predictor. |
aoqi@30 | 3191 | ld(AT, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3192 | xorr(boxReg, boxReg, AT); |
aoqi@30 | 3193 | |
aoqi@30 | 3194 | ld(AT, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ; |
aoqi@30 | 3195 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3196 | |
aoqi@30 | 3197 | ld(AT, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; |
aoqi@30 | 3198 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3199 | |
aoqi@30 | 3200 | ld(AT, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; |
aoqi@30 | 3201 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3202 | |
aoqi@30 | 3203 | bne(boxReg, R0, DONE_LABEL); |
aoqi@30 | 3204 | move(AT, R0); /* delay slot */ |
aoqi@30 | 3205 | |
aoqi@30 | 3206 | sw(R0, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3207 | b(DONE_LABEL); |
aoqi@30 | 3208 | move(AT, 0x1); /* delay slot */ |
aoqi@30 | 3209 | } else { |
aoqi@30 | 3210 | ld(AT, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3211 | xorr(boxReg, boxReg, AT); |
aoqi@30 | 3212 | |
aoqi@30 | 3213 | ld(AT, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ; |
aoqi@30 | 3214 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3215 | |
aoqi@30 | 3216 | bne(boxReg, R0, DONE_LABEL); |
aoqi@30 | 3217 | move(AT, R0); /* delay slot */ |
aoqi@30 | 3218 | |
aoqi@30 | 3219 | ld(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; |
aoqi@30 | 3220 | ld(AT, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; |
aoqi@30 | 3221 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3222 | |
aoqi@30 | 3223 | bne(boxReg, R0, CheckSucc); |
aoqi@30 | 3224 | move(AT, R0); /* delay slot */ |
aoqi@30 | 3225 | |
aoqi@30 | 3226 | sd(R0, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3227 | b(DONE_LABEL); |
aoqi@30 | 3228 | move(AT, 0x1); /* delay slot */ |
aoqi@30 | 3229 | } |
aoqi@30 | 3230 | |
aoqi@30 | 3231 | // The Following code fragment (EmitSync & 65536) improves the performance of |
aoqi@30 | 3232 | // contended applications and contended synchronization microbenchmarks. |
aoqi@30 | 3233 | // Unfortunately the emission of the code - even though not executed - causes regressions |
aoqi@30 | 3234 | // in scimark and jetstream, evidently because of $ effects. Replacing the code |
aoqi@30 | 3235 | // with an equal number of never-executed NOPs results in the same regression. |
aoqi@30 | 3236 | // We leave it off by default. |
aoqi@30 | 3237 | |
aoqi@30 | 3238 | if ((EmitSync & 65536) != 0) { |
aoqi@30 | 3239 | Label LSuccess, LGoSlowPath ; |
aoqi@30 | 3240 | |
aoqi@30 | 3241 | bind(CheckSucc) ; |
aoqi@30 | 3242 | |
aoqi@30 | 3243 | // Optional pre-test ... it's safe to elide this |
aoqi@30 | 3244 | if ((EmitSync & 16) == 0) { |
aoqi@30 | 3245 | ld(AT, Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2)) ; |
aoqi@30 | 3246 | beq(AT, R0, LGoSlowPath); |
aoqi@30 | 3247 | delayed()->nop(); |
aoqi@30 | 3248 | } |
aoqi@30 | 3249 | |
aoqi@30 | 3250 | // We have a classic Dekker-style idiom: |
aoqi@30 | 3251 | // ST m->_owner = 0 ; MEMBAR; LD m->_succ |
aoqi@30 | 3252 | // There are a number of ways to implement the barrier: |
aoqi@30 | 3253 | // (1) lock:andl &m->_owner, 0 |
aoqi@30 | 3254 | // is fast, but mask doesn't currently support the "ANDL M,IMM32" form. |
aoqi@30 | 3255 | // LOCK: ANDL [ebx+Offset(_Owner)-2], 0 |
aoqi@30 | 3256 | // Encodes as 81 31 OFF32 IMM32 or 83 63 OFF8 IMM8 |
aoqi@30 | 3257 | // (2) If supported, an explicit MFENCE is appealing. |
aoqi@30 | 3258 | // In older IA32 processors MFENCE is slower than lock:add or xchg |
aoqi@30 | 3259 | // particularly if the write-buffer is full as might be the case if |
aoqi@30 | 3260 | // if stores closely precede the fence or fence-equivalent instruction. |
aoqi@30 | 3261 | // In more modern implementations MFENCE appears faster, however. |
aoqi@30 | 3262 | // (3) In lieu of an explicit fence, use lock:addl to the top-of-stack |
aoqi@30 | 3263 | // The $lines underlying the top-of-stack should be in M-state. |
aoqi@30 | 3264 | // The locked add instruction is serializing, of course. |
aoqi@30 | 3265 | // (4) Use xchg, which is serializing |
aoqi@30 | 3266 | // mov boxReg, 0; xchgl boxReg, [tmpReg + Offset(_owner)-2] also works |
aoqi@30 | 3267 | // (5) ST m->_owner = 0 and then execute lock:orl &m->_succ, 0. |
aoqi@30 | 3268 | // The integer condition codes will tell us if succ was 0. |
aoqi@30 | 3269 | // Since _succ and _owner should reside in the same $line and |
aoqi@30 | 3270 | // we just stored into _owner, it's likely that the $line |
aoqi@30 | 3271 | // remains in M-state for the lock:orl. |
aoqi@30 | 3272 | // |
aoqi@30 | 3273 | // We currently use (3), although it's likely that switching to (2) |
aoqi@30 | 3274 | // is correct for the future. |
aoqi@30 | 3275 | |
aoqi@30 | 3276 | sd(R0, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3277 | |
aoqi@30 | 3278 | // Ratify _succ remains non-null |
aoqi@30 | 3279 | ld(AT, Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2)) ; |
aoqi@30 | 3280 | bne(AT, R0, LSuccess); |
aoqi@30 | 3281 | delayed()->nop(); /* delay slot */ |
aoqi@30 | 3282 | /* |
aoqi@30 | 3283 | masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; |
aoqi@30 | 3284 | masm.jccb (Assembler::notZero, LSuccess) ; |
aoqi@30 | 3285 | */ |
aoqi@30 | 3286 | |
aoqi@30 | 3287 | move(boxReg, R0) ; // box is really EAX |
aoqi@30 | 3288 | |
aoqi@30 | 3289 | cmpxchg(SP, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), boxReg); |
aoqi@30 | 3290 | beq(AT, R0, LSuccess); |
aoqi@30 | 3291 | delayed()->nop(); |
aoqi@30 | 3292 | |
aoqi@30 | 3293 | // Since we're low on registers we installed rsp as a placeholding in _owner. |
aoqi@30 | 3294 | // Now install Self over rsp. This is safe as we're transitioning from |
aoqi@30 | 3295 | // non-null to non=null |
aoqi@30 | 3296 | get_thread (boxReg) ; |
aoqi@30 | 3297 | sd(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3298 | // Intentional fall-through into LGoSlowPath ... |
aoqi@30 | 3299 | |
aoqi@30 | 3300 | bind(LGoSlowPath) ; |
aoqi@30 | 3301 | ori(boxReg, boxReg, 1) ; // set ICC.ZF=0 to indicate failure |
aoqi@30 | 3302 | b(DONE_LABEL) ; |
aoqi@30 | 3303 | move(AT, R0) ; /* delay slot */ |
aoqi@30 | 3304 | |
aoqi@30 | 3305 | bind(LSuccess) ; |
aoqi@30 | 3306 | move(boxReg, R0) ; // set ICC.ZF=1 to indicate success |
aoqi@30 | 3307 | b(DONE_LABEL) ; |
aoqi@30 | 3308 | move(AT, 0x1) ; /* delay slot */ |
aoqi@30 | 3309 | } |
aoqi@30 | 3310 | |
aoqi@30 | 3311 | bind (Stacked) ; |
aoqi@30 | 3312 | // It's not inflated and it's not recursively stack-locked and it's not biased. |
aoqi@30 | 3313 | // It must be stack-locked. |
aoqi@30 | 3314 | // Try to reset the header to displaced header. |
aoqi@30 | 3315 | // The "box" value on the stack is stable, so we can reload |
aoqi@30 | 3316 | // and be assured we observe the same value as above. |
aoqi@30 | 3317 | ld(tmpReg, Address(boxReg, 0)) ; |
aoqi@30 | 3318 | |
aoqi@30 | 3319 | cmpxchg(tmpReg, Address(objReg, 0), boxReg); // Uses EAX which is box |
aoqi@30 | 3320 | // Intention fall-thru into DONE_LABEL |
aoqi@30 | 3321 | |
aoqi@30 | 3322 | |
aoqi@30 | 3323 | // DONE_LABEL is a hot target - we'd really like to place it at the |
aoqi@30 | 3324 | // start of cache line by padding with NOPs. |
aoqi@30 | 3325 | // See the AMD and Intel software optimization manuals for the |
aoqi@30 | 3326 | // most efficient "long" NOP encodings. |
aoqi@30 | 3327 | // Unfortunately none of our alignment mechanisms suffice. |
aoqi@30 | 3328 | if ((EmitSync & 65536) == 0) { |
aoqi@30 | 3329 | bind (CheckSucc) ; |
aoqi@30 | 3330 | } |
aoqi@30 | 3331 | #else // _LP64 |
aoqi@30 | 3332 | // It's inflated |
aoqi@30 | 3333 | ld(AT, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3334 | xorr(boxReg, boxReg, AT); |
aoqi@30 | 3335 | |
aoqi@30 | 3336 | ld(AT, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ; |
aoqi@30 | 3337 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3338 | |
aoqi@30 | 3339 | move(AT, R0); |
aoqi@30 | 3340 | bne(boxReg, R0, DONE_LABEL); |
aoqi@30 | 3341 | delayed()->nop(); |
aoqi@30 | 3342 | |
aoqi@30 | 3343 | ld(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; |
aoqi@30 | 3344 | ld(AT, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; |
aoqi@30 | 3345 | orr(boxReg, boxReg, AT); |
aoqi@30 | 3346 | |
aoqi@30 | 3347 | move(AT, R0); |
aoqi@30 | 3348 | bne(boxReg, R0, CheckSucc); |
aoqi@30 | 3349 | delayed()->nop(); |
aoqi@30 | 3350 | |
aoqi@30 | 3351 | sd(R0, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3352 | move(AT, 0x1); |
aoqi@30 | 3353 | b(DONE_LABEL); |
aoqi@30 | 3354 | delayed()->nop(); |
aoqi@30 | 3355 | |
aoqi@30 | 3356 | |
aoqi@30 | 3357 | if ((EmitSync & 65536) == 0) { |
aoqi@30 | 3358 | Label LSuccess, LGoSlowPath ; |
aoqi@30 | 3359 | bind (CheckSucc); |
aoqi@30 | 3360 | ld(AT, Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2)) ; |
aoqi@30 | 3361 | beq(AT, R0, LGoSlowPath); |
aoqi@30 | 3362 | delayed()->nop(); |
aoqi@30 | 3363 | |
aoqi@30 | 3364 | // I'd much rather use lock:andl m->_owner, 0 as it's faster than the |
aoqi@30 | 3365 | // the explicit ST;MEMBAR combination, but masm doesn't currently support |
aoqi@30 | 3366 | // "ANDQ M,IMM". Don't use MFENCE here. lock:add to TOS, xchg, etc |
aoqi@30 | 3367 | // are all faster when the write buffer is populated. |
aoqi@30 | 3368 | sd(R0, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; |
aoqi@30 | 3369 | if (os::is_MP()) { |
aoqi@30 | 3370 | // lock (); |
aoqi@30 | 3371 | //addl (Address(rsp, 0), 0); //? |
aoqi@30 | 3372 | } |
aoqi@30 | 3373 | ld(AT, Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2)) ; |
aoqi@30 | 3374 | bne(AT, R0, LSuccess); |
aoqi@30 | 3375 | delayed()->nop(); |
aoqi@30 | 3376 | |
aoqi@30 | 3377 | move(boxReg, R0) ; // box is really EAX |
aoqi@30 | 3378 | //if (os::is_MP()) { lock(); } |
aoqi@30 | 3379 | cmpxchg(SP, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), boxReg); |
aoqi@30 | 3380 | beq(AT, R0, LSuccess); |
aoqi@30 | 3381 | delayed()->nop(); |
aoqi@30 | 3382 | // Intentional fall-through into slow-path |
aoqi@30 | 3383 | |
aoqi@30 | 3384 | bind (LGoSlowPath); |
aoqi@30 | 3385 | ori(boxReg, boxReg, 1) ; // set ICC.ZF=0 to indicate failure |
aoqi@30 | 3386 | move(AT, R0); |
aoqi@30 | 3387 | b(DONE_LABEL) ; |
aoqi@30 | 3388 | delayed()->nop(); |
aoqi@30 | 3389 | |
aoqi@30 | 3390 | |
aoqi@30 | 3391 | bind (LSuccess); |
aoqi@30 | 3392 | move(boxReg, R0) ; // set ICC.ZF=1 to indicate success |
aoqi@30 | 3393 | move(AT, 0x1) ; |
aoqi@30 | 3394 | b(DONE_LABEL) ; |
aoqi@30 | 3395 | delayed()->nop(); |
aoqi@30 | 3396 | } |
aoqi@30 | 3397 | |
aoqi@30 | 3398 | bind (Stacked); |
aoqi@30 | 3399 | ld(tmpReg, Address(boxReg, 0)) ; |
aoqi@30 | 3400 | //if (os::is_MP()) { lock(); } |
aoqi@30 | 3401 | cmpxchg(tmpReg, Address(objReg, 0), boxReg); // Uses EAX which is box |
aoqi@30 | 3402 | |
aoqi@30 | 3403 | if (EmitSync & 65536) { |
aoqi@30 | 3404 | bind (CheckSucc); |
aoqi@30 | 3405 | } |
aoqi@30 | 3406 | #endif |
aoqi@30 | 3407 | |
aoqi@30 | 3408 | bind(DONE_LABEL); |
aoqi@30 | 3409 | |
aoqi@30 | 3410 | // Avoid branch to branch on AMD processors |
aoqi@30 | 3411 | if (EmitSync & 32768) { nop() ; } |
aoqi@30 | 3412 | } |
aoqi@30 | 3413 | } |
aoqi@30 | 3414 | |
aoqi@1 | 3415 | class ControlWord { |
aoqi@1 | 3416 | public: |
aoqi@1 | 3417 | int32_t _value; |
aoqi@1 | 3418 | |
aoqi@1 | 3419 | int rounding_control() const { return (_value >> 10) & 3 ; } |
aoqi@1 | 3420 | int precision_control() const { return (_value >> 8) & 3 ; } |
aoqi@1 | 3421 | bool precision() const { return ((_value >> 5) & 1) != 0; } |
aoqi@1 | 3422 | bool underflow() const { return ((_value >> 4) & 1) != 0; } |
aoqi@1 | 3423 | bool overflow() const { return ((_value >> 3) & 1) != 0; } |
aoqi@1 | 3424 | bool zero_divide() const { return ((_value >> 2) & 1) != 0; } |
aoqi@1 | 3425 | bool denormalized() const { return ((_value >> 1) & 1) != 0; } |
aoqi@1 | 3426 | bool invalid() const { return ((_value >> 0) & 1) != 0; } |
aoqi@1 | 3427 | |
aoqi@1 | 3428 | void print() const { |
aoqi@1 | 3429 | // rounding control |
aoqi@1 | 3430 | const char* rc; |
aoqi@1 | 3431 | switch (rounding_control()) { |
aoqi@1 | 3432 | case 0: rc = "round near"; break; |
aoqi@1 | 3433 | case 1: rc = "round down"; break; |
aoqi@1 | 3434 | case 2: rc = "round up "; break; |
aoqi@1 | 3435 | case 3: rc = "chop "; break; |
aoqi@1 | 3436 | }; |
aoqi@1 | 3437 | // precision control |
aoqi@1 | 3438 | const char* pc; |
aoqi@1 | 3439 | switch (precision_control()) { |
aoqi@1 | 3440 | case 0: pc = "24 bits "; break; |
aoqi@1 | 3441 | case 1: pc = "reserved"; break; |
aoqi@1 | 3442 | case 2: pc = "53 bits "; break; |
aoqi@1 | 3443 | case 3: pc = "64 bits "; break; |
aoqi@1 | 3444 | }; |
aoqi@1 | 3445 | // flags |
aoqi@1 | 3446 | char f[9]; |
aoqi@1 | 3447 | f[0] = ' '; |
aoqi@1 | 3448 | f[1] = ' '; |
aoqi@1 | 3449 | f[2] = (precision ()) ? 'P' : 'p'; |
aoqi@1 | 3450 | f[3] = (underflow ()) ? 'U' : 'u'; |
aoqi@1 | 3451 | f[4] = (overflow ()) ? 'O' : 'o'; |
aoqi@1 | 3452 | f[5] = (zero_divide ()) ? 'Z' : 'z'; |
aoqi@1 | 3453 | f[6] = (denormalized()) ? 'D' : 'd'; |
aoqi@1 | 3454 | f[7] = (invalid ()) ? 'I' : 'i'; |
aoqi@1 | 3455 | f[8] = '\x0'; |
aoqi@1 | 3456 | // output |
aoqi@1 | 3457 | printf("%04x masks = %s, %s, %s", _value & 0xFFFF, f, rc, pc); |
aoqi@1 | 3458 | } |
aoqi@1 | 3459 | |
aoqi@1 | 3460 | }; |
aoqi@1 | 3461 | |
aoqi@1 | 3462 | class StatusWord { |
aoqi@1 | 3463 | public: |
aoqi@1 | 3464 | int32_t _value; |
aoqi@1 | 3465 | |
aoqi@1 | 3466 | bool busy() const { return ((_value >> 15) & 1) != 0; } |
aoqi@1 | 3467 | bool C3() const { return ((_value >> 14) & 1) != 0; } |
aoqi@1 | 3468 | bool C2() const { return ((_value >> 10) & 1) != 0; } |
aoqi@1 | 3469 | bool C1() const { return ((_value >> 9) & 1) != 0; } |
aoqi@1 | 3470 | bool C0() const { return ((_value >> 8) & 1) != 0; } |
aoqi@1 | 3471 | int top() const { return (_value >> 11) & 7 ; } |
aoqi@1 | 3472 | bool error_status() const { return ((_value >> 7) & 1) != 0; } |
aoqi@1 | 3473 | bool stack_fault() const { return ((_value >> 6) & 1) != 0; } |
aoqi@1 | 3474 | bool precision() const { return ((_value >> 5) & 1) != 0; } |
aoqi@1 | 3475 | bool underflow() const { return ((_value >> 4) & 1) != 0; } |
aoqi@1 | 3476 | bool overflow() const { return ((_value >> 3) & 1) != 0; } |
aoqi@1 | 3477 | bool zero_divide() const { return ((_value >> 2) & 1) != 0; } |
aoqi@1 | 3478 | bool denormalized() const { return ((_value >> 1) & 1) != 0; } |
aoqi@1 | 3479 | bool invalid() const { return ((_value >> 0) & 1) != 0; } |
aoqi@1 | 3480 | |
aoqi@1 | 3481 | void print() const { |
aoqi@1 | 3482 | // condition codes |
aoqi@1 | 3483 | char c[5]; |
aoqi@1 | 3484 | c[0] = (C3()) ? '3' : '-'; |
aoqi@1 | 3485 | c[1] = (C2()) ? '2' : '-'; |
aoqi@1 | 3486 | c[2] = (C1()) ? '1' : '-'; |
aoqi@1 | 3487 | c[3] = (C0()) ? '0' : '-'; |
aoqi@1 | 3488 | c[4] = '\x0'; |
aoqi@1 | 3489 | // flags |
aoqi@1 | 3490 | char f[9]; |
aoqi@1 | 3491 | f[0] = (error_status()) ? 'E' : '-'; |
aoqi@1 | 3492 | f[1] = (stack_fault ()) ? 'S' : '-'; |
aoqi@1 | 3493 | f[2] = (precision ()) ? 'P' : '-'; |
aoqi@1 | 3494 | f[3] = (underflow ()) ? 'U' : '-'; |
aoqi@1 | 3495 | f[4] = (overflow ()) ? 'O' : '-'; |
aoqi@1 | 3496 | f[5] = (zero_divide ()) ? 'Z' : '-'; |
aoqi@1 | 3497 | f[6] = (denormalized()) ? 'D' : '-'; |
aoqi@1 | 3498 | f[7] = (invalid ()) ? 'I' : '-'; |
aoqi@1 | 3499 | f[8] = '\x0'; |
aoqi@1 | 3500 | // output |
aoqi@1 | 3501 | printf("%04x flags = %s, cc = %s, top = %d", _value & 0xFFFF, f, c, top()); |
aoqi@1 | 3502 | } |
aoqi@1 | 3503 | |
aoqi@1 | 3504 | }; |
aoqi@1 | 3505 | |
aoqi@1 | 3506 | class TagWord { |
aoqi@1 | 3507 | public: |
aoqi@1 | 3508 | int32_t _value; |
aoqi@1 | 3509 | |
aoqi@1 | 3510 | int tag_at(int i) const { return (_value >> (i*2)) & 3; } |
aoqi@1 | 3511 | |
aoqi@1 | 3512 | void print() const { |
aoqi@1 | 3513 | printf("%04x", _value & 0xFFFF); |
aoqi@1 | 3514 | } |
aoqi@1 | 3515 | |
aoqi@1 | 3516 | }; |
aoqi@1 | 3517 | |
aoqi@1 | 3518 | class FPU_Register { |
aoqi@1 | 3519 | public: |
aoqi@1 | 3520 | int32_t _m0; |
aoqi@1 | 3521 | int32_t _m1; |
aoqi@1 | 3522 | int16_t _ex; |
aoqi@1 | 3523 | |
aoqi@1 | 3524 | bool is_indefinite() const { |
aoqi@1 | 3525 | return _ex == -1 && _m1 == (int32_t)0xC0000000 && _m0 == 0; |
aoqi@1 | 3526 | } |
aoqi@1 | 3527 | |
aoqi@1 | 3528 | void print() const { |
aoqi@1 | 3529 | char sign = (_ex < 0) ? '-' : '+'; |
aoqi@1 | 3530 | const char* kind = (_ex == 0x7FFF || _ex == (int16_t)-1) ? "NaN" : " "; |
aoqi@1 | 3531 | printf("%c%04hx.%08x%08x %s", sign, _ex, _m1, _m0, kind); |
aoqi@1 | 3532 | }; |
aoqi@1 | 3533 | |
aoqi@1 | 3534 | }; |
aoqi@1 | 3535 | |
aoqi@1 | 3536 | class FPU_State { |
aoqi@1 | 3537 | public: |
aoqi@1 | 3538 | enum { |
aoqi@1 | 3539 | register_size = 10, |
aoqi@1 | 3540 | number_of_registers = 8, |
aoqi@1 | 3541 | register_mask = 7 |
aoqi@1 | 3542 | }; |
aoqi@1 | 3543 | |
aoqi@1 | 3544 | ControlWord _control_word; |
aoqi@1 | 3545 | StatusWord _status_word; |
aoqi@1 | 3546 | TagWord _tag_word; |
aoqi@1 | 3547 | int32_t _error_offset; |
aoqi@1 | 3548 | int32_t _error_selector; |
aoqi@1 | 3549 | int32_t _data_offset; |
aoqi@1 | 3550 | int32_t _data_selector; |
aoqi@1 | 3551 | int8_t _register[register_size * number_of_registers]; |
aoqi@1 | 3552 | |
aoqi@1 | 3553 | int tag_for_st(int i) const { return _tag_word.tag_at((_status_word.top() + i) & register_mask); } |
aoqi@1 | 3554 | FPU_Register* st(int i) const { return (FPU_Register*)&_register[register_size * i]; } |
aoqi@1 | 3555 | |
aoqi@1 | 3556 | const char* tag_as_string(int tag) const { |
aoqi@1 | 3557 | switch (tag) { |
aoqi@1 | 3558 | case 0: return "valid"; |
aoqi@1 | 3559 | case 1: return "zero"; |
aoqi@1 | 3560 | case 2: return "special"; |
aoqi@1 | 3561 | case 3: return "empty"; |
aoqi@1 | 3562 | } |
aoqi@1 | 3563 | ShouldNotReachHere(); |
aoqi@1 | 3564 | return NULL; |
aoqi@1 | 3565 | } |
aoqi@1 | 3566 | |
aoqi@1 | 3567 | void print() const { |
aoqi@1 | 3568 | // print computation registers |
aoqi@1 | 3569 | { int t = _status_word.top(); |
aoqi@1 | 3570 | for (int i = 0; i < number_of_registers; i++) { |
aoqi@1 | 3571 | int j = (i - t) & register_mask; |
aoqi@1 | 3572 | printf("%c r%d = ST%d = ", (j == 0 ? '*' : ' '), i, j); |
aoqi@1 | 3573 | st(j)->print(); |
aoqi@1 | 3574 | printf(" %s\n", tag_as_string(_tag_word.tag_at(i))); |
aoqi@1 | 3575 | } |
aoqi@1 | 3576 | } |
aoqi@1 | 3577 | printf("\n"); |
aoqi@1 | 3578 | // print control registers |
aoqi@1 | 3579 | printf("ctrl = "); _control_word.print(); printf("\n"); |
aoqi@1 | 3580 | printf("stat = "); _status_word .print(); printf("\n"); |
aoqi@1 | 3581 | printf("tags = "); _tag_word .print(); printf("\n"); |
aoqi@1 | 3582 | } |
aoqi@1 | 3583 | |
aoqi@1 | 3584 | }; |
aoqi@1 | 3585 | |
aoqi@1 | 3586 | class Flag_Register { |
aoqi@1 | 3587 | public: |
aoqi@1 | 3588 | int32_t _value; |
aoqi@1 | 3589 | |
aoqi@1 | 3590 | bool overflow() const { return ((_value >> 11) & 1) != 0; } |
aoqi@1 | 3591 | bool direction() const { return ((_value >> 10) & 1) != 0; } |
aoqi@1 | 3592 | bool sign() const { return ((_value >> 7) & 1) != 0; } |
aoqi@1 | 3593 | bool zero() const { return ((_value >> 6) & 1) != 0; } |
aoqi@1 | 3594 | bool auxiliary_carry() const { return ((_value >> 4) & 1) != 0; } |
aoqi@1 | 3595 | bool parity() const { return ((_value >> 2) & 1) != 0; } |
aoqi@1 | 3596 | bool carry() const { return ((_value >> 0) & 1) != 0; } |
aoqi@1 | 3597 | |
aoqi@1 | 3598 | void print() const { |
aoqi@1 | 3599 | // flags |
aoqi@1 | 3600 | char f[8]; |
aoqi@1 | 3601 | f[0] = (overflow ()) ? 'O' : '-'; |
aoqi@1 | 3602 | f[1] = (direction ()) ? 'D' : '-'; |
aoqi@1 | 3603 | f[2] = (sign ()) ? 'S' : '-'; |
aoqi@1 | 3604 | f[3] = (zero ()) ? 'Z' : '-'; |
aoqi@1 | 3605 | f[4] = (auxiliary_carry()) ? 'A' : '-'; |
aoqi@1 | 3606 | f[5] = (parity ()) ? 'P' : '-'; |
aoqi@1 | 3607 | f[6] = (carry ()) ? 'C' : '-'; |
aoqi@1 | 3608 | f[7] = '\x0'; |
aoqi@1 | 3609 | // output |
aoqi@1 | 3610 | printf("%08x flags = %s", _value, f); |
aoqi@1 | 3611 | } |
aoqi@1 | 3612 | |
aoqi@1 | 3613 | }; |
aoqi@1 | 3614 | |
aoqi@1 | 3615 | class IU_Register { |
aoqi@1 | 3616 | public: |
aoqi@1 | 3617 | int32_t _value; |
aoqi@1 | 3618 | |
aoqi@1 | 3619 | void print() const { |
aoqi@1 | 3620 | printf("%08x %11d", _value, _value); |
aoqi@1 | 3621 | } |
aoqi@1 | 3622 | |
aoqi@1 | 3623 | }; |
aoqi@1 | 3624 | |
aoqi@1 | 3625 | class IU_State { |
aoqi@1 | 3626 | public: |
aoqi@1 | 3627 | Flag_Register _eflags; |
aoqi@1 | 3628 | IU_Register _rdi; |
aoqi@1 | 3629 | IU_Register _rsi; |
aoqi@1 | 3630 | IU_Register _rbp; |
aoqi@1 | 3631 | IU_Register _rsp; |
aoqi@1 | 3632 | IU_Register _rbx; |
aoqi@1 | 3633 | IU_Register _rdx; |
aoqi@1 | 3634 | IU_Register _rcx; |
aoqi@1 | 3635 | IU_Register _rax; |
aoqi@1 | 3636 | |
aoqi@1 | 3637 | void print() const { |
aoqi@1 | 3638 | // computation registers |
aoqi@1 | 3639 | printf("rax, = "); _rax.print(); printf("\n"); |
aoqi@1 | 3640 | printf("rbx, = "); _rbx.print(); printf("\n"); |
aoqi@1 | 3641 | printf("rcx = "); _rcx.print(); printf("\n"); |
aoqi@1 | 3642 | printf("rdx = "); _rdx.print(); printf("\n"); |
aoqi@1 | 3643 | printf("rdi = "); _rdi.print(); printf("\n"); |
aoqi@1 | 3644 | printf("rsi = "); _rsi.print(); printf("\n"); |
aoqi@1 | 3645 | printf("rbp, = "); _rbp.print(); printf("\n"); |
aoqi@1 | 3646 | printf("rsp = "); _rsp.print(); printf("\n"); |
aoqi@1 | 3647 | printf("\n"); |
aoqi@1 | 3648 | // control registers |
aoqi@1 | 3649 | printf("flgs = "); _eflags.print(); printf("\n"); |
aoqi@1 | 3650 | } |
aoqi@1 | 3651 | }; |
aoqi@1 | 3652 | |
aoqi@1 | 3653 | |
aoqi@1 | 3654 | class CPU_State { |
aoqi@1 | 3655 | public: |
aoqi@1 | 3656 | FPU_State _fpu_state; |
aoqi@1 | 3657 | IU_State _iu_state; |
aoqi@1 | 3658 | |
aoqi@1 | 3659 | void print() const { |
aoqi@1 | 3660 | printf("--------------------------------------------------\n"); |
aoqi@1 | 3661 | _iu_state .print(); |
aoqi@1 | 3662 | printf("\n"); |
aoqi@1 | 3663 | _fpu_state.print(); |
aoqi@1 | 3664 | printf("--------------------------------------------------\n"); |
aoqi@1 | 3665 | } |
aoqi@1 | 3666 | |
aoqi@1 | 3667 | }; |
aoqi@1 | 3668 | |
aoqi@1 | 3669 | |
aoqi@1 | 3670 | /* |
aoqi@1 | 3671 | static void _print_CPU_state(CPU_State* state) { |
aoqi@1 | 3672 | state->print(); |
aoqi@1 | 3673 | }; |
aoqi@1 | 3674 | |
aoqi@1 | 3675 | void MacroAssembler::print_CPU_state() { |
aoqi@1 | 3676 | push_CPU_state(); |
aoqi@1 | 3677 | push(rsp); // pass CPU state |
aoqi@1 | 3678 | call(RuntimeAddress(CAST_FROM_FN_PTR(address, _print_CPU_state))); |
aoqi@1 | 3679 | addptr(rsp, wordSize); // discard argument |
aoqi@1 | 3680 | pop_CPU_state(); |
aoqi@1 | 3681 | } |
aoqi@1 | 3682 | */ |
aoqi@1 | 3683 | |
aoqi@1 | 3684 | void MacroAssembler::align(int modulus) { |
aoqi@1 | 3685 | while (offset() % modulus != 0) nop(); |
aoqi@1 | 3686 | } |
aoqi@1 | 3687 | |
aoqi@1 | 3688 | #if 0 |
aoqi@1 | 3689 | static bool _verify_FPU(int stack_depth, char* s, CPU_State* state) { |
aoqi@1 | 3690 | static int counter = 0; |
aoqi@1 | 3691 | FPU_State* fs = &state->_fpu_state; |
aoqi@1 | 3692 | counter++; |
aoqi@1 | 3693 | // For leaf calls, only verify that the top few elements remain empty. |
aoqi@1 | 3694 | // We only need 1 empty at the top for C2 code. |
aoqi@1 | 3695 | if( stack_depth < 0 ) { |
aoqi@1 | 3696 | if( fs->tag_for_st(7) != 3 ) { |
aoqi@1 | 3697 | printf("FPR7 not empty\n"); |
aoqi@1 | 3698 | state->print(); |
aoqi@1 | 3699 | assert(false, "error"); |
aoqi@1 | 3700 | return false; |
aoqi@1 | 3701 | } |
aoqi@1 | 3702 | return true; // All other stack states do not matter |
aoqi@1 | 3703 | } |
aoqi@1 | 3704 | |
aoqi@1 | 3705 | assert((fs->_control_word._value & 0xffff) == StubRoutines::_fpu_cntrl_wrd_std, |
aoqi@1 | 3706 | "bad FPU control word"); |
aoqi@1 | 3707 | |
aoqi@1 | 3708 | // compute stack depth |
aoqi@1 | 3709 | int i = 0; |
aoqi@1 | 3710 | while (i < FPU_State::number_of_registers && fs->tag_for_st(i) < 3) i++; |
aoqi@1 | 3711 | int d = i; |
aoqi@1 | 3712 | while (i < FPU_State::number_of_registers && fs->tag_for_st(i) == 3) i++; |
aoqi@1 | 3713 | // verify findings |
aoqi@1 | 3714 | if (i != FPU_State::number_of_registers) { |
aoqi@1 | 3715 | // stack not contiguous |
aoqi@1 | 3716 | printf("%s: stack not contiguous at ST%d\n", s, i); |
aoqi@1 | 3717 | state->print(); |
aoqi@1 | 3718 | assert(false, "error"); |
aoqi@1 | 3719 | return false; |
aoqi@1 | 3720 | } |
aoqi@1 | 3721 | // check if computed stack depth corresponds to expected stack depth |
aoqi@1 | 3722 | if (stack_depth < 0) { |
aoqi@1 | 3723 | // expected stack depth is -stack_depth or less |
aoqi@1 | 3724 | if (d > -stack_depth) { |
aoqi@1 | 3725 | // too many elements on the stack |
aoqi@1 | 3726 | printf("%s: <= %d stack elements expected but found %d\n", s, -stack_depth, d); |
aoqi@1 | 3727 | state->print(); |
aoqi@1 | 3728 | assert(false, "error"); |
aoqi@1 | 3729 | return false; |
aoqi@1 | 3730 | } |
aoqi@1 | 3731 | } else { |
aoqi@1 | 3732 | // expected stack depth is stack_depth |
aoqi@1 | 3733 | if (d != stack_depth) { |
aoqi@1 | 3734 | // wrong stack depth |
aoqi@1 | 3735 | printf("%s: %d stack elements expected but found %d\n", s, stack_depth, d); |
aoqi@1 | 3736 | state->print(); |
aoqi@1 | 3737 | assert(false, "error"); |
aoqi@1 | 3738 | return false; |
aoqi@1 | 3739 | } |
aoqi@1 | 3740 | } |
aoqi@1 | 3741 | // everything is cool |
aoqi@1 | 3742 | return true; |
aoqi@1 | 3743 | } |
aoqi@1 | 3744 | #endif |
aoqi@1 | 3745 | |
aoqi@1 | 3746 | |
aoqi@1 | 3747 | void MacroAssembler::verify_FPU(int stack_depth, const char* s) { |
aoqi@1 | 3748 | //FIXME aoqi |
aoqi@1 | 3749 | // %%%%% need to implement this |
aoqi@1 | 3750 | //Unimplemented(); |
aoqi@1 | 3751 | /* |
aoqi@1 | 3752 | if (!VerifyFPU) return; |
aoqi@1 | 3753 | push_CPU_state(); |
aoqi@1 | 3754 | push(rsp); // pass CPU state |
aoqi@1 | 3755 | ExternalAddress msg((address) s); |
aoqi@1 | 3756 | // pass message string s |
aoqi@1 | 3757 | pushptr(msg.addr()); |
aoqi@1 | 3758 | push(stack_depth); // pass stack depth |
aoqi@1 | 3759 | call(RuntimeAddress(CAST_FROM_FN_PTR(address, _verify_FPU))); |
aoqi@1 | 3760 | addptr(rsp, 3 * wordSize); // discard arguments |
aoqi@1 | 3761 | // check for error |
aoqi@1 | 3762 | { Label L; |
aoqi@1 | 3763 | testl(rax, rax); |
aoqi@1 | 3764 | jcc(Assembler::notZero, L); |
aoqi@1 | 3765 | int3(); // break if error condition |
aoqi@1 | 3766 | bind(L); |
aoqi@1 | 3767 | } |
aoqi@1 | 3768 | pop_CPU_state(); |
aoqi@1 | 3769 | */ |
aoqi@1 | 3770 | } |
aoqi@1 | 3771 | |
aoqi@1 | 3772 | #ifdef _LP64 |
aoqi@1 | 3773 | Register caller_saved_registers[] = {AT, V0, V1, A0, A1, A2, A3, A4, A5, A6, A7, T0, T1, T2, T3, T8, T9, GP, RA, FP}; |
aoqi@1 | 3774 | |
aoqi@1 | 3775 | /* FIXME: Jin: In MIPS64, F0~23 are all caller-saved registers */ |
aoqi@1 | 3776 | FloatRegister caller_saved_fpu_registers[] = {F0, F12, F13}; |
aoqi@1 | 3777 | #else |
aoqi@1 | 3778 | Register caller_saved_registers[] = {AT, V0, V1, A0, A1, A2, A3, T4, T5, T6, T7, T0, T1, T2, T3, T8, T9, GP, RA, FP}; |
aoqi@1 | 3779 | |
aoqi@1 | 3780 | Register caller_saved_fpu_registers[] = {}; |
aoqi@1 | 3781 | #endif |
aoqi@1 | 3782 | |
aoqi@1 | 3783 | //We preserve all caller-saved register |
aoqi@1 | 3784 | void MacroAssembler::pushad(){ |
aoqi@1 | 3785 | int i; |
aoqi@1 | 3786 | |
aoqi@1 | 3787 | /* Fixed-point registers */ |
aoqi@1 | 3788 | int len = sizeof(caller_saved_registers) / sizeof(caller_saved_registers[0]); |
aoqi@1 | 3789 | daddi(SP, SP, -1 * len * wordSize); |
aoqi@1 | 3790 | for (i = 0; i < len; i++) |
aoqi@1 | 3791 | { |
aoqi@1 | 3792 | #ifdef _LP64 |
aoqi@1 | 3793 | sd(caller_saved_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3794 | #else |
aoqi@1 | 3795 | sw(caller_saved_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3796 | #endif |
aoqi@1 | 3797 | } |
aoqi@1 | 3798 | |
aoqi@1 | 3799 | /* Floating-point registers */ |
aoqi@1 | 3800 | len = sizeof(caller_saved_fpu_registers) / sizeof(caller_saved_fpu_registers[0]); |
aoqi@1 | 3801 | daddi(SP, SP, -1 * len * wordSize); |
aoqi@1 | 3802 | for (i = 0; i < len; i++) |
aoqi@1 | 3803 | { |
aoqi@1 | 3804 | #ifdef _LP64 |
aoqi@1 | 3805 | sdc1(caller_saved_fpu_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3806 | #else |
aoqi@1 | 3807 | swc1(caller_saved_fpu_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3808 | #endif |
aoqi@1 | 3809 | } |
aoqi@1 | 3810 | }; |
aoqi@1 | 3811 | |
aoqi@1 | 3812 | void MacroAssembler::popad(){ |
aoqi@1 | 3813 | int i; |
aoqi@1 | 3814 | |
aoqi@1 | 3815 | /* Floating-point registers */ |
aoqi@1 | 3816 | int len = sizeof(caller_saved_fpu_registers) / sizeof(caller_saved_fpu_registers[0]); |
aoqi@1 | 3817 | for (i = 0; i < len; i++) |
aoqi@1 | 3818 | { |
aoqi@1 | 3819 | #ifdef _LP64 |
aoqi@1 | 3820 | ldc1(caller_saved_fpu_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3821 | #else |
aoqi@1 | 3822 | lwc1(caller_saved_fpu_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3823 | #endif |
aoqi@1 | 3824 | } |
aoqi@1 | 3825 | daddi(SP, SP, len * wordSize); |
aoqi@1 | 3826 | |
aoqi@1 | 3827 | /* Fixed-point registers */ |
aoqi@1 | 3828 | len = sizeof(caller_saved_registers) / sizeof(caller_saved_registers[0]); |
aoqi@1 | 3829 | for (i = 0; i < len; i++) |
aoqi@1 | 3830 | { |
aoqi@1 | 3831 | #ifdef _LP64 |
aoqi@1 | 3832 | ld(caller_saved_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3833 | #else |
aoqi@1 | 3834 | lw(caller_saved_registers[i], SP, (len - i - 1) * wordSize); |
aoqi@1 | 3835 | #endif |
aoqi@1 | 3836 | } |
aoqi@1 | 3837 | daddi(SP, SP, len * wordSize); |
aoqi@1 | 3838 | }; |
aoqi@1 | 3839 | |
aoqi@1 | 3840 | void MacroAssembler::push2(Register reg1, Register reg2) { |
aoqi@1 | 3841 | #ifdef _LP64 |
aoqi@1 | 3842 | daddi(SP, SP, -16); |
aoqi@1 | 3843 | sd(reg2, SP, 0); |
aoqi@1 | 3844 | sd(reg1, SP, 8); |
aoqi@1 | 3845 | #else |
aoqi@1 | 3846 | addi(SP, SP, -8); |
aoqi@1 | 3847 | sw(reg2, SP, 0); |
aoqi@1 | 3848 | sw(reg1, SP, 4); |
aoqi@1 | 3849 | #endif |
aoqi@1 | 3850 | } |
aoqi@1 | 3851 | |
aoqi@1 | 3852 | void MacroAssembler::pop2(Register reg1, Register reg2) { |
aoqi@1 | 3853 | #ifdef _LP64 |
aoqi@1 | 3854 | ld(reg1, SP, 0); |
aoqi@1 | 3855 | ld(reg2, SP, 8); |
aoqi@1 | 3856 | daddi(SP, SP, 16); |
aoqi@1 | 3857 | #else |
aoqi@1 | 3858 | lw(reg1, SP, 0); |
aoqi@1 | 3859 | lw(reg2, SP, 4); |
aoqi@1 | 3860 | addi(SP, SP, 8); |
aoqi@1 | 3861 | #endif |
aoqi@1 | 3862 | } |
aoqi@1 | 3863 | |
aoqi@1 | 3864 | //for UseCompressedOops Option |
aoqi@1 | 3865 | void MacroAssembler::load_klass(Register dst, Register src) { |
aoqi@1 | 3866 | #ifdef _LP64 |
aoqi@1 | 3867 | if(UseCompressedClassPointers){ |
aoqi@1 | 3868 | lwu(dst, Address(src, oopDesc::klass_offset_in_bytes())); |
aoqi@1 | 3869 | decode_klass_not_null(dst); |
aoqi@1 | 3870 | } else |
aoqi@1 | 3871 | #endif |
aoqi@1 | 3872 | ld(dst, src, oopDesc::klass_offset_in_bytes()); |
aoqi@1 | 3873 | } |
aoqi@1 | 3874 | |
aoqi@1 | 3875 | void MacroAssembler::store_klass(Register dst, Register src) { |
aoqi@1 | 3876 | #ifdef _LP64 |
aoqi@1 | 3877 | if(UseCompressedClassPointers){ |
aoqi@1 | 3878 | encode_klass_not_null(src); |
aoqi@1 | 3879 | sw(src, dst, oopDesc::klass_offset_in_bytes()); |
aoqi@1 | 3880 | } else { |
aoqi@1 | 3881 | #endif |
aoqi@1 | 3882 | sd(src, dst, oopDesc::klass_offset_in_bytes()); |
aoqi@1 | 3883 | } |
aoqi@1 | 3884 | } |
aoqi@1 | 3885 | |
aoqi@1 | 3886 | void MacroAssembler::load_prototype_header(Register dst, Register src) { |
aoqi@1 | 3887 | load_klass(dst, src); |
aoqi@1 | 3888 | ld(dst, Address(dst, Klass::prototype_header_offset())); |
aoqi@1 | 3889 | } |
aoqi@1 | 3890 | |
aoqi@1 | 3891 | #ifdef _LP64 |
aoqi@1 | 3892 | void MacroAssembler::store_klass_gap(Register dst, Register src) { |
aoqi@1 | 3893 | if (UseCompressedClassPointers) { |
aoqi@1 | 3894 | sw(src, dst, oopDesc::klass_gap_offset_in_bytes()); |
aoqi@1 | 3895 | } |
aoqi@1 | 3896 | } |
aoqi@1 | 3897 | |
aoqi@1 | 3898 | void MacroAssembler::load_heap_oop(Register dst, Address src) { |
aoqi@1 | 3899 | if(UseCompressedOops){ |
aoqi@1 | 3900 | lwu(dst, src); |
aoqi@1 | 3901 | decode_heap_oop(dst); |
aoqi@1 | 3902 | } else{ |
aoqi@1 | 3903 | ld(dst, src); |
aoqi@1 | 3904 | } |
aoqi@1 | 3905 | } |
aoqi@1 | 3906 | |
aoqi@1 | 3907 | void MacroAssembler::store_heap_oop(Address dst, Register src){ |
aoqi@1 | 3908 | if(UseCompressedOops){ |
aoqi@1 | 3909 | assert(!dst.uses(src), "not enough registers"); |
aoqi@1 | 3910 | encode_heap_oop(src); |
aoqi@1 | 3911 | sw(src, dst); |
aoqi@1 | 3912 | } else{ |
aoqi@1 | 3913 | sd(src, dst); |
aoqi@1 | 3914 | } |
aoqi@1 | 3915 | } |
aoqi@1 | 3916 | |
aoqi@1 | 3917 | #ifdef ASSERT |
aoqi@1 | 3918 | void MacroAssembler::verify_heapbase(const char* msg) { |
aoqi@1 | 3919 | assert (UseCompressedOops || UseCompressedClassPointers, "should be compressed"); |
aoqi@1 | 3920 | assert (Universe::heap() != NULL, "java heap should be initialized"); |
aoqi@1 | 3921 | /* if (CheckCompressedOops) { |
aoqi@1 | 3922 | Label ok; |
aoqi@1 | 3923 | push(rscratch1); // cmpptr trashes rscratch1 |
aoqi@1 | 3924 | cmpptr(r12_heapbase, ExternalAddress((address)Universe::narrow_ptrs_base_addr())); |
aoqi@1 | 3925 | jcc(Assembler::equal, ok); |
aoqi@1 | 3926 | STOP(msg); |
aoqi@1 | 3927 | bind(ok); |
aoqi@1 | 3928 | pop(rscratch1); |
aoqi@1 | 3929 | }*/ |
aoqi@1 | 3930 | } |
aoqi@1 | 3931 | #endif |
aoqi@1 | 3932 | |
aoqi@1 | 3933 | |
aoqi@1 | 3934 | // Algorithm must match oop.inline.hpp encode_heap_oop. |
aoqi@1 | 3935 | void MacroAssembler::encode_heap_oop(Register r) { |
aoqi@1 | 3936 | #ifdef ASSERT |
aoqi@1 | 3937 | verify_heapbase("MacroAssembler::encode_heap_oop:heap base corrupted?"); |
aoqi@1 | 3938 | #endif |
aoqi@1 | 3939 | verify_oop(r, "broken oop in encode_heap_oop"); |
aoqi@1 | 3940 | if (Universe::narrow_oop_base() == NULL) { |
aoqi@1 | 3941 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 3942 | assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 3943 | shr(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 3944 | } |
aoqi@1 | 3945 | return; |
aoqi@1 | 3946 | } |
aoqi@1 | 3947 | |
aoqi@1 | 3948 | Label done; |
aoqi@1 | 3949 | beq(r, R0, done); |
aoqi@1 | 3950 | delayed()->nop(); |
aoqi@1 | 3951 | dsub(r, r, S5_heapbase); |
aoqi@1 | 3952 | shr(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 3953 | bind(done); |
aoqi@1 | 3954 | } |
aoqi@1 | 3955 | |
aoqi@1 | 3956 | void MacroAssembler::encode_heap_oop_not_null(Register r) { |
aoqi@1 | 3957 | assert (UseCompressedOops, "should be compressed"); |
aoqi@1 | 3958 | #ifdef ASSERT |
aoqi@1 | 3959 | if (CheckCompressedOops) { |
aoqi@1 | 3960 | Label ok; |
aoqi@1 | 3961 | bne(r, R0, ok); |
aoqi@1 | 3962 | delayed()->nop(); |
aoqi@1 | 3963 | stop("null oop passed to encode_heap_oop_not_null"); |
aoqi@1 | 3964 | bind(ok); |
aoqi@1 | 3965 | } |
aoqi@1 | 3966 | #endif |
aoqi@1 | 3967 | verify_oop(r, "broken oop in encode_heap_oop_not_null"); |
aoqi@1 | 3968 | if (Universe::narrow_oop_base() != NULL) { |
aoqi@1 | 3969 | dsub(r, r, S5_heapbase); |
aoqi@1 | 3970 | } |
aoqi@1 | 3971 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 3972 | assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 3973 | shr(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 3974 | } |
aoqi@1 | 3975 | |
aoqi@1 | 3976 | } |
aoqi@1 | 3977 | |
aoqi@1 | 3978 | void MacroAssembler::encode_heap_oop_not_null(Register dst, Register src) { |
aoqi@1 | 3979 | assert (UseCompressedOops, "should be compressed"); |
aoqi@1 | 3980 | #ifdef ASSERT |
aoqi@1 | 3981 | if (CheckCompressedOops) { |
aoqi@1 | 3982 | Label ok; |
aoqi@1 | 3983 | bne(src, R0, ok); |
aoqi@1 | 3984 | delayed()->nop(); |
aoqi@1 | 3985 | stop("null oop passed to encode_heap_oop_not_null2"); |
aoqi@1 | 3986 | bind(ok); |
aoqi@1 | 3987 | } |
aoqi@1 | 3988 | #endif |
aoqi@1 | 3989 | verify_oop(src, "broken oop in encode_heap_oop_not_null2"); |
aoqi@1 | 3990 | if (dst != src) { |
aoqi@1 | 3991 | move(dst, src); |
aoqi@1 | 3992 | } |
aoqi@1 | 3993 | |
aoqi@1 | 3994 | if (Universe::narrow_oop_base() != NULL) { |
aoqi@1 | 3995 | dsub(dst, dst, S5_heapbase); |
aoqi@1 | 3996 | } |
aoqi@1 | 3997 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 3998 | assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 3999 | shr(dst, LogMinObjAlignmentInBytes); |
aoqi@1 | 4000 | } |
aoqi@1 | 4001 | |
aoqi@1 | 4002 | } |
aoqi@1 | 4003 | |
aoqi@1 | 4004 | void MacroAssembler::decode_heap_oop(Register r) { |
aoqi@1 | 4005 | #ifdef ASSERT |
aoqi@1 | 4006 | verify_heapbase("MacroAssembler::decode_heap_oop corrupted?"); |
aoqi@1 | 4007 | #endif |
aoqi@1 | 4008 | if (Universe::narrow_oop_base() == NULL) { |
aoqi@1 | 4009 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 4010 | assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 4011 | shl(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 4012 | } |
aoqi@1 | 4013 | } else { |
aoqi@1 | 4014 | Label done; |
aoqi@1 | 4015 | shl(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 4016 | beq(r, R0, done); |
aoqi@1 | 4017 | delayed()->nop(); |
aoqi@1 | 4018 | dadd(r, r, S5_heapbase); |
aoqi@1 | 4019 | bind(done); |
aoqi@1 | 4020 | } |
aoqi@1 | 4021 | verify_oop(r, "broken oop in decode_heap_oop"); |
aoqi@1 | 4022 | } |
aoqi@1 | 4023 | |
aoqi@1 | 4024 | void MacroAssembler::decode_heap_oop_not_null(Register r) { |
aoqi@1 | 4025 | // Note: it will change flags |
aoqi@1 | 4026 | assert (UseCompressedOops, "should only be used for compressed headers"); |
aoqi@1 | 4027 | assert (Universe::heap() != NULL, "java heap should be initialized"); |
aoqi@1 | 4028 | // Cannot assert, unverified entry point counts instructions (see .ad file) |
aoqi@1 | 4029 | // vtableStubs also counts instructions in pd_code_size_limit. |
aoqi@1 | 4030 | // Also do not verify_oop as this is called by verify_oop. |
aoqi@1 | 4031 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 4032 | assert(LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 4033 | shl(r, LogMinObjAlignmentInBytes); |
aoqi@1 | 4034 | if (Universe::narrow_oop_base() != NULL) { |
aoqi@1 | 4035 | dadd(r, r, S5_heapbase); |
aoqi@1 | 4036 | } |
aoqi@1 | 4037 | } else { |
aoqi@1 | 4038 | assert (Universe::narrow_oop_base() == NULL, "sanity"); |
aoqi@1 | 4039 | } |
aoqi@1 | 4040 | } |
aoqi@1 | 4041 | |
aoqi@1 | 4042 | void MacroAssembler::decode_heap_oop_not_null(Register dst, Register src) { |
aoqi@1 | 4043 | assert (UseCompressedOops, "should only be used for compressed headers"); |
aoqi@1 | 4044 | assert (Universe::heap() != NULL, "java heap should be initialized"); |
aoqi@1 | 4045 | |
aoqi@1 | 4046 | // Cannot assert, unverified entry point counts instructions (see .ad file) |
aoqi@1 | 4047 | // vtableStubs also counts instructions in pd_code_size_limit. |
aoqi@1 | 4048 | // Also do not verify_oop as this is called by verify_oop. |
aoqi@1 | 4049 | //lea(dst, Address(S5_heapbase, src, Address::times_8, 0)); |
aoqi@1 | 4050 | if (Universe::narrow_oop_shift() != 0) { |
aoqi@1 | 4051 | assert(LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); |
aoqi@1 | 4052 | if (LogMinObjAlignmentInBytes == Address::times_8) { |
aoqi@1 | 4053 | dsll(dst, src, LogMinObjAlignmentInBytes); |
aoqi@1 | 4054 | dadd(dst, dst, S5_heapbase); |
aoqi@1 | 4055 | } else { |
aoqi@1 | 4056 | if (dst != src) { |
aoqi@1 | 4057 | move(dst, src); |
aoqi@1 | 4058 | } |
aoqi@1 | 4059 | shl(dst, LogMinObjAlignmentInBytes); |
aoqi@1 | 4060 | if (Universe::narrow_oop_base() != NULL) { |
aoqi@1 | 4061 | dadd(dst, dst, S5_heapbase); |
aoqi@1 | 4062 | } |
aoqi@1 | 4063 | } |
aoqi@1 | 4064 | } else { |
aoqi@1 | 4065 | assert (Universe::narrow_oop_base() == NULL, "sanity"); |
aoqi@1 | 4066 | if (dst != src) { |
aoqi@1 | 4067 | move(dst, src); |
aoqi@1 | 4068 | } |
aoqi@1 | 4069 | } |
aoqi@1 | 4070 | } |
aoqi@1 | 4071 | |
aoqi@1 | 4072 | void MacroAssembler::encode_klass_not_null(Register r) { |
aoqi@1 | 4073 | if (Universe::narrow_klass_base() != NULL) { |
aoqi@1 | 4074 | // Use r12 as a scratch register in which to temporarily load the narrow_klass_base. |
aoqi@1 | 4075 | assert(r != S5_heapbase, "Encoding a klass in r12"); |
aoqi@1 | 4076 | li48(S5_heapbase, (int64_t)Universe::narrow_klass_base()); |
aoqi@1 | 4077 | dsub(r, r, S5_heapbase); |
aoqi@1 | 4078 | } |
aoqi@1 | 4079 | if (Universe::narrow_klass_shift() != 0) { |
aoqi@1 | 4080 | assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); |
aoqi@1 | 4081 | shr(r, LogKlassAlignmentInBytes); |
aoqi@1 | 4082 | } |
aoqi@1 | 4083 | if (Universe::narrow_klass_base() != NULL) { |
aoqi@1 | 4084 | reinit_heapbase(); |
aoqi@1 | 4085 | } |
aoqi@1 | 4086 | } |
aoqi@1 | 4087 | |
aoqi@1 | 4088 | void MacroAssembler::encode_klass_not_null(Register dst, Register src) { |
aoqi@1 | 4089 | if (dst == src) { |
aoqi@1 | 4090 | encode_klass_not_null(src); |
aoqi@1 | 4091 | } else { |
aoqi@1 | 4092 | if (Universe::narrow_klass_base() != NULL) { |
aoqi@1 | 4093 | li48(dst, (int64_t)Universe::narrow_klass_base()); |
aoqi@1 | 4094 | dsub(dst, src, dst); |
aoqi@1 | 4095 | } else { |
aoqi@1 | 4096 | move(dst, src); |
aoqi@1 | 4097 | } |
aoqi@1 | 4098 | if (Universe::narrow_klass_shift() != 0) { |
aoqi@1 | 4099 | assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); |
aoqi@1 | 4100 | shr(dst, LogKlassAlignmentInBytes); |
aoqi@1 | 4101 | } |
aoqi@1 | 4102 | } |
aoqi@1 | 4103 | } |
aoqi@1 | 4104 | |
aoqi@1 | 4105 | // Function instr_size_for_decode_klass_not_null() counts the instructions |
aoqi@1 | 4106 | // generated by decode_klass_not_null(register r) and reinit_heapbase(), |
aoqi@1 | 4107 | // when (Universe::heap() != NULL). Hence, if the instructions they |
aoqi@1 | 4108 | // generate change, then this method needs to be updated. |
aoqi@1 | 4109 | int MacroAssembler::instr_size_for_decode_klass_not_null() { |
aoqi@1 | 4110 | assert (UseCompressedClassPointers, "only for compressed klass ptrs"); |
aoqi@1 | 4111 | if (Universe::narrow_klass_base() != NULL) { |
aoqi@1 | 4112 | // mov64 + addq + shlq? + mov64 (for reinit_heapbase()). |
aoqi@1 | 4113 | return (Universe::narrow_klass_shift() == 0 ? 4 * 9 : 4 * 10); |
aoqi@1 | 4114 | } else { |
aoqi@1 | 4115 | // longest load decode klass function, mov64, leaq |
aoqi@1 | 4116 | return (Universe::narrow_klass_shift() == 0 ? 4 * 0 : 4 * 1); |
aoqi@1 | 4117 | } |
aoqi@1 | 4118 | } |
aoqi@1 | 4119 | |
aoqi@1 | 4120 | void MacroAssembler::decode_klass_not_null(Register r) { |
aoqi@1 | 4121 | // Note: it will change flags |
aoqi@1 | 4122 | assert (UseCompressedClassPointers, "should only be used for compressed headers"); |
aoqi@1 | 4123 | assert(r != S5_heapbase, "Decoding a klass in r12"); |
aoqi@1 | 4124 | // Cannot assert, unverified entry point counts instructions (see .ad file) |
aoqi@1 | 4125 | // vtableStubs also counts instructions in pd_code_size_limit. |
aoqi@1 | 4126 | // Also do not verify_oop as this is called by verify_oop. |
aoqi@1 | 4127 | if (Universe::narrow_klass_shift() != 0) { |
aoqi@1 | 4128 | assert(LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); |
aoqi@1 | 4129 | shl(r, LogKlassAlignmentInBytes); |
aoqi@1 | 4130 | } |
aoqi@1 | 4131 | if (Universe::narrow_klass_base() != NULL) { |
aoqi@1 | 4132 | li48(S5_heapbase, (int64_t)Universe::narrow_klass_base()); |
aoqi@1 | 4133 | dadd(r, r, S5_heapbase); |
aoqi@1 | 4134 | reinit_heapbase(); |
aoqi@1 | 4135 | } |
aoqi@1 | 4136 | } |
aoqi@1 | 4137 | |
aoqi@1 | 4138 | void MacroAssembler::decode_klass_not_null(Register dst, Register src) { |
aoqi@1 | 4139 | assert (UseCompressedClassPointers, "should only be used for compressed headers"); |
aoqi@1 | 4140 | |
aoqi@1 | 4141 | if (dst == src) { |
aoqi@1 | 4142 | decode_klass_not_null(dst); |
aoqi@1 | 4143 | } else { |
aoqi@1 | 4144 | // Cannot assert, unverified entry point counts instructions (see .ad file) |
aoqi@1 | 4145 | // vtableStubs also counts instructions in pd_code_size_limit. |
aoqi@1 | 4146 | // Also do not verify_oop as this is called by verify_oop. |
aoqi@1 | 4147 | li48(S5_heapbase, (int64_t)Universe::narrow_klass_base()); |
aoqi@1 | 4148 | if (Universe::narrow_klass_shift() != 0) { |
aoqi@1 | 4149 | assert(LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); |
aoqi@1 | 4150 | assert(LogKlassAlignmentInBytes == Address::times_8, "klass not aligned on 64bits?"); |
aoqi@1 | 4151 | dsll(dst, src, Address::times_8); |
aoqi@1 | 4152 | dadd(dst, dst, S5_heapbase); |
aoqi@1 | 4153 | } else { |
aoqi@1 | 4154 | dadd(dst, src, S5_heapbase); |
aoqi@1 | 4155 | } |
aoqi@1 | 4156 | reinit_heapbase(); |
aoqi@1 | 4157 | } |
aoqi@1 | 4158 | } |
aoqi@1 | 4159 | |
aoqi@1 | 4160 | /* |
aoqi@1 | 4161 | void MacroAssembler::set_narrow_oop(Register dst, jobject obj) { |
aoqi@1 | 4162 | assert(oop_recorder() != NULL, "this assembler needs an OopRecorder"); |
aoqi@1 | 4163 | int oop_index = oop_recorder()->find_index(obj); |
aoqi@1 | 4164 | RelocationHolder rspec = oop_Relocation::spec(oop_index); |
aoqi@1 | 4165 | mov_literal32(dst, oop_index, rspec, narrow_oop_operand); |
aoqi@1 | 4166 | } |
aoqi@1 | 4167 | */ |
aoqi@1 | 4168 | |
aoqi@1 | 4169 | void MacroAssembler::incrementl(Register reg, int value) { |
aoqi@1 | 4170 | if (value == min_jint) { |
aoqi@1 | 4171 | move(AT, value); |
aoqi@1 | 4172 | LP64_ONLY(addu32(reg, reg, AT)) NOT_LP64(addu(reg, reg, AT)); |
aoqi@1 | 4173 | return; |
aoqi@1 | 4174 | } |
aoqi@1 | 4175 | if (value < 0) { decrementl(reg, -value); return; } |
aoqi@1 | 4176 | if (value == 0) { ; return; } |
aoqi@1 | 4177 | |
aoqi@1 | 4178 | if(Assembler::is_simm16(value)) { |
aoqi@1 | 4179 | NOT_LP64(addiu(reg, reg, value)); |
aoqi@1 | 4180 | LP64_ONLY(move(AT, value); addu32(reg, reg, AT)); |
aoqi@1 | 4181 | } else { |
aoqi@1 | 4182 | move(AT, value); |
aoqi@1 | 4183 | LP64_ONLY(addu32(reg, reg, AT)) NOT_LP64(addu(reg, reg, AT)); |
aoqi@1 | 4184 | } |
aoqi@1 | 4185 | } |
aoqi@1 | 4186 | |
aoqi@1 | 4187 | void MacroAssembler::decrementl(Register reg, int value) { |
aoqi@1 | 4188 | if (value == min_jint) { |
aoqi@1 | 4189 | move(AT, value); |
aoqi@1 | 4190 | LP64_ONLY(subu32(reg, reg, AT)) NOT_LP64(subu(reg, reg, AT)); |
aoqi@1 | 4191 | return; |
aoqi@1 | 4192 | } |
aoqi@1 | 4193 | if (value < 0) { incrementl(reg, -value); return; } |
aoqi@1 | 4194 | if (value == 0) { ; return; } |
aoqi@1 | 4195 | |
aoqi@1 | 4196 | if(Assembler::is_simm16(value)) { |
aoqi@1 | 4197 | NOT_LP64(addiu(reg, reg, -value)); |
aoqi@1 | 4198 | LP64_ONLY(move(AT, value); subu32(reg, reg, AT)); |
aoqi@1 | 4199 | } else { |
aoqi@1 | 4200 | move(AT, value); |
aoqi@1 | 4201 | LP64_ONLY(subu32(reg, reg, AT)) NOT_LP64(subu(reg, reg, AT)); |
aoqi@1 | 4202 | } |
aoqi@1 | 4203 | } |
aoqi@1 | 4204 | |
aoqi@1 | 4205 | void MacroAssembler::reinit_heapbase() { |
aoqi@1 | 4206 | if (UseCompressedOops || UseCompressedClassPointers) { |
aoqi@1 | 4207 | if (Universe::heap() != NULL) { |
aoqi@1 | 4208 | if (Universe::narrow_oop_base() == NULL) { |
aoqi@1 | 4209 | move(S5_heapbase, R0); |
aoqi@1 | 4210 | } else { |
aoqi@1 | 4211 | li48(S5_heapbase, (int64_t)Universe::narrow_ptrs_base()); |
aoqi@1 | 4212 | } |
aoqi@1 | 4213 | } else { |
aoqi@1 | 4214 | li48(S5_heapbase, (intptr_t)Universe::narrow_ptrs_base_addr()); |
aoqi@1 | 4215 | ld(S5_heapbase, S5_heapbase, 0); |
aoqi@1 | 4216 | } |
aoqi@1 | 4217 | } |
aoqi@1 | 4218 | } |
aoqi@1 | 4219 | #endif // _LP64 |
aoqi@1 | 4220 | |
aoqi@1 | 4221 | void MacroAssembler::check_klass_subtype(Register sub_klass, |
aoqi@1 | 4222 | Register super_klass, |
aoqi@1 | 4223 | Register temp_reg, |
aoqi@1 | 4224 | Label& L_success) { |
aoqi@1 | 4225 | //implement ind gen_subtype_check |
aoqi@1 | 4226 | Label L_failure; |
aoqi@1 | 4227 | check_klass_subtype_fast_path(sub_klass, super_klass, temp_reg, &L_success, &L_failure, NULL); |
aoqi@1 | 4228 | check_klass_subtype_slow_path(sub_klass, super_klass, temp_reg, noreg, &L_success, NULL); |
aoqi@1 | 4229 | bind(L_failure); |
aoqi@1 | 4230 | } |
aoqi@1 | 4231 | |
aoqi@1 | 4232 | SkipIfEqual::SkipIfEqual( |
aoqi@1 | 4233 | MacroAssembler* masm, const bool* flag_addr, bool value) { |
aoqi@1 | 4234 | _masm = masm; |
aoqi@1 | 4235 | _masm->li(AT, (address)flag_addr); |
aoqi@1 | 4236 | _masm->lb(AT,AT,0); |
aoqi@1 | 4237 | _masm->addi(AT,AT,-value); |
aoqi@1 | 4238 | _masm->beq(AT,R0,_label); |
aoqi@1 | 4239 | _masm->delayed()->nop(); |
aoqi@1 | 4240 | } |
aoqi@1 | 4241 | void MacroAssembler::check_klass_subtype_fast_path(Register sub_klass, |
aoqi@1 | 4242 | Register super_klass, |
aoqi@1 | 4243 | Register temp_reg, |
aoqi@1 | 4244 | Label* L_success, |
aoqi@1 | 4245 | Label* L_failure, |
aoqi@1 | 4246 | Label* L_slow_path, |
aoqi@1 | 4247 | RegisterOrConstant super_check_offset) { |
aoqi@1 | 4248 | assert_different_registers(sub_klass, super_klass, temp_reg); |
aoqi@1 | 4249 | bool must_load_sco = (super_check_offset.constant_or_zero() == -1); |
aoqi@1 | 4250 | if (super_check_offset.is_register()) { |
aoqi@1 | 4251 | assert_different_registers(sub_klass, super_klass, |
aoqi@1 | 4252 | super_check_offset.as_register()); |
aoqi@1 | 4253 | } else if (must_load_sco) { |
aoqi@1 | 4254 | assert(temp_reg != noreg, "supply either a temp or a register offset"); |
aoqi@1 | 4255 | } |
aoqi@1 | 4256 | |
aoqi@1 | 4257 | Label L_fallthrough; |
aoqi@1 | 4258 | int label_nulls = 0; |
aoqi@1 | 4259 | if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; } |
aoqi@1 | 4260 | if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; } |
aoqi@1 | 4261 | if (L_slow_path == NULL) { L_slow_path = &L_fallthrough; label_nulls++; } |
aoqi@1 | 4262 | assert(label_nulls <= 1, "at most one NULL in the batch"); |
aoqi@1 | 4263 | |
aoqi@1 | 4264 | int sc_offset = in_bytes(Klass::secondary_super_cache_offset()); |
aoqi@1 | 4265 | int sco_offset = in_bytes(Klass::super_check_offset_offset()); |
aoqi@1 | 4266 | // If the pointers are equal, we are done (e.g., String[] elements). |
aoqi@1 | 4267 | // This self-check enables sharing of secondary supertype arrays among |
aoqi@1 | 4268 | // non-primary types such as array-of-interface. Otherwise, each such |
aoqi@1 | 4269 | // type would need its own customized SSA. |
aoqi@1 | 4270 | // We move this check to the front of the fast path because many |
aoqi@1 | 4271 | // type checks are in fact trivially successful in this manner, |
aoqi@1 | 4272 | // so we get a nicely predicted branch right at the start of the check. |
aoqi@1 | 4273 | //cmpptr(sub_klass, super_klass); |
aoqi@1 | 4274 | //local_jcc(Assembler::equal, *L_success); |
aoqi@1 | 4275 | beq(sub_klass, super_klass, *L_success); |
aoqi@1 | 4276 | delayed()->nop(); |
aoqi@1 | 4277 | // Check the supertype display: |
aoqi@1 | 4278 | if (must_load_sco) { |
aoqi@1 | 4279 | // Positive movl does right thing on LP64. |
aoqi@1 | 4280 | lwu(temp_reg, super_klass, sco_offset); |
aoqi@1 | 4281 | super_check_offset = RegisterOrConstant(temp_reg); |
aoqi@1 | 4282 | } |
aoqi@1 | 4283 | dsll(AT, super_check_offset.register_or_noreg(), Address::times_1); |
aoqi@1 | 4284 | daddu(AT, sub_klass, AT); |
aoqi@1 | 4285 | ld(AT, AT, super_check_offset.constant_or_zero()*Address::times_1); |
aoqi@1 | 4286 | |
aoqi@1 | 4287 | // This check has worked decisively for primary supers. |
aoqi@1 | 4288 | // Secondary supers are sought in the super_cache ('super_cache_addr'). |
aoqi@1 | 4289 | // (Secondary supers are interfaces and very deeply nested subtypes.) |
aoqi@1 | 4290 | // This works in the same check above because of a tricky aliasing |
aoqi@1 | 4291 | // between the super_cache and the primary super display elements. |
aoqi@1 | 4292 | // (The 'super_check_addr' can address either, as the case requires.) |
aoqi@1 | 4293 | // Note that the cache is updated below if it does not help us find |
aoqi@1 | 4294 | // what we need immediately. |
aoqi@1 | 4295 | // So if it was a primary super, we can just fail immediately. |
aoqi@1 | 4296 | // Otherwise, it's the slow path for us (no success at this point). |
aoqi@1 | 4297 | |
aoqi@1 | 4298 | if (super_check_offset.is_register()) { |
aoqi@1 | 4299 | beq(super_klass, AT, *L_success); |
aoqi@1 | 4300 | delayed()->nop(); |
aoqi@1 | 4301 | addi(AT, super_check_offset.as_register(), -sc_offset); |
aoqi@1 | 4302 | if (L_failure == &L_fallthrough) { |
aoqi@1 | 4303 | beq(AT, R0, *L_slow_path); |
aoqi@1 | 4304 | delayed()->nop(); |
aoqi@1 | 4305 | } else { |
aoqi@1 | 4306 | bne(AT, R0, *L_failure); |
aoqi@1 | 4307 | delayed()->nop(); |
aoqi@1 | 4308 | b(*L_slow_path); |
aoqi@1 | 4309 | delayed()->nop(); |
aoqi@1 | 4310 | } |
aoqi@1 | 4311 | } else if (super_check_offset.as_constant() == sc_offset) { |
aoqi@1 | 4312 | // Need a slow path; fast failure is impossible. |
aoqi@1 | 4313 | if (L_slow_path == &L_fallthrough) { |
aoqi@1 | 4314 | beq(super_klass, AT, *L_success); |
aoqi@1 | 4315 | delayed()->nop(); |
aoqi@1 | 4316 | } else { |
aoqi@1 | 4317 | bne(super_klass, AT, *L_slow_path); |
aoqi@1 | 4318 | delayed()->nop(); |
aoqi@1 | 4319 | b(*L_success); |
aoqi@1 | 4320 | delayed()->nop(); |
aoqi@1 | 4321 | } |
aoqi@1 | 4322 | } else { |
aoqi@1 | 4323 | // No slow path; it's a fast decision. |
aoqi@1 | 4324 | if (L_failure == &L_fallthrough) { |
aoqi@1 | 4325 | beq(super_klass, AT, *L_success); |
aoqi@1 | 4326 | delayed()->nop(); |
aoqi@1 | 4327 | } else { |
aoqi@1 | 4328 | bne(super_klass, AT, *L_failure); |
aoqi@1 | 4329 | delayed()->nop(); |
aoqi@1 | 4330 | b(*L_success); |
aoqi@1 | 4331 | delayed()->nop(); |
aoqi@1 | 4332 | } |
aoqi@1 | 4333 | } |
aoqi@1 | 4334 | |
aoqi@1 | 4335 | bind(L_fallthrough); |
aoqi@1 | 4336 | |
aoqi@1 | 4337 | } |
aoqi@1 | 4338 | |
aoqi@1 | 4339 | |
aoqi@1 | 4340 | void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass, |
aoqi@1 | 4341 | Register super_klass, |
aoqi@1 | 4342 | Register temp_reg, |
aoqi@1 | 4343 | Register temp2_reg, |
aoqi@1 | 4344 | Label* L_success, |
aoqi@1 | 4345 | Label* L_failure, |
aoqi@1 | 4346 | bool set_cond_codes) { |
aoqi@1 | 4347 | assert_different_registers(sub_klass, super_klass, temp_reg); |
aoqi@1 | 4348 | if (temp2_reg != noreg) |
aoqi@1 | 4349 | assert_different_registers(sub_klass, super_klass, temp_reg, temp2_reg); |
aoqi@1 | 4350 | else |
aoqi@1 | 4351 | temp2_reg = T9; |
aoqi@1 | 4352 | #define IS_A_TEMP(reg) ((reg) == temp_reg || (reg) == temp2_reg) |
aoqi@1 | 4353 | |
aoqi@1 | 4354 | Label L_fallthrough; |
aoqi@1 | 4355 | int label_nulls = 0; |
aoqi@1 | 4356 | if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; } |
aoqi@1 | 4357 | if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; } |
aoqi@1 | 4358 | assert(label_nulls <= 1, "at most one NULL in the batch"); |
aoqi@1 | 4359 | |
aoqi@1 | 4360 | // a couple of useful fields in sub_klass: |
aoqi@1 | 4361 | int ss_offset = in_bytes(Klass::secondary_supers_offset()); |
aoqi@1 | 4362 | int sc_offset = in_bytes(Klass::secondary_super_cache_offset()); |
aoqi@1 | 4363 | Address secondary_supers_addr(sub_klass, ss_offset); |
aoqi@1 | 4364 | Address super_cache_addr( sub_klass, sc_offset); |
aoqi@1 | 4365 | |
aoqi@1 | 4366 | // Do a linear scan of the secondary super-klass chain. |
aoqi@1 | 4367 | // This code is rarely used, so simplicity is a virtue here. |
aoqi@1 | 4368 | // The repne_scan instruction uses fixed registers, which we must spill. |
aoqi@1 | 4369 | // Don't worry too much about pre-existing connections with the input regs. |
aoqi@1 | 4370 | |
aoqi@1 | 4371 | #if 0 |
aoqi@1 | 4372 | assert(sub_klass != T9, "killed reg"); // killed by mov(rax, super) |
aoqi@1 | 4373 | assert(sub_klass != T1, "killed reg"); // killed by lea(rcx, &pst_counter) |
aoqi@1 | 4374 | #endif |
aoqi@1 | 4375 | |
aoqi@1 | 4376 | // Get super_klass value into rax (even if it was in rdi or rcx). |
aoqi@1 | 4377 | /* |
aoqi@1 | 4378 | bool pushed_rax = false, pushed_rcx = false, pushed_rdi = false; |
aoqi@1 | 4379 | if (super_klass != rax || UseCompressedOops) { |
aoqi@1 | 4380 | if (!IS_A_TEMP(rax)) { push(rax); pushed_rax = true; } |
aoqi@1 | 4381 | mov(rax, super_klass); |
aoqi@1 | 4382 | } |
aoqi@1 | 4383 | if (!IS_A_TEMP(rcx)) { push(rcx); pushed_rcx = true; } |
aoqi@1 | 4384 | if (!IS_A_TEMP(rdi)) { push(rdi); pushed_rdi = true; } |
aoqi@1 | 4385 | */ |
aoqi@1 | 4386 | #ifndef PRODUCT |
aoqi@1 | 4387 | int* pst_counter = &SharedRuntime::_partial_subtype_ctr; |
aoqi@1 | 4388 | ExternalAddress pst_counter_addr((address) pst_counter); |
aoqi@1 | 4389 | NOT_LP64( incrementl(pst_counter_addr) ); |
aoqi@1 | 4390 | //LP64_ONLY( lea(rcx, pst_counter_addr) ); |
aoqi@1 | 4391 | //LP64_ONLY( incrementl(Address(rcx, 0)) ); |
aoqi@1 | 4392 | #endif //PRODUCT |
aoqi@1 | 4393 | |
aoqi@1 | 4394 | // We will consult the secondary-super array. |
aoqi@1 | 4395 | ld(temp_reg, secondary_supers_addr); |
aoqi@1 | 4396 | // Load the array length. (Positive movl does right thing on LP64.) |
aoqi@1 | 4397 | lw(temp2_reg, Address(temp_reg, Array<Klass*>::length_offset_in_bytes())); |
aoqi@1 | 4398 | // Skip to start of data. |
aoqi@1 | 4399 | daddiu(temp_reg, temp_reg, Array<Klass*>::base_offset_in_bytes()); |
aoqi@1 | 4400 | |
aoqi@1 | 4401 | // Scan RCX words at [RDI] for an occurrence of RAX. |
aoqi@1 | 4402 | // Set NZ/Z based on last compare. |
aoqi@1 | 4403 | // Z flag value will not be set by 'repne' if RCX == 0 since 'repne' does |
aoqi@1 | 4404 | // not change flags (only scas instruction which is repeated sets flags). |
aoqi@1 | 4405 | // Set Z = 0 (not equal) before 'repne' to indicate that class was not found. |
aoqi@1 | 4406 | |
aoqi@1 | 4407 | /* 2013/4/3 Jin: OpenJDK8 never compresses klass pointers in secondary-super array. */ |
aoqi@1 | 4408 | Label Loop, subtype; |
aoqi@1 | 4409 | bind(Loop); |
aoqi@1 | 4410 | beq(temp2_reg, R0, *L_failure); |
aoqi@1 | 4411 | delayed()->nop(); |
aoqi@1 | 4412 | ld(AT, temp_reg, 0); |
aoqi@1 | 4413 | beq(AT, super_klass, subtype); |
aoqi@1 | 4414 | delayed()->daddi(temp_reg, temp_reg, 1 * wordSize); |
aoqi@1 | 4415 | b(Loop); |
aoqi@1 | 4416 | delayed()->daddi(temp2_reg, temp2_reg, -1); |
aoqi@1 | 4417 | |
aoqi@1 | 4418 | bind(subtype); |
aoqi@1 | 4419 | sd(super_klass, super_cache_addr); |
aoqi@1 | 4420 | if (L_success != &L_fallthrough) { |
aoqi@1 | 4421 | b(*L_success); |
aoqi@1 | 4422 | delayed()->nop(); |
aoqi@1 | 4423 | } |
aoqi@1 | 4424 | |
aoqi@1 | 4425 | /* |
aoqi@1 | 4426 | if (set_cond_codes) { |
aoqi@1 | 4427 | // Special hack for the AD files: rdi is guaranteed non-zero. |
aoqi@1 | 4428 | assert(!pushed_rdi, "rdi must be left non-NULL"); |
aoqi@1 | 4429 | // Also, the condition codes are properly set Z/NZ on succeed/failure. |
aoqi@1 | 4430 | } |
aoqi@1 | 4431 | */ |
aoqi@1 | 4432 | // Success. Cache the super we found and proceed in triumph. |
aoqi@1 | 4433 | #undef IS_A_TEMP |
aoqi@1 | 4434 | |
aoqi@1 | 4435 | bind(L_fallthrough); |
aoqi@1 | 4436 | } |
aoqi@1 | 4437 | void MacroAssembler::get_vm_result(Register oop_result, Register java_thread) { |
aoqi@1 | 4438 | ld(oop_result, Address(java_thread, JavaThread::vm_result_offset())); |
aoqi@1 | 4439 | sd(R0, Address(java_thread, JavaThread::vm_result_offset())); |
aoqi@1 | 4440 | verify_oop(oop_result, "broken oop in call_VM_base"); |
aoqi@1 | 4441 | } |
aoqi@1 | 4442 | |
aoqi@1 | 4443 | void MacroAssembler::get_vm_result_2(Register metadata_result, Register java_thread) { |
aoqi@1 | 4444 | ld(metadata_result, Address(java_thread, JavaThread::vm_result_2_offset())); |
aoqi@1 | 4445 | sd(R0, Address(java_thread, JavaThread::vm_result_2_offset())); |
aoqi@1 | 4446 | } |
aoqi@1 | 4447 | |
aoqi@1 | 4448 | Address MacroAssembler::argument_address(RegisterOrConstant arg_slot, |
aoqi@1 | 4449 | int extra_slot_offset) { |
aoqi@1 | 4450 | // cf. TemplateTable::prepare_invoke(), if (load_receiver). |
aoqi@1 | 4451 | int stackElementSize = Interpreter::stackElementSize; |
aoqi@1 | 4452 | int offset = Interpreter::expr_offset_in_bytes(extra_slot_offset+0); |
aoqi@1 | 4453 | #ifdef ASSERT |
aoqi@1 | 4454 | int offset1 = Interpreter::expr_offset_in_bytes(extra_slot_offset+1); |
aoqi@1 | 4455 | assert(offset1 - offset == stackElementSize, "correct arithmetic"); |
aoqi@1 | 4456 | #endif |
aoqi@1 | 4457 | Register scale_reg = NOREG; |
aoqi@1 | 4458 | Address::ScaleFactor scale_factor = Address::no_scale; |
aoqi@1 | 4459 | if (arg_slot.is_constant()) { |
aoqi@1 | 4460 | offset += arg_slot.as_constant() * stackElementSize; |
aoqi@1 | 4461 | } else { |
aoqi@1 | 4462 | scale_reg = arg_slot.as_register(); |
aoqi@1 | 4463 | scale_factor = Address::times_8; |
aoqi@1 | 4464 | } |
aoqi@1 | 4465 | // 2014/07/31 Fu: We don't push RA on stack in prepare_invoke. |
aoqi@1 | 4466 | // offset += wordSize; // return PC is on stack |
aoqi@1 | 4467 | if(scale_reg==NOREG) return Address(SP, offset); |
aoqi@1 | 4468 | else { |
aoqi@1 | 4469 | dsll(scale_reg, scale_reg, scale_factor); |
aoqi@1 | 4470 | daddu(scale_reg, SP, scale_reg); |
aoqi@1 | 4471 | return Address(scale_reg, offset); |
aoqi@1 | 4472 | } |
aoqi@1 | 4473 | } |
aoqi@1 | 4474 | |
aoqi@1 | 4475 | SkipIfEqual::~SkipIfEqual() { |
aoqi@1 | 4476 | _masm->bind(_label); |
aoqi@1 | 4477 | } |
aoqi@1 | 4478 | |
aoqi@1 | 4479 | void MacroAssembler::load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed, Register dst2) { |
aoqi@1 | 4480 | switch (size_in_bytes) { |
aoqi@1 | 4481 | #ifndef _LP64 |
aoqi@1 | 4482 | case 8: |
aoqi@1 | 4483 | assert(dst2 != noreg, "second dest register required"); |
aoqi@1 | 4484 | lw(dst, src); |
aoqi@1 | 4485 | lw(dst2, src.plus_disp(BytesPerInt)); |
aoqi@1 | 4486 | break; |
aoqi@1 | 4487 | #else |
aoqi@1 | 4488 | case 8: ld(dst, src); break; |
aoqi@1 | 4489 | #endif |
aoqi@1 | 4490 | case 4: lw(dst, src); break; |
aoqi@1 | 4491 | case 2: is_signed ? lh(dst, src) : lhu(dst, src); break; |
aoqi@1 | 4492 | case 1: is_signed ? lb( dst, src) : lbu( dst, src); break; |
aoqi@1 | 4493 | default: ShouldNotReachHere(); |
aoqi@1 | 4494 | } |
aoqi@1 | 4495 | } |
aoqi@1 | 4496 | |
aoqi@1 | 4497 | void MacroAssembler::store_sized_value(Address dst, Register src, size_t size_in_bytes, Register src2) { |
aoqi@1 | 4498 | switch (size_in_bytes) { |
aoqi@1 | 4499 | #ifndef _LP64 |
aoqi@1 | 4500 | case 8: |
aoqi@1 | 4501 | assert(src2 != noreg, "second source register required"); |
aoqi@1 | 4502 | sw(src, dst); |
aoqi@1 | 4503 | sw(src2, dst.plus_disp(BytesPerInt)); |
aoqi@1 | 4504 | break; |
aoqi@1 | 4505 | #else |
aoqi@1 | 4506 | case 8: sd(src, dst); break; |
aoqi@1 | 4507 | #endif |
aoqi@1 | 4508 | case 4: sw(src, dst); break; |
aoqi@1 | 4509 | case 2: sh(src, dst); break; |
aoqi@1 | 4510 | case 1: sb(src, dst); break; |
aoqi@1 | 4511 | default: ShouldNotReachHere(); |
aoqi@1 | 4512 | } |
aoqi@1 | 4513 | } |
aoqi@1 | 4514 | |
aoqi@1 | 4515 | // Look up the method for a megamorphic invokeinterface call. |
aoqi@1 | 4516 | // The target method is determined by <intf_klass, itable_index>. |
aoqi@1 | 4517 | // The receiver klass is in recv_klass. |
aoqi@1 | 4518 | // On success, the result will be in method_result, and execution falls through. |
aoqi@1 | 4519 | // On failure, execution transfers to the given label. |
aoqi@1 | 4520 | void MacroAssembler::lookup_interface_method(Register recv_klass, |
aoqi@1 | 4521 | Register intf_klass, |
aoqi@1 | 4522 | RegisterOrConstant itable_index, |
aoqi@1 | 4523 | Register method_result, |
aoqi@1 | 4524 | Register scan_temp, |
aoqi@1 | 4525 | Label& L_no_such_interface) { |
aoqi@1 | 4526 | assert_different_registers(recv_klass, intf_klass, method_result, scan_temp); |
aoqi@1 | 4527 | assert(itable_index.is_constant() || itable_index.as_register() == method_result, |
aoqi@1 | 4528 | "caller must use same register for non-constant itable index as for method"); |
aoqi@1 | 4529 | |
aoqi@1 | 4530 | // Compute start of first itableOffsetEntry (which is at the end of the vtable) |
aoqi@1 | 4531 | int vtable_base = InstanceKlass::vtable_start_offset() * wordSize; |
aoqi@1 | 4532 | int itentry_off = itableMethodEntry::method_offset_in_bytes(); |
aoqi@1 | 4533 | int scan_step = itableOffsetEntry::size() * wordSize; |
aoqi@1 | 4534 | int vte_size = vtableEntry::size() * wordSize; |
aoqi@1 | 4535 | Address::ScaleFactor times_vte_scale = Address::times_ptr; |
aoqi@1 | 4536 | assert(vte_size == wordSize, "else adjust times_vte_scale"); |
aoqi@1 | 4537 | |
aoqi@1 | 4538 | lw(scan_temp, Address(recv_klass, InstanceKlass::vtable_length_offset() * wordSize)); |
aoqi@1 | 4539 | |
aoqi@1 | 4540 | // %%% Could store the aligned, prescaled offset in the klassoop. |
aoqi@1 | 4541 | // lea(scan_temp, Address(recv_klass, scan_temp, times_vte_scale, vtable_base)); |
aoqi@1 | 4542 | dsll(scan_temp, scan_temp, times_vte_scale); |
aoqi@1 | 4543 | daddu(scan_temp, recv_klass, scan_temp); |
aoqi@1 | 4544 | daddiu(scan_temp, scan_temp, vtable_base); |
aoqi@1 | 4545 | if (HeapWordsPerLong > 1) { |
aoqi@1 | 4546 | // Round up to align_object_offset boundary |
aoqi@1 | 4547 | // see code for InstanceKlass::start_of_itable! |
aoqi@1 | 4548 | round_to(scan_temp, BytesPerLong); |
aoqi@1 | 4549 | } |
aoqi@1 | 4550 | |
aoqi@1 | 4551 | // Adjust recv_klass by scaled itable_index, so we can free itable_index. |
aoqi@1 | 4552 | assert(itableMethodEntry::size() * wordSize == wordSize, "adjust the scaling in the code below"); |
aoqi@1 | 4553 | // lea(recv_klass, Address(recv_klass, itable_index, Address::times_ptr, itentry_off)); |
aoqi@1 | 4554 | if (itable_index.is_constant()) { |
aoqi@1 | 4555 | li48(AT, (int)itable_index.is_constant()); |
aoqi@1 | 4556 | dsll(AT, AT, (int)Address::times_ptr); |
aoqi@1 | 4557 | } else { |
aoqi@1 | 4558 | dsll(AT, itable_index.as_register(), (int)Address::times_ptr); |
aoqi@1 | 4559 | } |
aoqi@1 | 4560 | daddu(AT, AT, recv_klass); |
aoqi@1 | 4561 | daddiu(recv_klass, AT, itentry_off); |
aoqi@1 | 4562 | |
aoqi@1 | 4563 | // for (scan = klass->itable(); scan->interface() != NULL; scan += scan_step) { |
aoqi@1 | 4564 | // if (scan->interface() == intf) { |
aoqi@1 | 4565 | // result = (klass + scan->offset() + itable_index); |
aoqi@1 | 4566 | // } |
aoqi@1 | 4567 | // } |
aoqi@1 | 4568 | Label search, found_method; |
aoqi@1 | 4569 | |
aoqi@1 | 4570 | for (int peel = 1; peel >= 0; peel--) { |
aoqi@1 | 4571 | ld(method_result, Address(scan_temp, itableOffsetEntry::interface_offset_in_bytes())); |
aoqi@1 | 4572 | |
aoqi@1 | 4573 | if (peel) { |
aoqi@1 | 4574 | beq(intf_klass, method_result, found_method); |
aoqi@1 | 4575 | nop(); |
aoqi@1 | 4576 | } else { |
aoqi@1 | 4577 | bne(intf_klass, method_result, search); |
aoqi@1 | 4578 | nop(); |
aoqi@1 | 4579 | // (invert the test to fall through to found_method...) |
aoqi@1 | 4580 | } |
aoqi@1 | 4581 | |
aoqi@1 | 4582 | if (!peel) break; |
aoqi@1 | 4583 | |
aoqi@1 | 4584 | bind(search); |
aoqi@1 | 4585 | |
aoqi@1 | 4586 | // Check that the previous entry is non-null. A null entry means that |
aoqi@1 | 4587 | // the receiver class doesn't implement the interface, and wasn't the |
aoqi@1 | 4588 | // same as when the caller was compiled. |
aoqi@1 | 4589 | beq(method_result, R0, L_no_such_interface); |
aoqi@1 | 4590 | nop(); |
aoqi@1 | 4591 | daddiu(scan_temp, scan_temp, scan_step); |
aoqi@1 | 4592 | } |
aoqi@1 | 4593 | |
aoqi@1 | 4594 | bind(found_method); |
aoqi@1 | 4595 | |
aoqi@1 | 4596 | // Got a hit. |
aoqi@1 | 4597 | lw(scan_temp, Address(scan_temp, itableOffsetEntry::offset_offset_in_bytes())); |
aoqi@1 | 4598 | ld(method_result, Address(recv_klass, scan_temp, Address::times_1)); |
aoqi@1 | 4599 | } |
aoqi@1 | 4600 | |
aoqi@1 | 4601 | |
aoqi@1 | 4602 | // virtual method calling |
aoqi@1 | 4603 | void MacroAssembler::lookup_virtual_method(Register recv_klass, |
aoqi@1 | 4604 | RegisterOrConstant vtable_index, |
aoqi@1 | 4605 | Register method_result) { |
aoqi@1 | 4606 | Register tmp = GP; |
aoqi@1 | 4607 | push(tmp); |
aoqi@1 | 4608 | |
aoqi@1 | 4609 | if (vtable_index.is_constant()) { |
aoqi@1 | 4610 | assert_different_registers(recv_klass, method_result, tmp); |
aoqi@1 | 4611 | } else { |
aoqi@1 | 4612 | assert_different_registers(recv_klass, method_result, vtable_index.as_register(), tmp); |
aoqi@1 | 4613 | } |
aoqi@1 | 4614 | const int base = InstanceKlass::vtable_start_offset() * wordSize; |
aoqi@1 | 4615 | assert(vtableEntry::size() * wordSize == wordSize, "else adjust the scaling in the code below"); |
aoqi@1 | 4616 | /* |
aoqi@1 | 4617 | Address vtable_entry_addr(recv_klass, |
aoqi@1 | 4618 | vtable_index, Address::times_ptr, |
aoqi@1 | 4619 | base + vtableEntry::method_offset_in_bytes()); |
aoqi@1 | 4620 | */ |
aoqi@1 | 4621 | if (vtable_index.is_constant()) { |
aoqi@1 | 4622 | li48(AT, vtable_index.as_constant()); |
aoqi@1 | 4623 | dsll(AT, AT, (int)Address::times_ptr); |
aoqi@1 | 4624 | } else { |
aoqi@1 | 4625 | dsll(AT, vtable_index.as_register(), (int)Address::times_ptr); |
aoqi@1 | 4626 | } |
aoqi@1 | 4627 | li48(tmp, base + vtableEntry::method_offset_in_bytes()); |
aoqi@1 | 4628 | daddu(tmp, tmp, AT); |
aoqi@1 | 4629 | daddu(tmp, tmp, recv_klass); |
aoqi@1 | 4630 | ld(method_result, tmp, 0); |
aoqi@1 | 4631 | |
aoqi@1 | 4632 | pop(tmp); |
aoqi@1 | 4633 | } |
aoqi@1 | 4634 |