Path: blob/master/src/hotspot/share/c1/c1_LIRGenerator.cpp
40930 views
/*1* Copyright (c) 2005, 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_Compilation.hpp"26#include "c1/c1_Defs.hpp"27#include "c1/c1_FrameMap.hpp"28#include "c1/c1_Instruction.hpp"29#include "c1/c1_LIRAssembler.hpp"30#include "c1/c1_LIRGenerator.hpp"31#include "c1/c1_ValueStack.hpp"32#include "ci/ciArrayKlass.hpp"33#include "ci/ciInstance.hpp"34#include "ci/ciObjArray.hpp"35#include "ci/ciUtilities.hpp"36#include "gc/shared/barrierSet.hpp"37#include "gc/shared/c1/barrierSetC1.hpp"38#include "oops/klass.inline.hpp"39#include "runtime/sharedRuntime.hpp"40#include "runtime/stubRoutines.hpp"41#include "runtime/vm_version.hpp"42#include "utilities/bitMap.inline.hpp"43#include "utilities/macros.hpp"44#include "utilities/powerOfTwo.hpp"4546#ifdef ASSERT47#define __ gen()->lir(__FILE__, __LINE__)->48#else49#define __ gen()->lir()->50#endif5152#ifndef PATCHED_ADDR53#define PATCHED_ADDR (max_jint)54#endif5556void PhiResolverState::reset() {57_virtual_operands.clear();58_other_operands.clear();59_vreg_table.clear();60}616263//--------------------------------------------------------------64// PhiResolver6566// Resolves cycles:67//68// r1 := r2 becomes temp := r169// r2 := r1 r1 := r270// r2 := temp71// and orders moves:72//73// r2 := r3 becomes r1 := r274// r1 := r2 r2 := r37576PhiResolver::PhiResolver(LIRGenerator* gen)77: _gen(gen)78, _state(gen->resolver_state())79, _temp(LIR_OprFact::illegalOpr)80{81// reinitialize the shared state arrays82_state.reset();83}848586void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) {87assert(src->is_valid(), "");88assert(dest->is_valid(), "");89__ move(src, dest);90}919293void PhiResolver::move_temp_to(LIR_Opr dest) {94assert(_temp->is_valid(), "");95emit_move(_temp, dest);96NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr);97}9899100void PhiResolver::move_to_temp(LIR_Opr src) {101assert(_temp->is_illegal(), "");102_temp = _gen->new_register(src->type());103emit_move(src, _temp);104}105106107// Traverse assignment graph in depth first order and generate moves in post order108// ie. two assignments: b := c, a := b start with node c:109// Call graph: move(NULL, c) -> move(c, b) -> move(b, a)110// Generates moves in this order: move b to a and move c to b111// ie. cycle a := b, b := a start with node a112// Call graph: move(NULL, a) -> move(a, b) -> move(b, a)113// Generates moves in this order: move b to temp, move a to b, move temp to a114void PhiResolver::move(ResolveNode* src, ResolveNode* dest) {115if (!dest->visited()) {116dest->set_visited();117for (int i = dest->no_of_destinations()-1; i >= 0; i --) {118move(dest, dest->destination_at(i));119}120} else if (!dest->start_node()) {121// cylce in graph detected122assert(_loop == NULL, "only one loop valid!");123_loop = dest;124move_to_temp(src->operand());125return;126} // else dest is a start node127128if (!dest->assigned()) {129if (_loop == dest) {130move_temp_to(dest->operand());131dest->set_assigned();132} else if (src != NULL) {133emit_move(src->operand(), dest->operand());134dest->set_assigned();135}136}137}138139140PhiResolver::~PhiResolver() {141int i;142// resolve any cycles in moves from and to virtual registers143for (i = virtual_operands().length() - 1; i >= 0; i --) {144ResolveNode* node = virtual_operands().at(i);145if (!node->visited()) {146_loop = NULL;147move(NULL, node);148node->set_start_node();149assert(_temp->is_illegal(), "move_temp_to() call missing");150}151}152153// generate move for move from non virtual register to abitrary destination154for (i = other_operands().length() - 1; i >= 0; i --) {155ResolveNode* node = other_operands().at(i);156for (int j = node->no_of_destinations() - 1; j >= 0; j --) {157emit_move(node->operand(), node->destination_at(j)->operand());158}159}160}161162163ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) {164ResolveNode* node;165if (opr->is_virtual()) {166int vreg_num = opr->vreg_number();167node = vreg_table().at_grow(vreg_num, NULL);168assert(node == NULL || node->operand() == opr, "");169if (node == NULL) {170node = new ResolveNode(opr);171vreg_table().at_put(vreg_num, node);172}173// Make sure that all virtual operands show up in the list when174// they are used as the source of a move.175if (source && !virtual_operands().contains(node)) {176virtual_operands().append(node);177}178} else {179assert(source, "");180node = new ResolveNode(opr);181other_operands().append(node);182}183return node;184}185186187void PhiResolver::move(LIR_Opr src, LIR_Opr dest) {188assert(dest->is_virtual(), "");189// tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr();190assert(src->is_valid(), "");191assert(dest->is_valid(), "");192ResolveNode* source = source_node(src);193source->append(destination_node(dest));194}195196197//--------------------------------------------------------------198// LIRItem199200void LIRItem::set_result(LIR_Opr opr) {201assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change");202value()->set_operand(opr);203204if (opr->is_virtual()) {205_gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL);206}207208_result = opr;209}210211void LIRItem::load_item() {212if (result()->is_illegal()) {213// update the items result214_result = value()->operand();215}216if (!result()->is_register()) {217LIR_Opr reg = _gen->new_register(value()->type());218__ move(result(), reg);219if (result()->is_constant()) {220_result = reg;221} else {222set_result(reg);223}224}225}226227228void LIRItem::load_for_store(BasicType type) {229if (_gen->can_store_as_constant(value(), type)) {230_result = value()->operand();231if (!_result->is_constant()) {232_result = LIR_OprFact::value_type(value()->type());233}234} else if (type == T_BYTE || type == T_BOOLEAN) {235load_byte_item();236} else {237load_item();238}239}240241void LIRItem::load_item_force(LIR_Opr reg) {242LIR_Opr r = result();243if (r != reg) {244#if !defined(ARM) && !defined(E500V2)245if (r->type() != reg->type()) {246// moves between different types need an intervening spill slot247r = _gen->force_to_spill(r, reg->type());248}249#endif250__ move(r, reg);251_result = reg;252}253}254255ciObject* LIRItem::get_jobject_constant() const {256ObjectType* oc = type()->as_ObjectType();257if (oc) {258return oc->constant_value();259}260return NULL;261}262263264jint LIRItem::get_jint_constant() const {265assert(is_constant() && value() != NULL, "");266assert(type()->as_IntConstant() != NULL, "type check");267return type()->as_IntConstant()->value();268}269270271jint LIRItem::get_address_constant() const {272assert(is_constant() && value() != NULL, "");273assert(type()->as_AddressConstant() != NULL, "type check");274return type()->as_AddressConstant()->value();275}276277278jfloat LIRItem::get_jfloat_constant() const {279assert(is_constant() && value() != NULL, "");280assert(type()->as_FloatConstant() != NULL, "type check");281return type()->as_FloatConstant()->value();282}283284285jdouble LIRItem::get_jdouble_constant() const {286assert(is_constant() && value() != NULL, "");287assert(type()->as_DoubleConstant() != NULL, "type check");288return type()->as_DoubleConstant()->value();289}290291292jlong LIRItem::get_jlong_constant() const {293assert(is_constant() && value() != NULL, "");294assert(type()->as_LongConstant() != NULL, "type check");295return type()->as_LongConstant()->value();296}297298299300//--------------------------------------------------------------301302303void LIRGenerator::block_do_prolog(BlockBegin* block) {304#ifndef PRODUCT305if (PrintIRWithLIR) {306block->print();307}308#endif309310// set up the list of LIR instructions311assert(block->lir() == NULL, "LIR list already computed for this block");312_lir = new LIR_List(compilation(), block);313block->set_lir(_lir);314315__ branch_destination(block->label());316317if (LIRTraceExecution &&318Compilation::current()->hir()->start()->block_id() != block->block_id() &&319!block->is_set(BlockBegin::exception_entry_flag)) {320assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");321trace_block_entry(block);322}323}324325326void LIRGenerator::block_do_epilog(BlockBegin* block) {327#ifndef PRODUCT328if (PrintIRWithLIR) {329tty->cr();330}331#endif332333// LIR_Opr for unpinned constants shouldn't be referenced by other334// blocks so clear them out after processing the block.335for (int i = 0; i < _unpinned_constants.length(); i++) {336_unpinned_constants.at(i)->clear_operand();337}338_unpinned_constants.trunc_to(0);339340// clear our any registers for other local constants341_constants.trunc_to(0);342_reg_for_constants.trunc_to(0);343}344345346void LIRGenerator::block_do(BlockBegin* block) {347CHECK_BAILOUT();348349block_do_prolog(block);350set_block(block);351352for (Instruction* instr = block; instr != NULL; instr = instr->next()) {353if (instr->is_pinned()) do_root(instr);354}355356set_block(NULL);357block_do_epilog(block);358}359360361//-------------------------LIRGenerator-----------------------------362363// This is where the tree-walk starts; instr must be root;364void LIRGenerator::do_root(Value instr) {365CHECK_BAILOUT();366367InstructionMark im(compilation(), instr);368369assert(instr->is_pinned(), "use only with roots");370assert(instr->subst() == instr, "shouldn't have missed substitution");371372instr->visit(this);373374assert(!instr->has_uses() || instr->operand()->is_valid() ||375instr->as_Constant() != NULL || bailed_out(), "invalid item set");376}377378379// This is called for each node in tree; the walk stops if a root is reached380void LIRGenerator::walk(Value instr) {381InstructionMark im(compilation(), instr);382//stop walk when encounter a root383if ((instr->is_pinned() && instr->as_Phi() == NULL) || instr->operand()->is_valid()) {384assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited");385} else {386assert(instr->subst() == instr, "shouldn't have missed substitution");387instr->visit(this);388// assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use");389}390}391392393CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {394assert(state != NULL, "state must be defined");395396#ifndef PRODUCT397state->verify();398#endif399400ValueStack* s = state;401for_each_state(s) {402if (s->kind() == ValueStack::EmptyExceptionState) {403assert(s->stack_size() == 0 && s->locals_size() == 0 && (s->locks_size() == 0 || s->locks_size() == 1), "state must be empty");404continue;405}406407int index;408Value value;409for_each_stack_value(s, index, value) {410assert(value->subst() == value, "missed substitution");411if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {412walk(value);413assert(value->operand()->is_valid(), "must be evaluated now");414}415}416417int bci = s->bci();418IRScope* scope = s->scope();419ciMethod* method = scope->method();420421MethodLivenessResult liveness = method->liveness_at_bci(bci);422if (bci == SynchronizationEntryBCI) {423if (x->as_ExceptionObject() || x->as_Throw()) {424// all locals are dead on exit from the synthetic unlocker425liveness.clear();426} else {427assert(x->as_MonitorEnter() || x->as_ProfileInvoke(), "only other cases are MonitorEnter and ProfileInvoke");428}429}430if (!liveness.is_valid()) {431// Degenerate or breakpointed method.432bailout("Degenerate or breakpointed method");433} else {434assert((int)liveness.size() == s->locals_size(), "error in use of liveness");435for_each_local_value(s, index, value) {436assert(value->subst() == value, "missed substition");437if (liveness.at(index) && !value->type()->is_illegal()) {438if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {439walk(value);440assert(value->operand()->is_valid(), "must be evaluated now");441}442} else {443// NULL out this local so that linear scan can assume that all non-NULL values are live.444s->invalidate_local(index);445}446}447}448}449450return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException));451}452453454CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {455return state_for(x, x->exception_state());456}457458459void LIRGenerator::klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve) {460/* C2 relies on constant pool entries being resolved (ciTypeFlow), so if tiered compilation461* is active and the class hasn't yet been resolved we need to emit a patch that resolves462* the class. */463if ((!CompilerConfig::is_c1_only_no_jvmci() && need_resolve) || !obj->is_loaded() || PatchALot) {464assert(info != NULL, "info must be set if class is not loaded");465__ klass2reg_patch(NULL, r, info);466} else {467// no patching needed468__ metadata2reg(obj->constant_encoding(), r);469}470}471472473void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index,474CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) {475CodeStub* stub = new RangeCheckStub(range_check_info, index, array);476if (index->is_constant()) {477cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(),478index->as_jint(), null_check_info);479__ branch(lir_cond_belowEqual, stub); // forward branch480} else {481cmp_reg_mem(lir_cond_aboveEqual, index, array,482arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info);483__ branch(lir_cond_aboveEqual, stub); // forward branch484}485}486487488void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {489CodeStub* stub = new RangeCheckStub(info, index);490if (index->is_constant()) {491cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info);492__ branch(lir_cond_belowEqual, stub); // forward branch493} else {494cmp_reg_mem(lir_cond_aboveEqual, index, buffer,495java_nio_Buffer::limit_offset(), T_INT, info);496__ branch(lir_cond_aboveEqual, stub); // forward branch497}498__ move(index, result);499}500501502503void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp_op, CodeEmitInfo* info) {504LIR_Opr result_op = result;505LIR_Opr left_op = left;506LIR_Opr right_op = right;507508if (TwoOperandLIRForm && left_op != result_op) {509assert(right_op != result_op, "malformed");510__ move(left_op, result_op);511left_op = result_op;512}513514switch(code) {515case Bytecodes::_dadd:516case Bytecodes::_fadd:517case Bytecodes::_ladd:518case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break;519case Bytecodes::_fmul:520case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break;521522case Bytecodes::_dmul: __ mul(left_op, right_op, result_op, tmp_op); break;523524case Bytecodes::_imul:525{526bool did_strength_reduce = false;527528if (right->is_constant()) {529jint c = right->as_jint();530if (c > 0 && is_power_of_2(c)) {531// do not need tmp here532__ shift_left(left_op, exact_log2(c), result_op);533did_strength_reduce = true;534} else {535did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);536}537}538// we couldn't strength reduce so just emit the multiply539if (!did_strength_reduce) {540__ mul(left_op, right_op, result_op);541}542}543break;544545case Bytecodes::_dsub:546case Bytecodes::_fsub:547case Bytecodes::_lsub:548case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break;549550case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break;551// ldiv and lrem are implemented with a direct runtime call552553case Bytecodes::_ddiv: __ div(left_op, right_op, result_op, tmp_op); break;554555case Bytecodes::_drem:556case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break;557558default: ShouldNotReachHere();559}560}561562563void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) {564arithmetic_op(code, result, left, right, tmp);565}566567568void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) {569arithmetic_op(code, result, left, right, LIR_OprFact::illegalOpr, info);570}571572573void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) {574arithmetic_op(code, result, left, right, tmp);575}576577578void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) {579580if (TwoOperandLIRForm && value != result_op581// Only 32bit right shifts require two operand form on S390.582S390_ONLY(&& (code == Bytecodes::_ishr || code == Bytecodes::_iushr))) {583assert(count != result_op, "malformed");584__ move(value, result_op);585value = result_op;586}587588assert(count->is_constant() || count->is_register(), "must be");589switch(code) {590case Bytecodes::_ishl:591case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break;592case Bytecodes::_ishr:593case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break;594case Bytecodes::_iushr:595case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break;596default: ShouldNotReachHere();597}598}599600601void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) {602if (TwoOperandLIRForm && left_op != result_op) {603assert(right_op != result_op, "malformed");604__ move(left_op, result_op);605left_op = result_op;606}607608switch(code) {609case Bytecodes::_iand:610case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break;611612case Bytecodes::_ior:613case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break;614615case Bytecodes::_ixor:616case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break;617618default: ShouldNotReachHere();619}620}621622623void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) {624if (!GenerateSynchronizationCode) return;625// for slow path, use debug info for state after successful locking626CodeStub* slow_path = new MonitorEnterStub(object, lock, info);627__ load_stack_address_monitor(monitor_no, lock);628// for handling NullPointerException, use debug info representing just the lock stack before this monitorenter629__ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception);630}631632633void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) {634if (!GenerateSynchronizationCode) return;635// setup registers636LIR_Opr hdr = lock;637lock = new_hdr;638CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no);639__ load_stack_address_monitor(monitor_no, lock);640__ unlock_object(hdr, object, lock, scratch, slow_path);641}642643#ifndef PRODUCT644void LIRGenerator::print_if_not_loaded(const NewInstance* new_instance) {645if (PrintNotLoaded && !new_instance->klass()->is_loaded()) {646tty->print_cr(" ###class not loaded at new bci %d", new_instance->printable_bci());647} else if (PrintNotLoaded && (!CompilerConfig::is_c1_only_no_jvmci() && new_instance->is_unresolved())) {648tty->print_cr(" ###class not resolved at new bci %d", new_instance->printable_bci());649}650}651#endif652653void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) {654klass2reg_with_patching(klass_reg, klass, info, is_unresolved);655// If klass is not loaded we do not know if the klass has finalizers:656if (UseFastNewInstance && klass->is_loaded()657&& !Klass::layout_helper_needs_slow_path(klass->layout_helper())) {658659Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id;660661CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id);662663assert(klass->is_loaded(), "must be loaded");664// allocate space for instance665assert(klass->size_helper() >= 0, "illegal instance size");666const int instance_size = align_object_size(klass->size_helper());667__ allocate_object(dst, scratch1, scratch2, scratch3, scratch4,668oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);669} else {670CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id);671__ branch(lir_cond_always, slow_path);672__ branch_destination(slow_path->continuation());673}674}675676677static bool is_constant_zero(Instruction* inst) {678IntConstant* c = inst->type()->as_IntConstant();679if (c) {680return (c->value() == 0);681}682return false;683}684685686static bool positive_constant(Instruction* inst) {687IntConstant* c = inst->type()->as_IntConstant();688if (c) {689return (c->value() >= 0);690}691return false;692}693694695static ciArrayKlass* as_array_klass(ciType* type) {696if (type != NULL && type->is_array_klass() && type->is_loaded()) {697return (ciArrayKlass*)type;698} else {699return NULL;700}701}702703static ciType* phi_declared_type(Phi* phi) {704ciType* t = phi->operand_at(0)->declared_type();705if (t == NULL) {706return NULL;707}708for(int i = 1; i < phi->operand_count(); i++) {709if (t != phi->operand_at(i)->declared_type()) {710return NULL;711}712}713return t;714}715716void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) {717Instruction* src = x->argument_at(0);718Instruction* src_pos = x->argument_at(1);719Instruction* dst = x->argument_at(2);720Instruction* dst_pos = x->argument_at(3);721Instruction* length = x->argument_at(4);722723// first try to identify the likely type of the arrays involved724ciArrayKlass* expected_type = NULL;725bool is_exact = false, src_objarray = false, dst_objarray = false;726{727ciArrayKlass* src_exact_type = as_array_klass(src->exact_type());728ciArrayKlass* src_declared_type = as_array_klass(src->declared_type());729Phi* phi;730if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) {731src_declared_type = as_array_klass(phi_declared_type(phi));732}733ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type());734ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type());735if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) {736dst_declared_type = as_array_klass(phi_declared_type(phi));737}738739if (src_exact_type != NULL && src_exact_type == dst_exact_type) {740// the types exactly match so the type is fully known741is_exact = true;742expected_type = src_exact_type;743} else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) {744ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type;745ciArrayKlass* src_type = NULL;746if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) {747src_type = (ciArrayKlass*) src_exact_type;748} else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) {749src_type = (ciArrayKlass*) src_declared_type;750}751if (src_type != NULL) {752if (src_type->element_type()->is_subtype_of(dst_type->element_type())) {753is_exact = true;754expected_type = dst_type;755}756}757}758// at least pass along a good guess759if (expected_type == NULL) expected_type = dst_exact_type;760if (expected_type == NULL) expected_type = src_declared_type;761if (expected_type == NULL) expected_type = dst_declared_type;762763src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass());764dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass());765}766767// if a probable array type has been identified, figure out if any768// of the required checks for a fast case can be elided.769int flags = LIR_OpArrayCopy::all_flags;770771if (!src_objarray)772flags &= ~LIR_OpArrayCopy::src_objarray;773if (!dst_objarray)774flags &= ~LIR_OpArrayCopy::dst_objarray;775776if (!x->arg_needs_null_check(0))777flags &= ~LIR_OpArrayCopy::src_null_check;778if (!x->arg_needs_null_check(2))779flags &= ~LIR_OpArrayCopy::dst_null_check;780781782if (expected_type != NULL) {783Value length_limit = NULL;784785IfOp* ifop = length->as_IfOp();786if (ifop != NULL) {787// look for expressions like min(v, a.length) which ends up as788// x > y ? y : x or x >= y ? y : x789if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) &&790ifop->x() == ifop->fval() &&791ifop->y() == ifop->tval()) {792length_limit = ifop->y();793}794}795796// try to skip null checks and range checks797NewArray* src_array = src->as_NewArray();798if (src_array != NULL) {799flags &= ~LIR_OpArrayCopy::src_null_check;800if (length_limit != NULL &&801src_array->length() == length_limit &&802is_constant_zero(src_pos)) {803flags &= ~LIR_OpArrayCopy::src_range_check;804}805}806807NewArray* dst_array = dst->as_NewArray();808if (dst_array != NULL) {809flags &= ~LIR_OpArrayCopy::dst_null_check;810if (length_limit != NULL &&811dst_array->length() == length_limit &&812is_constant_zero(dst_pos)) {813flags &= ~LIR_OpArrayCopy::dst_range_check;814}815}816817// check from incoming constant values818if (positive_constant(src_pos))819flags &= ~LIR_OpArrayCopy::src_pos_positive_check;820if (positive_constant(dst_pos))821flags &= ~LIR_OpArrayCopy::dst_pos_positive_check;822if (positive_constant(length))823flags &= ~LIR_OpArrayCopy::length_positive_check;824825// see if the range check can be elided, which might also imply826// that src or dst is non-null.827ArrayLength* al = length->as_ArrayLength();828if (al != NULL) {829if (al->array() == src) {830// it's the length of the source array831flags &= ~LIR_OpArrayCopy::length_positive_check;832flags &= ~LIR_OpArrayCopy::src_null_check;833if (is_constant_zero(src_pos))834flags &= ~LIR_OpArrayCopy::src_range_check;835}836if (al->array() == dst) {837// it's the length of the destination array838flags &= ~LIR_OpArrayCopy::length_positive_check;839flags &= ~LIR_OpArrayCopy::dst_null_check;840if (is_constant_zero(dst_pos))841flags &= ~LIR_OpArrayCopy::dst_range_check;842}843}844if (is_exact) {845flags &= ~LIR_OpArrayCopy::type_check;846}847}848849IntConstant* src_int = src_pos->type()->as_IntConstant();850IntConstant* dst_int = dst_pos->type()->as_IntConstant();851if (src_int && dst_int) {852int s_offs = src_int->value();853int d_offs = dst_int->value();854if (src_int->value() >= dst_int->value()) {855flags &= ~LIR_OpArrayCopy::overlapping;856}857if (expected_type != NULL) {858BasicType t = expected_type->element_type()->basic_type();859int element_size = type2aelembytes(t);860if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&861((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) {862flags &= ~LIR_OpArrayCopy::unaligned;863}864}865} else if (src_pos == dst_pos || is_constant_zero(dst_pos)) {866// src and dest positions are the same, or dst is zero so assume867// nonoverlapping copy.868flags &= ~LIR_OpArrayCopy::overlapping;869}870871if (src == dst) {872// moving within a single array so no type checks are needed873if (flags & LIR_OpArrayCopy::type_check) {874flags &= ~LIR_OpArrayCopy::type_check;875}876}877*flagsp = flags;878*expected_typep = (ciArrayKlass*)expected_type;879}880881882LIR_Opr LIRGenerator::round_item(LIR_Opr opr) {883assert(opr->is_register(), "why spill if item is not register?");884885if (strict_fp_requires_explicit_rounding) {886#ifdef IA32887if (UseSSE < 1 && opr->is_single_fpu()) {888LIR_Opr result = new_register(T_FLOAT);889set_vreg_flag(result, must_start_in_memory);890assert(opr->is_register(), "only a register can be spilled");891assert(opr->value_type()->is_float(), "rounding only for floats available");892__ roundfp(opr, LIR_OprFact::illegalOpr, result);893return result;894}895#else896Unimplemented();897#endif // IA32898}899return opr;900}901902903LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) {904assert(type2size[t] == type2size[value->type()],905"size mismatch: t=%s, value->type()=%s", type2name(t), type2name(value->type()));906if (!value->is_register()) {907// force into a register908LIR_Opr r = new_register(value->type());909__ move(value, r);910value = r;911}912913// create a spill location914LIR_Opr tmp = new_register(t);915set_vreg_flag(tmp, LIRGenerator::must_start_in_memory);916917// move from register to spill918__ move(value, tmp);919return tmp;920}921922void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) {923if (if_instr->should_profile()) {924ciMethod* method = if_instr->profiled_method();925assert(method != NULL, "method should be set if branch is profiled");926ciMethodData* md = method->method_data_or_null();927assert(md != NULL, "Sanity");928ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());929assert(data != NULL, "must have profiling data");930assert(data->is_BranchData(), "need BranchData for two-way branches");931int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset());932int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());933if (if_instr->is_swapped()) {934int t = taken_count_offset;935taken_count_offset = not_taken_count_offset;936not_taken_count_offset = t;937}938939LIR_Opr md_reg = new_register(T_METADATA);940__ metadata2reg(md->constant_encoding(), md_reg);941942LIR_Opr data_offset_reg = new_pointer_register();943__ cmove(lir_cond(cond),944LIR_OprFact::intptrConst(taken_count_offset),945LIR_OprFact::intptrConst(not_taken_count_offset),946data_offset_reg, as_BasicType(if_instr->x()->type()));947948// MDO cells are intptr_t, so the data_reg width is arch-dependent.949LIR_Opr data_reg = new_pointer_register();950LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());951__ move(data_addr, data_reg);952// Use leal instead of add to avoid destroying condition codes on x86953LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);954__ leal(LIR_OprFact::address(fake_incr_value), data_reg);955__ move(data_reg, data_addr);956}957}958959// Phi technique:960// This is about passing live values from one basic block to the other.961// In code generated with Java it is rather rare that more than one962// value is on the stack from one basic block to the other.963// We optimize our technique for efficient passing of one value964// (of type long, int, double..) but it can be extended.965// When entering or leaving a basic block, all registers and all spill966// slots are release and empty. We use the released registers967// and spill slots to pass the live values from one block968// to the other. The topmost value, i.e., the value on TOS of expression969// stack is passed in registers. All other values are stored in spilling970// area. Every Phi has an index which designates its spill slot971// At exit of a basic block, we fill the register(s) and spill slots.972// At entry of a basic block, the block_prolog sets up the content of phi nodes973// and locks necessary registers and spilling slots.974975976// move current value to referenced phi function977void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) {978Phi* phi = sux_val->as_Phi();979// cur_val can be null without phi being null in conjunction with inlining980if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) {981Phi* cur_phi = cur_val->as_Phi();982if (cur_phi != NULL && cur_phi->is_illegal()) {983// Phi and local would need to get invalidated984// (which is unexpected for Linear Scan).985// But this case is very rare so we simply bail out.986bailout("propagation of illegal phi");987return;988}989LIR_Opr operand = cur_val->operand();990if (operand->is_illegal()) {991assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL,992"these can be produced lazily");993operand = operand_for_instruction(cur_val);994}995resolver->move(operand, operand_for_instruction(phi));996}997}9989991000// Moves all stack values into their PHI position1001void LIRGenerator::move_to_phi(ValueStack* cur_state) {1002BlockBegin* bb = block();1003if (bb->number_of_sux() == 1) {1004BlockBegin* sux = bb->sux_at(0);1005assert(sux->number_of_preds() > 0, "invalid CFG");10061007// a block with only one predecessor never has phi functions1008if (sux->number_of_preds() > 1) {1009PhiResolver resolver(this);10101011ValueStack* sux_state = sux->state();1012Value sux_value;1013int index;10141015assert(cur_state->scope() == sux_state->scope(), "not matching");1016assert(cur_state->locals_size() == sux_state->locals_size(), "not matching");1017assert(cur_state->stack_size() == sux_state->stack_size(), "not matching");10181019for_each_stack_value(sux_state, index, sux_value) {1020move_to_phi(&resolver, cur_state->stack_at(index), sux_value);1021}10221023for_each_local_value(sux_state, index, sux_value) {1024move_to_phi(&resolver, cur_state->local_at(index), sux_value);1025}10261027assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal");1028}1029}1030}103110321033LIR_Opr LIRGenerator::new_register(BasicType type) {1034int vreg_num = _virtual_register_number;1035// Add a little fudge factor for the bailout since the bailout is only checked periodically. This allows us to hand out1036// a few extra registers before we really run out which helps to avoid to trip over assertions.1037if (vreg_num + 20 >= LIR_OprDesc::vreg_max) {1038bailout("out of virtual registers in LIR generator");1039if (vreg_num + 2 >= LIR_OprDesc::vreg_max) {1040// Wrap it around and continue until bailout really happens to avoid hitting assertions.1041_virtual_register_number = LIR_OprDesc::vreg_base;1042vreg_num = LIR_OprDesc::vreg_base;1043}1044}1045_virtual_register_number += 1;1046LIR_Opr vreg = LIR_OprFact::virtual_register(vreg_num, type);1047assert(vreg != LIR_OprFact::illegal(), "ran out of virtual registers");1048return vreg;1049}105010511052// Try to lock using register in hint1053LIR_Opr LIRGenerator::rlock(Value instr) {1054return new_register(instr->type());1055}105610571058// does an rlock and sets result1059LIR_Opr LIRGenerator::rlock_result(Value x) {1060LIR_Opr reg = rlock(x);1061set_result(x, reg);1062return reg;1063}106410651066// does an rlock and sets result1067LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) {1068LIR_Opr reg;1069switch (type) {1070case T_BYTE:1071case T_BOOLEAN:1072reg = rlock_byte(type);1073break;1074default:1075reg = rlock(x);1076break;1077}10781079set_result(x, reg);1080return reg;1081}108210831084//---------------------------------------------------------------------1085ciObject* LIRGenerator::get_jobject_constant(Value value) {1086ObjectType* oc = value->type()->as_ObjectType();1087if (oc) {1088return oc->constant_value();1089}1090return NULL;1091}109210931094void LIRGenerator::do_ExceptionObject(ExceptionObject* x) {1095assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block");1096assert(block()->next() == x, "ExceptionObject must be first instruction of block");10971098// no moves are created for phi functions at the begin of exception1099// handlers, so assign operands manually here1100for_each_phi_fun(block(), phi,1101if (!phi->is_illegal()) { operand_for_instruction(phi); });11021103LIR_Opr thread_reg = getThreadPointer();1104__ move_wide(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT),1105exceptionOopOpr());1106__ move_wide(LIR_OprFact::oopConst(NULL),1107new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT));1108__ move_wide(LIR_OprFact::oopConst(NULL),1109new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT));11101111LIR_Opr result = new_register(T_OBJECT);1112__ move(exceptionOopOpr(), result);1113set_result(x, result);1114}111511161117//----------------------------------------------------------------------1118//----------------------------------------------------------------------1119//----------------------------------------------------------------------1120//----------------------------------------------------------------------1121// visitor functions1122//----------------------------------------------------------------------1123//----------------------------------------------------------------------1124//----------------------------------------------------------------------1125//----------------------------------------------------------------------11261127void LIRGenerator::do_Phi(Phi* x) {1128// phi functions are never visited directly1129ShouldNotReachHere();1130}113111321133// Code for a constant is generated lazily unless the constant is frequently used and can't be inlined.1134void LIRGenerator::do_Constant(Constant* x) {1135if (x->state_before() != NULL) {1136// Any constant with a ValueStack requires patching so emit the patch here1137LIR_Opr reg = rlock_result(x);1138CodeEmitInfo* info = state_for(x, x->state_before());1139__ oop2reg_patch(NULL, reg, info);1140} else if (x->use_count() > 1 && !can_inline_as_constant(x)) {1141if (!x->is_pinned()) {1142// unpinned constants are handled specially so that they can be1143// put into registers when they are used multiple times within a1144// block. After the block completes their operand will be1145// cleared so that other blocks can't refer to that register.1146set_result(x, load_constant(x));1147} else {1148LIR_Opr res = x->operand();1149if (!res->is_valid()) {1150res = LIR_OprFact::value_type(x->type());1151}1152if (res->is_constant()) {1153LIR_Opr reg = rlock_result(x);1154__ move(res, reg);1155} else {1156set_result(x, res);1157}1158}1159} else {1160set_result(x, LIR_OprFact::value_type(x->type()));1161}1162}116311641165void LIRGenerator::do_Local(Local* x) {1166// operand_for_instruction has the side effect of setting the result1167// so there's no need to do it here.1168operand_for_instruction(x);1169}117011711172void LIRGenerator::do_Return(Return* x) {1173if (compilation()->env()->dtrace_method_probes()) {1174BasicTypeList signature;1175signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread1176signature.append(T_METADATA); // Method*1177LIR_OprList* args = new LIR_OprList();1178args->append(getThreadPointer());1179LIR_Opr meth = new_register(T_METADATA);1180__ metadata2reg(method()->constant_encoding(), meth);1181args->append(meth);1182call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);1183}11841185if (x->type()->is_void()) {1186__ return_op(LIR_OprFact::illegalOpr);1187} else {1188LIR_Opr reg = result_register_for(x->type(), /*callee=*/true);1189LIRItem result(x->result(), this);11901191result.load_item_force(reg);1192__ return_op(result.result());1193}1194set_no_result(x);1195}11961197// Examble: ref.get()1198// Combination of LoadField and g1 pre-write barrier1199void LIRGenerator::do_Reference_get(Intrinsic* x) {12001201const int referent_offset = java_lang_ref_Reference::referent_offset();12021203assert(x->number_of_arguments() == 1, "wrong type");12041205LIRItem reference(x->argument_at(0), this);1206reference.load_item();12071208// need to perform the null check on the reference objecy1209CodeEmitInfo* info = NULL;1210if (x->needs_null_check()) {1211info = state_for(x);1212}12131214LIR_Opr result = rlock_result(x, T_OBJECT);1215access_load_at(IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT,1216reference, LIR_OprFact::intConst(referent_offset), result);1217}12181219// Example: clazz.isInstance(object)1220void LIRGenerator::do_isInstance(Intrinsic* x) {1221assert(x->number_of_arguments() == 2, "wrong type");12221223// TODO could try to substitute this node with an equivalent InstanceOf1224// if clazz is known to be a constant Class. This will pick up newly found1225// constants after HIR construction. I'll leave this to a future change.12261227// as a first cut, make a simple leaf call to runtime to stay platform independent.1228// could follow the aastore example in a future change.12291230LIRItem clazz(x->argument_at(0), this);1231LIRItem object(x->argument_at(1), this);1232clazz.load_item();1233object.load_item();1234LIR_Opr result = rlock_result(x);12351236// need to perform null check on clazz1237if (x->needs_null_check()) {1238CodeEmitInfo* info = state_for(x);1239__ null_check(clazz.result(), info);1240}12411242LIR_Opr call_result = call_runtime(clazz.value(), object.value(),1243CAST_FROM_FN_PTR(address, Runtime1::is_instance_of),1244x->type(),1245NULL); // NULL CodeEmitInfo results in a leaf call1246__ move(call_result, result);1247}12481249// Example: object.getClass ()1250void LIRGenerator::do_getClass(Intrinsic* x) {1251assert(x->number_of_arguments() == 1, "wrong type");12521253LIRItem rcvr(x->argument_at(0), this);1254rcvr.load_item();1255LIR_Opr temp = new_register(T_METADATA);1256LIR_Opr result = rlock_result(x);12571258// need to perform the null check on the rcvr1259CodeEmitInfo* info = NULL;1260if (x->needs_null_check()) {1261info = state_for(x);1262}12631264// FIXME T_ADDRESS should actually be T_METADATA but it can't because the1265// meaning of these two is mixed up (see JDK-8026837).1266__ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), temp, info);1267__ move_wide(new LIR_Address(temp, in_bytes(Klass::java_mirror_offset()), T_ADDRESS), temp);1268// mirror = ((OopHandle)mirror)->resolve();1269access_load(IN_NATIVE, T_OBJECT,1270LIR_OprFact::address(new LIR_Address(temp, T_OBJECT)), result);1271}12721273// java.lang.Class::isPrimitive()1274void LIRGenerator::do_isPrimitive(Intrinsic* x) {1275assert(x->number_of_arguments() == 1, "wrong type");12761277LIRItem rcvr(x->argument_at(0), this);1278rcvr.load_item();1279LIR_Opr temp = new_register(T_METADATA);1280LIR_Opr result = rlock_result(x);12811282CodeEmitInfo* info = NULL;1283if (x->needs_null_check()) {1284info = state_for(x);1285}12861287__ move(new LIR_Address(rcvr.result(), java_lang_Class::klass_offset(), T_ADDRESS), temp, info);1288__ cmp(lir_cond_notEqual, temp, LIR_OprFact::metadataConst(0));1289__ cmove(lir_cond_notEqual, LIR_OprFact::intConst(0), LIR_OprFact::intConst(1), result, T_BOOLEAN);1290}12911292// Example: Foo.class.getModifiers()1293void LIRGenerator::do_getModifiers(Intrinsic* x) {1294assert(x->number_of_arguments() == 1, "wrong type");12951296LIRItem receiver(x->argument_at(0), this);1297receiver.load_item();1298LIR_Opr result = rlock_result(x);12991300CodeEmitInfo* info = NULL;1301if (x->needs_null_check()) {1302info = state_for(x);1303}13041305LabelObj* L_not_prim = new LabelObj();1306LabelObj* L_done = new LabelObj();13071308LIR_Opr klass = new_register(T_METADATA);1309// Checking if it's a java mirror of primitive type1310__ move(new LIR_Address(receiver.result(), java_lang_Class::klass_offset(), T_ADDRESS), klass, info);1311__ cmp(lir_cond_notEqual, klass, LIR_OprFact::metadataConst(0));1312__ branch(lir_cond_notEqual, L_not_prim->label());1313__ move(LIR_OprFact::intConst(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC), result);1314__ branch(lir_cond_always, L_done->label());13151316__ branch_destination(L_not_prim->label());1317__ move(new LIR_Address(klass, in_bytes(Klass::modifier_flags_offset()), T_INT), result);1318__ branch_destination(L_done->label());1319}13201321// Example: Thread.currentThread()1322void LIRGenerator::do_currentThread(Intrinsic* x) {1323assert(x->number_of_arguments() == 0, "wrong type");1324LIR_Opr temp = new_register(T_ADDRESS);1325LIR_Opr reg = rlock_result(x);1326__ move(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_ADDRESS), temp);1327// threadObj = ((OopHandle)_threadObj)->resolve();1328access_load(IN_NATIVE, T_OBJECT,1329LIR_OprFact::address(new LIR_Address(temp, T_OBJECT)), reg);1330}13311332void LIRGenerator::do_getObjectSize(Intrinsic* x) {1333assert(x->number_of_arguments() == 3, "wrong type");1334LIR_Opr result_reg = rlock_result(x);13351336LIRItem value(x->argument_at(2), this);1337value.load_item();13381339LIR_Opr klass = new_register(T_METADATA);1340__ move(new LIR_Address(value.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, NULL);1341LIR_Opr layout = new_register(T_INT);1342__ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);13431344LabelObj* L_done = new LabelObj();1345LabelObj* L_array = new LabelObj();13461347__ cmp(lir_cond_lessEqual, layout, 0);1348__ branch(lir_cond_lessEqual, L_array->label());13491350// Instance case: the layout helper gives us instance size almost directly,1351// but we need to mask out the _lh_instance_slow_path_bit.1352__ convert(Bytecodes::_i2l, layout, result_reg);13531354assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");1355jlong mask = ~(jlong) right_n_bits(LogBytesPerLong);1356__ logical_and(result_reg, LIR_OprFact::longConst(mask), result_reg);13571358__ branch(lir_cond_always, L_done->label());13591360// Array case: size is round(header + element_size*arraylength).1361// Since arraylength is different for every array instance, we have to1362// compute the whole thing at runtime.13631364__ branch_destination(L_array->label());13651366int round_mask = MinObjAlignmentInBytes - 1;13671368// Figure out header sizes first.1369LIR_Opr hss = LIR_OprFact::intConst(Klass::_lh_header_size_shift);1370LIR_Opr hsm = LIR_OprFact::intConst(Klass::_lh_header_size_mask);13711372LIR_Opr header_size = new_register(T_INT);1373__ move(layout, header_size);1374LIR_Opr tmp = new_register(T_INT);1375__ unsigned_shift_right(header_size, hss, header_size, tmp);1376__ logical_and(header_size, hsm, header_size);1377__ add(header_size, LIR_OprFact::intConst(round_mask), header_size);13781379// Figure out the array length in bytes1380assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place");1381LIR_Opr l2esm = LIR_OprFact::intConst(Klass::_lh_log2_element_size_mask);1382__ logical_and(layout, l2esm, layout);13831384LIR_Opr length_int = new_register(T_INT);1385__ move(new LIR_Address(value.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), length_int);13861387#ifdef _LP641388LIR_Opr length = new_register(T_LONG);1389__ convert(Bytecodes::_i2l, length_int, length);1390#endif13911392// Shift-left awkwardness. Normally it is just:1393// __ shift_left(length, layout, length);1394// But C1 cannot perform shift_left with non-constant count, so we end up1395// doing the per-bit loop dance here. x86_32 also does not know how to shift1396// longs, so we have to act on ints.1397LabelObj* L_shift_loop = new LabelObj();1398LabelObj* L_shift_exit = new LabelObj();13991400__ branch_destination(L_shift_loop->label());1401__ cmp(lir_cond_equal, layout, 0);1402__ branch(lir_cond_equal, L_shift_exit->label());14031404#ifdef _LP641405__ shift_left(length, 1, length);1406#else1407__ shift_left(length_int, 1, length_int);1408#endif14091410__ sub(layout, LIR_OprFact::intConst(1), layout);14111412__ branch(lir_cond_always, L_shift_loop->label());1413__ branch_destination(L_shift_exit->label());14141415// Mix all up, round, and push to the result.1416#ifdef _LP641417LIR_Opr header_size_long = new_register(T_LONG);1418__ convert(Bytecodes::_i2l, header_size, header_size_long);1419__ add(length, header_size_long, length);1420if (round_mask != 0) {1421__ logical_and(length, LIR_OprFact::longConst(~round_mask), length);1422}1423__ move(length, result_reg);1424#else1425__ add(length_int, header_size, length_int);1426if (round_mask != 0) {1427__ logical_and(length_int, LIR_OprFact::intConst(~round_mask), length_int);1428}1429__ convert(Bytecodes::_i2l, length_int, result_reg);1430#endif14311432__ branch_destination(L_done->label());1433}14341435void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) {1436assert(x->number_of_arguments() == 1, "wrong type");1437LIRItem receiver(x->argument_at(0), this);14381439receiver.load_item();1440BasicTypeList signature;1441signature.append(T_OBJECT); // receiver1442LIR_OprList* args = new LIR_OprList();1443args->append(receiver.result());1444CodeEmitInfo* info = state_for(x, x->state());1445call_runtime(&signature, args,1446CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)),1447voidType, info);14481449set_no_result(x);1450}145114521453//------------------------local access--------------------------------------14541455LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) {1456if (x->operand()->is_illegal()) {1457Constant* c = x->as_Constant();1458if (c != NULL) {1459x->set_operand(LIR_OprFact::value_type(c->type()));1460} else {1461assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local");1462// allocate a virtual register for this local or phi1463x->set_operand(rlock(x));1464_instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL);1465}1466}1467return x->operand();1468}146914701471Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) {1472if (opr->is_virtual()) {1473return instruction_for_vreg(opr->vreg_number());1474}1475return NULL;1476}147714781479Instruction* LIRGenerator::instruction_for_vreg(int reg_num) {1480if (reg_num < _instruction_for_operand.length()) {1481return _instruction_for_operand.at(reg_num);1482}1483return NULL;1484}148514861487void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) {1488if (_vreg_flags.size_in_bits() == 0) {1489BitMap2D temp(100, num_vreg_flags);1490_vreg_flags = temp;1491}1492_vreg_flags.at_put_grow(vreg_num, f, true);1493}14941495bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) {1496if (!_vreg_flags.is_valid_index(vreg_num, f)) {1497return false;1498}1499return _vreg_flags.at(vreg_num, f);1500}150115021503// Block local constant handling. This code is useful for keeping1504// unpinned constants and constants which aren't exposed in the IR in1505// registers. Unpinned Constant instructions have their operands1506// cleared when the block is finished so that other blocks can't end1507// up referring to their registers.15081509LIR_Opr LIRGenerator::load_constant(Constant* x) {1510assert(!x->is_pinned(), "only for unpinned constants");1511_unpinned_constants.append(x);1512return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr());1513}151415151516LIR_Opr LIRGenerator::load_constant(LIR_Const* c) {1517BasicType t = c->type();1518for (int i = 0; i < _constants.length(); i++) {1519LIR_Const* other = _constants.at(i);1520if (t == other->type()) {1521switch (t) {1522case T_INT:1523case T_FLOAT:1524if (c->as_jint_bits() != other->as_jint_bits()) continue;1525break;1526case T_LONG:1527case T_DOUBLE:1528if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;1529if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;1530break;1531case T_OBJECT:1532if (c->as_jobject() != other->as_jobject()) continue;1533break;1534default:1535break;1536}1537return _reg_for_constants.at(i);1538}1539}15401541LIR_Opr result = new_register(t);1542__ move((LIR_Opr)c, result);1543_constants.append(c);1544_reg_for_constants.append(result);1545return result;1546}15471548//------------------------field access--------------------------------------15491550void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {1551assert(x->number_of_arguments() == 4, "wrong type");1552LIRItem obj (x->argument_at(0), this); // object1553LIRItem offset(x->argument_at(1), this); // offset of field1554LIRItem cmp (x->argument_at(2), this); // value to compare with field1555LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp1556assert(obj.type()->tag() == objectTag, "invalid type");1557assert(cmp.type()->tag() == type->tag(), "invalid type");1558assert(val.type()->tag() == type->tag(), "invalid type");15591560LIR_Opr result = access_atomic_cmpxchg_at(IN_HEAP, as_BasicType(type),1561obj, offset, cmp, val);1562set_result(x, result);1563}15641565// Comment copied form templateTable_i486.cpp1566// ----------------------------------------------------------------------------1567// Volatile variables demand their effects be made known to all CPU's in1568// order. Store buffers on most chips allow reads & writes to reorder; the1569// JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of1570// memory barrier (i.e., it's not sufficient that the interpreter does not1571// reorder volatile references, the hardware also must not reorder them).1572//1573// According to the new Java Memory Model (JMM):1574// (1) All volatiles are serialized wrt to each other.1575// ALSO reads & writes act as aquire & release, so:1576// (2) A read cannot let unrelated NON-volatile memory refs that happen after1577// the read float up to before the read. It's OK for non-volatile memory refs1578// that happen before the volatile read to float down below it.1579// (3) Similar a volatile write cannot let unrelated NON-volatile memory refs1580// that happen BEFORE the write float down to after the write. It's OK for1581// non-volatile memory refs that happen after the volatile write to float up1582// before it.1583//1584// We only put in barriers around volatile refs (they are expensive), not1585// _between_ memory refs (that would require us to track the flavor of the1586// previous memory refs). Requirements (2) and (3) require some barriers1587// before volatile stores and after volatile loads. These nearly cover1588// requirement (1) but miss the volatile-store-volatile-load case. This final1589// case is placed after volatile-stores although it could just as well go1590// before volatile-loads.159115921593void LIRGenerator::do_StoreField(StoreField* x) {1594bool needs_patching = x->needs_patching();1595bool is_volatile = x->field()->is_volatile();1596BasicType field_type = x->field_type();15971598CodeEmitInfo* info = NULL;1599if (needs_patching) {1600assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");1601info = state_for(x, x->state_before());1602} else if (x->needs_null_check()) {1603NullCheck* nc = x->explicit_null_check();1604if (nc == NULL) {1605info = state_for(x);1606} else {1607info = state_for(nc);1608}1609}16101611LIRItem object(x->obj(), this);1612LIRItem value(x->value(), this);16131614object.load_item();16151616if (is_volatile || needs_patching) {1617// load item if field is volatile (fewer special cases for volatiles)1618// load item if field not initialized1619// load item if field not constant1620// because of code patching we cannot inline constants1621if (field_type == T_BYTE || field_type == T_BOOLEAN) {1622value.load_byte_item();1623} else {1624value.load_item();1625}1626} else {1627value.load_for_store(field_type);1628}16291630set_no_result(x);16311632#ifndef PRODUCT1633if (PrintNotLoaded && needs_patching) {1634tty->print_cr(" ###class not loaded at store_%s bci %d",1635x->is_static() ? "static" : "field", x->printable_bci());1636}1637#endif16381639if (x->needs_null_check() &&1640(needs_patching ||1641MacroAssembler::needs_explicit_null_check(x->offset()))) {1642// Emit an explicit null check because the offset is too large.1643// If the class is not loaded and the object is NULL, we need to deoptimize to throw a1644// NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.1645__ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);1646}16471648DecoratorSet decorators = IN_HEAP;1649if (is_volatile) {1650decorators |= MO_SEQ_CST;1651}1652if (needs_patching) {1653decorators |= C1_NEEDS_PATCHING;1654}16551656access_store_at(decorators, field_type, object, LIR_OprFact::intConst(x->offset()),1657value.result(), info != NULL ? new CodeEmitInfo(info) : NULL, info);1658}16591660void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {1661assert(x->is_pinned(),"");1662bool needs_range_check = x->compute_needs_range_check();1663bool use_length = x->length() != NULL;1664bool obj_store = is_reference_type(x->elt_type());1665bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||1666!get_jobject_constant(x->value())->is_null_object() ||1667x->should_profile());16681669LIRItem array(x->array(), this);1670LIRItem index(x->index(), this);1671LIRItem value(x->value(), this);1672LIRItem length(this);16731674array.load_item();1675index.load_nonconstant();16761677if (use_length && needs_range_check) {1678length.set_instruction(x->length());1679length.load_item();16801681}1682if (needs_store_check || x->check_boolean()) {1683value.load_item();1684} else {1685value.load_for_store(x->elt_type());1686}16871688set_no_result(x);16891690// the CodeEmitInfo must be duplicated for each different1691// LIR-instruction because spilling can occur anywhere between two1692// instructions and so the debug information must be different1693CodeEmitInfo* range_check_info = state_for(x);1694CodeEmitInfo* null_check_info = NULL;1695if (x->needs_null_check()) {1696null_check_info = new CodeEmitInfo(range_check_info);1697}16981699if (GenerateRangeChecks && needs_range_check) {1700if (use_length) {1701__ cmp(lir_cond_belowEqual, length.result(), index.result());1702__ branch(lir_cond_belowEqual, new RangeCheckStub(range_check_info, index.result(), array.result()));1703} else {1704array_range_check(array.result(), index.result(), null_check_info, range_check_info);1705// range_check also does the null check1706null_check_info = NULL;1707}1708}17091710if (GenerateArrayStoreCheck && needs_store_check) {1711CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);1712array_store_check(value.result(), array.result(), store_check_info, x->profiled_method(), x->profiled_bci());1713}17141715DecoratorSet decorators = IN_HEAP | IS_ARRAY;1716if (x->check_boolean()) {1717decorators |= C1_MASK_BOOLEAN;1718}17191720access_store_at(decorators, x->elt_type(), array, index.result(), value.result(),1721NULL, null_check_info);1722}17231724void LIRGenerator::access_load_at(DecoratorSet decorators, BasicType type,1725LIRItem& base, LIR_Opr offset, LIR_Opr result,1726CodeEmitInfo* patch_info, CodeEmitInfo* load_emit_info) {1727decorators |= ACCESS_READ;1728LIRAccess access(this, decorators, base, offset, type, patch_info, load_emit_info);1729if (access.is_raw()) {1730_barrier_set->BarrierSetC1::load_at(access, result);1731} else {1732_barrier_set->load_at(access, result);1733}1734}17351736void LIRGenerator::access_load(DecoratorSet decorators, BasicType type,1737LIR_Opr addr, LIR_Opr result) {1738decorators |= ACCESS_READ;1739LIRAccess access(this, decorators, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, type);1740access.set_resolved_addr(addr);1741if (access.is_raw()) {1742_barrier_set->BarrierSetC1::load(access, result);1743} else {1744_barrier_set->load(access, result);1745}1746}17471748void LIRGenerator::access_store_at(DecoratorSet decorators, BasicType type,1749LIRItem& base, LIR_Opr offset, LIR_Opr value,1750CodeEmitInfo* patch_info, CodeEmitInfo* store_emit_info) {1751decorators |= ACCESS_WRITE;1752LIRAccess access(this, decorators, base, offset, type, patch_info, store_emit_info);1753if (access.is_raw()) {1754_barrier_set->BarrierSetC1::store_at(access, value);1755} else {1756_barrier_set->store_at(access, value);1757}1758}17591760LIR_Opr LIRGenerator::access_atomic_cmpxchg_at(DecoratorSet decorators, BasicType type,1761LIRItem& base, LIRItem& offset, LIRItem& cmp_value, LIRItem& new_value) {1762decorators |= ACCESS_READ;1763decorators |= ACCESS_WRITE;1764// Atomic operations are SEQ_CST by default1765decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0;1766LIRAccess access(this, decorators, base, offset, type);1767if (access.is_raw()) {1768return _barrier_set->BarrierSetC1::atomic_cmpxchg_at(access, cmp_value, new_value);1769} else {1770return _barrier_set->atomic_cmpxchg_at(access, cmp_value, new_value);1771}1772}17731774LIR_Opr LIRGenerator::access_atomic_xchg_at(DecoratorSet decorators, BasicType type,1775LIRItem& base, LIRItem& offset, LIRItem& value) {1776decorators |= ACCESS_READ;1777decorators |= ACCESS_WRITE;1778// Atomic operations are SEQ_CST by default1779decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0;1780LIRAccess access(this, decorators, base, offset, type);1781if (access.is_raw()) {1782return _barrier_set->BarrierSetC1::atomic_xchg_at(access, value);1783} else {1784return _barrier_set->atomic_xchg_at(access, value);1785}1786}17871788LIR_Opr LIRGenerator::access_atomic_add_at(DecoratorSet decorators, BasicType type,1789LIRItem& base, LIRItem& offset, LIRItem& value) {1790decorators |= ACCESS_READ;1791decorators |= ACCESS_WRITE;1792// Atomic operations are SEQ_CST by default1793decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0;1794LIRAccess access(this, decorators, base, offset, type);1795if (access.is_raw()) {1796return _barrier_set->BarrierSetC1::atomic_add_at(access, value);1797} else {1798return _barrier_set->atomic_add_at(access, value);1799}1800}18011802void LIRGenerator::do_LoadField(LoadField* x) {1803bool needs_patching = x->needs_patching();1804bool is_volatile = x->field()->is_volatile();1805BasicType field_type = x->field_type();18061807CodeEmitInfo* info = NULL;1808if (needs_patching) {1809assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");1810info = state_for(x, x->state_before());1811} else if (x->needs_null_check()) {1812NullCheck* nc = x->explicit_null_check();1813if (nc == NULL) {1814info = state_for(x);1815} else {1816info = state_for(nc);1817}1818}18191820LIRItem object(x->obj(), this);18211822object.load_item();18231824#ifndef PRODUCT1825if (PrintNotLoaded && needs_patching) {1826tty->print_cr(" ###class not loaded at load_%s bci %d",1827x->is_static() ? "static" : "field", x->printable_bci());1828}1829#endif18301831bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();1832if (x->needs_null_check() &&1833(needs_patching ||1834MacroAssembler::needs_explicit_null_check(x->offset()) ||1835stress_deopt)) {1836LIR_Opr obj = object.result();1837if (stress_deopt) {1838obj = new_register(T_OBJECT);1839__ move(LIR_OprFact::oopConst(NULL), obj);1840}1841// Emit an explicit null check because the offset is too large.1842// If the class is not loaded and the object is NULL, we need to deoptimize to throw a1843// NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.1844__ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);1845}18461847DecoratorSet decorators = IN_HEAP;1848if (is_volatile) {1849decorators |= MO_SEQ_CST;1850}1851if (needs_patching) {1852decorators |= C1_NEEDS_PATCHING;1853}18541855LIR_Opr result = rlock_result(x, field_type);1856access_load_at(decorators, field_type,1857object, LIR_OprFact::intConst(x->offset()), result,1858info ? new CodeEmitInfo(info) : NULL, info);1859}186018611862//------------------------java.nio.Buffer.checkIndex------------------------18631864// int java.nio.Buffer.checkIndex(int)1865void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {1866// NOTE: by the time we are in checkIndex() we are guaranteed that1867// the buffer is non-null (because checkIndex is package-private and1868// only called from within other methods in the buffer).1869assert(x->number_of_arguments() == 2, "wrong type");1870LIRItem buf (x->argument_at(0), this);1871LIRItem index(x->argument_at(1), this);1872buf.load_item();1873index.load_item();18741875LIR_Opr result = rlock_result(x);1876if (GenerateRangeChecks) {1877CodeEmitInfo* info = state_for(x);1878CodeStub* stub = new RangeCheckStub(info, index.result());1879if (index.result()->is_constant()) {1880cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info);1881__ branch(lir_cond_belowEqual, stub);1882} else {1883cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(),1884java_nio_Buffer::limit_offset(), T_INT, info);1885__ branch(lir_cond_aboveEqual, stub);1886}1887__ move(index.result(), result);1888} else {1889// Just load the index into the result register1890__ move(index.result(), result);1891}1892}189318941895//------------------------array access--------------------------------------189618971898void LIRGenerator::do_ArrayLength(ArrayLength* x) {1899LIRItem array(x->array(), this);1900array.load_item();1901LIR_Opr reg = rlock_result(x);19021903CodeEmitInfo* info = NULL;1904if (x->needs_null_check()) {1905NullCheck* nc = x->explicit_null_check();1906if (nc == NULL) {1907info = state_for(x);1908} else {1909info = state_for(nc);1910}1911if (StressLoopInvariantCodeMotion && info->deoptimize_on_exception()) {1912LIR_Opr obj = new_register(T_OBJECT);1913__ move(LIR_OprFact::oopConst(NULL), obj);1914__ null_check(obj, new CodeEmitInfo(info));1915}1916}1917__ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);1918}191919201921void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {1922bool use_length = x->length() != NULL;1923LIRItem array(x->array(), this);1924LIRItem index(x->index(), this);1925LIRItem length(this);1926bool needs_range_check = x->compute_needs_range_check();19271928if (use_length && needs_range_check) {1929length.set_instruction(x->length());1930length.load_item();1931}19321933array.load_item();1934if (index.is_constant() && can_inline_as_constant(x->index())) {1935// let it be a constant1936index.dont_load_item();1937} else {1938index.load_item();1939}19401941CodeEmitInfo* range_check_info = state_for(x);1942CodeEmitInfo* null_check_info = NULL;1943if (x->needs_null_check()) {1944NullCheck* nc = x->explicit_null_check();1945if (nc != NULL) {1946null_check_info = state_for(nc);1947} else {1948null_check_info = range_check_info;1949}1950if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {1951LIR_Opr obj = new_register(T_OBJECT);1952__ move(LIR_OprFact::oopConst(NULL), obj);1953__ null_check(obj, new CodeEmitInfo(null_check_info));1954}1955}19561957if (GenerateRangeChecks && needs_range_check) {1958if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {1959__ branch(lir_cond_always, new RangeCheckStub(range_check_info, index.result(), array.result()));1960} else if (use_length) {1961// TODO: use a (modified) version of array_range_check that does not require a1962// constant length to be loaded to a register1963__ cmp(lir_cond_belowEqual, length.result(), index.result());1964__ branch(lir_cond_belowEqual, new RangeCheckStub(range_check_info, index.result(), array.result()));1965} else {1966array_range_check(array.result(), index.result(), null_check_info, range_check_info);1967// The range check performs the null check, so clear it out for the load1968null_check_info = NULL;1969}1970}19711972DecoratorSet decorators = IN_HEAP | IS_ARRAY;19731974LIR_Opr result = rlock_result(x, x->elt_type());1975access_load_at(decorators, x->elt_type(),1976array, index.result(), result,1977NULL, null_check_info);1978}197919801981void LIRGenerator::do_NullCheck(NullCheck* x) {1982if (x->can_trap()) {1983LIRItem value(x->obj(), this);1984value.load_item();1985CodeEmitInfo* info = state_for(x);1986__ null_check(value.result(), info);1987}1988}198919901991void LIRGenerator::do_TypeCast(TypeCast* x) {1992LIRItem value(x->obj(), this);1993value.load_item();1994// the result is the same as from the node we are casting1995set_result(x, value.result());1996}199719981999void LIRGenerator::do_Throw(Throw* x) {2000LIRItem exception(x->exception(), this);2001exception.load_item();2002set_no_result(x);2003LIR_Opr exception_opr = exception.result();2004CodeEmitInfo* info = state_for(x, x->state());20052006#ifndef PRODUCT2007if (PrintC1Statistics) {2008increment_counter(Runtime1::throw_count_address(), T_INT);2009}2010#endif20112012// check if the instruction has an xhandler in any of the nested scopes2013bool unwind = false;2014if (info->exception_handlers()->length() == 0) {2015// this throw is not inside an xhandler2016unwind = true;2017} else {2018// get some idea of the throw type2019bool type_is_exact = true;2020ciType* throw_type = x->exception()->exact_type();2021if (throw_type == NULL) {2022type_is_exact = false;2023throw_type = x->exception()->declared_type();2024}2025if (throw_type != NULL && throw_type->is_instance_klass()) {2026ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type;2027unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact);2028}2029}20302031// do null check before moving exception oop into fixed register2032// to avoid a fixed interval with an oop during the null check.2033// Use a copy of the CodeEmitInfo because debug information is2034// different for null_check and throw.2035if (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL) {2036// if the exception object wasn't created using new then it might be null.2037__ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci())));2038}20392040if (compilation()->env()->jvmti_can_post_on_exceptions()) {2041// we need to go through the exception lookup path to get JVMTI2042// notification done2043unwind = false;2044}20452046// move exception oop into fixed register2047__ move(exception_opr, exceptionOopOpr());20482049if (unwind) {2050__ unwind_exception(exceptionOopOpr());2051} else {2052__ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info);2053}2054}205520562057void LIRGenerator::do_RoundFP(RoundFP* x) {2058assert(strict_fp_requires_explicit_rounding, "not required");20592060LIRItem input(x->input(), this);2061input.load_item();2062LIR_Opr input_opr = input.result();2063assert(input_opr->is_register(), "why round if value is not in a register?");2064assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value");2065if (input_opr->is_single_fpu()) {2066set_result(x, round_item(input_opr)); // This code path not currently taken2067} else {2068LIR_Opr result = new_register(T_DOUBLE);2069set_vreg_flag(result, must_start_in_memory);2070__ roundfp(input_opr, LIR_OprFact::illegalOpr, result);2071set_result(x, result);2072}2073}20742075// Here UnsafeGetRaw may have x->base() and x->index() be int or long2076// on both 64 and 32 bits. Expecting x->base() to be always long on 64bit.2077void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) {2078LIRItem base(x->base(), this);2079LIRItem idx(this);20802081base.load_item();2082if (x->has_index()) {2083idx.set_instruction(x->index());2084idx.load_nonconstant();2085}20862087LIR_Opr reg = rlock_result(x, x->basic_type());20882089int log2_scale = 0;2090if (x->has_index()) {2091log2_scale = x->log2_scale();2092}20932094assert(!x->has_index() || idx.value() == x->index(), "should match");20952096LIR_Opr base_op = base.result();2097LIR_Opr index_op = idx.result();2098#ifndef _LP642099if (base_op->type() == T_LONG) {2100base_op = new_register(T_INT);2101__ convert(Bytecodes::_l2i, base.result(), base_op);2102}2103if (x->has_index()) {2104if (index_op->type() == T_LONG) {2105LIR_Opr long_index_op = index_op;2106if (index_op->is_constant()) {2107long_index_op = new_register(T_LONG);2108__ move(index_op, long_index_op);2109}2110index_op = new_register(T_INT);2111__ convert(Bytecodes::_l2i, long_index_op, index_op);2112} else {2113assert(x->index()->type()->tag() == intTag, "must be");2114}2115}2116// At this point base and index should be all ints.2117assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");2118assert(!x->has_index() || index_op->type() == T_INT, "index should be an int");2119#else2120if (x->has_index()) {2121if (index_op->type() == T_INT) {2122if (!index_op->is_constant()) {2123index_op = new_register(T_LONG);2124__ convert(Bytecodes::_i2l, idx.result(), index_op);2125}2126} else {2127assert(index_op->type() == T_LONG, "must be");2128if (index_op->is_constant()) {2129index_op = new_register(T_LONG);2130__ move(idx.result(), index_op);2131}2132}2133}2134// At this point base is a long non-constant2135// Index is a long register or a int constant.2136// We allow the constant to stay an int because that would allow us a more compact encoding by2137// embedding an immediate offset in the address expression. If we have a long constant, we have to2138// move it into a register first.2139assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a long non-constant");2140assert(!x->has_index() || (index_op->type() == T_INT && index_op->is_constant()) ||2141(index_op->type() == T_LONG && !index_op->is_constant()), "unexpected index type");2142#endif21432144BasicType dst_type = x->basic_type();21452146LIR_Address* addr;2147if (index_op->is_constant()) {2148assert(log2_scale == 0, "must not have a scale");2149assert(index_op->type() == T_INT, "only int constants supported");2150addr = new LIR_Address(base_op, index_op->as_jint(), dst_type);2151} else {2152#ifdef X862153addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type);2154#elif defined(GENERATE_ADDRESS_IS_PREFERRED)2155addr = generate_address(base_op, index_op, log2_scale, 0, dst_type);2156#else2157if (index_op->is_illegal() || log2_scale == 0) {2158addr = new LIR_Address(base_op, index_op, dst_type);2159} else {2160LIR_Opr tmp = new_pointer_register();2161__ shift_left(index_op, log2_scale, tmp);2162addr = new LIR_Address(base_op, tmp, dst_type);2163}2164#endif2165}21662167if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) {2168__ unaligned_move(addr, reg);2169} else {2170if (dst_type == T_OBJECT && x->is_wide()) {2171__ move_wide(addr, reg);2172} else {2173__ move(addr, reg);2174}2175}2176}217721782179void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) {2180int log2_scale = 0;2181BasicType type = x->basic_type();21822183if (x->has_index()) {2184log2_scale = x->log2_scale();2185}21862187LIRItem base(x->base(), this);2188LIRItem value(x->value(), this);2189LIRItem idx(this);21902191base.load_item();2192if (x->has_index()) {2193idx.set_instruction(x->index());2194idx.load_item();2195}21962197if (type == T_BYTE || type == T_BOOLEAN) {2198value.load_byte_item();2199} else {2200value.load_item();2201}22022203set_no_result(x);22042205LIR_Opr base_op = base.result();2206LIR_Opr index_op = idx.result();22072208#ifdef GENERATE_ADDRESS_IS_PREFERRED2209LIR_Address* addr = generate_address(base_op, index_op, log2_scale, 0, x->basic_type());2210#else2211#ifndef _LP642212if (base_op->type() == T_LONG) {2213base_op = new_register(T_INT);2214__ convert(Bytecodes::_l2i, base.result(), base_op);2215}2216if (x->has_index()) {2217if (index_op->type() == T_LONG) {2218index_op = new_register(T_INT);2219__ convert(Bytecodes::_l2i, idx.result(), index_op);2220}2221}2222// At this point base and index should be all ints and not constants2223assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");2224assert(!x->has_index() || (index_op->type() == T_INT && !index_op->is_constant()), "index should be an non-constant int");2225#else2226if (x->has_index()) {2227if (index_op->type() == T_INT) {2228index_op = new_register(T_LONG);2229__ convert(Bytecodes::_i2l, idx.result(), index_op);2230}2231}2232// At this point base and index are long and non-constant2233assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a non-constant long");2234assert(!x->has_index() || (index_op->type() == T_LONG && !index_op->is_constant()), "index must be a non-constant long");2235#endif22362237if (log2_scale != 0) {2238// temporary fix (platform dependent code without shift on Intel would be better)2239// TODO: ARM also allows embedded shift in the address2240LIR_Opr tmp = new_pointer_register();2241if (TwoOperandLIRForm) {2242__ move(index_op, tmp);2243index_op = tmp;2244}2245__ shift_left(index_op, log2_scale, tmp);2246if (!TwoOperandLIRForm) {2247index_op = tmp;2248}2249}22502251LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());2252#endif // !GENERATE_ADDRESS_IS_PREFERRED2253__ move(value.result(), addr);2254}225522562257void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {2258BasicType type = x->basic_type();2259LIRItem src(x->object(), this);2260LIRItem off(x->offset(), this);22612262off.load_item();2263src.load_item();22642265DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS;22662267if (x->is_volatile()) {2268decorators |= MO_SEQ_CST;2269}2270if (type == T_BOOLEAN) {2271decorators |= C1_MASK_BOOLEAN;2272}2273if (is_reference_type(type)) {2274decorators |= ON_UNKNOWN_OOP_REF;2275}22762277LIR_Opr result = rlock_result(x, type);2278access_load_at(decorators, type,2279src, off.result(), result);2280}228122822283void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {2284BasicType type = x->basic_type();2285LIRItem src(x->object(), this);2286LIRItem off(x->offset(), this);2287LIRItem data(x->value(), this);22882289src.load_item();2290if (type == T_BOOLEAN || type == T_BYTE) {2291data.load_byte_item();2292} else {2293data.load_item();2294}2295off.load_item();22962297set_no_result(x);22982299DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS;2300if (is_reference_type(type)) {2301decorators |= ON_UNKNOWN_OOP_REF;2302}2303if (x->is_volatile()) {2304decorators |= MO_SEQ_CST;2305}2306access_store_at(decorators, type, src, off.result(), data.result());2307}23082309void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {2310BasicType type = x->basic_type();2311LIRItem src(x->object(), this);2312LIRItem off(x->offset(), this);2313LIRItem value(x->value(), this);23142315DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS | MO_SEQ_CST;23162317if (is_reference_type(type)) {2318decorators |= ON_UNKNOWN_OOP_REF;2319}23202321LIR_Opr result;2322if (x->is_add()) {2323result = access_atomic_add_at(decorators, type, src, off, value);2324} else {2325result = access_atomic_xchg_at(decorators, type, src, off, value);2326}2327set_result(x, result);2328}23292330void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {2331int lng = x->length();23322333for (int i = 0; i < lng; i++) {2334C1SwitchRange* one_range = x->at(i);2335int low_key = one_range->low_key();2336int high_key = one_range->high_key();2337BlockBegin* dest = one_range->sux();2338if (low_key == high_key) {2339__ cmp(lir_cond_equal, value, low_key);2340__ branch(lir_cond_equal, dest);2341} else if (high_key - low_key == 1) {2342__ cmp(lir_cond_equal, value, low_key);2343__ branch(lir_cond_equal, dest);2344__ cmp(lir_cond_equal, value, high_key);2345__ branch(lir_cond_equal, dest);2346} else {2347LabelObj* L = new LabelObj();2348__ cmp(lir_cond_less, value, low_key);2349__ branch(lir_cond_less, L->label());2350__ cmp(lir_cond_lessEqual, value, high_key);2351__ branch(lir_cond_lessEqual, dest);2352__ branch_destination(L->label());2353}2354}2355__ jump(default_sux);2356}235723582359SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) {2360SwitchRangeList* res = new SwitchRangeList();2361int len = x->length();2362if (len > 0) {2363BlockBegin* sux = x->sux_at(0);2364int key = x->lo_key();2365BlockBegin* default_sux = x->default_sux();2366C1SwitchRange* range = new C1SwitchRange(key, sux);2367for (int i = 0; i < len; i++, key++) {2368BlockBegin* new_sux = x->sux_at(i);2369if (sux == new_sux) {2370// still in same range2371range->set_high_key(key);2372} else {2373// skip tests which explicitly dispatch to the default2374if (sux != default_sux) {2375res->append(range);2376}2377range = new C1SwitchRange(key, new_sux);2378}2379sux = new_sux;2380}2381if (res->length() == 0 || res->last() != range) res->append(range);2382}2383return res;2384}238523862387// we expect the keys to be sorted by increasing value2388SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) {2389SwitchRangeList* res = new SwitchRangeList();2390int len = x->length();2391if (len > 0) {2392BlockBegin* default_sux = x->default_sux();2393int key = x->key_at(0);2394BlockBegin* sux = x->sux_at(0);2395C1SwitchRange* range = new C1SwitchRange(key, sux);2396for (int i = 1; i < len; i++) {2397int new_key = x->key_at(i);2398BlockBegin* new_sux = x->sux_at(i);2399if (key+1 == new_key && sux == new_sux) {2400// still in same range2401range->set_high_key(new_key);2402} else {2403// skip tests which explicitly dispatch to the default2404if (range->sux() != default_sux) {2405res->append(range);2406}2407range = new C1SwitchRange(new_key, new_sux);2408}2409key = new_key;2410sux = new_sux;2411}2412if (res->length() == 0 || res->last() != range) res->append(range);2413}2414return res;2415}241624172418void LIRGenerator::do_TableSwitch(TableSwitch* x) {2419LIRItem tag(x->tag(), this);2420tag.load_item();2421set_no_result(x);24222423if (x->is_safepoint()) {2424__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));2425}24262427// move values into phi locations2428move_to_phi(x->state());24292430int lo_key = x->lo_key();2431int len = x->length();2432assert(lo_key <= (lo_key + (len - 1)), "integer overflow");2433LIR_Opr value = tag.result();24342435if (compilation()->env()->comp_level() == CompLevel_full_profile && UseSwitchProfiling) {2436ciMethod* method = x->state()->scope()->method();2437ciMethodData* md = method->method_data_or_null();2438assert(md != NULL, "Sanity");2439ciProfileData* data = md->bci_to_data(x->state()->bci());2440assert(data != NULL, "must have profiling data");2441assert(data->is_MultiBranchData(), "bad profile data?");2442int default_count_offset = md->byte_offset_of_slot(data, MultiBranchData::default_count_offset());2443LIR_Opr md_reg = new_register(T_METADATA);2444__ metadata2reg(md->constant_encoding(), md_reg);2445LIR_Opr data_offset_reg = new_pointer_register();2446LIR_Opr tmp_reg = new_pointer_register();24472448__ move(LIR_OprFact::intptrConst(default_count_offset), data_offset_reg);2449for (int i = 0; i < len; i++) {2450int count_offset = md->byte_offset_of_slot(data, MultiBranchData::case_count_offset(i));2451__ cmp(lir_cond_equal, value, i + lo_key);2452__ move(data_offset_reg, tmp_reg);2453__ cmove(lir_cond_equal,2454LIR_OprFact::intptrConst(count_offset),2455tmp_reg,2456data_offset_reg, T_INT);2457}24582459LIR_Opr data_reg = new_pointer_register();2460LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());2461__ move(data_addr, data_reg);2462__ add(data_reg, LIR_OprFact::intptrConst(1), data_reg);2463__ move(data_reg, data_addr);2464}24652466if (UseTableRanges) {2467do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());2468} else {2469for (int i = 0; i < len; i++) {2470__ cmp(lir_cond_equal, value, i + lo_key);2471__ branch(lir_cond_equal, x->sux_at(i));2472}2473__ jump(x->default_sux());2474}2475}247624772478void LIRGenerator::do_LookupSwitch(LookupSwitch* x) {2479LIRItem tag(x->tag(), this);2480tag.load_item();2481set_no_result(x);24822483if (x->is_safepoint()) {2484__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));2485}24862487// move values into phi locations2488move_to_phi(x->state());24892490LIR_Opr value = tag.result();2491int len = x->length();24922493if (compilation()->env()->comp_level() == CompLevel_full_profile && UseSwitchProfiling) {2494ciMethod* method = x->state()->scope()->method();2495ciMethodData* md = method->method_data_or_null();2496assert(md != NULL, "Sanity");2497ciProfileData* data = md->bci_to_data(x->state()->bci());2498assert(data != NULL, "must have profiling data");2499assert(data->is_MultiBranchData(), "bad profile data?");2500int default_count_offset = md->byte_offset_of_slot(data, MultiBranchData::default_count_offset());2501LIR_Opr md_reg = new_register(T_METADATA);2502__ metadata2reg(md->constant_encoding(), md_reg);2503LIR_Opr data_offset_reg = new_pointer_register();2504LIR_Opr tmp_reg = new_pointer_register();25052506__ move(LIR_OprFact::intptrConst(default_count_offset), data_offset_reg);2507for (int i = 0; i < len; i++) {2508int count_offset = md->byte_offset_of_slot(data, MultiBranchData::case_count_offset(i));2509__ cmp(lir_cond_equal, value, x->key_at(i));2510__ move(data_offset_reg, tmp_reg);2511__ cmove(lir_cond_equal,2512LIR_OprFact::intptrConst(count_offset),2513tmp_reg,2514data_offset_reg, T_INT);2515}25162517LIR_Opr data_reg = new_pointer_register();2518LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());2519__ move(data_addr, data_reg);2520__ add(data_reg, LIR_OprFact::intptrConst(1), data_reg);2521__ move(data_reg, data_addr);2522}25232524if (UseTableRanges) {2525do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());2526} else {2527int len = x->length();2528for (int i = 0; i < len; i++) {2529__ cmp(lir_cond_equal, value, x->key_at(i));2530__ branch(lir_cond_equal, x->sux_at(i));2531}2532__ jump(x->default_sux());2533}2534}253525362537void LIRGenerator::do_Goto(Goto* x) {2538set_no_result(x);25392540if (block()->next()->as_OsrEntry()) {2541// need to free up storage used for OSR entry point2542LIR_Opr osrBuffer = block()->next()->operand();2543BasicTypeList signature;2544signature.append(NOT_LP64(T_INT) LP64_ONLY(T_LONG)); // pass a pointer to osrBuffer2545CallingConvention* cc = frame_map()->c_calling_convention(&signature);2546__ move(osrBuffer, cc->args()->at(0));2547__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),2548getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());2549}25502551if (x->is_safepoint()) {2552ValueStack* state = x->state_before() ? x->state_before() : x->state();25532554// increment backedge counter if needed2555CodeEmitInfo* info = state_for(x, state);2556increment_backedge_counter(info, x->profiled_bci());2557CodeEmitInfo* safepoint_info = state_for(x, state);2558__ safepoint(safepoint_poll_register(), safepoint_info);2559}25602561// Gotos can be folded Ifs, handle this case.2562if (x->should_profile()) {2563ciMethod* method = x->profiled_method();2564assert(method != NULL, "method should be set if branch is profiled");2565ciMethodData* md = method->method_data_or_null();2566assert(md != NULL, "Sanity");2567ciProfileData* data = md->bci_to_data(x->profiled_bci());2568assert(data != NULL, "must have profiling data");2569int offset;2570if (x->direction() == Goto::taken) {2571assert(data->is_BranchData(), "need BranchData for two-way branches");2572offset = md->byte_offset_of_slot(data, BranchData::taken_offset());2573} else if (x->direction() == Goto::not_taken) {2574assert(data->is_BranchData(), "need BranchData for two-way branches");2575offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());2576} else {2577assert(data->is_JumpData(), "need JumpData for branches");2578offset = md->byte_offset_of_slot(data, JumpData::taken_offset());2579}2580LIR_Opr md_reg = new_register(T_METADATA);2581__ metadata2reg(md->constant_encoding(), md_reg);25822583increment_counter(new LIR_Address(md_reg, offset,2584NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);2585}25862587// emit phi-instruction move after safepoint since this simplifies2588// describing the state as the safepoint.2589move_to_phi(x->state());25902591__ jump(x->default_sux());2592}25932594/**2595* Emit profiling code if needed for arguments, parameters, return value types2596*2597* @param md MDO the code will update at runtime2598* @param md_base_offset common offset in the MDO for this profile and subsequent ones2599* @param md_offset offset in the MDO (on top of md_base_offset) for this profile2600* @param profiled_k current profile2601* @param obj IR node for the object to be profiled2602* @param mdp register to hold the pointer inside the MDO (md + md_base_offset).2603* Set once we find an update to make and use for next ones.2604* @param not_null true if we know obj cannot be null2605* @param signature_at_call_k signature at call for obj2606* @param callee_signature_k signature of callee for obj2607* at call and callee signatures differ at method handle call2608* @return the only klass we know will ever be seen at this profile point2609*/2610ciKlass* LIRGenerator::profile_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k,2611Value obj, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,2612ciKlass* callee_signature_k) {2613ciKlass* result = NULL;2614bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);2615bool do_update = !TypeEntries::is_type_unknown(profiled_k);2616// known not to be null or null bit already set and already set to2617// unknown: nothing we can do to improve profiling2618if (!do_null && !do_update) {2619return result;2620}26212622ciKlass* exact_klass = NULL;2623Compilation* comp = Compilation::current();2624if (do_update) {2625// try to find exact type, using CHA if possible, so that loading2626// the klass from the object can be avoided2627ciType* type = obj->exact_type();2628if (type == NULL) {2629type = obj->declared_type();2630type = comp->cha_exact_type(type);2631}2632assert(type == NULL || type->is_klass(), "type should be class");2633exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;26342635do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;2636}26372638if (!do_null && !do_update) {2639return result;2640}26412642ciKlass* exact_signature_k = NULL;2643if (do_update) {2644// Is the type from the signature exact (the only one possible)?2645exact_signature_k = signature_at_call_k->exact_klass();2646if (exact_signature_k == NULL) {2647exact_signature_k = comp->cha_exact_type(signature_at_call_k);2648} else {2649result = exact_signature_k;2650// Known statically. No need to emit any code: prevent2651// LIR_Assembler::emit_profile_type() from emitting useless code2652profiled_k = ciTypeEntries::with_status(result, profiled_k);2653}2654// exact_klass and exact_signature_k can be both non NULL but2655// different if exact_klass is loaded after the ciObject for2656// exact_signature_k is created.2657if (exact_klass == NULL && exact_signature_k != NULL && exact_klass != exact_signature_k) {2658// sometimes the type of the signature is better than the best type2659// the compiler has2660exact_klass = exact_signature_k;2661}2662if (callee_signature_k != NULL &&2663callee_signature_k != signature_at_call_k) {2664ciKlass* improved_klass = callee_signature_k->exact_klass();2665if (improved_klass == NULL) {2666improved_klass = comp->cha_exact_type(callee_signature_k);2667}2668if (exact_klass == NULL && improved_klass != NULL && exact_klass != improved_klass) {2669exact_klass = exact_signature_k;2670}2671}2672do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;2673}26742675if (!do_null && !do_update) {2676return result;2677}26782679if (mdp == LIR_OprFact::illegalOpr) {2680mdp = new_register(T_METADATA);2681__ metadata2reg(md->constant_encoding(), mdp);2682if (md_base_offset != 0) {2683LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);2684mdp = new_pointer_register();2685__ leal(LIR_OprFact::address(base_type_address), mdp);2686}2687}2688LIRItem value(obj, this);2689value.load_item();2690__ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),2691value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);2692return result;2693}26942695// profile parameters on entry to the root of the compilation2696void LIRGenerator::profile_parameters(Base* x) {2697if (compilation()->profile_parameters()) {2698CallingConvention* args = compilation()->frame_map()->incoming_arguments();2699ciMethodData* md = scope()->method()->method_data_or_null();2700assert(md != NULL, "Sanity");27012702if (md->parameters_type_data() != NULL) {2703ciParametersTypeData* parameters_type_data = md->parameters_type_data();2704ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();2705LIR_Opr mdp = LIR_OprFact::illegalOpr;2706for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {2707LIR_Opr src = args->at(i);2708assert(!src->is_illegal(), "check");2709BasicType t = src->type();2710if (is_reference_type(t)) {2711intptr_t profiled_k = parameters->type(j);2712Local* local = x->state()->local_at(java_index)->as_Local();2713ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),2714in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),2715profiled_k, local, mdp, false, local->declared_type()->as_klass(), NULL);2716// If the profile is known statically set it once for all and do not emit any code2717if (exact != NULL) {2718md->set_parameter_type(j, exact);2719}2720j++;2721}2722java_index += type2size[t];2723}2724}2725}2726}27272728void LIRGenerator::do_Base(Base* x) {2729__ std_entry(LIR_OprFact::illegalOpr);2730// Emit moves from physical registers / stack slots to virtual registers2731CallingConvention* args = compilation()->frame_map()->incoming_arguments();2732IRScope* irScope = compilation()->hir()->top_scope();2733int java_index = 0;2734for (int i = 0; i < args->length(); i++) {2735LIR_Opr src = args->at(i);2736assert(!src->is_illegal(), "check");2737BasicType t = src->type();27382739// Types which are smaller than int are passed as int, so2740// correct the type which passed.2741switch (t) {2742case T_BYTE:2743case T_BOOLEAN:2744case T_SHORT:2745case T_CHAR:2746t = T_INT;2747break;2748default:2749break;2750}27512752LIR_Opr dest = new_register(t);2753__ move(src, dest);27542755// Assign new location to Local instruction for this local2756Local* local = x->state()->local_at(java_index)->as_Local();2757assert(local != NULL, "Locals for incoming arguments must have been created");2758#ifndef __SOFTFP__2759// The java calling convention passes double as long and float as int.2760assert(as_ValueType(t)->tag() == local->type()->tag(), "check");2761#endif // __SOFTFP__2762local->set_operand(dest);2763_instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL);2764java_index += type2size[t];2765}27662767if (compilation()->env()->dtrace_method_probes()) {2768BasicTypeList signature;2769signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread2770signature.append(T_METADATA); // Method*2771LIR_OprList* args = new LIR_OprList();2772args->append(getThreadPointer());2773LIR_Opr meth = new_register(T_METADATA);2774__ metadata2reg(method()->constant_encoding(), meth);2775args->append(meth);2776call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);2777}27782779if (method()->is_synchronized()) {2780LIR_Opr obj;2781if (method()->is_static()) {2782obj = new_register(T_OBJECT);2783__ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);2784} else {2785Local* receiver = x->state()->local_at(0)->as_Local();2786assert(receiver != NULL, "must already exist");2787obj = receiver->operand();2788}2789assert(obj->is_valid(), "must be valid");27902791if (method()->is_synchronized() && GenerateSynchronizationCode) {2792LIR_Opr lock = syncLockOpr();2793__ load_stack_address_monitor(0, lock);27942795CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));2796CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);27972798// receiver is guaranteed non-NULL so don't need CodeEmitInfo2799__ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);2800}2801}2802if (compilation()->age_code()) {2803CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, 0), NULL, false);2804decrement_age(info);2805}2806// increment invocation counters if needed2807if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.2808profile_parameters(x);2809CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);2810increment_invocation_counter(info);2811}28122813// all blocks with a successor must end with an unconditional jump2814// to the successor even if they are consecutive2815__ jump(x->default_sux());2816}281728182819void LIRGenerator::do_OsrEntry(OsrEntry* x) {2820// construct our frame and model the production of incoming pointer2821// to the OSR buffer.2822__ osr_entry(LIR_Assembler::osrBufferPointer());2823LIR_Opr result = rlock_result(x);2824__ move(LIR_Assembler::osrBufferPointer(), result);2825}282628272828void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {2829assert(args->length() == arg_list->length(),2830"args=%d, arg_list=%d", args->length(), arg_list->length());2831for (int i = x->has_receiver() ? 1 : 0; i < args->length(); i++) {2832LIRItem* param = args->at(i);2833LIR_Opr loc = arg_list->at(i);2834if (loc->is_register()) {2835param->load_item_force(loc);2836} else {2837LIR_Address* addr = loc->as_address_ptr();2838param->load_for_store(addr->type());2839if (addr->type() == T_OBJECT) {2840__ move_wide(param->result(), addr);2841} else2842if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {2843__ unaligned_move(param->result(), addr);2844} else {2845__ move(param->result(), addr);2846}2847}2848}28492850if (x->has_receiver()) {2851LIRItem* receiver = args->at(0);2852LIR_Opr loc = arg_list->at(0);2853if (loc->is_register()) {2854receiver->load_item_force(loc);2855} else {2856assert(loc->is_address(), "just checking");2857receiver->load_for_store(T_OBJECT);2858__ move_wide(receiver->result(), loc->as_address_ptr());2859}2860}2861}286228632864// Visits all arguments, returns appropriate items without loading them2865LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) {2866LIRItemList* argument_items = new LIRItemList();2867if (x->has_receiver()) {2868LIRItem* receiver = new LIRItem(x->receiver(), this);2869argument_items->append(receiver);2870}2871for (int i = 0; i < x->number_of_arguments(); i++) {2872LIRItem* param = new LIRItem(x->argument_at(i), this);2873argument_items->append(param);2874}2875return argument_items;2876}287728782879// The invoke with receiver has following phases:2880// a) traverse and load/lock receiver;2881// b) traverse all arguments -> item-array (invoke_visit_argument)2882// c) push receiver on stack2883// d) load each of the items and push on stack2884// e) unlock receiver2885// f) move receiver into receiver-register %o02886// g) lock result registers and emit call operation2887//2888// Before issuing a call, we must spill-save all values on stack2889// that are in caller-save register. "spill-save" moves those registers2890// either in a free callee-save register or spills them if no free2891// callee save register is available.2892//2893// The problem is where to invoke spill-save.2894// - if invoked between e) and f), we may lock callee save2895// register in "spill-save" that destroys the receiver register2896// before f) is executed2897// - if we rearrange f) to be earlier (by loading %o0) it2898// may destroy a value on the stack that is currently in %o02899// and is waiting to be spilled2900// - if we keep the receiver locked while doing spill-save,2901// we cannot spill it as it is spill-locked2902//2903void LIRGenerator::do_Invoke(Invoke* x) {2904CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true);29052906LIR_OprList* arg_list = cc->args();2907LIRItemList* args = invoke_visit_arguments(x);2908LIR_Opr receiver = LIR_OprFact::illegalOpr;29092910// setup result register2911LIR_Opr result_register = LIR_OprFact::illegalOpr;2912if (x->type() != voidType) {2913result_register = result_register_for(x->type());2914}29152916CodeEmitInfo* info = state_for(x, x->state());29172918invoke_load_arguments(x, args, arg_list);29192920if (x->has_receiver()) {2921args->at(0)->load_item_force(LIR_Assembler::receiverOpr());2922receiver = args->at(0)->result();2923}29242925// emit invoke code2926assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match");29272928// JSR 2922929// Preserve the SP over MethodHandle call sites, if needed.2930ciMethod* target = x->target();2931bool is_method_handle_invoke = (// %%% FIXME: Are both of these relevant?2932target->is_method_handle_intrinsic() ||2933target->is_compiled_lambda_form());2934if (is_method_handle_invoke) {2935info->set_is_method_handle_invoke(true);2936if(FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {2937__ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr());2938}2939}29402941switch (x->code()) {2942case Bytecodes::_invokestatic:2943__ call_static(target, result_register,2944SharedRuntime::get_resolve_static_call_stub(),2945arg_list, info);2946break;2947case Bytecodes::_invokespecial:2948case Bytecodes::_invokevirtual:2949case Bytecodes::_invokeinterface:2950// for loaded and final (method or class) target we still produce an inline cache,2951// in order to be able to call mixed mode2952if (x->code() == Bytecodes::_invokespecial || x->target_is_final()) {2953__ call_opt_virtual(target, receiver, result_register,2954SharedRuntime::get_resolve_opt_virtual_call_stub(),2955arg_list, info);2956} else {2957__ call_icvirtual(target, receiver, result_register,2958SharedRuntime::get_resolve_virtual_call_stub(),2959arg_list, info);2960}2961break;2962case Bytecodes::_invokedynamic: {2963__ call_dynamic(target, receiver, result_register,2964SharedRuntime::get_resolve_static_call_stub(),2965arg_list, info);2966break;2967}2968default:2969fatal("unexpected bytecode: %s", Bytecodes::name(x->code()));2970break;2971}29722973// JSR 2922974// Restore the SP after MethodHandle call sites, if needed.2975if (is_method_handle_invoke2976&& FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {2977__ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer());2978}29792980if (result_register->is_valid()) {2981LIR_Opr result = rlock_result(x);2982__ move(result_register, result);2983}2984}298529862987void LIRGenerator::do_FPIntrinsics(Intrinsic* x) {2988assert(x->number_of_arguments() == 1, "wrong type");2989LIRItem value (x->argument_at(0), this);2990LIR_Opr reg = rlock_result(x);2991value.load_item();2992LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type()));2993__ move(tmp, reg);2994}2995299629972998// Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval()2999void LIRGenerator::do_IfOp(IfOp* x) {3000#ifdef ASSERT3001{3002ValueTag xtag = x->x()->type()->tag();3003ValueTag ttag = x->tval()->type()->tag();3004assert(xtag == intTag || xtag == objectTag, "cannot handle others");3005assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");3006assert(ttag == x->fval()->type()->tag(), "cannot handle others");3007}3008#endif30093010LIRItem left(x->x(), this);3011LIRItem right(x->y(), this);3012left.load_item();3013if (can_inline_as_constant(right.value())) {3014right.dont_load_item();3015} else {3016right.load_item();3017}30183019LIRItem t_val(x->tval(), this);3020LIRItem f_val(x->fval(), this);3021t_val.dont_load_item();3022f_val.dont_load_item();3023LIR_Opr reg = rlock_result(x);30243025__ cmp(lir_cond(x->cond()), left.result(), right.result());3026__ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type()));3027}30283029#ifdef JFR_HAVE_INTRINSICS30303031void LIRGenerator::do_getEventWriter(Intrinsic* x) {3032LabelObj* L_end = new LabelObj();30333034// FIXME T_ADDRESS should actually be T_METADATA but it can't because the3035// meaning of these two is mixed up (see JDK-8026837).3036LIR_Address* jobj_addr = new LIR_Address(getThreadPointer(),3037in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR),3038T_ADDRESS);3039LIR_Opr result = rlock_result(x);3040__ move(LIR_OprFact::oopConst(NULL), result);3041LIR_Opr jobj = new_register(T_METADATA);3042__ move_wide(jobj_addr, jobj);3043__ cmp(lir_cond_equal, jobj, LIR_OprFact::metadataConst(0));3044__ branch(lir_cond_equal, L_end->label());30453046access_load(IN_NATIVE, T_OBJECT, LIR_OprFact::address(new LIR_Address(jobj, T_OBJECT)), result);30473048__ branch_destination(L_end->label());3049}30503051#endif305230533054void LIRGenerator::do_RuntimeCall(address routine, Intrinsic* x) {3055assert(x->number_of_arguments() == 0, "wrong type");3056// Enforce computation of _reserved_argument_area_size which is required on some platforms.3057BasicTypeList signature;3058CallingConvention* cc = frame_map()->c_calling_convention(&signature);3059LIR_Opr reg = result_register_for(x->type());3060__ call_runtime_leaf(routine, getThreadTemp(),3061reg, new LIR_OprList());3062LIR_Opr result = rlock_result(x);3063__ move(reg, result);3064}3065306630673068void LIRGenerator::do_Intrinsic(Intrinsic* x) {3069switch (x->id()) {3070case vmIntrinsics::_intBitsToFloat :3071case vmIntrinsics::_doubleToRawLongBits :3072case vmIntrinsics::_longBitsToDouble :3073case vmIntrinsics::_floatToRawIntBits : {3074do_FPIntrinsics(x);3075break;3076}30773078#ifdef JFR_HAVE_INTRINSICS3079case vmIntrinsics::_getEventWriter:3080do_getEventWriter(x);3081break;3082case vmIntrinsics::_counterTime:3083do_RuntimeCall(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), x);3084break;3085#endif30863087case vmIntrinsics::_currentTimeMillis:3088do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), x);3089break;30903091case vmIntrinsics::_nanoTime:3092do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), x);3093break;30943095case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;3096case vmIntrinsics::_isInstance: do_isInstance(x); break;3097case vmIntrinsics::_isPrimitive: do_isPrimitive(x); break;3098case vmIntrinsics::_getModifiers: do_getModifiers(x); break;3099case vmIntrinsics::_getClass: do_getClass(x); break;3100case vmIntrinsics::_currentThread: do_currentThread(x); break;3101case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break;31023103case vmIntrinsics::_dlog: // fall through3104case vmIntrinsics::_dlog10: // fall through3105case vmIntrinsics::_dabs: // fall through3106case vmIntrinsics::_dsqrt: // fall through3107case vmIntrinsics::_dtan: // fall through3108case vmIntrinsics::_dsin : // fall through3109case vmIntrinsics::_dcos : // fall through3110case vmIntrinsics::_dexp : // fall through3111case vmIntrinsics::_dpow : do_MathIntrinsic(x); break;3112case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break;31133114case vmIntrinsics::_fmaD: do_FmaIntrinsic(x); break;3115case vmIntrinsics::_fmaF: do_FmaIntrinsic(x); break;31163117// java.nio.Buffer.checkIndex3118case vmIntrinsics::_checkIndex: do_NIOCheckIndex(x); break;31193120case vmIntrinsics::_compareAndSetReference:3121do_CompareAndSwap(x, objectType);3122break;3123case vmIntrinsics::_compareAndSetInt:3124do_CompareAndSwap(x, intType);3125break;3126case vmIntrinsics::_compareAndSetLong:3127do_CompareAndSwap(x, longType);3128break;31293130case vmIntrinsics::_loadFence :3131__ membar_acquire();3132break;3133case vmIntrinsics::_storeFence:3134__ membar_release();3135break;3136case vmIntrinsics::_fullFence :3137__ membar();3138break;3139case vmIntrinsics::_onSpinWait:3140__ on_spin_wait();3141break;3142case vmIntrinsics::_Reference_get:3143do_Reference_get(x);3144break;31453146case vmIntrinsics::_updateCRC32:3147case vmIntrinsics::_updateBytesCRC32:3148case vmIntrinsics::_updateByteBufferCRC32:3149do_update_CRC32(x);3150break;31513152case vmIntrinsics::_updateBytesCRC32C:3153case vmIntrinsics::_updateDirectByteBufferCRC32C:3154do_update_CRC32C(x);3155break;31563157case vmIntrinsics::_vectorizedMismatch:3158do_vectorizedMismatch(x);3159break;31603161case vmIntrinsics::_blackhole:3162do_blackhole(x);3163break;31643165default: ShouldNotReachHere(); break;3166}3167}31683169void LIRGenerator::profile_arguments(ProfileCall* x) {3170if (compilation()->profile_arguments()) {3171int bci = x->bci_of_invoke();3172ciMethodData* md = x->method()->method_data_or_null();3173assert(md != NULL, "Sanity");3174ciProfileData* data = md->bci_to_data(bci);3175if (data != NULL) {3176if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||3177(data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {3178ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();3179int base_offset = md->byte_offset_of_slot(data, extra);3180LIR_Opr mdp = LIR_OprFact::illegalOpr;3181ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();31823183Bytecodes::Code bc = x->method()->java_code_at_bci(bci);3184int start = 0;3185int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();3186if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {3187// first argument is not profiled at call (method handle invoke)3188assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");3189start = 1;3190}3191ciSignature* callee_signature = x->callee()->signature();3192// method handle call to virtual method3193bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);3194ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);31953196bool ignored_will_link;3197ciSignature* signature_at_call = NULL;3198x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);3199ciSignatureStream signature_at_call_stream(signature_at_call);32003201// if called through method handle invoke, some arguments may have been popped3202for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) {3203int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());3204ciKlass* exact = profile_type(md, base_offset, off,3205args->type(i), x->profiled_arg_at(i+start), mdp,3206!x->arg_needs_null_check(i+start),3207signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());3208if (exact != NULL) {3209md->set_argument_type(bci, i, exact);3210}3211}3212} else {3213#ifdef ASSERT3214Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());3215int n = x->nb_profiled_args();3216assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() ||3217(x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))),3218"only at JSR292 bytecodes");3219#endif3220}3221}3222}3223}32243225// profile parameters on entry to an inlined method3226void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {3227if (compilation()->profile_parameters() && x->inlined()) {3228ciMethodData* md = x->callee()->method_data_or_null();3229if (md != NULL) {3230ciParametersTypeData* parameters_type_data = md->parameters_type_data();3231if (parameters_type_data != NULL) {3232ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();3233LIR_Opr mdp = LIR_OprFact::illegalOpr;3234bool has_receiver = !x->callee()->is_static();3235ciSignature* sig = x->callee()->signature();3236ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);3237int i = 0; // to iterate on the Instructions3238Value arg = x->recv();3239bool not_null = false;3240int bci = x->bci_of_invoke();3241Bytecodes::Code bc = x->method()->java_code_at_bci(bci);3242// The first parameter is the receiver so that's what we start3243// with if it exists. One exception is method handle call to3244// virtual method: the receiver is in the args list3245if (arg == NULL || !Bytecodes::has_receiver(bc)) {3246i = 1;3247arg = x->profiled_arg_at(0);3248not_null = !x->arg_needs_null_check(0);3249}3250int k = 0; // to iterate on the profile data3251for (;;) {3252intptr_t profiled_k = parameters->type(k);3253ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),3254in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),3255profiled_k, arg, mdp, not_null, sig_stream.next_klass(), NULL);3256// If the profile is known statically set it once for all and do not emit any code3257if (exact != NULL) {3258md->set_parameter_type(k, exact);3259}3260k++;3261if (k >= parameters_type_data->number_of_parameters()) {3262#ifdef ASSERT3263int extra = 0;3264if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&3265x->nb_profiled_args() >= TypeProfileParmsLimit &&3266x->recv() != NULL && Bytecodes::has_receiver(bc)) {3267extra += 1;3268}3269assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");3270#endif3271break;3272}3273arg = x->profiled_arg_at(i);3274not_null = !x->arg_needs_null_check(i);3275i++;3276}3277}3278}3279}3280}32813282void LIRGenerator::do_ProfileCall(ProfileCall* x) {3283// Need recv in a temporary register so it interferes with the other temporaries3284LIR_Opr recv = LIR_OprFact::illegalOpr;3285LIR_Opr mdo = new_register(T_METADATA);3286// tmp is used to hold the counters on SPARC3287LIR_Opr tmp = new_pointer_register();32883289if (x->nb_profiled_args() > 0) {3290profile_arguments(x);3291}32923293// profile parameters on inlined method entry including receiver3294if (x->recv() != NULL || x->nb_profiled_args() > 0) {3295profile_parameters_at_call(x);3296}32973298if (x->recv() != NULL) {3299LIRItem value(x->recv(), this);3300value.load_item();3301recv = new_register(T_OBJECT);3302__ move(value.result(), recv);3303}3304__ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());3305}33063307void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {3308int bci = x->bci_of_invoke();3309ciMethodData* md = x->method()->method_data_or_null();3310assert(md != NULL, "Sanity");3311ciProfileData* data = md->bci_to_data(bci);3312if (data != NULL) {3313assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");3314ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();3315LIR_Opr mdp = LIR_OprFact::illegalOpr;33163317bool ignored_will_link;3318ciSignature* signature_at_call = NULL;3319x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);33203321// The offset within the MDO of the entry to update may be too large3322// to be used in load/store instructions on some platforms. So have3323// profile_type() compute the address of the profile in a register.3324ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0,3325ret->type(), x->ret(), mdp,3326!x->needs_null_check(),3327signature_at_call->return_type()->as_klass(),3328x->callee()->signature()->return_type()->as_klass());3329if (exact != NULL) {3330md->set_return_type(bci, exact);3331}3332}3333}33343335void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {3336// We can safely ignore accessors here, since c2 will inline them anyway,3337// accessors are also always mature.3338if (!x->inlinee()->is_accessor()) {3339CodeEmitInfo* info = state_for(x, x->state(), true);3340// Notify the runtime very infrequently only to take care of counter overflows3341int freq_log = Tier23InlineeNotifyFreqLog;3342double scale;3343if (_method->has_option_value(CompileCommand::CompileThresholdScaling, scale)) {3344freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);3345}3346increment_event_counter_impl(info, x->inlinee(), LIR_OprFact::intConst(InvocationCounter::count_increment), right_n_bits(freq_log), InvocationEntryBci, false, true);3347}3348}33493350void LIRGenerator::increment_backedge_counter_conditionally(LIR_Condition cond, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info, int left_bci, int right_bci, int bci) {3351if (compilation()->count_backedges()) {3352#if defined(X86) && !defined(_LP64)3353// BEWARE! On 32-bit x86 cmp clobbers its left argument so we need a temp copy.3354LIR_Opr left_copy = new_register(left->type());3355__ move(left, left_copy);3356__ cmp(cond, left_copy, right);3357#else3358__ cmp(cond, left, right);3359#endif3360LIR_Opr step = new_register(T_INT);3361LIR_Opr plus_one = LIR_OprFact::intConst(InvocationCounter::count_increment);3362LIR_Opr zero = LIR_OprFact::intConst(0);3363__ cmove(cond,3364(left_bci < bci) ? plus_one : zero,3365(right_bci < bci) ? plus_one : zero,3366step, left->type());3367increment_backedge_counter(info, step, bci);3368}3369}337033713372void LIRGenerator::increment_event_counter(CodeEmitInfo* info, LIR_Opr step, int bci, bool backedge) {3373int freq_log = 0;3374int level = compilation()->env()->comp_level();3375if (level == CompLevel_limited_profile) {3376freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);3377} else if (level == CompLevel_full_profile) {3378freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);3379} else {3380ShouldNotReachHere();3381}3382// Increment the appropriate invocation/backedge counter and notify the runtime.3383double scale;3384if (_method->has_option_value(CompileCommand::CompileThresholdScaling, scale)) {3385freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);3386}3387increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);3388}33893390void LIRGenerator::decrement_age(CodeEmitInfo* info) {3391ciMethod* method = info->scope()->method();3392MethodCounters* mc_adr = method->ensure_method_counters();3393if (mc_adr != NULL) {3394LIR_Opr mc = new_pointer_register();3395__ move(LIR_OprFact::intptrConst(mc_adr), mc);3396int offset = in_bytes(MethodCounters::nmethod_age_offset());3397LIR_Address* counter = new LIR_Address(mc, offset, T_INT);3398LIR_Opr result = new_register(T_INT);3399__ load(counter, result);3400__ sub(result, LIR_OprFact::intConst(1), result);3401__ store(result, counter);3402// DeoptimizeStub will reexecute from the current state in code info.3403CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_tenured,3404Deoptimization::Action_make_not_entrant);3405__ cmp(lir_cond_lessEqual, result, LIR_OprFact::intConst(0));3406__ branch(lir_cond_lessEqual, deopt);3407}3408}340934103411void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,3412ciMethod *method, LIR_Opr step, int frequency,3413int bci, bool backedge, bool notify) {3414assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");3415int level = _compilation->env()->comp_level();3416assert(level > CompLevel_simple, "Shouldn't be here");34173418int offset = -1;3419LIR_Opr counter_holder = NULL;3420if (level == CompLevel_limited_profile) {3421MethodCounters* counters_adr = method->ensure_method_counters();3422if (counters_adr == NULL) {3423bailout("method counters allocation failed");3424return;3425}3426counter_holder = new_pointer_register();3427__ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);3428offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :3429MethodCounters::invocation_counter_offset());3430} else if (level == CompLevel_full_profile) {3431counter_holder = new_register(T_METADATA);3432offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :3433MethodData::invocation_counter_offset());3434ciMethodData* md = method->method_data_or_null();3435assert(md != NULL, "Sanity");3436__ metadata2reg(md->constant_encoding(), counter_holder);3437} else {3438ShouldNotReachHere();3439}3440LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);3441LIR_Opr result = new_register(T_INT);3442__ load(counter, result);3443__ add(result, step, result);3444__ store(result, counter);3445if (notify && (!backedge || UseOnStackReplacement)) {3446LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());3447// The bci for info can point to cmp for if's we want the if bci3448CodeStub* overflow = new CounterOverflowStub(info, bci, meth);3449int freq = frequency << InvocationCounter::count_shift;3450if (freq == 0) {3451if (!step->is_constant()) {3452__ cmp(lir_cond_notEqual, step, LIR_OprFact::intConst(0));3453__ branch(lir_cond_notEqual, overflow);3454} else {3455__ branch(lir_cond_always, overflow);3456}3457} else {3458LIR_Opr mask = load_immediate(freq, T_INT);3459if (!step->is_constant()) {3460// If step is 0, make sure the overflow check below always fails3461__ cmp(lir_cond_notEqual, step, LIR_OprFact::intConst(0));3462__ cmove(lir_cond_notEqual, result, LIR_OprFact::intConst(InvocationCounter::count_increment), result, T_INT);3463}3464__ logical_and(result, mask, result);3465__ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0));3466__ branch(lir_cond_equal, overflow);3467}3468__ branch_destination(overflow->continuation());3469}3470}34713472void LIRGenerator::do_RuntimeCall(RuntimeCall* x) {3473LIR_OprList* args = new LIR_OprList(x->number_of_arguments());3474BasicTypeList* signature = new BasicTypeList(x->number_of_arguments());34753476if (x->pass_thread()) {3477signature->append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread3478args->append(getThreadPointer());3479}34803481for (int i = 0; i < x->number_of_arguments(); i++) {3482Value a = x->argument_at(i);3483LIRItem* item = new LIRItem(a, this);3484item->load_item();3485args->append(item->result());3486signature->append(as_BasicType(a->type()));3487}34883489LIR_Opr result = call_runtime(signature, args, x->entry(), x->type(), NULL);3490if (x->type() == voidType) {3491set_no_result(x);3492} else {3493__ move(result, rlock_result(x));3494}3495}34963497#ifdef ASSERT3498void LIRGenerator::do_Assert(Assert *x) {3499ValueTag tag = x->x()->type()->tag();3500If::Condition cond = x->cond();35013502LIRItem xitem(x->x(), this);3503LIRItem yitem(x->y(), this);3504LIRItem* xin = &xitem;3505LIRItem* yin = &yitem;35063507assert(tag == intTag, "Only integer assertions are valid!");35083509xin->load_item();3510yin->dont_load_item();35113512set_no_result(x);35133514LIR_Opr left = xin->result();3515LIR_Opr right = yin->result();35163517__ lir_assert(lir_cond(x->cond()), left, right, x->message(), true);3518}3519#endif35203521void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) {352235233524Instruction *a = x->x();3525Instruction *b = x->y();3526if (!a || StressRangeCheckElimination) {3527assert(!b || StressRangeCheckElimination, "B must also be null");35283529CodeEmitInfo *info = state_for(x, x->state());3530CodeStub* stub = new PredicateFailedStub(info);35313532__ jump(stub);3533} else if (a->type()->as_IntConstant() && b->type()->as_IntConstant()) {3534int a_int = a->type()->as_IntConstant()->value();3535int b_int = b->type()->as_IntConstant()->value();35363537bool ok = false;35383539switch(x->cond()) {3540case Instruction::eql: ok = (a_int == b_int); break;3541case Instruction::neq: ok = (a_int != b_int); break;3542case Instruction::lss: ok = (a_int < b_int); break;3543case Instruction::leq: ok = (a_int <= b_int); break;3544case Instruction::gtr: ok = (a_int > b_int); break;3545case Instruction::geq: ok = (a_int >= b_int); break;3546case Instruction::aeq: ok = ((unsigned int)a_int >= (unsigned int)b_int); break;3547case Instruction::beq: ok = ((unsigned int)a_int <= (unsigned int)b_int); break;3548default: ShouldNotReachHere();3549}35503551if (ok) {35523553CodeEmitInfo *info = state_for(x, x->state());3554CodeStub* stub = new PredicateFailedStub(info);35553556__ jump(stub);3557}3558} else {35593560ValueTag tag = x->x()->type()->tag();3561If::Condition cond = x->cond();3562LIRItem xitem(x->x(), this);3563LIRItem yitem(x->y(), this);3564LIRItem* xin = &xitem;3565LIRItem* yin = &yitem;35663567assert(tag == intTag, "Only integer deoptimizations are valid!");35683569xin->load_item();3570yin->dont_load_item();3571set_no_result(x);35723573LIR_Opr left = xin->result();3574LIR_Opr right = yin->result();35753576CodeEmitInfo *info = state_for(x, x->state());3577CodeStub* stub = new PredicateFailedStub(info);35783579__ cmp(lir_cond(cond), left, right);3580__ branch(lir_cond(cond), stub);3581}3582}35833584void LIRGenerator::do_blackhole(Intrinsic *x) {3585assert(!x->has_receiver(), "Should have been checked before: only static methods here");3586for (int c = 0; c < x->number_of_arguments(); c++) {3587// Load the argument3588LIRItem vitem(x->argument_at(c), this);3589vitem.load_item();3590// ...and leave it unused.3591}3592}35933594LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {3595LIRItemList args(1);3596LIRItem value(arg1, this);3597args.append(&value);3598BasicTypeList signature;3599signature.append(as_BasicType(arg1->type()));36003601return call_runtime(&signature, &args, entry, result_type, info);3602}360336043605LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) {3606LIRItemList args(2);3607LIRItem value1(arg1, this);3608LIRItem value2(arg2, this);3609args.append(&value1);3610args.append(&value2);3611BasicTypeList signature;3612signature.append(as_BasicType(arg1->type()));3613signature.append(as_BasicType(arg2->type()));36143615return call_runtime(&signature, &args, entry, result_type, info);3616}361736183619LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args,3620address entry, ValueType* result_type, CodeEmitInfo* info) {3621// get a result register3622LIR_Opr phys_reg = LIR_OprFact::illegalOpr;3623LIR_Opr result = LIR_OprFact::illegalOpr;3624if (result_type->tag() != voidTag) {3625result = new_register(result_type);3626phys_reg = result_register_for(result_type);3627}36283629// move the arguments into the correct location3630CallingConvention* cc = frame_map()->c_calling_convention(signature);3631assert(cc->length() == args->length(), "argument mismatch");3632for (int i = 0; i < args->length(); i++) {3633LIR_Opr arg = args->at(i);3634LIR_Opr loc = cc->at(i);3635if (loc->is_register()) {3636__ move(arg, loc);3637} else {3638LIR_Address* addr = loc->as_address_ptr();3639// if (!can_store_as_constant(arg)) {3640// LIR_Opr tmp = new_register(arg->type());3641// __ move(arg, tmp);3642// arg = tmp;3643// }3644if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {3645__ unaligned_move(arg, addr);3646} else {3647__ move(arg, addr);3648}3649}3650}36513652if (info) {3653__ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);3654} else {3655__ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());3656}3657if (result->is_valid()) {3658__ move(phys_reg, result);3659}3660return result;3661}366236633664LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args,3665address entry, ValueType* result_type, CodeEmitInfo* info) {3666// get a result register3667LIR_Opr phys_reg = LIR_OprFact::illegalOpr;3668LIR_Opr result = LIR_OprFact::illegalOpr;3669if (result_type->tag() != voidTag) {3670result = new_register(result_type);3671phys_reg = result_register_for(result_type);3672}36733674// move the arguments into the correct location3675CallingConvention* cc = frame_map()->c_calling_convention(signature);36763677assert(cc->length() == args->length(), "argument mismatch");3678for (int i = 0; i < args->length(); i++) {3679LIRItem* arg = args->at(i);3680LIR_Opr loc = cc->at(i);3681if (loc->is_register()) {3682arg->load_item_force(loc);3683} else {3684LIR_Address* addr = loc->as_address_ptr();3685arg->load_for_store(addr->type());3686if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {3687__ unaligned_move(arg->result(), addr);3688} else {3689__ move(arg->result(), addr);3690}3691}3692}36933694if (info) {3695__ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);3696} else {3697__ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());3698}3699if (result->is_valid()) {3700__ move(phys_reg, result);3701}3702return result;3703}37043705void LIRGenerator::do_MemBar(MemBar* x) {3706LIR_Code code = x->code();3707switch(code) {3708case lir_membar_acquire : __ membar_acquire(); break;3709case lir_membar_release : __ membar_release(); break;3710case lir_membar : __ membar(); break;3711case lir_membar_loadload : __ membar_loadload(); break;3712case lir_membar_storestore: __ membar_storestore(); break;3713case lir_membar_loadstore : __ membar_loadstore(); break;3714case lir_membar_storeload : __ membar_storeload(); break;3715default : ShouldNotReachHere(); break;3716}3717}37183719LIR_Opr LIRGenerator::mask_boolean(LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {3720LIR_Opr value_fixed = rlock_byte(T_BYTE);3721if (TwoOperandLIRForm) {3722__ move(value, value_fixed);3723__ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed);3724} else {3725__ logical_and(value, LIR_OprFact::intConst(1), value_fixed);3726}3727LIR_Opr klass = new_register(T_METADATA);3728__ move(new LIR_Address(array, oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, null_check_info);3729null_check_info = NULL;3730LIR_Opr layout = new_register(T_INT);3731__ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);3732int diffbit = Klass::layout_helper_boolean_diffbit();3733__ logical_and(layout, LIR_OprFact::intConst(diffbit), layout);3734__ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0));3735__ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE);3736value = value_fixed;3737return value;3738}37393740LIR_Opr LIRGenerator::maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {3741if (x->check_boolean()) {3742value = mask_boolean(array, value, null_check_info);3743}3744return value;3745}374637473748