Path: blob/master/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
40930 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2018 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "c1/c1_MacroAssembler.hpp"28#include "c1/c1_Runtime1.hpp"29#include "gc/shared/collectedHeap.hpp"30#include "gc/shared/tlab_globals.hpp"31#include "interpreter/interpreter.hpp"32#include "oops/arrayOop.hpp"33#include "oops/markWord.hpp"34#include "runtime/basicLock.hpp"35#include "runtime/biasedLocking.hpp"36#include "runtime/os.hpp"37#include "runtime/sharedRuntime.hpp"38#include "runtime/stubRoutines.hpp"39#include "utilities/align.hpp"40#include "utilities/powerOfTwo.hpp"4142void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {43const Register temp_reg = R12_scratch2;44Label Lmiss;4546verify_oop(receiver, FILE_AND_LINE);47MacroAssembler::null_check(receiver, oopDesc::klass_offset_in_bytes(), &Lmiss);48load_klass(temp_reg, receiver);4950if (TrapBasedICMissChecks && TrapBasedNullChecks) {51trap_ic_miss_check(temp_reg, iCache);52} else {53Label Lok;54cmpd(CCR0, temp_reg, iCache);55beq(CCR0, Lok);56bind(Lmiss);57//load_const_optimized(temp_reg, SharedRuntime::get_ic_miss_stub(), R0);58calculate_address_from_global_toc(temp_reg, SharedRuntime::get_ic_miss_stub(), true, true, false);59mtctr(temp_reg);60bctr();61align(32, 12);62bind(Lok);63}64}656667void C1_MacroAssembler::explicit_null_check(Register base) {68Unimplemented();69}707172void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {73// Avoid stack bang as first instruction. It may get overwritten by patch_verified_entry.74const Register return_pc = R20;75mflr(return_pc);7677// Make sure there is enough stack space for this method's activation.78assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");79generate_stack_overflow_check(bang_size_in_bytes);8081std(return_pc, _abi0(lr), R1_SP); // SP->lr = return_pc82push_frame(frame_size_in_bytes, R0); // SP -= frame_size_in_bytes8384BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();85bs->nmethod_entry_barrier(this, R20);86}878889void C1_MacroAssembler::verified_entry() {90if (C1Breakpoint) illtrap();91// build frame92}939495void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case) {96assert_different_registers(Rmark, Roop, Rbox, Rscratch);9798Label done, cas_failed, slow_int;99100// The following move must be the first instruction of emitted since debug101// information may be generated for it.102// Load object header.103ld(Rmark, oopDesc::mark_offset_in_bytes(), Roop);104105verify_oop(Roop, FILE_AND_LINE);106107// Save object being locked into the BasicObjectLock...108std(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);109110if (DiagnoseSyncOnValueBasedClasses != 0) {111load_klass(Rscratch, Roop);112lwz(Rscratch, in_bytes(Klass::access_flags_offset()), Rscratch);113testbitdi(CCR0, R0, Rscratch, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));114bne(CCR0, slow_int);115}116117if (UseBiasedLocking) {118biased_locking_enter(CCR0, Roop, Rmark, Rscratch, R0, done, &slow_int);119}120121// ... and mark it unlocked.122ori(Rmark, Rmark, markWord::unlocked_value);123124// Save unlocked object header into the displaced header location on the stack.125std(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);126127// Compare object markWord with Rmark and if equal exchange Rscratch with object markWord.128assert(oopDesc::mark_offset_in_bytes() == 0, "cas must take a zero displacement");129cmpxchgd(/*flag=*/CCR0,130/*current_value=*/Rscratch,131/*compare_value=*/Rmark,132/*exchange_value=*/Rbox,133/*where=*/Roop/*+0==mark_offset_in_bytes*/,134MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq,135MacroAssembler::cmpxchgx_hint_acquire_lock(),136noreg,137&cas_failed,138/*check without membar and ldarx first*/true);139// If compare/exchange succeeded we found an unlocked object and we now have locked it140// hence we are done.141b(done);142143bind(slow_int);144b(slow_case); // far145146bind(cas_failed);147// We did not find an unlocked object so see if this is a recursive case.148sub(Rscratch, Rscratch, R1_SP);149load_const_optimized(R0, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));150and_(R0/*==0?*/, Rscratch, R0);151std(R0/*==0, perhaps*/, BasicLock::displaced_header_offset_in_bytes(), Rbox);152bne(CCR0, slow_int);153154bind(done);155}156157158void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {159assert_different_registers(Rmark, Roop, Rbox);160161Label slow_int, done;162163Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());164assert(mark_addr.disp() == 0, "cas must take a zero displacement");165166if (UseBiasedLocking) {167// Load the object out of the BasicObjectLock.168ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);169verify_oop(Roop, FILE_AND_LINE);170biased_locking_exit(CCR0, Roop, R0, done);171}172// Test first it it is a fast recursive unlock.173ld(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);174cmpdi(CCR0, Rmark, 0);175beq(CCR0, done);176if (!UseBiasedLocking) {177// Load object.178ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);179verify_oop(Roop, FILE_AND_LINE);180}181182// Check if it is still a light weight lock, this is is true if we see183// the stack address of the basicLock in the markWord of the object.184cmpxchgd(/*flag=*/CCR0,185/*current_value=*/R0,186/*compare_value=*/Rbox,187/*exchange_value=*/Rmark,188/*where=*/Roop,189MacroAssembler::MemBarRel,190MacroAssembler::cmpxchgx_hint_release_lock(),191noreg,192&slow_int);193b(done);194bind(slow_int);195b(slow_case); // far196197// Done198bind(done);199}200201202void C1_MacroAssembler::try_allocate(203Register obj, // result: pointer to object after successful allocation204Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise205int con_size_in_bytes, // object size in bytes if known at compile time206Register t1, // temp register, must be global register for incr_allocated_bytes207Register t2, // temp register208Label& slow_case // continuation point if fast allocation fails209) {210if (UseTLAB) {211tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);212} else {213eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);214RegisterOrConstant size_in_bytes = var_size_in_bytes->is_valid()215? RegisterOrConstant(var_size_in_bytes)216: RegisterOrConstant(con_size_in_bytes);217incr_allocated_bytes(size_in_bytes, t1, t2);218}219}220221222void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {223assert_different_registers(obj, klass, len, t1, t2);224if (UseBiasedLocking && !len->is_valid()) {225ld(t1, in_bytes(Klass::prototype_header_offset()), klass);226} else {227load_const_optimized(t1, (intx)markWord::prototype().value());228}229std(t1, oopDesc::mark_offset_in_bytes(), obj);230store_klass(obj, klass);231if (len->is_valid()) {232stw(len, arrayOopDesc::length_offset_in_bytes(), obj);233} else if (UseCompressedClassPointers) {234// Otherwise length is in the class gap.235store_klass_gap(obj);236}237}238239240void C1_MacroAssembler::initialize_body(Register base, Register index) {241assert_different_registers(base, index);242srdi(index, index, LogBytesPerWord);243clear_memory_doubleword(base, index);244}245246void C1_MacroAssembler::initialize_body(Register obj, Register tmp1, Register tmp2,247int obj_size_in_bytes, int hdr_size_in_bytes) {248const int index = (obj_size_in_bytes - hdr_size_in_bytes) / HeapWordSize;249250// 2x unrolled loop is shorter with more than 9 HeapWords.251if (index <= 9) {252clear_memory_unrolled(obj, index, R0, hdr_size_in_bytes);253} else {254const Register base_ptr = tmp1,255cnt_dwords = tmp2;256257addi(base_ptr, obj, hdr_size_in_bytes); // Compute address of first element.258clear_memory_doubleword(base_ptr, cnt_dwords, R0, index);259}260}261262void C1_MacroAssembler::allocate_object(263Register obj, // result: pointer to object after successful allocation264Register t1, // temp register265Register t2, // temp register266Register t3, // temp register267int hdr_size, // object header size in words268int obj_size, // object size in words269Register klass, // object klass270Label& slow_case // continuation point if fast allocation fails271) {272assert_different_registers(obj, t1, t2, t3, klass);273274// allocate space & initialize header275if (!is_simm16(obj_size * wordSize)) {276// Would need to use extra register to load277// object size => go the slow case for now.278b(slow_case);279return;280}281try_allocate(obj, noreg, obj_size * wordSize, t2, t3, slow_case);282283initialize_object(obj, klass, noreg, obj_size * HeapWordSize, t1, t2);284}285286void C1_MacroAssembler::initialize_object(287Register obj, // result: pointer to object after successful allocation288Register klass, // object klass289Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise290int con_size_in_bytes, // object size in bytes if known at compile time291Register t1, // temp register292Register t2 // temp register293) {294const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;295296initialize_header(obj, klass, noreg, t1, t2);297298#ifdef ASSERT299{300lwz(t1, in_bytes(Klass::layout_helper_offset()), klass);301if (var_size_in_bytes != noreg) {302cmpw(CCR0, t1, var_size_in_bytes);303} else {304cmpwi(CCR0, t1, con_size_in_bytes);305}306asm_assert_eq("bad size in initialize_object");307}308#endif309310// Initialize body.311if (var_size_in_bytes != noreg) {312// Use a loop.313addi(t1, obj, hdr_size_in_bytes); // Compute address of first element.314addi(t2, var_size_in_bytes, -hdr_size_in_bytes); // Compute size of body.315initialize_body(t1, t2);316} else if (con_size_in_bytes > hdr_size_in_bytes) {317// Use a loop.318initialize_body(obj, t1, t2, con_size_in_bytes, hdr_size_in_bytes);319}320321if (CURRENT_ENV->dtrace_alloc_probes()) {322Unimplemented();323// assert(obj == O0, "must be");324// call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),325// relocInfo::runtime_call_type);326}327328verify_oop(obj, FILE_AND_LINE);329}330331332void C1_MacroAssembler::allocate_array(333Register obj, // result: pointer to array after successful allocation334Register len, // array length335Register t1, // temp register336Register t2, // temp register337Register t3, // temp register338int hdr_size, // object header size in words339int elt_size, // element size in bytes340Register klass, // object klass341Label& slow_case // continuation point if fast allocation fails342) {343assert_different_registers(obj, len, t1, t2, t3, klass);344345// Determine alignment mask.346assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");347int log2_elt_size = exact_log2(elt_size);348349// Check for negative or excessive length.350size_t max_length = max_array_allocation_length >> log2_elt_size;351if (UseTLAB) {352size_t max_tlab = align_up(ThreadLocalAllocBuffer::max_size() >> log2_elt_size, 64*K);353if (max_tlab < max_length) { max_length = max_tlab; }354}355load_const_optimized(t1, max_length);356cmpld(CCR0, len, t1);357bc_far_optimized(Assembler::bcondCRbiIs1, bi0(CCR0, Assembler::greater), slow_case);358359// compute array size360// note: If 0 <= len <= max_length, len*elt_size + header + alignment is361// smaller or equal to the largest integer; also, since top is always362// aligned, we can do the alignment here instead of at the end address363// computation.364const Register arr_size = t1;365Register arr_len_in_bytes = len;366if (elt_size != 1) {367sldi(t1, len, log2_elt_size);368arr_len_in_bytes = t1;369}370addi(arr_size, arr_len_in_bytes, hdr_size * wordSize + MinObjAlignmentInBytesMask); // Add space for header & alignment.371clrrdi(arr_size, arr_size, LogMinObjAlignmentInBytes); // Align array size.372373// Allocate space & initialize header.374if (UseTLAB) {375tlab_allocate(obj, arr_size, 0, t2, slow_case);376} else {377eden_allocate(obj, arr_size, 0, t2, t3, slow_case);378}379initialize_header(obj, klass, len, t2, t3);380381// Initialize body.382const Register base = t2;383const Register index = t3;384addi(base, obj, hdr_size * wordSize); // compute address of first element385addi(index, arr_size, -(hdr_size * wordSize)); // compute index = number of bytes to clear386initialize_body(base, index);387388if (CURRENT_ENV->dtrace_alloc_probes()) {389Unimplemented();390//assert(obj == O0, "must be");391//call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),392// relocInfo::runtime_call_type);393}394395verify_oop(obj, FILE_AND_LINE);396}397398399#ifndef PRODUCT400401void C1_MacroAssembler::verify_stack_oop(int stack_offset) {402verify_oop_addr((RegisterOrConstant)stack_offset, R1_SP, "broken oop in stack slot");403}404405void C1_MacroAssembler::verify_not_null_oop(Register r) {406Label not_null;407cmpdi(CCR0, r, 0);408bne(CCR0, not_null);409stop("non-null oop required");410bind(not_null);411verify_oop(r, FILE_AND_LINE);412}413414#endif // PRODUCT415416void C1_MacroAssembler::null_check(Register r, Label* Lnull) {417if (TrapBasedNullChecks) { // SIGTRAP based418trap_null_check(r);419} else { // explicit420//const address exception_entry = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);421assert(Lnull != NULL, "must have Label for explicit check");422cmpdi(CCR0, r, 0);423bc_far_optimized(Assembler::bcondCRbiIs1, bi0(CCR0, Assembler::equal), *Lnull);424}425}426427address C1_MacroAssembler::call_c_with_frame_resize(address dest, int frame_resize) {428if (frame_resize) { resize_frame(-frame_resize, R0); }429#if defined(ABI_ELFv2)430address return_pc = call_c(dest, relocInfo::runtime_call_type);431#else432address return_pc = call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, dest), relocInfo::runtime_call_type);433#endif434if (frame_resize) { resize_frame(frame_resize, R0); }435return return_pc;436}437438439