Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_MacroAssembler.hpp"26#include "c1/c1_Runtime1.hpp"27#include "classfile/systemDictionary.hpp"28#include "gc_interface/collectedHeap.hpp"29#include "interpreter/interpreter.hpp"30#include "oops/arrayOop.hpp"31#include "oops/markOop.hpp"32#include "runtime/basicLock.hpp"33#include "runtime/biasedLocking.hpp"34#include "runtime/os.hpp"35#include "runtime/stubRoutines.hpp"3637void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {38Label L;39const Register temp_reg = G3_scratch;40// Note: needs more testing of out-of-line vs. inline slow case41verify_oop(receiver);42load_klass(receiver, temp_reg);43cmp_and_brx_short(temp_reg, iCache, Assembler::equal, Assembler::pt, L);44AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());45jump_to(ic_miss, temp_reg);46delayed()->nop();47align(CodeEntryAlignment);48bind(L);49}505152void C1_MacroAssembler::explicit_null_check(Register base) {53Unimplemented();54}555657void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {58assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");59generate_stack_overflow_check(bang_size_in_bytes);60// Create the frame.61save_frame_c1(frame_size_in_bytes);62}636465void C1_MacroAssembler::unverified_entry(Register receiver, Register ic_klass) {66if (C1Breakpoint) breakpoint_trap();67inline_cache_check(receiver, ic_klass);68}697071void C1_MacroAssembler::verified_entry() {72if (C1Breakpoint) breakpoint_trap();73// build frame74verify_FPU(0, "method_entry");75}767778void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case) {79assert_different_registers(Rmark, Roop, Rbox, Rscratch);8081Label done;8283Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());8485// The following move must be the first instruction of emitted since debug86// information may be generated for it.87// Load object header88ld_ptr(mark_addr, Rmark);8990verify_oop(Roop);9192// save object being locked into the BasicObjectLock93st_ptr(Roop, Rbox, BasicObjectLock::obj_offset_in_bytes());9495if (UseBiasedLocking) {96biased_locking_enter(Roop, Rmark, Rscratch, done, &slow_case);97}9899// Save Rbox in Rscratch to be used for the cas operation100mov(Rbox, Rscratch);101102// and mark it unlocked103or3(Rmark, markOopDesc::unlocked_value, Rmark);104105// save unlocked object header into the displaced header location on the stack106st_ptr(Rmark, Rbox, BasicLock::displaced_header_offset_in_bytes());107108// compare object markOop with Rmark and if equal exchange Rscratch with object markOop109assert(mark_addr.disp() == 0, "cas must take a zero displacement");110cas_ptr(mark_addr.base(), Rmark, Rscratch);111// if compare/exchange succeeded we found an unlocked object and we now have locked it112// hence we are done113cmp(Rmark, Rscratch);114brx(Assembler::equal, false, Assembler::pt, done);115delayed()->sub(Rscratch, SP, Rscratch); //pull next instruction into delay slot116// we did not find an unlocked object so see if this is a recursive case117// sub(Rscratch, SP, Rscratch);118assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");119andcc(Rscratch, 0xfffff003, Rscratch);120brx(Assembler::notZero, false, Assembler::pn, slow_case);121delayed()->st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes());122bind(done);123}124125126void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {127assert_different_registers(Rmark, Roop, Rbox);128129Label done;130131Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());132assert(mark_addr.disp() == 0, "cas must take a zero displacement");133134if (UseBiasedLocking) {135// load the object out of the BasicObjectLock136ld_ptr(Rbox, BasicObjectLock::obj_offset_in_bytes(), Roop);137verify_oop(Roop);138biased_locking_exit(mark_addr, Rmark, done);139}140// Test first it it is a fast recursive unlock141ld_ptr(Rbox, BasicLock::displaced_header_offset_in_bytes(), Rmark);142br_null_short(Rmark, Assembler::pt, done);143if (!UseBiasedLocking) {144// load object145ld_ptr(Rbox, BasicObjectLock::obj_offset_in_bytes(), Roop);146verify_oop(Roop);147}148149// Check if it is still a light weight lock, this is is true if we see150// the stack address of the basicLock in the markOop of the object151cas_ptr(mark_addr.base(), Rbox, Rmark);152cmp(Rbox, Rmark);153154brx(Assembler::notEqual, false, Assembler::pn, slow_case);155delayed()->nop();156// Done157bind(done);158}159160161void C1_MacroAssembler::try_allocate(162Register obj, // result: pointer to object after successful allocation163Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise164int con_size_in_bytes, // object size in bytes if known at compile time165Register t1, // temp register, must be global register for incr_allocated_bytes166Register t2, // temp register167Label& slow_case // continuation point if fast allocation fails168) {169RegisterOrConstant size_in_bytes = var_size_in_bytes->is_valid()170? RegisterOrConstant(var_size_in_bytes) : RegisterOrConstant(con_size_in_bytes);171if (UseTLAB) {172tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);173} else {174eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);175incr_allocated_bytes(size_in_bytes, t1, t2);176}177}178179180void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {181assert_different_registers(obj, klass, len, t1, t2);182if (UseBiasedLocking && !len->is_valid()) {183ld_ptr(klass, in_bytes(Klass::prototype_header_offset()), t1);184} else {185set((intx)markOopDesc::prototype(), t1);186}187st_ptr(t1, obj, oopDesc::mark_offset_in_bytes());188if (UseCompressedClassPointers) {189// Save klass190mov(klass, t1);191encode_klass_not_null(t1);192stw(t1, obj, oopDesc::klass_offset_in_bytes());193} else {194st_ptr(klass, obj, oopDesc::klass_offset_in_bytes());195}196if (len->is_valid()) {197st(len, obj, arrayOopDesc::length_offset_in_bytes());198} else if (UseCompressedClassPointers) {199// otherwise length is in the class gap200store_klass_gap(G0, obj);201}202}203204205void C1_MacroAssembler::initialize_body(Register base, Register index) {206assert_different_registers(base, index);207Label loop;208bind(loop);209subcc(index, HeapWordSize, index);210brx(Assembler::greaterEqual, true, Assembler::pt, loop);211delayed()->st_ptr(G0, base, index);212}213214215void C1_MacroAssembler::allocate_object(216Register obj, // result: pointer to object after successful allocation217Register t1, // temp register218Register t2, // temp register, must be a global register for try_allocate219Register t3, // temp register220int hdr_size, // object header size in words221int obj_size, // object size in words222Register klass, // object klass223Label& slow_case // continuation point if fast allocation fails224) {225assert_different_registers(obj, t1, t2, t3, klass);226assert(klass == G5, "must be G5");227228// allocate space & initialize header229if (!is_simm13(obj_size * wordSize)) {230// would need to use extra register to load231// object size => go the slow case for now232ba(slow_case);233delayed()->nop();234return;235}236try_allocate(obj, noreg, obj_size * wordSize, t2, t3, slow_case);237238initialize_object(obj, klass, noreg, obj_size * HeapWordSize, t1, t2);239}240241void C1_MacroAssembler::initialize_object(242Register obj, // result: pointer to object after successful allocation243Register klass, // object klass244Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise245int con_size_in_bytes, // object size in bytes if known at compile time246Register t1, // temp register247Register t2 // temp register248) {249const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;250251initialize_header(obj, klass, noreg, t1, t2);252253#ifdef ASSERT254{255Label ok;256ld(klass, in_bytes(Klass::layout_helper_offset()), t1);257if (var_size_in_bytes != noreg) {258cmp_and_brx_short(t1, var_size_in_bytes, Assembler::equal, Assembler::pt, ok);259} else {260cmp_and_brx_short(t1, con_size_in_bytes, Assembler::equal, Assembler::pt, ok);261}262stop("bad size in initialize_object");263should_not_reach_here();264265bind(ok);266}267268#endif269270// initialize body271const int threshold = 5 * HeapWordSize; // approximate break even point for code size272if (var_size_in_bytes != noreg) {273// use a loop274add(obj, hdr_size_in_bytes, t1); // compute address of first element275sub(var_size_in_bytes, hdr_size_in_bytes, t2); // compute size of body276initialize_body(t1, t2);277#ifndef _LP64278} else if (con_size_in_bytes < threshold * 2) {279// on v9 we can do double word stores to fill twice as much space.280assert(hdr_size_in_bytes % 8 == 0, "double word aligned");281assert(con_size_in_bytes % 8 == 0, "double word aligned");282for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += 2 * HeapWordSize) stx(G0, obj, i);283#endif284} else if (con_size_in_bytes <= threshold) {285// use explicit NULL stores286for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += HeapWordSize) st_ptr(G0, obj, i);287} else if (con_size_in_bytes > hdr_size_in_bytes) {288// use a loop289const Register base = t1;290const Register index = t2;291add(obj, hdr_size_in_bytes, base); // compute address of first element292// compute index = number of words to clear293set(con_size_in_bytes - hdr_size_in_bytes, index);294initialize_body(base, index);295}296297if (CURRENT_ENV->dtrace_alloc_probes()) {298assert(obj == O0, "must be");299call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),300relocInfo::runtime_call_type);301delayed()->nop();302}303304verify_oop(obj);305}306307308void C1_MacroAssembler::allocate_array(309Register obj, // result: pointer to array after successful allocation310Register len, // array length311Register t1, // temp register312Register t2, // temp register313Register t3, // temp register314int hdr_size, // object header size in words315int elt_size, // element size in bytes316Register klass, // object klass317Label& slow_case // continuation point if fast allocation fails318) {319assert_different_registers(obj, len, t1, t2, t3, klass);320assert(klass == G5, "must be G5");321assert(t1 == G1, "must be G1");322323// determine alignment mask324assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");325326// check for negative or excessive length327// note: the maximum length allowed is chosen so that arrays of any328// element size with this length are always smaller or equal329// to the largest integer (i.e., array size computation will330// not overflow)331set(max_array_allocation_length, t1);332cmp(len, t1);333br(Assembler::greaterUnsigned, false, Assembler::pn, slow_case);334335// compute array size336// note: if 0 <= len <= max_length, len*elt_size + header + alignment is337// smaller or equal to the largest integer; also, since top is always338// aligned, we can do the alignment here instead of at the end address339// computation340const Register arr_size = t1;341switch (elt_size) {342case 1: delayed()->mov(len, arr_size); break;343case 2: delayed()->sll(len, 1, arr_size); break;344case 4: delayed()->sll(len, 2, arr_size); break;345case 8: delayed()->sll(len, 3, arr_size); break;346default: ShouldNotReachHere();347}348add(arr_size, hdr_size * wordSize + MinObjAlignmentInBytesMask, arr_size); // add space for header & alignment349and3(arr_size, ~MinObjAlignmentInBytesMask, arr_size); // align array size350351// allocate space & initialize header352if (UseTLAB) {353tlab_allocate(obj, arr_size, 0, t2, slow_case);354} else {355eden_allocate(obj, arr_size, 0, t2, t3, slow_case);356}357initialize_header(obj, klass, len, t2, t3);358359// initialize body360const Register base = t2;361const Register index = t3;362add(obj, hdr_size * wordSize, base); // compute address of first element363sub(arr_size, hdr_size * wordSize, index); // compute index = number of words to clear364initialize_body(base, index);365366if (CURRENT_ENV->dtrace_alloc_probes()) {367assert(obj == O0, "must be");368call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),369relocInfo::runtime_call_type);370delayed()->nop();371}372373verify_oop(obj);374}375376377#ifndef PRODUCT378379void C1_MacroAssembler::verify_stack_oop(int stack_offset) {380if (!VerifyOops) return;381verify_oop_addr(Address(SP, stack_offset + STACK_BIAS));382}383384void C1_MacroAssembler::verify_not_null_oop(Register r) {385Label not_null;386br_notnull_short(r, Assembler::pt, not_null);387stop("non-null oop required");388bind(not_null);389if (!VerifyOops) return;390verify_oop(r);391}392393void C1_MacroAssembler::invalidate_registers(bool iregisters, bool lregisters, bool oregisters,394Register preserve1, Register preserve2) {395if (iregisters) {396for (int i = 0; i < 6; i++) {397Register r = as_iRegister(i);398if (r != preserve1 && r != preserve2) set(0xdead, r);399}400}401if (oregisters) {402for (int i = 0; i < 6; i++) {403Register r = as_oRegister(i);404if (r != preserve1 && r != preserve2) set(0xdead, r);405}406}407if (lregisters) {408for (int i = 0; i < 8; i++) {409Register r = as_lRegister(i);410if (r != preserve1 && r != preserve2) set(0xdead, r);411}412}413}414415416#endif417418419