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