Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
48785 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// Item will be loaded into a byte register; Intel only46void LIRItem::load_byte_item() {47load_item();48LIR_Opr res = result();4950if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {51// make sure that it is a byte register52assert(!value()->type()->is_float() && !value()->type()->is_double(),53"can't load floats in byte register");54LIR_Opr reg = _gen->rlock_byte(T_BYTE);55__ move(res, reg);5657_result = reg;58}59}606162void LIRItem::load_nonconstant() {63LIR_Opr r = value()->operand();64if (r->is_constant()) {65_result = r;66} else {67load_item();68}69}7071//--------------------------------------------------------------72// LIRGenerator73//--------------------------------------------------------------747576LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::rax_oop_opr; }77LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::rdx_opr; }78LIR_Opr LIRGenerator::divInOpr() { return FrameMap::rax_opr; }79LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::rax_opr; }80LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::rdx_opr; }81LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::rcx_opr; }82LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::rax_opr; }83LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }848586LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {87LIR_Opr opr;88switch (type->tag()) {89case intTag: opr = FrameMap::rax_opr; break;90case objectTag: opr = FrameMap::rax_oop_opr; break;91case longTag: opr = FrameMap::long0_opr; break;92case floatTag: opr = UseSSE >= 1 ? FrameMap::xmm0_float_opr : FrameMap::fpu0_float_opr; break;93case doubleTag: opr = UseSSE >= 2 ? FrameMap::xmm0_double_opr : FrameMap::fpu0_double_opr; break;9495case addressTag:96default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;97}9899assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");100return opr;101}102103104LIR_Opr LIRGenerator::rlock_byte(BasicType type) {105LIR_Opr reg = new_register(T_INT);106set_vreg_flag(reg, LIRGenerator::byte_reg);107return reg;108}109110111//--------- loading items into registers --------------------------------112113114// i486 instructions can inline constants115bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {116if (type == T_SHORT || type == T_CHAR) {117// there is no immediate move of word values in asembler_i486.?pp118return false;119}120Constant* c = v->as_Constant();121if (c && c->state_before() == NULL) {122// constants of any type can be stored directly, except for123// unloaded object constants.124return true;125}126return false;127}128129130bool LIRGenerator::can_inline_as_constant(Value v) const {131if (v->type()->tag() == longTag) return false;132return v->type()->tag() != objectTag ||133(v->type()->is_constant() && v->type()->as_ObjectType()->constant_value()->is_null_object());134}135136137bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {138if (c->type() == T_LONG) return false;139return c->type() != T_OBJECT || c->as_jobject() == NULL;140}141142143LIR_Opr LIRGenerator::safepoint_poll_register() {144return LIR_OprFact::illegalOpr;145}146147148LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,149int shift, int disp, BasicType type) {150assert(base->is_register(), "must be");151if (index->is_constant()) {152return new LIR_Address(base,153(index->as_constant_ptr()->as_jint() << shift) + disp,154type);155} else {156return new LIR_Address(base, index, (LIR_Address::Scale)shift, disp, type);157}158}159160161LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,162BasicType type, bool needs_card_mark) {163int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);164165LIR_Address* addr;166if (index_opr->is_constant()) {167int elem_size = type2aelembytes(type);168addr = new LIR_Address(array_opr,169offset_in_bytes + index_opr->as_jint() * elem_size, type);170} else {171#ifdef _LP64172if (index_opr->type() == T_INT) {173LIR_Opr tmp = new_register(T_LONG);174__ convert(Bytecodes::_i2l, index_opr, tmp);175index_opr = tmp;176}177#endif // _LP64178addr = new LIR_Address(array_opr,179index_opr,180LIR_Address::scale(type),181offset_in_bytes, type);182}183if (needs_card_mark) {184// This store will need a precise card mark, so go ahead and185// compute the full adddres instead of computing once for the186// store and again for the card mark.187LIR_Opr tmp = new_pointer_register();188__ leal(LIR_OprFact::address(addr), tmp);189return new LIR_Address(tmp, type);190} else {191return addr;192}193}194195196LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {197LIR_Opr r = NULL;198if (type == T_LONG) {199r = LIR_OprFact::longConst(x);200} else if (type == T_INT) {201r = LIR_OprFact::intConst(x);202} else {203ShouldNotReachHere();204}205return r;206}207208void LIRGenerator::increment_counter(address counter, BasicType type, int step) {209LIR_Opr pointer = new_pointer_register();210__ move(LIR_OprFact::intptrConst(counter), pointer);211LIR_Address* addr = new LIR_Address(pointer, type);212increment_counter(addr, step);213}214215216void LIRGenerator::increment_counter(LIR_Address* addr, int step) {217__ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);218}219220void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {221__ cmp_mem_int(condition, base, disp, c, info);222}223224225void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {226__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);227}228229230void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info) {231__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);232}233234235bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {236if (tmp->is_valid() && c > 0 && c < max_jint) {237if (is_power_of_2(c + 1)) {238__ move(left, tmp);239__ shift_left(left, log2_jint(c + 1), left);240__ sub(left, tmp, result);241return true;242} else if (is_power_of_2(c - 1)) {243__ move(left, tmp);244__ shift_left(left, log2_jint(c - 1), left);245__ add(left, tmp, result);246return true;247}248}249return false;250}251252253void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {254BasicType type = item->type();255__ store(item, new LIR_Address(FrameMap::rsp_opr, in_bytes(offset_from_sp), type));256}257258//----------------------------------------------------------------------259// visitor functions260//----------------------------------------------------------------------261262263void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {264assert(x->is_pinned(),"");265bool needs_range_check = x->compute_needs_range_check();266bool use_length = x->length() != NULL;267bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;268bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||269!get_jobject_constant(x->value())->is_null_object() ||270x->should_profile());271272LIRItem array(x->array(), this);273LIRItem index(x->index(), this);274LIRItem value(x->value(), this);275LIRItem length(this);276277array.load_item();278index.load_nonconstant();279280if (use_length && needs_range_check) {281length.set_instruction(x->length());282length.load_item();283284}285if (needs_store_check || x->check_boolean()) {286value.load_item();287} else {288value.load_for_store(x->elt_type());289}290291set_no_result(x);292293// the CodeEmitInfo must be duplicated for each different294// LIR-instruction because spilling can occur anywhere between two295// instructions and so the debug information must be different296CodeEmitInfo* range_check_info = state_for(x);297CodeEmitInfo* null_check_info = NULL;298if (x->needs_null_check()) {299null_check_info = new CodeEmitInfo(range_check_info);300}301302// emit array address setup early so it schedules better303LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);304305if (GenerateRangeChecks && needs_range_check) {306if (use_length) {307__ cmp(lir_cond_belowEqual, length.result(), index.result());308__ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));309} else {310array_range_check(array.result(), index.result(), null_check_info, range_check_info);311// range_check also does the null check312null_check_info = NULL;313}314}315316if (GenerateArrayStoreCheck && needs_store_check) {317LIR_Opr tmp1 = new_register(objectType);318LIR_Opr tmp2 = new_register(objectType);319LIR_Opr tmp3 = new_register(objectType);320321CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);322__ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());323}324325if (obj_store) {326// Needs GC write barriers.327pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,328true /* do_load */, false /* patch */, NULL);329__ move(value.result(), array_addr, null_check_info);330// Seems to be a precise331post_barrier(LIR_OprFact::address(array_addr), value.result());332} else {333LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);334__ move(result, array_addr, null_check_info);335}336}337338339void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {340assert(x->is_pinned(),"");341LIRItem obj(x->obj(), this);342obj.load_item();343344set_no_result(x);345346// "lock" stores the address of the monitor stack slot, so this is not an oop347LIR_Opr lock = new_register(T_INT);348// Need a scratch register for biased locking on x86349LIR_Opr scratch = LIR_OprFact::illegalOpr;350if (UseBiasedLocking) {351scratch = new_register(T_INT);352}353354CodeEmitInfo* info_for_exception = NULL;355if (x->needs_null_check()) {356info_for_exception = state_for(x);357}358// this CodeEmitInfo must not have the xhandlers because here the359// object is already locked (xhandlers expect object to be unlocked)360CodeEmitInfo* info = state_for(x, x->state(), true);361monitor_enter(obj.result(), lock, syncTempOpr(), scratch,362x->monitor_no(), info_for_exception, info);363}364365366void LIRGenerator::do_MonitorExit(MonitorExit* x) {367assert(x->is_pinned(),"");368369LIRItem obj(x->obj(), this);370obj.dont_load_item();371372LIR_Opr lock = new_register(T_INT);373LIR_Opr obj_temp = new_register(T_INT);374set_no_result(x);375monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());376}377378379// _ineg, _lneg, _fneg, _dneg380void LIRGenerator::do_NegateOp(NegateOp* x) {381LIRItem value(x->x(), this);382value.set_destroys_register();383value.load_item();384LIR_Opr reg = rlock(x);385__ negate(value.result(), reg);386387set_result(x, round_item(reg));388}389390391// for _fadd, _fmul, _fsub, _fdiv, _frem392// _dadd, _dmul, _dsub, _ddiv, _drem393void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {394LIRItem left(x->x(), this);395LIRItem right(x->y(), this);396LIRItem* left_arg = &left;397LIRItem* right_arg = &right;398assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");399bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);400if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {401left.load_item();402} else {403left.dont_load_item();404}405406// do not load right operand if it is a constant. only 0 and 1 are407// loaded because there are special instructions for loading them408// without memory access (not needed for SSE2 instructions)409bool must_load_right = false;410if (right.is_constant()) {411LIR_Const* c = right.result()->as_constant_ptr();412assert(c != NULL, "invalid constant");413assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");414415if (c->type() == T_FLOAT) {416must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());417} else {418must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());419}420}421422if (must_load_both) {423// frem and drem destroy also right operand, so move it to a new register424right.set_destroys_register();425right.load_item();426} else if (right.is_register() || must_load_right) {427right.load_item();428} else {429right.dont_load_item();430}431LIR_Opr reg = rlock(x);432LIR_Opr tmp = LIR_OprFact::illegalOpr;433if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {434tmp = new_register(T_DOUBLE);435}436437if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {438// special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots439LIR_Opr fpu0, fpu1;440if (x->op() == Bytecodes::_frem) {441fpu0 = LIR_OprFact::single_fpu(0);442fpu1 = LIR_OprFact::single_fpu(1);443} else {444fpu0 = LIR_OprFact::double_fpu(0);445fpu1 = LIR_OprFact::double_fpu(1);446}447__ move(right.result(), fpu1); // order of left and right operand is important!448__ move(left.result(), fpu0);449__ rem (fpu0, fpu1, fpu0);450__ move(fpu0, reg);451452} else {453arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp(), tmp);454}455456set_result(x, round_item(reg));457}458459460// for _ladd, _lmul, _lsub, _ldiv, _lrem461void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {462if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {463// long division is implemented as a direct call into the runtime464LIRItem left(x->x(), this);465LIRItem right(x->y(), this);466467// the check for division by zero destroys the right operand468right.set_destroys_register();469470BasicTypeList signature(2);471signature.append(T_LONG);472signature.append(T_LONG);473CallingConvention* cc = frame_map()->c_calling_convention(&signature);474475// check for division by zero (destroys registers of right operand!)476CodeEmitInfo* info = state_for(x);477478const LIR_Opr result_reg = result_register_for(x->type());479left.load_item_force(cc->at(1));480right.load_item();481482__ move(right.result(), cc->at(0));483484__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));485__ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));486487address entry = NULL;488switch (x->op()) {489case Bytecodes::_lrem:490entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);491break; // check if dividend is 0 is done elsewhere492case Bytecodes::_ldiv:493entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);494break; // check if dividend is 0 is done elsewhere495case Bytecodes::_lmul:496entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);497break;498default:499ShouldNotReachHere();500}501502LIR_Opr result = rlock_result(x);503__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());504__ move(result_reg, result);505} else if (x->op() == Bytecodes::_lmul) {506// missing test if instr is commutative and if we should swap507LIRItem left(x->x(), this);508LIRItem right(x->y(), this);509510// right register is destroyed by the long mul, so it must be511// copied to a new register.512right.set_destroys_register();513514left.load_item();515right.load_item();516517LIR_Opr reg = FrameMap::long0_opr;518arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);519LIR_Opr result = rlock_result(x);520__ move(reg, result);521} else {522// missing test if instr is commutative and if we should swap523LIRItem left(x->x(), this);524LIRItem right(x->y(), this);525526left.load_item();527// don't load constants to save register528right.load_nonconstant();529rlock_result(x);530arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);531}532}533534535536// for: _iadd, _imul, _isub, _idiv, _irem537void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {538if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {539// The requirements for division and modulo540// input : rax,: dividend min_int541// reg: divisor (may not be rax,/rdx) -1542//543// output: rax,: quotient (= rax, idiv reg) min_int544// rdx: remainder (= rax, irem reg) 0545546// rax, and rdx will be destroyed547548// Note: does this invalidate the spec ???549LIRItem right(x->y(), this);550LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid551552// call state_for before load_item_force because state_for may553// force the evaluation of other instructions that are needed for554// correct debug info. Otherwise the live range of the fix555// register might be too long.556CodeEmitInfo* info = state_for(x);557558left.load_item_force(divInOpr());559560right.load_item();561562LIR_Opr result = rlock_result(x);563LIR_Opr result_reg;564if (x->op() == Bytecodes::_idiv) {565result_reg = divOutOpr();566} else {567result_reg = remOutOpr();568}569570if (!ImplicitDiv0Checks) {571__ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));572__ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));573}574LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation575if (x->op() == Bytecodes::_irem) {576__ irem(left.result(), right.result(), result_reg, tmp, info);577} else if (x->op() == Bytecodes::_idiv) {578__ idiv(left.result(), right.result(), result_reg, tmp, info);579} else {580ShouldNotReachHere();581}582583__ move(result_reg, result);584} else {585// missing test if instr is commutative and if we should swap586LIRItem left(x->x(), this);587LIRItem right(x->y(), this);588LIRItem* left_arg = &left;589LIRItem* right_arg = &right;590if (x->is_commutative() && left.is_stack() && right.is_register()) {591// swap them if left is real stack (or cached) and right is real register(not cached)592left_arg = &right;593right_arg = &left;594}595596left_arg->load_item();597598// do not need to load right, as we can handle stack and constants599if (x->op() == Bytecodes::_imul ) {600// check if we can use shift instead601bool use_constant = false;602bool use_tmp = false;603if (right_arg->is_constant()) {604jint iconst = right_arg->get_jint_constant();605if (iconst > 0 && iconst < max_jint) {606if (is_power_of_2(iconst)) {607use_constant = true;608} else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {609use_constant = true;610use_tmp = true;611}612}613}614if (use_constant) {615right_arg->dont_load_item();616} else {617right_arg->load_item();618}619LIR_Opr tmp = LIR_OprFact::illegalOpr;620if (use_tmp) {621tmp = new_register(T_INT);622}623rlock_result(x);624625arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);626} else {627right_arg->dont_load_item();628rlock_result(x);629LIR_Opr tmp = LIR_OprFact::illegalOpr;630arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);631}632}633}634635636void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {637// when an operand with use count 1 is the left operand, then it is638// likely that no move for 2-operand-LIR-form is necessary639if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {640x->swap_operands();641}642643ValueTag tag = x->type()->tag();644assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");645switch (tag) {646case floatTag:647case doubleTag: do_ArithmeticOp_FPU(x); return;648case longTag: do_ArithmeticOp_Long(x); return;649case intTag: do_ArithmeticOp_Int(x); return;650}651ShouldNotReachHere();652}653654655// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr656void LIRGenerator::do_ShiftOp(ShiftOp* x) {657// count must always be in rcx658LIRItem value(x->x(), this);659LIRItem count(x->y(), this);660661ValueTag elemType = x->type()->tag();662bool must_load_count = !count.is_constant() || elemType == longTag;663if (must_load_count) {664// count for long must be in register665count.load_item_force(shiftCountOpr());666} else {667count.dont_load_item();668}669value.load_item();670LIR_Opr reg = rlock_result(x);671672shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);673}674675676// _iand, _land, _ior, _lor, _ixor, _lxor677void LIRGenerator::do_LogicOp(LogicOp* x) {678// when an operand with use count 1 is the left operand, then it is679// likely that no move for 2-operand-LIR-form is necessary680if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {681x->swap_operands();682}683684LIRItem left(x->x(), this);685LIRItem right(x->y(), this);686687left.load_item();688right.load_nonconstant();689LIR_Opr reg = rlock_result(x);690691logic_op(x->op(), reg, left.result(), right.result());692}693694695696// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg697void LIRGenerator::do_CompareOp(CompareOp* x) {698LIRItem left(x->x(), this);699LIRItem right(x->y(), this);700ValueTag tag = x->x()->type()->tag();701if (tag == longTag) {702left.set_destroys_register();703}704left.load_item();705right.load_item();706LIR_Opr reg = rlock_result(x);707708if (x->x()->type()->is_float_kind()) {709Bytecodes::Code code = x->op();710__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));711} else if (x->x()->type()->tag() == longTag) {712__ lcmp2int(left.result(), right.result(), reg);713} else {714Unimplemented();715}716}717718719void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {720assert(x->number_of_arguments() == 4, "wrong type");721LIRItem obj (x->argument_at(0), this); // object722LIRItem offset(x->argument_at(1), this); // offset of field723LIRItem cmp (x->argument_at(2), this); // value to compare with field724LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp725726assert(obj.type()->tag() == objectTag, "invalid type");727728// In 64bit the type can be long, sparc doesn't have this assert729// assert(offset.type()->tag() == intTag, "invalid type");730731assert(cmp.type()->tag() == type->tag(), "invalid type");732assert(val.type()->tag() == type->tag(), "invalid type");733734// get address of field735obj.load_item();736offset.load_nonconstant();737738if (type == objectType) {739cmp.load_item_force(FrameMap::rax_oop_opr);740val.load_item();741} else if (type == intType) {742cmp.load_item_force(FrameMap::rax_opr);743val.load_item();744} else if (type == longType) {745cmp.load_item_force(FrameMap::long0_opr);746val.load_item_force(FrameMap::long1_opr);747} else {748ShouldNotReachHere();749}750751LIR_Opr addr = new_pointer_register();752LIR_Address* a;753if(offset.result()->is_constant()) {754#ifdef _LP64755jlong c = offset.result()->as_jlong();756if ((jlong)((jint)c) == c) {757a = new LIR_Address(obj.result(),758(jint)c,759as_BasicType(type));760} else {761LIR_Opr tmp = new_register(T_LONG);762__ move(offset.result(), tmp);763a = new LIR_Address(obj.result(),764tmp,765as_BasicType(type));766}767#else768a = new LIR_Address(obj.result(),769offset.result()->as_jint(),770as_BasicType(type));771#endif772} else {773a = new LIR_Address(obj.result(),774offset.result(),775LIR_Address::times_1,7760,777as_BasicType(type));778}779__ leal(LIR_OprFact::address(a), addr);780781if (type == objectType) { // Write-barrier needed for Object fields.782// Do the pre-write barrier, if any.783pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,784true /* do_load */, false /* patch */, NULL);785}786787LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience788if (type == objectType)789__ cas_obj(addr, cmp.result(), val.result(), ill, ill);790else if (type == intType)791__ cas_int(addr, cmp.result(), val.result(), ill, ill);792else if (type == longType)793__ cas_long(addr, cmp.result(), val.result(), ill, ill);794else {795ShouldNotReachHere();796}797798// generate conditional move of boolean result799LIR_Opr result = rlock_result(x);800__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),801result, as_BasicType(type));802if (type == objectType) { // Write-barrier needed for Object fields.803// Seems to be precise804post_barrier(addr, val.result());805}806}807808809void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {810assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");811LIRItem value(x->argument_at(0), this);812813bool use_fpu = false;814if (UseSSE >= 2) {815switch(x->id()) {816case vmIntrinsics::_dsin:817case vmIntrinsics::_dcos:818case vmIntrinsics::_dtan:819case vmIntrinsics::_dlog:820case vmIntrinsics::_dlog10:821case vmIntrinsics::_dexp:822case vmIntrinsics::_dpow:823use_fpu = true;824}825} else {826value.set_destroys_register();827}828829value.load_item();830831LIR_Opr calc_input = value.result();832LIR_Opr calc_input2 = NULL;833if (x->id() == vmIntrinsics::_dpow) {834LIRItem extra_arg(x->argument_at(1), this);835if (UseSSE < 2) {836extra_arg.set_destroys_register();837}838extra_arg.load_item();839calc_input2 = extra_arg.result();840}841LIR_Opr calc_result = rlock_result(x);842843// sin, cos, pow and exp need two free fpu stack slots, so register844// two temporary operands845LIR_Opr tmp1 = FrameMap::caller_save_fpu_reg_at(0);846LIR_Opr tmp2 = FrameMap::caller_save_fpu_reg_at(1);847848if (use_fpu) {849LIR_Opr tmp = FrameMap::fpu0_double_opr;850int tmp_start = 1;851if (calc_input2 != NULL) {852__ move(calc_input2, tmp);853tmp_start = 2;854calc_input2 = tmp;855}856__ move(calc_input, tmp);857858calc_input = tmp;859calc_result = tmp;860861tmp1 = FrameMap::caller_save_fpu_reg_at(tmp_start);862tmp2 = FrameMap::caller_save_fpu_reg_at(tmp_start + 1);863}864865switch(x->id()) {866case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, LIR_OprFact::illegalOpr); break;867case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;868case vmIntrinsics::_dsin: __ sin (calc_input, calc_result, tmp1, tmp2); break;869case vmIntrinsics::_dcos: __ cos (calc_input, calc_result, tmp1, tmp2); break;870case vmIntrinsics::_dtan: __ tan (calc_input, calc_result, tmp1, tmp2); break;871case vmIntrinsics::_dlog: __ log (calc_input, calc_result, tmp1); break;872case vmIntrinsics::_dlog10: __ log10(calc_input, calc_result, tmp1); break;873case vmIntrinsics::_dexp: __ exp (calc_input, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;874case vmIntrinsics::_dpow: __ pow (calc_input, calc_input2, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;875default: ShouldNotReachHere();876}877878if (use_fpu) {879__ move(calc_result, x->operand());880}881}882883884void LIRGenerator::do_ArrayCopy(Intrinsic* x) {885assert(x->number_of_arguments() == 5, "wrong type");886887// Make all state_for calls early since they can emit code888CodeEmitInfo* info = state_for(x, x->state());889890LIRItem src(x->argument_at(0), this);891LIRItem src_pos(x->argument_at(1), this);892LIRItem dst(x->argument_at(2), this);893LIRItem dst_pos(x->argument_at(3), this);894LIRItem length(x->argument_at(4), this);895896// operands for arraycopy must use fixed registers, otherwise897// LinearScan will fail allocation (because arraycopy always needs a898// call)899900#ifndef _LP64901src.load_item_force (FrameMap::rcx_oop_opr);902src_pos.load_item_force (FrameMap::rdx_opr);903dst.load_item_force (FrameMap::rax_oop_opr);904dst_pos.load_item_force (FrameMap::rbx_opr);905length.load_item_force (FrameMap::rdi_opr);906LIR_Opr tmp = (FrameMap::rsi_opr);907#else908909// The java calling convention will give us enough registers910// so that on the stub side the args will be perfect already.911// On the other slow/special case side we call C and the arg912// positions are not similar enough to pick one as the best.913// Also because the java calling convention is a "shifted" version914// of the C convention we can process the java args trivially into C915// args without worry of overwriting during the xfer916917src.load_item_force (FrameMap::as_oop_opr(j_rarg0));918src_pos.load_item_force (FrameMap::as_opr(j_rarg1));919dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));920dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));921length.load_item_force (FrameMap::as_opr(j_rarg4));922923LIR_Opr tmp = FrameMap::as_opr(j_rarg5);924#endif // LP64925926set_no_result(x);927928int flags;929ciArrayKlass* expected_type;930arraycopy_helper(x, &flags, &expected_type);931932__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint933}934935void LIRGenerator::do_update_CRC32(Intrinsic* x) {936assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");937// Make all state_for calls early since they can emit code938LIR_Opr result = rlock_result(x);939int flags = 0;940switch (x->id()) {941case vmIntrinsics::_updateCRC32: {942LIRItem crc(x->argument_at(0), this);943LIRItem val(x->argument_at(1), this);944// val is destroyed by update_crc32945val.set_destroys_register();946crc.load_item();947val.load_item();948__ update_crc32(crc.result(), val.result(), result);949break;950}951case vmIntrinsics::_updateBytesCRC32:952case vmIntrinsics::_updateByteBufferCRC32: {953bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);954955LIRItem crc(x->argument_at(0), this);956LIRItem buf(x->argument_at(1), this);957LIRItem off(x->argument_at(2), this);958LIRItem len(x->argument_at(3), this);959buf.load_item();960off.load_nonconstant();961962LIR_Opr index = off.result();963int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;964if(off.result()->is_constant()) {965index = LIR_OprFact::illegalOpr;966offset += off.result()->as_jint();967}968LIR_Opr base_op = buf.result();969970#ifndef _LP64971if (!is_updateBytes) { // long b raw address972base_op = new_register(T_INT);973__ convert(Bytecodes::_l2i, buf.result(), base_op);974}975#else976if (index->is_valid()) {977LIR_Opr tmp = new_register(T_LONG);978__ convert(Bytecodes::_i2l, index, tmp);979index = tmp;980}981#endif982983LIR_Address* a = new LIR_Address(base_op,984index,985LIR_Address::times_1,986offset,987T_BYTE);988BasicTypeList signature(3);989signature.append(T_INT);990signature.append(T_ADDRESS);991signature.append(T_INT);992CallingConvention* cc = frame_map()->c_calling_convention(&signature);993const LIR_Opr result_reg = result_register_for(x->type());994995LIR_Opr addr = new_pointer_register();996__ leal(LIR_OprFact::address(a), addr);997998crc.load_item_force(cc->at(0));999__ move(addr, cc->at(1));1000len.load_item_force(cc->at(2));10011002__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1003__ move(result_reg, result);10041005break;1006}1007default: {1008ShouldNotReachHere();1009}1010}1011}10121013// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1014// _i2b, _i2c, _i2s1015LIR_Opr fixed_register_for(BasicType type) {1016switch (type) {1017case T_FLOAT: return FrameMap::fpu0_float_opr;1018case T_DOUBLE: return FrameMap::fpu0_double_opr;1019case T_INT: return FrameMap::rax_opr;1020case T_LONG: return FrameMap::long0_opr;1021default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;1022}1023}10241025void LIRGenerator::do_Convert(Convert* x) {1026// flags that vary for the different operations and different SSE-settings1027bool fixed_input = false, fixed_result = false, round_result = false, needs_stub = false;10281029switch (x->op()) {1030case Bytecodes::_i2l: // fall through1031case Bytecodes::_l2i: // fall through1032case Bytecodes::_i2b: // fall through1033case Bytecodes::_i2c: // fall through1034case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;10351036case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;1037case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;1038case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;1039case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;1040case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1041case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1042case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;1043case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;1044case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1045case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1046default: ShouldNotReachHere();1047}10481049LIRItem value(x->value(), this);1050value.load_item();1051LIR_Opr input = value.result();1052LIR_Opr result = rlock(x);10531054// arguments of lir_convert1055LIR_Opr conv_input = input;1056LIR_Opr conv_result = result;1057ConversionStub* stub = NULL;10581059if (fixed_input) {1060conv_input = fixed_register_for(input->type());1061__ move(input, conv_input);1062}10631064assert(fixed_result == false || round_result == false, "cannot set both");1065if (fixed_result) {1066conv_result = fixed_register_for(result->type());1067} else if (round_result) {1068result = new_register(result->type());1069set_vreg_flag(result, must_start_in_memory);1070}10711072if (needs_stub) {1073stub = new ConversionStub(x->op(), conv_input, conv_result);1074}10751076__ convert(x->op(), conv_input, conv_result, stub);10771078if (result != conv_result) {1079__ move(conv_result, result);1080}10811082assert(result->is_virtual(), "result must be virtual register");1083set_result(x, result);1084}108510861087void LIRGenerator::do_NewInstance(NewInstance* x) {1088print_if_not_loaded(x);10891090CodeEmitInfo* info = state_for(x, x->state());1091LIR_Opr reg = result_register_for(x->type());1092new_instance(reg, x->klass(), x->is_unresolved(),1093FrameMap::rcx_oop_opr,1094FrameMap::rdi_oop_opr,1095FrameMap::rsi_oop_opr,1096LIR_OprFact::illegalOpr,1097FrameMap::rdx_metadata_opr, info);1098LIR_Opr result = rlock_result(x);1099__ move(reg, result);1100}110111021103void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1104CodeEmitInfo* info = state_for(x, x->state());11051106LIRItem length(x->length(), this);1107length.load_item_force(FrameMap::rbx_opr);11081109LIR_Opr reg = result_register_for(x->type());1110LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1111LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1112LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1113LIR_Opr tmp4 = reg;1114LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;1115LIR_Opr len = length.result();1116BasicType elem_type = x->elt_type();11171118__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);11191120CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1121__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);11221123LIR_Opr result = rlock_result(x);1124__ move(reg, result);1125}112611271128void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1129LIRItem length(x->length(), this);1130// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1131// and therefore provide the state before the parameters have been consumed1132CodeEmitInfo* patching_info = NULL;1133if (!x->klass()->is_loaded() || PatchALot) {1134patching_info = state_for(x, x->state_before());1135}11361137CodeEmitInfo* info = state_for(x, x->state());11381139const LIR_Opr reg = result_register_for(x->type());1140LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1141LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1142LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1143LIR_Opr tmp4 = reg;1144LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;11451146length.load_item_force(FrameMap::rbx_opr);1147LIR_Opr len = length.result();11481149CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1150ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1151if (obj == ciEnv::unloaded_ciobjarrayklass()) {1152BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1153}1154klass2reg_with_patching(klass_reg, obj, patching_info);1155__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);11561157LIR_Opr result = rlock_result(x);1158__ move(reg, result);1159}116011611162void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1163Values* dims = x->dims();1164int i = dims->length();1165LIRItemList* items = new LIRItemList(dims->length(), NULL);1166while (i-- > 0) {1167LIRItem* size = new LIRItem(dims->at(i), this);1168items->at_put(i, size);1169}11701171// Evaluate state_for early since it may emit code.1172CodeEmitInfo* patching_info = NULL;1173if (!x->klass()->is_loaded() || PatchALot) {1174patching_info = state_for(x, x->state_before());11751176// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1177// clone all handlers (NOTE: Usually this is handled transparently1178// by the CodeEmitInfo cloning logic in CodeStub constructors but1179// is done explicitly here because a stub isn't being used).1180x->set_exception_handlers(new XHandlers(x->exception_handlers()));1181}1182CodeEmitInfo* info = state_for(x, x->state());11831184i = dims->length();1185while (i-- > 0) {1186LIRItem* size = items->at(i);1187size->load_nonconstant();11881189store_stack_parameter(size->result(), in_ByteSize(i*4));1190}11911192LIR_Opr klass_reg = FrameMap::rax_metadata_opr;1193klass2reg_with_patching(klass_reg, x->klass(), patching_info);11941195LIR_Opr rank = FrameMap::rbx_opr;1196__ move(LIR_OprFact::intConst(x->rank()), rank);1197LIR_Opr varargs = FrameMap::rcx_opr;1198__ move(FrameMap::rsp_opr, varargs);1199LIR_OprList* args = new LIR_OprList(3);1200args->append(klass_reg);1201args->append(rank);1202args->append(varargs);1203LIR_Opr reg = result_register_for(x->type());1204__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1205LIR_OprFact::illegalOpr,1206reg, args, info);12071208LIR_Opr result = rlock_result(x);1209__ move(reg, result);1210}121112121213void LIRGenerator::do_BlockBegin(BlockBegin* x) {1214// nothing to do for now1215}121612171218void LIRGenerator::do_CheckCast(CheckCast* x) {1219LIRItem obj(x->obj(), this);12201221CodeEmitInfo* patching_info = NULL;1222if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {1223// must do this before locking the destination register as an oop register,1224// and before the obj is loaded (the latter is for deoptimization)1225patching_info = state_for(x, x->state_before());1226}1227obj.load_item();12281229// info for exceptions1230CodeEmitInfo* info_for_exception =1231(x->needs_exception_state() ? state_for(x) :1232state_for(x, x->state_before(), true /*ignore_xhandler*/));12331234CodeStub* stub;1235if (x->is_incompatible_class_change_check()) {1236assert(patching_info == NULL, "can't patch this");1237stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1238} else if (x->is_invokespecial_receiver_check()) {1239assert(patching_info == NULL, "can't patch this");1240stub = new DeoptimizeStub(info_for_exception);1241} else {1242stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1243}1244LIR_Opr reg = rlock_result(x);1245LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1246if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1247tmp3 = new_register(objectType);1248}1249__ checkcast(reg, obj.result(), x->klass(),1250new_register(objectType), new_register(objectType), tmp3,1251x->direct_compare(), info_for_exception, patching_info, stub,1252x->profiled_method(), x->profiled_bci());1253}125412551256void LIRGenerator::do_InstanceOf(InstanceOf* x) {1257LIRItem obj(x->obj(), this);12581259// result and test object may not be in same register1260LIR_Opr reg = rlock_result(x);1261CodeEmitInfo* patching_info = NULL;1262if ((!x->klass()->is_loaded() || PatchALot)) {1263// must do this before locking the destination register as an oop register1264patching_info = state_for(x, x->state_before());1265}1266obj.load_item();1267LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1268if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1269tmp3 = new_register(objectType);1270}1271__ instanceof(reg, obj.result(), x->klass(),1272new_register(objectType), new_register(objectType), tmp3,1273x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1274}127512761277void LIRGenerator::do_If(If* x) {1278assert(x->number_of_sux() == 2, "inconsistency");1279ValueTag tag = x->x()->type()->tag();1280bool is_safepoint = x->is_safepoint();12811282If::Condition cond = x->cond();12831284LIRItem xitem(x->x(), this);1285LIRItem yitem(x->y(), this);1286LIRItem* xin = &xitem;1287LIRItem* yin = &yitem;12881289if (tag == longTag) {1290// for longs, only conditions "eql", "neq", "lss", "geq" are valid;1291// mirror for other conditions1292if (cond == If::gtr || cond == If::leq) {1293cond = Instruction::mirror(cond);1294xin = &yitem;1295yin = &xitem;1296}1297xin->set_destroys_register();1298}1299xin->load_item();1300if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {1301// inline long zero1302yin->dont_load_item();1303} else if (tag == longTag || tag == floatTag || tag == doubleTag) {1304// longs cannot handle constants at right side1305yin->load_item();1306} else {1307yin->dont_load_item();1308}13091310// add safepoint before generating condition code so it can be recomputed1311if (x->is_safepoint()) {1312// increment backedge counter if needed1313increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());1314__ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));1315}1316set_no_result(x);13171318LIR_Opr left = xin->result();1319LIR_Opr right = yin->result();1320__ cmp(lir_cond(cond), left, right);1321// Generate branch profiling. Profiling code doesn't kill flags.1322profile_branch(x, cond);1323move_to_phi(x->state());1324if (x->x()->type()->is_float_kind()) {1325__ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());1326} else {1327__ branch(lir_cond(cond), right->type(), x->tsux());1328}1329assert(x->default_sux() == x->fsux(), "wrong destination above");1330__ jump(x->default_sux());1331}133213331334LIR_Opr LIRGenerator::getThreadPointer() {1335#ifdef _LP641336return FrameMap::as_pointer_opr(r15_thread);1337#else1338LIR_Opr result = new_register(T_INT);1339__ get_thread(result);1340return result;1341#endif //1342}13431344void LIRGenerator::trace_block_entry(BlockBegin* block) {1345store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));1346LIR_OprList* args = new LIR_OprList();1347address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1348__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1349}135013511352void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1353CodeEmitInfo* info) {1354if (address->type() == T_LONG) {1355address = new LIR_Address(address->base(),1356address->index(), address->scale(),1357address->disp(), T_DOUBLE);1358// Transfer the value atomically by using FP moves. This means1359// the value has to be moved between CPU and FPU registers. It1360// always has to be moved through spill slot since there's no1361// quick way to pack the value into an SSE register.1362LIR_Opr temp_double = new_register(T_DOUBLE);1363LIR_Opr spill = new_register(T_LONG);1364set_vreg_flag(spill, must_start_in_memory);1365__ move(value, spill);1366__ volatile_move(spill, temp_double, T_LONG);1367__ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);1368} else {1369__ store(value, address, info);1370}1371}1372137313741375void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1376CodeEmitInfo* info) {1377if (address->type() == T_LONG) {1378address = new LIR_Address(address->base(),1379address->index(), address->scale(),1380address->disp(), T_DOUBLE);1381// Transfer the value atomically by using FP moves. This means1382// the value has to be moved between CPU and FPU registers. In1383// SSE0 and SSE1 mode it has to be moved through spill slot but in1384// SSE2+ mode it can be moved directly.1385LIR_Opr temp_double = new_register(T_DOUBLE);1386__ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);1387__ volatile_move(temp_double, result, T_LONG);1388if (UseSSE < 2) {1389// no spill slot needed in SSE2 mode because xmm->cpu register move is possible1390set_vreg_flag(result, must_start_in_memory);1391}1392} else {1393__ load(address, result, info);1394}1395}13961397void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,1398BasicType type, bool is_volatile) {1399if (is_volatile && type == T_LONG) {1400LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);1401LIR_Opr tmp = new_register(T_DOUBLE);1402__ load(addr, tmp);1403LIR_Opr spill = new_register(T_LONG);1404set_vreg_flag(spill, must_start_in_memory);1405__ move(tmp, spill);1406__ move(spill, dst);1407} else {1408LIR_Address* addr = new LIR_Address(src, offset, type);1409__ load(addr, dst);1410}1411}141214131414void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,1415BasicType type, bool is_volatile) {1416if (is_volatile && type == T_LONG) {1417LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);1418LIR_Opr tmp = new_register(T_DOUBLE);1419LIR_Opr spill = new_register(T_DOUBLE);1420set_vreg_flag(spill, must_start_in_memory);1421__ move(data, spill);1422__ move(spill, tmp);1423__ move(tmp, addr);1424} else {1425LIR_Address* addr = new LIR_Address(src, offset, type);1426bool is_obj = (type == T_ARRAY || type == T_OBJECT);1427if (is_obj) {1428// Do the pre-write barrier, if any.1429pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1430true /* do_load */, false /* patch */, NULL);1431__ move(data, addr);1432assert(src->is_register(), "must be register");1433// Seems to be a precise address1434post_barrier(LIR_OprFact::address(addr), data);1435} else {1436__ move(data, addr);1437}1438}1439}14401441void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {1442BasicType type = x->basic_type();1443LIRItem src(x->object(), this);1444LIRItem off(x->offset(), this);1445LIRItem value(x->value(), this);14461447src.load_item();1448value.load_item();1449off.load_nonconstant();14501451LIR_Opr dst = rlock_result(x, type);1452LIR_Opr data = value.result();1453bool is_obj = (type == T_ARRAY || type == T_OBJECT);1454LIR_Opr offset = off.result();14551456assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");1457LIR_Address* addr;1458if (offset->is_constant()) {1459#ifdef _LP641460jlong c = offset->as_jlong();1461if ((jlong)((jint)c) == c) {1462addr = new LIR_Address(src.result(), (jint)c, type);1463} else {1464LIR_Opr tmp = new_register(T_LONG);1465__ move(offset, tmp);1466addr = new LIR_Address(src.result(), tmp, type);1467}1468#else1469addr = new LIR_Address(src.result(), offset->as_jint(), type);1470#endif1471} else {1472addr = new LIR_Address(src.result(), offset, type);1473}14741475// Because we want a 2-arg form of xchg and xadd1476__ move(data, dst);14771478if (x->is_add()) {1479__ xadd(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);1480} else {1481if (is_obj) {1482// Do the pre-write barrier, if any.1483pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1484true /* do_load */, false /* patch */, NULL);1485}1486__ xchg(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);1487if (is_obj) {1488// Seems to be a precise address1489post_barrier(LIR_OprFact::address(addr), data);1490}1491}1492}149314941495