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