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