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