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