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