11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/assembler.hpp"
26 #include "asm/assembler.inline.hpp"
27 #include "code/aotCodeCache.hpp"
28 #include "code/compiledIC.hpp"
29 #include "compiler/compiler_globals.hpp"
30 #include "compiler/disassembler.hpp"
31 #include "crc32c.h"
32 #include "gc/shared/barrierSet.hpp"
33 #include "gc/shared/barrierSetAssembler.hpp"
34 #include "gc/shared/collectedHeap.inline.hpp"
35 #include "gc/shared/tlab_globals.hpp"
36 #include "interpreter/bytecodeHistogram.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/interpreterRuntime.hpp"
39 #include "jvm.h"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.hpp"
42 #include "oops/accessDecorators.hpp"
43 #include "oops/compressedKlass.inline.hpp"
44 #include "oops/compressedOops.inline.hpp"
45 #include "oops/klass.inline.hpp"
46 #include "prims/methodHandles.hpp"
47 #include "runtime/continuation.hpp"
48 #include "runtime/interfaceSupport.inline.hpp"
49 #include "runtime/javaThread.hpp"
50 #include "runtime/jniHandles.hpp"
51 #include "runtime/objectMonitor.hpp"
52 #include "runtime/os.hpp"
53 #include "runtime/safepoint.hpp"
54 #include "runtime/safepointMechanism.hpp"
55 #include "runtime/sharedRuntime.hpp"
56 #include "runtime/stubRoutines.hpp"
57 #include "utilities/checkedCast.hpp"
58 #include "utilities/globalDefinitions.hpp"
59 #include "utilities/macros.hpp"
60
61 #ifdef PRODUCT
62 #define BLOCK_COMMENT(str) /* nothing */
63 #define STOP(error) stop(error)
64 #else
65 #define BLOCK_COMMENT(str) block_comment(str)
66 #define STOP(error) block_comment(error); stop(error)
67 #endif
68
69 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
70
71 #ifdef ASSERT
72 bool AbstractAssembler::pd_check_instruction_mark() { return true; }
73 #endif
74
75 static const Assembler::Condition reverse[] = {
76 Assembler::noOverflow /* overflow = 0x0 */ ,
77 Assembler::overflow /* noOverflow = 0x1 */ ,
78 Assembler::aboveEqual /* carrySet = 0x2, below = 0x2 */ ,
79 Assembler::below /* aboveEqual = 0x3, carryClear = 0x3 */ ,
1285 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
1286 assert_different_registers(arg_0, c_rarg1, c_rarg2);
1287 assert_different_registers(arg_1, c_rarg2);
1288 pass_arg2(this, arg_2);
1289 pass_arg1(this, arg_1);
1290 pass_arg0(this, arg_0);
1291 call_VM_leaf(entry_point, 3);
1292 }
1293
1294 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2, Register arg_3) {
1295 assert_different_registers(arg_0, c_rarg1, c_rarg2, c_rarg3);
1296 assert_different_registers(arg_1, c_rarg2, c_rarg3);
1297 assert_different_registers(arg_2, c_rarg3);
1298 pass_arg3(this, arg_3);
1299 pass_arg2(this, arg_2);
1300 pass_arg1(this, arg_1);
1301 pass_arg0(this, arg_0);
1302 call_VM_leaf(entry_point, 3);
1303 }
1304
1305 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0) {
1306 pass_arg0(this, arg_0);
1307 MacroAssembler::call_VM_leaf_base(entry_point, 1);
1308 }
1309
1310 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1) {
1311 assert_different_registers(arg_0, c_rarg1);
1312 pass_arg1(this, arg_1);
1313 pass_arg0(this, arg_0);
1314 MacroAssembler::call_VM_leaf_base(entry_point, 2);
1315 }
1316
1317 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
1318 assert_different_registers(arg_0, c_rarg1, c_rarg2);
1319 assert_different_registers(arg_1, c_rarg2);
1320 pass_arg2(this, arg_2);
1321 pass_arg1(this, arg_1);
1322 pass_arg0(this, arg_0);
1323 MacroAssembler::call_VM_leaf_base(entry_point, 3);
1324 }
2376 lea(rscratch, src);
2377 Assembler::mulss(dst, Address(rscratch, 0));
2378 }
2379 }
2380
2381 void MacroAssembler::null_check(Register reg, int offset) {
2382 if (needs_explicit_null_check(offset)) {
2383 // provoke OS null exception if reg is null by
2384 // accessing M[reg] w/o changing any (non-CC) registers
2385 // NOTE: cmpl is plenty here to provoke a segv
2386 cmpptr(rax, Address(reg, 0));
2387 // Note: should probably use testl(rax, Address(reg, 0));
2388 // may be shorter code (however, this version of
2389 // testl needs to be implemented first)
2390 } else {
2391 // nothing to do, (later) access of M[reg + offset]
2392 // will provoke OS null exception if reg is null
2393 }
2394 }
2395
2396 void MacroAssembler::os_breakpoint() {
2397 // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
2398 // (e.g., MSVC can't call ps() otherwise)
2399 call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
2400 }
2401
2402 void MacroAssembler::unimplemented(const char* what) {
2403 const char* buf = nullptr;
2404 {
2405 ResourceMark rm;
2406 stringStream ss;
2407 ss.print("unimplemented: %s", what);
2408 buf = code_string(ss.as_string());
2409 }
2410 stop(buf);
2411 }
2412
2413 #define XSTATE_BV 0x200
2414
2415 void MacroAssembler::pop_CPU_state() {
3716 xorptr(temp, temp); // use _zero reg to clear memory (shorter code)
3717 if (UseIncDec) {
3718 shrptr(index, 3); // divide by 8/16 and set carry flag if bit 2 was set
3719 } else {
3720 shrptr(index, 2); // use 2 instructions to avoid partial flag stall
3721 shrptr(index, 1);
3722 }
3723
3724 // initialize remaining object fields: index is a multiple of 2 now
3725 {
3726 Label loop;
3727 bind(loop);
3728 movptr(Address(address, index, Address::times_8, offset_in_bytes - 1*BytesPerWord), temp);
3729 decrement(index);
3730 jcc(Assembler::notZero, loop);
3731 }
3732
3733 bind(done);
3734 }
3735
3736 // Look up the method for a megamorphic invokeinterface call.
3737 // The target method is determined by <intf_klass, itable_index>.
3738 // The receiver klass is in recv_klass.
3739 // On success, the result will be in method_result, and execution falls through.
3740 // On failure, execution transfers to the given label.
3741 void MacroAssembler::lookup_interface_method(Register recv_klass,
3742 Register intf_klass,
3743 RegisterOrConstant itable_index,
3744 Register method_result,
3745 Register scan_temp,
3746 Label& L_no_such_interface,
3747 bool return_method) {
3748 assert_different_registers(recv_klass, intf_klass, scan_temp);
3749 assert_different_registers(method_result, intf_klass, scan_temp);
3750 assert(recv_klass != method_result || !return_method,
3751 "recv_klass can be destroyed when method isn't needed");
3752
3753 assert(itable_index.is_constant() || itable_index.as_register() == method_result,
3754 "caller must use same register for non-constant itable index as for method");
3755
4766 } else {
4767 Label L;
4768 jccb(negate_condition(cc), L);
4769 movl(dst, src);
4770 bind(L);
4771 }
4772 }
4773
4774 void MacroAssembler::cmov32(Condition cc, Register dst, Register src) {
4775 if (VM_Version::supports_cmov()) {
4776 cmovl(cc, dst, src);
4777 } else {
4778 Label L;
4779 jccb(negate_condition(cc), L);
4780 movl(dst, src);
4781 bind(L);
4782 }
4783 }
4784
4785 void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file, int line) {
4786 if (!VerifyOops) return;
4787
4788 BLOCK_COMMENT("verify_oop {");
4789 push(rscratch1);
4790 push(rax); // save rax
4791 push(reg); // pass register argument
4792
4793 // Pass register number to verify_oop_subroutine
4794 const char* b = nullptr;
4795 {
4796 ResourceMark rm;
4797 stringStream ss;
4798 ss.print("verify_oop: %s: %s (%s:%d)", reg->name(), s, file, line);
4799 b = code_string(ss.as_string());
4800 }
4801 AddressLiteral buffer((address) b, external_word_Relocation::spec_for_immediate());
4802 pushptr(buffer.addr(), rscratch1);
4803
4804 // call indirectly to solve generation ordering problem
4805 movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
4806 call(rax);
5019 } else {
5020 pop(rax);
5021 }
5022
5023 // CAS success means the slot now has the receiver we want. CAS failure means
5024 // something had claimed the slot concurrently: it can be the same receiver we want,
5025 // or something else. Since this is a slow path, we can optimize for code density,
5026 // and just restart the search from the beginning.
5027 jmpb(L_restart);
5028
5029 // Found a receiver, convert its slot offset to corresponding count offset.
5030 bind(L_found_recv);
5031 addptr(offset, receiver_to_count_step);
5032
5033 // Finally, update the counter
5034 bind(L_count_update);
5035 addptr(Address(mdp, offset, Address::times_ptr), DataLayout::counter_increment);
5036 }
5037
5038 void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* file, int line) {
5039 if (!VerifyOops) return;
5040
5041 push(rscratch1);
5042 push(rax); // save rax,
5043 // addr may contain rsp so we will have to adjust it based on the push
5044 // we just did (and on 64 bit we do two pushes)
5045 // NOTE: 64bit seemed to have had a bug in that it did movq(addr, rax); which
5046 // stores rax into addr which is backwards of what was intended.
5047 if (addr.uses(rsp)) {
5048 lea(rax, addr);
5049 pushptr(Address(rax, 2 * BytesPerWord));
5050 } else {
5051 pushptr(addr);
5052 }
5053
5054 // Pass register number to verify_oop_subroutine
5055 const char* b = nullptr;
5056 {
5057 ResourceMark rm;
5058 stringStream ss;
5059 ss.print("verify_oop_addr: %s (%s:%d)", s, file, line);
5411
5412 void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
5413 // get mirror
5414 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
5415 load_method_holder(mirror, method);
5416 movptr(mirror, Address(mirror, mirror_offset));
5417 resolve_oop_handle(mirror, tmp);
5418 }
5419
5420 void MacroAssembler::load_method_holder_cld(Register rresult, Register rmethod) {
5421 load_method_holder(rresult, rmethod);
5422 movptr(rresult, Address(rresult, InstanceKlass::class_loader_data_offset()));
5423 }
5424
5425 void MacroAssembler::load_method_holder(Register holder, Register method) {
5426 movptr(holder, Address(method, Method::const_offset())); // ConstMethod*
5427 movptr(holder, Address(holder, ConstMethod::constants_offset())); // ConstantPool*
5428 movptr(holder, Address(holder, ConstantPool::pool_holder_offset())); // InstanceKlass*
5429 }
5430
5431 void MacroAssembler::load_narrow_klass_compact(Register dst, Register src) {
5432 assert(UseCompactObjectHeaders, "expect compact object headers");
5433 movq(dst, Address(src, oopDesc::mark_offset_in_bytes()));
5434 shrq(dst, markWord::klass_shift);
5435 }
5436
5437 void MacroAssembler::load_narrow_klass(Register dst, Register src) {
5438 if (UseCompactObjectHeaders) {
5439 load_narrow_klass_compact(dst, src);
5440 } else {
5441 movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
5442 }
5443 }
5444
5445 void MacroAssembler::load_klass(Register dst, Register src, Register tmp) {
5446 assert_different_registers(src, tmp);
5447 assert_different_registers(dst, tmp);
5448 load_narrow_klass(dst, src);
5449 decode_klass_not_null(dst, tmp);
5450 }
5451
5452 void MacroAssembler::store_klass(Register dst, Register src, Register tmp) {
5453 assert(!UseCompactObjectHeaders, "not with compact headers");
5454 assert_different_registers(src, tmp);
5455 assert_different_registers(dst, tmp);
5456 encode_klass_not_null(src, tmp);
5457 movl(Address(dst, oopDesc::klass_offset_in_bytes()), src);
5458 }
5459
5460 void MacroAssembler::cmp_klass(Register klass, Register obj, Register tmp) {
5461 if (UseCompactObjectHeaders) {
5462 assert(tmp != noreg, "need tmp");
5463 assert_different_registers(klass, obj, tmp);
5464 load_narrow_klass_compact(tmp, obj);
5465 cmpl(klass, tmp);
5466 } else {
5467 cmpl(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
5468 }
5469 }
5470
5471 void MacroAssembler::cmp_klasses_from_objects(Register obj1, Register obj2, Register tmp1, Register tmp2) {
5488 bool as_raw = (decorators & AS_RAW) != 0;
5489 if (as_raw) {
5490 bs->BarrierSetAssembler::load_at(this, decorators, type, dst, src, tmp1);
5491 } else {
5492 bs->load_at(this, decorators, type, dst, src, tmp1);
5493 }
5494 }
5495
5496 void MacroAssembler::access_store_at(BasicType type, DecoratorSet decorators, Address dst, Register val,
5497 Register tmp1, Register tmp2, Register tmp3) {
5498 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
5499 decorators = AccessInternal::decorator_fixup(decorators, type);
5500 bool as_raw = (decorators & AS_RAW) != 0;
5501 if (as_raw) {
5502 bs->BarrierSetAssembler::store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
5503 } else {
5504 bs->store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
5505 }
5506 }
5507
5508 void MacroAssembler::load_heap_oop(Register dst, Address src, Register tmp1, DecoratorSet decorators) {
5509 access_load_at(T_OBJECT, IN_HEAP | decorators, dst, src, tmp1);
5510 }
5511
5512 // Doesn't do verification, generates fixed size code
5513 void MacroAssembler::load_heap_oop_not_null(Register dst, Address src, Register tmp1, DecoratorSet decorators) {
5514 access_load_at(T_OBJECT, IN_HEAP | IS_NOT_NULL | decorators, dst, src, tmp1);
5515 }
5516
5517 void MacroAssembler::store_heap_oop(Address dst, Register val, Register tmp1,
5518 Register tmp2, Register tmp3, DecoratorSet decorators) {
5519 access_store_at(T_OBJECT, IN_HEAP | decorators, dst, val, tmp1, tmp2, tmp3);
5520 }
5521
5522 // Used for storing nulls.
5523 void MacroAssembler::store_heap_oop_null(Address dst) {
5524 access_store_at(T_OBJECT, IN_HEAP, dst, noreg, noreg, noreg, noreg);
5525 }
5526
5527 void MacroAssembler::store_klass_gap(Register dst, Register src) {
5850 assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
5851 int klass_index = oop_recorder()->find_index(k);
5852 RelocationHolder rspec = metadata_Relocation::spec(klass_index);
5853 Assembler::cmp_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
5854 }
5855
5856 void MacroAssembler::reinit_heapbase() {
5857 if (UseCompressedOops) {
5858 if (Universe::heap() != nullptr && !AOTCodeCache::is_on_for_dump()) {
5859 if (CompressedOops::base() == nullptr) {
5860 MacroAssembler::xorptr(r12_heapbase, r12_heapbase);
5861 } else {
5862 mov64(r12_heapbase, (int64_t)CompressedOops::base());
5863 }
5864 } else {
5865 movptr(r12_heapbase, ExternalAddress(CompressedOops::base_addr()));
5866 }
5867 }
5868 }
5869
5870 #ifdef COMPILER2
5871
5872 // clear memory of size 'cnt' qwords, starting at 'base' using XMM/YMM/ZMM registers
5873 void MacroAssembler::xmm_clear_mem(Register base, Register cnt, Register rtmp, XMMRegister xtmp, KRegister mask) {
5874 // cnt - number of qwords (8-byte words).
5875 // base - start address, qword aligned.
5876 Label L_zero_64_bytes, L_loop, L_sloop, L_tail, L_end;
5877 bool use64byteVector = (MaxVectorSize == 64) && (CopyAVX3Threshold == 0);
5878 if (use64byteVector) {
5879 vpxor(xtmp, xtmp, xtmp, AVX_512bit);
5880 } else if (MaxVectorSize >= 32) {
5881 vpxor(xtmp, xtmp, xtmp, AVX_256bit);
5882 } else {
5883 pxor(xtmp, xtmp);
5884 }
5885 jmp(L_zero_64_bytes);
5886
5887 BIND(L_loop);
5888 if (MaxVectorSize >= 32) {
5889 fill64(base, 0, xtmp, use64byteVector);
5890 } else {
5891 movdqu(Address(base, 0), xtmp);
5892 movdqu(Address(base, 16), xtmp);
5893 movdqu(Address(base, 32), xtmp);
5894 movdqu(Address(base, 48), xtmp);
5895 }
5896 addptr(base, 64);
5897
5898 BIND(L_zero_64_bytes);
5899 subptr(cnt, 8);
5900 jccb(Assembler::greaterEqual, L_loop);
5901
5902 // Copy trailing 64 bytes
5903 if (use64byteVector) {
5904 addptr(cnt, 8);
5905 jccb(Assembler::equal, L_end);
5906 fill64_masked(3, base, 0, xtmp, mask, cnt, rtmp, true);
5907 jmp(L_end);
5908 } else {
5909 addptr(cnt, 4);
5910 jccb(Assembler::less, L_tail);
5911 if (MaxVectorSize >= 32) {
5912 vmovdqu(Address(base, 0), xtmp);
5913 } else {
5914 movdqu(Address(base, 0), xtmp);
5915 movdqu(Address(base, 16), xtmp);
5916 }
5917 }
5918 addptr(base, 32);
5919 subptr(cnt, 4);
5920
5921 BIND(L_tail);
5922 addptr(cnt, 4);
5923 jccb(Assembler::lessEqual, L_end);
5924 if (UseAVX > 2 && MaxVectorSize >= 32 && VM_Version::supports_avx512vl()) {
5925 fill32_masked(3, base, 0, xtmp, mask, cnt, rtmp);
5926 } else {
5927 decrement(cnt);
5928
5929 BIND(L_sloop);
5930 movq(Address(base, 0), xtmp);
5931 addptr(base, 8);
5932 decrement(cnt);
5933 jccb(Assembler::greaterEqual, L_sloop);
5934 }
5935 BIND(L_end);
5936 }
5937
5938 // Clearing constant sized memory using YMM/ZMM registers.
5939 void MacroAssembler::clear_mem(Register base, int cnt, Register rtmp, XMMRegister xtmp, KRegister mask) {
5940 assert(UseAVX > 2 && VM_Version::supports_avx512vl(), "");
5941 bool use64byteVector = (MaxVectorSize > 32) && (CopyAVX3Threshold == 0);
5942
5943 int vector64_count = (cnt & (~0x7)) >> 3;
5944 cnt = cnt & 0x7;
5945 const int fill64_per_loop = 4;
6007 break;
6008 case 7:
6009 if (use64byteVector) {
6010 movl(rtmp, 0x7F);
6011 kmovwl(mask, rtmp);
6012 evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_512bit);
6013 } else {
6014 evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
6015 movl(rtmp, 0x7);
6016 kmovwl(mask, rtmp);
6017 evmovdqu(T_LONG, mask, Address(base, disp + 32), xtmp, true, Assembler::AVX_256bit);
6018 }
6019 break;
6020 default:
6021 fatal("Unexpected length : %d\n",cnt);
6022 break;
6023 }
6024 }
6025 }
6026
6027 void MacroAssembler::clear_mem(Register base, Register cnt, Register tmp, XMMRegister xtmp,
6028 bool is_large, KRegister mask) {
6029 // cnt - number of qwords (8-byte words).
6030 // base - start address, qword aligned.
6031 // is_large - if optimizers know cnt is larger than InitArrayShortSize
6032 assert(base==rdi, "base register must be edi for rep stos");
6033 assert(tmp==rax, "tmp register must be eax for rep stos");
6034 assert(cnt==rcx, "cnt register must be ecx for rep stos");
6035 assert(InitArrayShortSize % BytesPerLong == 0,
6036 "InitArrayShortSize should be the multiple of BytesPerLong");
6037
6038 Label DONE;
6039 if (!is_large || !UseXMMForObjInit) {
6040 xorptr(tmp, tmp);
6041 }
6042
6043 if (!is_large) {
6044 Label LOOP, LONG;
6045 cmpptr(cnt, InitArrayShortSize/BytesPerLong);
6046 jccb(Assembler::greater, LONG);
6047
6048 decrement(cnt);
6049 jccb(Assembler::negative, DONE); // Zero length
6050
6051 // Use individual pointer-sized stores for small counts:
6052 BIND(LOOP);
6053 movptr(Address(base, cnt, Address::times_ptr), tmp);
6054 decrement(cnt);
6055 jccb(Assembler::greaterEqual, LOOP);
6056 jmpb(DONE);
6057
6058 BIND(LONG);
6059 }
6060
6061 // Use longer rep-prefixed ops for non-small counts:
6062 if (UseFastStosb) {
6063 shlptr(cnt, 3); // convert to number of bytes
6064 rep_stosb();
6065 } else if (UseXMMForObjInit) {
6066 xmm_clear_mem(base, cnt, tmp, xtmp, mask);
6067 } else {
6068 rep_stos();
6069 }
6070
6071 BIND(DONE);
6072 }
6073
6074 #endif //COMPILER2
6075
6076
6077 void MacroAssembler::generate_fill(BasicType t, bool aligned,
6078 Register to, Register value, Register count,
6079 Register rtmp, XMMRegister xtmp) {
6080 ShortBranchVerifier sbv(this);
6081 assert_different_registers(to, value, count, rtmp);
6082 Label L_exit;
6083 Label L_fill_2_bytes, L_fill_4_bytes;
6084
6085 #if defined(COMPILER2)
6086 if(MaxVectorSize >=32 &&
9963
9964 // Load top.
9965 movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
9966
9967 // Check if the lock-stack is full.
9968 cmpl(top, LockStack::end_offset());
9969 jcc(Assembler::greaterEqual, slow);
9970
9971 // Check for recursion.
9972 cmpptr(obj, Address(thread, top, Address::times_1, -oopSize));
9973 jcc(Assembler::equal, push);
9974
9975 // Check header for monitor (0b10).
9976 testptr(reg_rax, markWord::monitor_value);
9977 jcc(Assembler::notZero, slow);
9978
9979 // Try to lock. Transition lock bits 0b01 => 0b00
9980 movptr(tmp, reg_rax);
9981 andptr(tmp, ~(int32_t)markWord::unlocked_value);
9982 orptr(reg_rax, markWord::unlocked_value);
9983 lock(); cmpxchgptr(tmp, Address(obj, oopDesc::mark_offset_in_bytes()));
9984 jcc(Assembler::notEqual, slow);
9985
9986 // Restore top, CAS clobbers register.
9987 movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
9988
9989 bind(push);
9990 // After successful lock, push object on lock-stack.
9991 movptr(Address(thread, top), obj);
9992 incrementl(top, oopSize);
9993 movl(Address(thread, JavaThread::lock_stack_top_offset()), top);
9994 }
9995
9996 // Implements fast-unlocking.
9997 //
9998 // obj: the object to be unlocked
9999 // reg_rax: rax
10000 // thread: the thread
10001 // tmp: a temporary register
10002 void MacroAssembler::fast_unlock(Register obj, Register reg_rax, Register tmp, Label& slow) {
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/assembler.hpp"
26 #include "asm/assembler.inline.hpp"
27 #include "code/aotCodeCache.hpp"
28 #include "code/compiledIC.hpp"
29 #include "compiler/compiler_globals.hpp"
30 #include "compiler/disassembler.hpp"
31 #include "ci/ciInlineKlass.hpp"
32 #include "crc32c.h"
33 #include "gc/shared/barrierSet.hpp"
34 #include "gc/shared/barrierSetAssembler.hpp"
35 #include "gc/shared/collectedHeap.inline.hpp"
36 #include "gc/shared/tlab_globals.hpp"
37 #include "interpreter/bytecodeHistogram.hpp"
38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "jvm.h"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/accessDecorators.hpp"
44 #include "oops/compressedKlass.inline.hpp"
45 #include "oops/compressedOops.inline.hpp"
46 #include "oops/klass.inline.hpp"
47 #include "oops/resolvedFieldEntry.hpp"
48 #include "prims/methodHandles.hpp"
49 #include "runtime/arguments.hpp"
50 #include "runtime/continuation.hpp"
51 #include "runtime/interfaceSupport.inline.hpp"
52 #include "runtime/javaThread.hpp"
53 #include "runtime/jniHandles.hpp"
54 #include "runtime/objectMonitor.hpp"
55 #include "runtime/os.hpp"
56 #include "runtime/safepoint.hpp"
57 #include "runtime/safepointMechanism.hpp"
58 #include "runtime/sharedRuntime.hpp"
59 #include "runtime/signature_cc.hpp"
60 #include "runtime/stubRoutines.hpp"
61 #include "utilities/checkedCast.hpp"
62 #include "utilities/globalDefinitions.hpp"
63 #include "utilities/macros.hpp"
64 #include "vmreg_x86.inline.hpp"
65 #ifdef COMPILER2
66 #include "opto/output.hpp"
67 #endif
68
69 #ifdef PRODUCT
70 #define BLOCK_COMMENT(str) /* nothing */
71 #define STOP(error) stop(error)
72 #else
73 #define BLOCK_COMMENT(str) block_comment(str)
74 #define STOP(error) block_comment(error); stop(error)
75 #endif
76
77 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
78
79 #ifdef ASSERT
80 bool AbstractAssembler::pd_check_instruction_mark() { return true; }
81 #endif
82
83 static const Assembler::Condition reverse[] = {
84 Assembler::noOverflow /* overflow = 0x0 */ ,
85 Assembler::overflow /* noOverflow = 0x1 */ ,
86 Assembler::aboveEqual /* carrySet = 0x2, below = 0x2 */ ,
87 Assembler::below /* aboveEqual = 0x3, carryClear = 0x3 */ ,
1293 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
1294 assert_different_registers(arg_0, c_rarg1, c_rarg2);
1295 assert_different_registers(arg_1, c_rarg2);
1296 pass_arg2(this, arg_2);
1297 pass_arg1(this, arg_1);
1298 pass_arg0(this, arg_0);
1299 call_VM_leaf(entry_point, 3);
1300 }
1301
1302 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2, Register arg_3) {
1303 assert_different_registers(arg_0, c_rarg1, c_rarg2, c_rarg3);
1304 assert_different_registers(arg_1, c_rarg2, c_rarg3);
1305 assert_different_registers(arg_2, c_rarg3);
1306 pass_arg3(this, arg_3);
1307 pass_arg2(this, arg_2);
1308 pass_arg1(this, arg_1);
1309 pass_arg0(this, arg_0);
1310 call_VM_leaf(entry_point, 3);
1311 }
1312
1313 void MacroAssembler::super_call_VM_leaf(address entry_point) {
1314 MacroAssembler::call_VM_leaf_base(entry_point, 1);
1315 }
1316
1317 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0) {
1318 pass_arg0(this, arg_0);
1319 MacroAssembler::call_VM_leaf_base(entry_point, 1);
1320 }
1321
1322 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1) {
1323 assert_different_registers(arg_0, c_rarg1);
1324 pass_arg1(this, arg_1);
1325 pass_arg0(this, arg_0);
1326 MacroAssembler::call_VM_leaf_base(entry_point, 2);
1327 }
1328
1329 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
1330 assert_different_registers(arg_0, c_rarg1, c_rarg2);
1331 assert_different_registers(arg_1, c_rarg2);
1332 pass_arg2(this, arg_2);
1333 pass_arg1(this, arg_1);
1334 pass_arg0(this, arg_0);
1335 MacroAssembler::call_VM_leaf_base(entry_point, 3);
1336 }
2388 lea(rscratch, src);
2389 Assembler::mulss(dst, Address(rscratch, 0));
2390 }
2391 }
2392
2393 void MacroAssembler::null_check(Register reg, int offset) {
2394 if (needs_explicit_null_check(offset)) {
2395 // provoke OS null exception if reg is null by
2396 // accessing M[reg] w/o changing any (non-CC) registers
2397 // NOTE: cmpl is plenty here to provoke a segv
2398 cmpptr(rax, Address(reg, 0));
2399 // Note: should probably use testl(rax, Address(reg, 0));
2400 // may be shorter code (however, this version of
2401 // testl needs to be implemented first)
2402 } else {
2403 // nothing to do, (later) access of M[reg + offset]
2404 // will provoke OS null exception if reg is null
2405 }
2406 }
2407
2408 void MacroAssembler::test_markword_is_inline_type(Register markword, Label& is_inline_type) {
2409 andptr(markword, markWord::inline_type_pattern_mask);
2410 cmpptr(markword, markWord::inline_type_pattern);
2411 jcc(Assembler::equal, is_inline_type);
2412 }
2413
2414 void MacroAssembler::test_oop_is_not_inline_type(Register object, Register tmp, Label& not_inline_type, bool can_be_null) {
2415 if (can_be_null) {
2416 testptr(object, object);
2417 jcc(Assembler::zero, not_inline_type);
2418 }
2419 const int is_inline_type_mask = markWord::inline_type_pattern;
2420 movptr(tmp, Address(object, oopDesc::mark_offset_in_bytes()));
2421 andptr(tmp, is_inline_type_mask);
2422 cmpptr(tmp, is_inline_type_mask);
2423 jcc(Assembler::notEqual, not_inline_type);
2424 }
2425
2426 void MacroAssembler::test_field_is_null_free_inline_type(Register flags, Register temp_reg, Label& is_null_free_inline_type) {
2427 movl(temp_reg, flags);
2428 testl(temp_reg, 1 << ResolvedFieldEntry::is_null_free_inline_type_shift);
2429 jcc(Assembler::notEqual, is_null_free_inline_type);
2430 }
2431
2432 void MacroAssembler::test_field_is_not_null_free_inline_type(Register flags, Register temp_reg, Label& not_null_free_inline_type) {
2433 movl(temp_reg, flags);
2434 testl(temp_reg, 1 << ResolvedFieldEntry::is_null_free_inline_type_shift);
2435 jcc(Assembler::equal, not_null_free_inline_type);
2436 }
2437
2438 void MacroAssembler::test_field_is_flat(Register flags, Register temp_reg, Label& is_flat) {
2439 movl(temp_reg, flags);
2440 testl(temp_reg, 1 << ResolvedFieldEntry::is_flat_shift);
2441 jcc(Assembler::notEqual, is_flat);
2442 }
2443
2444 void MacroAssembler::test_oop_prototype_bit(Register oop, Register temp_reg, int32_t test_bit, bool jmp_set, Label& jmp_label) {
2445 // load mark word
2446 movptr(temp_reg, Address(oop, oopDesc::mark_offset_in_bytes()));
2447 if (!UseObjectMonitorTable) {
2448 Label test_mark_word;
2449 // check displaced
2450 testl(temp_reg, markWord::unlocked_value);
2451 jccb(Assembler::notZero, test_mark_word);
2452 // slow path use klass prototype
2453 push(rscratch1);
2454 load_prototype_header(temp_reg, oop, rscratch1);
2455 pop(rscratch1);
2456
2457 bind(test_mark_word);
2458 }
2459 testl(temp_reg, test_bit);
2460 jcc((jmp_set) ? Assembler::notZero : Assembler::zero, jmp_label);
2461 }
2462
2463 void MacroAssembler::test_flat_array_oop(Register oop, Register temp_reg,
2464 Label& is_flat_array) {
2465 test_oop_prototype_bit(oop, temp_reg, markWord::flat_array_bit_in_place, true, is_flat_array);
2466 }
2467
2468 void MacroAssembler::test_non_flat_array_oop(Register oop, Register temp_reg,
2469 Label& is_non_flat_array) {
2470 test_oop_prototype_bit(oop, temp_reg, markWord::flat_array_bit_in_place, false, is_non_flat_array);
2471 }
2472
2473 void MacroAssembler::test_null_free_array_oop(Register oop, Register temp_reg, Label&is_null_free_array) {
2474 test_oop_prototype_bit(oop, temp_reg, markWord::null_free_array_bit_in_place, true, is_null_free_array);
2475 }
2476
2477 void MacroAssembler::test_non_null_free_array_oop(Register oop, Register temp_reg, Label&is_non_null_free_array) {
2478 test_oop_prototype_bit(oop, temp_reg, markWord::null_free_array_bit_in_place, false, is_non_null_free_array);
2479 }
2480
2481 void MacroAssembler::test_flat_array_layout(Register lh, Label& is_flat_array) {
2482 testl(lh, Klass::_lh_array_tag_flat_value_bit_inplace);
2483 jcc(Assembler::notZero, is_flat_array);
2484 }
2485
2486 void MacroAssembler::os_breakpoint() {
2487 // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
2488 // (e.g., MSVC can't call ps() otherwise)
2489 call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
2490 }
2491
2492 void MacroAssembler::unimplemented(const char* what) {
2493 const char* buf = nullptr;
2494 {
2495 ResourceMark rm;
2496 stringStream ss;
2497 ss.print("unimplemented: %s", what);
2498 buf = code_string(ss.as_string());
2499 }
2500 stop(buf);
2501 }
2502
2503 #define XSTATE_BV 0x200
2504
2505 void MacroAssembler::pop_CPU_state() {
3806 xorptr(temp, temp); // use _zero reg to clear memory (shorter code)
3807 if (UseIncDec) {
3808 shrptr(index, 3); // divide by 8/16 and set carry flag if bit 2 was set
3809 } else {
3810 shrptr(index, 2); // use 2 instructions to avoid partial flag stall
3811 shrptr(index, 1);
3812 }
3813
3814 // initialize remaining object fields: index is a multiple of 2 now
3815 {
3816 Label loop;
3817 bind(loop);
3818 movptr(Address(address, index, Address::times_8, offset_in_bytes - 1*BytesPerWord), temp);
3819 decrement(index);
3820 jcc(Assembler::notZero, loop);
3821 }
3822
3823 bind(done);
3824 }
3825
3826 void MacroAssembler::inline_layout_info(Register holder_klass, Register index, Register layout_info) {
3827 movptr(layout_info, Address(holder_klass, InstanceKlass::inline_layout_info_array_offset()));
3828 #ifdef ASSERT
3829 {
3830 Label done;
3831 cmpptr(layout_info, 0);
3832 jcc(Assembler::notEqual, done);
3833 stop("inline_layout_info_array is null");
3834 bind(done);
3835 }
3836 #endif
3837
3838 InlineLayoutInfo array[2];
3839 int size = (char*)&array[1] - (char*)&array[0]; // computing size of array elements
3840 if (is_power_of_2(size)) {
3841 shll(index, log2i_exact(size)); // Scale index by power of 2
3842 } else {
3843 imull(index, index, size); // Scale the index to be the entry index * array_element_size
3844 }
3845 lea(layout_info, Address(layout_info, index, Address::times_1, Array<InlineLayoutInfo>::base_offset_in_bytes()));
3846 }
3847
3848 // Look up the method for a megamorphic invokeinterface call.
3849 // The target method is determined by <intf_klass, itable_index>.
3850 // The receiver klass is in recv_klass.
3851 // On success, the result will be in method_result, and execution falls through.
3852 // On failure, execution transfers to the given label.
3853 void MacroAssembler::lookup_interface_method(Register recv_klass,
3854 Register intf_klass,
3855 RegisterOrConstant itable_index,
3856 Register method_result,
3857 Register scan_temp,
3858 Label& L_no_such_interface,
3859 bool return_method) {
3860 assert_different_registers(recv_klass, intf_klass, scan_temp);
3861 assert_different_registers(method_result, intf_klass, scan_temp);
3862 assert(recv_klass != method_result || !return_method,
3863 "recv_klass can be destroyed when method isn't needed");
3864
3865 assert(itable_index.is_constant() || itable_index.as_register() == method_result,
3866 "caller must use same register for non-constant itable index as for method");
3867
4878 } else {
4879 Label L;
4880 jccb(negate_condition(cc), L);
4881 movl(dst, src);
4882 bind(L);
4883 }
4884 }
4885
4886 void MacroAssembler::cmov32(Condition cc, Register dst, Register src) {
4887 if (VM_Version::supports_cmov()) {
4888 cmovl(cc, dst, src);
4889 } else {
4890 Label L;
4891 jccb(negate_condition(cc), L);
4892 movl(dst, src);
4893 bind(L);
4894 }
4895 }
4896
4897 void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file, int line) {
4898 if (!VerifyOops || VerifyAdapterSharing) {
4899 // Below address of the code string confuses VerifyAdapterSharing
4900 // because it may differ between otherwise equivalent adapters.
4901 return;
4902 }
4903
4904 BLOCK_COMMENT("verify_oop {");
4905 push(rscratch1);
4906 push(rax); // save rax
4907 push(reg); // pass register argument
4908
4909 // Pass register number to verify_oop_subroutine
4910 const char* b = nullptr;
4911 {
4912 ResourceMark rm;
4913 stringStream ss;
4914 ss.print("verify_oop: %s: %s (%s:%d)", reg->name(), s, file, line);
4915 b = code_string(ss.as_string());
4916 }
4917 AddressLiteral buffer((address) b, external_word_Relocation::spec_for_immediate());
4918 pushptr(buffer.addr(), rscratch1);
4919
4920 // call indirectly to solve generation ordering problem
4921 movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
4922 call(rax);
5135 } else {
5136 pop(rax);
5137 }
5138
5139 // CAS success means the slot now has the receiver we want. CAS failure means
5140 // something had claimed the slot concurrently: it can be the same receiver we want,
5141 // or something else. Since this is a slow path, we can optimize for code density,
5142 // and just restart the search from the beginning.
5143 jmpb(L_restart);
5144
5145 // Found a receiver, convert its slot offset to corresponding count offset.
5146 bind(L_found_recv);
5147 addptr(offset, receiver_to_count_step);
5148
5149 // Finally, update the counter
5150 bind(L_count_update);
5151 addptr(Address(mdp, offset, Address::times_ptr), DataLayout::counter_increment);
5152 }
5153
5154 void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* file, int line) {
5155 if (!VerifyOops || VerifyAdapterSharing) {
5156 // Below address of the code string confuses VerifyAdapterSharing
5157 // because it may differ between otherwise equivalent adapters.
5158 return;
5159 }
5160
5161 push(rscratch1);
5162 push(rax); // save rax,
5163 // addr may contain rsp so we will have to adjust it based on the push
5164 // we just did (and on 64 bit we do two pushes)
5165 // NOTE: 64bit seemed to have had a bug in that it did movq(addr, rax); which
5166 // stores rax into addr which is backwards of what was intended.
5167 if (addr.uses(rsp)) {
5168 lea(rax, addr);
5169 pushptr(Address(rax, 2 * BytesPerWord));
5170 } else {
5171 pushptr(addr);
5172 }
5173
5174 // Pass register number to verify_oop_subroutine
5175 const char* b = nullptr;
5176 {
5177 ResourceMark rm;
5178 stringStream ss;
5179 ss.print("verify_oop_addr: %s (%s:%d)", s, file, line);
5531
5532 void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
5533 // get mirror
5534 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
5535 load_method_holder(mirror, method);
5536 movptr(mirror, Address(mirror, mirror_offset));
5537 resolve_oop_handle(mirror, tmp);
5538 }
5539
5540 void MacroAssembler::load_method_holder_cld(Register rresult, Register rmethod) {
5541 load_method_holder(rresult, rmethod);
5542 movptr(rresult, Address(rresult, InstanceKlass::class_loader_data_offset()));
5543 }
5544
5545 void MacroAssembler::load_method_holder(Register holder, Register method) {
5546 movptr(holder, Address(method, Method::const_offset())); // ConstMethod*
5547 movptr(holder, Address(holder, ConstMethod::constants_offset())); // ConstantPool*
5548 movptr(holder, Address(holder, ConstantPool::pool_holder_offset())); // InstanceKlass*
5549 }
5550
5551 void MacroAssembler::load_metadata(Register dst, Register src) {
5552 if (UseCompactObjectHeaders) {
5553 load_narrow_klass_compact(dst, src);
5554 } else {
5555 movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
5556 }
5557 }
5558
5559 void MacroAssembler::load_narrow_klass_compact(Register dst, Register src) {
5560 assert(UseCompactObjectHeaders, "expect compact object headers");
5561 movq(dst, Address(src, oopDesc::mark_offset_in_bytes()));
5562 shrq(dst, markWord::klass_shift);
5563 }
5564
5565 void MacroAssembler::load_narrow_klass(Register dst, Register src) {
5566 if (UseCompactObjectHeaders) {
5567 load_narrow_klass_compact(dst, src);
5568 } else {
5569 movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
5570 }
5571 }
5572
5573 void MacroAssembler::load_klass(Register dst, Register src, Register tmp) {
5574 assert_different_registers(src, tmp);
5575 assert_different_registers(dst, tmp);
5576 load_narrow_klass(dst, src);
5577 decode_klass_not_null(dst, tmp);
5578 }
5579
5580 void MacroAssembler::load_prototype_header(Register dst, Register src, Register tmp) {
5581 load_klass(dst, src, tmp);
5582 movptr(dst, Address(dst, Klass::prototype_header_offset()));
5583 }
5584
5585 void MacroAssembler::store_klass(Register dst, Register src, Register tmp) {
5586 assert(!UseCompactObjectHeaders, "not with compact headers");
5587 assert_different_registers(src, tmp);
5588 assert_different_registers(dst, tmp);
5589 encode_klass_not_null(src, tmp);
5590 movl(Address(dst, oopDesc::klass_offset_in_bytes()), src);
5591 }
5592
5593 void MacroAssembler::cmp_klass(Register klass, Register obj, Register tmp) {
5594 if (UseCompactObjectHeaders) {
5595 assert(tmp != noreg, "need tmp");
5596 assert_different_registers(klass, obj, tmp);
5597 load_narrow_klass_compact(tmp, obj);
5598 cmpl(klass, tmp);
5599 } else {
5600 cmpl(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
5601 }
5602 }
5603
5604 void MacroAssembler::cmp_klasses_from_objects(Register obj1, Register obj2, Register tmp1, Register tmp2) {
5621 bool as_raw = (decorators & AS_RAW) != 0;
5622 if (as_raw) {
5623 bs->BarrierSetAssembler::load_at(this, decorators, type, dst, src, tmp1);
5624 } else {
5625 bs->load_at(this, decorators, type, dst, src, tmp1);
5626 }
5627 }
5628
5629 void MacroAssembler::access_store_at(BasicType type, DecoratorSet decorators, Address dst, Register val,
5630 Register tmp1, Register tmp2, Register tmp3) {
5631 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
5632 decorators = AccessInternal::decorator_fixup(decorators, type);
5633 bool as_raw = (decorators & AS_RAW) != 0;
5634 if (as_raw) {
5635 bs->BarrierSetAssembler::store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
5636 } else {
5637 bs->store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
5638 }
5639 }
5640
5641 void MacroAssembler::flat_field_copy(DecoratorSet decorators, Register src, Register dst,
5642 Register inline_layout_info) {
5643 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
5644 bs->flat_field_copy(this, decorators, src, dst, inline_layout_info);
5645 }
5646
5647 void MacroAssembler::payload_offset(Register inline_klass, Register offset) {
5648 movptr(offset, Address(inline_klass, InlineKlass::adr_members_offset()));
5649 movl(offset, Address(offset, InlineKlass::payload_offset_offset()));
5650 }
5651
5652 void MacroAssembler::payload_addr(Register oop, Register data, Register inline_klass) {
5653 // ((address) (void*) o) + vk->payload_offset();
5654 Register offset = (data == oop) ? rscratch1 : data;
5655 payload_offset(inline_klass, offset);
5656 if (data == oop) {
5657 addptr(data, offset);
5658 } else {
5659 lea(data, Address(oop, offset));
5660 }
5661 }
5662
5663 void MacroAssembler::load_heap_oop(Register dst, Address src, Register tmp1, DecoratorSet decorators) {
5664 access_load_at(T_OBJECT, IN_HEAP | decorators, dst, src, tmp1);
5665 }
5666
5667 // Doesn't do verification, generates fixed size code
5668 void MacroAssembler::load_heap_oop_not_null(Register dst, Address src, Register tmp1, DecoratorSet decorators) {
5669 access_load_at(T_OBJECT, IN_HEAP | IS_NOT_NULL | decorators, dst, src, tmp1);
5670 }
5671
5672 void MacroAssembler::store_heap_oop(Address dst, Register val, Register tmp1,
5673 Register tmp2, Register tmp3, DecoratorSet decorators) {
5674 access_store_at(T_OBJECT, IN_HEAP | decorators, dst, val, tmp1, tmp2, tmp3);
5675 }
5676
5677 // Used for storing nulls.
5678 void MacroAssembler::store_heap_oop_null(Address dst) {
5679 access_store_at(T_OBJECT, IN_HEAP, dst, noreg, noreg, noreg, noreg);
5680 }
5681
5682 void MacroAssembler::store_klass_gap(Register dst, Register src) {
6005 assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
6006 int klass_index = oop_recorder()->find_index(k);
6007 RelocationHolder rspec = metadata_Relocation::spec(klass_index);
6008 Assembler::cmp_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
6009 }
6010
6011 void MacroAssembler::reinit_heapbase() {
6012 if (UseCompressedOops) {
6013 if (Universe::heap() != nullptr && !AOTCodeCache::is_on_for_dump()) {
6014 if (CompressedOops::base() == nullptr) {
6015 MacroAssembler::xorptr(r12_heapbase, r12_heapbase);
6016 } else {
6017 mov64(r12_heapbase, (int64_t)CompressedOops::base());
6018 }
6019 } else {
6020 movptr(r12_heapbase, ExternalAddress(CompressedOops::base_addr()));
6021 }
6022 }
6023 }
6024
6025 int MacroAssembler::store_inline_type_fields_to_buf(ciInlineKlass* vk, bool from_interpreter) {
6026 assert(InlineTypeReturnedAsFields, "Inline types should never be returned as fields");
6027 // An inline type might be returned. If fields are in registers we
6028 // need to allocate an inline type instance and initialize it with
6029 // the value of the fields.
6030 Label skip;
6031 // We only need a new buffered inline type if a new one is not returned
6032 testptr(rax, 1);
6033 jcc(Assembler::zero, skip);
6034 int call_offset = -1;
6035
6036 // The following code is similar to allocation code in TemplateTable::_new but has some slight differences,
6037 // e.g. object size is always not zero, sometimes it's constant; storing klass ptr after
6038 // allocating is not necessary if vk != nullptr, etc.
6039 Label slow_case;
6040 // 1. Try to allocate a new buffered inline instance either from TLAB or eden space
6041 mov(rscratch1, rax); // save rax for slow_case since *_allocate may corrupt it when allocation failed
6042 if (vk != nullptr) {
6043 // Called from C1, where the return type is statically known.
6044 movptr(rbx, (intptr_t)vk->get_InlineKlass());
6045 jint lh = vk->layout_helper();
6046 assert(lh != Klass::_lh_neutral_value, "inline class in return type must have been resolved");
6047 if (UseTLAB && !Klass::layout_helper_needs_slow_path(lh)) {
6048 tlab_allocate(rax, noreg, lh, r13, r14, slow_case);
6049 } else {
6050 jmp(slow_case);
6051 }
6052 } else {
6053 // Call from interpreter. RAX contains ((the InlineKlass* of the return type) | 0x01)
6054 mov(rbx, rax);
6055 andptr(rbx, -2);
6056 if (UseTLAB) {
6057 movl(r14, Address(rbx, Klass::layout_helper_offset()));
6058 testl(r14, Klass::_lh_instance_slow_path_bit);
6059 jcc(Assembler::notZero, slow_case);
6060 tlab_allocate(rax, r14, 0, r13, r14, slow_case);
6061 } else {
6062 jmp(slow_case);
6063 }
6064 }
6065 if (UseTLAB) {
6066 // 2. Initialize buffered inline instance header
6067 Register buffer_obj = rax;
6068 Register klass = rbx;
6069 if (UseCompactObjectHeaders) {
6070 Register mark_word = r13;
6071 movptr(mark_word, Address(klass, Klass::prototype_header_offset()));
6072 movptr(Address(buffer_obj, oopDesc::mark_offset_in_bytes()), mark_word);
6073 } else {
6074 movptr(Address(buffer_obj, oopDesc::mark_offset_in_bytes()), (intptr_t)markWord::inline_type_prototype().value());
6075 xorl(r13, r13);
6076 store_klass_gap(buffer_obj, r13);
6077 if (vk == nullptr) {
6078 // store_klass corrupts rbx(klass), so save it in r13 for later use (interpreter case only).
6079 mov(r13, klass);
6080 }
6081 store_klass(buffer_obj, klass, rscratch1);
6082 klass = r13;
6083 }
6084 // 3. Initialize its fields with an inline class specific handler
6085 if (vk != nullptr) {
6086 call(RuntimeAddress(vk->pack_handler())); // no need for call info as this will not safepoint.
6087 } else {
6088 movptr(rbx, Address(klass, InlineKlass::adr_members_offset()));
6089 movptr(rbx, Address(rbx, InlineKlass::pack_handler_offset()));
6090 call(rbx);
6091 }
6092 jmp(skip);
6093 }
6094 bind(slow_case);
6095 // We failed to allocate a new inline type, fall back to a runtime
6096 // call. Some oop field may be live in some registers but we can't
6097 // tell. That runtime call will take care of preserving them
6098 // across a GC if there's one.
6099 mov(rax, rscratch1);
6100
6101 if (from_interpreter) {
6102 super_call_VM_leaf(SharedRuntime::store_inline_type_fields_to_buf_entry());
6103 } else {
6104 call(RuntimeAddress(SharedRuntime::store_inline_type_fields_to_buf_entry()));
6105 call_offset = offset();
6106 }
6107
6108 bind(skip);
6109 return call_offset;
6110 }
6111
6112 // Move a value between registers/stack slots and update the reg_state
6113 bool MacroAssembler::move_helper(VMReg from, VMReg to, BasicType bt, RegState reg_state[]) {
6114 assert(from->is_valid() && to->is_valid(), "source and destination must be valid");
6115 if (reg_state[to->value()] == reg_written) {
6116 return true; // Already written
6117 }
6118 if (from != to && bt != T_VOID) {
6119 if (reg_state[to->value()] == reg_readonly) {
6120 return false; // Not yet writable
6121 }
6122 if (from->is_reg()) {
6123 if (to->is_reg()) {
6124 if (from->is_XMMRegister()) {
6125 if (bt == T_DOUBLE) {
6126 movdbl(to->as_XMMRegister(), from->as_XMMRegister());
6127 } else {
6128 assert(bt == T_FLOAT, "must be float");
6129 movflt(to->as_XMMRegister(), from->as_XMMRegister());
6130 }
6131 } else {
6132 movq(to->as_Register(), from->as_Register());
6133 }
6134 } else {
6135 int st_off = to->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6136 Address to_addr = Address(rsp, st_off);
6137 if (from->is_XMMRegister()) {
6138 if (bt == T_DOUBLE) {
6139 movdbl(to_addr, from->as_XMMRegister());
6140 } else {
6141 assert(bt == T_FLOAT, "must be float");
6142 movflt(to_addr, from->as_XMMRegister());
6143 }
6144 } else {
6145 movq(to_addr, from->as_Register());
6146 }
6147 }
6148 } else {
6149 Address from_addr = Address(rsp, from->reg2stack() * VMRegImpl::stack_slot_size + wordSize);
6150 if (to->is_reg()) {
6151 if (to->is_XMMRegister()) {
6152 if (bt == T_DOUBLE) {
6153 movdbl(to->as_XMMRegister(), from_addr);
6154 } else {
6155 assert(bt == T_FLOAT, "must be float");
6156 movflt(to->as_XMMRegister(), from_addr);
6157 }
6158 } else {
6159 movq(to->as_Register(), from_addr);
6160 }
6161 } else {
6162 int st_off = to->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6163 movq(r13, from_addr);
6164 movq(Address(rsp, st_off), r13);
6165 }
6166 }
6167 }
6168 // Update register states
6169 reg_state[from->value()] = reg_writable;
6170 reg_state[to->value()] = reg_written;
6171 return true;
6172 }
6173
6174 // Calculate the extra stack space required for packing or unpacking inline
6175 // args and adjust the stack pointer (see MacroAssembler::remove_frame).
6176 int MacroAssembler::extend_stack_for_inline_args(int args_on_stack) {
6177 int sp_inc = args_on_stack * VMRegImpl::stack_slot_size;
6178 sp_inc = align_up(sp_inc, StackAlignmentInBytes);
6179 assert(sp_inc > 0, "sanity");
6180 // Two additional slots to account for return address
6181 sp_inc += 2 * VMRegImpl::stack_slot_size;
6182
6183 push(rbp);
6184 subptr(rsp, sp_inc);
6185 #ifdef ASSERT
6186 movl(Address(rsp, 0), badRegWordVal);
6187 movl(Address(rsp, VMRegImpl::stack_slot_size), badRegWordVal);
6188 #endif
6189 return sp_inc + wordSize; // account for rbp space
6190 }
6191
6192 // Read all fields from an inline type buffer and store the field values in registers/stack slots.
6193 bool MacroAssembler::unpack_inline_helper(const GrowableArray<SigEntry>* sig, int& sig_index,
6194 VMReg from, int& from_index, VMRegPair* to, int to_count, int& to_index,
6195 RegState reg_state[]) {
6196 assert(sig->at(sig_index)._bt == T_VOID, "should be at end delimiter");
6197 assert(from->is_valid(), "source must be valid");
6198 bool progress = false;
6199 #ifdef ASSERT
6200 const int start_offset = offset();
6201 #endif
6202
6203 Label L_null, L_notNull;
6204 // Don't use r14 as tmp because it's used for spilling (see MacroAssembler::spill_reg_for)
6205 Register tmp1 = r10;
6206 Register tmp2 = r13;
6207 Register fromReg = noreg;
6208 ScalarizedInlineArgsStream stream(sig, sig_index, to, to_count, to_index, true);
6209 bool done = true;
6210 bool mark_done = true;
6211 VMReg toReg;
6212 BasicType bt;
6213 // Check if argument requires a null check
6214 bool null_check = false;
6215 VMReg nullCheckReg;
6216 while (stream.next(nullCheckReg, bt)) {
6217 if (sig->at(stream.sig_index())._offset == -1) {
6218 null_check = true;
6219 break;
6220 }
6221 }
6222 stream.reset(sig_index, to_index);
6223 while (stream.next(toReg, bt)) {
6224 assert(toReg->is_valid(), "destination must be valid");
6225 int idx = (int)toReg->value();
6226 if (reg_state[idx] == reg_readonly) {
6227 if (idx != from->value()) {
6228 mark_done = false;
6229 }
6230 done = false;
6231 continue;
6232 } else if (reg_state[idx] == reg_written) {
6233 continue;
6234 }
6235 assert(reg_state[idx] == reg_writable, "must be writable");
6236 reg_state[idx] = reg_written;
6237 progress = true;
6238
6239 if (fromReg == noreg) {
6240 if (from->is_reg()) {
6241 fromReg = from->as_Register();
6242 } else {
6243 int st_off = from->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6244 movq(tmp1, Address(rsp, st_off));
6245 fromReg = tmp1;
6246 }
6247 if (null_check) {
6248 // Nullable inline type argument, emit null check
6249 testptr(fromReg, fromReg);
6250 jcc(Assembler::zero, L_null);
6251 }
6252 }
6253 int off = sig->at(stream.sig_index())._offset;
6254 if (off == -1) {
6255 assert(null_check, "Missing null check at");
6256 if (toReg->is_stack()) {
6257 int st_off = toReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6258 movq(Address(rsp, st_off), 1);
6259 } else {
6260 movq(toReg->as_Register(), 1);
6261 }
6262 continue;
6263 }
6264 if (sig->at(stream.sig_index())._vt_oop) {
6265 if (toReg->is_stack()) {
6266 int st_off = toReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6267 movq(Address(rsp, st_off), fromReg);
6268 } else {
6269 movq(toReg->as_Register(), fromReg);
6270 }
6271 continue;
6272 }
6273 assert(off > 0, "offset in object should be positive");
6274 Address fromAddr = Address(fromReg, off);
6275 if (!toReg->is_XMMRegister()) {
6276 Register dst = toReg->is_stack() ? tmp2 : toReg->as_Register();
6277 if (is_reference_type(bt)) {
6278 load_heap_oop(dst, fromAddr);
6279 } else {
6280 bool is_signed = (bt != T_CHAR) && (bt != T_BOOLEAN);
6281 load_sized_value(dst, fromAddr, type2aelembytes(bt), is_signed);
6282 }
6283 if (toReg->is_stack()) {
6284 int st_off = toReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6285 movq(Address(rsp, st_off), dst);
6286 }
6287 } else if (bt == T_DOUBLE) {
6288 movdbl(toReg->as_XMMRegister(), fromAddr);
6289 } else {
6290 assert(bt == T_FLOAT, "must be float");
6291 movflt(toReg->as_XMMRegister(), fromAddr);
6292 }
6293 }
6294 if (progress && null_check) {
6295 if (done) {
6296 jmp(L_notNull);
6297 bind(L_null);
6298 // Set null marker to zero to signal that the argument is null.
6299 // Also set all fields to zero since the runtime requires a canonical
6300 // representation of a flat null.
6301 stream.reset(sig_index, to_index);
6302 while (stream.next(toReg, bt)) {
6303 if (toReg->is_stack()) {
6304 int st_off = toReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6305 movq(Address(rsp, st_off), 0);
6306 } else if (toReg->is_XMMRegister()) {
6307 xorps(toReg->as_XMMRegister(), toReg->as_XMMRegister());
6308 } else {
6309 xorl(toReg->as_Register(), toReg->as_Register());
6310 }
6311 }
6312 bind(L_notNull);
6313 } else {
6314 bind(L_null);
6315 }
6316 }
6317
6318 sig_index = stream.sig_index();
6319 to_index = stream.regs_index();
6320
6321 if (mark_done && reg_state[from->value()] != reg_written) {
6322 // This is okay because no one else will write to that slot
6323 reg_state[from->value()] = reg_writable;
6324 }
6325 from_index--;
6326 assert(progress || (start_offset == offset()), "should not emit code");
6327 return done;
6328 }
6329
6330 bool MacroAssembler::pack_inline_helper(const GrowableArray<SigEntry>* sig, int& sig_index, int vtarg_index,
6331 VMRegPair* from, int from_count, int& from_index, VMReg to,
6332 RegState reg_state[], Register val_array) {
6333 assert(sig->at(sig_index)._bt == T_METADATA, "should be at delimiter");
6334 assert(to->is_valid(), "destination must be valid");
6335
6336 if (reg_state[to->value()] == reg_written) {
6337 skip_unpacked_fields(sig, sig_index, from, from_count, from_index);
6338 return true; // Already written
6339 }
6340
6341 // Be careful with r14 because it's used for spilling (see MacroAssembler::spill_reg_for).
6342 Register val_obj_tmp = r11;
6343 Register from_reg_tmp = r14;
6344 Register tmp1 = r10;
6345 Register tmp2 = r13;
6346 Register tmp3 = rbx;
6347 Register val_obj = to->is_stack() ? val_obj_tmp : to->as_Register();
6348
6349 assert_different_registers(val_obj_tmp, from_reg_tmp, tmp1, tmp2, tmp3, val_array);
6350
6351 if (reg_state[to->value()] == reg_readonly) {
6352 if (!is_reg_in_unpacked_fields(sig, sig_index, to, from, from_count, from_index)) {
6353 skip_unpacked_fields(sig, sig_index, from, from_count, from_index);
6354 return false; // Not yet writable
6355 }
6356 val_obj = val_obj_tmp;
6357 }
6358
6359 ScalarizedInlineArgsStream stream(sig, sig_index, from, from_count, from_index);
6360 VMReg fromReg;
6361 BasicType bt;
6362 Label L_null;
6363 while (stream.next(fromReg, bt)) {
6364 assert(fromReg->is_valid(), "source must be valid");
6365 reg_state[fromReg->value()] = reg_writable;
6366
6367 int off = sig->at(stream.sig_index())._offset;
6368 if (off == -1) {
6369 // Nullable inline type argument, emit null check
6370 Label L_notNull;
6371 if (fromReg->is_stack()) {
6372 int ld_off = fromReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6373 testb(Address(rsp, ld_off), 1);
6374 } else {
6375 testb(fromReg->as_Register(), 1);
6376 }
6377 jcc(Assembler::notZero, L_notNull);
6378 movptr(val_obj, 0);
6379 jmp(L_null);
6380 bind(L_notNull);
6381 continue;
6382 }
6383 if (sig->at(stream.sig_index())._vt_oop) {
6384 // buffer argument: use if non null
6385 if (fromReg->is_stack()) {
6386 int ld_off = fromReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6387 movptr(val_obj, Address(rsp, ld_off));
6388 } else {
6389 movptr(val_obj, fromReg->as_Register());
6390 }
6391 testptr(val_obj, val_obj);
6392 jcc(Assembler::notEqual, L_null);
6393 // otherwise get the buffer from the just allocated pool of buffers
6394 int index = arrayOopDesc::base_offset_in_bytes(T_OBJECT) + vtarg_index * type2aelembytes(T_OBJECT);
6395 load_heap_oop(val_obj, Address(val_array, index));
6396 continue;
6397 }
6398
6399 assert(off > 0, "offset in object should be positive");
6400 size_t size_in_bytes = is_java_primitive(bt) ? type2aelembytes(bt) : wordSize;
6401
6402 // Pack the scalarized field into the value object.
6403 Address dst(val_obj, off);
6404 if (!fromReg->is_XMMRegister()) {
6405 Register src;
6406 if (fromReg->is_stack()) {
6407 src = from_reg_tmp;
6408 int ld_off = fromReg->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
6409 load_sized_value(src, Address(rsp, ld_off), size_in_bytes, /* is_signed */ false);
6410 } else {
6411 src = fromReg->as_Register();
6412 }
6413 assert_different_registers(dst.base(), src, tmp1, tmp2, tmp3, val_array);
6414 if (is_reference_type(bt)) {
6415 // store_heap_oop transitively calls oop_store_at which corrupts to.base(). We need to keep val_obj valid.
6416 mov(tmp3, val_obj);
6417 Address dst_with_tmp3(tmp3, off);
6418 store_heap_oop(dst_with_tmp3, src, tmp1, tmp2, tmp3, IN_HEAP | ACCESS_WRITE | IS_DEST_UNINITIALIZED);
6419 } else {
6420 store_sized_value(dst, src, size_in_bytes);
6421 }
6422 } else if (bt == T_DOUBLE) {
6423 movdbl(dst, fromReg->as_XMMRegister());
6424 } else {
6425 assert(bt == T_FLOAT, "must be float");
6426 movflt(dst, fromReg->as_XMMRegister());
6427 }
6428 }
6429 bind(L_null);
6430 sig_index = stream.sig_index();
6431 from_index = stream.regs_index();
6432
6433 assert(reg_state[to->value()] == reg_writable, "must have already been read");
6434 bool success = move_helper(val_obj->as_VMReg(), to, T_OBJECT, reg_state);
6435 assert(success, "to register must be writable");
6436 return true;
6437 }
6438
6439 VMReg MacroAssembler::spill_reg_for(VMReg reg) {
6440 return reg->is_XMMRegister() ? xmm8->as_VMReg() : r14->as_VMReg();
6441 }
6442
6443 void MacroAssembler::remove_frame(int initial_framesize, bool needs_stack_repair) {
6444 assert((initial_framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
6445 if (needs_stack_repair) {
6446 // The method has a scalarized entry point (where fields of value object arguments
6447 // are passed through registers and stack), and a non-scalarized entry point (where
6448 // value object arguments are given as oops). The non-scalarized entry point will
6449 // first load each field of value object arguments and store them in registers and on
6450 // the stack in a way compatible with the scalarized entry point. To do so, some extra
6451 // stack space might be reserved (if argument registers are not enough). On leaving the
6452 // method, this space must be freed.
6453 //
6454 // In case we used the non-scalarized entry point the stack looks like this:
6455 //
6456 // | Arguments from caller |
6457 // |---------------------------| <-- caller's SP
6458 // | Return address #1 |
6459 // | Saved RBP #1 |
6460 // |---------------------------|
6461 // | Extension space for |
6462 // | inline arg (un)packing |
6463 // |---------------------------| <-- start of this method's frame
6464 // | Return address #2 |
6465 // | Saved RBP #2 |
6466 // |---------------------------| <-- RBP (with -XX:+PreserveFramePointer)
6467 // | sp_inc |
6468 // | method locals |
6469 // |---------------------------| <-- SP
6470 //
6471 // Space for the return pc and saved rbp is reserved twice. But only the #1 copies
6472 // contain the real values of return pc and saved rbp. The #2 copies are not reliable
6473 // and should not be used. They are mostly needed to add space between the extension
6474 // space and the locals, as there would be between the real arguments and the locals
6475 // if we don't need to do unpacking (from the scalarized entry point).
6476 //
6477 // When leaving, one must load RBP #1 into RBP, and use the copy #1 of the return address,
6478 // while keeping in mind that from the scalarized entry point, there will be only one
6479 // copy. Indeed, in the case we used the scalarized calling convention, the stack looks like this:
6480 //
6481 // | Arguments from caller |
6482 // |---------------------------| <-- caller's SP
6483 // | Return address |
6484 // | Saved RBP |
6485 // |---------------------------| <-- FP (with -XX:+PreserveFramePointer)
6486 // | sp_inc |
6487 // | method locals |
6488 // |---------------------------| <-- SP
6489 //
6490 // The sp_inc stack slot holds the total size of the frame, including the extension
6491 // space and copies #2 of the return address and the saved RBP (but never the copies
6492 // #1 of the return address and saved RBP). That is how to find the copies #1 of the
6493 // return address and saved rbp. This size is expressed in bytes. Be careful when using
6494 // it from C++ in pointer arithmetic you might need to divide it by wordSize.
6495
6496 // The stack increment resides just below the saved rbp
6497 addq(rsp, Address(rsp, initial_framesize - wordSize));
6498 pop(rbp);
6499 } else {
6500 if (initial_framesize > 0) {
6501 addq(rsp, initial_framesize);
6502 }
6503 pop(rbp);
6504 }
6505 }
6506
6507 #ifdef COMPILER2
6508
6509 // clear memory of size 'cnt' qwords, starting at 'base' using XMM/YMM/ZMM registers
6510 void MacroAssembler::xmm_clear_mem(Register base, Register cnt, Register val, XMMRegister xtmp, KRegister mask) {
6511 // cnt - number of qwords (8-byte words).
6512 // base - start address, qword aligned.
6513 Label L_zero_64_bytes, L_loop, L_sloop, L_tail, L_end;
6514 bool use64byteVector = (MaxVectorSize == 64) && (CopyAVX3Threshold == 0);
6515 if (use64byteVector) {
6516 evpbroadcastq(xtmp, val, AVX_512bit);
6517 } else if (MaxVectorSize >= 32) {
6518 movdq(xtmp, val);
6519 punpcklqdq(xtmp, xtmp);
6520 vinserti128_high(xtmp, xtmp);
6521 } else {
6522 movdq(xtmp, val);
6523 punpcklqdq(xtmp, xtmp);
6524 }
6525 jmp(L_zero_64_bytes);
6526
6527 BIND(L_loop);
6528 if (MaxVectorSize >= 32) {
6529 fill64(base, 0, xtmp, use64byteVector);
6530 } else {
6531 movdqu(Address(base, 0), xtmp);
6532 movdqu(Address(base, 16), xtmp);
6533 movdqu(Address(base, 32), xtmp);
6534 movdqu(Address(base, 48), xtmp);
6535 }
6536 addptr(base, 64);
6537
6538 BIND(L_zero_64_bytes);
6539 subptr(cnt, 8);
6540 jccb(Assembler::greaterEqual, L_loop);
6541
6542 // Copy trailing 64 bytes
6543 if (use64byteVector) {
6544 addptr(cnt, 8);
6545 jccb(Assembler::equal, L_end);
6546 fill64_masked(3, base, 0, xtmp, mask, cnt, val, true);
6547 jmp(L_end);
6548 } else {
6549 addptr(cnt, 4);
6550 jccb(Assembler::less, L_tail);
6551 if (MaxVectorSize >= 32) {
6552 vmovdqu(Address(base, 0), xtmp);
6553 } else {
6554 movdqu(Address(base, 0), xtmp);
6555 movdqu(Address(base, 16), xtmp);
6556 }
6557 }
6558 addptr(base, 32);
6559 subptr(cnt, 4);
6560
6561 BIND(L_tail);
6562 addptr(cnt, 4);
6563 jccb(Assembler::lessEqual, L_end);
6564 if (UseAVX > 2 && MaxVectorSize >= 32 && VM_Version::supports_avx512vl()) {
6565 fill32_masked(3, base, 0, xtmp, mask, cnt, val);
6566 } else {
6567 decrement(cnt);
6568
6569 BIND(L_sloop);
6570 movq(Address(base, 0), xtmp);
6571 addptr(base, 8);
6572 decrement(cnt);
6573 jccb(Assembler::greaterEqual, L_sloop);
6574 }
6575 BIND(L_end);
6576 }
6577
6578 // Clearing constant sized memory using YMM/ZMM registers.
6579 void MacroAssembler::clear_mem(Register base, int cnt, Register rtmp, XMMRegister xtmp, KRegister mask) {
6580 assert(UseAVX > 2 && VM_Version::supports_avx512vl(), "");
6581 bool use64byteVector = (MaxVectorSize > 32) && (CopyAVX3Threshold == 0);
6582
6583 int vector64_count = (cnt & (~0x7)) >> 3;
6584 cnt = cnt & 0x7;
6585 const int fill64_per_loop = 4;
6647 break;
6648 case 7:
6649 if (use64byteVector) {
6650 movl(rtmp, 0x7F);
6651 kmovwl(mask, rtmp);
6652 evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_512bit);
6653 } else {
6654 evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
6655 movl(rtmp, 0x7);
6656 kmovwl(mask, rtmp);
6657 evmovdqu(T_LONG, mask, Address(base, disp + 32), xtmp, true, Assembler::AVX_256bit);
6658 }
6659 break;
6660 default:
6661 fatal("Unexpected length : %d\n",cnt);
6662 break;
6663 }
6664 }
6665 }
6666
6667 void MacroAssembler::clear_mem(Register base, Register cnt, Register val, XMMRegister xtmp,
6668 bool is_large, bool word_copy_only, KRegister mask) {
6669 // cnt - number of qwords (8-byte words).
6670 // base - start address, qword aligned.
6671 // is_large - if optimizers know cnt is larger than InitArrayShortSize
6672 assert(base==rdi, "base register must be edi for rep stos");
6673 assert(val==rax, "val register must be eax for rep stos");
6674 assert(cnt==rcx, "cnt register must be ecx for rep stos");
6675 assert(InitArrayShortSize % BytesPerLong == 0,
6676 "InitArrayShortSize should be the multiple of BytesPerLong");
6677
6678 Label DONE;
6679
6680 if (!is_large) {
6681 Label LOOP, LONG;
6682 cmpptr(cnt, InitArrayShortSize/BytesPerLong);
6683 jccb(Assembler::greater, LONG);
6684
6685 decrement(cnt);
6686 jccb(Assembler::negative, DONE); // Zero length
6687
6688 // Use individual pointer-sized stores for small counts:
6689 BIND(LOOP);
6690 movptr(Address(base, cnt, Address::times_ptr), val);
6691 decrement(cnt);
6692 jccb(Assembler::greaterEqual, LOOP);
6693 jmpb(DONE);
6694
6695 BIND(LONG);
6696 }
6697
6698 // Use longer rep-prefixed ops for non-small counts:
6699 if (UseFastStosb && !word_copy_only) {
6700 shlptr(cnt, 3); // convert to number of bytes
6701 rep_stosb();
6702 } else if (UseXMMForObjInit) {
6703 xmm_clear_mem(base, cnt, val, xtmp, mask);
6704 } else {
6705 rep_stos();
6706 }
6707
6708 BIND(DONE);
6709 }
6710
6711 #endif //COMPILER2
6712
6713
6714 void MacroAssembler::generate_fill(BasicType t, bool aligned,
6715 Register to, Register value, Register count,
6716 Register rtmp, XMMRegister xtmp) {
6717 ShortBranchVerifier sbv(this);
6718 assert_different_registers(to, value, count, rtmp);
6719 Label L_exit;
6720 Label L_fill_2_bytes, L_fill_4_bytes;
6721
6722 #if defined(COMPILER2)
6723 if(MaxVectorSize >=32 &&
10600
10601 // Load top.
10602 movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10603
10604 // Check if the lock-stack is full.
10605 cmpl(top, LockStack::end_offset());
10606 jcc(Assembler::greaterEqual, slow);
10607
10608 // Check for recursion.
10609 cmpptr(obj, Address(thread, top, Address::times_1, -oopSize));
10610 jcc(Assembler::equal, push);
10611
10612 // Check header for monitor (0b10).
10613 testptr(reg_rax, markWord::monitor_value);
10614 jcc(Assembler::notZero, slow);
10615
10616 // Try to lock. Transition lock bits 0b01 => 0b00
10617 movptr(tmp, reg_rax);
10618 andptr(tmp, ~(int32_t)markWord::unlocked_value);
10619 orptr(reg_rax, markWord::unlocked_value);
10620 // Mask inline_type bit such that we go to the slow path if object is an inline type
10621 andptr(reg_rax, ~((int) markWord::inline_type_bit_in_place));
10622
10623 lock(); cmpxchgptr(tmp, Address(obj, oopDesc::mark_offset_in_bytes()));
10624 jcc(Assembler::notEqual, slow);
10625
10626 // Restore top, CAS clobbers register.
10627 movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10628
10629 bind(push);
10630 // After successful lock, push object on lock-stack.
10631 movptr(Address(thread, top), obj);
10632 incrementl(top, oopSize);
10633 movl(Address(thread, JavaThread::lock_stack_top_offset()), top);
10634 }
10635
10636 // Implements fast-unlocking.
10637 //
10638 // obj: the object to be unlocked
10639 // reg_rax: rax
10640 // thread: the thread
10641 // tmp: a temporary register
10642 void MacroAssembler::fast_unlock(Register obj, Register reg_rax, Register tmp, Label& slow) {
|