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