src/cpu/mips/vm/macroAssembler_mips.cpp

Mon, 03 Sep 2018 14:27:42 +0800

author
zhaixiang
date
Mon, 03 Sep 2018 14:27:42 +0800
changeset 9227
f1560009a081
parent 9219
0fa7c31d7b02
child 9228
617b86d17edb
permissions
-rw-r--r--

#7503 [C1] Fix guarantee(Assembler::is_simm16(disp)) failed: must be issue
Summary: Implement disp is not simm16 for store_for_type and load_for_type
Reviewed-by: fujie

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

mercurial