1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/macroAssembler.hpp" 27 #include "interpreter/interpreter.hpp" 28 #include "interpreter/interpreterRuntime.hpp" 29 #include "interpreter/interp_masm.hpp" 30 #include "interpreter/templateTable.hpp" 31 #include "memory/universe.inline.hpp" 32 #include "oops/methodData.hpp" 33 #include "oops/objArrayKlass.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "prims/methodHandles.hpp" 36 #include "runtime/sharedRuntime.hpp" 37 #include "runtime/stubRoutines.hpp" 38 #include "runtime/synchronizer.hpp" 39 #include "utilities/macros.hpp" 40 41 #ifndef CC_INTERP 42 43 #define __ _masm-> 44 45 // Global Register Names 46 Register rbcp = LP64_ONLY(r13) NOT_LP64(rsi); 47 Register rlocals = LP64_ONLY(r14) NOT_LP64(rdi); 48 49 // Platform-dependent initialization 50 void TemplateTable::pd_initialize() { 51 // No x86 specific initialization 52 } 53 54 // Address Computation: local variables 55 static inline Address iaddress(int n) { 56 return Address(rlocals, Interpreter::local_offset_in_bytes(n)); 57 } 58 59 static inline Address laddress(int n) { 60 return iaddress(n + 1); 61 } 62 63 #ifndef _LP64 64 static inline Address haddress(int n) { 65 return iaddress(n + 0); 66 } 67 #endif 68 69 static inline Address faddress(int n) { 70 return iaddress(n); 71 } 72 73 static inline Address daddress(int n) { 74 return laddress(n); 75 } 76 77 static inline Address aaddress(int n) { 78 return iaddress(n); 79 } 80 81 static inline Address iaddress(Register r) { 82 return Address(rlocals, r, Address::times_ptr); 83 } 84 85 static inline Address laddress(Register r) { 86 return Address(rlocals, r, Address::times_ptr, Interpreter::local_offset_in_bytes(1)); 87 } 88 89 #ifndef _LP64 90 static inline Address haddress(Register r) { 91 return Address(rlocals, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0)); 92 } 93 #endif 94 95 static inline Address faddress(Register r) { 96 return iaddress(r); 97 } 98 99 static inline Address daddress(Register r) { 100 return laddress(r); 101 } 102 103 static inline Address aaddress(Register r) { 104 return iaddress(r); 105 } 106 107 108 // expression stack 109 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store 110 // data beyond the rsp which is potentially unsafe in an MT environment; 111 // an interrupt may overwrite that data.) 112 static inline Address at_rsp () { 113 return Address(rsp, 0); 114 } 115 116 // At top of Java expression stack which may be different than esp(). It 117 // isn't for category 1 objects. 118 static inline Address at_tos () { 119 return Address(rsp, Interpreter::expr_offset_in_bytes(0)); 120 } 121 122 static inline Address at_tos_p1() { 123 return Address(rsp, Interpreter::expr_offset_in_bytes(1)); 124 } 125 126 static inline Address at_tos_p2() { 127 return Address(rsp, Interpreter::expr_offset_in_bytes(2)); 128 } 129 130 // Condition conversion 131 static Assembler::Condition j_not(TemplateTable::Condition cc) { 132 switch (cc) { 133 case TemplateTable::equal : return Assembler::notEqual; 134 case TemplateTable::not_equal : return Assembler::equal; 135 case TemplateTable::less : return Assembler::greaterEqual; 136 case TemplateTable::less_equal : return Assembler::greater; 137 case TemplateTable::greater : return Assembler::lessEqual; 138 case TemplateTable::greater_equal: return Assembler::less; 139 } 140 ShouldNotReachHere(); 141 return Assembler::zero; 142 } 143 144 145 146 // Miscelaneous helper routines 147 // Store an oop (or NULL) at the address described by obj. 148 // If val == noreg this means store a NULL 149 150 151 static void do_oop_store(InterpreterMacroAssembler* _masm, 152 Address obj, 153 Register val, 154 BarrierSet::Name barrier, 155 bool precise) { 156 assert(val == noreg || val == rax, "parameter is just for looks"); 157 switch (barrier) { 158 #if INCLUDE_ALL_GCS 159 case BarrierSet::G1SATBCTLogging: 160 { 161 // flatten object address if needed 162 // We do it regardless of precise because we need the registers 163 if (obj.index() == noreg && obj.disp() == 0) { 164 if (obj.base() != rdx) { 165 __ movptr(rdx, obj.base()); 166 } 167 } else { 168 __ lea(rdx, obj); 169 } 170 171 Register rtmp = LP64_ONLY(r8) NOT_LP64(rsi); 172 Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx); 173 174 NOT_LP64(__ get_thread(rcx)); 175 NOT_LP64(__ save_bcp()); 176 177 __ g1_write_barrier_pre(rdx /* obj */, 178 rbx /* pre_val */, 179 rthread /* thread */, 180 rtmp /* tmp */, 181 val != noreg /* tosca_live */, 182 false /* expand_call */); 183 if (val == noreg) { 184 __ store_heap_oop_null(Address(rdx, 0)); 185 } else { 186 // G1 barrier needs uncompressed oop for region cross check. 187 Register new_val = val; 188 if (UseCompressedOops) { 189 new_val = rbx; 190 __ movptr(new_val, val); 191 } 192 __ store_heap_oop(Address(rdx, 0), val); 193 __ g1_write_barrier_post(rdx /* store_adr */, 194 new_val /* new_val */, 195 rthread /* thread */, 196 rtmp /* tmp */, 197 rbx /* tmp2 */); 198 } 199 NOT_LP64( __ restore_bcp()); 200 } 201 break; 202 #endif // INCLUDE_ALL_GCS 203 case BarrierSet::CardTableModRef: 204 case BarrierSet::CardTableExtension: 205 { 206 if (val == noreg) { 207 __ store_heap_oop_null(obj); 208 } else { 209 __ store_heap_oop(obj, val); 210 // flatten object address if needed 211 if (!precise || (obj.index() == noreg && obj.disp() == 0)) { 212 __ store_check(obj.base()); 213 } else { 214 __ lea(rdx, obj); 215 __ store_check(rdx); 216 } 217 } 218 } 219 break; 220 case BarrierSet::ModRef: 221 if (val == noreg) { 222 __ store_heap_oop_null(obj); 223 } else { 224 __ store_heap_oop(obj, val); 225 } 226 break; 227 default : 228 ShouldNotReachHere(); 229 230 } 231 } 232 233 Address TemplateTable::at_bcp(int offset) { 234 assert(_desc->uses_bcp(), "inconsistent uses_bcp information"); 235 return Address(rbcp, offset); 236 } 237 238 239 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg, 240 Register temp_reg, bool load_bc_into_bc_reg/*=true*/, 241 int byte_no) { 242 if (!RewriteBytecodes) return; 243 Label L_patch_done; 244 245 switch (bc) { 246 case Bytecodes::_fast_aputfield: 247 case Bytecodes::_fast_bputfield: 248 case Bytecodes::_fast_cputfield: 249 case Bytecodes::_fast_dputfield: 250 case Bytecodes::_fast_fputfield: 251 case Bytecodes::_fast_iputfield: 252 case Bytecodes::_fast_lputfield: 253 case Bytecodes::_fast_sputfield: 254 { 255 // We skip bytecode quickening for putfield instructions when 256 // the put_code written to the constant pool cache is zero. 257 // This is required so that every execution of this instruction 258 // calls out to InterpreterRuntime::resolve_get_put to do 259 // additional, required work. 260 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 261 assert(load_bc_into_bc_reg, "we use bc_reg as temp"); 262 __ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1); 263 __ movl(bc_reg, bc); 264 __ cmpl(temp_reg, (int) 0); 265 __ jcc(Assembler::zero, L_patch_done); // don't patch 266 } 267 break; 268 default: 269 assert(byte_no == -1, "sanity"); 270 // the pair bytecodes have already done the load. 271 if (load_bc_into_bc_reg) { 272 __ movl(bc_reg, bc); 273 } 274 } 275 276 if (JvmtiExport::can_post_breakpoint()) { 277 Label L_fast_patch; 278 // if a breakpoint is present we can't rewrite the stream directly 279 __ movzbl(temp_reg, at_bcp(0)); 280 __ cmpl(temp_reg, Bytecodes::_breakpoint); 281 __ jcc(Assembler::notEqual, L_fast_patch); 282 __ get_method(temp_reg); 283 // Let breakpoint table handling rewrite to quicker bytecode 284 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), temp_reg, rbcp, bc_reg); 285 #ifndef ASSERT 286 __ jmpb(L_patch_done); 287 #else 288 __ jmp(L_patch_done); 289 #endif 290 __ bind(L_fast_patch); 291 } 292 293 #ifdef ASSERT 294 Label L_okay; 295 __ load_unsigned_byte(temp_reg, at_bcp(0)); 296 __ cmpl(temp_reg, (int) Bytecodes::java_code(bc)); 297 __ jcc(Assembler::equal, L_okay); 298 __ cmpl(temp_reg, bc_reg); 299 __ jcc(Assembler::equal, L_okay); 300 __ stop("patching the wrong bytecode"); 301 __ bind(L_okay); 302 #endif 303 304 // patch bytecode 305 __ movb(at_bcp(0), bc_reg); 306 __ bind(L_patch_done); 307 } 308 // Individual instructions 309 310 311 void TemplateTable::nop() { 312 transition(vtos, vtos); 313 // nothing to do 314 } 315 316 void TemplateTable::shouldnotreachhere() { 317 transition(vtos, vtos); 318 __ stop("shouldnotreachhere bytecode"); 319 } 320 321 void TemplateTable::aconst_null() { 322 transition(vtos, atos); 323 __ xorl(rax, rax); 324 } 325 326 void TemplateTable::iconst(int value) { 327 transition(vtos, itos); 328 if (value == 0) { 329 __ xorl(rax, rax); 330 } else { 331 __ movl(rax, value); 332 } 333 } 334 335 void TemplateTable::lconst(int value) { 336 transition(vtos, ltos); 337 if (value == 0) { 338 __ xorl(rax, rax); 339 } else { 340 __ movl(rax, value); 341 } 342 #ifndef _LP64 343 assert(value >= 0, "check this code"); 344 __ xorptr(rdx, rdx); 345 #endif 346 } 347 348 349 350 void TemplateTable::fconst(int value) { 351 transition(vtos, ftos); 352 #ifdef _LP64 353 static float one = 1.0f, two = 2.0f; 354 switch (value) { 355 case 0: 356 __ xorps(xmm0, xmm0); 357 break; 358 case 1: 359 __ movflt(xmm0, ExternalAddress((address) &one)); 360 break; 361 case 2: 362 __ movflt(xmm0, ExternalAddress((address) &two)); 363 break; 364 default: 365 ShouldNotReachHere(); 366 break; 367 } 368 #else 369 if (value == 0) { __ fldz(); 370 } else if (value == 1) { __ fld1(); 371 } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here 372 } else { ShouldNotReachHere(); 373 } 374 #endif 375 } 376 377 void TemplateTable::dconst(int value) { 378 transition(vtos, dtos); 379 #ifdef _LP64 380 static double one = 1.0; 381 switch (value) { 382 case 0: 383 __ xorpd(xmm0, xmm0); 384 break; 385 case 1: 386 __ movdbl(xmm0, ExternalAddress((address) &one)); 387 break; 388 default: 389 ShouldNotReachHere(); 390 break; 391 } 392 393 #else 394 if (value == 0) { __ fldz(); 395 } else if (value == 1) { __ fld1(); 396 } else { ShouldNotReachHere(); 397 } 398 #endif 399 } 400 401 void TemplateTable::bipush() { 402 transition(vtos, itos); 403 __ load_signed_byte(rax, at_bcp(1)); 404 } 405 406 void TemplateTable::sipush() { 407 transition(vtos, itos); 408 __ load_unsigned_short(rax, at_bcp(1)); 409 __ bswapl(rax); 410 __ sarl(rax, 16); 411 } 412 413 void TemplateTable::ldc(bool wide) { 414 transition(vtos, vtos); 415 Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1); 416 Label call_ldc, notFloat, notClass, Done; 417 418 if (wide) { 419 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); 420 } else { 421 __ load_unsigned_byte(rbx, at_bcp(1)); 422 } 423 424 __ get_cpool_and_tags(rcx, rax); 425 const int base_offset = ConstantPool::header_size() * wordSize; 426 const int tags_offset = Array<u1>::base_offset_in_bytes(); 427 428 // get type 429 __ movzbl(rdx, Address(rax, rbx, Address::times_1, tags_offset)); 430 431 // unresolved class - get the resolved class 432 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass); 433 __ jccb(Assembler::equal, call_ldc); 434 435 // unresolved class in error state - call into runtime to throw the error 436 // from the first resolution attempt 437 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError); 438 __ jccb(Assembler::equal, call_ldc); 439 440 // resolved class - need to call vm to get java mirror of the class 441 __ cmpl(rdx, JVM_CONSTANT_Class); 442 __ jcc(Assembler::notEqual, notClass); 443 444 __ bind(call_ldc); 445 446 __ movl(rarg, wide); 447 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rarg); 448 449 __ push(atos); 450 __ jmp(Done); 451 452 __ bind(notClass); 453 __ cmpl(rdx, JVM_CONSTANT_Float); 454 __ jccb(Assembler::notEqual, notFloat); 455 456 // ftos 457 LP64_ONLY(__ movflt(xmm0, Address(rcx, rbx, Address::times_8, base_offset))); 458 NOT_LP64(__ fld_s( Address(rcx, rbx, Address::times_ptr, base_offset))); 459 __ push(ftos); 460 __ jmp(Done); 461 462 __ bind(notFloat); 463 #ifdef ASSERT 464 { 465 Label L; 466 __ cmpl(rdx, JVM_CONSTANT_Integer); 467 __ jcc(Assembler::equal, L); 468 // String and Object are rewritten to fast_aldc 469 __ stop("unexpected tag type in ldc"); 470 __ bind(L); 471 } 472 #endif 473 // itos JVM_CONSTANT_Integer only 474 __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset)); 475 __ push(itos); 476 __ bind(Done); 477 } 478 479 // Fast path for caching oop constants. 480 void TemplateTable::fast_aldc(bool wide) { 481 transition(vtos, atos); 482 483 Register result = rax; 484 Register tmp = rdx; 485 int index_size = wide ? sizeof(u2) : sizeof(u1); 486 487 Label resolved; 488 489 // We are resolved if the resolved reference cache entry contains a 490 // non-null object (String, MethodType, etc.) 491 assert_different_registers(result, tmp); 492 __ get_cache_index_at_bcp(tmp, 1, index_size); 493 __ load_resolved_reference_at_index(result, tmp); 494 __ testl(result, result); 495 __ jcc(Assembler::notZero, resolved); 496 497 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); 498 499 // first time invocation - must resolve first 500 __ movl(tmp, (int)bytecode()); 501 __ call_VM(result, entry, tmp); 502 503 __ bind(resolved); 504 505 if (VerifyOops) { 506 __ verify_oop(result); 507 } 508 } 509 510 void TemplateTable::ldc2_w() { 511 transition(vtos, vtos); 512 Label Long, Done; 513 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); 514 515 __ get_cpool_and_tags(rcx, rax); 516 const int base_offset = ConstantPool::header_size() * wordSize; 517 const int tags_offset = Array<u1>::base_offset_in_bytes(); 518 519 // get type 520 __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), 521 JVM_CONSTANT_Double); 522 __ jccb(Assembler::notEqual, Long); 523 524 // dtos 525 LP64_ONLY(__ movdbl(xmm0, Address(rcx, rbx, Address::times_8, base_offset))); 526 NOT_LP64(__ fld_d( Address(rcx, rbx, Address::times_ptr, base_offset))); 527 __ push(dtos); 528 529 __ jmpb(Done); 530 __ bind(Long); 531 532 // ltos 533 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize)); 534 NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize))); 535 __ push(ltos); 536 537 __ bind(Done); 538 } 539 540 void TemplateTable::locals_index(Register reg, int offset) { 541 __ load_unsigned_byte(reg, at_bcp(offset)); 542 __ negptr(reg); 543 } 544 545 void TemplateTable::iload() { 546 iload_internal(); 547 } 548 549 void TemplateTable::nofast_iload() { 550 iload_internal(may_not_rewrite); 551 } 552 553 void TemplateTable::iload_internal(RewriteControl rc) { 554 transition(vtos, itos); 555 if (RewriteFrequentPairs && rc == may_rewrite) { 556 Label rewrite, done; 557 const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 558 LP64_ONLY(assert(rbx != bc, "register damaged")); 559 560 // get next byte 561 __ load_unsigned_byte(rbx, 562 at_bcp(Bytecodes::length_for(Bytecodes::_iload))); 563 // if _iload, wait to rewrite to iload2. We only want to rewrite the 564 // last two iloads in a pair. Comparing against fast_iload means that 565 // the next bytecode is neither an iload or a caload, and therefore 566 // an iload pair. 567 __ cmpl(rbx, Bytecodes::_iload); 568 __ jcc(Assembler::equal, done); 569 570 __ cmpl(rbx, Bytecodes::_fast_iload); 571 __ movl(bc, Bytecodes::_fast_iload2); 572 573 __ jccb(Assembler::equal, rewrite); 574 575 // if _caload, rewrite to fast_icaload 576 __ cmpl(rbx, Bytecodes::_caload); 577 __ movl(bc, Bytecodes::_fast_icaload); 578 __ jccb(Assembler::equal, rewrite); 579 580 // rewrite so iload doesn't check again. 581 __ movl(bc, Bytecodes::_fast_iload); 582 583 // rewrite 584 // bc: fast bytecode 585 __ bind(rewrite); 586 patch_bytecode(Bytecodes::_iload, bc, rbx, false); 587 __ bind(done); 588 } 589 590 // Get the local value into tos 591 locals_index(rbx); 592 __ movl(rax, iaddress(rbx)); 593 } 594 595 void TemplateTable::fast_iload2() { 596 transition(vtos, itos); 597 locals_index(rbx); 598 __ movl(rax, iaddress(rbx)); 599 __ push(itos); 600 locals_index(rbx, 3); 601 __ movl(rax, iaddress(rbx)); 602 } 603 604 void TemplateTable::fast_iload() { 605 transition(vtos, itos); 606 locals_index(rbx); 607 __ movl(rax, iaddress(rbx)); 608 } 609 610 void TemplateTable::lload() { 611 transition(vtos, ltos); 612 locals_index(rbx); 613 __ movptr(rax, laddress(rbx)); 614 NOT_LP64(__ movl(rdx, haddress(rbx))); 615 } 616 617 void TemplateTable::fload() { 618 transition(vtos, ftos); 619 locals_index(rbx); 620 LP64_ONLY(__ movflt(xmm0, faddress(rbx))); 621 NOT_LP64(__ fld_s(faddress(rbx))); 622 } 623 624 void TemplateTable::dload() { 625 transition(vtos, dtos); 626 locals_index(rbx); 627 LP64_ONLY(__ movdbl(xmm0, daddress(rbx))); 628 NOT_LP64(__ fld_d(daddress(rbx))); 629 } 630 631 void TemplateTable::aload() { 632 transition(vtos, atos); 633 locals_index(rbx); 634 __ movptr(rax, aaddress(rbx)); 635 } 636 637 void TemplateTable::locals_index_wide(Register reg) { 638 __ load_unsigned_short(reg, at_bcp(2)); 639 __ bswapl(reg); 640 __ shrl(reg, 16); 641 __ negptr(reg); 642 } 643 644 void TemplateTable::wide_iload() { 645 transition(vtos, itos); 646 locals_index_wide(rbx); 647 __ movl(rax, iaddress(rbx)); 648 } 649 650 void TemplateTable::wide_lload() { 651 transition(vtos, ltos); 652 locals_index_wide(rbx); 653 __ movptr(rax, laddress(rbx)); 654 NOT_LP64(__ movl(rdx, haddress(rbx))); 655 } 656 657 void TemplateTable::wide_fload() { 658 transition(vtos, ftos); 659 locals_index_wide(rbx); 660 LP64_ONLY(__ movflt(xmm0, faddress(rbx))); 661 NOT_LP64(__ fld_s(faddress(rbx))); 662 } 663 664 void TemplateTable::wide_dload() { 665 transition(vtos, dtos); 666 locals_index_wide(rbx); 667 LP64_ONLY(__ movdbl(xmm0, daddress(rbx))); 668 NOT_LP64(__ fld_d(daddress(rbx))); 669 } 670 671 void TemplateTable::wide_aload() { 672 transition(vtos, atos); 673 locals_index_wide(rbx); 674 __ movptr(rax, aaddress(rbx)); 675 } 676 677 void TemplateTable::index_check(Register array, Register index) { 678 // Pop ptr into array 679 __ pop_ptr(array); 680 index_check_without_pop(array, index); 681 } 682 683 void TemplateTable::index_check_without_pop(Register array, Register index) { 684 // destroys rbx 685 // check array 686 __ null_check(array, arrayOopDesc::length_offset_in_bytes()); 687 // sign extend index for use by indexed load 688 __ movl2ptr(index, index); 689 // check index 690 __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes())); 691 if (index != rbx) { 692 // ??? convention: move aberrant index into rbx for exception message 693 assert(rbx != array, "different registers"); 694 __ movl(rbx, index); 695 } 696 __ jump_cc(Assembler::aboveEqual, 697 ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry)); 698 } 699 700 701 void TemplateTable::iaload() { 702 transition(itos, itos); 703 // rax: index 704 // rdx: array 705 index_check(rdx, rax); // kills rbx 706 __ movl(rax, Address(rdx, rax, 707 Address::times_4, 708 arrayOopDesc::base_offset_in_bytes(T_INT))); 709 } 710 711 void TemplateTable::laload() { 712 transition(itos, ltos); 713 // rax: index 714 // rdx: array 715 index_check(rdx, rax); // kills rbx 716 NOT_LP64(__ mov(rbx, rax)); 717 // rbx,: index 718 __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize)); 719 NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize))); 720 } 721 722 723 724 void TemplateTable::faload() { 725 transition(itos, ftos); 726 // rax: index 727 // rdx: array 728 index_check(rdx, rax); // kills rbx 729 LP64_ONLY(__ movflt(xmm0, Address(rdx, rax, 730 Address::times_4, 731 arrayOopDesc::base_offset_in_bytes(T_FLOAT)))); 732 NOT_LP64(__ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)))); 733 } 734 735 void TemplateTable::daload() { 736 transition(itos, dtos); 737 // rax: index 738 // rdx: array 739 index_check(rdx, rax); // kills rbx 740 LP64_ONLY(__ movdbl(xmm0, Address(rdx, rax, 741 Address::times_8, 742 arrayOopDesc::base_offset_in_bytes(T_DOUBLE)))); 743 NOT_LP64(__ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)))); 744 } 745 746 void TemplateTable::aaload() { 747 transition(itos, atos); 748 // rax: index 749 // rdx: array 750 index_check(rdx, rax); // kills rbx 751 __ load_heap_oop(rax, Address(rdx, rax, 752 UseCompressedOops ? Address::times_4 : Address::times_ptr, 753 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); 754 } 755 756 void TemplateTable::baload() { 757 transition(itos, itos); 758 // rax: index 759 // rdx: array 760 index_check(rdx, rax); // kills rbx 761 __ load_signed_byte(rax, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE))); 762 } 763 764 void TemplateTable::caload() { 765 transition(itos, itos); 766 // rax: index 767 // rdx: array 768 index_check(rdx, rax); // kills rbx 769 __ load_unsigned_short(rax, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 770 } 771 772 // iload followed by caload frequent pair 773 void TemplateTable::fast_icaload() { 774 transition(vtos, itos); 775 // load index out of locals 776 locals_index(rbx); 777 __ movl(rax, iaddress(rbx)); 778 779 // rax: index 780 // rdx: array 781 index_check(rdx, rax); // kills rbx 782 __ load_unsigned_short(rax, 783 Address(rdx, rax, 784 Address::times_2, 785 arrayOopDesc::base_offset_in_bytes(T_CHAR))); 786 } 787 788 789 void TemplateTable::saload() { 790 transition(itos, itos); 791 // rax: index 792 // rdx: array 793 index_check(rdx, rax); // kills rbx 794 __ load_signed_short(rax, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT))); 795 } 796 797 void TemplateTable::iload(int n) { 798 transition(vtos, itos); 799 __ movl(rax, iaddress(n)); 800 } 801 802 void TemplateTable::lload(int n) { 803 transition(vtos, ltos); 804 __ movptr(rax, laddress(n)); 805 NOT_LP64(__ movptr(rdx, haddress(n))); 806 } 807 808 void TemplateTable::fload(int n) { 809 transition(vtos, ftos); 810 LP64_ONLY(__ movflt(xmm0, faddress(n))); 811 NOT_LP64(__ fld_s(faddress(n))); 812 } 813 814 void TemplateTable::dload(int n) { 815 transition(vtos, dtos); 816 LP64_ONLY(__ movdbl(xmm0, daddress(n))); 817 NOT_LP64(__ fld_d(daddress(n))); 818 } 819 820 void TemplateTable::aload(int n) { 821 transition(vtos, atos); 822 __ movptr(rax, aaddress(n)); 823 } 824 825 void TemplateTable::aload_0() { 826 aload_0_internal(); 827 } 828 829 void TemplateTable::nofast_aload_0() { 830 aload_0_internal(may_not_rewrite); 831 } 832 833 void TemplateTable::aload_0_internal(RewriteControl rc) { 834 transition(vtos, atos); 835 // According to bytecode histograms, the pairs: 836 // 837 // _aload_0, _fast_igetfield 838 // _aload_0, _fast_agetfield 839 // _aload_0, _fast_fgetfield 840 // 841 // occur frequently. If RewriteFrequentPairs is set, the (slow) 842 // _aload_0 bytecode checks if the next bytecode is either 843 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then 844 // rewrites the current bytecode into a pair bytecode; otherwise it 845 // rewrites the current bytecode into _fast_aload_0 that doesn't do 846 // the pair check anymore. 847 // 848 // Note: If the next bytecode is _getfield, the rewrite must be 849 // delayed, otherwise we may miss an opportunity for a pair. 850 // 851 // Also rewrite frequent pairs 852 // aload_0, aload_1 853 // aload_0, iload_1 854 // These bytecodes with a small amount of code are most profitable 855 // to rewrite 856 if (RewriteFrequentPairs && rc == may_rewrite) { 857 Label rewrite, done; 858 859 const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 860 LP64_ONLY(assert(rbx != bc, "register damaged")); 861 862 // get next byte 863 __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0))); 864 865 // do actual aload_0 866 aload(0); 867 868 // if _getfield then wait with rewrite 869 __ cmpl(rbx, Bytecodes::_getfield); 870 __ jcc(Assembler::equal, done); 871 872 // if _igetfield then reqrite to _fast_iaccess_0 873 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 874 __ cmpl(rbx, Bytecodes::_fast_igetfield); 875 __ movl(bc, Bytecodes::_fast_iaccess_0); 876 __ jccb(Assembler::equal, rewrite); 877 878 // if _agetfield then reqrite to _fast_aaccess_0 879 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 880 __ cmpl(rbx, Bytecodes::_fast_agetfield); 881 __ movl(bc, Bytecodes::_fast_aaccess_0); 882 __ jccb(Assembler::equal, rewrite); 883 884 // if _fgetfield then reqrite to _fast_faccess_0 885 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 886 __ cmpl(rbx, Bytecodes::_fast_fgetfield); 887 __ movl(bc, Bytecodes::_fast_faccess_0); 888 __ jccb(Assembler::equal, rewrite); 889 890 // else rewrite to _fast_aload0 891 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition"); 892 __ movl(bc, Bytecodes::_fast_aload_0); 893 894 // rewrite 895 // bc: fast bytecode 896 __ bind(rewrite); 897 patch_bytecode(Bytecodes::_aload_0, bc, rbx, false); 898 899 __ bind(done); 900 } else { 901 aload(0); 902 } 903 } 904 905 void TemplateTable::istore() { 906 transition(itos, vtos); 907 locals_index(rbx); 908 __ movl(iaddress(rbx), rax); 909 } 910 911 912 void TemplateTable::lstore() { 913 transition(ltos, vtos); 914 locals_index(rbx); 915 __ movptr(laddress(rbx), rax); 916 NOT_LP64(__ movptr(haddress(rbx), rdx)); 917 } 918 919 void TemplateTable::fstore() { 920 transition(ftos, vtos); 921 locals_index(rbx); 922 LP64_ONLY(__ movflt(faddress(rbx), xmm0)); 923 NOT_LP64(__ fstp_s(faddress(rbx))); 924 } 925 926 void TemplateTable::dstore() { 927 transition(dtos, vtos); 928 locals_index(rbx); 929 LP64_ONLY(__ movdbl(daddress(rbx), xmm0)); 930 NOT_LP64(__ fstp_d(daddress(rbx))); 931 } 932 933 void TemplateTable::astore() { 934 transition(vtos, vtos); 935 __ pop_ptr(rax); 936 locals_index(rbx); 937 __ movptr(aaddress(rbx), rax); 938 } 939 940 void TemplateTable::wide_istore() { 941 transition(vtos, vtos); 942 __ pop_i(); 943 locals_index_wide(rbx); 944 __ movl(iaddress(rbx), rax); 945 } 946 947 void TemplateTable::wide_lstore() { 948 transition(vtos, vtos); 949 NOT_LP64(__ pop_l(rax, rdx)); 950 LP64_ONLY(__ pop_l()); 951 locals_index_wide(rbx); 952 __ movptr(laddress(rbx), rax); 953 NOT_LP64(__ movl(haddress(rbx), rdx)); 954 } 955 956 void TemplateTable::wide_fstore() { 957 #ifdef _LP64 958 transition(vtos, vtos); 959 __ pop_f(); 960 locals_index_wide(rbx); 961 __ movflt(faddress(rbx), xmm0); 962 #else 963 wide_istore(); 964 #endif 965 } 966 967 void TemplateTable::wide_dstore() { 968 #ifdef _LP64 969 transition(vtos, vtos); 970 __ pop_d(); 971 locals_index_wide(rbx); 972 __ movdbl(daddress(rbx), xmm0); 973 #else 974 wide_lstore(); 975 #endif 976 } 977 978 void TemplateTable::wide_astore() { 979 transition(vtos, vtos); 980 __ pop_ptr(rax); 981 locals_index_wide(rbx); 982 __ movptr(aaddress(rbx), rax); 983 } 984 985 void TemplateTable::iastore() { 986 transition(itos, vtos); 987 __ pop_i(rbx); 988 // rax: value 989 // rbx: index 990 // rdx: array 991 index_check(rdx, rbx); // prefer index in rbx 992 __ movl(Address(rdx, rbx, 993 Address::times_4, 994 arrayOopDesc::base_offset_in_bytes(T_INT)), 995 rax); 996 } 997 998 void TemplateTable::lastore() { 999 transition(ltos, vtos); 1000 __ pop_i(rbx); 1001 // rax,: low(value) 1002 // rcx: array 1003 // rdx: high(value) 1004 index_check(rcx, rbx); // prefer index in rbx, 1005 // rbx,: index 1006 __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax); 1007 NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx)); 1008 } 1009 1010 1011 void TemplateTable::fastore() { 1012 transition(ftos, vtos); 1013 __ pop_i(rbx); 1014 // xmm0: value 1015 // rbx: index 1016 // rdx: array 1017 index_check(rdx, rbx); // prefer index in rbx 1018 LP64_ONLY(__ movflt(Address(rdx, rbx, 1019 Address::times_4, 1020 arrayOopDesc::base_offset_in_bytes(T_FLOAT)), 1021 xmm0)); 1022 NOT_LP64(__ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)))); 1023 } 1024 1025 void TemplateTable::dastore() { 1026 transition(dtos, vtos); 1027 __ pop_i(rbx); 1028 // xmm0: value 1029 // rbx: index 1030 // rdx: array 1031 index_check(rdx, rbx); // prefer index in rbx 1032 LP64_ONLY(__ movdbl(Address(rdx, rbx, 1033 Address::times_8, 1034 arrayOopDesc::base_offset_in_bytes(T_DOUBLE)), 1035 xmm0)); 1036 NOT_LP64(__ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)))); 1037 } 1038 1039 void TemplateTable::aastore() { 1040 Label is_null, ok_is_subtype, done; 1041 transition(vtos, vtos); 1042 // stack: ..., array, index, value 1043 __ movptr(rax, at_tos()); // value 1044 __ movl(rcx, at_tos_p1()); // index 1045 __ movptr(rdx, at_tos_p2()); // array 1046 1047 Address element_address(rdx, rcx, 1048 UseCompressedOops? Address::times_4 : Address::times_ptr, 1049 arrayOopDesc::base_offset_in_bytes(T_OBJECT)); 1050 1051 index_check_without_pop(rdx, rcx); // kills rbx 1052 __ testptr(rax, rax); 1053 __ jcc(Assembler::zero, is_null); 1054 1055 // Move subklass into rbx 1056 __ load_klass(rbx, rax); 1057 // Move superklass into rax 1058 __ load_klass(rax, rdx); 1059 __ movptr(rax, Address(rax, 1060 ObjArrayKlass::element_klass_offset())); 1061 // Compress array + index*oopSize + 12 into a single register. Frees rcx. 1062 __ lea(rdx, element_address); 1063 1064 // Generate subtype check. Blows rcx, rdi 1065 // Superklass in rax. Subklass in rbx. 1066 __ gen_subtype_check(rbx, ok_is_subtype); 1067 1068 // Come here on failure 1069 // object is at TOS 1070 __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry)); 1071 1072 // Come here on success 1073 __ bind(ok_is_subtype); 1074 1075 // Get the value we will store 1076 __ movptr(rax, at_tos()); 1077 // Now store using the appropriate barrier 1078 do_oop_store(_masm, Address(rdx, 0), rax, _bs->kind(), true); 1079 __ jmp(done); 1080 1081 // Have a NULL in rax, rdx=array, ecx=index. Store NULL at ary[idx] 1082 __ bind(is_null); 1083 __ profile_null_seen(rbx); 1084 1085 // Store a NULL 1086 do_oop_store(_masm, element_address, noreg, _bs->kind(), true); 1087 1088 // Pop stack arguments 1089 __ bind(done); 1090 __ addptr(rsp, 3 * Interpreter::stackElementSize); 1091 } 1092 1093 void TemplateTable::bastore() { 1094 transition(itos, vtos); 1095 __ pop_i(rbx); 1096 // rax: value 1097 // rbx: index 1098 // rdx: array 1099 index_check(rdx, rbx); // prefer index in rbx 1100 __ movb(Address(rdx, rbx, 1101 Address::times_1, 1102 arrayOopDesc::base_offset_in_bytes(T_BYTE)), 1103 rax); 1104 } 1105 1106 void TemplateTable::castore() { 1107 transition(itos, vtos); 1108 __ pop_i(rbx); 1109 // rax: value 1110 // rbx: index 1111 // rdx: array 1112 index_check(rdx, rbx); // prefer index in rbx 1113 __ movw(Address(rdx, rbx, 1114 Address::times_2, 1115 arrayOopDesc::base_offset_in_bytes(T_CHAR)), 1116 rax); 1117 } 1118 1119 1120 void TemplateTable::sastore() { 1121 castore(); 1122 } 1123 1124 void TemplateTable::istore(int n) { 1125 transition(itos, vtos); 1126 __ movl(iaddress(n), rax); 1127 } 1128 1129 void TemplateTable::lstore(int n) { 1130 transition(ltos, vtos); 1131 __ movptr(laddress(n), rax); 1132 NOT_LP64(__ movptr(haddress(n), rdx)); 1133 } 1134 1135 void TemplateTable::fstore(int n) { 1136 transition(ftos, vtos); 1137 LP64_ONLY(__ movflt(faddress(n), xmm0)); 1138 NOT_LP64(__ fstp_s(faddress(n))); 1139 } 1140 1141 void TemplateTable::dstore(int n) { 1142 transition(dtos, vtos); 1143 LP64_ONLY(__ movdbl(daddress(n), xmm0)); 1144 NOT_LP64(__ fstp_d(daddress(n))); 1145 } 1146 1147 1148 void TemplateTable::astore(int n) { 1149 transition(vtos, vtos); 1150 __ pop_ptr(rax); 1151 __ movptr(aaddress(n), rax); 1152 } 1153 1154 void TemplateTable::pop() { 1155 transition(vtos, vtos); 1156 __ addptr(rsp, Interpreter::stackElementSize); 1157 } 1158 1159 void TemplateTable::pop2() { 1160 transition(vtos, vtos); 1161 __ addptr(rsp, 2 * Interpreter::stackElementSize); 1162 } 1163 1164 1165 void TemplateTable::dup() { 1166 transition(vtos, vtos); 1167 __ load_ptr(0, rax); 1168 __ push_ptr(rax); 1169 // stack: ..., a, a 1170 } 1171 1172 void TemplateTable::dup_x1() { 1173 transition(vtos, vtos); 1174 // stack: ..., a, b 1175 __ load_ptr( 0, rax); // load b 1176 __ load_ptr( 1, rcx); // load a 1177 __ store_ptr(1, rax); // store b 1178 __ store_ptr(0, rcx); // store a 1179 __ push_ptr(rax); // push b 1180 // stack: ..., b, a, b 1181 } 1182 1183 void TemplateTable::dup_x2() { 1184 transition(vtos, vtos); 1185 // stack: ..., a, b, c 1186 __ load_ptr( 0, rax); // load c 1187 __ load_ptr( 2, rcx); // load a 1188 __ store_ptr(2, rax); // store c in a 1189 __ push_ptr(rax); // push c 1190 // stack: ..., c, b, c, c 1191 __ load_ptr( 2, rax); // load b 1192 __ store_ptr(2, rcx); // store a in b 1193 // stack: ..., c, a, c, c 1194 __ store_ptr(1, rax); // store b in c 1195 // stack: ..., c, a, b, c 1196 } 1197 1198 void TemplateTable::dup2() { 1199 transition(vtos, vtos); 1200 // stack: ..., a, b 1201 __ load_ptr(1, rax); // load a 1202 __ push_ptr(rax); // push a 1203 __ load_ptr(1, rax); // load b 1204 __ push_ptr(rax); // push b 1205 // stack: ..., a, b, a, b 1206 } 1207 1208 1209 void TemplateTable::dup2_x1() { 1210 transition(vtos, vtos); 1211 // stack: ..., a, b, c 1212 __ load_ptr( 0, rcx); // load c 1213 __ load_ptr( 1, rax); // load b 1214 __ push_ptr(rax); // push b 1215 __ push_ptr(rcx); // push c 1216 // stack: ..., a, b, c, b, c 1217 __ store_ptr(3, rcx); // store c in b 1218 // stack: ..., a, c, c, b, c 1219 __ load_ptr( 4, rcx); // load a 1220 __ store_ptr(2, rcx); // store a in 2nd c 1221 // stack: ..., a, c, a, b, c 1222 __ store_ptr(4, rax); // store b in a 1223 // stack: ..., b, c, a, b, c 1224 } 1225 1226 void TemplateTable::dup2_x2() { 1227 transition(vtos, vtos); 1228 // stack: ..., a, b, c, d 1229 __ load_ptr( 0, rcx); // load d 1230 __ load_ptr( 1, rax); // load c 1231 __ push_ptr(rax); // push c 1232 __ push_ptr(rcx); // push d 1233 // stack: ..., a, b, c, d, c, d 1234 __ load_ptr( 4, rax); // load b 1235 __ store_ptr(2, rax); // store b in d 1236 __ store_ptr(4, rcx); // store d in b 1237 // stack: ..., a, d, c, b, c, d 1238 __ load_ptr( 5, rcx); // load a 1239 __ load_ptr( 3, rax); // load c 1240 __ store_ptr(3, rcx); // store a in c 1241 __ store_ptr(5, rax); // store c in a 1242 // stack: ..., c, d, a, b, c, d 1243 } 1244 1245 void TemplateTable::swap() { 1246 transition(vtos, vtos); 1247 // stack: ..., a, b 1248 __ load_ptr( 1, rcx); // load a 1249 __ load_ptr( 0, rax); // load b 1250 __ store_ptr(0, rcx); // store a in b 1251 __ store_ptr(1, rax); // store b in a 1252 // stack: ..., b, a 1253 } 1254 1255 void TemplateTable::iop2(Operation op) { 1256 transition(itos, itos); 1257 switch (op) { 1258 case add : __ pop_i(rdx); __ addl (rax, rdx); break; 1259 case sub : __ movl(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break; 1260 case mul : __ pop_i(rdx); __ imull(rax, rdx); break; 1261 case _and : __ pop_i(rdx); __ andl (rax, rdx); break; 1262 case _or : __ pop_i(rdx); __ orl (rax, rdx); break; 1263 case _xor : __ pop_i(rdx); __ xorl (rax, rdx); break; 1264 case shl : __ movl(rcx, rax); __ pop_i(rax); __ shll (rax); break; 1265 case shr : __ movl(rcx, rax); __ pop_i(rax); __ sarl (rax); break; 1266 case ushr : __ movl(rcx, rax); __ pop_i(rax); __ shrl (rax); break; 1267 default : ShouldNotReachHere(); 1268 } 1269 } 1270 1271 void TemplateTable::lop2(Operation op) { 1272 transition(ltos, ltos); 1273 #ifdef _LP64 1274 switch (op) { 1275 case add : __ pop_l(rdx); __ addptr(rax, rdx); break; 1276 case sub : __ mov(rdx, rax); __ pop_l(rax); __ subptr(rax, rdx); break; 1277 case _and : __ pop_l(rdx); __ andptr(rax, rdx); break; 1278 case _or : __ pop_l(rdx); __ orptr (rax, rdx); break; 1279 case _xor : __ pop_l(rdx); __ xorptr(rax, rdx); break; 1280 default : ShouldNotReachHere(); 1281 } 1282 #else 1283 __ pop_l(rbx, rcx); 1284 switch (op) { 1285 case add : __ addl(rax, rbx); __ adcl(rdx, rcx); break; 1286 case sub : __ subl(rbx, rax); __ sbbl(rcx, rdx); 1287 __ mov (rax, rbx); __ mov (rdx, rcx); break; 1288 case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break; 1289 case _or : __ orl (rax, rbx); __ orl (rdx, rcx); break; 1290 case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break; 1291 default : ShouldNotReachHere(); 1292 } 1293 #endif 1294 } 1295 1296 void TemplateTable::idiv() { 1297 transition(itos, itos); 1298 __ movl(rcx, rax); 1299 __ pop_i(rax); 1300 // Note: could xor rax and ecx and compare with (-1 ^ min_int). If 1301 // they are not equal, one could do a normal division (no correction 1302 // needed), which may speed up this implementation for the common case. 1303 // (see also JVM spec., p.243 & p.271) 1304 __ corrected_idivl(rcx); 1305 } 1306 1307 void TemplateTable::irem() { 1308 transition(itos, itos); 1309 __ movl(rcx, rax); 1310 __ pop_i(rax); 1311 // Note: could xor rax and ecx and compare with (-1 ^ min_int). If 1312 // they are not equal, one could do a normal division (no correction 1313 // needed), which may speed up this implementation for the common case. 1314 // (see also JVM spec., p.243 & p.271) 1315 __ corrected_idivl(rcx); 1316 __ movl(rax, rdx); 1317 } 1318 1319 void TemplateTable::lmul() { 1320 transition(ltos, ltos); 1321 #ifdef _LP64 1322 __ pop_l(rdx); 1323 __ imulq(rax, rdx); 1324 #else 1325 __ pop_l(rbx, rcx); 1326 __ push(rcx); __ push(rbx); 1327 __ push(rdx); __ push(rax); 1328 __ lmul(2 * wordSize, 0); 1329 __ addptr(rsp, 4 * wordSize); // take off temporaries 1330 #endif 1331 } 1332 1333 void TemplateTable::ldiv() { 1334 transition(ltos, ltos); 1335 #ifdef _LP64 1336 __ mov(rcx, rax); 1337 __ pop_l(rax); 1338 // generate explicit div0 check 1339 __ testq(rcx, rcx); 1340 __ jump_cc(Assembler::zero, 1341 ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); 1342 // Note: could xor rax and rcx and compare with (-1 ^ min_int). If 1343 // they are not equal, one could do a normal division (no correction 1344 // needed), which may speed up this implementation for the common case. 1345 // (see also JVM spec., p.243 & p.271) 1346 __ corrected_idivq(rcx); // kills rbx 1347 #else 1348 __ pop_l(rbx, rcx); 1349 __ push(rcx); __ push(rbx); 1350 __ push(rdx); __ push(rax); 1351 // check if y = 0 1352 __ orl(rax, rdx); 1353 __ jump_cc(Assembler::zero, 1354 ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); 1355 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv)); 1356 __ addptr(rsp, 4 * wordSize); // take off temporaries 1357 #endif 1358 } 1359 1360 void TemplateTable::lrem() { 1361 transition(ltos, ltos); 1362 #ifdef _LP64 1363 __ mov(rcx, rax); 1364 __ pop_l(rax); 1365 __ testq(rcx, rcx); 1366 __ jump_cc(Assembler::zero, 1367 ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); 1368 // Note: could xor rax and rcx and compare with (-1 ^ min_int). If 1369 // they are not equal, one could do a normal division (no correction 1370 // needed), which may speed up this implementation for the common case. 1371 // (see also JVM spec., p.243 & p.271) 1372 __ corrected_idivq(rcx); // kills rbx 1373 __ mov(rax, rdx); 1374 #else 1375 __ pop_l(rbx, rcx); 1376 __ push(rcx); __ push(rbx); 1377 __ push(rdx); __ push(rax); 1378 // check if y = 0 1379 __ orl(rax, rdx); 1380 __ jump_cc(Assembler::zero, 1381 ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); 1382 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem)); 1383 __ addptr(rsp, 4 * wordSize); 1384 #endif 1385 } 1386 1387 void TemplateTable::lshl() { 1388 transition(itos, ltos); 1389 __ movl(rcx, rax); // get shift count 1390 #ifdef _LP64 1391 __ pop_l(rax); // get shift value 1392 __ shlq(rax); 1393 #else 1394 __ pop_l(rax, rdx); // get shift value 1395 __ lshl(rdx, rax); 1396 #endif 1397 } 1398 1399 void TemplateTable::lshr() { 1400 #ifdef _LP64 1401 transition(itos, ltos); 1402 __ movl(rcx, rax); // get shift count 1403 __ pop_l(rax); // get shift value 1404 __ sarq(rax); 1405 #else 1406 transition(itos, ltos); 1407 __ mov(rcx, rax); // get shift count 1408 __ pop_l(rax, rdx); // get shift value 1409 __ lshr(rdx, rax, true); 1410 #endif 1411 } 1412 1413 void TemplateTable::lushr() { 1414 transition(itos, ltos); 1415 #ifdef _LP64 1416 __ movl(rcx, rax); // get shift count 1417 __ pop_l(rax); // get shift value 1418 __ shrq(rax); 1419 #else 1420 __ mov(rcx, rax); // get shift count 1421 __ pop_l(rax, rdx); // get shift value 1422 __ lshr(rdx, rax); 1423 #endif 1424 } 1425 1426 void TemplateTable::fop2(Operation op) { 1427 transition(ftos, ftos); 1428 #ifdef _LP64 1429 switch (op) { 1430 case add: 1431 __ addss(xmm0, at_rsp()); 1432 __ addptr(rsp, Interpreter::stackElementSize); 1433 break; 1434 case sub: 1435 __ movflt(xmm1, xmm0); 1436 __ pop_f(xmm0); 1437 __ subss(xmm0, xmm1); 1438 break; 1439 case mul: 1440 __ mulss(xmm0, at_rsp()); 1441 __ addptr(rsp, Interpreter::stackElementSize); 1442 break; 1443 case div: 1444 __ movflt(xmm1, xmm0); 1445 __ pop_f(xmm0); 1446 __ divss(xmm0, xmm1); 1447 break; 1448 case rem: 1449 __ movflt(xmm1, xmm0); 1450 __ pop_f(xmm0); 1451 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem), 2); 1452 break; 1453 default: 1454 ShouldNotReachHere(); 1455 break; 1456 } 1457 #else 1458 switch (op) { 1459 case add: __ fadd_s (at_rsp()); break; 1460 case sub: __ fsubr_s(at_rsp()); break; 1461 case mul: __ fmul_s (at_rsp()); break; 1462 case div: __ fdivr_s(at_rsp()); break; 1463 case rem: __ fld_s (at_rsp()); __ fremr(rax); break; 1464 default : ShouldNotReachHere(); 1465 } 1466 __ f2ieee(); 1467 __ pop(rax); // pop float thing off 1468 #endif 1469 } 1470 1471 void TemplateTable::dop2(Operation op) { 1472 transition(dtos, dtos); 1473 #ifdef _LP64 1474 switch (op) { 1475 case add: 1476 __ addsd(xmm0, at_rsp()); 1477 __ addptr(rsp, 2 * Interpreter::stackElementSize); 1478 break; 1479 case sub: 1480 __ movdbl(xmm1, xmm0); 1481 __ pop_d(xmm0); 1482 __ subsd(xmm0, xmm1); 1483 break; 1484 case mul: 1485 __ mulsd(xmm0, at_rsp()); 1486 __ addptr(rsp, 2 * Interpreter::stackElementSize); 1487 break; 1488 case div: 1489 __ movdbl(xmm1, xmm0); 1490 __ pop_d(xmm0); 1491 __ divsd(xmm0, xmm1); 1492 break; 1493 case rem: 1494 __ movdbl(xmm1, xmm0); 1495 __ pop_d(xmm0); 1496 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem), 2); 1497 break; 1498 default: 1499 ShouldNotReachHere(); 1500 break; 1501 } 1502 #else 1503 switch (op) { 1504 case add: __ fadd_d (at_rsp()); break; 1505 case sub: __ fsubr_d(at_rsp()); break; 1506 case mul: { 1507 Label L_strict; 1508 Label L_join; 1509 const Address access_flags (rcx, Method::access_flags_offset()); 1510 __ get_method(rcx); 1511 __ movl(rcx, access_flags); 1512 __ testl(rcx, JVM_ACC_STRICT); 1513 __ jccb(Assembler::notZero, L_strict); 1514 __ fmul_d (at_rsp()); 1515 __ jmpb(L_join); 1516 __ bind(L_strict); 1517 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1())); 1518 __ fmulp(); 1519 __ fmul_d (at_rsp()); 1520 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2())); 1521 __ fmulp(); 1522 __ bind(L_join); 1523 break; 1524 } 1525 case div: { 1526 Label L_strict; 1527 Label L_join; 1528 const Address access_flags (rcx, Method::access_flags_offset()); 1529 __ get_method(rcx); 1530 __ movl(rcx, access_flags); 1531 __ testl(rcx, JVM_ACC_STRICT); 1532 __ jccb(Assembler::notZero, L_strict); 1533 __ fdivr_d(at_rsp()); 1534 __ jmp(L_join); 1535 __ bind(L_strict); 1536 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1())); 1537 __ fmul_d (at_rsp()); 1538 __ fdivrp(); 1539 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2())); 1540 __ fmulp(); 1541 __ bind(L_join); 1542 break; 1543 } 1544 case rem: __ fld_d (at_rsp()); __ fremr(rax); break; 1545 default : ShouldNotReachHere(); 1546 } 1547 __ d2ieee(); 1548 // Pop double precision number from rsp. 1549 __ pop(rax); 1550 __ pop(rdx); 1551 #endif 1552 } 1553 1554 void TemplateTable::ineg() { 1555 transition(itos, itos); 1556 __ negl(rax); 1557 } 1558 1559 void TemplateTable::lneg() { 1560 transition(ltos, ltos); 1561 LP64_ONLY(__ negq(rax)); 1562 NOT_LP64(__ lneg(rdx, rax)); 1563 } 1564 1565 #ifdef _LP64 1566 // Note: 'double' and 'long long' have 32-bits alignment on x86. 1567 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) { 1568 // Use the expression (adr)&(~0xF) to provide 128-bits aligned address 1569 // of 128-bits operands for SSE instructions. 1570 jlong *operand = (jlong*)(((intptr_t)adr)&((intptr_t)(~0xF))); 1571 // Store the value to a 128-bits operand. 1572 operand[0] = lo; 1573 operand[1] = hi; 1574 return operand; 1575 } 1576 1577 // Buffer for 128-bits masks used by SSE instructions. 1578 static jlong float_signflip_pool[2*2]; 1579 static jlong double_signflip_pool[2*2]; 1580 #endif 1581 1582 void TemplateTable::fneg() { 1583 transition(ftos, ftos); 1584 #ifdef _LP64 1585 static jlong *float_signflip = double_quadword(&float_signflip_pool[1], 0x8000000080000000, 0x8000000080000000); 1586 __ xorps(xmm0, ExternalAddress((address) float_signflip)); 1587 #else 1588 __ fchs(); 1589 #endif 1590 } 1591 1592 void TemplateTable::dneg() { 1593 transition(dtos, dtos); 1594 #ifdef _LP64 1595 static jlong *double_signflip = double_quadword(&double_signflip_pool[1], 0x8000000000000000, 0x8000000000000000); 1596 __ xorpd(xmm0, ExternalAddress((address) double_signflip)); 1597 #else 1598 __ fchs(); 1599 #endif 1600 } 1601 1602 void TemplateTable::iinc() { 1603 transition(vtos, vtos); 1604 __ load_signed_byte(rdx, at_bcp(2)); // get constant 1605 locals_index(rbx); 1606 __ addl(iaddress(rbx), rdx); 1607 } 1608 1609 void TemplateTable::wide_iinc() { 1610 transition(vtos, vtos); 1611 __ movl(rdx, at_bcp(4)); // get constant 1612 locals_index_wide(rbx); 1613 __ bswapl(rdx); // swap bytes & sign-extend constant 1614 __ sarl(rdx, 16); 1615 __ addl(iaddress(rbx), rdx); 1616 // Note: should probably use only one movl to get both 1617 // the index and the constant -> fix this 1618 } 1619 1620 void TemplateTable::convert() { 1621 #ifdef _LP64 1622 // Checking 1623 #ifdef ASSERT 1624 { 1625 TosState tos_in = ilgl; 1626 TosState tos_out = ilgl; 1627 switch (bytecode()) { 1628 case Bytecodes::_i2l: // fall through 1629 case Bytecodes::_i2f: // fall through 1630 case Bytecodes::_i2d: // fall through 1631 case Bytecodes::_i2b: // fall through 1632 case Bytecodes::_i2c: // fall through 1633 case Bytecodes::_i2s: tos_in = itos; break; 1634 case Bytecodes::_l2i: // fall through 1635 case Bytecodes::_l2f: // fall through 1636 case Bytecodes::_l2d: tos_in = ltos; break; 1637 case Bytecodes::_f2i: // fall through 1638 case Bytecodes::_f2l: // fall through 1639 case Bytecodes::_f2d: tos_in = ftos; break; 1640 case Bytecodes::_d2i: // fall through 1641 case Bytecodes::_d2l: // fall through 1642 case Bytecodes::_d2f: tos_in = dtos; break; 1643 default : ShouldNotReachHere(); 1644 } 1645 switch (bytecode()) { 1646 case Bytecodes::_l2i: // fall through 1647 case Bytecodes::_f2i: // fall through 1648 case Bytecodes::_d2i: // fall through 1649 case Bytecodes::_i2b: // fall through 1650 case Bytecodes::_i2c: // fall through 1651 case Bytecodes::_i2s: tos_out = itos; break; 1652 case Bytecodes::_i2l: // fall through 1653 case Bytecodes::_f2l: // fall through 1654 case Bytecodes::_d2l: tos_out = ltos; break; 1655 case Bytecodes::_i2f: // fall through 1656 case Bytecodes::_l2f: // fall through 1657 case Bytecodes::_d2f: tos_out = ftos; break; 1658 case Bytecodes::_i2d: // fall through 1659 case Bytecodes::_l2d: // fall through 1660 case Bytecodes::_f2d: tos_out = dtos; break; 1661 default : ShouldNotReachHere(); 1662 } 1663 transition(tos_in, tos_out); 1664 } 1665 #endif // ASSERT 1666 1667 static const int64_t is_nan = 0x8000000000000000L; 1668 1669 // Conversion 1670 switch (bytecode()) { 1671 case Bytecodes::_i2l: 1672 __ movslq(rax, rax); 1673 break; 1674 case Bytecodes::_i2f: 1675 __ cvtsi2ssl(xmm0, rax); 1676 break; 1677 case Bytecodes::_i2d: 1678 __ cvtsi2sdl(xmm0, rax); 1679 break; 1680 case Bytecodes::_i2b: 1681 __ movsbl(rax, rax); 1682 break; 1683 case Bytecodes::_i2c: 1684 __ movzwl(rax, rax); 1685 break; 1686 case Bytecodes::_i2s: 1687 __ movswl(rax, rax); 1688 break; 1689 case Bytecodes::_l2i: 1690 __ movl(rax, rax); 1691 break; 1692 case Bytecodes::_l2f: 1693 __ cvtsi2ssq(xmm0, rax); 1694 break; 1695 case Bytecodes::_l2d: 1696 __ cvtsi2sdq(xmm0, rax); 1697 break; 1698 case Bytecodes::_f2i: 1699 { 1700 Label L; 1701 __ cvttss2sil(rax, xmm0); 1702 __ cmpl(rax, 0x80000000); // NaN or overflow/underflow? 1703 __ jcc(Assembler::notEqual, L); 1704 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1); 1705 __ bind(L); 1706 } 1707 break; 1708 case Bytecodes::_f2l: 1709 { 1710 Label L; 1711 __ cvttss2siq(rax, xmm0); 1712 // NaN or overflow/underflow? 1713 __ cmp64(rax, ExternalAddress((address) &is_nan)); 1714 __ jcc(Assembler::notEqual, L); 1715 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1); 1716 __ bind(L); 1717 } 1718 break; 1719 case Bytecodes::_f2d: 1720 __ cvtss2sd(xmm0, xmm0); 1721 break; 1722 case Bytecodes::_d2i: 1723 { 1724 Label L; 1725 __ cvttsd2sil(rax, xmm0); 1726 __ cmpl(rax, 0x80000000); // NaN or overflow/underflow? 1727 __ jcc(Assembler::notEqual, L); 1728 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 1); 1729 __ bind(L); 1730 } 1731 break; 1732 case Bytecodes::_d2l: 1733 { 1734 Label L; 1735 __ cvttsd2siq(rax, xmm0); 1736 // NaN or overflow/underflow? 1737 __ cmp64(rax, ExternalAddress((address) &is_nan)); 1738 __ jcc(Assembler::notEqual, L); 1739 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 1); 1740 __ bind(L); 1741 } 1742 break; 1743 case Bytecodes::_d2f: 1744 __ cvtsd2ss(xmm0, xmm0); 1745 break; 1746 default: 1747 ShouldNotReachHere(); 1748 } 1749 #else 1750 // Checking 1751 #ifdef ASSERT 1752 { TosState tos_in = ilgl; 1753 TosState tos_out = ilgl; 1754 switch (bytecode()) { 1755 case Bytecodes::_i2l: // fall through 1756 case Bytecodes::_i2f: // fall through 1757 case Bytecodes::_i2d: // fall through 1758 case Bytecodes::_i2b: // fall through 1759 case Bytecodes::_i2c: // fall through 1760 case Bytecodes::_i2s: tos_in = itos; break; 1761 case Bytecodes::_l2i: // fall through 1762 case Bytecodes::_l2f: // fall through 1763 case Bytecodes::_l2d: tos_in = ltos; break; 1764 case Bytecodes::_f2i: // fall through 1765 case Bytecodes::_f2l: // fall through 1766 case Bytecodes::_f2d: tos_in = ftos; break; 1767 case Bytecodes::_d2i: // fall through 1768 case Bytecodes::_d2l: // fall through 1769 case Bytecodes::_d2f: tos_in = dtos; break; 1770 default : ShouldNotReachHere(); 1771 } 1772 switch (bytecode()) { 1773 case Bytecodes::_l2i: // fall through 1774 case Bytecodes::_f2i: // fall through 1775 case Bytecodes::_d2i: // fall through 1776 case Bytecodes::_i2b: // fall through 1777 case Bytecodes::_i2c: // fall through 1778 case Bytecodes::_i2s: tos_out = itos; break; 1779 case Bytecodes::_i2l: // fall through 1780 case Bytecodes::_f2l: // fall through 1781 case Bytecodes::_d2l: tos_out = ltos; break; 1782 case Bytecodes::_i2f: // fall through 1783 case Bytecodes::_l2f: // fall through 1784 case Bytecodes::_d2f: tos_out = ftos; break; 1785 case Bytecodes::_i2d: // fall through 1786 case Bytecodes::_l2d: // fall through 1787 case Bytecodes::_f2d: tos_out = dtos; break; 1788 default : ShouldNotReachHere(); 1789 } 1790 transition(tos_in, tos_out); 1791 } 1792 #endif // ASSERT 1793 1794 // Conversion 1795 // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation) 1796 switch (bytecode()) { 1797 case Bytecodes::_i2l: 1798 __ extend_sign(rdx, rax); 1799 break; 1800 case Bytecodes::_i2f: 1801 __ push(rax); // store int on tos 1802 __ fild_s(at_rsp()); // load int to ST0 1803 __ f2ieee(); // truncate to float size 1804 __ pop(rcx); // adjust rsp 1805 break; 1806 case Bytecodes::_i2d: 1807 __ push(rax); // add one slot for d2ieee() 1808 __ push(rax); // store int on tos 1809 __ fild_s(at_rsp()); // load int to ST0 1810 __ d2ieee(); // truncate to double size 1811 __ pop(rcx); // adjust rsp 1812 __ pop(rcx); 1813 break; 1814 case Bytecodes::_i2b: 1815 __ shll(rax, 24); // truncate upper 24 bits 1816 __ sarl(rax, 24); // and sign-extend byte 1817 LP64_ONLY(__ movsbl(rax, rax)); 1818 break; 1819 case Bytecodes::_i2c: 1820 __ andl(rax, 0xFFFF); // truncate upper 16 bits 1821 LP64_ONLY(__ movzwl(rax, rax)); 1822 break; 1823 case Bytecodes::_i2s: 1824 __ shll(rax, 16); // truncate upper 16 bits 1825 __ sarl(rax, 16); // and sign-extend short 1826 LP64_ONLY(__ movswl(rax, rax)); 1827 break; 1828 case Bytecodes::_l2i: 1829 /* nothing to do */ 1830 break; 1831 case Bytecodes::_l2f: 1832 __ push(rdx); // store long on tos 1833 __ push(rax); 1834 __ fild_d(at_rsp()); // load long to ST0 1835 __ f2ieee(); // truncate to float size 1836 __ pop(rcx); // adjust rsp 1837 __ pop(rcx); 1838 break; 1839 case Bytecodes::_l2d: 1840 __ push(rdx); // store long on tos 1841 __ push(rax); 1842 __ fild_d(at_rsp()); // load long to ST0 1843 __ d2ieee(); // truncate to double size 1844 __ pop(rcx); // adjust rsp 1845 __ pop(rcx); 1846 break; 1847 case Bytecodes::_f2i: 1848 __ push(rcx); // reserve space for argument 1849 __ fstp_s(at_rsp()); // pass float argument on stack 1850 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1); 1851 break; 1852 case Bytecodes::_f2l: 1853 __ push(rcx); // reserve space for argument 1854 __ fstp_s(at_rsp()); // pass float argument on stack 1855 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1); 1856 break; 1857 case Bytecodes::_f2d: 1858 /* nothing to do */ 1859 break; 1860 case Bytecodes::_d2i: 1861 __ push(rcx); // reserve space for argument 1862 __ push(rcx); 1863 __ fstp_d(at_rsp()); // pass double argument on stack 1864 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2); 1865 break; 1866 case Bytecodes::_d2l: 1867 __ push(rcx); // reserve space for argument 1868 __ push(rcx); 1869 __ fstp_d(at_rsp()); // pass double argument on stack 1870 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2); 1871 break; 1872 case Bytecodes::_d2f: 1873 __ push(rcx); // reserve space for f2ieee() 1874 __ f2ieee(); // truncate to float size 1875 __ pop(rcx); // adjust rsp 1876 break; 1877 default : 1878 ShouldNotReachHere(); 1879 } 1880 #endif 1881 } 1882 1883 void TemplateTable::lcmp() { 1884 transition(ltos, itos); 1885 #ifdef _LP64 1886 Label done; 1887 __ pop_l(rdx); 1888 __ cmpq(rdx, rax); 1889 __ movl(rax, -1); 1890 __ jccb(Assembler::less, done); 1891 __ setb(Assembler::notEqual, rax); 1892 __ movzbl(rax, rax); 1893 __ bind(done); 1894 #else 1895 1896 // y = rdx:rax 1897 __ pop_l(rbx, rcx); // get x = rcx:rbx 1898 __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y) 1899 __ mov(rax, rcx); 1900 #endif 1901 } 1902 1903 void TemplateTable::float_cmp(bool is_float, int unordered_result) { 1904 #ifdef _LP64 1905 Label done; 1906 if (is_float) { 1907 // XXX get rid of pop here, use ... reg, mem32 1908 __ pop_f(xmm1); 1909 __ ucomiss(xmm1, xmm0); 1910 } else { 1911 // XXX get rid of pop here, use ... reg, mem64 1912 __ pop_d(xmm1); 1913 __ ucomisd(xmm1, xmm0); 1914 } 1915 if (unordered_result < 0) { 1916 __ movl(rax, -1); 1917 __ jccb(Assembler::parity, done); 1918 __ jccb(Assembler::below, done); 1919 __ setb(Assembler::notEqual, rdx); 1920 __ movzbl(rax, rdx); 1921 } else { 1922 __ movl(rax, 1); 1923 __ jccb(Assembler::parity, done); 1924 __ jccb(Assembler::above, done); 1925 __ movl(rax, 0); 1926 __ jccb(Assembler::equal, done); 1927 __ decrementl(rax); 1928 } 1929 __ bind(done); 1930 #else 1931 if (is_float) { 1932 __ fld_s(at_rsp()); 1933 } else { 1934 __ fld_d(at_rsp()); 1935 __ pop(rdx); 1936 } 1937 __ pop(rcx); 1938 __ fcmp2int(rax, unordered_result < 0); 1939 #endif 1940 } 1941 1942 void TemplateTable::branch(bool is_jsr, bool is_wide) { 1943 __ get_method(rcx); // rcx holds method 1944 __ profile_taken_branch(rax, rbx); // rax holds updated MDP, rbx 1945 // holds bumped taken count 1946 1947 const ByteSize be_offset = MethodCounters::backedge_counter_offset() + 1948 InvocationCounter::counter_offset(); 1949 const ByteSize inv_offset = MethodCounters::invocation_counter_offset() + 1950 InvocationCounter::counter_offset(); 1951 1952 // Load up edx with the branch displacement 1953 if (is_wide) { 1954 __ movl(rdx, at_bcp(1)); 1955 } else { 1956 __ load_signed_short(rdx, at_bcp(1)); 1957 } 1958 __ bswapl(rdx); 1959 1960 if (!is_wide) { 1961 __ sarl(rdx, 16); 1962 } 1963 LP64_ONLY(__ movl2ptr(rdx, rdx)); 1964 1965 // Handle all the JSR stuff here, then exit. 1966 // It's much shorter and cleaner than intermingling with the non-JSR 1967 // normal-branch stuff occurring below. 1968 if (is_jsr) { 1969 // Pre-load the next target bytecode into rbx 1970 __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1, 0)); 1971 1972 // compute return address as bci in rax 1973 __ lea(rax, at_bcp((is_wide ? 5 : 3) - 1974 in_bytes(ConstMethod::codes_offset()))); 1975 __ subptr(rax, Address(rcx, Method::const_offset())); 1976 // Adjust the bcp in r13 by the displacement in rdx 1977 __ addptr(rbcp, rdx); 1978 // jsr returns atos that is not an oop 1979 __ push_i(rax); 1980 __ dispatch_only(vtos); 1981 return; 1982 } 1983 1984 // Normal (non-jsr) branch handling 1985 1986 // Adjust the bcp in r13 by the displacement in rdx 1987 __ addptr(rbcp, rdx); 1988 1989 assert(UseLoopCounter || !UseOnStackReplacement, 1990 "on-stack-replacement requires loop counters"); 1991 Label backedge_counter_overflow; 1992 Label profile_method; 1993 Label dispatch; 1994 if (UseLoopCounter) { 1995 // increment backedge counter for backward branches 1996 // rax: MDO 1997 // rbx: MDO bumped taken-count 1998 // rcx: method 1999 // rdx: target offset 2000 // r13: target bcp 2001 // r14: locals pointer 2002 __ testl(rdx, rdx); // check if forward or backward branch 2003 __ jcc(Assembler::positive, dispatch); // count only if backward branch 2004 2005 // check if MethodCounters exists 2006 Label has_counters; 2007 __ movptr(rax, Address(rcx, Method::method_counters_offset())); 2008 __ testptr(rax, rax); 2009 __ jcc(Assembler::notZero, has_counters); 2010 __ push(rdx); 2011 __ push(rcx); 2012 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), 2013 rcx); 2014 __ pop(rcx); 2015 __ pop(rdx); 2016 __ movptr(rax, Address(rcx, Method::method_counters_offset())); 2017 __ jcc(Assembler::zero, dispatch); 2018 __ bind(has_counters); 2019 2020 if (TieredCompilation) { 2021 Label no_mdo; 2022 int increment = InvocationCounter::count_increment; 2023 if (ProfileInterpreter) { 2024 // Are we profiling? 2025 __ movptr(rbx, Address(rcx, in_bytes(Method::method_data_offset()))); 2026 __ testptr(rbx, rbx); 2027 __ jccb(Assembler::zero, no_mdo); 2028 // Increment the MDO backedge counter 2029 const Address mdo_backedge_counter(rbx, in_bytes(MethodData::backedge_counter_offset()) + 2030 in_bytes(InvocationCounter::counter_offset())); 2031 const Address mask(rbx, in_bytes(MethodData::backedge_mask_offset())); 2032 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, 2033 rax, false, Assembler::zero, &backedge_counter_overflow); 2034 __ jmp(dispatch); 2035 } 2036 __ bind(no_mdo); 2037 // Increment backedge counter in MethodCounters* 2038 __ movptr(rcx, Address(rcx, Method::method_counters_offset())); 2039 const Address mask(rcx, in_bytes(MethodCounters::backedge_mask_offset())); 2040 __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask, 2041 rax, false, Assembler::zero, &backedge_counter_overflow); 2042 } else { // not TieredCompilation 2043 // increment counter 2044 __ movptr(rcx, Address(rcx, Method::method_counters_offset())); 2045 __ movl(rax, Address(rcx, be_offset)); // load backedge counter 2046 __ incrementl(rax, InvocationCounter::count_increment); // increment counter 2047 __ movl(Address(rcx, be_offset), rax); // store counter 2048 2049 __ movl(rax, Address(rcx, inv_offset)); // load invocation counter 2050 2051 __ andl(rax, InvocationCounter::count_mask_value); // and the status bits 2052 __ addl(rax, Address(rcx, be_offset)); // add both counters 2053 2054 if (ProfileInterpreter) { 2055 // Test to see if we should create a method data oop 2056 __ cmp32(rax, Address(rcx, in_bytes(MethodCounters::interpreter_profile_limit_offset()))); 2057 __ jcc(Assembler::less, dispatch); 2058 2059 // if no method data exists, go to profile method 2060 __ test_method_data_pointer(rax, profile_method); 2061 2062 if (UseOnStackReplacement) { 2063 // check for overflow against rbx which is the MDO taken count 2064 __ cmp32(rbx, Address(rcx, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset()))); 2065 __ jcc(Assembler::below, dispatch); 2066 2067 // When ProfileInterpreter is on, the backedge_count comes 2068 // from the MethodData*, which value does not get reset on 2069 // the call to frequency_counter_overflow(). To avoid 2070 // excessive calls to the overflow routine while the method is 2071 // being compiled, add a second test to make sure the overflow 2072 // function is called only once every overflow_frequency. 2073 const int overflow_frequency = 1024; 2074 __ andl(rbx, overflow_frequency - 1); 2075 __ jcc(Assembler::zero, backedge_counter_overflow); 2076 2077 } 2078 } else { 2079 if (UseOnStackReplacement) { 2080 // check for overflow against rax, which is the sum of the 2081 // counters 2082 __ cmp32(rax, Address(rcx, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset()))); 2083 __ jcc(Assembler::aboveEqual, backedge_counter_overflow); 2084 2085 } 2086 } 2087 } 2088 __ bind(dispatch); 2089 } 2090 2091 // Pre-load the next target bytecode into rbx 2092 __ load_unsigned_byte(rbx, Address(rbcp, 0)); 2093 2094 // continue with the bytecode @ target 2095 // rax: return bci for jsr's, unused otherwise 2096 // rbx: target bytecode 2097 // r13: target bcp 2098 __ dispatch_only(vtos); 2099 2100 if (UseLoopCounter) { 2101 if (ProfileInterpreter) { 2102 // Out-of-line code to allocate method data oop. 2103 __ bind(profile_method); 2104 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 2105 __ load_unsigned_byte(rbx, Address(rbcp, 0)); // restore target bytecode 2106 __ set_method_data_pointer_for_bcp(); 2107 __ jmp(dispatch); 2108 } 2109 2110 if (UseOnStackReplacement) { 2111 // invocation counter overflow 2112 __ bind(backedge_counter_overflow); 2113 __ negptr(rdx); 2114 __ addptr(rdx, rbcp); // branch bcp 2115 // IcoResult frequency_counter_overflow([JavaThread*], address branch_bcp) 2116 __ call_VM(noreg, 2117 CAST_FROM_FN_PTR(address, 2118 InterpreterRuntime::frequency_counter_overflow), 2119 rdx); 2120 __ load_unsigned_byte(rbx, Address(rbcp, 0)); // restore target bytecode 2121 2122 // rax: osr nmethod (osr ok) or NULL (osr not possible) 2123 // rbx: target bytecode 2124 // rdx: scratch 2125 // r14: locals pointer 2126 // r13: bcp 2127 __ testptr(rax, rax); // test result 2128 __ jcc(Assembler::zero, dispatch); // no osr if null 2129 // nmethod may have been invalidated (VM may block upon call_VM return) 2130 __ cmpb(Address(rax, nmethod::state_offset()), nmethod::in_use); 2131 __ jcc(Assembler::notEqual, dispatch); 2132 2133 // We have the address of an on stack replacement routine in rax 2134 // We need to prepare to execute the OSR method. First we must 2135 // migrate the locals and monitors off of the stack. 2136 2137 LP64_ONLY(__ mov(r13, rax)); // save the nmethod 2138 NOT_LP64(__ mov(rbx, rax)); // save the nmethod 2139 NOT_LP64(__ get_thread(rcx)); 2140 2141 call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin)); 2142 2143 // rax is OSR buffer, move it to expected parameter location 2144 LP64_ONLY(__ mov(j_rarg0, rax)); 2145 NOT_LP64(__ mov(rcx, rax)); 2146 // We use j_rarg definitions here so that registers don't conflict as parameter 2147 // registers change across platforms as we are in the midst of a calling 2148 // sequence to the OSR nmethod and we don't want collision. These are NOT parameters. 2149 2150 const Register retaddr = LP64_ONLY(j_rarg2) NOT_LP64(rdi); 2151 const Register sender_sp = LP64_ONLY(j_rarg1) NOT_LP64(rdx); 2152 2153 2154 // pop the interpreter frame 2155 __ movptr(sender_sp, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp 2156 __ leave(); // remove frame anchor 2157 __ pop(retaddr); // get return address 2158 __ mov(rsp, sender_sp); // set sp to sender sp 2159 // Ensure compiled code always sees stack at proper alignment 2160 __ andptr(rsp, -(StackAlignmentInBytes)); 2161 2162 // unlike x86 we need no specialized return from compiled code 2163 // to the interpreter or the call stub. 2164 2165 // push the return address 2166 __ push(retaddr); 2167 2168 // and begin the OSR nmethod 2169 LP64_ONLY(__ jmp(Address(r13, nmethod::osr_entry_point_offset()))); 2170 NOT_LP64(__ jmp(Address(rbx, nmethod::osr_entry_point_offset()))); 2171 } 2172 } 2173 } 2174 2175 void TemplateTable::if_0cmp(Condition cc) { 2176 transition(itos, vtos); 2177 // assume branch is more often taken than not (loops use backward branches) 2178 Label not_taken; 2179 __ testl(rax, rax); 2180 __ jcc(j_not(cc), not_taken); 2181 branch(false, false); 2182 __ bind(not_taken); 2183 __ profile_not_taken_branch(rax); 2184 } 2185 2186 void TemplateTable::if_icmp(Condition cc) { 2187 transition(itos, vtos); 2188 // assume branch is more often taken than not (loops use backward branches) 2189 Label not_taken; 2190 __ pop_i(rdx); 2191 __ cmpl(rdx, rax); 2192 __ jcc(j_not(cc), not_taken); 2193 branch(false, false); 2194 __ bind(not_taken); 2195 __ profile_not_taken_branch(rax); 2196 } 2197 2198 void TemplateTable::if_nullcmp(Condition cc) { 2199 transition(atos, vtos); 2200 // assume branch is more often taken than not (loops use backward branches) 2201 Label not_taken; 2202 __ testptr(rax, rax); 2203 __ jcc(j_not(cc), not_taken); 2204 branch(false, false); 2205 __ bind(not_taken); 2206 __ profile_not_taken_branch(rax); 2207 } 2208 2209 void TemplateTable::if_acmp(Condition cc) { 2210 transition(atos, vtos); 2211 // assume branch is more often taken than not (loops use backward branches) 2212 Label not_taken; 2213 __ pop_ptr(rdx); 2214 __ cmpptr(rdx, rax); 2215 __ jcc(j_not(cc), not_taken); 2216 branch(false, false); 2217 __ bind(not_taken); 2218 __ profile_not_taken_branch(rax); 2219 } 2220 2221 void TemplateTable::ret() { 2222 transition(vtos, vtos); 2223 locals_index(rbx); 2224 LP64_ONLY(__ movslq(rbx, iaddress(rbx))); // get return bci, compute return bcp 2225 NOT_LP64(__ movptr(rbx, iaddress(rbx))); 2226 __ profile_ret(rbx, rcx); 2227 __ get_method(rax); 2228 __ movptr(rbcp, Address(rax, Method::const_offset())); 2229 __ lea(rbcp, Address(rbcp, rbx, Address::times_1, 2230 ConstMethod::codes_offset())); 2231 __ dispatch_next(vtos); 2232 } 2233 2234 void TemplateTable::wide_ret() { 2235 transition(vtos, vtos); 2236 locals_index_wide(rbx); 2237 __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp 2238 __ profile_ret(rbx, rcx); 2239 __ get_method(rax); 2240 __ movptr(rbcp, Address(rax, Method::const_offset())); 2241 __ lea(rbcp, Address(rbcp, rbx, Address::times_1, ConstMethod::codes_offset())); 2242 __ dispatch_next(vtos); 2243 } 2244 2245 void TemplateTable::tableswitch() { 2246 Label default_case, continue_execution; 2247 transition(itos, vtos); 2248 2249 // align r13/rsi 2250 __ lea(rbx, at_bcp(BytesPerInt)); 2251 __ andptr(rbx, -BytesPerInt); 2252 // load lo & hi 2253 __ movl(rcx, Address(rbx, BytesPerInt)); 2254 __ movl(rdx, Address(rbx, 2 * BytesPerInt)); 2255 __ bswapl(rcx); 2256 __ bswapl(rdx); 2257 // check against lo & hi 2258 __ cmpl(rax, rcx); 2259 __ jcc(Assembler::less, default_case); 2260 __ cmpl(rax, rdx); 2261 __ jcc(Assembler::greater, default_case); 2262 // lookup dispatch offset 2263 __ subl(rax, rcx); 2264 __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt)); 2265 __ profile_switch_case(rax, rbx, rcx); 2266 // continue execution 2267 __ bind(continue_execution); 2268 __ bswapl(rdx); 2269 LP64_ONLY(__ movl2ptr(rdx, rdx)); 2270 __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1)); 2271 __ addptr(rbcp, rdx); 2272 __ dispatch_only(vtos); 2273 // handle default 2274 __ bind(default_case); 2275 __ profile_switch_default(rax); 2276 __ movl(rdx, Address(rbx, 0)); 2277 __ jmp(continue_execution); 2278 } 2279 2280 void TemplateTable::lookupswitch() { 2281 transition(itos, itos); 2282 __ stop("lookupswitch bytecode should have been rewritten"); 2283 } 2284 2285 void TemplateTable::fast_linearswitch() { 2286 transition(itos, vtos); 2287 Label loop_entry, loop, found, continue_execution; 2288 // bswap rax so we can avoid bswapping the table entries 2289 __ bswapl(rax); 2290 // align r13 2291 __ lea(rbx, at_bcp(BytesPerInt)); // btw: should be able to get rid of 2292 // this instruction (change offsets 2293 // below) 2294 __ andptr(rbx, -BytesPerInt); 2295 // set counter 2296 __ movl(rcx, Address(rbx, BytesPerInt)); 2297 __ bswapl(rcx); 2298 __ jmpb(loop_entry); 2299 // table search 2300 __ bind(loop); 2301 __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * BytesPerInt)); 2302 __ jcc(Assembler::equal, found); 2303 __ bind(loop_entry); 2304 __ decrementl(rcx); 2305 __ jcc(Assembler::greaterEqual, loop); 2306 // default case 2307 __ profile_switch_default(rax); 2308 __ movl(rdx, Address(rbx, 0)); 2309 __ jmp(continue_execution); 2310 // entry found -> get offset 2311 __ bind(found); 2312 __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * BytesPerInt)); 2313 __ profile_switch_case(rcx, rax, rbx); 2314 // continue execution 2315 __ bind(continue_execution); 2316 __ bswapl(rdx); 2317 __ movl2ptr(rdx, rdx); 2318 __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1)); 2319 __ addptr(rbcp, rdx); 2320 __ dispatch_only(vtos); 2321 } 2322 2323 void TemplateTable::fast_binaryswitch() { 2324 transition(itos, vtos); 2325 // Implementation using the following core algorithm: 2326 // 2327 // int binary_search(int key, LookupswitchPair* array, int n) { 2328 // // Binary search according to "Methodik des Programmierens" by 2329 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. 2330 // int i = 0; 2331 // int j = n; 2332 // while (i+1 < j) { 2333 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) 2334 // // with Q: for all i: 0 <= i < n: key < a[i] 2335 // // where a stands for the array and assuming that the (inexisting) 2336 // // element a[n] is infinitely big. 2337 // int h = (i + j) >> 1; 2338 // // i < h < j 2339 // if (key < array[h].fast_match()) { 2340 // j = h; 2341 // } else { 2342 // i = h; 2343 // } 2344 // } 2345 // // R: a[i] <= key < a[i+1] or Q 2346 // // (i.e., if key is within array, i is the correct index) 2347 // return i; 2348 // } 2349 2350 // Register allocation 2351 const Register key = rax; // already set (tosca) 2352 const Register array = rbx; 2353 const Register i = rcx; 2354 const Register j = rdx; 2355 const Register h = rdi; 2356 const Register temp = rsi; 2357 2358 // Find array start 2359 NOT_LP64(__ save_bcp()); 2360 2361 __ lea(array, at_bcp(3 * BytesPerInt)); // btw: should be able to 2362 // get rid of this 2363 // instruction (change 2364 // offsets below) 2365 __ andptr(array, -BytesPerInt); 2366 2367 // Initialize i & j 2368 __ xorl(i, i); // i = 0; 2369 __ movl(j, Address(array, -BytesPerInt)); // j = length(array); 2370 2371 // Convert j into native byteordering 2372 __ bswapl(j); 2373 2374 // And start 2375 Label entry; 2376 __ jmp(entry); 2377 2378 // binary search loop 2379 { 2380 Label loop; 2381 __ bind(loop); 2382 // int h = (i + j) >> 1; 2383 __ leal(h, Address(i, j, Address::times_1)); // h = i + j; 2384 __ sarl(h, 1); // h = (i + j) >> 1; 2385 // if (key < array[h].fast_match()) { 2386 // j = h; 2387 // } else { 2388 // i = h; 2389 // } 2390 // Convert array[h].match to native byte-ordering before compare 2391 __ movl(temp, Address(array, h, Address::times_8)); 2392 __ bswapl(temp); 2393 __ cmpl(key, temp); 2394 // j = h if (key < array[h].fast_match()) 2395 __ cmov32(Assembler::less, j, h); 2396 // i = h if (key >= array[h].fast_match()) 2397 __ cmov32(Assembler::greaterEqual, i, h); 2398 // while (i+1 < j) 2399 __ bind(entry); 2400 __ leal(h, Address(i, 1)); // i+1 2401 __ cmpl(h, j); // i+1 < j 2402 __ jcc(Assembler::less, loop); 2403 } 2404 2405 // end of binary search, result index is i (must check again!) 2406 Label default_case; 2407 // Convert array[i].match to native byte-ordering before compare 2408 __ movl(temp, Address(array, i, Address::times_8)); 2409 __ bswapl(temp); 2410 __ cmpl(key, temp); 2411 __ jcc(Assembler::notEqual, default_case); 2412 2413 // entry found -> j = offset 2414 __ movl(j , Address(array, i, Address::times_8, BytesPerInt)); 2415 __ profile_switch_case(i, key, array); 2416 __ bswapl(j); 2417 LP64_ONLY(__ movslq(j, j)); 2418 2419 NOT_LP64(__ restore_bcp()); 2420 NOT_LP64(__ restore_locals()); // restore rdi 2421 2422 __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1)); 2423 __ addptr(rbcp, j); 2424 __ dispatch_only(vtos); 2425 2426 // default case -> j = default offset 2427 __ bind(default_case); 2428 __ profile_switch_default(i); 2429 __ movl(j, Address(array, -2 * BytesPerInt)); 2430 __ bswapl(j); 2431 LP64_ONLY(__ movslq(j, j)); 2432 2433 NOT_LP64(__ restore_bcp()); 2434 NOT_LP64(__ restore_locals()); 2435 2436 __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1)); 2437 __ addptr(rbcp, j); 2438 __ dispatch_only(vtos); 2439 } 2440 2441 void TemplateTable::_return(TosState state) { 2442 transition(state, state); 2443 2444 Register robj = LP64_ONLY(c_rarg1) NOT_LP64(rax); 2445 2446 assert(_desc->calls_vm(), 2447 "inconsistent calls_vm information"); // call in remove_activation 2448 2449 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) { 2450 assert(state == vtos, "only valid state"); 2451 __ movptr(robj, aaddress(0)); 2452 __ load_klass(rdi, robj); 2453 __ movl(rdi, Address(rdi, Klass::access_flags_offset())); 2454 __ testl(rdi, JVM_ACC_HAS_FINALIZER); 2455 Label skip_register_finalizer; 2456 __ jcc(Assembler::zero, skip_register_finalizer); 2457 2458 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), robj); 2459 2460 __ bind(skip_register_finalizer); 2461 } 2462 2463 __ remove_activation(state, rbcp); 2464 __ jmp(rbcp); 2465 } 2466 2467 // ---------------------------------------------------------------------------- 2468 // Volatile variables demand their effects be made known to all CPU's 2469 // in order. Store buffers on most chips allow reads & writes to 2470 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode 2471 // without some kind of memory barrier (i.e., it's not sufficient that 2472 // the interpreter does not reorder volatile references, the hardware 2473 // also must not reorder them). 2474 // 2475 // According to the new Java Memory Model (JMM): 2476 // (1) All volatiles are serialized wrt to each other. ALSO reads & 2477 // writes act as aquire & release, so: 2478 // (2) A read cannot let unrelated NON-volatile memory refs that 2479 // happen after the read float up to before the read. It's OK for 2480 // non-volatile memory refs that happen before the volatile read to 2481 // float down below it. 2482 // (3) Similar a volatile write cannot let unrelated NON-volatile 2483 // memory refs that happen BEFORE the write float down to after the 2484 // write. It's OK for non-volatile memory refs that happen after the 2485 // volatile write to float up before it. 2486 // 2487 // We only put in barriers around volatile refs (they are expensive), 2488 // not _between_ memory refs (that would require us to track the 2489 // flavor of the previous memory refs). Requirements (2) and (3) 2490 // require some barriers before volatile stores and after volatile 2491 // loads. These nearly cover requirement (1) but miss the 2492 // volatile-store-volatile-load case. This final case is placed after 2493 // volatile-stores although it could just as well go before 2494 // volatile-loads. 2495 2496 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) { 2497 // Helper function to insert a is-volatile test and memory barrier 2498 if(!os::is_MP()) return; // Not needed on single CPU 2499 __ membar(order_constraint); 2500 } 2501 2502 void TemplateTable::resolve_cache_and_index(int byte_no, 2503 Register Rcache, 2504 Register index, 2505 size_t index_size) { 2506 const Register temp = rbx; 2507 assert_different_registers(Rcache, index, temp); 2508 2509 Label resolved; 2510 2511 Bytecodes::Code code = bytecode(); 2512 switch (code) { 2513 case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break; 2514 case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break; 2515 } 2516 2517 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 2518 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size); 2519 __ cmpl(temp, code); // have we resolved this bytecode? 2520 __ jcc(Assembler::equal, resolved); 2521 2522 // resolve first time through 2523 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache); 2524 __ movl(temp, code); 2525 __ call_VM(noreg, entry, temp); 2526 // Update registers with resolved info 2527 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size); 2528 __ bind(resolved); 2529 } 2530 2531 // The cache and index registers must be set before call 2532 void TemplateTable::load_field_cp_cache_entry(Register obj, 2533 Register cache, 2534 Register index, 2535 Register off, 2536 Register flags, 2537 bool is_static = false) { 2538 assert_different_registers(cache, index, flags, off); 2539 2540 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2541 // Field offset 2542 __ movptr(off, Address(cache, index, Address::times_ptr, 2543 in_bytes(cp_base_offset + 2544 ConstantPoolCacheEntry::f2_offset()))); 2545 // Flags 2546 __ movl(flags, Address(cache, index, Address::times_ptr, 2547 in_bytes(cp_base_offset + 2548 ConstantPoolCacheEntry::flags_offset()))); 2549 2550 // klass overwrite register 2551 if (is_static) { 2552 __ movptr(obj, Address(cache, index, Address::times_ptr, 2553 in_bytes(cp_base_offset + 2554 ConstantPoolCacheEntry::f1_offset()))); 2555 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 2556 __ movptr(obj, Address(obj, mirror_offset)); 2557 } 2558 } 2559 2560 void TemplateTable::load_invoke_cp_cache_entry(int byte_no, 2561 Register method, 2562 Register itable_index, 2563 Register flags, 2564 bool is_invokevirtual, 2565 bool is_invokevfinal, /*unused*/ 2566 bool is_invokedynamic) { 2567 // setup registers 2568 const Register cache = rcx; 2569 const Register index = rdx; 2570 assert_different_registers(method, flags); 2571 assert_different_registers(method, cache, index); 2572 assert_different_registers(itable_index, flags); 2573 assert_different_registers(itable_index, cache, index); 2574 // determine constant pool cache field offsets 2575 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant"); 2576 const int method_offset = in_bytes( 2577 ConstantPoolCache::base_offset() + 2578 ((byte_no == f2_byte) 2579 ? ConstantPoolCacheEntry::f2_offset() 2580 : ConstantPoolCacheEntry::f1_offset())); 2581 const int flags_offset = in_bytes(ConstantPoolCache::base_offset() + 2582 ConstantPoolCacheEntry::flags_offset()); 2583 // access constant pool cache fields 2584 const int index_offset = in_bytes(ConstantPoolCache::base_offset() + 2585 ConstantPoolCacheEntry::f2_offset()); 2586 2587 size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2)); 2588 resolve_cache_and_index(byte_no, cache, index, index_size); 2589 __ movptr(method, Address(cache, index, Address::times_ptr, method_offset)); 2590 2591 if (itable_index != noreg) { 2592 // pick up itable or appendix index from f2 also: 2593 __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset)); 2594 } 2595 __ movl(flags, Address(cache, index, Address::times_ptr, flags_offset)); 2596 } 2597 2598 // The registers cache and index expected to be set before call. 2599 // Correct values of the cache and index registers are preserved. 2600 void TemplateTable::jvmti_post_field_access(Register cache, 2601 Register index, 2602 bool is_static, 2603 bool has_tos) { 2604 if (JvmtiExport::can_post_field_access()) { 2605 // Check to see if a field access watch has been set before we take 2606 // the time to call into the VM. 2607 Label L1; 2608 assert_different_registers(cache, index, rax); 2609 __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); 2610 __ testl(rax,rax); 2611 __ jcc(Assembler::zero, L1); 2612 2613 // cache entry pointer 2614 __ addptr(cache, in_bytes(ConstantPoolCache::base_offset())); 2615 __ shll(index, LogBytesPerWord); 2616 __ addptr(cache, index); 2617 if (is_static) { 2618 __ xorptr(rax, rax); // NULL object reference 2619 } else { 2620 __ pop(atos); // Get the object 2621 __ verify_oop(rax); 2622 __ push(atos); // Restore stack state 2623 } 2624 // rax,: object pointer or NULL 2625 // cache: cache entry pointer 2626 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), 2627 rax, cache); 2628 __ get_cache_and_index_at_bcp(cache, index, 1); 2629 __ bind(L1); 2630 } 2631 } 2632 2633 void TemplateTable::pop_and_check_object(Register r) { 2634 __ pop_ptr(r); 2635 __ null_check(r); // for field access must check obj. 2636 __ verify_oop(r); 2637 } 2638 2639 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2640 transition(vtos, vtos); 2641 2642 const Register cache = rcx; 2643 const Register index = rdx; 2644 const Register obj = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 2645 const Register off = rbx; 2646 const Register flags = rax; 2647 const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // uses same reg as obj, so don't mix them 2648 2649 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2650 jvmti_post_field_access(cache, index, is_static, false); 2651 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); 2652 2653 if (!is_static) pop_and_check_object(obj); 2654 2655 const Address field(obj, off, Address::times_1, 0*wordSize); 2656 NOT_LP64(const Address hi(obj, off, Address::times_1, 1*wordSize)); 2657 2658 Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble; 2659 2660 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); 2661 // Make sure we don't need to mask edx after the above shift 2662 assert(btos == 0, "change code, btos != 0"); 2663 2664 __ andl(flags, ConstantPoolCacheEntry::tos_state_mask); 2665 2666 __ jcc(Assembler::notZero, notByte); 2667 // btos 2668 __ load_signed_byte(rax, field); 2669 __ push(btos); 2670 // Rewrite bytecode to be faster 2671 if (!is_static && rc == may_rewrite) { 2672 patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx); 2673 } 2674 __ jmp(Done); 2675 2676 __ bind(notByte); 2677 __ cmpl(flags, atos); 2678 __ jcc(Assembler::notEqual, notObj); 2679 // atos 2680 __ load_heap_oop(rax, field); 2681 __ push(atos); 2682 if (!is_static && rc == may_rewrite) { 2683 patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx); 2684 } 2685 __ jmp(Done); 2686 2687 __ bind(notObj); 2688 __ cmpl(flags, itos); 2689 __ jcc(Assembler::notEqual, notInt); 2690 // itos 2691 __ movl(rax, field); 2692 __ push(itos); 2693 // Rewrite bytecode to be faster 2694 if (!is_static && rc == may_rewrite) { 2695 patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx); 2696 } 2697 __ jmp(Done); 2698 2699 __ bind(notInt); 2700 __ cmpl(flags, ctos); 2701 __ jcc(Assembler::notEqual, notChar); 2702 // ctos 2703 __ load_unsigned_short(rax, field); 2704 __ push(ctos); 2705 // Rewrite bytecode to be faster 2706 if (!is_static && rc == may_rewrite) { 2707 patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx); 2708 } 2709 __ jmp(Done); 2710 2711 __ bind(notChar); 2712 __ cmpl(flags, stos); 2713 __ jcc(Assembler::notEqual, notShort); 2714 // stos 2715 __ load_signed_short(rax, field); 2716 __ push(stos); 2717 // Rewrite bytecode to be faster 2718 if (!is_static && rc == may_rewrite) { 2719 patch_bytecode(Bytecodes::_fast_sgetfield, bc, rbx); 2720 } 2721 __ jmp(Done); 2722 2723 __ bind(notShort); 2724 __ cmpl(flags, ltos); 2725 __ jcc(Assembler::notEqual, notLong); 2726 // ltos 2727 2728 #ifndef _LP64 2729 // Generate code as if volatile. There just aren't enough registers to 2730 // save that information and this code is faster than the test. 2731 __ fild_d(field); // Must load atomically 2732 __ subptr(rsp,2*wordSize); // Make space for store 2733 __ fistp_d(Address(rsp,0)); 2734 __ pop(rax); 2735 __ pop(rdx); 2736 #else 2737 __ movq(rax, field); 2738 #endif 2739 2740 __ push(ltos); 2741 // Rewrite bytecode to be faster 2742 LP64_ONLY(if (!is_static && rc == may_rewrite) patch_bytecode(Bytecodes::_fast_lgetfield, bc, rbx)); 2743 __ jmp(Done); 2744 2745 __ bind(notLong); 2746 __ cmpl(flags, ftos); 2747 __ jcc(Assembler::notEqual, notFloat); 2748 // ftos 2749 2750 LP64_ONLY(__ movflt(xmm0, field)); 2751 NOT_LP64(__ fld_s(field)); 2752 __ push(ftos); 2753 // Rewrite bytecode to be faster 2754 if (!is_static && rc == may_rewrite) { 2755 patch_bytecode(Bytecodes::_fast_fgetfield, bc, rbx); 2756 } 2757 __ jmp(Done); 2758 2759 __ bind(notFloat); 2760 #ifdef ASSERT 2761 __ cmpl(flags, dtos); 2762 __ jcc(Assembler::notEqual, notDouble); 2763 #endif 2764 // dtos 2765 LP64_ONLY(__ movdbl(xmm0, field)); 2766 NOT_LP64(__ fld_d(field)); 2767 __ push(dtos); 2768 // Rewrite bytecode to be faster 2769 if (!is_static && rc == may_rewrite) { 2770 patch_bytecode(Bytecodes::_fast_dgetfield, bc, rbx); 2771 } 2772 #ifdef ASSERT 2773 __ jmp(Done); 2774 2775 2776 __ bind(notDouble); 2777 __ stop("Bad state"); 2778 #endif 2779 2780 __ bind(Done); 2781 // [jk] not needed currently 2782 // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad | 2783 // Assembler::LoadStore)); 2784 } 2785 2786 void TemplateTable::getfield(int byte_no) { 2787 getfield_or_static(byte_no, false); 2788 } 2789 2790 void TemplateTable::nofast_getfield(int byte_no) { 2791 getfield_or_static(byte_no, false, may_not_rewrite); 2792 } 2793 2794 void TemplateTable::getstatic(int byte_no) { 2795 getfield_or_static(byte_no, true); 2796 } 2797 2798 2799 // The registers cache and index expected to be set before call. 2800 // The function may destroy various registers, just not the cache and index registers. 2801 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) { 2802 2803 const Register robj = LP64_ONLY(c_rarg2) NOT_LP64(rax); 2804 const Register RBX = LP64_ONLY(c_rarg1) NOT_LP64(rbx); 2805 const Register RCX = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 2806 const Register RDX = LP64_ONLY(rscratch1) NOT_LP64(rdx); 2807 2808 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2809 2810 if (JvmtiExport::can_post_field_modification()) { 2811 // Check to see if a field modification watch has been set before 2812 // we take the time to call into the VM. 2813 Label L1; 2814 assert_different_registers(cache, index, rax); 2815 __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); 2816 __ testl(rax, rax); 2817 __ jcc(Assembler::zero, L1); 2818 2819 __ get_cache_and_index_at_bcp(robj, RDX, 1); 2820 2821 2822 if (is_static) { 2823 // Life is simple. Null out the object pointer. 2824 __ xorl(RBX, RBX); 2825 2826 } else { 2827 // Life is harder. The stack holds the value on top, followed by 2828 // the object. We don't know the size of the value, though; it 2829 // could be one or two words depending on its type. As a result, 2830 // we must find the type to determine where the object is. 2831 #ifndef _LP64 2832 Label two_word, valsize_known; 2833 #endif 2834 __ movl(RCX, Address(robj, RDX, 2835 Address::times_ptr, 2836 in_bytes(cp_base_offset + 2837 ConstantPoolCacheEntry::flags_offset()))); 2838 NOT_LP64(__ mov(rbx, rsp)); 2839 __ shrl(RCX, ConstantPoolCacheEntry::tos_state_shift); 2840 2841 // Make sure we don't need to mask rcx after the above shift 2842 ConstantPoolCacheEntry::verify_tos_state_shift(); 2843 #ifdef _LP64 2844 __ movptr(c_rarg1, at_tos_p1()); // initially assume a one word jvalue 2845 __ cmpl(c_rarg3, ltos); 2846 __ cmovptr(Assembler::equal, 2847 c_rarg1, at_tos_p2()); // ltos (two word jvalue) 2848 __ cmpl(c_rarg3, dtos); 2849 __ cmovptr(Assembler::equal, 2850 c_rarg1, at_tos_p2()); // dtos (two word jvalue) 2851 #else 2852 __ cmpl(rcx, ltos); 2853 __ jccb(Assembler::equal, two_word); 2854 __ cmpl(rcx, dtos); 2855 __ jccb(Assembler::equal, two_word); 2856 __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos) 2857 __ jmpb(valsize_known); 2858 2859 __ bind(two_word); 2860 __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue 2861 2862 __ bind(valsize_known); 2863 // setup object pointer 2864 __ movptr(rbx, Address(rbx, 0)); 2865 #endif 2866 } 2867 // cache entry pointer 2868 __ addptr(robj, in_bytes(cp_base_offset)); 2869 __ shll(RDX, LogBytesPerWord); 2870 __ addptr(robj, RDX); 2871 // object (tos) 2872 __ mov(RCX, rsp); 2873 // c_rarg1: object pointer set up above (NULL if static) 2874 // c_rarg2: cache entry pointer 2875 // c_rarg3: jvalue object on the stack 2876 __ call_VM(noreg, 2877 CAST_FROM_FN_PTR(address, 2878 InterpreterRuntime::post_field_modification), 2879 RBX, robj, RCX); 2880 __ get_cache_and_index_at_bcp(cache, index, 1); 2881 __ bind(L1); 2882 } 2883 } 2884 2885 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2886 transition(vtos, vtos); 2887 2888 const Register cache = rcx; 2889 const Register index = rdx; 2890 const Register obj = rcx; 2891 const Register off = rbx; 2892 const Register flags = rax; 2893 const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 2894 2895 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2896 jvmti_post_field_mod(cache, index, is_static); 2897 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); 2898 2899 // [jk] not needed currently 2900 // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore | 2901 // Assembler::StoreStore)); 2902 2903 Label notVolatile, Done; 2904 __ movl(rdx, flags); 2905 __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); 2906 __ andl(rdx, 0x1); 2907 2908 // field addresses 2909 const Address field(obj, off, Address::times_1, 0*wordSize); 2910 NOT_LP64( const Address hi(obj, off, Address::times_1, 1*wordSize);) 2911 2912 Label notByte, notInt, notShort, notChar, 2913 notLong, notFloat, notObj, notDouble; 2914 2915 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); 2916 2917 assert(btos == 0, "change code, btos != 0"); 2918 __ andl(flags, ConstantPoolCacheEntry::tos_state_mask); 2919 __ jcc(Assembler::notZero, notByte); 2920 2921 // btos 2922 { 2923 __ pop(btos); 2924 if (!is_static) pop_and_check_object(obj); 2925 __ movb(field, rax); 2926 if (!is_static && rc == may_rewrite) { 2927 patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no); 2928 } 2929 __ jmp(Done); 2930 } 2931 2932 __ bind(notByte); 2933 __ cmpl(flags, atos); 2934 __ jcc(Assembler::notEqual, notObj); 2935 2936 // atos 2937 { 2938 __ pop(atos); 2939 if (!is_static) pop_and_check_object(obj); 2940 // Store into the field 2941 do_oop_store(_masm, field, rax, _bs->kind(), false); 2942 if (!is_static && rc == may_rewrite) { 2943 patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no); 2944 } 2945 __ jmp(Done); 2946 } 2947 2948 __ bind(notObj); 2949 __ cmpl(flags, itos); 2950 __ jcc(Assembler::notEqual, notInt); 2951 2952 // itos 2953 { 2954 __ pop(itos); 2955 if (!is_static) pop_and_check_object(obj); 2956 __ movl(field, rax); 2957 if (!is_static && rc == may_rewrite) { 2958 patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no); 2959 } 2960 __ jmp(Done); 2961 } 2962 2963 __ bind(notInt); 2964 __ cmpl(flags, ctos); 2965 __ jcc(Assembler::notEqual, notChar); 2966 2967 // ctos 2968 { 2969 __ pop(ctos); 2970 if (!is_static) pop_and_check_object(obj); 2971 __ movw(field, rax); 2972 if (!is_static && rc == may_rewrite) { 2973 patch_bytecode(Bytecodes::_fast_cputfield, bc, rbx, true, byte_no); 2974 } 2975 __ jmp(Done); 2976 } 2977 2978 __ bind(notChar); 2979 __ cmpl(flags, stos); 2980 __ jcc(Assembler::notEqual, notShort); 2981 2982 // stos 2983 { 2984 __ pop(stos); 2985 if (!is_static) pop_and_check_object(obj); 2986 __ movw(field, rax); 2987 if (!is_static && rc == may_rewrite) { 2988 patch_bytecode(Bytecodes::_fast_sputfield, bc, rbx, true, byte_no); 2989 } 2990 __ jmp(Done); 2991 } 2992 2993 __ bind(notShort); 2994 __ cmpl(flags, ltos); 2995 __ jcc(Assembler::notEqual, notLong); 2996 2997 // ltos 2998 #ifdef _LP64 2999 { 3000 __ pop(ltos); 3001 if (!is_static) pop_and_check_object(obj); 3002 __ movq(field, rax); 3003 if (!is_static && rc == may_rewrite) { 3004 patch_bytecode(Bytecodes::_fast_lputfield, bc, rbx, true, byte_no); 3005 } 3006 __ jmp(Done); 3007 } 3008 #else 3009 { 3010 Label notVolatileLong; 3011 __ testl(rdx, rdx); 3012 __ jcc(Assembler::zero, notVolatileLong); 3013 3014 __ pop(ltos); // overwrites rdx, do this after testing volatile. 3015 if (!is_static) pop_and_check_object(obj); 3016 3017 // Replace with real volatile test 3018 __ push(rdx); 3019 __ push(rax); // Must update atomically with FIST 3020 __ fild_d(Address(rsp,0)); // So load into FPU register 3021 __ fistp_d(field); // and put into memory atomically 3022 __ addptr(rsp, 2*wordSize); 3023 // volatile_barrier(); 3024 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | 3025 Assembler::StoreStore)); 3026 // Don't rewrite volatile version 3027 __ jmp(notVolatile); 3028 3029 __ bind(notVolatileLong); 3030 3031 __ pop(ltos); // overwrites rdx 3032 if (!is_static) pop_and_check_object(obj); 3033 __ movptr(hi, rdx); 3034 __ movptr(field, rax); 3035 // Don't rewrite to _fast_lputfield for potential volatile case. 3036 __ jmp(notVolatile); 3037 } 3038 #endif // _LP64 3039 3040 __ bind(notLong); 3041 __ cmpl(flags, ftos); 3042 __ jcc(Assembler::notEqual, notFloat); 3043 3044 // ftos 3045 { 3046 __ pop(ftos); 3047 if (!is_static) pop_and_check_object(obj); 3048 NOT_LP64( __ fstp_s(field);) 3049 LP64_ONLY( __ movflt(field, xmm0);) 3050 if (!is_static && rc == may_rewrite) { 3051 patch_bytecode(Bytecodes::_fast_fputfield, bc, rbx, true, byte_no); 3052 } 3053 __ jmp(Done); 3054 } 3055 3056 __ bind(notFloat); 3057 #ifdef ASSERT 3058 __ cmpl(flags, dtos); 3059 __ jcc(Assembler::notEqual, notDouble); 3060 #endif 3061 3062 // dtos 3063 { 3064 __ pop(dtos); 3065 if (!is_static) pop_and_check_object(obj); 3066 NOT_LP64( __ fstp_d(field);) 3067 LP64_ONLY( __ movdbl(field, xmm0);) 3068 if (!is_static && rc == may_rewrite) { 3069 patch_bytecode(Bytecodes::_fast_dputfield, bc, rbx, true, byte_no); 3070 } 3071 } 3072 3073 #ifdef ASSERT 3074 __ jmp(Done); 3075 3076 __ bind(notDouble); 3077 __ stop("Bad state"); 3078 #endif 3079 3080 __ bind(Done); 3081 3082 // Check for volatile store 3083 __ testl(rdx, rdx); 3084 __ jcc(Assembler::zero, notVolatile); 3085 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | 3086 Assembler::StoreStore)); 3087 __ bind(notVolatile); 3088 } 3089 3090 void TemplateTable::putfield(int byte_no) { 3091 putfield_or_static(byte_no, false); 3092 } 3093 3094 void TemplateTable::nofast_putfield(int byte_no) { 3095 putfield_or_static(byte_no, false, may_not_rewrite); 3096 } 3097 3098 void TemplateTable::putstatic(int byte_no) { 3099 putfield_or_static(byte_no, true); 3100 } 3101 3102 void TemplateTable::jvmti_post_fast_field_mod() { 3103 3104 const Register scratch = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 3105 3106 if (JvmtiExport::can_post_field_modification()) { 3107 // Check to see if a field modification watch has been set before 3108 // we take the time to call into the VM. 3109 Label L2; 3110 __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); 3111 __ testl(scratch, scratch); 3112 __ jcc(Assembler::zero, L2); 3113 __ pop_ptr(rbx); // copy the object pointer from tos 3114 __ verify_oop(rbx); 3115 __ push_ptr(rbx); // put the object pointer back on tos 3116 // Save tos values before call_VM() clobbers them. Since we have 3117 // to do it for every data type, we use the saved values as the 3118 // jvalue object. 3119 switch (bytecode()) { // load values into the jvalue object 3120 case Bytecodes::_fast_aputfield: __ push_ptr(rax); break; 3121 case Bytecodes::_fast_bputfield: // fall through 3122 case Bytecodes::_fast_sputfield: // fall through 3123 case Bytecodes::_fast_cputfield: // fall through 3124 case Bytecodes::_fast_iputfield: __ push_i(rax); break; 3125 case Bytecodes::_fast_dputfield: __ push_d(); break; 3126 case Bytecodes::_fast_fputfield: __ push_f(); break; 3127 case Bytecodes::_fast_lputfield: __ push_l(rax); break; 3128 3129 default: 3130 ShouldNotReachHere(); 3131 } 3132 __ mov(scratch, rsp); // points to jvalue on the stack 3133 // access constant pool cache entry 3134 LP64_ONLY(__ get_cache_entry_pointer_at_bcp(c_rarg2, rax, 1)); 3135 NOT_LP64(__ get_cache_entry_pointer_at_bcp(rax, rdx, 1)); 3136 __ verify_oop(rbx); 3137 // rbx: object pointer copied above 3138 // c_rarg2: cache entry pointer 3139 // c_rarg3: jvalue object on the stack 3140 LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3)); 3141 NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx)); 3142 3143 switch (bytecode()) { // restore tos values 3144 case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break; 3145 case Bytecodes::_fast_bputfield: // fall through 3146 case Bytecodes::_fast_sputfield: // fall through 3147 case Bytecodes::_fast_cputfield: // fall through 3148 case Bytecodes::_fast_iputfield: __ pop_i(rax); break; 3149 case Bytecodes::_fast_dputfield: __ pop_d(); break; 3150 case Bytecodes::_fast_fputfield: __ pop_f(); break; 3151 case Bytecodes::_fast_lputfield: __ pop_l(rax); break; 3152 } 3153 __ bind(L2); 3154 } 3155 } 3156 3157 void TemplateTable::fast_storefield(TosState state) { 3158 transition(state, vtos); 3159 3160 ByteSize base = ConstantPoolCache::base_offset(); 3161 3162 jvmti_post_fast_field_mod(); 3163 3164 // access constant pool cache 3165 __ get_cache_and_index_at_bcp(rcx, rbx, 1); 3166 3167 // test for volatile with rdx but rdx is tos register for lputfield. 3168 __ movl(rdx, Address(rcx, rbx, Address::times_ptr, 3169 in_bytes(base + 3170 ConstantPoolCacheEntry::flags_offset()))); 3171 3172 // replace index with field offset from cache entry 3173 __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, 3174 in_bytes(base + ConstantPoolCacheEntry::f2_offset()))); 3175 3176 // [jk] not needed currently 3177 // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore | 3178 // Assembler::StoreStore)); 3179 3180 Label notVolatile; 3181 __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); 3182 __ andl(rdx, 0x1); 3183 3184 // Get object from stack 3185 pop_and_check_object(rcx); 3186 3187 // field address 3188 const Address field(rcx, rbx, Address::times_1); 3189 3190 // access field 3191 switch (bytecode()) { 3192 case Bytecodes::_fast_aputfield: 3193 do_oop_store(_masm, field, rax, _bs->kind(), false); 3194 break; 3195 case Bytecodes::_fast_lputfield: 3196 #ifdef _LP64 3197 __ movq(field, rax); 3198 #else 3199 __ stop("should not be rewritten"); 3200 #endif 3201 break; 3202 case Bytecodes::_fast_iputfield: 3203 __ movl(field, rax); 3204 break; 3205 case Bytecodes::_fast_bputfield: 3206 __ movb(field, rax); 3207 break; 3208 case Bytecodes::_fast_sputfield: 3209 // fall through 3210 case Bytecodes::_fast_cputfield: 3211 __ movw(field, rax); 3212 break; 3213 case Bytecodes::_fast_fputfield: 3214 NOT_LP64( __ fstp_s(field); ) 3215 LP64_ONLY( __ movflt(field, xmm0);) 3216 break; 3217 case Bytecodes::_fast_dputfield: 3218 NOT_LP64( __ fstp_d(field); ) 3219 LP64_ONLY( __ movdbl(field, xmm0);) 3220 break; 3221 default: 3222 ShouldNotReachHere(); 3223 } 3224 3225 // Check for volatile store 3226 __ testl(rdx, rdx); 3227 __ jcc(Assembler::zero, notVolatile); 3228 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | 3229 Assembler::StoreStore)); 3230 __ bind(notVolatile); 3231 } 3232 3233 void TemplateTable::fast_accessfield(TosState state) { 3234 transition(atos, state); 3235 3236 // Do the JVMTI work here to avoid disturbing the register state below 3237 if (JvmtiExport::can_post_field_access()) { 3238 // Check to see if a field access watch has been set before we 3239 // take the time to call into the VM. 3240 Label L1; 3241 __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); 3242 __ testl(rcx, rcx); 3243 __ jcc(Assembler::zero, L1); 3244 // access constant pool cache entry 3245 LP64_ONLY(__ get_cache_entry_pointer_at_bcp(c_rarg2, rcx, 1)); 3246 NOT_LP64(__ get_cache_entry_pointer_at_bcp(rcx, rdx, 1)); 3247 __ verify_oop(rax); 3248 __ push_ptr(rax); // save object pointer before call_VM() clobbers it 3249 LP64_ONLY(__ mov(c_rarg1, rax)); 3250 // c_rarg1: object pointer copied above 3251 // c_rarg2: cache entry pointer 3252 LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2)); 3253 NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx)); 3254 __ pop_ptr(rax); // restore object pointer 3255 __ bind(L1); 3256 } 3257 3258 // access constant pool cache 3259 __ get_cache_and_index_at_bcp(rcx, rbx, 1); 3260 // replace index with field offset from cache entry 3261 // [jk] not needed currently 3262 // if (os::is_MP()) { 3263 // __ movl(rdx, Address(rcx, rbx, Address::times_8, 3264 // in_bytes(ConstantPoolCache::base_offset() + 3265 // ConstantPoolCacheEntry::flags_offset()))); 3266 // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); 3267 // __ andl(rdx, 0x1); 3268 // } 3269 __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, 3270 in_bytes(ConstantPoolCache::base_offset() + 3271 ConstantPoolCacheEntry::f2_offset()))); 3272 3273 // rax: object 3274 __ verify_oop(rax); 3275 __ null_check(rax); 3276 Address field(rax, rbx, Address::times_1); 3277 3278 // access field 3279 switch (bytecode()) { 3280 case Bytecodes::_fast_agetfield: 3281 __ load_heap_oop(rax, field); 3282 __ verify_oop(rax); 3283 break; 3284 case Bytecodes::_fast_lgetfield: 3285 #ifdef _LP64 3286 __ movq(rax, field); 3287 #else 3288 __ stop("should not be rewritten"); 3289 #endif 3290 break; 3291 case Bytecodes::_fast_igetfield: 3292 __ movl(rax, field); 3293 break; 3294 case Bytecodes::_fast_bgetfield: 3295 __ movsbl(rax, field); 3296 break; 3297 case Bytecodes::_fast_sgetfield: 3298 __ load_signed_short(rax, field); 3299 break; 3300 case Bytecodes::_fast_cgetfield: 3301 __ load_unsigned_short(rax, field); 3302 break; 3303 case Bytecodes::_fast_fgetfield: 3304 LP64_ONLY(__ movflt(xmm0, field)); 3305 NOT_LP64(__ fld_s(field)); 3306 break; 3307 case Bytecodes::_fast_dgetfield: 3308 LP64_ONLY(__ movdbl(xmm0, field)); 3309 NOT_LP64(__ fld_d(field)); 3310 break; 3311 default: 3312 ShouldNotReachHere(); 3313 } 3314 // [jk] not needed currently 3315 // if (os::is_MP()) { 3316 // Label notVolatile; 3317 // __ testl(rdx, rdx); 3318 // __ jcc(Assembler::zero, notVolatile); 3319 // __ membar(Assembler::LoadLoad); 3320 // __ bind(notVolatile); 3321 //}; 3322 } 3323 3324 void TemplateTable::fast_xaccess(TosState state) { 3325 transition(vtos, state); 3326 3327 // get receiver 3328 __ movptr(rax, aaddress(0)); 3329 // access constant pool cache 3330 __ get_cache_and_index_at_bcp(rcx, rdx, 2); 3331 __ movptr(rbx, 3332 Address(rcx, rdx, Address::times_ptr, 3333 in_bytes(ConstantPoolCache::base_offset() + 3334 ConstantPoolCacheEntry::f2_offset()))); 3335 // make sure exception is reported in correct bcp range (getfield is 3336 // next instruction) 3337 __ increment(rbcp); 3338 __ null_check(rax); 3339 const Address field = Address(rax, rbx, Address::times_1, 0*wordSize); 3340 switch (state) { 3341 case itos: 3342 __ movl(rax, field); 3343 break; 3344 case atos: 3345 __ load_heap_oop(rax, field); 3346 __ verify_oop(rax); 3347 break; 3348 case ftos: 3349 LP64_ONLY(__ movflt(xmm0, field)); 3350 NOT_LP64(__ fld_s(field)); 3351 break; 3352 default: 3353 ShouldNotReachHere(); 3354 } 3355 3356 // [jk] not needed currently 3357 // if (os::is_MP()) { 3358 // Label notVolatile; 3359 // __ movl(rdx, Address(rcx, rdx, Address::times_8, 3360 // in_bytes(ConstantPoolCache::base_offset() + 3361 // ConstantPoolCacheEntry::flags_offset()))); 3362 // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); 3363 // __ testl(rdx, 0x1); 3364 // __ jcc(Assembler::zero, notVolatile); 3365 // __ membar(Assembler::LoadLoad); 3366 // __ bind(notVolatile); 3367 // } 3368 3369 __ decrement(rbcp); 3370 } 3371 3372 //----------------------------------------------------------------------------- 3373 // Calls 3374 3375 void TemplateTable::count_calls(Register method, Register temp) { 3376 // implemented elsewhere 3377 ShouldNotReachHere(); 3378 } 3379 3380 void TemplateTable::prepare_invoke(int byte_no, 3381 Register method, // linked method (or i-klass) 3382 Register index, // itable index, MethodType, etc. 3383 Register recv, // if caller wants to see it 3384 Register flags // if caller wants to test it 3385 ) { 3386 // determine flags 3387 const Bytecodes::Code code = bytecode(); 3388 const bool is_invokeinterface = code == Bytecodes::_invokeinterface; 3389 const bool is_invokedynamic = code == Bytecodes::_invokedynamic; 3390 const bool is_invokehandle = code == Bytecodes::_invokehandle; 3391 const bool is_invokevirtual = code == Bytecodes::_invokevirtual; 3392 const bool is_invokespecial = code == Bytecodes::_invokespecial; 3393 const bool load_receiver = (recv != noreg); 3394 const bool save_flags = (flags != noreg); 3395 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), ""); 3396 assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal"); 3397 assert(flags == noreg || flags == rdx, ""); 3398 assert(recv == noreg || recv == rcx, ""); 3399 3400 // setup registers & access constant pool cache 3401 if (recv == noreg) recv = rcx; 3402 if (flags == noreg) flags = rdx; 3403 assert_different_registers(method, index, recv, flags); 3404 3405 // save 'interpreter return address' 3406 __ save_bcp(); 3407 3408 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic); 3409 3410 // maybe push appendix to arguments (just before return address) 3411 if (is_invokedynamic || is_invokehandle) { 3412 Label L_no_push; 3413 __ testl(flags, (1 << ConstantPoolCacheEntry::has_appendix_shift)); 3414 __ jcc(Assembler::zero, L_no_push); 3415 // Push the appendix as a trailing parameter. 3416 // This must be done before we get the receiver, 3417 // since the parameter_size includes it. 3418 __ push(rbx); 3419 __ mov(rbx, index); 3420 assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0"); 3421 __ load_resolved_reference_at_index(index, rbx); 3422 __ pop(rbx); 3423 __ push(index); // push appendix (MethodType, CallSite, etc.) 3424 __ bind(L_no_push); 3425 } 3426 3427 // load receiver if needed (after appendix is pushed so parameter size is correct) 3428 // Note: no return address pushed yet 3429 if (load_receiver) { 3430 __ movl(recv, flags); 3431 __ andl(recv, ConstantPoolCacheEntry::parameter_size_mask); 3432 const int no_return_pc_pushed_yet = -1; // argument slot correction before we push return address 3433 const int receiver_is_at_end = -1; // back off one slot to get receiver 3434 Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end); 3435 __ movptr(recv, recv_addr); 3436 __ verify_oop(recv); 3437 } 3438 3439 if (save_flags) { 3440 __ movl(rbcp, flags); 3441 } 3442 3443 // compute return type 3444 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); 3445 // Make sure we don't need to mask flags after the above shift 3446 ConstantPoolCacheEntry::verify_tos_state_shift(); 3447 // load return address 3448 { 3449 const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code); 3450 ExternalAddress table(table_addr); 3451 LP64_ONLY(__ lea(rscratch1, table)); 3452 LP64_ONLY(__ movptr(flags, Address(rscratch1, flags, Address::times_ptr))); 3453 NOT_LP64(__ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)))); 3454 } 3455 3456 // push return address 3457 __ push(flags); 3458 3459 // Restore flags value from the constant pool cache, and restore rsi 3460 // for later null checks. r13 is the bytecode pointer 3461 if (save_flags) { 3462 __ movl(flags, rbcp); 3463 __ restore_bcp(); 3464 } 3465 } 3466 3467 void TemplateTable::invokevirtual_helper(Register index, 3468 Register recv, 3469 Register flags) { 3470 // Uses temporary registers rax, rdx 3471 assert_different_registers(index, recv, rax, rdx); 3472 assert(index == rbx, ""); 3473 assert(recv == rcx, ""); 3474 3475 // Test for an invoke of a final method 3476 Label notFinal; 3477 __ movl(rax, flags); 3478 __ andl(rax, (1 << ConstantPoolCacheEntry::is_vfinal_shift)); 3479 __ jcc(Assembler::zero, notFinal); 3480 3481 const Register method = index; // method must be rbx 3482 assert(method == rbx, 3483 "Method* must be rbx for interpreter calling convention"); 3484 3485 // do the call - the index is actually the method to call 3486 // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method* 3487 3488 // It's final, need a null check here! 3489 __ null_check(recv); 3490 3491 // profile this call 3492 __ profile_final_call(rax); 3493 __ profile_arguments_type(rax, method, rbcp, true); 3494 3495 __ jump_from_interpreted(method, rax); 3496 3497 __ bind(notFinal); 3498 3499 // get receiver klass 3500 __ null_check(recv, oopDesc::klass_offset_in_bytes()); 3501 __ load_klass(rax, recv); 3502 3503 // profile this call 3504 __ profile_virtual_call(rax, rlocals, rdx); 3505 // get target Method* & entry point 3506 __ lookup_virtual_method(rax, index, method); 3507 __ profile_arguments_type(rdx, method, rbcp, true); 3508 __ jump_from_interpreted(method, rdx); 3509 } 3510 3511 void TemplateTable::invokevirtual(int byte_no) { 3512 transition(vtos, vtos); 3513 assert(byte_no == f2_byte, "use this argument"); 3514 prepare_invoke(byte_no, 3515 rbx, // method or vtable index 3516 noreg, // unused itable index 3517 rcx, rdx); // recv, flags 3518 3519 // rbx: index 3520 // rcx: receiver 3521 // rdx: flags 3522 3523 invokevirtual_helper(rbx, rcx, rdx); 3524 } 3525 3526 void TemplateTable::invokespecial(int byte_no) { 3527 transition(vtos, vtos); 3528 assert(byte_no == f1_byte, "use this argument"); 3529 prepare_invoke(byte_no, rbx, noreg, // get f1 Method* 3530 rcx); // get receiver also for null check 3531 __ verify_oop(rcx); 3532 __ null_check(rcx); 3533 // do the call 3534 __ profile_call(rax); 3535 __ profile_arguments_type(rax, rbx, rbcp, false); 3536 __ jump_from_interpreted(rbx, rax); 3537 } 3538 3539 void TemplateTable::invokestatic(int byte_no) { 3540 transition(vtos, vtos); 3541 assert(byte_no == f1_byte, "use this argument"); 3542 prepare_invoke(byte_no, rbx); // get f1 Method* 3543 // do the call 3544 __ profile_call(rax); 3545 __ profile_arguments_type(rax, rbx, rbcp, false); 3546 __ jump_from_interpreted(rbx, rax); 3547 } 3548 3549 3550 void TemplateTable::fast_invokevfinal(int byte_no) { 3551 transition(vtos, vtos); 3552 assert(byte_no == f2_byte, "use this argument"); 3553 __ stop("fast_invokevfinal not used on x86"); 3554 } 3555 3556 3557 void TemplateTable::invokeinterface(int byte_no) { 3558 transition(vtos, vtos); 3559 assert(byte_no == f1_byte, "use this argument"); 3560 prepare_invoke(byte_no, rax, rbx, // get f1 Klass*, f2 itable index 3561 rcx, rdx); // recv, flags 3562 3563 // rax: interface klass (from f1) 3564 // rbx: itable index (from f2) 3565 // rcx: receiver 3566 // rdx: flags 3567 3568 // Special case of invokeinterface called for virtual method of 3569 // java.lang.Object. See cpCacheOop.cpp for details. 3570 // This code isn't produced by javac, but could be produced by 3571 // another compliant java compiler. 3572 Label notMethod; 3573 __ movl(rlocals, rdx); 3574 __ andl(rlocals, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift)); 3575 3576 __ jcc(Assembler::zero, notMethod); 3577 3578 invokevirtual_helper(rbx, rcx, rdx); 3579 __ bind(notMethod); 3580 3581 // Get receiver klass into rdx - also a null check 3582 __ restore_locals(); // restore r14 3583 __ null_check(rcx, oopDesc::klass_offset_in_bytes()); 3584 __ load_klass(rdx, rcx); 3585 3586 // profile this call 3587 __ profile_virtual_call(rdx, rbcp, rlocals); 3588 3589 Label no_such_interface, no_such_method; 3590 3591 __ lookup_interface_method(// inputs: rec. class, interface, itable index 3592 rdx, rax, rbx, 3593 // outputs: method, scan temp. reg 3594 rbx, rbcp, 3595 no_such_interface); 3596 3597 // rbx: Method* to call 3598 // rcx: receiver 3599 // Check for abstract method error 3600 // Note: This should be done more efficiently via a throw_abstract_method_error 3601 // interpreter entry point and a conditional jump to it in case of a null 3602 // method. 3603 __ testptr(rbx, rbx); 3604 __ jcc(Assembler::zero, no_such_method); 3605 3606 __ profile_arguments_type(rdx, rbx, rbcp, true); 3607 3608 // do the call 3609 // rcx: receiver 3610 // rbx,: Method* 3611 __ jump_from_interpreted(rbx, rdx); 3612 __ should_not_reach_here(); 3613 3614 // exception handling code follows... 3615 // note: must restore interpreter registers to canonical 3616 // state for exception handling to work correctly! 3617 3618 __ bind(no_such_method); 3619 // throw exception 3620 __ pop(rbx); // pop return address (pushed by prepare_invoke) 3621 __ restore_bcp(); // rbcp must be correct for exception handler (was destroyed) 3622 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 3623 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError)); 3624 // the call_VM checks for exception, so we should never return here. 3625 __ should_not_reach_here(); 3626 3627 __ bind(no_such_interface); 3628 // throw exception 3629 __ pop(rbx); // pop return address (pushed by prepare_invoke) 3630 __ restore_bcp(); // rbcp must be correct for exception handler (was destroyed) 3631 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 3632 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 3633 InterpreterRuntime::throw_IncompatibleClassChangeError)); 3634 // the call_VM checks for exception, so we should never return here. 3635 __ should_not_reach_here(); 3636 } 3637 3638 void TemplateTable::invokehandle(int byte_no) { 3639 transition(vtos, vtos); 3640 assert(byte_no == f1_byte, "use this argument"); 3641 const Register rbx_method = rbx; 3642 const Register rax_mtype = rax; 3643 const Register rcx_recv = rcx; 3644 const Register rdx_flags = rdx; 3645 3646 prepare_invoke(byte_no, rbx_method, rax_mtype, rcx_recv); 3647 __ verify_method_ptr(rbx_method); 3648 __ verify_oop(rcx_recv); 3649 __ null_check(rcx_recv); 3650 3651 // rax: MethodType object (from cpool->resolved_references[f1], if necessary) 3652 // rbx: MH.invokeExact_MT method (from f2) 3653 3654 // Note: rax_mtype is already pushed (if necessary) by prepare_invoke 3655 3656 // FIXME: profile the LambdaForm also 3657 __ profile_final_call(rax); 3658 __ profile_arguments_type(rdx, rbx_method, rbcp, true); 3659 3660 __ jump_from_interpreted(rbx_method, rdx); 3661 } 3662 3663 void TemplateTable::invokedynamic(int byte_no) { 3664 transition(vtos, vtos); 3665 assert(byte_no == f1_byte, "use this argument"); 3666 3667 const Register rbx_method = rbx; 3668 const Register rax_callsite = rax; 3669 3670 prepare_invoke(byte_no, rbx_method, rax_callsite); 3671 3672 // rax: CallSite object (from cpool->resolved_references[f1]) 3673 // rbx: MH.linkToCallSite method (from f2) 3674 3675 // Note: rax_callsite is already pushed by prepare_invoke 3676 3677 // %%% should make a type profile for any invokedynamic that takes a ref argument 3678 // profile this call 3679 __ profile_call(rbcp); 3680 __ profile_arguments_type(rdx, rbx_method, rbcp, false); 3681 3682 __ verify_oop(rax_callsite); 3683 3684 __ jump_from_interpreted(rbx_method, rdx); 3685 } 3686 3687 //----------------------------------------------------------------------------- 3688 // Allocation 3689 3690 void TemplateTable::_new() { 3691 transition(vtos, atos); 3692 __ get_unsigned_2_byte_index_at_bcp(rdx, 1); 3693 Label slow_case; 3694 Label slow_case_no_pop; 3695 Label done; 3696 Label initialize_header; 3697 Label initialize_object; // including clearing the fields 3698 Label allocate_shared; 3699 3700 __ get_cpool_and_tags(rcx, rax); 3701 3702 // Make sure the class we're about to instantiate has been resolved. 3703 // This is done before loading InstanceKlass to be consistent with the order 3704 // how Constant Pool is updated (see ConstantPool::klass_at_put) 3705 const int tags_offset = Array<u1>::base_offset_in_bytes(); 3706 __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class); 3707 __ jcc(Assembler::notEqual, slow_case_no_pop); 3708 3709 // get InstanceKlass 3710 __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(ConstantPool))); 3711 __ push(rcx); // save the contexts of klass for initializing the header 3712 3713 // make sure klass is initialized & doesn't have finalizer 3714 // make sure klass is fully initialized 3715 __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized); 3716 __ jcc(Assembler::notEqual, slow_case); 3717 3718 // get instance_size in InstanceKlass (scaled to a count of bytes) 3719 __ movl(rdx, Address(rcx, Klass::layout_helper_offset())); 3720 // test to see if it has a finalizer or is malformed in some way 3721 __ testl(rdx, Klass::_lh_instance_slow_path_bit); 3722 __ jcc(Assembler::notZero, slow_case); 3723 3724 // 3725 // Allocate the instance 3726 // 1) Try to allocate in the TLAB 3727 // 2) if fail and the object is large allocate in the shared Eden 3728 // 3) if the above fails (or is not applicable), go to a slow case 3729 // (creates a new TLAB, etc.) 3730 3731 const bool allow_shared_alloc = 3732 Universe::heap()->supports_inline_contig_alloc(); 3733 3734 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx); 3735 #ifndef _LP64 3736 if (UseTLAB || allow_shared_alloc) { 3737 __ get_thread(thread); 3738 } 3739 #endif // _LP64 3740 3741 if (UseTLAB) { 3742 __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset()))); 3743 __ lea(rbx, Address(rax, rdx, Address::times_1)); 3744 __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset()))); 3745 __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case); 3746 __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx); 3747 if (ZeroTLAB) { 3748 // the fields have been already cleared 3749 __ jmp(initialize_header); 3750 } else { 3751 // initialize both the header and fields 3752 __ jmp(initialize_object); 3753 } 3754 } 3755 3756 // Allocation in the shared Eden, if allowed. 3757 // 3758 // rdx: instance size in bytes 3759 if (allow_shared_alloc) { 3760 __ bind(allocate_shared); 3761 3762 ExternalAddress heap_top((address)Universe::heap()->top_addr()); 3763 ExternalAddress heap_end((address)Universe::heap()->end_addr()); 3764 3765 Label retry; 3766 __ bind(retry); 3767 __ movptr(rax, heap_top); 3768 __ lea(rbx, Address(rax, rdx, Address::times_1)); 3769 __ cmpptr(rbx, heap_end); 3770 __ jcc(Assembler::above, slow_case); 3771 3772 // Compare rax, with the top addr, and if still equal, store the new 3773 // top addr in rbx, at the address of the top addr pointer. Sets ZF if was 3774 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs. 3775 // 3776 // rax,: object begin 3777 // rbx,: object end 3778 // rdx: instance size in bytes 3779 __ locked_cmpxchgptr(rbx, heap_top); 3780 3781 // if someone beat us on the allocation, try again, otherwise continue 3782 __ jcc(Assembler::notEqual, retry); 3783 3784 __ incr_allocated_bytes(thread, rdx, 0); 3785 } 3786 3787 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) { 3788 // The object is initialized before the header. If the object size is 3789 // zero, go directly to the header initialization. 3790 __ bind(initialize_object); 3791 __ decrement(rdx, sizeof(oopDesc)); 3792 __ jcc(Assembler::zero, initialize_header); 3793 3794 // Initialize topmost object field, divide rdx by 8, check if odd and 3795 // test if zero. 3796 __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code) 3797 __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd 3798 3799 // rdx must have been multiple of 8 3800 #ifdef ASSERT 3801 // make sure rdx was multiple of 8 3802 Label L; 3803 // Ignore partial flag stall after shrl() since it is debug VM 3804 __ jccb(Assembler::carryClear, L); 3805 __ stop("object size is not multiple of 2 - adjust this code"); 3806 __ bind(L); 3807 // rdx must be > 0, no extra check needed here 3808 #endif 3809 3810 // initialize remaining object fields: rdx was a multiple of 8 3811 { Label loop; 3812 __ bind(loop); 3813 __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx); 3814 NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx)); 3815 __ decrement(rdx); 3816 __ jcc(Assembler::notZero, loop); 3817 } 3818 3819 // initialize object header only. 3820 __ bind(initialize_header); 3821 if (UseBiasedLocking) { 3822 __ pop(rcx); // get saved klass back in the register. 3823 __ movptr(rbx, Address(rcx, Klass::prototype_header_offset())); 3824 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx); 3825 } else { 3826 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), 3827 (intptr_t)markOopDesc::prototype()); // header 3828 __ pop(rcx); // get saved klass back in the register. 3829 } 3830 #ifdef _LP64 3831 __ xorl(rsi, rsi); // use zero reg to clear memory (shorter code) 3832 __ store_klass_gap(rax, rsi); // zero klass gap for compressed oops 3833 #endif 3834 __ store_klass(rax, rcx); // klass 3835 3836 { 3837 SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0); 3838 // Trigger dtrace event for fastpath 3839 __ push(atos); 3840 __ call_VM_leaf( 3841 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax); 3842 __ pop(atos); 3843 } 3844 3845 __ jmp(done); 3846 } 3847 3848 // slow case 3849 __ bind(slow_case); 3850 __ pop(rcx); // restore stack pointer to what it was when we came in. 3851 __ bind(slow_case_no_pop); 3852 3853 Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax); 3854 Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx); 3855 3856 __ get_constant_pool(rarg1); 3857 __ get_unsigned_2_byte_index_at_bcp(rarg2, 1); 3858 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2); 3859 __ verify_oop(rax); 3860 3861 // continue 3862 __ bind(done); 3863 } 3864 3865 void TemplateTable::newarray() { 3866 transition(itos, atos); 3867 Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rdx); 3868 __ load_unsigned_byte(rarg1, at_bcp(1)); 3869 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), 3870 rarg1, rax); 3871 } 3872 3873 void TemplateTable::anewarray() { 3874 transition(itos, atos); 3875 3876 Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx); 3877 Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx); 3878 3879 __ get_unsigned_2_byte_index_at_bcp(rarg2, 1); 3880 __ get_constant_pool(rarg1); 3881 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), 3882 rarg1, rarg2, rax); 3883 } 3884 3885 void TemplateTable::arraylength() { 3886 transition(atos, itos); 3887 __ null_check(rax, arrayOopDesc::length_offset_in_bytes()); 3888 __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes())); 3889 } 3890 3891 void TemplateTable::checkcast() { 3892 transition(atos, atos); 3893 Label done, is_null, ok_is_subtype, quicked, resolved; 3894 __ testptr(rax, rax); // object is in rax 3895 __ jcc(Assembler::zero, is_null); 3896 3897 // Get cpool & tags index 3898 __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array 3899 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index 3900 // See if bytecode has already been quicked 3901 __ cmpb(Address(rdx, rbx, 3902 Address::times_1, 3903 Array<u1>::base_offset_in_bytes()), 3904 JVM_CONSTANT_Class); 3905 __ jcc(Assembler::equal, quicked); 3906 __ push(atos); // save receiver for result, and for GC 3907 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3908 3909 // vm_result_2 has metadata result 3910 #ifndef _LP64 3911 // borrow rdi from locals 3912 __ get_thread(rdi); 3913 __ get_vm_result_2(rax, rdi); 3914 __ restore_locals(); 3915 #else 3916 __ get_vm_result_2(rax, r15_thread); 3917 #endif 3918 3919 __ pop_ptr(rdx); // restore receiver 3920 __ jmpb(resolved); 3921 3922 // Get superklass in rax and subklass in rbx 3923 __ bind(quicked); 3924 __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check 3925 __ movptr(rax, Address(rcx, rbx, 3926 Address::times_ptr, sizeof(ConstantPool))); 3927 3928 __ bind(resolved); 3929 __ load_klass(rbx, rdx); 3930 3931 // Generate subtype check. Blows rcx, rdi. Object in rdx. 3932 // Superklass in rax. Subklass in rbx. 3933 __ gen_subtype_check(rbx, ok_is_subtype); 3934 3935 // Come here on failure 3936 __ push_ptr(rdx); 3937 // object is at TOS 3938 __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry)); 3939 3940 // Come here on success 3941 __ bind(ok_is_subtype); 3942 __ mov(rax, rdx); // Restore object in rdx 3943 3944 // Collect counts on whether this check-cast sees NULLs a lot or not. 3945 if (ProfileInterpreter) { 3946 __ jmp(done); 3947 __ bind(is_null); 3948 __ profile_null_seen(rcx); 3949 } else { 3950 __ bind(is_null); // same as 'done' 3951 } 3952 __ bind(done); 3953 } 3954 3955 void TemplateTable::instanceof() { 3956 transition(atos, itos); 3957 Label done, is_null, ok_is_subtype, quicked, resolved; 3958 __ testptr(rax, rax); 3959 __ jcc(Assembler::zero, is_null); 3960 3961 // Get cpool & tags index 3962 __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array 3963 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index 3964 // See if bytecode has already been quicked 3965 __ cmpb(Address(rdx, rbx, 3966 Address::times_1, 3967 Array<u1>::base_offset_in_bytes()), 3968 JVM_CONSTANT_Class); 3969 __ jcc(Assembler::equal, quicked); 3970 3971 __ push(atos); // save receiver for result, and for GC 3972 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3973 // vm_result_2 has metadata result 3974 3975 #ifndef _LP64 3976 // borrow rdi from locals 3977 __ get_thread(rdi); 3978 __ get_vm_result_2(rax, rdi); 3979 __ restore_locals(); 3980 #else 3981 __ get_vm_result_2(rax, r15_thread); 3982 #endif 3983 3984 __ pop_ptr(rdx); // restore receiver 3985 __ verify_oop(rdx); 3986 __ load_klass(rdx, rdx); 3987 __ jmpb(resolved); 3988 3989 // Get superklass in rax and subklass in rdx 3990 __ bind(quicked); 3991 __ load_klass(rdx, rax); 3992 __ movptr(rax, Address(rcx, rbx, 3993 Address::times_ptr, sizeof(ConstantPool))); 3994 3995 __ bind(resolved); 3996 3997 // Generate subtype check. Blows rcx, rdi 3998 // Superklass in rax. Subklass in rdx. 3999 __ gen_subtype_check(rdx, ok_is_subtype); 4000 4001 // Come here on failure 4002 __ xorl(rax, rax); 4003 __ jmpb(done); 4004 // Come here on success 4005 __ bind(ok_is_subtype); 4006 __ movl(rax, 1); 4007 4008 // Collect counts on whether this test sees NULLs a lot or not. 4009 if (ProfileInterpreter) { 4010 __ jmp(done); 4011 __ bind(is_null); 4012 __ profile_null_seen(rcx); 4013 } else { 4014 __ bind(is_null); // same as 'done' 4015 } 4016 __ bind(done); 4017 // rax = 0: obj == NULL or obj is not an instanceof the specified klass 4018 // rax = 1: obj != NULL and obj is an instanceof the specified klass 4019 } 4020 4021 4022 //---------------------------------------------------------------------------------------------------- 4023 // Breakpoints 4024 void TemplateTable::_breakpoint() { 4025 // Note: We get here even if we are single stepping.. 4026 // jbug insists on setting breakpoints at every bytecode 4027 // even if we are in single step mode. 4028 4029 transition(vtos, vtos); 4030 4031 Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx); 4032 4033 // get the unpatched byte code 4034 __ get_method(rarg); 4035 __ call_VM(noreg, 4036 CAST_FROM_FN_PTR(address, 4037 InterpreterRuntime::get_original_bytecode_at), 4038 rarg, rbcp); 4039 __ mov(rbx, rax); // why? 4040 4041 // post the breakpoint event 4042 __ get_method(rarg); 4043 __ call_VM(noreg, 4044 CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), 4045 rarg, rbcp); 4046 4047 // complete the execution of original bytecode 4048 __ dispatch_only_normal(vtos); 4049 } 4050 4051 //----------------------------------------------------------------------------- 4052 // Exceptions 4053 4054 void TemplateTable::athrow() { 4055 transition(atos, vtos); 4056 __ null_check(rax); 4057 __ jump(ExternalAddress(Interpreter::throw_exception_entry())); 4058 } 4059 4060 //----------------------------------------------------------------------------- 4061 // Synchronization 4062 // 4063 // Note: monitorenter & exit are symmetric routines; which is reflected 4064 // in the assembly code structure as well 4065 // 4066 // Stack layout: 4067 // 4068 // [expressions ] <--- rsp = expression stack top 4069 // .. 4070 // [expressions ] 4071 // [monitor entry] <--- monitor block top = expression stack bot 4072 // .. 4073 // [monitor entry] 4074 // [frame data ] <--- monitor block bot 4075 // ... 4076 // [saved rbp ] <--- rbp 4077 void TemplateTable::monitorenter() { 4078 transition(atos, vtos); 4079 4080 // check for NULL object 4081 __ null_check(rax); 4082 4083 const Address monitor_block_top( 4084 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 4085 const Address monitor_block_bot( 4086 rbp, frame::interpreter_frame_initial_sp_offset * wordSize); 4087 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 4088 4089 Label allocated; 4090 4091 Register rtop = LP64_ONLY(c_rarg3) NOT_LP64(rcx); 4092 Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx); 4093 Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rdx); 4094 4095 // initialize entry pointer 4096 __ xorl(rmon, rmon); // points to free slot or NULL 4097 4098 // find a free slot in the monitor block (result in rmon) 4099 { 4100 Label entry, loop, exit; 4101 __ movptr(rtop, monitor_block_top); // points to current entry, 4102 // starting with top-most entry 4103 __ lea(rbot, monitor_block_bot); // points to word before bottom 4104 // of monitor block 4105 __ jmpb(entry); 4106 4107 __ bind(loop); 4108 // check if current entry is used 4109 __ cmpptr(Address(rtop, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL_WORD); 4110 // if not used then remember entry in rmon 4111 __ cmovptr(Assembler::equal, rmon, rtop); // cmov => cmovptr 4112 // check if current entry is for same object 4113 __ cmpptr(rax, Address(rtop, BasicObjectLock::obj_offset_in_bytes())); 4114 // if same object then stop searching 4115 __ jccb(Assembler::equal, exit); 4116 // otherwise advance to next entry 4117 __ addptr(rtop, entry_size); 4118 __ bind(entry); 4119 // check if bottom reached 4120 __ cmpptr(rtop, rbot); 4121 // if not at bottom then check this entry 4122 __ jcc(Assembler::notEqual, loop); 4123 __ bind(exit); 4124 } 4125 4126 __ testptr(rmon, rmon); // check if a slot has been found 4127 __ jcc(Assembler::notZero, allocated); // if found, continue with that one 4128 4129 // allocate one if there's no free slot 4130 { 4131 Label entry, loop; 4132 // 1. compute new pointers // rsp: old expression stack top 4133 __ movptr(rmon, monitor_block_bot); // rmon: old expression stack bottom 4134 __ subptr(rsp, entry_size); // move expression stack top 4135 __ subptr(rmon, entry_size); // move expression stack bottom 4136 __ mov(rtop, rsp); // set start value for copy loop 4137 __ movptr(monitor_block_bot, rmon); // set new monitor block bottom 4138 __ jmp(entry); 4139 // 2. move expression stack contents 4140 __ bind(loop); 4141 __ movptr(rbot, Address(rtop, entry_size)); // load expression stack 4142 // word from old location 4143 __ movptr(Address(rtop, 0), rbot); // and store it at new location 4144 __ addptr(rtop, wordSize); // advance to next word 4145 __ bind(entry); 4146 __ cmpptr(rtop, rmon); // check if bottom reached 4147 __ jcc(Assembler::notEqual, loop); // if not at bottom then 4148 // copy next word 4149 } 4150 4151 // call run-time routine 4152 // rmon: points to monitor entry 4153 __ bind(allocated); 4154 4155 // Increment bcp to point to the next bytecode, so exception 4156 // handling for async. exceptions work correctly. 4157 // The object has already been poped from the stack, so the 4158 // expression stack looks correct. 4159 __ increment(rbcp); 4160 4161 // store object 4162 __ movptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), rax); 4163 __ lock_object(rmon); 4164 4165 // check to make sure this monitor doesn't cause stack overflow after locking 4166 __ save_bcp(); // in case of exception 4167 __ generate_stack_overflow_check(0); 4168 4169 // The bcp has already been incremented. Just need to dispatch to 4170 // next instruction. 4171 __ dispatch_next(vtos); 4172 } 4173 4174 void TemplateTable::monitorexit() { 4175 transition(atos, vtos); 4176 4177 // check for NULL object 4178 __ null_check(rax); 4179 4180 const Address monitor_block_top( 4181 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 4182 const Address monitor_block_bot( 4183 rbp, frame::interpreter_frame_initial_sp_offset * wordSize); 4184 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 4185 4186 Register rtop = LP64_ONLY(c_rarg1) NOT_LP64(rdx); 4187 Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx); 4188 4189 Label found; 4190 4191 // find matching slot 4192 { 4193 Label entry, loop; 4194 __ movptr(rtop, monitor_block_top); // points to current entry, 4195 // starting with top-most entry 4196 __ lea(rbot, monitor_block_bot); // points to word before bottom 4197 // of monitor block 4198 __ jmpb(entry); 4199 4200 __ bind(loop); 4201 // check if current entry is for same object 4202 __ cmpptr(rax, Address(rtop, BasicObjectLock::obj_offset_in_bytes())); 4203 // if same object then stop searching 4204 __ jcc(Assembler::equal, found); 4205 // otherwise advance to next entry 4206 __ addptr(rtop, entry_size); 4207 __ bind(entry); 4208 // check if bottom reached 4209 __ cmpptr(rtop, rbot); 4210 // if not at bottom then check this entry 4211 __ jcc(Assembler::notEqual, loop); 4212 } 4213 4214 // error handling. Unlocking was not block-structured 4215 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 4216 InterpreterRuntime::throw_illegal_monitor_state_exception)); 4217 __ should_not_reach_here(); 4218 4219 // call run-time routine 4220 __ bind(found); 4221 __ push_ptr(rax); // make sure object is on stack (contract with oopMaps) 4222 __ unlock_object(rtop); 4223 __ pop_ptr(rax); // discard object 4224 } 4225 4226 // Wide instructions 4227 void TemplateTable::wide() { 4228 transition(vtos, vtos); 4229 __ load_unsigned_byte(rbx, at_bcp(1)); 4230 ExternalAddress wtable((address)Interpreter::_wentry_point); 4231 __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr))); 4232 // Note: the rbcp increment step is part of the individual wide bytecode implementations 4233 } 4234 4235 // Multi arrays 4236 void TemplateTable::multianewarray() { 4237 transition(vtos, atos); 4238 4239 Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rax); 4240 __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions 4241 // last dim is on top of stack; we want address of first one: 4242 // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize 4243 // the latter wordSize to point to the beginning of the array. 4244 __ lea(rarg, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize)); 4245 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rarg); 4246 __ load_unsigned_byte(rbx, at_bcp(3)); 4247 __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale())); // get rid of counts 4248 } 4249 #endif /* !CC_INTERP */ 4250