Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/cpu/aarch64/vm/c1_LIRGenerator_aarch64.cpp
83402 views
/*1* Copyright (c) 2013, Red Hat Inc.2* Copyright (c) 2005, 2019, Oracle and/or its affiliates.3* All rights reserved.4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5*6* This code is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License version 2 only, as8* published by the Free Software Foundation.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*24*/2526#include "precompiled.hpp"27#include "c1/c1_Compilation.hpp"28#include "c1/c1_FrameMap.hpp"29#include "c1/c1_Instruction.hpp"30#include "c1/c1_LIRAssembler.hpp"31#include "c1/c1_LIRGenerator.hpp"32#include "c1/c1_Runtime1.hpp"33#include "c1/c1_ValueStack.hpp"34#include "ci/ciArray.hpp"35#include "ci/ciObjArrayKlass.hpp"36#include "ci/ciTypeArrayKlass.hpp"37#include "runtime/sharedRuntime.hpp"38#include "runtime/stubRoutines.hpp"39#include "vmreg_aarch64.inline.hpp"4041#ifdef ASSERT42#define __ gen()->lir(__FILE__, __LINE__)->43#else44#define __ gen()->lir()->45#endif4647// Item will be loaded into a byte register; Intel only48void LIRItem::load_byte_item() {49load_item();50}515253void LIRItem::load_nonconstant() {54LIR_Opr r = value()->operand();55if (r->is_constant()) {56_result = r;57} else {58load_item();59}60}6162//--------------------------------------------------------------63// LIRGenerator64//--------------------------------------------------------------656667LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::r0_oop_opr; }68LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::r3_opr; }69LIR_Opr LIRGenerator::divInOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }70LIR_Opr LIRGenerator::divOutOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }71LIR_Opr LIRGenerator::remOutOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }72LIR_Opr LIRGenerator::shiftCountOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }73LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::r0_opr; }74LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }757677LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {78LIR_Opr opr;79switch (type->tag()) {80case intTag: opr = FrameMap::r0_opr; break;81case objectTag: opr = FrameMap::r0_oop_opr; break;82case longTag: opr = FrameMap::long0_opr; break;83case floatTag: opr = FrameMap::fpu0_float_opr; break;84case doubleTag: opr = FrameMap::fpu0_double_opr; break;8586case addressTag:87default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;88}8990assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");91return opr;92}939495LIR_Opr LIRGenerator::rlock_byte(BasicType type) {96LIR_Opr reg = new_register(T_INT);97set_vreg_flag(reg, LIRGenerator::byte_reg);98return reg;99}100101102//--------- loading items into registers --------------------------------103104105bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {106if (v->type()->as_IntConstant() != NULL) {107return v->type()->as_IntConstant()->value() == 0L;108} else if (v->type()->as_LongConstant() != NULL) {109return v->type()->as_LongConstant()->value() == 0L;110} else if (v->type()->as_ObjectConstant() != NULL) {111return v->type()->as_ObjectConstant()->value()->is_null_object();112} else {113return false;114}115}116117bool LIRGenerator::can_inline_as_constant(Value v) const {118// FIXME: Just a guess119if (v->type()->as_IntConstant() != NULL) {120return Assembler::operand_valid_for_add_sub_immediate(v->type()->as_IntConstant()->value());121} else if (v->type()->as_LongConstant() != NULL) {122return v->type()->as_LongConstant()->value() == 0L;123} else if (v->type()->as_ObjectConstant() != NULL) {124return v->type()->as_ObjectConstant()->value()->is_null_object();125} else {126return false;127}128}129130131bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const { return false; }132133134LIR_Opr LIRGenerator::safepoint_poll_register() {135return LIR_OprFact::illegalOpr;136}137138139LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,140int shift, int disp, BasicType type) {141assert(base->is_register(), "must be");142143// accumulate fixed displacements144if (index->is_constant()) {145disp += index->as_constant_ptr()->as_jint() << shift;146index = LIR_OprFact::illegalOpr;147}148149if (index->is_register()) {150// apply the shift and accumulate the displacement151if (shift > 0) {152LIR_Opr tmp = new_pointer_register();153__ shift_left(index, shift, tmp);154index = tmp;155}156if (disp != 0) {157LIR_Opr tmp = new_pointer_register();158if (Assembler::operand_valid_for_add_sub_immediate(disp)) {159__ add(tmp, tmp, LIR_OprFact::intptrConst(disp));160index = tmp;161} else {162__ move(tmp, LIR_OprFact::intptrConst(disp));163__ add(tmp, index, tmp);164index = tmp;165}166disp = 0;167}168} else if (disp != 0 && !Address::offset_ok_for_immed(disp, shift)) {169// index is illegal so replace it with the displacement loaded into a register170index = new_pointer_register();171__ move(LIR_OprFact::intptrConst(disp), index);172disp = 0;173}174175// at this point we either have base + index or base + displacement176if (disp == 0) {177return new LIR_Address(base, index, type);178} else {179assert(Address::offset_ok_for_immed(disp, 0), "must be");180return new LIR_Address(base, disp, type);181}182}183184185LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,186BasicType type, bool needs_card_mark) {187int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);188int elem_size = type2aelembytes(type);189int shift = exact_log2(elem_size);190191LIR_Address* addr;192if (index_opr->is_constant()) {193addr = new LIR_Address(array_opr,194offset_in_bytes + index_opr->as_jint() * elem_size, type);195} else {196// #ifdef _LP64197// if (index_opr->type() == T_INT) {198// LIR_Opr tmp = new_register(T_LONG);199// __ convert(Bytecodes::_i2l, index_opr, tmp);200// index_opr = tmp;201// }202// #endif203if (offset_in_bytes) {204LIR_Opr tmp = new_pointer_register();205__ add(array_opr, LIR_OprFact::intConst(offset_in_bytes), tmp);206array_opr = tmp;207offset_in_bytes = 0;208}209addr = new LIR_Address(array_opr,210index_opr,211LIR_Address::scale(type),212offset_in_bytes, type);213}214if (needs_card_mark) {215// This store will need a precise card mark, so go ahead and216// compute the full adddres instead of computing once for the217// store and again for the card mark.218LIR_Opr tmp = new_pointer_register();219__ leal(LIR_OprFact::address(addr), tmp);220return new LIR_Address(tmp, type);221} else {222return addr;223}224}225226LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {227LIR_Opr r;228if (type == T_LONG) {229r = LIR_OprFact::longConst(x);230if (!Assembler::operand_valid_for_logical_immediate(false, x)) {231LIR_Opr tmp = new_register(type);232__ move(r, tmp);233return tmp;234}235} else if (type == T_INT) {236r = LIR_OprFact::intConst(x);237if (!Assembler::operand_valid_for_logical_immediate(true, x)) {238// This is all rather nasty. We don't know whether our constant239// is required for a logical or an arithmetic operation, wo we240// don't know what the range of valid values is!!241LIR_Opr tmp = new_register(type);242__ move(r, tmp);243return tmp;244}245} else {246ShouldNotReachHere();247}248return r;249}250251252253void LIRGenerator::increment_counter(address counter, BasicType type, int step) {254LIR_Opr pointer = new_pointer_register();255__ move(LIR_OprFact::intptrConst(counter), pointer);256LIR_Address* addr = new LIR_Address(pointer, type);257increment_counter(addr, step);258}259260261void LIRGenerator::increment_counter(LIR_Address* addr, int step) {262LIR_Opr imm = NULL;263switch(addr->type()) {264case T_INT:265imm = LIR_OprFact::intConst(step);266break;267case T_LONG:268imm = LIR_OprFact::longConst(step);269break;270default:271ShouldNotReachHere();272}273LIR_Opr reg = new_register(addr->type());274__ load(addr, reg);275__ add(reg, imm, reg);276__ store(reg, addr);277}278279void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {280LIR_Opr reg = new_register(T_INT);281__ load(generate_address(base, disp, T_INT), reg, info);282__ cmp(condition, reg, LIR_OprFact::intConst(c));283}284285void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {286LIR_Opr reg1 = new_register(T_INT);287__ load(generate_address(base, disp, type), reg1, info);288__ cmp(condition, reg, reg1);289}290291292bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {293294if (is_power_of_2(c - 1)) {295__ shift_left(left, exact_log2(c - 1), tmp);296__ add(tmp, left, result);297return true;298} else if (is_power_of_2(c + 1)) {299__ shift_left(left, exact_log2(c + 1), tmp);300__ sub(tmp, left, result);301return true;302} else {303return false;304}305}306307void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {308BasicType type = item->type();309__ store(item, new LIR_Address(FrameMap::sp_opr, in_bytes(offset_from_sp), type));310}311312//----------------------------------------------------------------------313// visitor functions314//----------------------------------------------------------------------315316317void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {318assert(x->is_pinned(),"");319bool needs_range_check = x->compute_needs_range_check();320bool use_length = x->length() != NULL;321bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;322bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||323!get_jobject_constant(x->value())->is_null_object() ||324x->should_profile());325326LIRItem array(x->array(), this);327LIRItem index(x->index(), this);328LIRItem value(x->value(), this);329LIRItem length(this);330331array.load_item();332index.load_nonconstant();333334if (use_length && needs_range_check) {335length.set_instruction(x->length());336length.load_item();337338}339if (needs_store_check || x->check_boolean()) {340value.load_item();341} else {342value.load_for_store(x->elt_type());343}344345set_no_result(x);346347// the CodeEmitInfo must be duplicated for each different348// LIR-instruction because spilling can occur anywhere between two349// instructions and so the debug information must be different350CodeEmitInfo* range_check_info = state_for(x);351CodeEmitInfo* null_check_info = NULL;352if (x->needs_null_check()) {353null_check_info = new CodeEmitInfo(range_check_info);354}355356// emit array address setup early so it schedules better357// FIXME? No harm in this on aarch64, and it might help358LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);359360if (GenerateRangeChecks && needs_range_check) {361if (use_length) {362__ cmp(lir_cond_belowEqual, length.result(), index.result());363__ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));364} else {365array_range_check(array.result(), index.result(), null_check_info, range_check_info);366// range_check also does the null check367null_check_info = NULL;368}369}370371if (GenerateArrayStoreCheck && needs_store_check) {372LIR_Opr tmp1 = new_register(objectType);373LIR_Opr tmp2 = new_register(objectType);374LIR_Opr tmp3 = new_register(objectType);375376CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);377__ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());378}379380if (obj_store) {381// Needs GC write barriers.382pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,383true /* do_load */, false /* patch */, NULL);384__ move(value.result(), array_addr, null_check_info);385// Seems to be a precise386post_barrier(LIR_OprFact::address(array_addr), value.result());387} else {388LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);389__ move(result, array_addr, null_check_info);390}391}392393void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {394assert(x->is_pinned(),"");395LIRItem obj(x->obj(), this);396obj.load_item();397398set_no_result(x);399400// "lock" stores the address of the monitor stack slot, so this is not an oop401LIR_Opr lock = new_register(T_INT);402// Need a scratch register for biased locking403LIR_Opr scratch = LIR_OprFact::illegalOpr;404if (UseBiasedLocking) {405scratch = new_register(T_INT);406}407408CodeEmitInfo* info_for_exception = NULL;409if (x->needs_null_check()) {410info_for_exception = state_for(x);411}412// this CodeEmitInfo must not have the xhandlers because here the413// object is already locked (xhandlers expect object to be unlocked)414CodeEmitInfo* info = state_for(x, x->state(), true);415monitor_enter(obj.result(), lock, syncTempOpr(), scratch,416x->monitor_no(), info_for_exception, info);417}418419420void LIRGenerator::do_MonitorExit(MonitorExit* x) {421assert(x->is_pinned(),"");422423LIRItem obj(x->obj(), this);424obj.dont_load_item();425426LIR_Opr lock = new_register(T_INT);427LIR_Opr obj_temp = new_register(T_INT);428set_no_result(x);429monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());430}431432433void LIRGenerator::do_NegateOp(NegateOp* x) {434435LIRItem from(x->x(), this);436from.load_item();437LIR_Opr result = rlock_result(x);438__ negate (from.result(), result);439440}441442// for _fadd, _fmul, _fsub, _fdiv, _frem443// _dadd, _dmul, _dsub, _ddiv, _drem444void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {445446if (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem) {447// float remainder is implemented as a direct call into the runtime448LIRItem right(x->x(), this);449LIRItem left(x->y(), this);450451BasicTypeList signature(2);452if (x->op() == Bytecodes::_frem) {453signature.append(T_FLOAT);454signature.append(T_FLOAT);455} else {456signature.append(T_DOUBLE);457signature.append(T_DOUBLE);458}459CallingConvention* cc = frame_map()->c_calling_convention(&signature);460461const LIR_Opr result_reg = result_register_for(x->type());462left.load_item_force(cc->at(1));463right.load_item();464465__ move(right.result(), cc->at(0));466467address entry;468if (x->op() == Bytecodes::_frem) {469entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);470} else {471entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);472}473474LIR_Opr result = rlock_result(x);475__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());476__ move(result_reg, result);477478return;479}480481LIRItem left(x->x(), this);482LIRItem right(x->y(), this);483LIRItem* left_arg = &left;484LIRItem* right_arg = &right;485486// Always load right hand side.487right.load_item();488489if (!left.is_register())490left.load_item();491492LIR_Opr reg = rlock(x);493LIR_Opr tmp = LIR_OprFact::illegalOpr;494if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {495tmp = new_register(T_DOUBLE);496}497498arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp());499500set_result(x, round_item(reg));501}502503// for _ladd, _lmul, _lsub, _ldiv, _lrem504void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {505506// missing test if instr is commutative and if we should swap507LIRItem left(x->x(), this);508LIRItem right(x->y(), this);509510if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {511512// the check for division by zero destroys the right operand513right.set_destroys_register();514515// check for division by zero (destroys registers of right operand!)516CodeEmitInfo* info = state_for(x);517518left.load_item();519right.load_item();520521__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));522__ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));523524rlock_result(x);525switch (x->op()) {526case Bytecodes::_lrem:527__ rem (left.result(), right.result(), x->operand());528break;529case Bytecodes::_ldiv:530__ div (left.result(), right.result(), x->operand());531break;532default:533ShouldNotReachHere();534break;535}536537538} else {539assert (x->op() == Bytecodes::_lmul || x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub,540"expect lmul, ladd or lsub");541// add, sub, mul542left.load_item();543if (! right.is_register()) {544if (x->op() == Bytecodes::_lmul545|| ! right.is_constant()546|| ! Assembler::operand_valid_for_add_sub_immediate(right.get_jlong_constant())) {547right.load_item();548} else { // add, sub549assert (x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub, "expect ladd or lsub");550// don't load constants to save register551right.load_nonconstant();552}553}554rlock_result(x);555arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);556}557}558559// for: _iadd, _imul, _isub, _idiv, _irem560void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {561562// Test if instr is commutative and if we should swap563LIRItem left(x->x(), this);564LIRItem right(x->y(), this);565LIRItem* left_arg = &left;566LIRItem* right_arg = &right;567if (x->is_commutative() && left.is_stack() && right.is_register()) {568// swap them if left is real stack (or cached) and right is real register(not cached)569left_arg = &right;570right_arg = &left;571}572573left_arg->load_item();574575// do not need to load right, as we can handle stack and constants576if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {577578right_arg->load_item();579rlock_result(x);580581CodeEmitInfo* info = state_for(x);582LIR_Opr tmp = new_register(T_INT);583__ cmp(lir_cond_equal, right_arg->result(), LIR_OprFact::longConst(0));584__ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));585info = state_for(x);586587if (x->op() == Bytecodes::_irem) {588__ irem(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);589} else if (x->op() == Bytecodes::_idiv) {590__ idiv(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);591}592593} else if (x->op() == Bytecodes::_iadd || x->op() == Bytecodes::_isub) {594if (right.is_constant()595&& Assembler::operand_valid_for_add_sub_immediate(right.get_jint_constant())) {596right.load_nonconstant();597} else {598right.load_item();599}600rlock_result(x);601arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), LIR_OprFact::illegalOpr);602} else {603assert (x->op() == Bytecodes::_imul, "expect imul");604if (right.is_constant()) {605int c = right.get_jint_constant();606if (! is_power_of_2(c) && ! is_power_of_2(c + 1) && ! is_power_of_2(c - 1)) {607// Cannot use constant op.608right.load_item();609} else {610right.dont_load_item();611}612} else {613right.load_item();614}615rlock_result(x);616arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), new_register(T_INT));617}618}619620void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {621// when an operand with use count 1 is the left operand, then it is622// likely that no move for 2-operand-LIR-form is necessary623if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {624x->swap_operands();625}626627ValueTag tag = x->type()->tag();628assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");629switch (tag) {630case floatTag:631case doubleTag: do_ArithmeticOp_FPU(x); return;632case longTag: do_ArithmeticOp_Long(x); return;633case intTag: do_ArithmeticOp_Int(x); return;634}635ShouldNotReachHere();636}637638// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr639void LIRGenerator::do_ShiftOp(ShiftOp* x) {640641LIRItem left(x->x(), this);642LIRItem right(x->y(), this);643644left.load_item();645646rlock_result(x);647if (right.is_constant()) {648right.dont_load_item();649650switch (x->op()) {651case Bytecodes::_ishl: {652int c = right.get_jint_constant() & 0x1f;653__ shift_left(left.result(), c, x->operand());654break;655}656case Bytecodes::_ishr: {657int c = right.get_jint_constant() & 0x1f;658__ shift_right(left.result(), c, x->operand());659break;660}661case Bytecodes::_iushr: {662int c = right.get_jint_constant() & 0x1f;663__ unsigned_shift_right(left.result(), c, x->operand());664break;665}666case Bytecodes::_lshl: {667int c = right.get_jint_constant() & 0x3f;668__ shift_left(left.result(), c, x->operand());669break;670}671case Bytecodes::_lshr: {672int c = right.get_jint_constant() & 0x3f;673__ shift_right(left.result(), c, x->operand());674break;675}676case Bytecodes::_lushr: {677int c = right.get_jint_constant() & 0x3f;678__ unsigned_shift_right(left.result(), c, x->operand());679break;680}681default:682ShouldNotReachHere();683}684} else {685right.load_item();686LIR_Opr tmp = new_register(T_INT);687switch (x->op()) {688case Bytecodes::_ishl: {689__ logical_and(right.result(), LIR_OprFact::intConst(0x1f), tmp);690__ shift_left(left.result(), tmp, x->operand(), tmp);691break;692}693case Bytecodes::_ishr: {694__ logical_and(right.result(), LIR_OprFact::intConst(0x1f), tmp);695__ shift_right(left.result(), tmp, x->operand(), tmp);696break;697}698case Bytecodes::_iushr: {699__ logical_and(right.result(), LIR_OprFact::intConst(0x1f), tmp);700__ unsigned_shift_right(left.result(), tmp, x->operand(), tmp);701break;702}703case Bytecodes::_lshl: {704__ logical_and(right.result(), LIR_OprFact::intConst(0x3f), tmp);705__ shift_left(left.result(), tmp, x->operand(), tmp);706break;707}708case Bytecodes::_lshr: {709__ logical_and(right.result(), LIR_OprFact::intConst(0x3f), tmp);710__ shift_right(left.result(), tmp, x->operand(), tmp);711break;712}713case Bytecodes::_lushr: {714__ logical_and(right.result(), LIR_OprFact::intConst(0x3f), tmp);715__ unsigned_shift_right(left.result(), tmp, x->operand(), tmp);716break;717}718default:719ShouldNotReachHere();720}721}722}723724// _iand, _land, _ior, _lor, _ixor, _lxor725void LIRGenerator::do_LogicOp(LogicOp* x) {726727LIRItem left(x->x(), this);728LIRItem right(x->y(), this);729730left.load_item();731732rlock_result(x);733if (right.is_constant()734&& ((right.type()->tag() == intTag735&& Assembler::operand_valid_for_logical_immediate(true, right.get_jint_constant()))736|| (right.type()->tag() == longTag737&& Assembler::operand_valid_for_logical_immediate(false, right.get_jlong_constant())))) {738right.dont_load_item();739} else {740right.load_item();741}742switch (x->op()) {743case Bytecodes::_iand:744case Bytecodes::_land:745__ logical_and(left.result(), right.result(), x->operand()); break;746case Bytecodes::_ior:747case Bytecodes::_lor:748__ logical_or (left.result(), right.result(), x->operand()); break;749case Bytecodes::_ixor:750case Bytecodes::_lxor:751__ logical_xor(left.result(), right.result(), x->operand()); break;752default: Unimplemented();753}754}755756// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg757void LIRGenerator::do_CompareOp(CompareOp* x) {758LIRItem left(x->x(), this);759LIRItem right(x->y(), this);760ValueTag tag = x->x()->type()->tag();761if (tag == longTag) {762left.set_destroys_register();763}764left.load_item();765right.load_item();766LIR_Opr reg = rlock_result(x);767768if (x->x()->type()->is_float_kind()) {769Bytecodes::Code code = x->op();770__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));771} else if (x->x()->type()->tag() == longTag) {772__ lcmp2int(left.result(), right.result(), reg);773} else {774Unimplemented();775}776}777778void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {779assert(x->number_of_arguments() == 4, "wrong type");780LIRItem obj (x->argument_at(0), this); // object781LIRItem offset(x->argument_at(1), this); // offset of field782LIRItem cmp (x->argument_at(2), this); // value to compare with field783LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp784785assert(obj.type()->tag() == objectTag, "invalid type");786787// In 64bit the type can be long, sparc doesn't have this assert788// assert(offset.type()->tag() == intTag, "invalid type");789790assert(cmp.type()->tag() == type->tag(), "invalid type");791assert(val.type()->tag() == type->tag(), "invalid type");792793// get address of field794obj.load_item();795offset.load_nonconstant();796val.load_item();797cmp.load_item();798799LIR_Address* a;800if(offset.result()->is_constant()) {801jlong c = offset.result()->as_jlong();802if ((jlong)((jint)c) == c) {803a = new LIR_Address(obj.result(),804(jint)c,805as_BasicType(type));806} else {807LIR_Opr tmp = new_register(T_LONG);808__ move(offset.result(), tmp);809a = new LIR_Address(obj.result(),810tmp,811as_BasicType(type));812}813} else {814a = new LIR_Address(obj.result(),815offset.result(),816LIR_Address::times_1,8170,818as_BasicType(type));819}820LIR_Opr addr = new_pointer_register();821__ leal(LIR_OprFact::address(a), addr);822823if (type == objectType) { // Write-barrier needed for Object fields.824// Do the pre-write barrier, if any.825pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,826true /* do_load */, false /* patch */, NULL);827}828829LIR_Opr result = rlock_result(x);830831LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience832if (type == objectType)833__ cas_obj(addr, cmp.result(), val.result(), new_register(T_INT), new_register(T_INT),834result);835else if (type == intType)836__ cas_int(addr, cmp.result(), val.result(), ill, ill);837else if (type == longType)838__ cas_long(addr, cmp.result(), val.result(), ill, ill);839else {840ShouldNotReachHere();841}842843__ logical_xor(FrameMap::r8_opr, LIR_OprFact::intConst(1), result);844845if (type == objectType) { // Write-barrier needed for Object fields.846// Seems to be precise847post_barrier(addr, val.result());848}849}850851void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {852switch (x->id()) {853case vmIntrinsics::_dabs:854case vmIntrinsics::_dsqrt: {855assert(x->number_of_arguments() == 1, "wrong type");856LIRItem value(x->argument_at(0), this);857value.load_item();858LIR_Opr dst = rlock_result(x);859860switch (x->id()) {861case vmIntrinsics::_dsqrt: {862__ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);863break;864}865case vmIntrinsics::_dabs: {866__ abs(value.result(), dst, LIR_OprFact::illegalOpr);867break;868}869}870break;871}872case vmIntrinsics::_dlog10: // fall through873case vmIntrinsics::_dlog: // fall through874case vmIntrinsics::_dsin: // fall through875case vmIntrinsics::_dtan: // fall through876case vmIntrinsics::_dcos: // fall through877case vmIntrinsics::_dexp: {878assert(x->number_of_arguments() == 1, "wrong type");879880address runtime_entry = NULL;881switch (x->id()) {882case vmIntrinsics::_dsin:883runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);884break;885case vmIntrinsics::_dcos:886runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);887break;888case vmIntrinsics::_dtan:889runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);890break;891case vmIntrinsics::_dlog:892runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);893break;894case vmIntrinsics::_dlog10:895runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);896break;897case vmIntrinsics::_dexp:898runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);899break;900default:901ShouldNotReachHere();902}903904LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);905set_result(x, result);906break;907}908case vmIntrinsics::_dpow: {909assert(x->number_of_arguments() == 2, "wrong type");910address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);911LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);912set_result(x, result);913break;914}915}916}917918919void LIRGenerator::do_ArrayCopy(Intrinsic* x) {920assert(x->number_of_arguments() == 5, "wrong type");921922// Make all state_for calls early since they can emit code923CodeEmitInfo* info = state_for(x, x->state());924925LIRItem src(x->argument_at(0), this);926LIRItem src_pos(x->argument_at(1), this);927LIRItem dst(x->argument_at(2), this);928LIRItem dst_pos(x->argument_at(3), this);929LIRItem length(x->argument_at(4), this);930931// operands for arraycopy must use fixed registers, otherwise932// LinearScan will fail allocation (because arraycopy always needs a933// call)934935// The java calling convention will give us enough registers936// so that on the stub side the args will be perfect already.937// On the other slow/special case side we call C and the arg938// positions are not similar enough to pick one as the best.939// Also because the java calling convention is a "shifted" version940// of the C convention we can process the java args trivially into C941// args without worry of overwriting during the xfer942943src.load_item_force (FrameMap::as_oop_opr(j_rarg0));944src_pos.load_item_force (FrameMap::as_opr(j_rarg1));945dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));946dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));947length.load_item_force (FrameMap::as_opr(j_rarg4));948949LIR_Opr tmp = FrameMap::as_opr(j_rarg5);950951set_no_result(x);952953int flags;954ciArrayKlass* expected_type;955arraycopy_helper(x, &flags, &expected_type);956957__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint958}959960void LIRGenerator::do_update_CRC32(Intrinsic* x) {961assert(UseCRC32Intrinsics, "why are we here?");962// Make all state_for calls early since they can emit code963LIR_Opr result = rlock_result(x);964int flags = 0;965switch (x->id()) {966case vmIntrinsics::_updateCRC32: {967LIRItem crc(x->argument_at(0), this);968LIRItem val(x->argument_at(1), this);969// val is destroyed by update_crc32970val.set_destroys_register();971crc.load_item();972val.load_item();973__ update_crc32(crc.result(), val.result(), result);974break;975}976case vmIntrinsics::_updateBytesCRC32:977case vmIntrinsics::_updateByteBufferCRC32: {978bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);979980LIRItem crc(x->argument_at(0), this);981LIRItem buf(x->argument_at(1), this);982LIRItem off(x->argument_at(2), this);983LIRItem len(x->argument_at(3), this);984buf.load_item();985off.load_nonconstant();986987LIR_Opr index = off.result();988int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;989if(off.result()->is_constant()) {990index = LIR_OprFact::illegalOpr;991offset += off.result()->as_jint();992}993LIR_Opr base_op = buf.result();994995if (index->is_valid()) {996LIR_Opr tmp = new_register(T_LONG);997__ convert(Bytecodes::_i2l, index, tmp);998index = tmp;999}10001001if (offset) {1002LIR_Opr tmp = new_pointer_register();1003__ add(base_op, LIR_OprFact::intConst(offset), tmp);1004base_op = tmp;1005offset = 0;1006}10071008LIR_Address* a = new LIR_Address(base_op,1009index,1010LIR_Address::times_1,1011offset,1012T_BYTE);1013BasicTypeList signature(3);1014signature.append(T_INT);1015signature.append(T_ADDRESS);1016signature.append(T_INT);1017CallingConvention* cc = frame_map()->c_calling_convention(&signature);1018const LIR_Opr result_reg = result_register_for(x->type());10191020LIR_Opr addr = new_pointer_register();1021__ leal(LIR_OprFact::address(a), addr);10221023crc.load_item_force(cc->at(0));1024__ move(addr, cc->at(1));1025len.load_item_force(cc->at(2));10261027__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1028__ move(result_reg, result);10291030break;1031}1032default: {1033ShouldNotReachHere();1034}1035}1036}10371038// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1039// _i2b, _i2c, _i2s1040void LIRGenerator::do_Convert(Convert* x) {1041bool needs_stub;10421043switch (x->op()) {1044case Bytecodes::_i2l:1045case Bytecodes::_l2i:1046case Bytecodes::_i2b:1047case Bytecodes::_i2c:1048case Bytecodes::_i2s:1049case Bytecodes::_f2d:1050case Bytecodes::_d2f:1051case Bytecodes::_i2f:1052case Bytecodes::_i2d:1053case Bytecodes::_l2f:1054case Bytecodes::_l2d: needs_stub = false;1055break;1056case Bytecodes::_f2l:1057case Bytecodes::_d2l:1058case Bytecodes::_f2i:1059case Bytecodes::_d2i: needs_stub = true;1060break;1061default: ShouldNotReachHere();1062}10631064LIRItem value(x->value(), this);1065value.load_item();1066LIR_Opr input = value.result();1067LIR_Opr result = rlock(x);10681069// arguments of lir_convert1070LIR_Opr conv_input = input;1071LIR_Opr conv_result = result;1072ConversionStub* stub = NULL;10731074if (needs_stub) {1075stub = new ConversionStub(x->op(), conv_input, conv_result);1076}10771078__ convert(x->op(), conv_input, conv_result, stub, new_register(T_INT));10791080assert(result->is_virtual(), "result must be virtual register");1081set_result(x, result);1082}10831084void LIRGenerator::do_NewInstance(NewInstance* x) {1085#ifndef PRODUCT1086if (PrintNotLoaded && !x->klass()->is_loaded()) {1087tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());1088}1089#endif1090CodeEmitInfo* info = state_for(x, x->state());1091LIR_Opr reg = result_register_for(x->type());1092new_instance(reg, x->klass(), x->is_unresolved(),1093FrameMap::r2_oop_opr,1094FrameMap::r5_oop_opr,1095FrameMap::r4_oop_opr,1096LIR_OprFact::illegalOpr,1097FrameMap::r3_metadata_opr, info);1098LIR_Opr result = rlock_result(x);1099__ move(reg, result);1100}11011102void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1103CodeEmitInfo* info = state_for(x, x->state());11041105LIRItem length(x->length(), this);1106length.load_item_force(FrameMap::r19_opr);11071108LIR_Opr reg = result_register_for(x->type());1109LIR_Opr tmp1 = FrameMap::r2_oop_opr;1110LIR_Opr tmp2 = FrameMap::r4_oop_opr;1111LIR_Opr tmp3 = FrameMap::r5_oop_opr;1112LIR_Opr tmp4 = reg;1113LIR_Opr klass_reg = FrameMap::r3_metadata_opr;1114LIR_Opr len = length.result();1115BasicType elem_type = x->elt_type();11161117__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);11181119CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1120__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);11211122LIR_Opr result = rlock_result(x);1123__ move(reg, result);1124}11251126void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1127LIRItem length(x->length(), this);1128// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1129// and therefore provide the state before the parameters have been consumed1130CodeEmitInfo* patching_info = NULL;1131if (!x->klass()->is_loaded() || PatchALot) {1132patching_info = state_for(x, x->state_before());1133}11341135CodeEmitInfo* info = state_for(x, x->state());11361137LIR_Opr reg = result_register_for(x->type());1138LIR_Opr tmp1 = FrameMap::r2_oop_opr;1139LIR_Opr tmp2 = FrameMap::r4_oop_opr;1140LIR_Opr tmp3 = FrameMap::r5_oop_opr;1141LIR_Opr tmp4 = reg;1142LIR_Opr klass_reg = FrameMap::r3_metadata_opr;11431144length.load_item_force(FrameMap::r19_opr);1145LIR_Opr len = length.result();11461147CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1148ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1149if (obj == ciEnv::unloaded_ciobjarrayklass()) {1150BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1151}1152klass2reg_with_patching(klass_reg, obj, patching_info);1153__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);11541155LIR_Opr result = rlock_result(x);1156__ move(reg, result);1157}115811591160void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1161Values* dims = x->dims();1162int i = dims->length();1163LIRItemList* items = new LIRItemList(dims->length(), NULL);1164while (i-- > 0) {1165LIRItem* size = new LIRItem(dims->at(i), this);1166items->at_put(i, size);1167}11681169// Evaluate state_for early since it may emit code.1170CodeEmitInfo* patching_info = NULL;1171if (!x->klass()->is_loaded() || PatchALot) {1172patching_info = state_for(x, x->state_before());11731174// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1175// clone all handlers (NOTE: Usually this is handled transparently1176// by the CodeEmitInfo cloning logic in CodeStub constructors but1177// is done explicitly here because a stub isn't being used).1178x->set_exception_handlers(new XHandlers(x->exception_handlers()));1179}1180CodeEmitInfo* info = state_for(x, x->state());11811182i = dims->length();1183while (i-- > 0) {1184LIRItem* size = items->at(i);1185size->load_item();11861187store_stack_parameter(size->result(), in_ByteSize(i*4));1188}11891190LIR_Opr klass_reg = FrameMap::r0_metadata_opr;1191klass2reg_with_patching(klass_reg, x->klass(), patching_info);11921193LIR_Opr rank = FrameMap::r19_opr;1194__ move(LIR_OprFact::intConst(x->rank()), rank);1195LIR_Opr varargs = FrameMap::r2_opr;1196__ move(FrameMap::sp_opr, varargs);1197LIR_OprList* args = new LIR_OprList(3);1198args->append(klass_reg);1199args->append(rank);1200args->append(varargs);1201LIR_Opr reg = result_register_for(x->type());1202__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1203LIR_OprFact::illegalOpr,1204reg, args, info);12051206LIR_Opr result = rlock_result(x);1207__ move(reg, result);1208}12091210void LIRGenerator::do_BlockBegin(BlockBegin* x) {1211// nothing to do for now1212}12131214void LIRGenerator::do_CheckCast(CheckCast* x) {1215LIRItem obj(x->obj(), this);12161217CodeEmitInfo* patching_info = NULL;1218if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {1219// must do this before locking the destination register as an oop register,1220// and before the obj is loaded (the latter is for deoptimization)1221patching_info = state_for(x, x->state_before());1222}1223obj.load_item();12241225// info for exceptions1226CodeEmitInfo* info_for_exception =1227(x->needs_exception_state() ? state_for(x) :1228state_for(x, x->state_before(), true /*ignore_xhandler*/));12291230CodeStub* stub;1231if (x->is_incompatible_class_change_check()) {1232assert(patching_info == NULL, "can't patch this");1233stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1234} else if (x->is_invokespecial_receiver_check()) {1235assert(patching_info == NULL, "can't patch this");1236stub = new DeoptimizeStub(info_for_exception);1237} else {1238stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1239}1240LIR_Opr reg = rlock_result(x);1241LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1242if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1243tmp3 = new_register(objectType);1244}1245__ checkcast(reg, obj.result(), x->klass(),1246new_register(objectType), new_register(objectType), tmp3,1247x->direct_compare(), info_for_exception, patching_info, stub,1248x->profiled_method(), x->profiled_bci());1249}12501251void LIRGenerator::do_InstanceOf(InstanceOf* x) {1252LIRItem obj(x->obj(), this);12531254// result and test object may not be in same register1255LIR_Opr reg = rlock_result(x);1256CodeEmitInfo* patching_info = NULL;1257if ((!x->klass()->is_loaded() || PatchALot)) {1258// must do this before locking the destination register as an oop register1259patching_info = state_for(x, x->state_before());1260}1261obj.load_item();1262LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1263if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1264tmp3 = new_register(objectType);1265}1266__ instanceof(reg, obj.result(), x->klass(),1267new_register(objectType), new_register(objectType), tmp3,1268x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1269}12701271void LIRGenerator::do_If(If* x) {1272assert(x->number_of_sux() == 2, "inconsistency");1273ValueTag tag = x->x()->type()->tag();1274bool is_safepoint = x->is_safepoint();12751276If::Condition cond = x->cond();12771278LIRItem xitem(x->x(), this);1279LIRItem yitem(x->y(), this);1280LIRItem* xin = &xitem;1281LIRItem* yin = &yitem;12821283if (tag == longTag) {1284// for longs, only conditions "eql", "neq", "lss", "geq" are valid;1285// mirror for other conditions1286if (cond == If::gtr || cond == If::leq) {1287cond = Instruction::mirror(cond);1288xin = &yitem;1289yin = &xitem;1290}1291xin->set_destroys_register();1292}1293xin->load_item();12941295if (tag == longTag) {1296if (yin->is_constant()1297&& Assembler::operand_valid_for_add_sub_immediate(yin->get_jlong_constant())) {1298yin->dont_load_item();1299} else {1300yin->load_item();1301}1302} else if (tag == intTag) {1303if (yin->is_constant()1304&& Assembler::operand_valid_for_add_sub_immediate(yin->get_jint_constant())) {1305yin->dont_load_item();1306} else {1307yin->load_item();1308}1309} else {1310yin->load_item();1311}13121313// add safepoint before generating condition code so it can be recomputed1314if (x->is_safepoint()) {1315// increment backedge counter if needed1316increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());1317__ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));1318}1319set_no_result(x);13201321LIR_Opr left = xin->result();1322LIR_Opr right = yin->result();13231324__ cmp(lir_cond(cond), left, right);1325// Generate branch profiling. Profiling code doesn't kill flags.1326profile_branch(x, cond);1327move_to_phi(x->state());1328if (x->x()->type()->is_float_kind()) {1329__ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());1330} else {1331__ branch(lir_cond(cond), right->type(), x->tsux());1332}1333assert(x->default_sux() == x->fsux(), "wrong destination above");1334__ jump(x->default_sux());1335}13361337LIR_Opr LIRGenerator::getThreadPointer() {1338return FrameMap::as_pointer_opr(rthread);1339}13401341void LIRGenerator::trace_block_entry(BlockBegin* block) { Unimplemented(); }13421343void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1344CodeEmitInfo* info) {1345__ volatile_store_mem_reg(value, address, info);1346}13471348void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1349CodeEmitInfo* info) {13501351// 8179954: We need to make sure that the code generated for1352// volatile accesses forms a sequentially-consistent set of1353// operations when combined with STLR and LDAR. Without a leading1354// membar it's possible for a simple Dekker test to fail if loads1355// use LD;DMB but stores use STLR. This can happen if C2 compiles1356// the stores in one method and C1 compiles the loads in another.1357if (! UseBarriersForVolatile) {1358__ membar();1359}13601361__ volatile_load_mem_reg(address, result, info);1362}13631364void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,1365BasicType type, bool is_volatile) {1366LIR_Address* addr = new LIR_Address(src, offset, type);1367__ load(addr, dst);1368}136913701371void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,1372BasicType type, bool is_volatile) {1373LIR_Address* addr = new LIR_Address(src, offset, type);1374bool is_obj = (type == T_ARRAY || type == T_OBJECT);1375if (is_obj) {1376// Do the pre-write barrier, if any.1377pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1378true /* do_load */, false /* patch */, NULL);1379__ move(data, addr);1380assert(src->is_register(), "must be register");1381// Seems to be a precise address1382post_barrier(LIR_OprFact::address(addr), data);1383} else {1384__ move(data, addr);1385}1386}13871388void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {1389BasicType type = x->basic_type();1390LIRItem src(x->object(), this);1391LIRItem off(x->offset(), this);1392LIRItem value(x->value(), this);13931394src.load_item();1395off.load_nonconstant();13961397// We can cope with a constant increment in an xadd1398if (! (x->is_add()1399&& value.is_constant()1400&& can_inline_as_constant(x->value()))) {1401value.load_item();1402}14031404LIR_Opr dst = rlock_result(x, type);1405LIR_Opr data = value.result();1406bool is_obj = (type == T_ARRAY || type == T_OBJECT);1407LIR_Opr offset = off.result();14081409if (data == dst) {1410LIR_Opr tmp = new_register(data->type());1411__ move(data, tmp);1412data = tmp;1413}14141415LIR_Address* addr;1416if (offset->is_constant()) {1417jlong l = offset->as_jlong();1418assert((jlong)((jint)l) == l, "offset too large for constant");1419jint c = (jint)l;1420addr = new LIR_Address(src.result(), c, type);1421} else {1422addr = new LIR_Address(src.result(), offset, type);1423}14241425LIR_Opr tmp = new_register(T_INT);1426LIR_Opr ptr = LIR_OprFact::illegalOpr;14271428if (x->is_add()) {1429__ xadd(LIR_OprFact::address(addr), data, dst, tmp);1430} else {1431if (is_obj) {1432// Do the pre-write barrier, if any.1433ptr = new_pointer_register();1434__ add(src.result(), off.result(), ptr);1435pre_barrier(ptr, LIR_OprFact::illegalOpr /* pre_val */,1436true /* do_load */, false /* patch */, NULL);1437}1438__ xchg(LIR_OprFact::address(addr), data, dst, tmp);1439if (is_obj) {1440post_barrier(ptr, data);1441}1442}1443}144414451446