Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch32/vm/c1_LIRGenerator_aarch32.cpp
32285 views
/*1* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2014, Red Hat Inc. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/24// This file is a derivative work resulting from (and including) modifications25// made by Azul Systems, Inc. The dates of such changes are 2013-2016.26// Copyright 2013-2016 Azul Systems, Inc. All Rights Reserved.27//28// Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale,29// CA 94089 USA or visit www.azul.com if you need additional information or30// have any questions.3132#include "precompiled.hpp"33#include "c1/c1_Compilation.hpp"34#include "c1/c1_FrameMap.hpp"35#include "c1/c1_Instruction.hpp"36#include "c1/c1_LIRAssembler.hpp"37#include "c1/c1_LIRGenerator.hpp"38#include "c1/c1_Runtime1.hpp"39#include "c1/c1_ValueStack.hpp"40#include "ci/ciArray.hpp"41#include "ci/ciObjArrayKlass.hpp"42#include "ci/ciTypeArrayKlass.hpp"43#include "runtime/sharedRuntime.hpp"44#include "runtime/stubRoutines.hpp"45#include "vmreg_aarch32.inline.hpp"46#include "vm_version_aarch32.hpp"4748#ifdef ASSERT49#define __ gen()->lir(__FILE__, __LINE__)->50#else51#define __ gen()->lir()->52#endif5354// Item will be loaded into a byte register; Intel only55void LIRItem::load_byte_item() {56load_item();57}585960void LIRItem::load_nonconstant() {61LIR_Opr r = value()->operand();62if (r->is_constant()) {63_result = r;64} else {65load_item();66}67}6869//--------------------------------------------------------------70// LIRGenerator71//--------------------------------------------------------------727374LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::r0_oop_opr; }75LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::r3_opr; }76LIR_Opr LIRGenerator::divInOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }77LIR_Opr LIRGenerator::divOutOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }78LIR_Opr LIRGenerator::remOutOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }79LIR_Opr LIRGenerator::shiftCountOpr() { Unimplemented(); return LIR_OprFact::illegalOpr; }80LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::r0_opr; }81LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }828384LIR_Opr LIRGenerator::java_result_register_for(ValueType* type, bool callee) {85LIR_Opr opr;86switch (type->tag()) {87case floatTag:88if(hasFPU()) {89opr = FrameMap::fpu0_float_opr; break;;90}91case doubleTag:92if(hasFPU()) {93opr = FrameMap::fpu0_double_opr; break;94}95default: opr = result_register_for(type, callee);96}97return opr;98}99LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {100LIR_Opr opr;101switch (type->tag()) {102case floatTag:103#ifdef HARD_FLOAT_CC104opr = FrameMap::fpu0_float_opr; break;105#endif106case intTag: opr = FrameMap::r0_opr; break;107case objectTag: opr = FrameMap::r0_oop_opr; break;108case doubleTag:109#ifdef HARD_FLOAT_CC110opr = FrameMap::fpu0_double_opr; break;111#endif112case longTag: opr = FrameMap::long0_opr; break;113114case addressTag:115default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;116}117#ifndef HARD_FLOAT_CC118assert(type->is_float_kind() || opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");119#else120assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");121#endif122return opr;123}124125126LIR_Opr LIRGenerator::rlock_byte(BasicType type) {127LIR_Opr reg = new_register(T_INT);128set_vreg_flag(reg, LIRGenerator::byte_reg);129return reg;130}131132133//--------- loading items into registers --------------------------------134135136bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {137if (v->type()->as_IntConstant() != NULL) {138return v->type()->as_IntConstant()->value() == 0L;139} else if (v->type()->as_LongConstant() != NULL) {140return v->type()->as_LongConstant()->value() == 0L;141} else if (v->type()->as_ObjectConstant() != NULL) {142return v->type()->as_ObjectConstant()->value()->is_null_object();143} else {144return false;145}146}147148bool LIRGenerator::can_inline_as_constant(Value v) const {149if (v->type()->as_IntConstant() != NULL) {150return Assembler::operand_valid_for_add_sub_immediate(v->type()->as_IntConstant()->value());151} else if (v->type()->as_LongConstant() != NULL) {152return Assembler::operand_valid_for_add_sub_immediate(v->type()->as_LongConstant()->value());153} else if (v->type()->as_ObjectConstant() != NULL) {154return v->type()->as_ObjectConstant()->value()->is_null_object();155} else {156return false;157}158}159160161bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {162switch (c->type()) {163case T_BOOLEAN:164case T_CHAR:165case T_BYTE:166case T_SHORT:167case T_INT:168return Assembler::operand_valid_for_add_sub_immediate(c->as_jint());169case T_LONG:170return Assembler::operand_valid_for_add_sub_immediate(c->as_jlong());171172case T_OBJECT:173return c->as_jobject() == (jobject) NULL;174case T_METADATA:175return c->as_metadata() == (Metadata*) NULL;176177case T_FLOAT:178if( hasFPU()) {179return Assembler::operand_valid_for_float_immediate(c->as_jfloat());180} else {181return Assembler::operand_valid_for_add_sub_immediate(c->as_jint());182}183case T_DOUBLE:184if( hasFPU()) {185return Assembler::operand_valid_for_float_immediate(c->as_jdouble());186} else {187return Assembler::operand_valid_for_add_sub_immediate(c->as_jlong());188}189}190return false;191}192193LIR_Opr LIRGenerator::safepoint_poll_register() {194return LIR_OprFact::illegalOpr;195}196197LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,198int shift, int disp, BasicType type) {199const Address::InsnDataType insn_type = Address::toInsnDataType(type);200assert(base->is_register(), "must be");201202// accumulate fixed displacements203if (index->is_constant()) {204disp += index->as_constant_ptr()->as_jint() << shift;205index = LIR_OprFact::illegalOpr;206shift = 0;207}208209// aarch32 cannot handle natively both index and offset at the same time210// need to calculate effective value211if (index->is_register()) {212if ((disp != 0) &&213Address::shift_ok_for_index(lsl(shift), insn_type) &&214Assembler::operand_valid_for_add_sub_immediate(disp)) {215// add tmp, base, disp216// ldr r, [tmp, index, LSL #shift ]217LIR_Opr tmp = new_pointer_register();218__ add(base, LIR_OprFact::intptrConst(disp), tmp);219base = tmp;220disp = 0;221} else {222assert(shift <= (int) LIR_Address::times_8, "no large shift could be here");223// add tmp, base, index, LSL #shift224// ...225// ldr r, [tmp, ...]226LIR_Opr tmp = new_pointer_register();227__ leal(LIR_OprFact::address(new LIR_Address(base, index, (LIR_Address::Scale) shift, 0, type)), tmp);228base = tmp;229index = LIR_OprFact::illegalOpr;230shift = 0;231}232}233234assert(!index->is_register() || (disp == 0), "should be");235236if (!Address::offset_ok_for_immed(disp, insn_type)) {237assert(!index->is_valid(), "should be");238// here index should be illegal so we can replace it with the displacement239// loaded into a register240// mov tmp, disp241// ldr r, [base, tmp]242index = new_pointer_register();243__ move(LIR_OprFact::intptrConst(disp), index);244disp = 0;245}246247assert(Address::offset_ok_for_immed(disp, Address::toInsnDataType(type)), "must be");248return new LIR_Address(base, index, (LIR_Address::Scale) shift, disp, type);249}250251252LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,253BasicType type, bool needs_card_mark) {254int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);255int elem_size = type2aelembytes(type);256int shift = exact_log2(elem_size);257258LIR_Address* addr = generate_address(array_opr, index_opr, shift, offset_in_bytes, type);259260if (needs_card_mark) {261// This store will need a precise card mark, so go ahead and262// compute the full adddres instead of computing once for the263// store and again for the card mark.264LIR_Opr tmp = new_pointer_register();265__ leal(LIR_OprFact::address(addr), tmp);266return new LIR_Address(tmp, type);267} else {268return addr;269}270}271272LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {273LIR_Opr r;274if (type == T_LONG) {275r = LIR_OprFact::longConst(x);276if (!Assembler::operand_valid_for_logical_immediate(false, x)) {277LIR_Opr tmp = new_register(type);278__ move(r, tmp);279return tmp;280}281} else if (type == T_INT) {282r = LIR_OprFact::intConst(x);283if (!Assembler::operand_valid_for_logical_immediate(true, x)) {284// This is all rather nasty. We don't know whether our constant285// is required for a logical or an arithmetic operation, wo we286// don't know what the range of valid values is!!287LIR_Opr tmp = new_register(type);288__ move(r, tmp);289return tmp;290}291} else {292ShouldNotReachHere();293}294return r;295}296297298299void LIRGenerator::increment_counter(address counter, BasicType type, int step) {300LIR_Opr pointer = new_pointer_register();301__ move(LIR_OprFact::intptrConst(counter), pointer);302LIR_Address* addr = new LIR_Address(pointer, type);303increment_counter(addr, step);304}305306307void LIRGenerator::increment_counter(LIR_Address* addr, int step) {308LIR_Opr imm = NULL;309switch(addr->type()) {310case T_INT:311imm = LIR_OprFact::intConst(step);312break;313case T_LONG:314imm = LIR_OprFact::longConst(step);315break;316default:317ShouldNotReachHere();318}319LIR_Opr reg = new_register(addr->type());320__ load(addr, reg);321__ add(reg, imm, reg);322__ store(reg, addr);323}324325void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {326LIR_Opr reg = new_register(T_INT);327__ load(generate_address(base, disp, T_INT), reg, info);328__ cmp(condition, reg, LIR_OprFact::intConst(c));329}330331void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {332LIR_Opr reg1 = new_register(T_INT);333__ load(generate_address(base, disp, type), reg1, info);334__ cmp(condition, reg, reg1);335}336337338bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {339340if (is_power_of_2(c - 1)) {341__ shift_left(left, exact_log2(c - 1), tmp);342__ add(tmp, left, result);343return true;344} else if (is_power_of_2(c + 1)) {345__ shift_left(left, exact_log2(c + 1), tmp);346__ sub(tmp, left, result);347return true;348} else {349return false;350}351}352353void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {354BasicType type = item->type();355__ store(item, new LIR_Address(FrameMap::sp_opr, in_bytes(offset_from_sp), type));356}357358//----------------------------------------------------------------------359// visitor functions360//----------------------------------------------------------------------361362363void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {364assert(x->is_pinned(),"");365bool needs_range_check = x->compute_needs_range_check();366bool use_length = x->length() != NULL;367bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;368bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||369!get_jobject_constant(x->value())->is_null_object() ||370x->should_profile());371372LIRItem array(x->array(), this);373LIRItem index(x->index(), this);374LIRItem value(x->value(), this);375LIRItem length(this);376377array.load_item();378index.load_nonconstant();379380if (use_length && needs_range_check) {381length.set_instruction(x->length());382length.load_item();383384}385if (needs_store_check || x->check_boolean()) {386value.load_item();387} else {388value.load_for_store(x->elt_type());389}390391set_no_result(x);392393// the CodeEmitInfo must be duplicated for each different394// LIR-instruction because spilling can occur anywhere between two395// instructions and so the debug information must be different396CodeEmitInfo* range_check_info = state_for(x);397CodeEmitInfo* null_check_info = NULL;398if (x->needs_null_check()) {399null_check_info = new CodeEmitInfo(range_check_info);400}401402// emit array address setup early so it schedules better403// FIXME? No harm in this on aarch64, and it might help404LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);405406if (GenerateRangeChecks && needs_range_check) {407if (use_length) {408__ cmp(lir_cond_belowEqual, length.result(), index.result());409__ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));410} else {411array_range_check(array.result(), index.result(), null_check_info, range_check_info);412// range_check also does the null check413null_check_info = NULL;414}415}416417if (GenerateArrayStoreCheck && needs_store_check) {418LIR_Opr tmp1 = new_register(objectType);419LIR_Opr tmp2 = new_register(objectType);420LIR_Opr tmp3 = new_register(objectType);421422CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);423__ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());424}425426if (obj_store) {427// Needs GC write barriers.428pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,429true /* do_load */, false /* patch */, NULL);430__ move(value.result(), array_addr, null_check_info);431// Seems to be a precise432post_barrier(LIR_OprFact::address(array_addr), value.result());433} else {434LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);435__ move(result, array_addr, null_check_info);436}437}438439void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {440assert(x->is_pinned(),"");441LIRItem obj(x->obj(), this);442obj.load_item();443444set_no_result(x);445446// "lock" stores the address of the monitor stack slot, so this is not an oop447LIR_Opr lock = new_register(T_INT);448// Need a scratch register for biased locking449LIR_Opr scratch = LIR_OprFact::illegalOpr;450if (UseBiasedLocking) {451scratch = new_register(T_INT);452}453454CodeEmitInfo* info_for_exception = NULL;455if (x->needs_null_check()) {456info_for_exception = state_for(x);457}458// this CodeEmitInfo must not have the xhandlers because here the459// object is already locked (xhandlers expect object to be unlocked)460CodeEmitInfo* info = state_for(x, x->state(), true);461monitor_enter(obj.result(), lock, syncTempOpr(), scratch,462x->monitor_no(), info_for_exception, info);463}464465466void LIRGenerator::do_MonitorExit(MonitorExit* x) {467assert(x->is_pinned(),"");468469LIRItem obj(x->obj(), this);470obj.dont_load_item();471472LIR_Opr lock = new_register(T_INT);473LIR_Opr obj_temp = new_register(T_INT);474set_no_result(x);475monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());476}477478479void LIRGenerator::do_NegateOp(NegateOp* x) {480#ifdef __SOFTFP__481if(x->x()->type()->is_float_kind() && !(hasFPU())) {482address entry;483if (x->x()->type()->is_float()) {484entry = CAST_FROM_FN_PTR(address, SharedRuntime::fneg);485} else {486entry = CAST_FROM_FN_PTR(address, SharedRuntime::dneg);487}488LIR_Opr result = call_runtime(x->x(), entry, x->type(), NULL);489set_result(x, result);490} else491#endif492{493LIRItem from(x->x(), this);494from.load_item();495LIR_Opr result = rlock_result(x);496__ negate (from.result(), result);497}498}499500// for _fadd, _fmul, _fsub, _fdiv, _frem501// _dadd, _dmul, _dsub, _ddiv, _drem502void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {503504if (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem) {505address entry;506if (x->op() == Bytecodes::_frem) {507entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);508} else {509entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);510}511LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);512set_result(x, result);513514return;515}516517if(hasFPU()) {518LIRItem left(x->x(), this);519LIRItem right(x->y(), this);520LIRItem* left_arg = &left;521LIRItem* right_arg = &right;522523// Always load right hand side.524right.load_item();525526if (!left.is_register())527left.load_item();528529LIR_Opr reg = rlock(x);530LIR_Opr tmp = LIR_OprFact::illegalOpr;531if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {532tmp = new_register(T_DOUBLE);533}534535arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), NULL);536537set_result(x, round_item(reg));538} else {539#ifdef __SOFTFP__540address entry;541542switch (x->op()) {543case Bytecodes::_fmul:544entry = CAST_FROM_FN_PTR(address, SharedRuntime::fmul);545break;546case Bytecodes::_dmul:547entry = CAST_FROM_FN_PTR(address, SharedRuntime::dmul);548break;549case Bytecodes::_fdiv:550entry = CAST_FROM_FN_PTR(address, SharedRuntime::fdiv);551break;552case Bytecodes::_ddiv:553entry = CAST_FROM_FN_PTR(address, SharedRuntime::ddiv);554break;555case Bytecodes::_fadd:556entry = CAST_FROM_FN_PTR(address, SharedRuntime::fadd);557break;558case Bytecodes::_dadd:559entry = CAST_FROM_FN_PTR(address, SharedRuntime::dadd);560break;561case Bytecodes::_fsub:562entry = CAST_FROM_FN_PTR(address, SharedRuntime::fsub);563break;564case Bytecodes::_dsub:565entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsub);566break;567default:568ShouldNotReachHere();569}570LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);571set_result(x, result);572#else573ShouldNotReachHere();// check your compiler settings574#endif575}576}577578// for _ladd, _lmul, _lsub, _ldiv, _lrem579void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {580581// missing test if instr is commutative and if we should swap582LIRItem left(x->x(), this);583LIRItem right(x->y(), this);584585if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {586587BasicTypeList signature(2);588signature.append(T_LONG);589signature.append(T_LONG);590CallingConvention* cc = frame_map()->c_calling_convention(&signature);591592// check for division by zero (destroys registers of right operand!)593CodeEmitInfo* info = state_for(x);594595right.load_item();596597__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));598__ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));599600const LIR_Opr result_reg = result_register_for(x->type());601left.load_item_force(cc->at(1));602__ move(right.result(), cc->at(0));603604address entry;605switch (x->op()) {606case Bytecodes::_lrem:607entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);608break; // check if dividend is 0 is done elsewhere609case Bytecodes::_ldiv:610entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);611break; // check if dividend is 0 is done elsewhere612default:613ShouldNotReachHere();614}615616LIR_Opr result = rlock_result(x);617__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());618__ move(result_reg, result);619} else {620assert (x->op() == Bytecodes::_lmul || x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub,621"expect lmul, ladd or lsub");622// add, sub, mul623left.load_item();624if (! right.is_register()) {625if (x->op() == Bytecodes::_lmul626|| ! right.is_constant()627|| ! Assembler::operand_valid_for_add_sub_immediate(right.get_jlong_constant())) {628right.load_item();629} else { // add, sub630assert (x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub, "expect ladd or lsub");631// don't load constants to save register632right.load_nonconstant();633}634}635rlock_result(x);636arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);637}638}639640// for: _iadd, _imul, _isub, _idiv, _irem641void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {642643// Test if instr is commutative and if we should swap644LIRItem left(x->x(), this);645LIRItem right(x->y(), this);646LIRItem* left_arg = &left;647LIRItem* right_arg = &right;648if (x->is_commutative() && left.is_stack() && right.is_register()) {649// swap them if left is real stack (or cached) and right is real register(not cached)650left_arg = &right;651right_arg = &left;652}653654left_arg->load_item();655656// do not need to load right, as we can handle stack and constants657if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {658659right_arg->load_item();660rlock_result(x);661662if (!(VM_Version::features() & FT_HW_DIVIDE)) {663// MacroAssembler::divide32 destroys both operand registers664left_arg->set_destroys_register();665right_arg->set_destroys_register();666}667668CodeEmitInfo* info = state_for(x);669LIR_Opr tmp = new_register(T_INT);670__ cmp(lir_cond_equal, right_arg->result(), LIR_OprFact::intConst(0));671__ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));672info = state_for(x);673674if (x->op() == Bytecodes::_irem) {675__ irem(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);676} else if (x->op() == Bytecodes::_idiv) {677__ idiv(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);678}679680} else if (x->op() == Bytecodes::_iadd || x->op() == Bytecodes::_isub) {681if (right.is_constant()682&& Assembler::operand_valid_for_add_sub_immediate(right.get_jint_constant())) {683right.load_nonconstant();684} else {685right.load_item();686}687rlock_result(x);688arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), LIR_OprFact::illegalOpr);689} else {690assert (x->op() == Bytecodes::_imul, "expect imul");691if (right.is_constant()) {692int c = right.get_jint_constant();693if (! is_power_of_2(c) && ! is_power_of_2(c + 1) && ! is_power_of_2(c - 1)) {694// Cannot use constant op.695right.load_item();696} else {697right.dont_load_item();698}699} else {700right.load_item();701}702rlock_result(x);703arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), new_register(T_INT));704}705}706707void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {708// when an operand with use count 1 is the left operand, then it is709// likely that no move for 2-operand-LIR-form is necessary710if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {711x->swap_operands();712}713714ValueTag tag = x->type()->tag();715assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");716switch (tag) {717case floatTag:718case doubleTag: do_ArithmeticOp_FPU(x); return;719case longTag: do_ArithmeticOp_Long(x); return;720case intTag: do_ArithmeticOp_Int(x); return;721}722ShouldNotReachHere();723}724725// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr726void LIRGenerator::do_ShiftOp(ShiftOp* x) {727728LIRItem left(x->x(), this);729LIRItem right(x->y(), this);730731left.load_item();732733rlock_result(x);734if (right.is_constant()) {735right.dont_load_item();736737switch (x->op()) {738case Bytecodes::_ishl: {739int c = right.get_jint_constant() & 0x1f;740__ shift_left(left.result(), c, x->operand());741break;742}743case Bytecodes::_ishr: {744int c = right.get_jint_constant() & 0x1f;745__ shift_right(left.result(), c, x->operand());746break;747}748case Bytecodes::_iushr: {749int c = right.get_jint_constant() & 0x1f;750__ unsigned_shift_right(left.result(), c, x->operand());751break;752}753case Bytecodes::_lshl: {754int c = right.get_jint_constant() & 0x3f;755__ shift_left(left.result(), c, x->operand());756break;757}758case Bytecodes::_lshr: {759int c = right.get_jint_constant() & 0x3f;760__ shift_right(left.result(), c, x->operand());761break;762}763case Bytecodes::_lushr: {764int c = right.get_jint_constant() & 0x3f;765__ unsigned_shift_right(left.result(), c, x->operand());766break;767}768default:769ShouldNotReachHere();770}771} else {772right.load_item();773LIR_Opr tmp = LIR_OprFact::illegalOpr;774if (left.result()->type() == T_LONG)775left.set_destroys_register();776switch (x->op()) {777case Bytecodes::_ishl: {778__ shift_left(left.result(), right.result(), x->operand(), tmp);779break;780}781case Bytecodes::_ishr: {782__ shift_right(left.result(), right.result(), x->operand(), tmp);783break;784}785case Bytecodes::_iushr: {786__ unsigned_shift_right(left.result(), right.result(), x->operand(), tmp);787break;788}789case Bytecodes::_lshl: {790__ shift_left(left.result(), right.result(), x->operand(), tmp);791break;792}793case Bytecodes::_lshr: {794__ shift_right(left.result(), right.result(), x->operand(), tmp);795break;796}797case Bytecodes::_lushr: {798__ unsigned_shift_right(left.result(), right.result(), x->operand(), tmp);799break;800}801default:802ShouldNotReachHere();803}804}805}806807// _iand, _land, _ior, _lor, _ixor, _lxor808void LIRGenerator::do_LogicOp(LogicOp* x) {809810LIRItem left(x->x(), this);811LIRItem right(x->y(), this);812813left.load_item();814815rlock_result(x);816if (right.is_constant()817&& ((right.type()->tag() == intTag818&& Assembler::operand_valid_for_logical_immediate(true, right.get_jint_constant()))819|| (right.type()->tag() == longTag820&& Assembler::operand_valid_for_logical_immediate(false, right.get_jlong_constant())))) {821right.dont_load_item();822} else {823right.load_item();824}825switch (x->op()) {826case Bytecodes::_iand:827case Bytecodes::_land:828__ logical_and(left.result(), right.result(), x->operand()); break;829case Bytecodes::_ior:830case Bytecodes::_lor:831__ logical_or (left.result(), right.result(), x->operand()); break;832case Bytecodes::_ixor:833case Bytecodes::_lxor:834__ logical_xor(left.result(), right.result(), x->operand()); break;835default: Unimplemented();836}837}838839// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg840void LIRGenerator::do_CompareOp(CompareOp* x) {841LIRItem left(x->x(), this);842LIRItem right(x->y(), this);843ValueTag tag = x->x()->type()->tag();844left.load_item();845right.load_item();846847if (x->x()->type()->is_float_kind()) {848Bytecodes::Code code = x->op();849if(hasFPU()) {850LIR_Opr reg = rlock_result(x);851__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));852} else {853#ifdef __SOFTFP__854address entry;855switch (code) {856case Bytecodes::_fcmpl:857entry = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpl);858break;859case Bytecodes::_fcmpg:860entry = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpg);861break;862case Bytecodes::_dcmpl:863entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpl);864break;865case Bytecodes::_dcmpg:866entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpg);867break;868default:869ShouldNotReachHere();870}871872LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);873set_result(x, result);874#else875ShouldNotReachHere(); // check your compiler settings876#endif877}878} else if (x->x()->type()->tag() == longTag) {879LIR_Opr reg = rlock_result(x);880__ lcmp2int(left.result(), right.result(), reg);881} else {882Unimplemented();883}884}885886void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {887assert(x->number_of_arguments() == 4, "wrong type");888LIRItem obj (x->argument_at(0), this); // object889LIRItem offset(x->argument_at(1), this); // offset of field890LIRItem cmp (x->argument_at(2), this); // value to compare with field891LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp892893assert(obj.type()->tag() == objectTag, "invalid type");894895// In 64bit the type can be long, sparc doesn't have this assert896// assert(offset.type()->tag() == intTag, "invalid type");897898assert(cmp.type()->tag() == type->tag(), "invalid type");899assert(val.type()->tag() == type->tag(), "invalid type");900901// get address of field902obj.load_item();903offset.load_nonconstant();904if (type == longType) {905// not need if allocator reserves correct pairs906val.load_item_force(FrameMap::long0_opr);907} else {908val.load_item();909}910cmp.load_item();911912LIR_Address* a;913if(offset.result()->is_constant()) {914jint c = offset.result()->as_jint();915a = new LIR_Address(obj.result(),916c,917as_BasicType(type));918} else {919a = new LIR_Address(obj.result(),920offset.result(),921LIR_Address::times_1,9220,923as_BasicType(type));924}925LIR_Opr addr = new_pointer_register();926__ leal(LIR_OprFact::address(a), addr);927928if (type == objectType) { // Write-barrier needed for Object fields.929// Do the pre-write barrier, if any.930pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,931true /* do_load */, false /* patch */, NULL);932}933934LIR_Opr result = rlock_result(x);935936LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience937if (type == objectType)938__ cas_obj(addr, cmp.result(), val.result(), ill, ill, result);939else if (type == intType)940__ cas_int(addr, cmp.result(), val.result(), ill, ill, result);941else if (type == longType)942__ cas_long(addr, cmp.result(), val.result(), FrameMap::long1_opr, ill,943result);944else {945ShouldNotReachHere();946}947948__ logical_xor(result, LIR_OprFact::intConst(1), result);949950if (type == objectType) { // Write-barrier needed for Object fields.951// Seems to be precise952post_barrier(addr, val.result());953}954}955956void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {957switch (x->id()) {958default:959ShouldNotReachHere();960break;961case vmIntrinsics::_dabs:962case vmIntrinsics::_dsqrt:963if(hasFPU()) {964assert(x->number_of_arguments() == 1, "wrong type");965LIRItem value(x->argument_at(0), this);966value.load_item();967LIR_Opr dst = rlock_result(x);968969switch (x->id()) {970case vmIntrinsics::_dsqrt: {971__ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);972break;973}974case vmIntrinsics::_dabs: {975__ abs(value.result(), dst, LIR_OprFact::illegalOpr);976break;977}978}979break;980}// fall through for FPU less cores981case vmIntrinsics::_dlog10: // fall through982case vmIntrinsics::_dlog: // fall through983case vmIntrinsics::_dsin: // fall through984case vmIntrinsics::_dtan: // fall through985case vmIntrinsics::_dcos: // fall through986case vmIntrinsics::_dexp: {987assert(x->number_of_arguments() == 1, "wrong type");988989address runtime_entry = NULL;990switch (x->id()) {991#ifdef __SOFTFP__992case vmIntrinsics::_dabs:993runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dabs);994break;995case vmIntrinsics::_dsqrt:996runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt);997break;998#endif999case vmIntrinsics::_dsin:1000runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);1001break;1002case vmIntrinsics::_dcos:1003runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);1004break;1005case vmIntrinsics::_dtan:1006runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);1007break;1008case vmIntrinsics::_dlog:1009runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);1010break;1011case vmIntrinsics::_dlog10:1012runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);1013break;1014case vmIntrinsics::_dexp:1015runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);1016break;1017default:1018ShouldNotReachHere();1019}10201021LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);1022set_result(x, result);1023break;1024}1025case vmIntrinsics::_dpow: {1026assert(x->number_of_arguments() == 2, "wrong type");1027address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);1028LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);1029set_result(x, result);1030break;1031}1032}1033}103410351036void LIRGenerator::do_ArrayCopy(Intrinsic* x) {1037assert(x->number_of_arguments() == 5, "wrong type");10381039// Make all state_for calls early since they can emit code1040CodeEmitInfo* info = state_for(x, x->state());10411042LIRItem src(x->argument_at(0), this);1043LIRItem src_pos(x->argument_at(1), this);1044LIRItem dst(x->argument_at(2), this);1045LIRItem dst_pos(x->argument_at(3), this);1046LIRItem length(x->argument_at(4), this);10471048// operands for arraycopy must use fixed registers, otherwise1049// LinearScan will fail allocation (because arraycopy always needs a1050// call)10511052// The java calling convention does not give us enough registers1053// so we occupy two more: r4 and r5. The fast path code will be able to1054// make use of these registers for performance purpose. If going into1055// slow path we'll spill extra data to the stack as necessary10561057src.load_item_force (FrameMap::as_oop_opr(j_rarg0));1058src_pos.load_item_force (FrameMap::as_opr(j_rarg1));1059dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));1060dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));10611062length.load_item_force (FrameMap::as_opr(r4));1063LIR_Opr tmp = FrameMap::as_opr(r5);10641065set_no_result(x);10661067int flags;1068ciArrayKlass* expected_type;1069arraycopy_helper(x, &flags, &expected_type);10701071__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint1072}10731074void LIRGenerator::do_update_CRC32(Intrinsic* x) {1075assert(UseCRC32Intrinsics, "why are we here?");1076// Make all state_for calls early since they can emit code1077LIR_Opr result = rlock_result(x);1078switch (x->id()) {1079case vmIntrinsics::_updateCRC32: {1080LIRItem crc(x->argument_at(0), this);1081LIRItem val(x->argument_at(1), this);1082// val is destroyed by update_crc321083val.set_destroys_register();1084crc.load_item();1085val.load_item();1086__ update_crc32(crc.result(), val.result(), result);1087break;1088}1089case vmIntrinsics::_updateBytesCRC32:1090case vmIntrinsics::_updateByteBufferCRC32: {1091bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);10921093LIRItem crc(x->argument_at(0), this);1094LIRItem buf(x->argument_at(1), this);1095LIRItem off(x->argument_at(2), this);1096LIRItem len(x->argument_at(3), this);1097buf.load_item();1098off.load_nonconstant();10991100LIR_Opr index = off.result();1101int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;1102if(off.result()->is_constant()) {1103index = LIR_OprFact::illegalOpr;1104offset += off.result()->as_jint();1105}1106LIR_Opr base_op = buf.result();11071108if (!is_updateBytes) { // long b raw address1109base_op = new_register(T_INT);1110__ convert(Bytecodes::_l2i, buf.result(), base_op);1111}11121113if (offset) {1114LIR_Opr tmp = new_pointer_register();1115__ add(base_op, LIR_OprFact::intConst(offset), tmp);1116base_op = tmp;1117offset = 0;1118}11191120LIR_Address* a = new LIR_Address(base_op,1121index,1122LIR_Address::times_1,1123offset,1124T_BYTE);1125BasicTypeList signature(3);1126signature.append(T_INT);1127signature.append(T_ADDRESS);1128signature.append(T_INT);1129CallingConvention* cc = frame_map()->c_calling_convention(&signature);1130const LIR_Opr result_reg = result_register_for(x->type());11311132LIR_Opr addr = new_pointer_register();1133__ leal(LIR_OprFact::address(a), addr);11341135crc.load_item_force(cc->at(0));1136__ move(addr, cc->at(1));1137len.load_item_force(cc->at(2));11381139__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1140__ move(result_reg, result);11411142break;1143}1144default: {1145ShouldNotReachHere();1146}1147}1148}11491150// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1151// _i2b, _i2c, _i2s1152void LIRGenerator::do_Convert(Convert* x) {1153address entry = NULL;1154switch (x->op()) {1155case Bytecodes::_d2i:1156case Bytecodes::_f2i:1157case Bytecodes::_i2f:1158case Bytecodes::_i2d:1159case Bytecodes::_f2d:1160case Bytecodes::_d2f:1161if(hasFPU()) {1162break;1163}// fall through for FPU-less cores1164case Bytecodes::_d2l:1165case Bytecodes::_f2l:1166case Bytecodes::_l2d:1167case Bytecodes::_l2f: {11681169switch (x->op()) {1170#ifdef __SOFTFP__1171case Bytecodes::_i2f:1172entry = CAST_FROM_FN_PTR(address, SharedRuntime::i2f);1173break;1174case Bytecodes::_i2d:1175entry = CAST_FROM_FN_PTR(address, SharedRuntime::i2d);1176break;1177case Bytecodes::_f2d:1178entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2d);1179break;1180case Bytecodes::_d2f:1181entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2f);1182break;1183case Bytecodes::_d2i:1184entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2i);1185break;1186case Bytecodes::_f2i:1187entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2i);1188break;1189#endif1190case Bytecodes::_d2l:1191entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2l);1192break;1193case Bytecodes::_f2l:1194entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2l);1195break;1196case Bytecodes::_l2d:1197entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2d);1198break;1199case Bytecodes::_l2f:1200entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2f);1201break;1202default:1203ShouldNotReachHere();1204}12051206LIR_Opr result = call_runtime(x->value(), entry, x->type(), NULL);1207set_result(x, result);1208}1209break;12101211default:1212break;1213}1214if(NULL == entry) {1215LIRItem value(x->value(), this);1216value.load_item();12171218if (x->op() == Bytecodes::_f2i || x->op() == Bytecodes::_d2i) {1219value.set_destroys_register();1220}12211222LIR_Opr input = value.result();1223LIR_Opr result = rlock(x);12241225__ convert(x->op(), input, result);12261227assert(result->is_virtual(), "result must be virtual register");1228set_result(x, result);1229}1230}12311232void LIRGenerator::do_NewInstance(NewInstance* x) {1233#ifndef PRODUCT1234if (PrintNotLoaded && !x->klass()->is_loaded()) {1235tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());1236}1237#endif1238CodeEmitInfo* info = state_for(x, x->state());1239LIR_Opr reg = result_register_for(x->type());1240new_instance(reg, x->klass(), x->is_unresolved(),1241FrameMap::r2_oop_opr,1242FrameMap::r5_oop_opr,1243FrameMap::r4_oop_opr,1244LIR_OprFact::illegalOpr,1245FrameMap::r3_metadata_opr, info);1246LIR_Opr result = rlock_result(x);1247__ move(reg, result);1248}12491250void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1251CodeEmitInfo* info = state_for(x, x->state());12521253LIRItem length(x->length(), this);1254length.load_item_force(FrameMap::r6_opr);12551256LIR_Opr reg = result_register_for(x->type());1257LIR_Opr tmp1 = FrameMap::r2_oop_opr;1258LIR_Opr tmp2 = FrameMap::r4_oop_opr;1259LIR_Opr tmp3 = FrameMap::r5_oop_opr;1260LIR_Opr tmp4 = reg;1261LIR_Opr klass_reg = FrameMap::r3_metadata_opr;1262LIR_Opr len = length.result();1263BasicType elem_type = x->elt_type();12641265__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);12661267CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1268__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);12691270LIR_Opr result = rlock_result(x);1271__ move(reg, result);1272}12731274void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1275LIRItem length(x->length(), this);1276// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1277// and therefore provide the state before the parameters have been consumed1278CodeEmitInfo* patching_info = NULL;1279if (!x->klass()->is_loaded() || PatchALot) {1280patching_info = state_for(x, x->state_before());1281}12821283CodeEmitInfo* info = state_for(x, x->state());12841285LIR_Opr reg = result_register_for(x->type());1286LIR_Opr tmp1 = FrameMap::r2_oop_opr;1287LIR_Opr tmp2 = FrameMap::r4_oop_opr;1288LIR_Opr tmp3 = FrameMap::r5_oop_opr;1289LIR_Opr tmp4 = reg;1290LIR_Opr klass_reg = FrameMap::r3_metadata_opr;12911292length.load_item_force(FrameMap::r6_opr);1293LIR_Opr len = length.result();12941295CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1296ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1297if (obj == ciEnv::unloaded_ciobjarrayklass()) {1298BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1299}1300klass2reg_with_patching(klass_reg, obj, patching_info);1301__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);13021303LIR_Opr result = rlock_result(x);1304__ move(reg, result);1305}130613071308void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1309Values* dims = x->dims();1310int i = dims->length();1311LIRItemList* items = new LIRItemList(dims->length(), NULL);1312while (i-- > 0) {1313LIRItem* size = new LIRItem(dims->at(i), this);1314items->at_put(i, size);1315}13161317// Evaluate state_for early since it may emit code.1318CodeEmitInfo* patching_info = NULL;1319if (!x->klass()->is_loaded() || PatchALot) {1320patching_info = state_for(x, x->state_before());13211322// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1323// clone all handlers (NOTE: Usually this is handled transparently1324// by the CodeEmitInfo cloning logic in CodeStub constructors but1325// is done explicitly here because a stub isn't being used).1326x->set_exception_handlers(new XHandlers(x->exception_handlers()));1327}1328CodeEmitInfo* info = state_for(x, x->state());13291330i = dims->length();1331while (i-- > 0) {1332LIRItem* size = items->at(i);1333size->load_item();13341335store_stack_parameter(size->result(), in_ByteSize(i*4));1336}13371338LIR_Opr klass_reg = FrameMap::r1_metadata_opr;1339klass2reg_with_patching(klass_reg, x->klass(), patching_info);13401341LIR_Opr rank = FrameMap::r2_opr;1342__ move(LIR_OprFact::intConst(x->rank()), rank);1343LIR_Opr varargs = FrameMap::r3_opr;1344__ move(FrameMap::sp_opr, varargs);1345LIR_OprList* args = new LIR_OprList(3);1346args->append(klass_reg);1347args->append(rank);1348args->append(varargs);1349LIR_Opr reg = result_register_for(x->type());1350__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1351LIR_OprFact::illegalOpr,1352reg, args, info);13531354LIR_Opr result = rlock_result(x);1355__ move(reg, result);1356}13571358void LIRGenerator::do_BlockBegin(BlockBegin* x) {1359// nothing to do for now1360}13611362void LIRGenerator::do_CheckCast(CheckCast* x) {1363LIRItem obj(x->obj(), this);13641365CodeEmitInfo* patching_info = NULL;1366if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {1367// must do this before locking the destination register as an oop register,1368// and before the obj is loaded (the latter is for deoptimization)1369patching_info = state_for(x, x->state_before());1370}1371obj.load_item();13721373// info for exceptions1374CodeEmitInfo* info_for_exception =1375(x->needs_exception_state() ? state_for(x) :1376state_for(x, x->state_before(), true /*ignore_xhandler*/));13771378CodeStub* stub;1379if (x->is_incompatible_class_change_check()) {1380assert(patching_info == NULL, "can't patch this");1381stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1382} else if (x->is_invokespecial_receiver_check()) {1383assert(patching_info == NULL, "can't patch this");1384stub = new DeoptimizeStub(info_for_exception);1385} else {1386stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1387}1388LIR_Opr reg = rlock_result(x);1389LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1390if (!x->klass()->is_loaded()) {1391tmp3 = new_register(objectType);1392}1393__ checkcast(reg, obj.result(), x->klass(),1394new_register(objectType), new_register(objectType), tmp3,1395x->direct_compare(), info_for_exception, patching_info, stub,1396x->profiled_method(), x->profiled_bci());1397}13981399void LIRGenerator::do_InstanceOf(InstanceOf* x) {1400LIRItem obj(x->obj(), this);14011402// result and test object may not be in same register1403LIR_Opr reg = rlock_result(x);1404CodeEmitInfo* patching_info = NULL;1405if ((!x->klass()->is_loaded() || PatchALot)) {1406// must do this before locking the destination register as an oop register1407patching_info = state_for(x, x->state_before());1408}1409obj.load_item();1410LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1411if (!x->klass()->is_loaded()) {1412tmp3 = new_register(objectType);1413}1414__ instanceof(reg, obj.result(), x->klass(),1415new_register(objectType), new_register(objectType), tmp3,1416x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1417}14181419void LIRGenerator::do_If(If* x) {1420assert(x->number_of_sux() == 2, "inconsistency");1421ValueTag tag = x->x()->type()->tag();14221423If::Condition cond = x->cond();14241425LIRItem xitem(x->x(), this);1426LIRItem yitem(x->y(), this);1427LIRItem* xin = &xitem;1428LIRItem* yin = &yitem;14291430xin->load_item();14311432if (yin->is_constant()) {1433if (tag == longTag1434&& Assembler::operand_valid_for_add_sub_immediate(yin->get_jlong_constant())) {1435yin->dont_load_item();1436} else if (tag == intTag1437&& Assembler::operand_valid_for_add_sub_immediate(yin->get_jint_constant())) {1438yin->dont_load_item();1439} else if (tag == addressTag1440&& Assembler::operand_valid_for_add_sub_immediate(yin->get_address_constant())) {1441yin->dont_load_item();1442} else if (tag == objectTag && yin->get_jobject_constant()->is_null_object()) {1443yin->dont_load_item();1444} else {1445yin->load_item();1446}1447} else {1448yin->load_item();1449}14501451// add safepoint before generating condition code so it can be recomputed1452if (x->is_safepoint()) {1453// increment backedge counter if needed1454increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());1455__ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));1456}1457set_no_result(x);14581459LIR_Opr left = xin->result();1460LIR_Opr right = yin->result();1461LIR_Condition lir_c = lir_cond(cond);14621463#ifdef __SOFTFP__1464if(x->x()->type()->is_float_kind() && !(hasFPU())) {// FPU-less cores1465address entry;1466bool unordered_flag = x->unordered_is_true() != (lir_c == lir_cond_greater || lir_c == lir_cond_lessEqual);1467if (x->x()->type()->is_float()) {1468entry = CAST_FROM_FN_PTR(address, unordered_flag ? SharedRuntime::fcmpg : SharedRuntime::fcmpl);1469} else if (x->x()->type()->is_double()) {1470entry = CAST_FROM_FN_PTR(address, unordered_flag ? SharedRuntime::dcmpg : SharedRuntime::dcmpl);1471} else {1472ShouldNotReachHere();1473}14741475LIR_Opr fcmp_res = call_runtime(x->x(), x->y(), entry, intType, NULL);1476LIR_Opr zero = LIR_OprFact::intConst(0);1477__ cmp(lir_c, fcmp_res, zero);1478} else1479#endif1480{1481__ cmp(lir_c, left, right);1482}14831484// Generate branch profiling. Profiling code doesn't kill flags.1485profile_branch(x, cond);1486move_to_phi(x->state());1487if (x->x()->type()->is_float_kind()) {1488if(hasFPU()) {1489__ branch(lir_c, right->type(), x->tsux(), x->usux());1490} else {1491__ branch(lir_c, T_INT, x->tsux());1492}1493} else1494{1495__ branch(lir_c, right->type(), x->tsux());1496}1497assert(x->default_sux() == x->fsux(), "wrong destination above");1498__ jump(x->default_sux());1499}15001501LIR_Opr LIRGenerator::getThreadPointer() {1502return FrameMap::as_pointer_opr(rthread);1503}15041505void LIRGenerator::trace_block_entry(BlockBegin* block) {1506__ move(LIR_OprFact::intConst(block->block_id()), FrameMap::r0_opr);1507LIR_OprList* args = new LIR_OprList(1);1508args->append(FrameMap::r0_opr);1509address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1510__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1511}15121513void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1514CodeEmitInfo* info) {1515if (value->is_double_cpu()) {1516__ move(value, FrameMap::long0_opr);1517__ volatile_store_mem_reg(FrameMap::long0_opr, address, info);1518} else {1519__ volatile_store_mem_reg(value, address, info);1520}1521}15221523void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1524CodeEmitInfo* info) {1525if (result->is_double_cpu()) {1526__ volatile_load_mem_reg(address, FrameMap::long0_opr, info);1527__ move(FrameMap::long0_opr, result);1528} else {1529__ volatile_load_mem_reg(address, result, info);1530}1531}15321533void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,1534BasicType type, bool is_volatile) {1535LIR_Address* addr = new LIR_Address(src, offset, type);1536__ load(addr, dst);1537}153815391540void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,1541BasicType type, bool is_volatile) {1542LIR_Address* addr = new LIR_Address(src, offset, type);1543bool is_obj = (type == T_ARRAY || type == T_OBJECT);1544if (is_obj) {1545// Do the pre-write barrier, if any.1546pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,1547true /* do_load */, false /* patch */, NULL);1548__ move(data, addr);1549assert(src->is_register(), "must be register");1550// Seems to be a precise address1551post_barrier(LIR_OprFact::address(addr), data);1552} else {1553__ move(data, addr);1554}1555}15561557void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {1558BasicType type = x->basic_type();1559LIRItem src(x->object(), this);1560LIRItem off(x->offset(), this);1561LIRItem value(x->value(), this);15621563src.load_item();1564off.load_nonconstant();1565if (type == T_LONG && !x->is_add()) {1566// not need if allocator reserves correct pairs1567value.load_item_force(FrameMap::long1_opr);1568} else {1569// We can cope with a constant increment in an xadd1570if (! (x->is_add()1571&& value.is_constant()1572&& can_inline_as_constant(x->value()))) {1573value.load_item();1574}1575}15761577bool is_long = (type == T_LONG);1578LIR_Opr dst = is_long ? FrameMap::long0_opr : rlock_result(x, type);1579LIR_Opr data = value.result();1580bool is_obj = (type == T_ARRAY || type == T_OBJECT);1581LIR_Opr offset = off.result();15821583if (data == dst) {1584LIR_Opr tmp = new_register(data->type());1585__ move(data, tmp);1586data = tmp;1587}15881589LIR_Address* addr;1590if (offset->is_constant()) {1591addr = new LIR_Address(src.result(), offset->as_jint(), type);1592} else {1593addr = new LIR_Address(src.result(), offset, type);1594}15951596LIR_Opr tmp = new_register(T_INT);1597LIR_Opr ptr = LIR_OprFact::illegalOpr;15981599if (x->is_add()) {1600__ xadd(LIR_OprFact::address(addr), data, dst, tmp);1601} else {1602if (is_obj) {1603// Do the pre-write barrier, if any.1604ptr = new_pointer_register();1605__ add(src.result(), off.result(), ptr);1606pre_barrier(ptr, LIR_OprFact::illegalOpr /* pre_val */,1607true /* do_load */, false /* patch */, NULL);1608}1609__ xchg(LIR_OprFact::address(addr), data, dst, tmp);1610if (is_obj) {1611post_barrier(ptr, data);1612}1613}16141615if (is_long) {1616dst = rlock_result(x, type);1617__ move(FrameMap::long0_opr, dst);1618}1619}162016211622