Path: blob/master/src/hotspot/share/c1/c1_LIR.cpp
40930 views
/*1* Copyright (c) 2000, 2021, 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_CodeStubs.hpp"26#include "c1/c1_InstructionPrinter.hpp"27#include "c1/c1_LIR.hpp"28#include "c1/c1_LIRAssembler.hpp"29#include "c1/c1_ValueStack.hpp"30#include "ci/ciInstance.hpp"31#include "runtime/safepointMechanism.inline.hpp"32#include "runtime/sharedRuntime.hpp"33#include "runtime/vm_version.hpp"3435Register LIR_OprDesc::as_register() const {36return FrameMap::cpu_rnr2reg(cpu_regnr());37}3839Register LIR_OprDesc::as_register_lo() const {40return FrameMap::cpu_rnr2reg(cpu_regnrLo());41}4243Register LIR_OprDesc::as_register_hi() const {44return FrameMap::cpu_rnr2reg(cpu_regnrHi());45}4647LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();4849LIR_Opr LIR_OprFact::value_type(ValueType* type) {50ValueTag tag = type->tag();51switch (tag) {52case metaDataTag : {53ClassConstant* c = type->as_ClassConstant();54if (c != NULL && !c->value()->is_loaded()) {55return LIR_OprFact::metadataConst(NULL);56} else if (c != NULL) {57return LIR_OprFact::metadataConst(c->value()->constant_encoding());58} else {59MethodConstant* m = type->as_MethodConstant();60assert (m != NULL, "not a class or a method?");61return LIR_OprFact::metadataConst(m->value()->constant_encoding());62}63}64case objectTag : {65return LIR_OprFact::oopConst(type->as_ObjectType()->encoding());66}67case addressTag: return LIR_OprFact::addressConst(type->as_AddressConstant()->value());68case intTag : return LIR_OprFact::intConst(type->as_IntConstant()->value());69case floatTag : return LIR_OprFact::floatConst(type->as_FloatConstant()->value());70case longTag : return LIR_OprFact::longConst(type->as_LongConstant()->value());71case doubleTag : return LIR_OprFact::doubleConst(type->as_DoubleConstant()->value());72default: ShouldNotReachHere(); return LIR_OprFact::intConst(-1);73}74}757677//---------------------------------------------------787980LIR_Address::Scale LIR_Address::scale(BasicType type) {81int elem_size = type2aelembytes(type);82switch (elem_size) {83case 1: return LIR_Address::times_1;84case 2: return LIR_Address::times_2;85case 4: return LIR_Address::times_4;86case 8: return LIR_Address::times_8;87}88ShouldNotReachHere();89return LIR_Address::times_1;90}9192//---------------------------------------------------9394char LIR_OprDesc::type_char(BasicType t) {95switch (t) {96case T_ARRAY:97t = T_OBJECT;98case T_BOOLEAN:99case T_CHAR:100case T_FLOAT:101case T_DOUBLE:102case T_BYTE:103case T_SHORT:104case T_INT:105case T_LONG:106case T_OBJECT:107case T_ADDRESS:108case T_VOID:109return ::type2char(t);110case T_METADATA:111return 'M';112case T_ILLEGAL:113return '?';114115default:116ShouldNotReachHere();117return '?';118}119}120121#ifndef PRODUCT122void LIR_OprDesc::validate_type() const {123124#ifdef ASSERT125if (!is_pointer() && !is_illegal()) {126OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160127switch (as_BasicType(type_field())) {128case T_LONG:129assert((kindfield == cpu_register || kindfield == stack_value) &&130size_field() == double_size, "must match");131break;132case T_FLOAT:133// FP return values can be also in CPU registers on ARM and PPC32 (softfp ABI)134assert((kindfield == fpu_register || kindfield == stack_value135ARM_ONLY(|| kindfield == cpu_register)136PPC32_ONLY(|| kindfield == cpu_register) ) &&137size_field() == single_size, "must match");138break;139case T_DOUBLE:140// FP return values can be also in CPU registers on ARM and PPC32 (softfp ABI)141assert((kindfield == fpu_register || kindfield == stack_value142ARM_ONLY(|| kindfield == cpu_register)143PPC32_ONLY(|| kindfield == cpu_register) ) &&144size_field() == double_size, "must match");145break;146case T_BOOLEAN:147case T_CHAR:148case T_BYTE:149case T_SHORT:150case T_INT:151case T_ADDRESS:152case T_OBJECT:153case T_METADATA:154case T_ARRAY:155assert((kindfield == cpu_register || kindfield == stack_value) &&156size_field() == single_size, "must match");157break;158159case T_ILLEGAL:160// XXX TKR also means unknown right now161// assert(is_illegal(), "must match");162break;163164default:165ShouldNotReachHere();166}167}168#endif169170}171#endif // PRODUCT172173174bool LIR_OprDesc::is_oop() const {175if (is_pointer()) {176return pointer()->is_oop_pointer();177} else {178OprType t= type_field();179assert(t != unknown_type, "not set");180return t == object_type;181}182}183184185186void LIR_Op2::verify() const {187#ifdef ASSERT188switch (code()) {189case lir_cmove:190case lir_xchg:191break;192193default:194assert(!result_opr()->is_register() || !result_opr()->is_oop_register(),195"can't produce oops from arith");196}197198if (TwoOperandLIRForm) {199200#ifdef ASSERT201bool threeOperandForm = false;202#ifdef S390203// There are 3 operand shifts on S390 (see LIR_Assembler::shift_op()).204threeOperandForm =205code() == lir_shl ||206((code() == lir_shr || code() == lir_ushr) && (result_opr()->is_double_cpu() || in_opr1()->type() == T_OBJECT));207#endif208#endif209210switch (code()) {211case lir_add:212case lir_sub:213case lir_mul:214case lir_div:215case lir_rem:216case lir_logic_and:217case lir_logic_or:218case lir_logic_xor:219case lir_shl:220case lir_shr:221assert(in_opr1() == result_opr() || threeOperandForm, "opr1 and result must match");222assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");223break;224225// special handling for lir_ushr because of write barriers226case lir_ushr:227assert(in_opr1() == result_opr() || in_opr2()->is_constant() || threeOperandForm, "opr1 and result must match or shift count is constant");228assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");229break;230231default:232break;233}234}235#endif236}237238239LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block)240: LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)241, _cond(cond)242, _label(block->label())243, _block(block)244, _ublock(NULL)245, _stub(NULL) {246}247248LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, CodeStub* stub) :249LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)250, _cond(cond)251, _label(stub->entry())252, _block(NULL)253, _ublock(NULL)254, _stub(stub) {255}256257LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock)258: LIR_Op(lir_cond_float_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)259, _cond(cond)260, _label(block->label())261, _block(block)262, _ublock(ublock)263, _stub(NULL)264{265}266267void LIR_OpBranch::change_block(BlockBegin* b) {268assert(_block != NULL, "must have old block");269assert(_block->label() == label(), "must be equal");270271_block = b;272_label = b->label();273}274275void LIR_OpBranch::change_ublock(BlockBegin* b) {276assert(_ublock != NULL, "must have old block");277_ublock = b;278}279280void LIR_OpBranch::negate_cond() {281switch (_cond) {282case lir_cond_equal: _cond = lir_cond_notEqual; break;283case lir_cond_notEqual: _cond = lir_cond_equal; break;284case lir_cond_less: _cond = lir_cond_greaterEqual; break;285case lir_cond_lessEqual: _cond = lir_cond_greater; break;286case lir_cond_greaterEqual: _cond = lir_cond_less; break;287case lir_cond_greater: _cond = lir_cond_lessEqual; break;288default: ShouldNotReachHere();289}290}291292293LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,294LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,295bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,296CodeStub* stub)297298: LIR_Op(code, result, NULL)299, _object(object)300, _array(LIR_OprFact::illegalOpr)301, _klass(klass)302, _tmp1(tmp1)303, _tmp2(tmp2)304, _tmp3(tmp3)305, _fast_check(fast_check)306, _info_for_patch(info_for_patch)307, _info_for_exception(info_for_exception)308, _stub(stub)309, _profiled_method(NULL)310, _profiled_bci(-1)311, _should_profile(false)312{313if (code == lir_checkcast) {314assert(info_for_exception != NULL, "checkcast throws exceptions");315} else if (code == lir_instanceof) {316assert(info_for_exception == NULL, "instanceof throws no exceptions");317} else {318ShouldNotReachHere();319}320}321322323324LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception)325: LIR_Op(code, LIR_OprFact::illegalOpr, NULL)326, _object(object)327, _array(array)328, _klass(NULL)329, _tmp1(tmp1)330, _tmp2(tmp2)331, _tmp3(tmp3)332, _fast_check(false)333, _info_for_patch(NULL)334, _info_for_exception(info_for_exception)335, _stub(NULL)336, _profiled_method(NULL)337, _profiled_bci(-1)338, _should_profile(false)339{340if (code == lir_store_check) {341_stub = new ArrayStoreExceptionStub(object, info_for_exception);342assert(info_for_exception != NULL, "store_check throws exceptions");343} else {344ShouldNotReachHere();345}346}347348349LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,350LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)351: LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)352, _src(src)353, _src_pos(src_pos)354, _dst(dst)355, _dst_pos(dst_pos)356, _length(length)357, _tmp(tmp)358, _expected_type(expected_type)359, _flags(flags) {360_stub = new ArrayCopyStub(this);361}362363LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)364: LIR_Op(lir_updatecrc32, res, NULL)365, _crc(crc)366, _val(val) {367}368369//-------------------verify--------------------------370371void LIR_Op1::verify() const {372switch(code()) {373case lir_move:374assert(in_opr()->is_valid() && result_opr()->is_valid(), "must be");375break;376case lir_null_check:377assert(in_opr()->is_register(), "must be");378break;379case lir_return:380assert(in_opr()->is_register() || in_opr()->is_illegal(), "must be");381break;382default:383break;384}385}386387void LIR_OpRTCall::verify() const {388assert(strcmp(Runtime1::name_for_address(addr()), "<unknown function>") != 0, "unknown function");389}390391//-------------------visits--------------------------392393// complete rework of LIR instruction visitor.394// The virtual call for each instruction type is replaced by a big395// switch that adds the operands for each instruction396397void LIR_OpVisitState::visit(LIR_Op* op) {398// copy information from the LIR_Op399reset();400set_op(op);401402switch (op->code()) {403404// LIR_Op0405case lir_backwardbranch_target: // result and info always invalid406case lir_fpop_raw: // result and info always invalid407case lir_breakpoint: // result and info always invalid408case lir_membar: // result and info always invalid409case lir_membar_acquire: // result and info always invalid410case lir_membar_release: // result and info always invalid411case lir_membar_loadload: // result and info always invalid412case lir_membar_storestore: // result and info always invalid413case lir_membar_loadstore: // result and info always invalid414case lir_membar_storeload: // result and info always invalid415case lir_on_spin_wait:416{417assert(op->as_Op0() != NULL, "must be");418assert(op->_info == NULL, "info not used by this instruction");419assert(op->_result->is_illegal(), "not used");420break;421}422423case lir_nop: // may have info, result always invalid424case lir_std_entry: // may have result, info always invalid425case lir_osr_entry: // may have result, info always invalid426case lir_get_thread: // may have result, info always invalid427{428assert(op->as_Op0() != NULL, "must be");429if (op->_info != NULL) do_info(op->_info);430if (op->_result->is_valid()) do_output(op->_result);431break;432}433434435// LIR_OpLabel436case lir_label: // result and info always invalid437{438assert(op->as_OpLabel() != NULL, "must be");439assert(op->_info == NULL, "info not used by this instruction");440assert(op->_result->is_illegal(), "not used");441break;442}443444445// LIR_Op1446case lir_fxch: // input always valid, result and info always invalid447case lir_fld: // input always valid, result and info always invalid448case lir_push: // input always valid, result and info always invalid449case lir_pop: // input always valid, result and info always invalid450case lir_leal: // input and result always valid, info always invalid451case lir_monaddr: // input and result always valid, info always invalid452case lir_null_check: // input and info always valid, result always invalid453case lir_move: // input and result always valid, may have info454{455assert(op->as_Op1() != NULL, "must be");456LIR_Op1* op1 = (LIR_Op1*)op;457458if (op1->_info) do_info(op1->_info);459if (op1->_opr->is_valid()) do_input(op1->_opr);460if (op1->_result->is_valid()) do_output(op1->_result);461462break;463}464465case lir_return:466{467assert(op->as_OpReturn() != NULL, "must be");468LIR_OpReturn* op_ret = (LIR_OpReturn*)op;469470if (op_ret->_info) do_info(op_ret->_info);471if (op_ret->_opr->is_valid()) do_input(op_ret->_opr);472if (op_ret->_result->is_valid()) do_output(op_ret->_result);473if (op_ret->stub() != NULL) do_stub(op_ret->stub());474475break;476}477478case lir_safepoint:479{480assert(op->as_Op1() != NULL, "must be");481LIR_Op1* op1 = (LIR_Op1*)op;482483assert(op1->_info != NULL, ""); do_info(op1->_info);484if (op1->_opr->is_valid()) do_temp(op1->_opr); // safepoints on SPARC need temporary register485assert(op1->_result->is_illegal(), "safepoint does not produce value");486487break;488}489490// LIR_OpConvert;491case lir_convert: // input and result always valid, info always invalid492{493assert(op->as_OpConvert() != NULL, "must be");494LIR_OpConvert* opConvert = (LIR_OpConvert*)op;495496assert(opConvert->_info == NULL, "must be");497if (opConvert->_opr->is_valid()) do_input(opConvert->_opr);498if (opConvert->_result->is_valid()) do_output(opConvert->_result);499#ifdef PPC32500if (opConvert->_tmp1->is_valid()) do_temp(opConvert->_tmp1);501if (opConvert->_tmp2->is_valid()) do_temp(opConvert->_tmp2);502#endif503do_stub(opConvert->_stub);504505break;506}507508// LIR_OpBranch;509case lir_branch: // may have info, input and result register always invalid510case lir_cond_float_branch: // may have info, input and result register always invalid511{512assert(op->as_OpBranch() != NULL, "must be");513LIR_OpBranch* opBranch = (LIR_OpBranch*)op;514515if (opBranch->_info != NULL) do_info(opBranch->_info);516assert(opBranch->_result->is_illegal(), "not used");517if (opBranch->_stub != NULL) opBranch->stub()->visit(this);518519break;520}521522523// LIR_OpAllocObj524case lir_alloc_object:525{526assert(op->as_OpAllocObj() != NULL, "must be");527LIR_OpAllocObj* opAllocObj = (LIR_OpAllocObj*)op;528529if (opAllocObj->_info) do_info(opAllocObj->_info);530if (opAllocObj->_opr->is_valid()) { do_input(opAllocObj->_opr);531do_temp(opAllocObj->_opr);532}533if (opAllocObj->_tmp1->is_valid()) do_temp(opAllocObj->_tmp1);534if (opAllocObj->_tmp2->is_valid()) do_temp(opAllocObj->_tmp2);535if (opAllocObj->_tmp3->is_valid()) do_temp(opAllocObj->_tmp3);536if (opAllocObj->_tmp4->is_valid()) do_temp(opAllocObj->_tmp4);537if (opAllocObj->_result->is_valid()) do_output(opAllocObj->_result);538do_stub(opAllocObj->_stub);539break;540}541542543// LIR_OpRoundFP;544case lir_roundfp: {545assert(op->as_OpRoundFP() != NULL, "must be");546LIR_OpRoundFP* opRoundFP = (LIR_OpRoundFP*)op;547548assert(op->_info == NULL, "info not used by this instruction");549assert(opRoundFP->_tmp->is_illegal(), "not used");550do_input(opRoundFP->_opr);551do_output(opRoundFP->_result);552553break;554}555556557// LIR_Op2558case lir_cmp:559case lir_cmp_l2i:560case lir_ucmp_fd2i:561case lir_cmp_fd2i:562case lir_add:563case lir_sub:564case lir_rem:565case lir_sqrt:566case lir_abs:567case lir_neg:568case lir_logic_and:569case lir_logic_or:570case lir_logic_xor:571case lir_shl:572case lir_shr:573case lir_ushr:574case lir_xadd:575case lir_xchg:576case lir_assert:577{578assert(op->as_Op2() != NULL, "must be");579LIR_Op2* op2 = (LIR_Op2*)op;580assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&581op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");582583if (op2->_info) do_info(op2->_info);584if (op2->_opr1->is_valid()) do_input(op2->_opr1);585if (op2->_opr2->is_valid()) do_input(op2->_opr2);586if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1);587if (op2->_result->is_valid()) do_output(op2->_result);588if (op->code() == lir_xchg || op->code() == lir_xadd) {589// on ARM and PPC, return value is loaded first so could590// destroy inputs. On other platforms that implement those591// (x86, sparc), the extra constrainsts are harmless.592if (op2->_opr1->is_valid()) do_temp(op2->_opr1);593if (op2->_opr2->is_valid()) do_temp(op2->_opr2);594}595596break;597}598599// special handling for cmove: right input operand must not be equal600// to the result operand, otherwise the backend fails601case lir_cmove:602{603assert(op->as_Op2() != NULL, "must be");604LIR_Op2* op2 = (LIR_Op2*)op;605606assert(op2->_info == NULL && op2->_tmp1->is_illegal() && op2->_tmp2->is_illegal() &&607op2->_tmp3->is_illegal() && op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");608assert(op2->_opr1->is_valid() && op2->_opr2->is_valid() && op2->_result->is_valid(), "used");609610do_input(op2->_opr1);611do_input(op2->_opr2);612do_temp(op2->_opr2);613do_output(op2->_result);614615break;616}617618// vspecial handling for strict operations: register input operands619// as temp to guarantee that they do not overlap with other620// registers621case lir_mul:622case lir_div:623{624assert(op->as_Op2() != NULL, "must be");625LIR_Op2* op2 = (LIR_Op2*)op;626627assert(op2->_info == NULL, "not used");628assert(op2->_opr1->is_valid(), "used");629assert(op2->_opr2->is_valid(), "used");630assert(op2->_result->is_valid(), "used");631assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&632op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");633634do_input(op2->_opr1); do_temp(op2->_opr1);635do_input(op2->_opr2); do_temp(op2->_opr2);636if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1);637do_output(op2->_result);638639break;640}641642case lir_throw: {643assert(op->as_Op2() != NULL, "must be");644LIR_Op2* op2 = (LIR_Op2*)op;645646if (op2->_info) do_info(op2->_info);647if (op2->_opr1->is_valid()) do_temp(op2->_opr1);648if (op2->_opr2->is_valid()) do_input(op2->_opr2); // exception object is input parameter649assert(op2->_result->is_illegal(), "no result");650assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&651op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");652653break;654}655656case lir_unwind: {657assert(op->as_Op1() != NULL, "must be");658LIR_Op1* op1 = (LIR_Op1*)op;659660assert(op1->_info == NULL, "no info");661assert(op1->_opr->is_valid(), "exception oop"); do_input(op1->_opr);662assert(op1->_result->is_illegal(), "no result");663664break;665}666667// LIR_Op3668case lir_idiv:669case lir_irem: {670assert(op->as_Op3() != NULL, "must be");671LIR_Op3* op3= (LIR_Op3*)op;672673if (op3->_info) do_info(op3->_info);674if (op3->_opr1->is_valid()) do_input(op3->_opr1);675676// second operand is input and temp, so ensure that second operand677// and third operand get not the same register678if (op3->_opr2->is_valid()) do_input(op3->_opr2);679if (op3->_opr2->is_valid()) do_temp(op3->_opr2);680if (op3->_opr3->is_valid()) do_temp(op3->_opr3);681682if (op3->_result->is_valid()) do_output(op3->_result);683684break;685}686687case lir_fmad:688case lir_fmaf: {689assert(op->as_Op3() != NULL, "must be");690LIR_Op3* op3= (LIR_Op3*)op;691assert(op3->_info == NULL, "no info");692do_input(op3->_opr1);693do_input(op3->_opr2);694do_input(op3->_opr3);695do_output(op3->_result);696break;697}698699// LIR_OpJavaCall700case lir_static_call:701case lir_optvirtual_call:702case lir_icvirtual_call:703case lir_dynamic_call: {704LIR_OpJavaCall* opJavaCall = op->as_OpJavaCall();705assert(opJavaCall != NULL, "must be");706707if (opJavaCall->_receiver->is_valid()) do_input(opJavaCall->_receiver);708709// only visit register parameters710int n = opJavaCall->_arguments->length();711for (int i = opJavaCall->_receiver->is_valid() ? 1 : 0; i < n; i++) {712if (!opJavaCall->_arguments->at(i)->is_pointer()) {713do_input(*opJavaCall->_arguments->adr_at(i));714}715}716717if (opJavaCall->_info) do_info(opJavaCall->_info);718if (FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr &&719opJavaCall->is_method_handle_invoke()) {720opJavaCall->_method_handle_invoke_SP_save_opr = FrameMap::method_handle_invoke_SP_save_opr();721do_temp(opJavaCall->_method_handle_invoke_SP_save_opr);722}723do_call();724if (opJavaCall->_result->is_valid()) do_output(opJavaCall->_result);725726break;727}728729730// LIR_OpRTCall731case lir_rtcall: {732assert(op->as_OpRTCall() != NULL, "must be");733LIR_OpRTCall* opRTCall = (LIR_OpRTCall*)op;734735// only visit register parameters736int n = opRTCall->_arguments->length();737for (int i = 0; i < n; i++) {738if (!opRTCall->_arguments->at(i)->is_pointer()) {739do_input(*opRTCall->_arguments->adr_at(i));740}741}742if (opRTCall->_info) do_info(opRTCall->_info);743if (opRTCall->_tmp->is_valid()) do_temp(opRTCall->_tmp);744do_call();745if (opRTCall->_result->is_valid()) do_output(opRTCall->_result);746747break;748}749750751// LIR_OpArrayCopy752case lir_arraycopy: {753assert(op->as_OpArrayCopy() != NULL, "must be");754LIR_OpArrayCopy* opArrayCopy = (LIR_OpArrayCopy*)op;755756assert(opArrayCopy->_result->is_illegal(), "unused");757assert(opArrayCopy->_src->is_valid(), "used"); do_input(opArrayCopy->_src); do_temp(opArrayCopy->_src);758assert(opArrayCopy->_src_pos->is_valid(), "used"); do_input(opArrayCopy->_src_pos); do_temp(opArrayCopy->_src_pos);759assert(opArrayCopy->_dst->is_valid(), "used"); do_input(opArrayCopy->_dst); do_temp(opArrayCopy->_dst);760assert(opArrayCopy->_dst_pos->is_valid(), "used"); do_input(opArrayCopy->_dst_pos); do_temp(opArrayCopy->_dst_pos);761assert(opArrayCopy->_length->is_valid(), "used"); do_input(opArrayCopy->_length); do_temp(opArrayCopy->_length);762assert(opArrayCopy->_tmp->is_valid(), "used"); do_temp(opArrayCopy->_tmp);763if (opArrayCopy->_info) do_info(opArrayCopy->_info);764765// the implementation of arraycopy always has a call into the runtime766do_call();767768break;769}770771772// LIR_OpUpdateCRC32773case lir_updatecrc32: {774assert(op->as_OpUpdateCRC32() != NULL, "must be");775LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op;776777assert(opUp->_crc->is_valid(), "used"); do_input(opUp->_crc); do_temp(opUp->_crc);778assert(opUp->_val->is_valid(), "used"); do_input(opUp->_val); do_temp(opUp->_val);779assert(opUp->_result->is_valid(), "used"); do_output(opUp->_result);780assert(opUp->_info == NULL, "no info for LIR_OpUpdateCRC32");781782break;783}784785786// LIR_OpLock787case lir_lock:788case lir_unlock: {789assert(op->as_OpLock() != NULL, "must be");790LIR_OpLock* opLock = (LIR_OpLock*)op;791792if (opLock->_info) do_info(opLock->_info);793794// TODO: check if these operands really have to be temp795// (or if input is sufficient). This may have influence on the oop map!796assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);797assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);798assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);799800if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);801assert(opLock->_result->is_illegal(), "unused");802803do_stub(opLock->_stub);804805break;806}807808809// LIR_OpDelay810case lir_delay_slot: {811assert(op->as_OpDelay() != NULL, "must be");812LIR_OpDelay* opDelay = (LIR_OpDelay*)op;813814visit(opDelay->delay_op());815break;816}817818// LIR_OpTypeCheck819case lir_instanceof:820case lir_checkcast:821case lir_store_check: {822assert(op->as_OpTypeCheck() != NULL, "must be");823LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;824825if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);826if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);827if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);828if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {829do_temp(opTypeCheck->_object);830}831if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);832if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);833if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);834if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);835if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);836do_stub(opTypeCheck->_stub);837break;838}839840// LIR_OpCompareAndSwap841case lir_cas_long:842case lir_cas_obj:843case lir_cas_int: {844assert(op->as_OpCompareAndSwap() != NULL, "must be");845LIR_OpCompareAndSwap* opCompareAndSwap = (LIR_OpCompareAndSwap*)op;846847assert(opCompareAndSwap->_addr->is_valid(), "used");848assert(opCompareAndSwap->_cmp_value->is_valid(), "used");849assert(opCompareAndSwap->_new_value->is_valid(), "used");850if (opCompareAndSwap->_info) do_info(opCompareAndSwap->_info);851do_input(opCompareAndSwap->_addr);852do_temp(opCompareAndSwap->_addr);853do_input(opCompareAndSwap->_cmp_value);854do_temp(opCompareAndSwap->_cmp_value);855do_input(opCompareAndSwap->_new_value);856do_temp(opCompareAndSwap->_new_value);857if (opCompareAndSwap->_tmp1->is_valid()) do_temp(opCompareAndSwap->_tmp1);858if (opCompareAndSwap->_tmp2->is_valid()) do_temp(opCompareAndSwap->_tmp2);859if (opCompareAndSwap->_result->is_valid()) do_output(opCompareAndSwap->_result);860861break;862}863864865// LIR_OpAllocArray;866case lir_alloc_array: {867assert(op->as_OpAllocArray() != NULL, "must be");868LIR_OpAllocArray* opAllocArray = (LIR_OpAllocArray*)op;869870if (opAllocArray->_info) do_info(opAllocArray->_info);871if (opAllocArray->_klass->is_valid()) do_input(opAllocArray->_klass); do_temp(opAllocArray->_klass);872if (opAllocArray->_len->is_valid()) do_input(opAllocArray->_len); do_temp(opAllocArray->_len);873if (opAllocArray->_tmp1->is_valid()) do_temp(opAllocArray->_tmp1);874if (opAllocArray->_tmp2->is_valid()) do_temp(opAllocArray->_tmp2);875if (opAllocArray->_tmp3->is_valid()) do_temp(opAllocArray->_tmp3);876if (opAllocArray->_tmp4->is_valid()) do_temp(opAllocArray->_tmp4);877if (opAllocArray->_result->is_valid()) do_output(opAllocArray->_result);878do_stub(opAllocArray->_stub);879break;880}881882// LIR_OpProfileCall:883case lir_profile_call: {884assert(op->as_OpProfileCall() != NULL, "must be");885LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;886887if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);888assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);889assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);890break;891}892893// LIR_OpProfileType:894case lir_profile_type: {895assert(op->as_OpProfileType() != NULL, "must be");896LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;897898do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);899do_input(opProfileType->_obj);900do_temp(opProfileType->_tmp);901break;902}903default:904op->visit(this);905}906}907908void LIR_Op::visit(LIR_OpVisitState* state) {909ShouldNotReachHere();910}911912void LIR_OpVisitState::do_stub(CodeStub* stub) {913if (stub != NULL) {914stub->visit(this);915}916}917918XHandlers* LIR_OpVisitState::all_xhandler() {919XHandlers* result = NULL;920921int i;922for (i = 0; i < info_count(); i++) {923if (info_at(i)->exception_handlers() != NULL) {924result = info_at(i)->exception_handlers();925break;926}927}928929#ifdef ASSERT930for (i = 0; i < info_count(); i++) {931assert(info_at(i)->exception_handlers() == NULL ||932info_at(i)->exception_handlers() == result,933"only one xhandler list allowed per LIR-operation");934}935#endif936937if (result != NULL) {938return result;939} else {940return new XHandlers();941}942943return result;944}945946947#ifdef ASSERT948bool LIR_OpVisitState::no_operands(LIR_Op* op) {949visit(op);950951return opr_count(inputMode) == 0 &&952opr_count(outputMode) == 0 &&953opr_count(tempMode) == 0 &&954info_count() == 0 &&955!has_call() &&956!has_slow_case();957}958#endif959960// LIR_OpReturn961LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :962LIR_Op1(lir_return, opr, (CodeEmitInfo*)NULL /* info */),963_stub(NULL) {964if (VM_Version::supports_stack_watermark_barrier()) {965_stub = new C1SafepointPollStub();966}967}968969//---------------------------------------------------970971972void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {973masm->emit_call(this);974}975976void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {977masm->emit_rtcall(this);978}979980void LIR_OpLabel::emit_code(LIR_Assembler* masm) {981masm->emit_opLabel(this);982}983984void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {985masm->emit_arraycopy(this);986masm->append_code_stub(stub());987}988989void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {990masm->emit_updatecrc32(this);991}992993void LIR_Op0::emit_code(LIR_Assembler* masm) {994masm->emit_op0(this);995}996997void LIR_Op1::emit_code(LIR_Assembler* masm) {998masm->emit_op1(this);999}10001001void LIR_OpAllocObj::emit_code(LIR_Assembler* masm) {1002masm->emit_alloc_obj(this);1003masm->append_code_stub(stub());1004}10051006void LIR_OpBranch::emit_code(LIR_Assembler* masm) {1007masm->emit_opBranch(this);1008if (stub()) {1009masm->append_code_stub(stub());1010}1011}10121013void LIR_OpConvert::emit_code(LIR_Assembler* masm) {1014masm->emit_opConvert(this);1015if (stub() != NULL) {1016masm->append_code_stub(stub());1017}1018}10191020void LIR_Op2::emit_code(LIR_Assembler* masm) {1021masm->emit_op2(this);1022}10231024void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {1025masm->emit_alloc_array(this);1026masm->append_code_stub(stub());1027}10281029void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {1030masm->emit_opTypeCheck(this);1031if (stub()) {1032masm->append_code_stub(stub());1033}1034}10351036void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {1037masm->emit_compare_and_swap(this);1038}10391040void LIR_Op3::emit_code(LIR_Assembler* masm) {1041masm->emit_op3(this);1042}10431044void LIR_OpLock::emit_code(LIR_Assembler* masm) {1045masm->emit_lock(this);1046if (stub()) {1047masm->append_code_stub(stub());1048}1049}10501051#ifdef ASSERT1052void LIR_OpAssert::emit_code(LIR_Assembler* masm) {1053masm->emit_assert(this);1054}1055#endif10561057void LIR_OpDelay::emit_code(LIR_Assembler* masm) {1058masm->emit_delay(this);1059}10601061void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {1062masm->emit_profile_call(this);1063}10641065void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {1066masm->emit_profile_type(this);1067}10681069// LIR_List1070LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)1071: _operations(8)1072, _compilation(compilation)1073#ifndef PRODUCT1074, _block(block)1075#endif1076#ifdef ASSERT1077, _file(NULL)1078, _line(0)1079#endif1080{ }108110821083#ifdef ASSERT1084void LIR_List::set_file_and_line(const char * file, int line) {1085const char * f = strrchr(file, '/');1086if (f == NULL) f = strrchr(file, '\\');1087if (f == NULL) {1088f = file;1089} else {1090f++;1091}1092_file = f;1093_line = line;1094}1095#endif109610971098void LIR_List::append(LIR_InsertionBuffer* buffer) {1099assert(this == buffer->lir_list(), "wrong lir list");1100const int n = _operations.length();11011102if (buffer->number_of_ops() > 0) {1103// increase size of instructions list1104_operations.at_grow(n + buffer->number_of_ops() - 1, NULL);1105// insert ops from buffer into instructions list1106int op_index = buffer->number_of_ops() - 1;1107int ip_index = buffer->number_of_insertion_points() - 1;1108int from_index = n - 1;1109int to_index = _operations.length() - 1;1110for (; ip_index >= 0; ip_index --) {1111int index = buffer->index_at(ip_index);1112// make room after insertion point1113while (index < from_index) {1114_operations.at_put(to_index --, _operations.at(from_index --));1115}1116// insert ops from buffer1117for (int i = buffer->count_at(ip_index); i > 0; i --) {1118_operations.at_put(to_index --, buffer->op_at(op_index --));1119}1120}1121}11221123buffer->finish();1124}112511261127void LIR_List::oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info) {1128assert(reg->type() == T_OBJECT, "bad reg");1129append(new LIR_Op1(lir_move, LIR_OprFact::oopConst(o), reg, T_OBJECT, lir_patch_normal, info));1130}11311132void LIR_List::klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info) {1133assert(reg->type() == T_METADATA, "bad reg");1134append(new LIR_Op1(lir_move, LIR_OprFact::metadataConst(o), reg, T_METADATA, lir_patch_normal, info));1135}11361137void LIR_List::load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info, LIR_PatchCode patch_code) {1138append(new LIR_Op1(1139lir_move,1140LIR_OprFact::address(addr),1141src,1142addr->type(),1143patch_code,1144info));1145}114611471148void LIR_List::volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code) {1149append(new LIR_Op1(1150lir_move,1151LIR_OprFact::address(address),1152dst,1153address->type(),1154patch_code,1155info, lir_move_volatile));1156}11571158void LIR_List::volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {1159append(new LIR_Op1(1160lir_move,1161LIR_OprFact::address(new LIR_Address(base, offset, type)),1162dst,1163type,1164patch_code,1165info, lir_move_volatile));1166}116711681169void LIR_List::store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {1170append(new LIR_Op1(1171lir_move,1172LIR_OprFact::intConst(v),1173LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)),1174type,1175patch_code,1176info));1177}117811791180void LIR_List::store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {1181append(new LIR_Op1(1182lir_move,1183LIR_OprFact::oopConst(o),1184LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)),1185type,1186patch_code,1187info));1188}118911901191void LIR_List::store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) {1192append(new LIR_Op1(1193lir_move,1194src,1195LIR_OprFact::address(addr),1196addr->type(),1197patch_code,1198info));1199}120012011202void LIR_List::volatile_store_mem_reg(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) {1203append(new LIR_Op1(1204lir_move,1205src,1206LIR_OprFact::address(addr),1207addr->type(),1208patch_code,1209info,1210lir_move_volatile));1211}12121213void LIR_List::volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {1214append(new LIR_Op1(1215lir_move,1216src,1217LIR_OprFact::address(new LIR_Address(base, offset, type)),1218type,1219patch_code,1220info, lir_move_volatile));1221}122212231224void LIR_List::idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {1225append(new LIR_Op3(1226lir_idiv,1227left,1228right,1229tmp,1230res,1231info));1232}123312341235void LIR_List::idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {1236append(new LIR_Op3(1237lir_idiv,1238left,1239LIR_OprFact::intConst(right),1240tmp,1241res,1242info));1243}124412451246void LIR_List::irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {1247append(new LIR_Op3(1248lir_irem,1249left,1250right,1251tmp,1252res,1253info));1254}125512561257void LIR_List::irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {1258append(new LIR_Op3(1259lir_irem,1260left,1261LIR_OprFact::intConst(right),1262tmp,1263res,1264info));1265}126612671268void LIR_List::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {1269append(new LIR_Op2(1270lir_cmp,1271condition,1272LIR_OprFact::address(new LIR_Address(base, disp, T_INT)),1273LIR_OprFact::intConst(c),1274info));1275}127612771278void LIR_List::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info) {1279append(new LIR_Op2(1280lir_cmp,1281condition,1282reg,1283LIR_OprFact::address(addr),1284info));1285}12861287void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,1288int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {1289append(new LIR_OpAllocObj(1290klass,1291dst,1292t1,1293t2,1294t3,1295t4,1296header_size,1297object_size,1298init_check,1299stub));1300}13011302void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub) {1303append(new LIR_OpAllocArray(1304klass,1305len,1306dst,1307t1,1308t2,1309t3,1310t4,1311type,1312stub));1313}13141315void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {1316append(new LIR_Op2(1317lir_shl,1318value,1319count,1320dst,1321tmp));1322}13231324void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {1325append(new LIR_Op2(1326lir_shr,1327value,1328count,1329dst,1330tmp));1331}133213331334void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {1335append(new LIR_Op2(1336lir_ushr,1337value,1338count,1339dst,1340tmp));1341}13421343void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {1344append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,1345left,1346right,1347dst));1348}13491350void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info) {1351append(new LIR_OpLock(1352lir_lock,1353hdr,1354obj,1355lock,1356scratch,1357stub,1358info));1359}13601361void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {1362append(new LIR_OpLock(1363lir_unlock,1364hdr,1365obj,1366lock,1367scratch,1368stub,1369NULL));1370}137113721373void check_LIR() {1374// cannot do the proper checking as PRODUCT and other modes return different results1375// guarantee(sizeof(LIR_OprDesc) == wordSize, "may not have a v-table");1376}1377137813791380void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,1381LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,1382CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,1383ciMethod* profiled_method, int profiled_bci) {1384LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,1385tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub);1386if (profiled_method != NULL) {1387c->set_profiled_method(profiled_method);1388c->set_profiled_bci(profiled_bci);1389c->set_should_profile(true);1390}1391append(c);1392}13931394void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) {1395LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, NULL, info_for_patch, NULL);1396if (profiled_method != NULL) {1397c->set_profiled_method(profiled_method);1398c->set_profiled_bci(profiled_bci);1399c->set_should_profile(true);1400}1401append(c);1402}140314041405void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,1406CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {1407LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);1408if (profiled_method != NULL) {1409c->set_profiled_method(profiled_method);1410c->set_profiled_bci(profiled_bci);1411c->set_should_profile(true);1412}1413append(c);1414}14151416void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {1417if (deoptimize_on_null) {1418// Emit an explicit null check and deoptimize if opr is null1419CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);1420cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(NULL));1421branch(lir_cond_equal, deopt);1422} else {1423// Emit an implicit null check1424append(new LIR_Op1(lir_null_check, opr, info));1425}1426}14271428void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,1429LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {1430append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));1431}14321433void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,1434LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {1435append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));1436}14371438void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,1439LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {1440append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));1441}144214431444#ifdef PRODUCT14451446void print_LIR(BlockList* blocks) {1447}14481449#else1450// LIR_OprDesc1451void LIR_OprDesc::print() const {1452print(tty);1453}14541455void LIR_OprDesc::print(outputStream* out) const {1456if (is_illegal()) {1457return;1458}14591460out->print("[");1461if (is_pointer()) {1462pointer()->print_value_on(out);1463} else if (is_single_stack()) {1464out->print("stack:%d", single_stack_ix());1465} else if (is_double_stack()) {1466out->print("dbl_stack:%d",double_stack_ix());1467} else if (is_virtual()) {1468out->print("R%d", vreg_number());1469} else if (is_single_cpu()) {1470out->print("%s", as_register()->name());1471} else if (is_double_cpu()) {1472out->print("%s", as_register_hi()->name());1473out->print("%s", as_register_lo()->name());1474#if defined(X86)1475} else if (is_single_xmm()) {1476out->print("%s", as_xmm_float_reg()->name());1477} else if (is_double_xmm()) {1478out->print("%s", as_xmm_double_reg()->name());1479} else if (is_single_fpu()) {1480out->print("fpu%d", fpu_regnr());1481} else if (is_double_fpu()) {1482out->print("fpu%d", fpu_regnrLo());1483#elif defined(AARCH64)1484} else if (is_single_fpu()) {1485out->print("fpu%d", fpu_regnr());1486} else if (is_double_fpu()) {1487out->print("fpu%d", fpu_regnrLo());1488#elif defined(ARM)1489} else if (is_single_fpu()) {1490out->print("s%d", fpu_regnr());1491} else if (is_double_fpu()) {1492out->print("d%d", fpu_regnrLo() >> 1);1493#else1494} else if (is_single_fpu()) {1495out->print("%s", as_float_reg()->name());1496} else if (is_double_fpu()) {1497out->print("%s", as_double_reg()->name());1498#endif14991500} else if (is_illegal()) {1501out->print("-");1502} else {1503out->print("Unknown Operand");1504}1505if (!is_illegal()) {1506out->print("|%c", type_char());1507}1508if (is_register() && is_last_use()) {1509out->print("(last_use)");1510}1511out->print("]");1512}151315141515// LIR_Address1516void LIR_Const::print_value_on(outputStream* out) const {1517switch (type()) {1518case T_ADDRESS:out->print("address:%d",as_jint()); break;1519case T_INT: out->print("int:%d", as_jint()); break;1520case T_LONG: out->print("lng:" JLONG_FORMAT, as_jlong()); break;1521case T_FLOAT: out->print("flt:%f", as_jfloat()); break;1522case T_DOUBLE: out->print("dbl:%f", as_jdouble()); break;1523case T_OBJECT: out->print("obj:" INTPTR_FORMAT, p2i(as_jobject())); break;1524case T_METADATA: out->print("metadata:" INTPTR_FORMAT, p2i(as_metadata()));break;1525default: out->print("%3d:0x" UINT64_FORMAT_X, type(), (uint64_t)as_jlong()); break;1526}1527}15281529// LIR_Address1530void LIR_Address::print_value_on(outputStream* out) const {1531out->print("Base:"); _base->print(out);1532if (!_index->is_illegal()) {1533out->print(" Index:"); _index->print(out);1534switch (scale()) {1535case times_1: break;1536case times_2: out->print(" * 2"); break;1537case times_4: out->print(" * 4"); break;1538case times_8: out->print(" * 8"); break;1539}1540}1541out->print(" Disp: " INTX_FORMAT, _disp);1542}15431544// debug output of block header without InstructionPrinter1545// (because phi functions are not necessary for LIR)1546static void print_block(BlockBegin* x) {1547// print block id1548BlockEnd* end = x->end();1549tty->print("B%d ", x->block_id());15501551// print flags1552if (x->is_set(BlockBegin::std_entry_flag)) tty->print("std ");1553if (x->is_set(BlockBegin::osr_entry_flag)) tty->print("osr ");1554if (x->is_set(BlockBegin::exception_entry_flag)) tty->print("ex ");1555if (x->is_set(BlockBegin::subroutine_entry_flag)) tty->print("jsr ");1556if (x->is_set(BlockBegin::backward_branch_target_flag)) tty->print("bb ");1557if (x->is_set(BlockBegin::linear_scan_loop_header_flag)) tty->print("lh ");1558if (x->is_set(BlockBegin::linear_scan_loop_end_flag)) tty->print("le ");15591560// print block bci range1561tty->print("[%d, %d] ", x->bci(), (end == NULL ? -1 : end->printable_bci()));15621563// print predecessors and successors1564if (x->number_of_preds() > 0) {1565tty->print("preds: ");1566for (int i = 0; i < x->number_of_preds(); i ++) {1567tty->print("B%d ", x->pred_at(i)->block_id());1568}1569}15701571if (x->number_of_sux() > 0) {1572tty->print("sux: ");1573for (int i = 0; i < x->number_of_sux(); i ++) {1574tty->print("B%d ", x->sux_at(i)->block_id());1575}1576}15771578// print exception handlers1579if (x->number_of_exception_handlers() > 0) {1580tty->print("xhandler: ");1581for (int i = 0; i < x->number_of_exception_handlers(); i++) {1582tty->print("B%d ", x->exception_handler_at(i)->block_id());1583}1584}15851586tty->cr();1587}15881589void print_LIR(BlockList* blocks) {1590tty->print_cr("LIR:");1591int i;1592for (i = 0; i < blocks->length(); i++) {1593BlockBegin* bb = blocks->at(i);1594print_block(bb);1595tty->print("__id_Instruction___________________________________________"); tty->cr();1596bb->lir()->print_instructions();1597}1598}15991600void LIR_List::print_instructions() {1601for (int i = 0; i < _operations.length(); i++) {1602_operations.at(i)->print(); tty->cr();1603}1604tty->cr();1605}16061607// LIR_Ops printing routines1608// LIR_Op1609void LIR_Op::print_on(outputStream* out) const {1610if (id() != -1 || PrintCFGToFile) {1611out->print("%4d ", id());1612} else {1613out->print(" ");1614}1615out->print("%s ", name());1616print_instr(out);1617if (info() != NULL) out->print(" [bci:%d]", info()->stack()->bci());1618#ifdef ASSERT1619if (Verbose && _file != NULL) {1620out->print(" (%s:%d)", _file, _line);1621}1622#endif1623}16241625const char * LIR_Op::name() const {1626const char* s = NULL;1627switch(code()) {1628// LIR_Op01629case lir_membar: s = "membar"; break;1630case lir_membar_acquire: s = "membar_acquire"; break;1631case lir_membar_release: s = "membar_release"; break;1632case lir_membar_loadload: s = "membar_loadload"; break;1633case lir_membar_storestore: s = "membar_storestore"; break;1634case lir_membar_loadstore: s = "membar_loadstore"; break;1635case lir_membar_storeload: s = "membar_storeload"; break;1636case lir_label: s = "label"; break;1637case lir_nop: s = "nop"; break;1638case lir_on_spin_wait: s = "on_spin_wait"; break;1639case lir_backwardbranch_target: s = "backbranch"; break;1640case lir_std_entry: s = "std_entry"; break;1641case lir_osr_entry: s = "osr_entry"; break;1642case lir_fpop_raw: s = "fpop_raw"; break;1643case lir_breakpoint: s = "breakpoint"; break;1644case lir_get_thread: s = "get_thread"; break;1645// LIR_Op11646case lir_fxch: s = "fxch"; break;1647case lir_fld: s = "fld"; break;1648case lir_push: s = "push"; break;1649case lir_pop: s = "pop"; break;1650case lir_null_check: s = "null_check"; break;1651case lir_return: s = "return"; break;1652case lir_safepoint: s = "safepoint"; break;1653case lir_leal: s = "leal"; break;1654case lir_branch: s = "branch"; break;1655case lir_cond_float_branch: s = "flt_cond_br"; break;1656case lir_move: s = "move"; break;1657case lir_roundfp: s = "roundfp"; break;1658case lir_rtcall: s = "rtcall"; break;1659case lir_throw: s = "throw"; break;1660case lir_unwind: s = "unwind"; break;1661case lir_convert: s = "convert"; break;1662case lir_alloc_object: s = "alloc_obj"; break;1663case lir_monaddr: s = "mon_addr"; break;1664// LIR_Op21665case lir_cmp: s = "cmp"; break;1666case lir_cmp_l2i: s = "cmp_l2i"; break;1667case lir_ucmp_fd2i: s = "ucomp_fd2i"; break;1668case lir_cmp_fd2i: s = "comp_fd2i"; break;1669case lir_cmove: s = "cmove"; break;1670case lir_add: s = "add"; break;1671case lir_sub: s = "sub"; break;1672case lir_mul: s = "mul"; break;1673case lir_div: s = "div"; break;1674case lir_rem: s = "rem"; break;1675case lir_abs: s = "abs"; break;1676case lir_neg: s = "neg"; break;1677case lir_sqrt: s = "sqrt"; break;1678case lir_logic_and: s = "logic_and"; break;1679case lir_logic_or: s = "logic_or"; break;1680case lir_logic_xor: s = "logic_xor"; break;1681case lir_shl: s = "shift_left"; break;1682case lir_shr: s = "shift_right"; break;1683case lir_ushr: s = "ushift_right"; break;1684case lir_alloc_array: s = "alloc_array"; break;1685case lir_xadd: s = "xadd"; break;1686case lir_xchg: s = "xchg"; break;1687// LIR_Op31688case lir_idiv: s = "idiv"; break;1689case lir_irem: s = "irem"; break;1690case lir_fmad: s = "fmad"; break;1691case lir_fmaf: s = "fmaf"; break;1692// LIR_OpJavaCall1693case lir_static_call: s = "static"; break;1694case lir_optvirtual_call: s = "optvirtual"; break;1695case lir_icvirtual_call: s = "icvirtual"; break;1696case lir_dynamic_call: s = "dynamic"; break;1697// LIR_OpArrayCopy1698case lir_arraycopy: s = "arraycopy"; break;1699// LIR_OpUpdateCRC321700case lir_updatecrc32: s = "updatecrc32"; break;1701// LIR_OpLock1702case lir_lock: s = "lock"; break;1703case lir_unlock: s = "unlock"; break;1704// LIR_OpDelay1705case lir_delay_slot: s = "delay"; break;1706// LIR_OpTypeCheck1707case lir_instanceof: s = "instanceof"; break;1708case lir_checkcast: s = "checkcast"; break;1709case lir_store_check: s = "store_check"; break;1710// LIR_OpCompareAndSwap1711case lir_cas_long: s = "cas_long"; break;1712case lir_cas_obj: s = "cas_obj"; break;1713case lir_cas_int: s = "cas_int"; break;1714// LIR_OpProfileCall1715case lir_profile_call: s = "profile_call"; break;1716// LIR_OpProfileType1717case lir_profile_type: s = "profile_type"; break;1718// LIR_OpAssert1719#ifdef ASSERT1720case lir_assert: s = "assert"; break;1721#endif1722case lir_none: ShouldNotReachHere();break;1723default: s = "illegal_op"; break;1724}1725return s;1726}17271728// LIR_OpJavaCall1729void LIR_OpJavaCall::print_instr(outputStream* out) const {1730out->print("call: ");1731out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));1732if (receiver()->is_valid()) {1733out->print(" [recv: "); receiver()->print(out); out->print("]");1734}1735if (result_opr()->is_valid()) {1736out->print(" [result: "); result_opr()->print(out); out->print("]");1737}1738}17391740// LIR_OpLabel1741void LIR_OpLabel::print_instr(outputStream* out) const {1742out->print("[label:" INTPTR_FORMAT "]", p2i(_label));1743}17441745// LIR_OpArrayCopy1746void LIR_OpArrayCopy::print_instr(outputStream* out) const {1747src()->print(out); out->print(" ");1748src_pos()->print(out); out->print(" ");1749dst()->print(out); out->print(" ");1750dst_pos()->print(out); out->print(" ");1751length()->print(out); out->print(" ");1752tmp()->print(out); out->print(" ");1753}17541755// LIR_OpUpdateCRC321756void LIR_OpUpdateCRC32::print_instr(outputStream* out) const {1757crc()->print(out); out->print(" ");1758val()->print(out); out->print(" ");1759result_opr()->print(out); out->print(" ");1760}17611762// LIR_OpCompareAndSwap1763void LIR_OpCompareAndSwap::print_instr(outputStream* out) const {1764addr()->print(out); out->print(" ");1765cmp_value()->print(out); out->print(" ");1766new_value()->print(out); out->print(" ");1767tmp1()->print(out); out->print(" ");1768tmp2()->print(out); out->print(" ");17691770}17711772// LIR_Op01773void LIR_Op0::print_instr(outputStream* out) const {1774result_opr()->print(out);1775}17761777// LIR_Op11778const char * LIR_Op1::name() const {1779if (code() == lir_move) {1780switch (move_kind()) {1781case lir_move_normal:1782return "move";1783case lir_move_unaligned:1784return "unaligned move";1785case lir_move_volatile:1786return "volatile_move";1787case lir_move_wide:1788return "wide_move";1789default:1790ShouldNotReachHere();1791return "illegal_op";1792}1793} else {1794return LIR_Op::name();1795}1796}179717981799void LIR_Op1::print_instr(outputStream* out) const {1800_opr->print(out); out->print(" ");1801result_opr()->print(out); out->print(" ");1802print_patch_code(out, patch_code());1803}180418051806// LIR_Op11807void LIR_OpRTCall::print_instr(outputStream* out) const {1808intx a = (intx)addr();1809out->print("%s", Runtime1::name_for_address(addr()));1810out->print(" ");1811tmp()->print(out);1812}18131814void LIR_Op1::print_patch_code(outputStream* out, LIR_PatchCode code) {1815switch(code) {1816case lir_patch_none: break;1817case lir_patch_low: out->print("[patch_low]"); break;1818case lir_patch_high: out->print("[patch_high]"); break;1819case lir_patch_normal: out->print("[patch_normal]"); break;1820default: ShouldNotReachHere();1821}1822}18231824// LIR_OpBranch1825void LIR_OpBranch::print_instr(outputStream* out) const {1826print_condition(out, cond()); out->print(" ");1827if (block() != NULL) {1828out->print("[B%d] ", block()->block_id());1829} else if (stub() != NULL) {1830out->print("[");1831stub()->print_name(out);1832out->print(": " INTPTR_FORMAT "]", p2i(stub()));1833if (stub()->info() != NULL) out->print(" [bci:%d]", stub()->info()->stack()->bci());1834} else {1835out->print("[label:" INTPTR_FORMAT "] ", p2i(label()));1836}1837if (ublock() != NULL) {1838out->print("unordered: [B%d] ", ublock()->block_id());1839}1840}18411842void LIR_Op::print_condition(outputStream* out, LIR_Condition cond) {1843switch(cond) {1844case lir_cond_equal: out->print("[EQ]"); break;1845case lir_cond_notEqual: out->print("[NE]"); break;1846case lir_cond_less: out->print("[LT]"); break;1847case lir_cond_lessEqual: out->print("[LE]"); break;1848case lir_cond_greaterEqual: out->print("[GE]"); break;1849case lir_cond_greater: out->print("[GT]"); break;1850case lir_cond_belowEqual: out->print("[BE]"); break;1851case lir_cond_aboveEqual: out->print("[AE]"); break;1852case lir_cond_always: out->print("[AL]"); break;1853default: out->print("[%d]",cond); break;1854}1855}18561857// LIR_OpConvert1858void LIR_OpConvert::print_instr(outputStream* out) const {1859print_bytecode(out, bytecode());1860in_opr()->print(out); out->print(" ");1861result_opr()->print(out); out->print(" ");1862#ifdef PPC321863if(tmp1()->is_valid()) {1864tmp1()->print(out); out->print(" ");1865tmp2()->print(out); out->print(" ");1866}1867#endif1868}18691870void LIR_OpConvert::print_bytecode(outputStream* out, Bytecodes::Code code) {1871switch(code) {1872case Bytecodes::_d2f: out->print("[d2f] "); break;1873case Bytecodes::_d2i: out->print("[d2i] "); break;1874case Bytecodes::_d2l: out->print("[d2l] "); break;1875case Bytecodes::_f2d: out->print("[f2d] "); break;1876case Bytecodes::_f2i: out->print("[f2i] "); break;1877case Bytecodes::_f2l: out->print("[f2l] "); break;1878case Bytecodes::_i2b: out->print("[i2b] "); break;1879case Bytecodes::_i2c: out->print("[i2c] "); break;1880case Bytecodes::_i2d: out->print("[i2d] "); break;1881case Bytecodes::_i2f: out->print("[i2f] "); break;1882case Bytecodes::_i2l: out->print("[i2l] "); break;1883case Bytecodes::_i2s: out->print("[i2s] "); break;1884case Bytecodes::_l2i: out->print("[l2i] "); break;1885case Bytecodes::_l2f: out->print("[l2f] "); break;1886case Bytecodes::_l2d: out->print("[l2d] "); break;1887default:1888out->print("[?%d]",code);1889break;1890}1891}18921893void LIR_OpAllocObj::print_instr(outputStream* out) const {1894klass()->print(out); out->print(" ");1895obj()->print(out); out->print(" ");1896tmp1()->print(out); out->print(" ");1897tmp2()->print(out); out->print(" ");1898tmp3()->print(out); out->print(" ");1899tmp4()->print(out); out->print(" ");1900out->print("[hdr:%d]", header_size()); out->print(" ");1901out->print("[obj:%d]", object_size()); out->print(" ");1902out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry()));1903}19041905void LIR_OpRoundFP::print_instr(outputStream* out) const {1906_opr->print(out); out->print(" ");1907tmp()->print(out); out->print(" ");1908result_opr()->print(out); out->print(" ");1909}19101911// LIR_Op21912void LIR_Op2::print_instr(outputStream* out) const {1913if (code() == lir_cmove || code() == lir_cmp) {1914print_condition(out, condition()); out->print(" ");1915}1916in_opr1()->print(out); out->print(" ");1917in_opr2()->print(out); out->print(" ");1918if (tmp1_opr()->is_valid()) { tmp1_opr()->print(out); out->print(" "); }1919if (tmp2_opr()->is_valid()) { tmp2_opr()->print(out); out->print(" "); }1920if (tmp3_opr()->is_valid()) { tmp3_opr()->print(out); out->print(" "); }1921if (tmp4_opr()->is_valid()) { tmp4_opr()->print(out); out->print(" "); }1922if (tmp5_opr()->is_valid()) { tmp5_opr()->print(out); out->print(" "); }1923result_opr()->print(out);1924}19251926void LIR_OpAllocArray::print_instr(outputStream* out) const {1927klass()->print(out); out->print(" ");1928len()->print(out); out->print(" ");1929obj()->print(out); out->print(" ");1930tmp1()->print(out); out->print(" ");1931tmp2()->print(out); out->print(" ");1932tmp3()->print(out); out->print(" ");1933tmp4()->print(out); out->print(" ");1934out->print("[type:0x%x]", type()); out->print(" ");1935out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));1936}193719381939void LIR_OpTypeCheck::print_instr(outputStream* out) const {1940object()->print(out); out->print(" ");1941if (code() == lir_store_check) {1942array()->print(out); out->print(" ");1943}1944if (code() != lir_store_check) {1945klass()->print_name_on(out); out->print(" ");1946if (fast_check()) out->print("fast_check ");1947}1948tmp1()->print(out); out->print(" ");1949tmp2()->print(out); out->print(" ");1950tmp3()->print(out); out->print(" ");1951result_opr()->print(out); out->print(" ");1952if (info_for_exception() != NULL) out->print(" [bci:%d]", info_for_exception()->stack()->bci());1953}195419551956// LIR_Op31957void LIR_Op3::print_instr(outputStream* out) const {1958in_opr1()->print(out); out->print(" ");1959in_opr2()->print(out); out->print(" ");1960in_opr3()->print(out); out->print(" ");1961result_opr()->print(out);1962}196319641965void LIR_OpLock::print_instr(outputStream* out) const {1966hdr_opr()->print(out); out->print(" ");1967obj_opr()->print(out); out->print(" ");1968lock_opr()->print(out); out->print(" ");1969if (_scratch->is_valid()) {1970_scratch->print(out); out->print(" ");1971}1972out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry()));1973}19741975#ifdef ASSERT1976void LIR_OpAssert::print_instr(outputStream* out) const {1977print_condition(out, condition()); out->print(" ");1978in_opr1()->print(out); out->print(" ");1979in_opr2()->print(out); out->print(", \"");1980out->print("%s", msg()); out->print("\"");1981}1982#endif198319841985void LIR_OpDelay::print_instr(outputStream* out) const {1986_op->print_on(out);1987}198819891990// LIR_OpProfileCall1991void LIR_OpProfileCall::print_instr(outputStream* out) const {1992profiled_method()->name()->print_symbol_on(out);1993out->print(".");1994profiled_method()->holder()->name()->print_symbol_on(out);1995out->print(" @ %d ", profiled_bci());1996mdo()->print(out); out->print(" ");1997recv()->print(out); out->print(" ");1998tmp1()->print(out); out->print(" ");1999}20002001// LIR_OpProfileType2002void LIR_OpProfileType::print_instr(outputStream* out) const {2003out->print("exact = ");2004if (exact_klass() == NULL) {2005out->print("unknown");2006} else {2007exact_klass()->print_name_on(out);2008}2009out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());2010out->print(" ");2011mdp()->print(out); out->print(" ");2012obj()->print(out); out->print(" ");2013tmp()->print(out); out->print(" ");2014}20152016#endif // PRODUCT20172018// Implementation of LIR_InsertionBuffer20192020void LIR_InsertionBuffer::append(int index, LIR_Op* op) {2021assert(_index_and_count.length() % 2 == 0, "must have a count for each index");20222023int i = number_of_insertion_points() - 1;2024if (i < 0 || index_at(i) < index) {2025append_new(index, 1);2026} else {2027assert(index_at(i) == index, "can append LIR_Ops in ascending order only");2028assert(count_at(i) > 0, "check");2029set_count_at(i, count_at(i) + 1);2030}2031_ops.push(op);20322033DEBUG_ONLY(verify());2034}20352036#ifdef ASSERT2037void LIR_InsertionBuffer::verify() {2038int sum = 0;2039int prev_idx = -1;20402041for (int i = 0; i < number_of_insertion_points(); i++) {2042assert(prev_idx < index_at(i), "index must be ordered ascending");2043sum += count_at(i);2044}2045assert(sum == number_of_ops(), "wrong total sum");2046}2047#endif204820492050