Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
32285 views
/*1* Copyright (c) 2005, 2016, 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_Compilation.hpp"26#include "c1/c1_FrameMap.hpp"27#include "c1/c1_Instruction.hpp"28#include "c1/c1_LIRAssembler.hpp"29#include "c1/c1_LIRGenerator.hpp"30#include "c1/c1_Runtime1.hpp"31#include "c1/c1_ValueStack.hpp"32#include "ci/ciArray.hpp"33#include "ci/ciObjArrayKlass.hpp"34#include "ci/ciTypeArrayKlass.hpp"35#include "runtime/sharedRuntime.hpp"36#include "runtime/stubRoutines.hpp"37#include "vmreg_x86.inline.hpp"3839#ifdef ASSERT40#define __ gen()->lir(__FILE__, __LINE__)->41#else42#define __ gen()->lir()->43#endif4445#if INCLUDE_ALL_GCS46#include "gc_implementation/shenandoah/c1/shenandoahBarrierSetC1.hpp"47#endif4849// Item will be loaded into a byte register; Intel only50void LIRItem::load_byte_item() {51load_item();52LIR_Opr res = result();5354if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {55// make sure that it is a byte register56assert(!value()->type()->is_float() && !value()->type()->is_double(),57"can't load floats in byte register");58LIR_Opr reg = _gen->rlock_byte(T_BYTE);59__ move(res, reg);6061_result = reg;62}63}646566void LIRItem::load_nonconstant() {67LIR_Opr r = value()->operand();68if (r->is_constant()) {69_result = r;70} else {71load_item();72}73}7475//--------------------------------------------------------------76// LIRGenerator77//--------------------------------------------------------------787980LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::rax_oop_opr; }81LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::rdx_opr; }82LIR_Opr LIRGenerator::divInOpr() { return FrameMap::rax_opr; }83LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::rax_opr; }84LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::rdx_opr; }85LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::rcx_opr; }86LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::rax_opr; }87LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }888990LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {91LIR_Opr opr;92switch (type->tag()) {93case intTag: opr = FrameMap::rax_opr; break;94case objectTag: opr = FrameMap::rax_oop_opr; break;95case longTag: opr = FrameMap::long0_opr; break;96case floatTag: opr = UseSSE >= 1 ? FrameMap::xmm0_float_opr : FrameMap::fpu0_float_opr; break;97case doubleTag: opr = UseSSE >= 2 ? FrameMap::xmm0_double_opr : FrameMap::fpu0_double_opr; break;9899case addressTag:100default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;101}102103assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");104return opr;105}106107108LIR_Opr LIRGenerator::rlock_byte(BasicType type) {109LIR_Opr reg = new_register(T_INT);110set_vreg_flag(reg, LIRGenerator::byte_reg);111return reg;112}113114115//--------- loading items into registers --------------------------------116117118// i486 instructions can inline constants119bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {120if (type == T_SHORT || type == T_CHAR) {121// there is no immediate move of word values in asembler_i486.?pp122return false;123}124Constant* c = v->as_Constant();125if (c && c->state_before() == NULL) {126// constants of any type can be stored directly, except for127// unloaded object constants.128return true;129}130return false;131}132133134bool LIRGenerator::can_inline_as_constant(Value v) const {135if (v->type()->tag() == longTag) return false;136return v->type()->tag() != objectTag ||137(v->type()->is_constant() && v->type()->as_ObjectType()->constant_value()->is_null_object());138}139140141bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {142if (c->type() == T_LONG) return false;143return c->type() != T_OBJECT || c->as_jobject() == NULL;144}145146147LIR_Opr LIRGenerator::safepoint_poll_register() {148return LIR_OprFact::illegalOpr;149}150151152LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,153int shift, int disp, BasicType type) {154assert(base->is_register(), "must be");155if (index->is_constant()) {156return new LIR_Address(base,157(index->as_constant_ptr()->as_jint() << shift) + disp,158type);159} else {160return new LIR_Address(base, index, (LIR_Address::Scale)shift, disp, type);161}162}163164165LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,166BasicType type, bool needs_card_mark) {167int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);168169LIR_Address* addr;170if (index_opr->is_constant()) {171int elem_size = type2aelembytes(type);172addr = new LIR_Address(array_opr,173offset_in_bytes + index_opr->as_jint() * elem_size, type);174} else {175#ifdef _LP64176if (index_opr->type() == T_INT) {177LIR_Opr tmp = new_register(T_LONG);178__ convert(Bytecodes::_i2l, index_opr, tmp);179index_opr = tmp;180}181#endif // _LP64182addr = new LIR_Address(array_opr,183index_opr,184LIR_Address::scale(type),185offset_in_bytes, type);186}187if (needs_card_mark) {188// This store will need a precise card mark, so go ahead and189// compute the full adddres instead of computing once for the190// store and again for the card mark.191LIR_Opr tmp = new_pointer_register();192__ leal(LIR_OprFact::address(addr), tmp);193return new LIR_Address(tmp, type);194} else {195return addr;196}197}198199200LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {201LIR_Opr r = NULL;202if (type == T_LONG) {203r = LIR_OprFact::longConst(x);204} else if (type == T_INT) {205r = LIR_OprFact::intConst(x);206} else {207ShouldNotReachHere();208}209return r;210}211212void LIRGenerator::increment_counter(address counter, BasicType type, int step) {213LIR_Opr pointer = new_pointer_register();214__ move(LIR_OprFact::intptrConst(counter), pointer);215LIR_Address* addr = new LIR_Address(pointer, type);216increment_counter(addr, step);217}218219220void LIRGenerator::increment_counter(LIR_Address* addr, int step) {221__ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);222}223224void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {225__ cmp_mem_int(condition, base, disp, c, info);226}227228229void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {230__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);231}232233234void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info) {235__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);236}237238239bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {240if (tmp->is_valid() && c > 0 && c < max_jint) {241if (is_power_of_2(c + 1)) {242__ move(left, tmp);243__ shift_left(left, log2_jint(c + 1), left);244__ sub(left, tmp, result);245return true;246} else if (is_power_of_2(c - 1)) {247__ move(left, tmp);248__ shift_left(left, log2_jint(c - 1), left);249__ add(left, tmp, result);250return true;251}252}253return false;254}255256257void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {258BasicType type = item->type();259__ store(item, new LIR_Address(FrameMap::rsp_opr, in_bytes(offset_from_sp), type));260}261262//----------------------------------------------------------------------263// visitor functions264//----------------------------------------------------------------------265266267void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {268assert(x->is_pinned(),"");269bool needs_range_check = x->compute_needs_range_check();270bool use_length = x->length() != NULL;271bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;272bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||273!get_jobject_constant(x->value())->is_null_object() ||274x->should_profile());275276LIRItem array(x->array(), this);277LIRItem index(x->index(), this);278LIRItem value(x->value(), this);279LIRItem length(this);280281array.load_item();282index.load_nonconstant();283284if (use_length && needs_range_check) {285length.set_instruction(x->length());286length.load_item();287288}289if (needs_store_check || x->check_boolean()) {290value.load_item();291} else {292value.load_for_store(x->elt_type());293}294295set_no_result(x);296297// the CodeEmitInfo must be duplicated for each different298// LIR-instruction because spilling can occur anywhere between two299// instructions and so the debug information must be different300CodeEmitInfo* range_check_info = state_for(x);301CodeEmitInfo* null_check_info = NULL;302if (x->needs_null_check()) {303null_check_info = new CodeEmitInfo(range_check_info);304}305306// emit array address setup early so it schedules better307LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);308309if (GenerateRangeChecks && needs_range_check) {310if (use_length) {311__ cmp(lir_cond_belowEqual, length.result(), index.result());312__ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));313} else {314array_range_check(array.result(), index.result(), null_check_info, range_check_info);315// range_check also does the null check316null_check_info = NULL;317}318}319320if (GenerateArrayStoreCheck && needs_store_check) {321LIR_Opr tmp1 = new_register(objectType);322LIR_Opr tmp2 = new_register(objectType);323LIR_Opr tmp3 = new_register(objectType);324325CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);326__ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());327}328329if (obj_store) {330// Needs GC write barriers.331pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,332true /* do_load */, false /* patch */, NULL);333__ move(value.result(), array_addr, null_check_info);334// Seems to be a precise335post_barrier(LIR_OprFact::address(array_addr), value.result());336} else {337LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);338__ move(result, array_addr, null_check_info);339}340}341342343void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {344assert(x->is_pinned(),"");345LIRItem obj(x->obj(), this);346obj.load_item();347348set_no_result(x);349350// "lock" stores the address of the monitor stack slot, so this is not an oop351LIR_Opr lock = new_register(T_INT);352// Need a scratch register for biased locking on x86353LIR_Opr scratch = LIR_OprFact::illegalOpr;354if (UseBiasedLocking) {355scratch = new_register(T_INT);356}357358CodeEmitInfo* info_for_exception = NULL;359if (x->needs_null_check()) {360info_for_exception = state_for(x);361}362// this CodeEmitInfo must not have the xhandlers because here the363// object is already locked (xhandlers expect object to be unlocked)364CodeEmitInfo* info = state_for(x, x->state(), true);365monitor_enter(obj.result(), lock, syncTempOpr(), scratch,366x->monitor_no(), info_for_exception, info);367}368369370void LIRGenerator::do_MonitorExit(MonitorExit* x) {371assert(x->is_pinned(),"");372373LIRItem obj(x->obj(), this);374obj.dont_load_item();375376LIR_Opr lock = new_register(T_INT);377LIR_Opr obj_temp = new_register(T_INT);378set_no_result(x);379monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());380}381382383// _ineg, _lneg, _fneg, _dneg384void LIRGenerator::do_NegateOp(NegateOp* x) {385LIRItem value(x->x(), this);386value.set_destroys_register();387value.load_item();388LIR_Opr reg = rlock(x);389__ negate(value.result(), reg);390391set_result(x, round_item(reg));392}393394395// for _fadd, _fmul, _fsub, _fdiv, _frem396// _dadd, _dmul, _dsub, _ddiv, _drem397void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {398LIRItem left(x->x(), this);399LIRItem right(x->y(), this);400LIRItem* left_arg = &left;401LIRItem* right_arg = &right;402assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");403bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);404if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {405left.load_item();406} else {407left.dont_load_item();408}409410// do not load right operand if it is a constant. only 0 and 1 are411// loaded because there are special instructions for loading them412// without memory access (not needed for SSE2 instructions)413bool must_load_right = false;414if (right.is_constant()) {415LIR_Const* c = right.result()->as_constant_ptr();416assert(c != NULL, "invalid constant");417assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");418419if (c->type() == T_FLOAT) {420must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());421} else {422must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());423}424}425426if (must_load_both) {427// frem and drem destroy also right operand, so move it to a new register428right.set_destroys_register();429right.load_item();430} else if (right.is_register() || must_load_right) {431right.load_item();432} else {433right.dont_load_item();434}435LIR_Opr reg = rlock(x);436LIR_Opr tmp = LIR_OprFact::illegalOpr;437if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {438tmp = new_register(T_DOUBLE);439}440441if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {442// special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots443LIR_Opr fpu0, fpu1;444if (x->op() == Bytecodes::_frem) {445fpu0 = LIR_OprFact::single_fpu(0);446fpu1 = LIR_OprFact::single_fpu(1);447} else {448fpu0 = LIR_OprFact::double_fpu(0);449fpu1 = LIR_OprFact::double_fpu(1);450}451__ move(right.result(), fpu1); // order of left and right operand is important!452__ move(left.result(), fpu0);453__ rem (fpu0, fpu1, fpu0);454__ move(fpu0, reg);455456} else {457arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp(), tmp);458}459460set_result(x, round_item(reg));461}462463464// for _ladd, _lmul, _lsub, _ldiv, _lrem465void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {466if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {467// long division is implemented as a direct call into the runtime468LIRItem left(x->x(), this);469LIRItem right(x->y(), this);470471// the check for division by zero destroys the right operand472right.set_destroys_register();473474BasicTypeList signature(2);475signature.append(T_LONG);476signature.append(T_LONG);477CallingConvention* cc = frame_map()->c_calling_convention(&signature);478479// check for division by zero (destroys registers of right operand!)480CodeEmitInfo* info = state_for(x);481482const LIR_Opr result_reg = result_register_for(x->type());483left.load_item_force(cc->at(1));484right.load_item();485486__ move(right.result(), cc->at(0));487488__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));489__ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));490491address entry = NULL;492switch (x->op()) {493case Bytecodes::_lrem:494entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);495break; // check if dividend is 0 is done elsewhere496case Bytecodes::_ldiv:497entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);498break; // check if dividend is 0 is done elsewhere499case Bytecodes::_lmul:500entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);501break;502default:503ShouldNotReachHere();504}505506LIR_Opr result = rlock_result(x);507__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());508__ move(result_reg, result);509} else if (x->op() == Bytecodes::_lmul) {510// missing test if instr is commutative and if we should swap511LIRItem left(x->x(), this);512LIRItem right(x->y(), this);513514// right register is destroyed by the long mul, so it must be515// copied to a new register.516right.set_destroys_register();517518left.load_item();519right.load_item();520521LIR_Opr reg = FrameMap::long0_opr;522arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);523LIR_Opr result = rlock_result(x);524__ move(reg, result);525} else {526// missing test if instr is commutative and if we should swap527LIRItem left(x->x(), this);528LIRItem right(x->y(), this);529530left.load_item();531// don't load constants to save register532right.load_nonconstant();533rlock_result(x);534arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);535}536}537538539540// for: _iadd, _imul, _isub, _idiv, _irem541void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {542if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {543// The requirements for division and modulo544// input : rax,: dividend min_int545// reg: divisor (may not be rax,/rdx) -1546//547// output: rax,: quotient (= rax, idiv reg) min_int548// rdx: remainder (= rax, irem reg) 0549550// rax, and rdx will be destroyed551552// Note: does this invalidate the spec ???553LIRItem right(x->y(), this);554LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid555556// call state_for before load_item_force because state_for may557// force the evaluation of other instructions that are needed for558// correct debug info. Otherwise the live range of the fix559// register might be too long.560CodeEmitInfo* info = state_for(x);561562left.load_item_force(divInOpr());563564right.load_item();565566LIR_Opr result = rlock_result(x);567LIR_Opr result_reg;568if (x->op() == Bytecodes::_idiv) {569result_reg = divOutOpr();570} else {571result_reg = remOutOpr();572}573574if (!ImplicitDiv0Checks) {575__ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));576__ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));577}578LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation579if (x->op() == Bytecodes::_irem) {580__ irem(left.result(), right.result(), result_reg, tmp, info);581} else if (x->op() == Bytecodes::_idiv) {582__ idiv(left.result(), right.result(), result_reg, tmp, info);583} else {584ShouldNotReachHere();585}586587__ move(result_reg, result);588} else {589// missing test if instr is commutative and if we should swap590LIRItem left(x->x(), this);591LIRItem right(x->y(), this);592LIRItem* left_arg = &left;593LIRItem* right_arg = &right;594if (x->is_commutative() && left.is_stack() && right.is_register()) {595// swap them if left is real stack (or cached) and right is real register(not cached)596left_arg = &right;597right_arg = &left;598}599600left_arg->load_item();601602// do not need to load right, as we can handle stack and constants603if (x->op() == Bytecodes::_imul ) {604// check if we can use shift instead605bool use_constant = false;606bool use_tmp = false;607if (right_arg->is_constant()) {608jint iconst = right_arg->get_jint_constant();609if (iconst > 0 && iconst < max_jint) {610if (is_power_of_2(iconst)) {611use_constant = true;612} else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {613use_constant = true;614use_tmp = true;615}616}617}618if (use_constant) {619right_arg->dont_load_item();620} else {621right_arg->load_item();622}623LIR_Opr tmp = LIR_OprFact::illegalOpr;624if (use_tmp) {625tmp = new_register(T_INT);626}627rlock_result(x);628629arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);630} else {631right_arg->dont_load_item();632rlock_result(x);633LIR_Opr tmp = LIR_OprFact::illegalOpr;634arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);635}636}637}638639640void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {641// when an operand with use count 1 is the left operand, then it is642// likely that no move for 2-operand-LIR-form is necessary643if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {644x->swap_operands();645}646647ValueTag tag = x->type()->tag();648assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");649switch (tag) {650case floatTag:651case doubleTag: do_ArithmeticOp_FPU(x); return;652case longTag: do_ArithmeticOp_Long(x); return;653case intTag: do_ArithmeticOp_Int(x); return;654}655ShouldNotReachHere();656}657658659// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr660void LIRGenerator::do_ShiftOp(ShiftOp* x) {661// count must always be in rcx662LIRItem value(x->x(), this);663LIRItem count(x->y(), this);664665ValueTag elemType = x->type()->tag();666bool must_load_count = !count.is_constant() || elemType == longTag;667if (must_load_count) {668// count for long must be in register669count.load_item_force(shiftCountOpr());670} else {671count.dont_load_item();672}673value.load_item();674LIR_Opr reg = rlock_result(x);675676shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);677}678679680// _iand, _land, _ior, _lor, _ixor, _lxor681void LIRGenerator::do_LogicOp(LogicOp* x) {682// when an operand with use count 1 is the left operand, then it is683// likely that no move for 2-operand-LIR-form is necessary684if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {685x->swap_operands();686}687688LIRItem left(x->x(), this);689LIRItem right(x->y(), this);690691left.load_item();692right.load_nonconstant();693LIR_Opr reg = rlock_result(x);694695logic_op(x->op(), reg, left.result(), right.result());696}697698699700// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg701void LIRGenerator::do_CompareOp(CompareOp* x) {702LIRItem left(x->x(), this);703LIRItem right(x->y(), this);704ValueTag tag = x->x()->type()->tag();705if (tag == longTag) {706left.set_destroys_register();707}708left.load_item();709right.load_item();710LIR_Opr reg = rlock_result(x);711712if (x->x()->type()->is_float_kind()) {713Bytecodes::Code code = x->op();714__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));715} else if (x->x()->type()->tag() == longTag) {716__ lcmp2int(left.result(), right.result(), reg);717} else {718Unimplemented();719}720}721722723void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {724assert(x->number_of_arguments() == 4, "wrong type");725LIRItem obj (x->argument_at(0), this); // object726LIRItem offset(x->argument_at(1), this); // offset of field727LIRItem cmp (x->argument_at(2), this); // value to compare with field728LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp729730assert(obj.type()->tag() == objectTag, "invalid type");731732// In 64bit the type can be long, sparc doesn't have this assert733// assert(offset.type()->tag() == intTag, "invalid type");734735assert(cmp.type()->tag() == type->tag(), "invalid type");736assert(val.type()->tag() == type->tag(), "invalid type");737738// get address of field739obj.load_item();740offset.load_nonconstant();741742if (type == objectType) {743cmp.load_item_force(FrameMap::rax_oop_opr);744val.load_item();745} else if (type == intType) {746cmp.load_item_force(FrameMap::rax_opr);747val.load_item();748} else if (type == longType) {749cmp.load_item_force(FrameMap::long0_opr);750val.load_item_force(FrameMap::long1_opr);751} else {752ShouldNotReachHere();753}754755LIR_Opr addr = new_pointer_register();756LIR_Address* a;757if(offset.result()->is_constant()) {758#ifdef _LP64759jlong c = offset.result()->as_jlong();760if ((jlong)((jint)c) == c) {761a = new LIR_Address(obj.result(),762(jint)c,763as_BasicType(type));764} else {765LIR_Opr tmp = new_register(T_LONG);766__ move(offset.result(), tmp);767a = new LIR_Address(obj.result(),768tmp,769as_BasicType(type));770}771#else772a = new LIR_Address(obj.result(),773offset.result()->as_jint(),774as_BasicType(type));775#endif776} else {777a = new LIR_Address(obj.result(),778offset.result(),779LIR_Address::times_1,7800,781as_BasicType(type));782}783__ leal(LIR_OprFact::address(a), addr);784785if (type == objectType) { // Write-barrier needed for Object fields.786// Do the pre-write barrier, if any.787pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,788true /* do_load */, false /* patch */, NULL);789}790791LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience792if (type == objectType) {793#if INCLUDE_ALL_GCS794if (UseShenandoahGC && ShenandoahCASBarrier) {795LIR_Opr result = rlock_result(x);796__ cas_obj(addr, cmp.result(), val.result(), new_register(T_OBJECT), new_register(T_OBJECT), result);797// Shenandoah C1 barrier would do all result management itself, shortcut here.798return;799} else800#endif801{802__ cas_obj(addr, cmp.result(), val.result(), ill, ill);803}804}805else if (type == intType)806__ cas_int(addr, cmp.result(), val.result(), ill, ill);807else if (type == longType)808__ cas_long(addr, cmp.result(), val.result(), ill, ill);809else {810ShouldNotReachHere();811}812813// generate conditional move of boolean result814LIR_Opr result = rlock_result(x);815__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),816result, as_BasicType(type));817if (type == objectType) { // Write-barrier needed for Object fields.818// Seems to be precise819post_barrier(addr, val.result());820}821}822823824void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {825assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");826LIRItem value(x->argument_at(0), this);827828bool use_fpu = false;829if (UseSSE >= 2) {830switch(x->id()) {831case vmIntrinsics::_dsin:832case vmIntrinsics::_dcos:833case vmIntrinsics::_dtan:834case vmIntrinsics::_dlog:835case vmIntrinsics::_dlog10:836case vmIntrinsics::_dexp:837case vmIntrinsics::_dpow:838use_fpu = true;839}840} else {841value.set_destroys_register();842}843844value.load_item();845846LIR_Opr calc_input = value.result();847LIR_Opr calc_input2 = NULL;848if (x->id() == vmIntrinsics::_dpow) {849LIRItem extra_arg(x->argument_at(1), this);850if (UseSSE < 2) {851extra_arg.set_destroys_register();852}853extra_arg.load_item();854calc_input2 = extra_arg.result();855}856LIR_Opr calc_result = rlock_result(x);857858// sin, cos, pow and exp need two free fpu stack slots, so register859// two temporary operands860LIR_Opr tmp1 = FrameMap::caller_save_fpu_reg_at(0);861LIR_Opr tmp2 = FrameMap::caller_save_fpu_reg_at(1);862863if (use_fpu) {864LIR_Opr tmp = FrameMap::fpu0_double_opr;865int tmp_start = 1;866if (calc_input2 != NULL) {867__ move(calc_input2, tmp);868tmp_start = 2;869calc_input2 = tmp;870}871__ move(calc_input, tmp);872873calc_input = tmp;874calc_result = tmp;875876tmp1 = FrameMap::caller_save_fpu_reg_at(tmp_start);877tmp2 = FrameMap::caller_save_fpu_reg_at(tmp_start + 1);878}879880switch(x->id()) {881case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, LIR_OprFact::illegalOpr); break;882case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;883case vmIntrinsics::_dsin: __ sin (calc_input, calc_result, tmp1, tmp2); break;884case vmIntrinsics::_dcos: __ cos (calc_input, calc_result, tmp1, tmp2); break;885case vmIntrinsics::_dtan: __ tan (calc_input, calc_result, tmp1, tmp2); break;886case vmIntrinsics::_dlog: __ log (calc_input, calc_result, tmp1); break;887case vmIntrinsics::_dlog10: __ log10(calc_input, calc_result, tmp1); break;888case vmIntrinsics::_dexp: __ exp (calc_input, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;889case vmIntrinsics::_dpow: __ pow (calc_input, calc_input2, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;890default: ShouldNotReachHere();891}892893if (use_fpu) {894__ move(calc_result, x->operand());895}896}897898899void LIRGenerator::do_ArrayCopy(Intrinsic* x) {900assert(x->number_of_arguments() == 5, "wrong type");901902// Make all state_for calls early since they can emit code903CodeEmitInfo* info = state_for(x, x->state());904905LIRItem src(x->argument_at(0), this);906LIRItem src_pos(x->argument_at(1), this);907LIRItem dst(x->argument_at(2), this);908LIRItem dst_pos(x->argument_at(3), this);909LIRItem length(x->argument_at(4), this);910911// operands for arraycopy must use fixed registers, otherwise912// LinearScan will fail allocation (because arraycopy always needs a913// call)914915#ifndef _LP64916src.load_item_force (FrameMap::rcx_oop_opr);917src_pos.load_item_force (FrameMap::rdx_opr);918dst.load_item_force (FrameMap::rax_oop_opr);919dst_pos.load_item_force (FrameMap::rbx_opr);920length.load_item_force (FrameMap::rdi_opr);921LIR_Opr tmp = (FrameMap::rsi_opr);922#else923924// The java calling convention will give us enough registers925// so that on the stub side the args will be perfect already.926// On the other slow/special case side we call C and the arg927// positions are not similar enough to pick one as the best.928// Also because the java calling convention is a "shifted" version929// of the C convention we can process the java args trivially into C930// args without worry of overwriting during the xfer931932src.load_item_force (FrameMap::as_oop_opr(j_rarg0));933src_pos.load_item_force (FrameMap::as_opr(j_rarg1));934dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));935dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));936length.load_item_force (FrameMap::as_opr(j_rarg4));937938LIR_Opr tmp = FrameMap::as_opr(j_rarg5);939#endif // LP64940941set_no_result(x);942943int flags;944ciArrayKlass* expected_type;945arraycopy_helper(x, &flags, &expected_type);946947__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint948}949950void LIRGenerator::do_update_CRC32(Intrinsic* x) {951assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");952// Make all state_for calls early since they can emit code953LIR_Opr result = rlock_result(x);954int flags = 0;955switch (x->id()) {956case vmIntrinsics::_updateCRC32: {957LIRItem crc(x->argument_at(0), this);958LIRItem val(x->argument_at(1), this);959// val is destroyed by update_crc32960val.set_destroys_register();961crc.load_item();962val.load_item();963__ update_crc32(crc.result(), val.result(), result);964break;965}966case vmIntrinsics::_updateBytesCRC32:967case vmIntrinsics::_updateByteBufferCRC32: {968bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);969970LIRItem crc(x->argument_at(0), this);971LIRItem buf(x->argument_at(1), this);972LIRItem off(x->argument_at(2), this);973LIRItem len(x->argument_at(3), this);974buf.load_item();975off.load_nonconstant();976977LIR_Opr index = off.result();978int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;979if(off.result()->is_constant()) {980index = LIR_OprFact::illegalOpr;981offset += off.result()->as_jint();982}983LIR_Opr base_op = buf.result();984985#ifndef _LP64986if (!is_updateBytes) { // long b raw address987base_op = new_register(T_INT);988__ convert(Bytecodes::_l2i, buf.result(), base_op);989}990#else991if (index->is_valid()) {992LIR_Opr tmp = new_register(T_LONG);993__ convert(Bytecodes::_i2l, index, tmp);994index = tmp;995}996#endif997998LIR_Address* a = new LIR_Address(base_op,999index,1000LIR_Address::times_1,1001offset,1002T_BYTE);1003BasicTypeList signature(3);1004signature.append(T_INT);1005signature.append(T_ADDRESS);1006signature.append(T_INT);1007CallingConvention* cc = frame_map()->c_calling_convention(&signature);1008const LIR_Opr result_reg = result_register_for(x->type());10091010LIR_Opr addr = new_pointer_register();1011__ leal(LIR_OprFact::address(a), addr);10121013crc.load_item_force(cc->at(0));1014__ move(addr, cc->at(1));1015len.load_item_force(cc->at(2));10161017__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1018__ move(result_reg, result);10191020break;1021}1022default: {1023ShouldNotReachHere();1024}1025}1026}10271028// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1029// _i2b, _i2c, _i2s1030LIR_Opr fixed_register_for(BasicType type) {1031switch (type) {1032case T_FLOAT: return FrameMap::fpu0_float_opr;1033case T_DOUBLE: return FrameMap::fpu0_double_opr;1034case T_INT: return FrameMap::rax_opr;1035case T_LONG: return FrameMap::long0_opr;1036default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;1037}1038}10391040void LIRGenerator::do_Convert(Convert* x) {1041// flags that vary for the different operations and different SSE-settings1042bool fixed_input = false, fixed_result = false, round_result = false, needs_stub = false;10431044switch (x->op()) {1045case Bytecodes::_i2l: // fall through1046case Bytecodes::_l2i: // fall through1047case Bytecodes::_i2b: // fall through1048case Bytecodes::_i2c: // fall through1049case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;10501051case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;1052case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;1053case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;1054case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;1055case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1056case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1057case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;1058case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;1059case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1060case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;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 (fixed_input) {1075conv_input = fixed_register_for(input->type());1076__ move(input, conv_input);1077}10781079assert(fixed_result == false || round_result == false, "cannot set both");1080if (fixed_result) {1081conv_result = fixed_register_for(result->type());1082} else if (round_result) {1083result = new_register(result->type());1084set_vreg_flag(result, must_start_in_memory);1085}10861087if (needs_stub) {1088stub = new ConversionStub(x->op(), conv_input, conv_result);1089}10901091__ convert(x->op(), conv_input, conv_result, stub);10921093if (result != conv_result) {1094__ move(conv_result, result);1095}10961097assert(result->is_virtual(), "result must be virtual register");1098set_result(x, result);1099}110011011102void LIRGenerator::do_NewInstance(NewInstance* x) {1103print_if_not_loaded(x);11041105CodeEmitInfo* info = state_for(x, x->state());1106LIR_Opr reg = result_register_for(x->type());1107new_instance(reg, x->klass(), x->is_unresolved(),1108FrameMap::rcx_oop_opr,1109FrameMap::rdi_oop_opr,1110FrameMap::rsi_oop_opr,1111LIR_OprFact::illegalOpr,1112FrameMap::rdx_metadata_opr, info);1113LIR_Opr result = rlock_result(x);1114__ move(reg, result);1115}111611171118void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1119CodeEmitInfo* info = state_for(x, x->state());11201121LIRItem length(x->length(), this);1122length.load_item_force(FrameMap::rbx_opr);11231124LIR_Opr reg = result_register_for(x->type());1125LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1126LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1127LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1128LIR_Opr tmp4 = reg;1129LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;1130LIR_Opr len = length.result();1131BasicType elem_type = x->elt_type();11321133__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);11341135CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1136__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);11371138LIR_Opr result = rlock_result(x);1139__ move(reg, result);1140}114111421143void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1144LIRItem length(x->length(), this);1145// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1146// and therefore provide the state before the parameters have been consumed1147CodeEmitInfo* patching_info = NULL;1148if (!x->klass()->is_loaded() || PatchALot) {1149patching_info = state_for(x, x->state_before());1150}11511152CodeEmitInfo* info = state_for(x, x->state());11531154const LIR_Opr reg = result_register_for(x->type());1155LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1156LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1157LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1158LIR_Opr tmp4 = reg;1159LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;11601161length.load_item_force(FrameMap::rbx_opr);1162LIR_Opr len = length.result();11631164CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1165ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1166if (obj == ciEnv::unloaded_ciobjarrayklass()) {1167BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1168}1169klass2reg_with_patching(klass_reg, obj, patching_info);1170__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);11711172LIR_Opr result = rlock_result(x);1173__ move(reg, result);1174}117511761177void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1178Values* dims = x->dims();1179int i = dims->length();1180LIRItemList* items = new LIRItemList(dims->length(), NULL);1181while (i-- > 0) {1182LIRItem* size = new LIRItem(dims->at(i), this);1183items->at_put(i, size);1184}11851186// Evaluate state_for early since it may emit code.1187CodeEmitInfo* patching_info = NULL;1188if (!x->klass()->is_loaded() || PatchALot) {1189patching_info = state_for(x, x->state_before());11901191// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1192// clone all handlers (NOTE: Usually this is handled transparently1193// by the CodeEmitInfo cloning logic in CodeStub constructors but1194// is done explicitly here because a stub isn't being used).1195x->set_exception_handlers(new XHandlers(x->exception_handlers()));1196}1197CodeEmitInfo* info = state_for(x, x->state());11981199i = dims->length();1200while (i-- > 0) {1201LIRItem* size = items->at(i);1202size->load_nonconstant();12031204store_stack_parameter(size->result(), in_ByteSize(i*4));1205}12061207LIR_Opr klass_reg = FrameMap::rax_metadata_opr;1208klass2reg_with_patching(klass_reg, x->klass(), patching_info);12091210LIR_Opr rank = FrameMap::rbx_opr;1211__ move(LIR_OprFact::intConst(x->rank()), rank);1212LIR_Opr varargs = FrameMap::rcx_opr;1213__ move(FrameMap::rsp_opr, varargs);1214LIR_OprList* args = new LIR_OprList(3);1215args->append(klass_reg);1216args->append(rank);1217args->append(varargs);1218LIR_Opr reg = result_register_for(x->type());1219__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1220LIR_OprFact::illegalOpr,1221reg, args, info);12221223LIR_Opr result = rlock_result(x);1224__ move(reg, result);1225}122612271228void LIRGenerator::do_BlockBegin(BlockBegin* x) {1229// nothing to do for now1230}123112321233void LIRGenerator::do_CheckCast(CheckCast* x) {1234LIRItem obj(x->obj(), this);12351236CodeEmitInfo* patching_info = NULL;1237if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {1238// must do this before locking the destination register as an oop register,1239// and before the obj is loaded (the latter is for deoptimization)1240patching_info = state_for(x, x->state_before());1241}1242obj.load_item();12431244// info for exceptions1245CodeEmitInfo* info_for_exception =1246(x->needs_exception_state() ? state_for(x) :1247state_for(x, x->state_before(), true /*ignore_xhandler*/));12481249CodeStub* stub;1250if (x->is_incompatible_class_change_check()) {1251assert(patching_info == NULL, "can't patch this");1252stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1253} else if (x->is_invokespecial_receiver_check()) {1254assert(patching_info == NULL, "can't patch this");1255stub = new DeoptimizeStub(info_for_exception);1256} else {1257stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1258}1259LIR_Opr reg = rlock_result(x);1260LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1261if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1262tmp3 = new_register(objectType);1263}1264__ checkcast(reg, obj.result(), x->klass(),1265new_register(objectType), new_register(objectType), tmp3,1266x->direct_compare(), info_for_exception, patching_info, stub,1267x->profiled_method(), x->profiled_bci());1268}126912701271void LIRGenerator::do_InstanceOf(InstanceOf* x) {1272LIRItem obj(x->obj(), this);12731274// result and test object may not be in same register1275LIR_Opr reg = rlock_result(x);1276CodeEmitInfo* patching_info = NULL;1277if ((!x->klass()->is_loaded() || PatchALot)) {1278// must do this before locking the destination register as an oop register1279patching_info = state_for(x, x->state_before());1280}1281obj.load_item();1282LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1283if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1284tmp3 = new_register(objectType);1285}1286__ instanceof(reg, obj.result(), x->klass(),1287new_register(objectType), new_register(objectType), tmp3,1288x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1289}129012911292void LIRGenerator::do_If(If* x) {1293assert(x->number_of_sux() == 2, "inconsistency");1294ValueTag tag = x->x()->type()->tag();1295bool is_safepoint = x->is_safepoint();12961297If::Condition cond = x->cond();12981299LIRItem xitem(x->x(), this);1300LIRItem yitem(x->y(), this);1301LIRItem* xin = &xitem;1302LIRItem* yin = &yitem;13031304if (tag == longTag) {1305// for longs, only conditions "eql", "neq", "lss", "geq" are valid;1306// mirror for other conditions1307if (cond == If::gtr || cond == If::leq) {1308cond = Instruction::mirror(cond);1309xin = &yitem;1310yin = &xitem;1311}1312xin->set_destroys_register();1313}1314xin->load_item();1315if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {1316// inline long zero1317yin->dont_load_item();1318} else if (tag == longTag || tag == floatTag || tag == doubleTag) {1319// longs cannot handle constants at right side1320yin->load_item();1321} else {1322yin->dont_load_item();1323}13241325// add safepoint before generating condition code so it can be recomputed1326if (x->is_safepoint()) {1327// increment backedge counter if needed1328increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());1329__ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));1330}1331set_no_result(x);13321333LIR_Opr left = xin->result();1334LIR_Opr right = yin->result();1335__ cmp(lir_cond(cond), left, right);1336// Generate branch profiling. Profiling code doesn't kill flags.1337profile_branch(x, cond);1338move_to_phi(x->state());1339if (x->x()->type()->is_float_kind()) {1340__ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());1341} else {1342__ branch(lir_cond(cond), right->type(), x->tsux());1343}1344assert(x->default_sux() == x->fsux(), "wrong destination above");1345__ jump(x->default_sux());1346}134713481349LIR_Opr LIRGenerator::getThreadPointer() {1350#ifdef _LP641351return FrameMap::as_pointer_opr(r15_thread);1352#else1353LIR_Opr result = new_register(T_INT);1354__ get_thread(result);1355return result;1356#endif //1357}13581359void LIRGenerator::trace_block_entry(BlockBegin* block) {1360store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));1361LIR_OprList* args = new LIR_OprList();1362address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1363__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1364}136513661367void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1368CodeEmitInfo* info) {1369if (address->type() == T_LONG) {1370address = new LIR_Address(address->base(),1371address->index(), address->scale(),1372address->disp(), T_DOUBLE);1373// Transfer the value atomically by using FP moves. This means1374// the value has to be moved between CPU and FPU registers. It1375// always has to be moved through spill slot since there's no1376// quick way to pack the value into an SSE register.1377LIR_Opr temp_double = new_register(T_DOUBLE);1378LIR_Opr spill = new_register(T_LONG);1379set_vreg_flag(spill, must_start_in_memory);1380__ move(value, spill);1381__ volatile_move(spill, temp_double, T_LONG);1382__ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);1383} else {1384__ store(value, address, info);1385}1386}1387138813891390void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1391CodeEmitInfo* info) {1392if (address->type() == T_LONG) {1393address = new LIR_Address(address->base(),1394address->index(), address->scale(),1395address->disp(), T_DOUBLE);1396// Transfer the value atomically by using FP moves. This means1397// the value has to be moved between CPU and FPU registers. In1398// SSE0 and SSE1 mode it has to be moved through spill slot but in1399// SSE2+ mode it can be moved directly.1400LIR_Opr temp_double = new_register(T_DOUBLE);1401__ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);1402__ volatile_move(temp_double, result, T_LONG);1403if (UseSSE < 2) {1404// no spill slot needed in SSE2 mode because xmm->cpu register move is possible1405set_vreg_flag(result, must_start_in_memory);1406}1407} else {1408__ load(address, result, info);1409}1410}14111412void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,1413BasicType type, bool is_volatile) {1414if (is_volatile && type == T_LONG) {1415LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);1416LIR_Opr tmp = new_register(T_DOUBLE);1417__ load(addr, tmp);1418LIR_Opr spill = new_register(T_LONG);1419set_vreg_flag(spill, must_start_in_memory);1420__ move(tmp, spill);1421__ move(spill, dst);1422} else {1423LIR_Address* addr = new LIR_Address(src, offset, type);1424__ load(addr, dst);1425}1426}142714281429void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,1430BasicType type, bool is_volatile) {1431if (is_volatile && type == T_LONG) {1432LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);1433LIR_Opr tmp = new_register(T_DOUBLE);1434LIR_Opr spill = new_register(T_DOUBLE);1435set_vreg_flag(spill, must_start_in_memory);1436__ move(data, spill);1437__ move(spill, tmp);1438__ move(tmp, addr);1439} else {1440LIR_Address* addr = new LIR_Address(src, offset, type);1441bool is_obj = (type == T_ARRAY || type == T_OBJECT);1442if (is_obj) {1443// Do the pre-write barrier, if any.1444pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1445true /* do_load */, false /* patch */, NULL);1446__ move(data, addr);1447assert(src->is_register(), "must be register");1448// Seems to be a precise address1449post_barrier(LIR_OprFact::address(addr), data);1450} else {1451__ move(data, addr);1452}1453}1454}14551456void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {1457BasicType type = x->basic_type();1458LIRItem src(x->object(), this);1459LIRItem off(x->offset(), this);1460LIRItem value(x->value(), this);14611462src.load_item();1463value.load_item();1464off.load_nonconstant();14651466LIR_Opr dst = rlock_result(x, type);1467LIR_Opr data = value.result();1468bool is_obj = (type == T_ARRAY || type == T_OBJECT);1469LIR_Opr offset = off.result();14701471assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");1472LIR_Address* addr;1473if (offset->is_constant()) {1474#ifdef _LP641475jlong c = offset->as_jlong();1476if ((jlong)((jint)c) == c) {1477addr = new LIR_Address(src.result(), (jint)c, type);1478} else {1479LIR_Opr tmp = new_register(T_LONG);1480__ move(offset, tmp);1481addr = new LIR_Address(src.result(), tmp, type);1482}1483#else1484addr = new LIR_Address(src.result(), offset->as_jint(), type);1485#endif1486} else {1487addr = new LIR_Address(src.result(), offset, type);1488}14891490// Because we want a 2-arg form of xchg and xadd1491__ move(data, dst);14921493if (x->is_add()) {1494__ xadd(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);1495} else {1496if (is_obj) {1497// Do the pre-write barrier, if any.1498pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1499true /* do_load */, false /* patch */, NULL);1500}1501__ xchg(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);15021503#if INCLUDE_ALL_GCS1504if (UseShenandoahGC && is_obj) {1505LIR_Opr tmp = ShenandoahBarrierSet::barrier_set()->bsc1()->load_reference_barrier(this, dst, LIR_OprFact::addressConst(0));1506__ move(tmp, dst);1507}1508#endif15091510if (is_obj) {1511// Seems to be a precise address1512post_barrier(LIR_OprFact::address(addr), data);1513}1514}1515}151615171518