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