Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
32285 views
/*1* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_Defs.hpp"26#include "c1/c1_Compilation.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 "gc_implementation/shenandoah/shenandoahHeap.hpp"36#include "gc_implementation/shenandoah/c1/shenandoahBarrierSetC1.hpp"37#include "runtime/sharedRuntime.hpp"38#include "runtime/stubRoutines.hpp"39#include "utilities/bitMap.inline.hpp"40#include "utilities/macros.hpp"41#if INCLUDE_ALL_GCS42#include "gc_implementation/g1/heapRegion.hpp"43#endif // INCLUDE_ALL_GCS4445#ifdef ASSERT46#define __ gen()->lir(__FILE__, __LINE__)->47#else48#define __ gen()->lir()->49#endif5051#ifndef PATCHED_ADDR52#define PATCHED_ADDR (max_jint)53#endif5455void PhiResolverState::reset(int max_vregs) {56// Initialize array sizes57_virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);58_virtual_operands.trunc_to(0);59_other_operands.at_put_grow(max_vregs - 1, NULL, NULL);60_other_operands.trunc_to(0);61_vreg_table.at_put_grow(max_vregs - 1, NULL, NULL);62_vreg_table.trunc_to(0);63}64656667//--------------------------------------------------------------68// PhiResolver6970// Resolves cycles:71//72// r1 := r2 becomes temp := r173// r2 := r1 r1 := r274// r2 := temp75// and orders moves:76//77// r2 := r3 becomes r1 := r278// r1 := r2 r2 := r37980PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs)81: _gen(gen)82, _state(gen->resolver_state())83, _temp(LIR_OprFact::illegalOpr)84{85// reinitialize the shared state arrays86_state.reset(max_vregs);87}888990void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) {91assert(src->is_valid(), "");92assert(dest->is_valid(), "");93__ move(src, dest);94}959697void PhiResolver::move_temp_to(LIR_Opr dest) {98assert(_temp->is_valid(), "");99emit_move(_temp, dest);100NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr);101}102103104void PhiResolver::move_to_temp(LIR_Opr src) {105assert(_temp->is_illegal(), "");106_temp = _gen->new_register(src->type());107emit_move(src, _temp);108}109110111// Traverse assignment graph in depth first order and generate moves in post order112// ie. two assignments: b := c, a := b start with node c:113// Call graph: move(NULL, c) -> move(c, b) -> move(b, a)114// Generates moves in this order: move b to a and move c to b115// ie. cycle a := b, b := a start with node a116// Call graph: move(NULL, a) -> move(a, b) -> move(b, a)117// Generates moves in this order: move b to temp, move a to b, move temp to a118void PhiResolver::move(ResolveNode* src, ResolveNode* dest) {119if (!dest->visited()) {120dest->set_visited();121for (int i = dest->no_of_destinations()-1; i >= 0; i --) {122move(dest, dest->destination_at(i));123}124} else if (!dest->start_node()) {125// cylce in graph detected126assert(_loop == NULL, "only one loop valid!");127_loop = dest;128move_to_temp(src->operand());129return;130} // else dest is a start node131132if (!dest->assigned()) {133if (_loop == dest) {134move_temp_to(dest->operand());135dest->set_assigned();136} else if (src != NULL) {137emit_move(src->operand(), dest->operand());138dest->set_assigned();139}140}141}142143144PhiResolver::~PhiResolver() {145int i;146// resolve any cycles in moves from and to virtual registers147for (i = virtual_operands().length() - 1; i >= 0; i --) {148ResolveNode* node = virtual_operands()[i];149if (!node->visited()) {150_loop = NULL;151move(NULL, node);152node->set_start_node();153assert(_temp->is_illegal(), "move_temp_to() call missing");154}155}156157// generate move for move from non virtual register to abitrary destination158for (i = other_operands().length() - 1; i >= 0; i --) {159ResolveNode* node = other_operands()[i];160for (int j = node->no_of_destinations() - 1; j >= 0; j --) {161emit_move(node->operand(), node->destination_at(j)->operand());162}163}164}165166167ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) {168ResolveNode* node;169if (opr->is_virtual()) {170int vreg_num = opr->vreg_number();171node = vreg_table().at_grow(vreg_num, NULL);172assert(node == NULL || node->operand() == opr, "");173if (node == NULL) {174node = new ResolveNode(opr);175vreg_table()[vreg_num] = node;176}177// Make sure that all virtual operands show up in the list when178// they are used as the source of a move.179if (source && !virtual_operands().contains(node)) {180virtual_operands().append(node);181}182} else {183assert(source, "");184node = new ResolveNode(opr);185other_operands().append(node);186}187return node;188}189190191void PhiResolver::move(LIR_Opr src, LIR_Opr dest) {192assert(dest->is_virtual(), "");193// tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr();194assert(src->is_valid(), "");195assert(dest->is_valid(), "");196ResolveNode* source = source_node(src);197source->append(destination_node(dest));198}199200201//--------------------------------------------------------------202// LIRItem203204void LIRItem::set_result(LIR_Opr opr) {205assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change");206value()->set_operand(opr);207208if (opr->is_virtual()) {209_gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL);210}211212_result = opr;213}214215void LIRItem::load_item() {216if (result()->is_illegal()) {217// update the items result218_result = value()->operand();219}220if (!result()->is_register()) {221LIR_Opr reg = _gen->new_register(value()->type());222__ move(result(), reg);223if (result()->is_constant()) {224_result = reg;225} else {226set_result(reg);227}228}229}230231232void LIRItem::load_for_store(BasicType type) {233if (_gen->can_store_as_constant(value(), type)) {234_result = value()->operand();235if (!_result->is_constant()) {236_result = LIR_OprFact::value_type(value()->type());237}238} else if (type == T_BYTE || type == T_BOOLEAN) {239load_byte_item();240} else {241load_item();242}243}244245void LIRItem::load_item_force(LIR_Opr reg) {246LIR_Opr r = result();247if (r != reg) {248#if !defined(ARM) && !defined(E500V2)249if (r->type() != reg->type()) {250// moves between different types need an intervening spill slot251r = _gen->force_to_spill(r, reg->type());252}253#endif254__ move(r, reg);255_result = reg;256}257}258259ciObject* LIRItem::get_jobject_constant() const {260ObjectType* oc = type()->as_ObjectType();261if (oc) {262return oc->constant_value();263}264return NULL;265}266267268jint LIRItem::get_jint_constant() const {269assert(is_constant() && value() != NULL, "");270assert(type()->as_IntConstant() != NULL, "type check");271return type()->as_IntConstant()->value();272}273274275jint LIRItem::get_address_constant() const {276assert(is_constant() && value() != NULL, "");277assert(type()->as_AddressConstant() != NULL, "type check");278return type()->as_AddressConstant()->value();279}280281282jfloat LIRItem::get_jfloat_constant() const {283assert(is_constant() && value() != NULL, "");284assert(type()->as_FloatConstant() != NULL, "type check");285return type()->as_FloatConstant()->value();286}287288289jdouble LIRItem::get_jdouble_constant() const {290assert(is_constant() && value() != NULL, "");291assert(type()->as_DoubleConstant() != NULL, "type check");292return type()->as_DoubleConstant()->value();293}294295296jlong LIRItem::get_jlong_constant() const {297assert(is_constant() && value() != NULL, "");298assert(type()->as_LongConstant() != NULL, "type check");299return type()->as_LongConstant()->value();300}301302303304//--------------------------------------------------------------305306307void LIRGenerator::init() {308_bs = Universe::heap()->barrier_set();309}310311312void LIRGenerator::block_do_prolog(BlockBegin* block) {313#ifndef PRODUCT314if (PrintIRWithLIR) {315block->print();316}317#endif318319// set up the list of LIR instructions320assert(block->lir() == NULL, "LIR list already computed for this block");321_lir = new LIR_List(compilation(), block);322block->set_lir(_lir);323324__ branch_destination(block->label());325326if (LIRTraceExecution &&327Compilation::current()->hir()->start()->block_id() != block->block_id() &&328!block->is_set(BlockBegin::exception_entry_flag)) {329assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");330trace_block_entry(block);331}332}333334335void LIRGenerator::block_do_epilog(BlockBegin* block) {336#ifndef PRODUCT337if (PrintIRWithLIR) {338tty->cr();339}340#endif341342// LIR_Opr for unpinned constants shouldn't be referenced by other343// blocks so clear them out after processing the block.344for (int i = 0; i < _unpinned_constants.length(); i++) {345_unpinned_constants.at(i)->clear_operand();346}347_unpinned_constants.trunc_to(0);348349// clear our any registers for other local constants350_constants.trunc_to(0);351_reg_for_constants.trunc_to(0);352}353354355void LIRGenerator::block_do(BlockBegin* block) {356CHECK_BAILOUT();357358block_do_prolog(block);359set_block(block);360361for (Instruction* instr = block; instr != NULL; instr = instr->next()) {362if (instr->is_pinned()) do_root(instr);363}364365set_block(NULL);366block_do_epilog(block);367}368369370//-------------------------LIRGenerator-----------------------------371372// This is where the tree-walk starts; instr must be root;373void LIRGenerator::do_root(Value instr) {374CHECK_BAILOUT();375376InstructionMark im(compilation(), instr);377378assert(instr->is_pinned(), "use only with roots");379assert(instr->subst() == instr, "shouldn't have missed substitution");380381instr->visit(this);382383assert(!instr->has_uses() || instr->operand()->is_valid() ||384instr->as_Constant() != NULL || bailed_out(), "invalid item set");385}386387388// This is called for each node in tree; the walk stops if a root is reached389void LIRGenerator::walk(Value instr) {390InstructionMark im(compilation(), instr);391//stop walk when encounter a root392if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) {393assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited");394} else {395assert(instr->subst() == instr, "shouldn't have missed substitution");396instr->visit(this);397// assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use");398}399}400401402CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {403assert(state != NULL, "state must be defined");404405#ifndef PRODUCT406state->verify();407#endif408409ValueStack* s = state;410for_each_state(s) {411if (s->kind() == ValueStack::EmptyExceptionState) {412assert(s->stack_size() == 0 && s->locals_size() == 0 && (s->locks_size() == 0 || s->locks_size() == 1), "state must be empty");413continue;414}415416int index;417Value value;418for_each_stack_value(s, index, value) {419assert(value->subst() == value, "missed substitution");420if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {421walk(value);422assert(value->operand()->is_valid(), "must be evaluated now");423}424}425426int bci = s->bci();427IRScope* scope = s->scope();428ciMethod* method = scope->method();429430MethodLivenessResult liveness = method->liveness_at_bci(bci);431if (bci == SynchronizationEntryBCI) {432if (x->as_ExceptionObject() || x->as_Throw()) {433// all locals are dead on exit from the synthetic unlocker434liveness.clear();435} else {436assert(x->as_MonitorEnter() || x->as_ProfileInvoke(), "only other cases are MonitorEnter and ProfileInvoke");437}438}439if (!liveness.is_valid()) {440// Degenerate or breakpointed method.441bailout("Degenerate or breakpointed method");442} else {443assert((int)liveness.size() == s->locals_size(), "error in use of liveness");444for_each_local_value(s, index, value) {445assert(value->subst() == value, "missed substition");446if (liveness.at(index) && !value->type()->is_illegal()) {447if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {448walk(value);449assert(value->operand()->is_valid(), "must be evaluated now");450}451} else {452// NULL out this local so that linear scan can assume that all non-NULL values are live.453s->invalidate_local(index);454}455}456}457}458459return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException));460}461462463CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {464return state_for(x, x->exception_state());465}466467468void LIRGenerator::klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve) {469/* C2 relies on constant pool entries being resolved (ciTypeFlow), so if TieredCompilation470* is active and the class hasn't yet been resolved we need to emit a patch that resolves471* the class. */472if ((TieredCompilation && need_resolve) || !obj->is_loaded() || PatchALot) {473assert(info != NULL, "info must be set if class is not loaded");474__ klass2reg_patch(NULL, r, info);475} else {476// no patching needed477__ metadata2reg(obj->constant_encoding(), r);478}479}480481482void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index,483CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) {484CodeStub* stub = new RangeCheckStub(range_check_info, index);485if (index->is_constant()) {486cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(),487index->as_jint(), null_check_info);488__ branch(lir_cond_belowEqual, T_INT, stub); // forward branch489} else {490cmp_reg_mem(lir_cond_aboveEqual, index, array,491arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info);492__ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch493}494}495496497void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {498CodeStub* stub = new RangeCheckStub(info, index, true);499if (index->is_constant()) {500cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info);501__ branch(lir_cond_belowEqual, T_INT, stub); // forward branch502} else {503cmp_reg_mem(lir_cond_aboveEqual, index, buffer,504java_nio_Buffer::limit_offset(), T_INT, info);505__ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch506}507__ move(index, result);508}509510511512void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) {513LIR_Opr result_op = result;514LIR_Opr left_op = left;515LIR_Opr right_op = right;516517if (TwoOperandLIRForm && left_op != result_op) {518assert(right_op != result_op, "malformed");519__ move(left_op, result_op);520left_op = result_op;521}522523switch(code) {524case Bytecodes::_dadd:525case Bytecodes::_fadd:526case Bytecodes::_ladd:527case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break;528case Bytecodes::_fmul:529case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break;530531case Bytecodes::_dmul:532{533if (is_strictfp) {534__ mul_strictfp(left_op, right_op, result_op, tmp_op); break;535} else {536__ mul(left_op, right_op, result_op); break;537}538}539break;540541case Bytecodes::_imul:542{543bool did_strength_reduce = false;544545if (right->is_constant()) {546jint c = right->as_jint();547if (c > 0 && is_power_of_2(c)) {548// do not need tmp here549__ shift_left(left_op, exact_log2(c), result_op);550did_strength_reduce = true;551} else {552did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);553}554}555// we couldn't strength reduce so just emit the multiply556if (!did_strength_reduce) {557__ mul(left_op, right_op, result_op);558}559}560break;561562case Bytecodes::_dsub:563case Bytecodes::_fsub:564case Bytecodes::_lsub:565case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break;566567case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break;568// ldiv and lrem are implemented with a direct runtime call569570case Bytecodes::_ddiv:571{572if (is_strictfp) {573__ div_strictfp (left_op, right_op, result_op, tmp_op); break;574} else {575__ div (left_op, right_op, result_op); break;576}577}578break;579580case Bytecodes::_drem:581case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break;582583default: ShouldNotReachHere();584}585}586587588void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) {589arithmetic_op(code, result, left, right, false, tmp);590}591592593void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) {594arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info);595}596597598void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp) {599arithmetic_op(code, result, left, right, is_strictfp, tmp);600}601602603void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) {604if (TwoOperandLIRForm && value != result_op) {605assert(count != result_op, "malformed");606__ move(value, result_op);607value = result_op;608}609610assert(count->is_constant() || count->is_register(), "must be");611switch(code) {612case Bytecodes::_ishl:613case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break;614case Bytecodes::_ishr:615case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break;616case Bytecodes::_iushr:617case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break;618default: ShouldNotReachHere();619}620}621622623void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) {624if (TwoOperandLIRForm && left_op != result_op) {625assert(right_op != result_op, "malformed");626__ move(left_op, result_op);627left_op = result_op;628}629630switch(code) {631case Bytecodes::_iand:632case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break;633634case Bytecodes::_ior:635case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break;636637case Bytecodes::_ixor:638case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break;639640default: ShouldNotReachHere();641}642}643644645void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) {646if (!GenerateSynchronizationCode) return;647// for slow path, use debug info for state after successful locking648CodeStub* slow_path = new MonitorEnterStub(object, lock, info);649__ load_stack_address_monitor(monitor_no, lock);650// for handling NullPointerException, use debug info representing just the lock stack before this monitorenter651__ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception);652}653654655void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) {656if (!GenerateSynchronizationCode) return;657// setup registers658LIR_Opr hdr = lock;659lock = new_hdr;660CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no);661__ load_stack_address_monitor(monitor_no, lock);662__ unlock_object(hdr, object, lock, scratch, slow_path);663}664665#ifndef PRODUCT666void LIRGenerator::print_if_not_loaded(const NewInstance* new_instance) {667if (PrintNotLoaded && !new_instance->klass()->is_loaded()) {668tty->print_cr(" ###class not loaded at new bci %d", new_instance->printable_bci());669} else if (PrintNotLoaded && (TieredCompilation && new_instance->is_unresolved())) {670tty->print_cr(" ###class not resolved at new bci %d", new_instance->printable_bci());671}672}673#endif674675void 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) {676klass2reg_with_patching(klass_reg, klass, info, is_unresolved);677// If klass is not loaded we do not know if the klass has finalizers:678if (UseFastNewInstance && klass->is_loaded()679&& !Klass::layout_helper_needs_slow_path(klass->layout_helper())) {680681Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id;682683CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id);684685assert(klass->is_loaded(), "must be loaded");686// allocate space for instance687assert(klass->size_helper() >= 0, "illegal instance size");688const int instance_size = align_object_size(klass->size_helper());689__ allocate_object(dst, scratch1, scratch2, scratch3, scratch4,690oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);691} else {692CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id);693__ branch(lir_cond_always, T_ILLEGAL, slow_path);694__ branch_destination(slow_path->continuation());695}696}697698699static bool is_constant_zero(Instruction* inst) {700IntConstant* c = inst->type()->as_IntConstant();701if (c) {702return (c->value() == 0);703}704return false;705}706707708static bool positive_constant(Instruction* inst) {709IntConstant* c = inst->type()->as_IntConstant();710if (c) {711return (c->value() >= 0);712}713return false;714}715716717static ciArrayKlass* as_array_klass(ciType* type) {718if (type != NULL && type->is_array_klass() && type->is_loaded()) {719return (ciArrayKlass*)type;720} else {721return NULL;722}723}724725static ciType* phi_declared_type(Phi* phi) {726ciType* t = phi->operand_at(0)->declared_type();727if (t == NULL) {728return NULL;729}730for(int i = 1; i < phi->operand_count(); i++) {731if (t != phi->operand_at(i)->declared_type()) {732return NULL;733}734}735return t;736}737738void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) {739Instruction* src = x->argument_at(0);740Instruction* src_pos = x->argument_at(1);741Instruction* dst = x->argument_at(2);742Instruction* dst_pos = x->argument_at(3);743Instruction* length = x->argument_at(4);744745// first try to identify the likely type of the arrays involved746ciArrayKlass* expected_type = NULL;747bool is_exact = false, src_objarray = false, dst_objarray = false;748{749ciArrayKlass* src_exact_type = as_array_klass(src->exact_type());750ciArrayKlass* src_declared_type = as_array_klass(src->declared_type());751Phi* phi;752if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) {753src_declared_type = as_array_klass(phi_declared_type(phi));754}755ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type());756ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type());757if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) {758dst_declared_type = as_array_klass(phi_declared_type(phi));759}760761if (src_exact_type != NULL && src_exact_type == dst_exact_type) {762// the types exactly match so the type is fully known763is_exact = true;764expected_type = src_exact_type;765} else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) {766ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type;767ciArrayKlass* src_type = NULL;768if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) {769src_type = (ciArrayKlass*) src_exact_type;770} else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) {771src_type = (ciArrayKlass*) src_declared_type;772}773if (src_type != NULL) {774if (src_type->element_type()->is_subtype_of(dst_type->element_type())) {775is_exact = true;776expected_type = dst_type;777}778}779}780// at least pass along a good guess781if (expected_type == NULL) expected_type = dst_exact_type;782if (expected_type == NULL) expected_type = src_declared_type;783if (expected_type == NULL) expected_type = dst_declared_type;784785src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass());786dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass());787}788789// if a probable array type has been identified, figure out if any790// of the required checks for a fast case can be elided.791int flags = LIR_OpArrayCopy::all_flags;792793if (!src_objarray)794flags &= ~LIR_OpArrayCopy::src_objarray;795if (!dst_objarray)796flags &= ~LIR_OpArrayCopy::dst_objarray;797798if (!x->arg_needs_null_check(0))799flags &= ~LIR_OpArrayCopy::src_null_check;800if (!x->arg_needs_null_check(2))801flags &= ~LIR_OpArrayCopy::dst_null_check;802803804if (expected_type != NULL) {805Value length_limit = NULL;806807IfOp* ifop = length->as_IfOp();808if (ifop != NULL) {809// look for expressions like min(v, a.length) which ends up as810// x > y ? y : x or x >= y ? y : x811if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) &&812ifop->x() == ifop->fval() &&813ifop->y() == ifop->tval()) {814length_limit = ifop->y();815}816}817818// try to skip null checks and range checks819NewArray* src_array = src->as_NewArray();820if (src_array != NULL) {821flags &= ~LIR_OpArrayCopy::src_null_check;822if (length_limit != NULL &&823src_array->length() == length_limit &&824is_constant_zero(src_pos)) {825flags &= ~LIR_OpArrayCopy::src_range_check;826}827}828829NewArray* dst_array = dst->as_NewArray();830if (dst_array != NULL) {831flags &= ~LIR_OpArrayCopy::dst_null_check;832if (length_limit != NULL &&833dst_array->length() == length_limit &&834is_constant_zero(dst_pos)) {835flags &= ~LIR_OpArrayCopy::dst_range_check;836}837}838839// check from incoming constant values840if (positive_constant(src_pos))841flags &= ~LIR_OpArrayCopy::src_pos_positive_check;842if (positive_constant(dst_pos))843flags &= ~LIR_OpArrayCopy::dst_pos_positive_check;844if (positive_constant(length))845flags &= ~LIR_OpArrayCopy::length_positive_check;846847// see if the range check can be elided, which might also imply848// that src or dst is non-null.849ArrayLength* al = length->as_ArrayLength();850if (al != NULL) {851if (al->array() == src) {852// it's the length of the source array853flags &= ~LIR_OpArrayCopy::length_positive_check;854flags &= ~LIR_OpArrayCopy::src_null_check;855if (is_constant_zero(src_pos))856flags &= ~LIR_OpArrayCopy::src_range_check;857}858if (al->array() == dst) {859// it's the length of the destination array860flags &= ~LIR_OpArrayCopy::length_positive_check;861flags &= ~LIR_OpArrayCopy::dst_null_check;862if (is_constant_zero(dst_pos))863flags &= ~LIR_OpArrayCopy::dst_range_check;864}865}866if (is_exact) {867flags &= ~LIR_OpArrayCopy::type_check;868}869}870871IntConstant* src_int = src_pos->type()->as_IntConstant();872IntConstant* dst_int = dst_pos->type()->as_IntConstant();873if (src_int && dst_int) {874int s_offs = src_int->value();875int d_offs = dst_int->value();876if (src_int->value() >= dst_int->value()) {877flags &= ~LIR_OpArrayCopy::overlapping;878}879if (expected_type != NULL) {880BasicType t = expected_type->element_type()->basic_type();881int element_size = type2aelembytes(t);882if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&883((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) {884flags &= ~LIR_OpArrayCopy::unaligned;885}886}887} else if (src_pos == dst_pos || is_constant_zero(dst_pos)) {888// src and dest positions are the same, or dst is zero so assume889// nonoverlapping copy.890flags &= ~LIR_OpArrayCopy::overlapping;891}892893if (src == dst) {894// moving within a single array so no type checks are needed895if (flags & LIR_OpArrayCopy::type_check) {896flags &= ~LIR_OpArrayCopy::type_check;897}898}899*flagsp = flags;900*expected_typep = (ciArrayKlass*)expected_type;901}902903904LIR_Opr LIRGenerator::round_item(LIR_Opr opr) {905assert(opr->is_register(), "why spill if item is not register?");906907if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) {908LIR_Opr result = new_register(T_FLOAT);909set_vreg_flag(result, must_start_in_memory);910assert(opr->is_register(), "only a register can be spilled");911assert(opr->value_type()->is_float(), "rounding only for floats available");912__ roundfp(opr, LIR_OprFact::illegalOpr, result);913return result;914}915return opr;916}917918919LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) {920assert(type2size[t] == type2size[value->type()],921err_msg_res("size mismatch: t=%s, value->type()=%s", type2name(t), type2name(value->type())));922if (!value->is_register()) {923// force into a register924LIR_Opr r = new_register(value->type());925__ move(value, r);926value = r;927}928929// create a spill location930LIR_Opr tmp = new_register(t);931set_vreg_flag(tmp, LIRGenerator::must_start_in_memory);932933// move from register to spill934__ move(value, tmp);935return tmp;936}937938void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) {939if (if_instr->should_profile()) {940ciMethod* method = if_instr->profiled_method();941assert(method != NULL, "method should be set if branch is profiled");942ciMethodData* md = method->method_data_or_null();943assert(md != NULL, "Sanity");944ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());945assert(data != NULL, "must have profiling data");946assert(data->is_BranchData(), "need BranchData for two-way branches");947int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset());948int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());949if (if_instr->is_swapped()) {950int t = taken_count_offset;951taken_count_offset = not_taken_count_offset;952not_taken_count_offset = t;953}954955LIR_Opr md_reg = new_register(T_METADATA);956__ metadata2reg(md->constant_encoding(), md_reg);957958LIR_Opr data_offset_reg = new_pointer_register();959__ cmove(lir_cond(cond),960LIR_OprFact::intptrConst(taken_count_offset),961LIR_OprFact::intptrConst(not_taken_count_offset),962data_offset_reg, as_BasicType(if_instr->x()->type()));963964// MDO cells are intptr_t, so the data_reg width is arch-dependent.965LIR_Opr data_reg = new_pointer_register();966LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());967__ move(data_addr, data_reg);968// Use leal instead of add to avoid destroying condition codes on x86969LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);970__ leal(LIR_OprFact::address(fake_incr_value), data_reg);971__ move(data_reg, data_addr);972}973}974975// Phi technique:976// This is about passing live values from one basic block to the other.977// In code generated with Java it is rather rare that more than one978// value is on the stack from one basic block to the other.979// We optimize our technique for efficient passing of one value980// (of type long, int, double..) but it can be extended.981// When entering or leaving a basic block, all registers and all spill982// slots are release and empty. We use the released registers983// and spill slots to pass the live values from one block984// to the other. The topmost value, i.e., the value on TOS of expression985// stack is passed in registers. All other values are stored in spilling986// area. Every Phi has an index which designates its spill slot987// At exit of a basic block, we fill the register(s) and spill slots.988// At entry of a basic block, the block_prolog sets up the content of phi nodes989// and locks necessary registers and spilling slots.990991992// move current value to referenced phi function993void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) {994Phi* phi = sux_val->as_Phi();995// cur_val can be null without phi being null in conjunction with inlining996if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) {997LIR_Opr operand = cur_val->operand();998if (cur_val->operand()->is_illegal()) {999assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL,1000"these can be produced lazily");1001operand = operand_for_instruction(cur_val);1002}1003resolver->move(operand, operand_for_instruction(phi));1004}1005}100610071008// Moves all stack values into their PHI position1009void LIRGenerator::move_to_phi(ValueStack* cur_state) {1010BlockBegin* bb = block();1011if (bb->number_of_sux() == 1) {1012BlockBegin* sux = bb->sux_at(0);1013assert(sux->number_of_preds() > 0, "invalid CFG");10141015// a block with only one predecessor never has phi functions1016if (sux->number_of_preds() > 1) {1017int max_phis = cur_state->stack_size() + cur_state->locals_size();1018PhiResolver resolver(this, _virtual_register_number + max_phis * 2);10191020ValueStack* sux_state = sux->state();1021Value sux_value;1022int index;10231024assert(cur_state->scope() == sux_state->scope(), "not matching");1025assert(cur_state->locals_size() == sux_state->locals_size(), "not matching");1026assert(cur_state->stack_size() == sux_state->stack_size(), "not matching");10271028for_each_stack_value(sux_state, index, sux_value) {1029move_to_phi(&resolver, cur_state->stack_at(index), sux_value);1030}10311032for_each_local_value(sux_state, index, sux_value) {1033move_to_phi(&resolver, cur_state->local_at(index), sux_value);1034}10351036assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal");1037}1038}1039}104010411042LIR_Opr LIRGenerator::new_register(BasicType type) {1043int vreg = _virtual_register_number;1044// add a little fudge factor for the bailout, since the bailout is1045// only checked periodically. This gives a few extra registers to1046// hand out before we really run out, which helps us keep from1047// tripping over assertions.1048if (vreg + 20 >= LIR_OprDesc::vreg_max) {1049bailout("out of virtual registers");1050if (vreg + 2 >= LIR_OprDesc::vreg_max) {1051// wrap it around1052_virtual_register_number = LIR_OprDesc::vreg_base;1053}1054}1055_virtual_register_number += 1;1056return LIR_OprFact::virtual_register(vreg, type);1057}105810591060// Try to lock using register in hint1061LIR_Opr LIRGenerator::rlock(Value instr) {1062return new_register(instr->type());1063}106410651066// does an rlock and sets result1067LIR_Opr LIRGenerator::rlock_result(Value x) {1068LIR_Opr reg = rlock(x);1069set_result(x, reg);1070return reg;1071}107210731074// does an rlock and sets result1075LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) {1076LIR_Opr reg;1077switch (type) {1078case T_BYTE:1079case T_BOOLEAN:1080reg = rlock_byte(type);1081break;1082default:1083reg = rlock(x);1084break;1085}10861087set_result(x, reg);1088return reg;1089}109010911092//---------------------------------------------------------------------1093ciObject* LIRGenerator::get_jobject_constant(Value value) {1094ObjectType* oc = value->type()->as_ObjectType();1095if (oc) {1096return oc->constant_value();1097}1098return NULL;1099}110011011102void LIRGenerator::do_ExceptionObject(ExceptionObject* x) {1103assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block");1104assert(block()->next() == x, "ExceptionObject must be first instruction of block");11051106// no moves are created for phi functions at the begin of exception1107// handlers, so assign operands manually here1108for_each_phi_fun(block(), phi,1109operand_for_instruction(phi));11101111LIR_Opr thread_reg = getThreadPointer();1112__ move_wide(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT),1113exceptionOopOpr());1114__ move_wide(LIR_OprFact::oopConst(NULL),1115new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT));1116__ move_wide(LIR_OprFact::oopConst(NULL),1117new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT));11181119LIR_Opr result = new_register(T_OBJECT);1120__ move(exceptionOopOpr(), result);1121set_result(x, result);1122}112311241125//----------------------------------------------------------------------1126//----------------------------------------------------------------------1127//----------------------------------------------------------------------1128//----------------------------------------------------------------------1129// visitor functions1130//----------------------------------------------------------------------1131//----------------------------------------------------------------------1132//----------------------------------------------------------------------1133//----------------------------------------------------------------------11341135void LIRGenerator::do_Phi(Phi* x) {1136// phi functions are never visited directly1137ShouldNotReachHere();1138}113911401141// Code for a constant is generated lazily unless the constant is frequently used and can't be inlined.1142void LIRGenerator::do_Constant(Constant* x) {1143if (x->state_before() != NULL) {1144// Any constant with a ValueStack requires patching so emit the patch here1145LIR_Opr reg = rlock_result(x);1146CodeEmitInfo* info = state_for(x, x->state_before());1147__ oop2reg_patch(NULL, reg, info);1148} else if (x->use_count() > 1 && !can_inline_as_constant(x)) {1149if (!x->is_pinned()) {1150// unpinned constants are handled specially so that they can be1151// put into registers when they are used multiple times within a1152// block. After the block completes their operand will be1153// cleared so that other blocks can't refer to that register.1154set_result(x, load_constant(x));1155} else {1156LIR_Opr res = x->operand();1157if (!res->is_valid()) {1158res = LIR_OprFact::value_type(x->type());1159}1160if (res->is_constant()) {1161LIR_Opr reg = rlock_result(x);1162__ move(res, reg);1163} else {1164set_result(x, res);1165}1166}1167} else {1168set_result(x, LIR_OprFact::value_type(x->type()));1169}1170}117111721173void LIRGenerator::do_Local(Local* x) {1174// operand_for_instruction has the side effect of setting the result1175// so there's no need to do it here.1176operand_for_instruction(x);1177}117811791180void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) {1181Unimplemented();1182}118311841185void LIRGenerator::do_Return(Return* x) {1186if (compilation()->env()->dtrace_method_probes()) {1187BasicTypeList signature;1188signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread1189signature.append(T_METADATA); // Method*1190LIR_OprList* args = new LIR_OprList();1191args->append(getThreadPointer());1192LIR_Opr meth = new_register(T_METADATA);1193__ metadata2reg(method()->constant_encoding(), meth);1194args->append(meth);1195call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);1196}11971198if (x->type()->is_void()) {1199__ return_op(LIR_OprFact::illegalOpr);1200} else {1201#ifdef AARCH321202LIR_Opr reg = java_result_register_for(x->type(), /*callee=*/true);1203#else1204LIR_Opr reg = result_register_for(x->type(), /*callee=*/true);1205#endif1206LIRItem result(x->result(), this);12071208result.load_item_force(reg);1209__ return_op(result.result());1210}1211set_no_result(x);1212}12131214// Examble: ref.get()1215// Combination of LoadField and g1 pre-write barrier1216void LIRGenerator::do_Reference_get(Intrinsic* x) {12171218const int referent_offset = java_lang_ref_Reference::referent_offset;1219guarantee(referent_offset > 0, "referent offset not initialized");12201221assert(x->number_of_arguments() == 1, "wrong type");12221223LIRItem reference(x->argument_at(0), this);1224reference.load_item();12251226// need to perform the null check on the reference objecy1227CodeEmitInfo* info = NULL;1228if (x->needs_null_check()) {1229info = state_for(x);1230}12311232LIR_Address* referent_field_adr =1233new LIR_Address(reference.result(), referent_offset, T_OBJECT);12341235LIR_Opr result = rlock_result(x);12361237#if INCLUDE_ALL_GCS1238if (UseShenandoahGC) {1239LIR_Opr tmp = new_register(T_OBJECT);1240LIR_Opr addr = ShenandoahBarrierSet::barrier_set()->bsc1()->resolve_address(this, referent_field_adr, T_OBJECT, NULL);1241__ load(addr->as_address_ptr(), tmp, info);1242tmp = ShenandoahBarrierSet::barrier_set()->bsc1()->load_reference_barrier(this, tmp, addr);1243__ move(tmp, result);1244} else1245#endif1246__ load(referent_field_adr, result, info);12471248// Register the value in the referent field with the pre-barrier1249pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,1250result /* pre_val */,1251false /* do_load */,1252false /* patch */,1253NULL /* info */);1254}12551256// Example: clazz.isInstance(object)1257void LIRGenerator::do_isInstance(Intrinsic* x) {1258assert(x->number_of_arguments() == 2, "wrong type");12591260// TODO could try to substitute this node with an equivalent InstanceOf1261// if clazz is known to be a constant Class. This will pick up newly found1262// constants after HIR construction. I'll leave this to a future change.12631264// as a first cut, make a simple leaf call to runtime to stay platform independent.1265// could follow the aastore example in a future change.12661267LIRItem clazz(x->argument_at(0), this);1268LIRItem object(x->argument_at(1), this);1269clazz.load_item();1270object.load_item();1271LIR_Opr result = rlock_result(x);12721273// need to perform null check on clazz1274if (x->needs_null_check()) {1275CodeEmitInfo* info = state_for(x);1276__ null_check(clazz.result(), info);1277}12781279LIR_Opr call_result = call_runtime(clazz.value(), object.value(),1280CAST_FROM_FN_PTR(address, Runtime1::is_instance_of),1281x->type(),1282NULL); // NULL CodeEmitInfo results in a leaf call1283__ move(call_result, result);1284}12851286// Example: object.getClass ()1287void LIRGenerator::do_getClass(Intrinsic* x) {1288assert(x->number_of_arguments() == 1, "wrong type");12891290LIRItem rcvr(x->argument_at(0), this);1291rcvr.load_item();1292LIR_Opr temp = new_register(T_METADATA);1293LIR_Opr result = rlock_result(x);12941295// need to perform the null check on the rcvr1296CodeEmitInfo* info = NULL;1297if (x->needs_null_check()) {1298info = state_for(x);1299}13001301// FIXME T_ADDRESS should actually be T_METADATA but it can't because the1302// meaning of these two is mixed up (see JDK-8026837).1303__ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), temp, info);1304__ move_wide(new LIR_Address(temp, in_bytes(Klass::java_mirror_offset()), T_OBJECT), result);1305}130613071308// Example: Thread.currentThread()1309void LIRGenerator::do_currentThread(Intrinsic* x) {1310assert(x->number_of_arguments() == 0, "wrong type");1311LIR_Opr reg = rlock_result(x);1312__ move_wide(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg);1313}131413151316void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) {1317assert(x->number_of_arguments() == 1, "wrong type");1318LIRItem receiver(x->argument_at(0), this);13191320receiver.load_item();1321BasicTypeList signature;1322signature.append(T_OBJECT); // receiver1323LIR_OprList* args = new LIR_OprList();1324args->append(receiver.result());1325CodeEmitInfo* info = state_for(x, x->state());1326call_runtime(&signature, args,1327CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)),1328voidType, info);13291330set_no_result(x);1331}133213331334//------------------------local access--------------------------------------13351336LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) {1337if (x->operand()->is_illegal()) {1338Constant* c = x->as_Constant();1339if (c != NULL) {1340x->set_operand(LIR_OprFact::value_type(c->type()));1341} else {1342assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local");1343// allocate a virtual register for this local or phi1344x->set_operand(rlock(x));1345_instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL);1346}1347}1348return x->operand();1349}135013511352Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) {1353if (opr->is_virtual()) {1354return instruction_for_vreg(opr->vreg_number());1355}1356return NULL;1357}135813591360Instruction* LIRGenerator::instruction_for_vreg(int reg_num) {1361if (reg_num < _instruction_for_operand.length()) {1362return _instruction_for_operand.at(reg_num);1363}1364return NULL;1365}136613671368void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) {1369if (_vreg_flags.size_in_bits() == 0) {1370BitMap2D temp(100, num_vreg_flags);1371temp.clear();1372_vreg_flags = temp;1373}1374_vreg_flags.at_put_grow(vreg_num, f, true);1375}13761377bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) {1378if (!_vreg_flags.is_valid_index(vreg_num, f)) {1379return false;1380}1381return _vreg_flags.at(vreg_num, f);1382}138313841385// Block local constant handling. This code is useful for keeping1386// unpinned constants and constants which aren't exposed in the IR in1387// registers. Unpinned Constant instructions have their operands1388// cleared when the block is finished so that other blocks can't end1389// up referring to their registers.13901391LIR_Opr LIRGenerator::load_constant(Constant* x) {1392assert(!x->is_pinned(), "only for unpinned constants");1393_unpinned_constants.append(x);1394return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr());1395}139613971398LIR_Opr LIRGenerator::load_constant(LIR_Const* c) {1399BasicType t = c->type();1400for (int i = 0; i < _constants.length(); i++) {1401LIR_Const* other = _constants.at(i);1402if (t == other->type()) {1403switch (t) {1404case T_INT:1405case T_FLOAT:1406if (c->as_jint_bits() != other->as_jint_bits()) continue;1407break;1408case T_LONG:1409case T_DOUBLE:1410if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;1411if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;1412break;1413case T_OBJECT:1414if (c->as_jobject() != other->as_jobject()) continue;1415break;1416}1417return _reg_for_constants.at(i);1418}1419}14201421LIR_Opr result = new_register(t);1422__ move((LIR_Opr)c, result);1423_constants.append(c);1424_reg_for_constants.append(result);1425return result;1426}14271428// Various barriers14291430void LIRGenerator::pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,1431bool do_load, bool patch, CodeEmitInfo* info) {1432// Do the pre-write barrier, if any.1433switch (_bs->kind()) {1434#if INCLUDE_ALL_GCS1435case BarrierSet::G1SATBCT:1436case BarrierSet::G1SATBCTLogging:1437G1SATBCardTableModRef_pre_barrier(addr_opr, pre_val, do_load, patch, info);1438break;1439case BarrierSet::ShenandoahBarrierSet:1440if (ShenandoahSATBBarrier) {1441G1SATBCardTableModRef_pre_barrier(addr_opr, pre_val, do_load, patch, info);1442}1443break;1444#endif // INCLUDE_ALL_GCS1445case BarrierSet::CardTableModRef:1446case BarrierSet::CardTableExtension:1447// No pre barriers1448break;1449case BarrierSet::ModRef:1450case BarrierSet::Other:1451// No pre barriers1452break;1453default :1454ShouldNotReachHere();14551456}1457}14581459void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {1460switch (_bs->kind()) {1461#if INCLUDE_ALL_GCS1462case BarrierSet::G1SATBCT:1463case BarrierSet::G1SATBCTLogging:1464G1SATBCardTableModRef_post_barrier(addr, new_val);1465break;1466case BarrierSet::ShenandoahBarrierSet:1467ShenandoahBarrierSetC1::bsc1()->storeval_barrier(this, new_val, NULL, false);1468break;1469#endif // INCLUDE_ALL_GCS1470case BarrierSet::CardTableModRef:1471case BarrierSet::CardTableExtension:1472CardTableModRef_post_barrier(addr, new_val);1473break;1474case BarrierSet::ModRef:1475case BarrierSet::Other:1476// No post barriers1477break;1478default :1479ShouldNotReachHere();1480}1481}14821483////////////////////////////////////////////////////////////////////////1484#if INCLUDE_ALL_GCS14851486void LIRGenerator::G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,1487bool do_load, bool patch, CodeEmitInfo* info) {1488// First we test whether marking is in progress.1489BasicType flag_type;1490if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {1491flag_type = T_INT;1492} else {1493guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1,1494"Assumption");1495flag_type = T_BYTE;1496}1497LIR_Opr thrd = getThreadPointer();1498LIR_Address* mark_active_flag_addr =1499new LIR_Address(thrd,1500in_bytes(JavaThread::satb_mark_queue_offset() +1501PtrQueue::byte_offset_of_active()),1502flag_type);1503// Read the marking-in-progress flag.1504LIR_Opr flag_val = new_register(T_INT);1505__ load(mark_active_flag_addr, flag_val);1506__ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0));15071508LIR_PatchCode pre_val_patch_code = lir_patch_none;15091510CodeStub* slow;15111512if (do_load) {1513assert(pre_val == LIR_OprFact::illegalOpr, "sanity");1514assert(addr_opr != LIR_OprFact::illegalOpr, "sanity");15151516if (patch)1517pre_val_patch_code = lir_patch_normal;15181519pre_val = new_register(T_OBJECT);15201521if (!addr_opr->is_address()) {1522assert(addr_opr->is_register(), "must be");1523addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, T_OBJECT));1524}1525slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code, info);1526} else {1527assert(addr_opr == LIR_OprFact::illegalOpr, "sanity");1528assert(pre_val->is_register(), "must be");1529assert(pre_val->type() == T_OBJECT, "must be an object");1530assert(info == NULL, "sanity");15311532slow = new G1PreBarrierStub(pre_val);1533}15341535__ branch(lir_cond_notEqual, T_INT, slow);1536__ branch_destination(slow->continuation());1537}15381539void LIRGenerator::G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {1540// If the "new_val" is a constant NULL, no barrier is necessary.1541if (new_val->is_constant() &&1542new_val->as_constant_ptr()->as_jobject() == NULL) return;15431544if (!new_val->is_register()) {1545LIR_Opr new_val_reg = new_register(T_OBJECT);1546if (new_val->is_constant()) {1547__ move(new_val, new_val_reg);1548} else {1549__ leal(new_val, new_val_reg);1550}1551new_val = new_val_reg;1552}1553assert(new_val->is_register(), "must be a register at this point");15541555if (addr->is_address()) {1556LIR_Address* address = addr->as_address_ptr();1557LIR_Opr ptr = new_pointer_register();1558if (!address->index()->is_valid() && address->disp() == 0) {1559__ move(address->base(), ptr);1560} else {1561assert(address->disp() != max_jint, "lea doesn't support patched addresses!");1562__ leal(addr, ptr);1563}1564addr = ptr;1565}1566assert(addr->is_register(), "must be a register at this point");15671568LIR_Opr xor_res = new_pointer_register();1569LIR_Opr xor_shift_res = new_pointer_register();1570if (TwoOperandLIRForm ) {1571__ move(addr, xor_res);1572__ logical_xor(xor_res, new_val, xor_res);1573__ move(xor_res, xor_shift_res);1574__ unsigned_shift_right(xor_shift_res,1575LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),1576xor_shift_res,1577LIR_OprDesc::illegalOpr());1578} else {1579__ logical_xor(addr, new_val, xor_res);1580__ unsigned_shift_right(xor_res,1581LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),1582xor_shift_res,1583LIR_OprDesc::illegalOpr());1584}15851586if (!new_val->is_register()) {1587LIR_Opr new_val_reg = new_register(T_OBJECT);1588__ leal(new_val, new_val_reg);1589new_val = new_val_reg;1590}1591assert(new_val->is_register(), "must be a register at this point");15921593__ cmp(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst(NULL_WORD));15941595CodeStub* slow = new G1PostBarrierStub(addr, new_val);1596__ branch(lir_cond_notEqual, LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow);1597__ branch_destination(slow->continuation());1598}15991600#endif // INCLUDE_ALL_GCS1601////////////////////////////////////////////////////////////////////////16021603void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {16041605assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code");1606LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base);1607if (addr->is_address()) {1608LIR_Address* address = addr->as_address_ptr();1609// ptr cannot be an object because we use this barrier for array card marks1610// and addr can point in the middle of an array.1611LIR_Opr ptr = new_pointer_register();1612if (!address->index()->is_valid() && address->disp() == 0) {1613__ move(address->base(), ptr);1614} else {1615assert(address->disp() != max_jint, "lea doesn't support patched addresses!");1616__ leal(addr, ptr);1617}1618addr = ptr;1619}1620assert(addr->is_register(), "must be a register at this point");16211622#ifdef CARDTABLEMODREF_POST_BARRIER_HELPER1623CardTableModRef_post_barrier_helper(addr, card_table_base);1624#else1625LIR_Opr tmp = new_pointer_register();1626if (TwoOperandLIRForm) {1627__ move(addr, tmp);1628__ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp);1629} else {1630__ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp);1631}16321633if (UseConcMarkSweepGC && CMSPrecleaningEnabled) {1634__ membar_storestore();1635}16361637if (can_inline_as_constant(card_table_base)) {1638__ move(LIR_OprFact::intConst(0),1639new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE));1640} else {1641__ move(LIR_OprFact::intConst(0),1642new LIR_Address(tmp, load_constant(card_table_base),1643T_BYTE));1644}1645#endif1646}164716481649//------------------------field access--------------------------------------16501651// Comment copied form templateTable_i486.cpp1652// ----------------------------------------------------------------------------1653// Volatile variables demand their effects be made known to all CPU's in1654// order. Store buffers on most chips allow reads & writes to reorder; the1655// JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of1656// memory barrier (i.e., it's not sufficient that the interpreter does not1657// reorder volatile references, the hardware also must not reorder them).1658//1659// According to the new Java Memory Model (JMM):1660// (1) All volatiles are serialized wrt to each other.1661// ALSO reads & writes act as aquire & release, so:1662// (2) A read cannot let unrelated NON-volatile memory refs that happen after1663// the read float up to before the read. It's OK for non-volatile memory refs1664// that happen before the volatile read to float down below it.1665// (3) Similar a volatile write cannot let unrelated NON-volatile memory refs1666// that happen BEFORE the write float down to after the write. It's OK for1667// non-volatile memory refs that happen after the volatile write to float up1668// before it.1669//1670// We only put in barriers around volatile refs (they are expensive), not1671// _between_ memory refs (that would require us to track the flavor of the1672// previous memory refs). Requirements (2) and (3) require some barriers1673// before volatile stores and after volatile loads. These nearly cover1674// requirement (1) but miss the volatile-store-volatile-load case. This final1675// case is placed after volatile-stores although it could just as well go1676// before volatile-loads.167716781679void LIRGenerator::do_StoreField(StoreField* x) {1680bool needs_patching = x->needs_patching();1681bool is_volatile = x->field()->is_volatile();1682BasicType field_type = x->field_type();1683bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT);16841685CodeEmitInfo* info = NULL;1686if (needs_patching) {1687assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");1688info = state_for(x, x->state_before());1689} else if (x->needs_null_check()) {1690NullCheck* nc = x->explicit_null_check();1691if (nc == NULL) {1692info = state_for(x);1693} else {1694info = state_for(nc);1695}1696}169716981699LIRItem object(x->obj(), this);1700LIRItem value(x->value(), this);17011702object.load_item();17031704if (is_volatile || needs_patching) {1705// load item if field is volatile (fewer special cases for volatiles)1706// load item if field not initialized1707// load item if field not constant1708// because of code patching we cannot inline constants1709if (field_type == T_BYTE || field_type == T_BOOLEAN) {1710value.load_byte_item();1711} else {1712value.load_item();1713}1714} else {1715value.load_for_store(field_type);1716}17171718set_no_result(x);17191720#ifndef PRODUCT1721if (PrintNotLoaded && needs_patching) {1722tty->print_cr(" ###class not loaded at store_%s bci %d",1723x->is_static() ? "static" : "field", x->printable_bci());1724}1725#endif17261727if (x->needs_null_check() &&1728(needs_patching ||1729MacroAssembler::needs_explicit_null_check(x->offset()))) {1730// Emit an explicit null check because the offset is too large.1731// If the class is not loaded and the object is NULL, we need to deoptimize to throw a1732// NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.1733__ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);1734}17351736LIR_Address* address;1737if (needs_patching) {1738// we need to patch the offset in the instruction so don't allow1739// generate_address to try to be smart about emitting the -1.1740// Otherwise the patching code won't know how to find the1741// instruction to patch.1742address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);1743} else {1744address = generate_address(object.result(), x->offset(), field_type);1745}17461747if (is_volatile && os::is_MP()) {1748__ membar_release();1749}17501751if (is_oop) {1752// Do the pre-write barrier, if any.1753pre_barrier(LIR_OprFact::address(address),1754LIR_OprFact::illegalOpr /* pre_val */,1755true /* do_load*/,1756needs_patching,1757(info ? new CodeEmitInfo(info) : NULL));1758}17591760if (is_volatile && !needs_patching) {1761volatile_field_store(value.result(), address, info);1762} else {1763LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;1764__ store(value.result(), address, info, patch_code);1765}17661767if (is_oop) {1768// Store to object so mark the card of the header1769post_barrier(object.result(), value.result());1770}17711772if (is_volatile && os::is_MP()) {1773__ membar();1774}1775}177617771778void LIRGenerator::do_LoadField(LoadField* x) {1779bool needs_patching = x->needs_patching();1780bool is_volatile = x->field()->is_volatile();1781BasicType field_type = x->field_type();17821783CodeEmitInfo* info = NULL;1784if (needs_patching) {1785assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");1786info = state_for(x, x->state_before());1787} else if (x->needs_null_check()) {1788NullCheck* nc = x->explicit_null_check();1789if (nc == NULL) {1790info = state_for(x);1791} else {1792info = state_for(nc);1793}1794}17951796LIRItem object(x->obj(), this);17971798object.load_item();17991800#ifndef PRODUCT1801if (PrintNotLoaded && needs_patching) {1802tty->print_cr(" ###class not loaded at load_%s bci %d",1803x->is_static() ? "static" : "field", x->printable_bci());1804}1805#endif18061807bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();1808if (x->needs_null_check() &&1809(needs_patching ||1810MacroAssembler::needs_explicit_null_check(x->offset()) ||1811stress_deopt)) {1812LIR_Opr obj = object.result();1813if (stress_deopt) {1814obj = new_register(T_OBJECT);1815__ move(LIR_OprFact::oopConst(NULL), obj);1816}1817// Emit an explicit null check because the offset is too large.1818// If the class is not loaded and the object is NULL, we need to deoptimize to throw a1819// NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.1820__ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);1821}18221823LIR_Opr reg = rlock_result(x, field_type);1824LIR_Address* address;1825if (needs_patching) {1826// we need to patch the offset in the instruction so don't allow1827// generate_address to try to be smart about emitting the -1.1828// Otherwise the patching code won't know how to find the1829// instruction to patch.1830address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);1831} else {1832address = generate_address(object.result(), x->offset(), field_type);1833}18341835#if INCLUDE_ALL_GCS1836if (UseShenandoahGC && (field_type == T_OBJECT || field_type == T_ARRAY)) {1837LIR_Opr tmp = new_register(T_OBJECT);1838LIR_Opr addr = ShenandoahBarrierSet::barrier_set()->bsc1()->resolve_address(this, address, field_type, needs_patching ? info : NULL);1839if (is_volatile) {1840volatile_field_load(addr->as_address_ptr(), tmp, info);1841} else {1842__ load(addr->as_address_ptr(), tmp, info);1843}1844if (is_volatile && os::is_MP()) {1845__ membar_acquire();1846}1847tmp = ShenandoahBarrierSet::barrier_set()->bsc1()->load_reference_barrier(this, tmp, addr);1848__ move(tmp, reg);1849} else1850#endif1851{1852if (is_volatile && !needs_patching) {1853volatile_field_load(address, reg, info);1854} else {1855LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;1856__ load(address, reg, info, patch_code);1857}1858if (is_volatile && os::is_MP()) {1859__ membar_acquire();1860}1861}1862}186318641865//------------------------java.nio.Buffer.checkIndex------------------------18661867// int java.nio.Buffer.checkIndex(int)1868void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {1869// NOTE: by the time we are in checkIndex() we are guaranteed that1870// the buffer is non-null (because checkIndex is package-private and1871// only called from within other methods in the buffer).1872assert(x->number_of_arguments() == 2, "wrong type");1873LIRItem buf (x->argument_at(0), this);1874LIRItem index(x->argument_at(1), this);1875buf.load_item();1876index.load_item();18771878LIR_Opr result = rlock_result(x);1879if (GenerateRangeChecks) {1880CodeEmitInfo* info = state_for(x);1881CodeStub* stub = new RangeCheckStub(info, index.result(), true);1882if (index.result()->is_constant()) {1883cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info);1884__ branch(lir_cond_belowEqual, T_INT, stub);1885} else {1886cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(),1887java_nio_Buffer::limit_offset(), T_INT, info);1888__ branch(lir_cond_aboveEqual, T_INT, stub);1889}1890__ move(index.result(), result);1891} else {1892// Just load the index into the result register1893__ move(index.result(), result);1894}1895}189618971898//------------------------array access--------------------------------------189919001901void LIRGenerator::do_ArrayLength(ArrayLength* x) {1902LIRItem array(x->array(), this);1903array.load_item();1904LIR_Opr reg = rlock_result(x);19051906CodeEmitInfo* info = NULL;1907if (x->needs_null_check()) {1908NullCheck* nc = x->explicit_null_check();1909if (nc == NULL) {1910info = state_for(x);1911} else {1912info = state_for(nc);1913}1914if (StressLoopInvariantCodeMotion && info->deoptimize_on_exception()) {1915LIR_Opr obj = new_register(T_OBJECT);1916__ move(LIR_OprFact::oopConst(NULL), obj);1917__ null_check(obj, new CodeEmitInfo(info));1918}1919}1920__ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);1921}192219231924void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {1925bool use_length = x->length() != NULL;1926LIRItem array(x->array(), this);1927LIRItem index(x->index(), this);1928LIRItem length(this);1929bool needs_range_check = x->compute_needs_range_check();19301931if (use_length && needs_range_check) {1932length.set_instruction(x->length());1933length.load_item();1934}19351936array.load_item();1937if (index.is_constant() && can_inline_as_constant(x->index())) {1938// let it be a constant1939index.dont_load_item();1940} else {1941index.load_item();1942}19431944CodeEmitInfo* range_check_info = state_for(x);1945CodeEmitInfo* null_check_info = NULL;1946if (x->needs_null_check()) {1947NullCheck* nc = x->explicit_null_check();1948if (nc != NULL) {1949null_check_info = state_for(nc);1950} else {1951null_check_info = range_check_info;1952}1953if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {1954LIR_Opr obj = new_register(T_OBJECT);1955__ move(LIR_OprFact::oopConst(NULL), obj);1956__ null_check(obj, new CodeEmitInfo(null_check_info));1957}1958}19591960// emit array address setup early so it schedules better1961LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false);19621963if (GenerateRangeChecks && needs_range_check) {1964if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {1965__ branch(lir_cond_always, T_ILLEGAL, new RangeCheckStub(range_check_info, index.result()));1966} else if (use_length) {1967// TODO: use a (modified) version of array_range_check that does not require a1968// constant length to be loaded to a register1969__ cmp(lir_cond_belowEqual, length.result(), index.result());1970__ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));1971} else {1972array_range_check(array.result(), index.result(), null_check_info, range_check_info);1973// The range check performs the null check, so clear it out for the load1974null_check_info = NULL;1975}1976}19771978LIR_Opr result = rlock_result(x, x->elt_type());19791980#if INCLUDE_ALL_GCS1981if (UseShenandoahGC && (x->elt_type() == T_OBJECT || x->elt_type() == T_ARRAY)) {1982LIR_Opr tmp = new_register(T_OBJECT);1983LIR_Opr addr = ShenandoahBarrierSet::barrier_set()->bsc1()->resolve_address(this, array_addr, x->elt_type(), NULL);1984__ move(addr->as_address_ptr(), tmp, null_check_info);1985tmp = ShenandoahBarrierSet::barrier_set()->bsc1()->load_reference_barrier(this, tmp, addr);1986__ move(tmp, result);1987} else1988#endif1989__ move(array_addr, result, null_check_info);19901991}199219931994void LIRGenerator::do_NullCheck(NullCheck* x) {1995if (x->can_trap()) {1996LIRItem value(x->obj(), this);1997value.load_item();1998CodeEmitInfo* info = state_for(x);1999__ null_check(value.result(), info);2000}2001}200220032004void LIRGenerator::do_TypeCast(TypeCast* x) {2005LIRItem value(x->obj(), this);2006value.load_item();2007// the result is the same as from the node we are casting2008set_result(x, value.result());2009}201020112012void LIRGenerator::do_Throw(Throw* x) {2013LIRItem exception(x->exception(), this);2014exception.load_item();2015set_no_result(x);2016LIR_Opr exception_opr = exception.result();2017CodeEmitInfo* info = state_for(x, x->state());20182019#ifndef PRODUCT2020if (PrintC1Statistics) {2021increment_counter(Runtime1::throw_count_address(), T_INT);2022}2023#endif20242025// check if the instruction has an xhandler in any of the nested scopes2026bool unwind = false;2027if (info->exception_handlers()->length() == 0) {2028// this throw is not inside an xhandler2029unwind = true;2030} else {2031// get some idea of the throw type2032bool type_is_exact = true;2033ciType* throw_type = x->exception()->exact_type();2034if (throw_type == NULL) {2035type_is_exact = false;2036throw_type = x->exception()->declared_type();2037}2038if (throw_type != NULL && throw_type->is_instance_klass()) {2039ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type;2040unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact);2041}2042}20432044// do null check before moving exception oop into fixed register2045// to avoid a fixed interval with an oop during the null check.2046// Use a copy of the CodeEmitInfo because debug information is2047// different for null_check and throw.2048if (GenerateCompilerNullChecks &&2049(x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) {2050// if the exception object wasn't created using new then it might be null.2051__ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci())));2052}20532054if (compilation()->env()->jvmti_can_post_on_exceptions()) {2055// we need to go through the exception lookup path to get JVMTI2056// notification done2057unwind = false;2058}20592060// move exception oop into fixed register2061__ move(exception_opr, exceptionOopOpr());20622063if (unwind) {2064__ unwind_exception(exceptionOopOpr());2065} else {2066__ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info);2067}2068}206920702071void LIRGenerator::do_RoundFP(RoundFP* x) {2072LIRItem input(x->input(), this);2073input.load_item();2074LIR_Opr input_opr = input.result();2075assert(input_opr->is_register(), "why round if value is not in a register?");2076assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value");2077if (input_opr->is_single_fpu()) {2078set_result(x, round_item(input_opr)); // This code path not currently taken2079} else {2080LIR_Opr result = new_register(T_DOUBLE);2081set_vreg_flag(result, must_start_in_memory);2082__ roundfp(input_opr, LIR_OprFact::illegalOpr, result);2083set_result(x, result);2084}2085}20862087// Here UnsafeGetRaw may have x->base() and x->index() be int or long2088// on both 64 and 32 bits. Expecting x->base() to be always long on 64bit.2089void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) {2090LIRItem base(x->base(), this);2091LIRItem idx(this);20922093base.load_item();2094if (x->has_index()) {2095idx.set_instruction(x->index());2096idx.load_nonconstant();2097}20982099LIR_Opr reg = rlock_result(x, x->basic_type());21002101int log2_scale = 0;2102if (x->has_index()) {2103log2_scale = x->log2_scale();2104}21052106assert(!x->has_index() || idx.value() == x->index(), "should match");21072108LIR_Opr base_op = base.result();2109LIR_Opr index_op = idx.result();2110#ifndef _LP642111if (base_op->type() == T_LONG) {2112base_op = new_register(T_INT);2113__ convert(Bytecodes::_l2i, base.result(), base_op);2114}2115if (x->has_index()) {2116if (index_op->type() == T_LONG) {2117LIR_Opr long_index_op = index_op;2118if (index_op->is_constant()) {2119long_index_op = new_register(T_LONG);2120__ move(index_op, long_index_op);2121}2122index_op = new_register(T_INT);2123__ convert(Bytecodes::_l2i, long_index_op, index_op);2124} else {2125assert(x->index()->type()->tag() == intTag, "must be");2126}2127}2128// At this point base and index should be all ints.2129assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");2130assert(!x->has_index() || index_op->type() == T_INT, "index should be an int");2131#else2132if (x->has_index()) {2133if (index_op->type() == T_INT) {2134if (!index_op->is_constant()) {2135index_op = new_register(T_LONG);2136__ convert(Bytecodes::_i2l, idx.result(), index_op);2137}2138} else {2139assert(index_op->type() == T_LONG, "must be");2140if (index_op->is_constant()) {2141index_op = new_register(T_LONG);2142__ move(idx.result(), index_op);2143}2144}2145}2146// At this point base is a long non-constant2147// Index is a long register or a int constant.2148// We allow the constant to stay an int because that would allow us a more compact encoding by2149// embedding an immediate offset in the address expression. If we have a long constant, we have to2150// move it into a register first.2151assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a long non-constant");2152assert(!x->has_index() || (index_op->type() == T_INT && index_op->is_constant()) ||2153(index_op->type() == T_LONG && !index_op->is_constant()), "unexpected index type");2154#endif21552156BasicType dst_type = x->basic_type();21572158LIR_Address* addr;2159if (index_op->is_constant()) {2160assert(log2_scale == 0, "must not have a scale");2161assert(index_op->type() == T_INT, "only int constants supported");2162addr = new LIR_Address(base_op, index_op->as_jint(), dst_type);2163} else {2164#if defined(X86) || defined(AARCH64)2165addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type);2166#elif defined(GENERATE_ADDRESS_IS_PREFERRED)2167addr = generate_address(base_op, index_op, log2_scale, 0, dst_type);2168#else2169if (index_op->is_illegal() || log2_scale == 0) {2170addr = new LIR_Address(base_op, index_op, dst_type);2171} else {2172LIR_Opr tmp = new_pointer_register();2173__ shift_left(index_op, log2_scale, tmp);2174addr = new LIR_Address(base_op, tmp, dst_type);2175}2176#endif2177}21782179if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) {2180__ unaligned_move(addr, reg);2181} else {2182if (dst_type == T_OBJECT && x->is_wide()) {2183__ move_wide(addr, reg);2184} else {2185__ move(addr, reg);2186}2187}2188}218921902191void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) {2192int log2_scale = 0;2193BasicType type = x->basic_type();21942195if (x->has_index()) {2196log2_scale = x->log2_scale();2197}21982199LIRItem base(x->base(), this);2200LIRItem value(x->value(), this);2201LIRItem idx(this);22022203base.load_item();2204if (x->has_index()) {2205idx.set_instruction(x->index());2206idx.load_item();2207}22082209if (type == T_BYTE || type == T_BOOLEAN) {2210value.load_byte_item();2211} else {2212value.load_item();2213}22142215set_no_result(x);22162217LIR_Opr base_op = base.result();2218LIR_Opr index_op = idx.result();22192220#ifdef GENERATE_ADDRESS_IS_PREFERRED2221LIR_Address* addr = generate_address(base_op, index_op, log2_scale, 0, x->basic_type());2222#else2223#ifndef _LP642224if (base_op->type() == T_LONG) {2225base_op = new_register(T_INT);2226__ convert(Bytecodes::_l2i, base.result(), base_op);2227}2228if (x->has_index()) {2229if (index_op->type() == T_LONG) {2230index_op = new_register(T_INT);2231__ convert(Bytecodes::_l2i, idx.result(), index_op);2232}2233}2234// At this point base and index should be all ints and not constants2235assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");2236assert(!x->has_index() || (index_op->type() == T_INT && !index_op->is_constant()), "index should be an non-constant int");2237#else2238if (x->has_index()) {2239if (index_op->type() == T_INT) {2240index_op = new_register(T_LONG);2241__ convert(Bytecodes::_i2l, idx.result(), index_op);2242}2243}2244// At this point base and index are long and non-constant2245assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a non-constant long");2246assert(!x->has_index() || (index_op->type() == T_LONG && !index_op->is_constant()), "index must be a non-constant long");2247#endif22482249if (log2_scale != 0) {2250// temporary fix (platform dependent code without shift on Intel would be better)2251// TODO: ARM also allows embedded shift in the address2252LIR_Opr tmp = new_pointer_register();2253if (TwoOperandLIRForm) {2254__ move(index_op, tmp);2255index_op = tmp;2256}2257__ shift_left(index_op, log2_scale, tmp);2258if (!TwoOperandLIRForm) {2259index_op = tmp;2260}2261}22622263LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());2264#endif // !GENERATE_ADDRESS_IS_PREFERRED2265__ move(value.result(), addr);2266}226722682269void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {2270BasicType type = x->basic_type();2271LIRItem src(x->object(), this);2272LIRItem off(x->offset(), this);22732274off.load_item();2275src.load_item();22762277LIR_Opr value = rlock_result(x, x->basic_type());22782279#if INCLUDE_ALL_GCS2280if (UseShenandoahGC && (type == T_OBJECT || type == T_ARRAY)) {2281LIR_Opr tmp = new_register(T_OBJECT);2282get_Object_unsafe(tmp, src.result(), off.result(), type, x->is_volatile());2283tmp = ShenandoahBarrierSet::barrier_set()->bsc1()->load_reference_barrier(this, tmp, LIR_OprFact::addressConst(0));2284__ move(tmp, value);2285} else2286#endif2287get_Object_unsafe(value, src.result(), off.result(), type, x->is_volatile());22882289#if INCLUDE_ALL_GCS2290// We might be reading the value of the referent field of a2291// Reference object in order to attach it back to the live2292// object graph. If G1 is enabled then we need to record2293// the value that is being returned in an SATB log buffer.2294//2295// We need to generate code similar to the following...2296//2297// if (offset == java_lang_ref_Reference::referent_offset) {2298// if (src != NULL) {2299// if (klass(src)->reference_type() != REF_NONE) {2300// pre_barrier(..., value, ...);2301// }2302// }2303// }23042305if ((UseShenandoahGC || UseG1GC) && type == T_OBJECT) {2306bool gen_pre_barrier = true; // Assume we need to generate pre_barrier.2307bool gen_offset_check = true; // Assume we need to generate the offset guard.2308bool gen_source_check = true; // Assume we need to check the src object for null.2309bool gen_type_check = true; // Assume we need to check the reference_type.23102311if (off.is_constant()) {2312jlong off_con = (off.type()->is_int() ?2313(jlong) off.get_jint_constant() :2314off.get_jlong_constant());231523162317if (off_con != (jlong) java_lang_ref_Reference::referent_offset) {2318// The constant offset is something other than referent_offset.2319// We can skip generating/checking the remaining guards and2320// skip generation of the code stub.2321gen_pre_barrier = false;2322} else {2323// The constant offset is the same as referent_offset -2324// we do not need to generate a runtime offset check.2325gen_offset_check = false;2326}2327}23282329// We don't need to generate stub if the source object is an array2330if (gen_pre_barrier && src.type()->is_array()) {2331gen_pre_barrier = false;2332}23332334if (gen_pre_barrier) {2335// We still need to continue with the checks.2336if (src.is_constant()) {2337ciObject* src_con = src.get_jobject_constant();2338guarantee(src_con != NULL, "no source constant");23392340if (src_con->is_null_object()) {2341// The constant src object is null - We can skip2342// generating the code stub.2343gen_pre_barrier = false;2344} else {2345// Non-null constant source object. We still have to generate2346// the slow stub - but we don't need to generate the runtime2347// null object check.2348gen_source_check = false;2349}2350}2351}2352if (gen_pre_barrier && !PatchALot) {2353// Can the klass of object be statically determined to be2354// a sub-class of Reference?2355ciType* type = src.value()->declared_type();2356if ((type != NULL) && type->is_loaded()) {2357if (type->is_subtype_of(compilation()->env()->Reference_klass())) {2358gen_type_check = false;2359} else if (type->is_klass() &&2360!compilation()->env()->Object_klass()->is_subtype_of(type->as_klass())) {2361// Not Reference and not Object klass.2362gen_pre_barrier = false;2363}2364}2365}23662367if (gen_pre_barrier) {2368LabelObj* Lcont = new LabelObj();23692370// We can have generate one runtime check here. Let's start with2371// the offset check.2372// Allocate temp register to src and load it here, otherwise2373// control flow below may confuse register allocator.2374LIR_Opr src_reg = new_register(T_OBJECT);2375__ move(src.result(), src_reg);2376if (gen_offset_check) {2377// if (offset != referent_offset) -> continue2378// If offset is an int then we can do the comparison with the2379// referent_offset constant; otherwise we need to move2380// referent_offset into a temporary register and generate2381// a reg-reg compare.23822383LIR_Opr referent_off;23842385if (off.type()->is_int()) {2386referent_off = LIR_OprFact::intConst(java_lang_ref_Reference::referent_offset);2387} else {2388assert(off.type()->is_long(), "what else?");2389referent_off = new_register(T_LONG);2390__ move(LIR_OprFact::longConst(java_lang_ref_Reference::referent_offset), referent_off);2391}2392__ cmp(lir_cond_notEqual, off.result(), referent_off);2393__ branch(lir_cond_notEqual, as_BasicType(off.type()), Lcont->label());2394}2395if (gen_source_check) {2396// offset is a const and equals referent offset2397// if (source == null) -> continue2398__ cmp(lir_cond_equal, src_reg, LIR_OprFact::oopConst(NULL));2399__ branch(lir_cond_equal, T_OBJECT, Lcont->label());2400}2401LIR_Opr src_klass = new_register(T_METADATA);2402if (gen_type_check) {2403// We have determined that offset == referent_offset && src != null.2404// if (src->_klass->_reference_type == REF_NONE) -> continue2405__ move(new LIR_Address(src_reg, oopDesc::klass_offset_in_bytes(), T_ADDRESS), src_klass);2406LIR_Address* reference_type_addr = new LIR_Address(src_klass, in_bytes(InstanceKlass::reference_type_offset()), T_BYTE);2407LIR_Opr reference_type = new_register(T_INT);2408__ move(reference_type_addr, reference_type);2409__ cmp(lir_cond_equal, reference_type, LIR_OprFact::intConst(REF_NONE));2410__ branch(lir_cond_equal, T_INT, Lcont->label());2411}2412{2413// We have determined that src->_klass->_reference_type != REF_NONE2414// so register the value in the referent field with the pre-barrier.2415pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,2416value /* pre_val */,2417false /* do_load */,2418false /* patch */,2419NULL /* info */);2420}2421__ branch_destination(Lcont->label());2422}2423}2424#endif // INCLUDE_ALL_GCS24252426if (x->is_volatile() && os::is_MP()) __ membar_acquire();2427}242824292430void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {2431BasicType type = x->basic_type();2432LIRItem src(x->object(), this);2433LIRItem off(x->offset(), this);2434LIRItem data(x->value(), this);24352436src.load_item();2437if (type == T_BOOLEAN || type == T_BYTE) {2438data.load_byte_item();2439} else {2440data.load_item();2441}2442off.load_item();24432444set_no_result(x);24452446if (x->is_volatile() && os::is_MP()) __ membar_release();2447put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile());2448if (x->is_volatile() && os::is_MP()) __ membar();2449}245024512452void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) {2453LIRItem src(x->object(), this);2454LIRItem off(x->offset(), this);24552456src.load_item();2457if (off.is_constant() && can_inline_as_constant(x->offset())) {2458// let it be a constant2459off.dont_load_item();2460} else {2461off.load_item();2462}24632464set_no_result(x);24652466LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE);2467__ prefetch(addr, is_store);2468}246924702471void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) {2472do_UnsafePrefetch(x, false);2473}247424752476void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {2477do_UnsafePrefetch(x, true);2478}247924802481void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {2482int lng = x->length();24832484for (int i = 0; i < lng; i++) {2485SwitchRange* one_range = x->at(i);2486int low_key = one_range->low_key();2487int high_key = one_range->high_key();2488BlockBegin* dest = one_range->sux();2489if (low_key == high_key) {2490__ cmp(lir_cond_equal, value, low_key);2491__ branch(lir_cond_equal, T_INT, dest);2492} else if (high_key - low_key == 1) {2493__ cmp(lir_cond_equal, value, low_key);2494__ branch(lir_cond_equal, T_INT, dest);2495__ cmp(lir_cond_equal, value, high_key);2496__ branch(lir_cond_equal, T_INT, dest);2497} else {2498LabelObj* L = new LabelObj();2499__ cmp(lir_cond_less, value, low_key);2500__ branch(lir_cond_less, T_INT, L->label());2501__ cmp(lir_cond_lessEqual, value, high_key);2502__ branch(lir_cond_lessEqual, T_INT, dest);2503__ branch_destination(L->label());2504}2505}2506__ jump(default_sux);2507}250825092510SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) {2511SwitchRangeList* res = new SwitchRangeList();2512int len = x->length();2513if (len > 0) {2514BlockBegin* sux = x->sux_at(0);2515int key = x->lo_key();2516BlockBegin* default_sux = x->default_sux();2517SwitchRange* range = new SwitchRange(key, sux);2518for (int i = 0; i < len; i++, key++) {2519BlockBegin* new_sux = x->sux_at(i);2520if (sux == new_sux) {2521// still in same range2522range->set_high_key(key);2523} else {2524// skip tests which explicitly dispatch to the default2525if (sux != default_sux) {2526res->append(range);2527}2528range = new SwitchRange(key, new_sux);2529}2530sux = new_sux;2531}2532if (res->length() == 0 || res->last() != range) res->append(range);2533}2534return res;2535}253625372538// we expect the keys to be sorted by increasing value2539SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) {2540SwitchRangeList* res = new SwitchRangeList();2541int len = x->length();2542if (len > 0) {2543BlockBegin* default_sux = x->default_sux();2544int key = x->key_at(0);2545BlockBegin* sux = x->sux_at(0);2546SwitchRange* range = new SwitchRange(key, sux);2547for (int i = 1; i < len; i++) {2548int new_key = x->key_at(i);2549BlockBegin* new_sux = x->sux_at(i);2550if (key+1 == new_key && sux == new_sux) {2551// still in same range2552range->set_high_key(new_key);2553} else {2554// skip tests which explicitly dispatch to the default2555if (range->sux() != default_sux) {2556res->append(range);2557}2558range = new SwitchRange(new_key, new_sux);2559}2560key = new_key;2561sux = new_sux;2562}2563if (res->length() == 0 || res->last() != range) res->append(range);2564}2565return res;2566}256725682569void LIRGenerator::do_TableSwitch(TableSwitch* x) {2570LIRItem tag(x->tag(), this);2571tag.load_item();2572set_no_result(x);25732574if (x->is_safepoint()) {2575__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));2576}25772578// move values into phi locations2579move_to_phi(x->state());25802581int lo_key = x->lo_key();2582int len = x->length();2583assert(lo_key <= (lo_key + (len - 1)), "integer overflow");2584LIR_Opr value = tag.result();2585if (UseTableRanges) {2586do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());2587} else {2588for (int i = 0; i < len; i++) {2589__ cmp(lir_cond_equal, value, i + lo_key);2590__ branch(lir_cond_equal, T_INT, x->sux_at(i));2591}2592__ jump(x->default_sux());2593}2594}259525962597void LIRGenerator::do_LookupSwitch(LookupSwitch* x) {2598LIRItem tag(x->tag(), this);2599tag.load_item();2600set_no_result(x);26012602if (x->is_safepoint()) {2603__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));2604}26052606// move values into phi locations2607move_to_phi(x->state());26082609LIR_Opr value = tag.result();2610if (UseTableRanges) {2611do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());2612} else {2613int len = x->length();2614for (int i = 0; i < len; i++) {2615__ cmp(lir_cond_equal, value, x->key_at(i));2616__ branch(lir_cond_equal, T_INT, x->sux_at(i));2617}2618__ jump(x->default_sux());2619}2620}262126222623void LIRGenerator::do_Goto(Goto* x) {2624set_no_result(x);26252626if (block()->next()->as_OsrEntry()) {2627// need to free up storage used for OSR entry point2628LIR_Opr osrBuffer = block()->next()->operand();2629BasicTypeList signature;2630signature.append(NOT_LP64(T_INT) LP64_ONLY(T_LONG)); // pass a pointer to osrBuffer2631CallingConvention* cc = frame_map()->c_calling_convention(&signature);2632__ move(osrBuffer, cc->args()->at(0));2633__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),2634getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());2635}26362637if (x->is_safepoint()) {2638ValueStack* state = x->state_before() ? x->state_before() : x->state();26392640// increment backedge counter if needed2641CodeEmitInfo* info = state_for(x, state);2642increment_backedge_counter(info, x->profiled_bci());2643CodeEmitInfo* safepoint_info = state_for(x, state);2644__ safepoint(safepoint_poll_register(), safepoint_info);2645}26462647// Gotos can be folded Ifs, handle this case.2648if (x->should_profile()) {2649ciMethod* method = x->profiled_method();2650assert(method != NULL, "method should be set if branch is profiled");2651ciMethodData* md = method->method_data_or_null();2652assert(md != NULL, "Sanity");2653ciProfileData* data = md->bci_to_data(x->profiled_bci());2654assert(data != NULL, "must have profiling data");2655int offset;2656if (x->direction() == Goto::taken) {2657assert(data->is_BranchData(), "need BranchData for two-way branches");2658offset = md->byte_offset_of_slot(data, BranchData::taken_offset());2659} else if (x->direction() == Goto::not_taken) {2660assert(data->is_BranchData(), "need BranchData for two-way branches");2661offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());2662} else {2663assert(data->is_JumpData(), "need JumpData for branches");2664offset = md->byte_offset_of_slot(data, JumpData::taken_offset());2665}2666LIR_Opr md_reg = new_register(T_METADATA);2667__ metadata2reg(md->constant_encoding(), md_reg);26682669increment_counter(new LIR_Address(md_reg, offset,2670NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);2671}26722673// emit phi-instruction move after safepoint since this simplifies2674// describing the state as the safepoint.2675move_to_phi(x->state());26762677__ jump(x->default_sux());2678}26792680/**2681* Emit profiling code if needed for arguments, parameters, return value types2682*2683* @param md MDO the code will update at runtime2684* @param md_base_offset common offset in the MDO for this profile and subsequent ones2685* @param md_offset offset in the MDO (on top of md_base_offset) for this profile2686* @param profiled_k current profile2687* @param obj IR node for the object to be profiled2688* @param mdp register to hold the pointer inside the MDO (md + md_base_offset).2689* Set once we find an update to make and use for next ones.2690* @param not_null true if we know obj cannot be null2691* @param signature_at_call_k signature at call for obj2692* @param callee_signature_k signature of callee for obj2693* at call and callee signatures differ at method handle call2694* @return the only klass we know will ever be seen at this profile point2695*/2696ciKlass* LIRGenerator::profile_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k,2697Value obj, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,2698ciKlass* callee_signature_k) {2699ciKlass* result = NULL;2700bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);2701bool do_update = !TypeEntries::is_type_unknown(profiled_k);2702// known not to be null or null bit already set and already set to2703// unknown: nothing we can do to improve profiling2704if (!do_null && !do_update) {2705return result;2706}27072708ciKlass* exact_klass = NULL;2709Compilation* comp = Compilation::current();2710if (do_update) {2711// try to find exact type, using CHA if possible, so that loading2712// the klass from the object can be avoided2713ciType* type = obj->exact_type();2714if (type == NULL) {2715type = obj->declared_type();2716type = comp->cha_exact_type(type);2717}2718assert(type == NULL || type->is_klass(), "type should be class");2719exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;27202721do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;2722}27232724if (!do_null && !do_update) {2725return result;2726}27272728ciKlass* exact_signature_k = NULL;2729if (do_update) {2730// Is the type from the signature exact (the only one possible)?2731exact_signature_k = signature_at_call_k->exact_klass();2732if (exact_signature_k == NULL) {2733exact_signature_k = comp->cha_exact_type(signature_at_call_k);2734} else {2735result = exact_signature_k;2736// Known statically. No need to emit any code: prevent2737// LIR_Assembler::emit_profile_type() from emitting useless code2738profiled_k = ciTypeEntries::with_status(result, profiled_k);2739}2740// exact_klass and exact_signature_k can be both non NULL but2741// different if exact_klass is loaded after the ciObject for2742// exact_signature_k is created.2743if (exact_klass == NULL && exact_signature_k != NULL && exact_klass != exact_signature_k) {2744// sometimes the type of the signature is better than the best type2745// the compiler has2746exact_klass = exact_signature_k;2747}2748if (callee_signature_k != NULL &&2749callee_signature_k != signature_at_call_k) {2750ciKlass* improved_klass = callee_signature_k->exact_klass();2751if (improved_klass == NULL) {2752improved_klass = comp->cha_exact_type(callee_signature_k);2753}2754if (exact_klass == NULL && improved_klass != NULL && exact_klass != improved_klass) {2755exact_klass = exact_signature_k;2756}2757}2758do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;2759}27602761if (!do_null && !do_update) {2762return result;2763}27642765if (mdp == LIR_OprFact::illegalOpr) {2766mdp = new_register(T_METADATA);2767__ metadata2reg(md->constant_encoding(), mdp);2768if (md_base_offset != 0) {2769LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);2770mdp = new_pointer_register();2771__ leal(LIR_OprFact::address(base_type_address), mdp);2772}2773}2774LIRItem value(obj, this);2775value.load_item();2776__ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),2777value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);2778return result;2779}27802781// profile parameters on entry to the root of the compilation2782void LIRGenerator::profile_parameters(Base* x) {2783if (compilation()->profile_parameters()) {2784CallingConvention* args = compilation()->frame_map()->incoming_arguments();2785ciMethodData* md = scope()->method()->method_data_or_null();2786assert(md != NULL, "Sanity");27872788if (md->parameters_type_data() != NULL) {2789ciParametersTypeData* parameters_type_data = md->parameters_type_data();2790ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();2791LIR_Opr mdp = LIR_OprFact::illegalOpr;2792for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {2793LIR_Opr src = args->at(i);2794assert(!src->is_illegal(), "check");2795BasicType t = src->type();2796if (t == T_OBJECT || t == T_ARRAY) {2797intptr_t profiled_k = parameters->type(j);2798Local* local = x->state()->local_at(java_index)->as_Local();2799ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),2800in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),2801profiled_k, local, mdp, false, local->declared_type()->as_klass(), NULL);2802// If the profile is known statically set it once for all and do not emit any code2803if (exact != NULL) {2804md->set_parameter_type(j, exact);2805}2806j++;2807}2808java_index += type2size[t];2809}2810}2811}2812}28132814void LIRGenerator::do_Base(Base* x) {2815__ std_entry(LIR_OprFact::illegalOpr);2816// Emit moves from physical registers / stack slots to virtual registers2817CallingConvention* args = compilation()->frame_map()->incoming_arguments();2818IRScope* irScope = compilation()->hir()->top_scope();2819int java_index = 0;2820for (int i = 0; i < args->length(); i++) {2821LIR_Opr src = args->at(i);2822assert(!src->is_illegal(), "check");2823BasicType t = src->type();28242825// Types which are smaller than int are passed as int, so2826// correct the type which passed.2827switch (t) {2828case T_BYTE:2829case T_BOOLEAN:2830case T_SHORT:2831case T_CHAR:2832t = T_INT;2833break;2834}28352836LIR_Opr dest = new_register(t);2837__ move(src, dest);28382839// Assign new location to Local instruction for this local2840Local* local = x->state()->local_at(java_index)->as_Local();2841assert(local != NULL, "Locals for incoming arguments must have been created");2842#ifndef __SOFTFP__2843// The java calling convention passes double as long and float as int.2844assert(as_ValueType(t)->tag() == local->type()->tag(), "check");2845#endif // __SOFTFP__2846local->set_operand(dest);2847_instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL);2848java_index += type2size[t];2849}28502851if (compilation()->env()->dtrace_method_probes()) {2852BasicTypeList signature;2853signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread2854signature.append(T_METADATA); // Method*2855LIR_OprList* args = new LIR_OprList();2856args->append(getThreadPointer());2857LIR_Opr meth = new_register(T_METADATA);2858__ metadata2reg(method()->constant_encoding(), meth);2859args->append(meth);2860call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);2861}28622863if (method()->is_synchronized()) {2864LIR_Opr obj;2865if (method()->is_static()) {2866obj = new_register(T_OBJECT);2867__ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);2868} else {2869Local* receiver = x->state()->local_at(0)->as_Local();2870assert(receiver != NULL, "must already exist");2871obj = receiver->operand();2872}2873assert(obj->is_valid(), "must be valid");28742875if (method()->is_synchronized() && GenerateSynchronizationCode) {2876LIR_Opr lock = new_register(T_INT);2877__ load_stack_address_monitor(0, lock);28782879CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));2880CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);28812882// receiver is guaranteed non-NULL so don't need CodeEmitInfo2883__ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);2884}2885}28862887// increment invocation counters if needed2888if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.2889profile_parameters(x);2890CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);2891increment_invocation_counter(info);2892}28932894// all blocks with a successor must end with an unconditional jump2895// to the successor even if they are consecutive2896__ jump(x->default_sux());2897}289828992900void LIRGenerator::do_OsrEntry(OsrEntry* x) {2901// construct our frame and model the production of incoming pointer2902// to the OSR buffer.2903__ osr_entry(LIR_Assembler::osrBufferPointer());2904LIR_Opr result = rlock_result(x);2905__ move(LIR_Assembler::osrBufferPointer(), result);2906}290729082909void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {2910assert(args->length() == arg_list->length(),2911err_msg_res("args=%d, arg_list=%d", args->length(), arg_list->length()));2912for (int i = x->has_receiver() ? 1 : 0; i < args->length(); i++) {2913LIRItem* param = args->at(i);2914LIR_Opr loc = arg_list->at(i);2915if (loc->is_register()) {2916param->load_item_force(loc);2917} else {2918LIR_Address* addr = loc->as_address_ptr();2919param->load_for_store(addr->type());2920if (addr->type() == T_OBJECT) {2921__ move_wide(param->result(), addr);2922} else2923if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {2924__ unaligned_move(param->result(), addr);2925} else {2926__ move(param->result(), addr);2927}2928}2929}29302931if (x->has_receiver()) {2932LIRItem* receiver = args->at(0);2933LIR_Opr loc = arg_list->at(0);2934if (loc->is_register()) {2935receiver->load_item_force(loc);2936} else {2937assert(loc->is_address(), "just checking");2938receiver->load_for_store(T_OBJECT);2939__ move_wide(receiver->result(), loc->as_address_ptr());2940}2941}2942}294329442945// Visits all arguments, returns appropriate items without loading them2946LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) {2947LIRItemList* argument_items = new LIRItemList();2948if (x->has_receiver()) {2949LIRItem* receiver = new LIRItem(x->receiver(), this);2950argument_items->append(receiver);2951}2952for (int i = 0; i < x->number_of_arguments(); i++) {2953LIRItem* param = new LIRItem(x->argument_at(i), this);2954argument_items->append(param);2955}2956return argument_items;2957}295829592960// The invoke with receiver has following phases:2961// a) traverse and load/lock receiver;2962// b) traverse all arguments -> item-array (invoke_visit_argument)2963// c) push receiver on stack2964// d) load each of the items and push on stack2965// e) unlock receiver2966// f) move receiver into receiver-register %o02967// g) lock result registers and emit call operation2968//2969// Before issuing a call, we must spill-save all values on stack2970// that are in caller-save register. "spill-save" moves those registers2971// either in a free callee-save register or spills them if no free2972// callee save register is available.2973//2974// The problem is where to invoke spill-save.2975// - if invoked between e) and f), we may lock callee save2976// register in "spill-save" that destroys the receiver register2977// before f) is executed2978// - if we rearrange f) to be earlier (by loading %o0) it2979// may destroy a value on the stack that is currently in %o02980// and is waiting to be spilled2981// - if we keep the receiver locked while doing spill-save,2982// we cannot spill it as it is spill-locked2983//2984void LIRGenerator::do_Invoke(Invoke* x) {2985CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true);29862987LIR_OprList* arg_list = cc->args();2988LIRItemList* args = invoke_visit_arguments(x);2989LIR_Opr receiver = LIR_OprFact::illegalOpr;29902991// setup result register2992LIR_Opr result_register = LIR_OprFact::illegalOpr;2993if (x->type() != voidType) {2994#ifdef AARCH322995result_register = java_result_register_for(x->type());2996#else2997result_register = result_register_for(x->type());2998#endif2999}30003001CodeEmitInfo* info = state_for(x, x->state());30023003invoke_load_arguments(x, args, arg_list);30043005if (x->has_receiver()) {3006args->at(0)->load_item_force(LIR_Assembler::receiverOpr());3007receiver = args->at(0)->result();3008}30093010// emit invoke code3011bool optimized = x->target_is_loaded() && x->target_is_final();3012assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match");30133014// JSR 2923015// Preserve the SP over MethodHandle call sites, if needed.3016ciMethod* target = x->target();3017bool is_method_handle_invoke = (// %%% FIXME: Are both of these relevant?3018target->is_method_handle_intrinsic() ||3019target->is_compiled_lambda_form());3020if (is_method_handle_invoke) {3021info->set_is_method_handle_invoke(true);3022if(FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {3023__ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr());3024}3025}30263027switch (x->code()) {3028case Bytecodes::_invokestatic:3029__ call_static(target, result_register,3030SharedRuntime::get_resolve_static_call_stub(),3031arg_list, info);3032break;3033case Bytecodes::_invokespecial:3034case Bytecodes::_invokevirtual:3035case Bytecodes::_invokeinterface:3036// for final target we still produce an inline cache, in order3037// to be able to call mixed mode3038if (x->code() == Bytecodes::_invokespecial || optimized) {3039__ call_opt_virtual(target, receiver, result_register,3040SharedRuntime::get_resolve_opt_virtual_call_stub(),3041arg_list, info);3042} else if (x->vtable_index() < 0) {3043__ call_icvirtual(target, receiver, result_register,3044SharedRuntime::get_resolve_virtual_call_stub(),3045arg_list, info);3046} else {3047int entry_offset = InstanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size();3048int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes();3049__ call_virtual(target, receiver, result_register, vtable_offset, arg_list, info);3050}3051break;3052case Bytecodes::_invokedynamic: {3053__ call_dynamic(target, receiver, result_register,3054SharedRuntime::get_resolve_static_call_stub(),3055arg_list, info);3056break;3057}3058default:3059fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(x->code())));3060break;3061}30623063// JSR 2923064// Restore the SP after MethodHandle call sites, if needed.3065if (is_method_handle_invoke3066&& FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {3067__ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer());3068}30693070if (x->type()->is_float() || x->type()->is_double()) {3071// Force rounding of results from non-strictfp when in strictfp3072// scope (or when we don't know the strictness of the callee, to3073// be safe.)3074if (method()->is_strict()) {3075if (!x->target_is_loaded() || !x->target_is_strictfp()) {3076result_register = round_item(result_register);3077}3078}3079}30803081if (result_register->is_valid()) {3082LIR_Opr result = rlock_result(x);3083__ move(result_register, result);3084}3085}308630873088void LIRGenerator::do_FPIntrinsics(Intrinsic* x) {3089assert(x->number_of_arguments() == 1, "wrong type");3090LIRItem value (x->argument_at(0), this);3091LIR_Opr reg = rlock_result(x);3092value.load_item();3093LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type()));3094__ move(tmp, reg);3095}3096309730983099// Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval()3100void LIRGenerator::do_IfOp(IfOp* x) {3101#ifdef ASSERT3102{3103ValueTag xtag = x->x()->type()->tag();3104ValueTag ttag = x->tval()->type()->tag();3105assert(xtag == intTag || xtag == objectTag, "cannot handle others");3106assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");3107assert(ttag == x->fval()->type()->tag(), "cannot handle others");3108}3109#endif31103111LIRItem left(x->x(), this);3112LIRItem right(x->y(), this);3113left.load_item();3114if (can_inline_as_constant(right.value())) {3115right.dont_load_item();3116} else {3117right.load_item();3118}31193120LIRItem t_val(x->tval(), this);3121LIRItem f_val(x->fval(), this);3122t_val.dont_load_item();3123f_val.dont_load_item();3124LIR_Opr reg = rlock_result(x);31253126__ cmp(lir_cond(x->cond()), left.result(), right.result());3127__ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type()));3128}31293130#ifdef JFR_HAVE_INTRINSICS3131void LIRGenerator::do_ClassIDIntrinsic(Intrinsic* x) {3132CodeEmitInfo* info = state_for(x);3133CodeEmitInfo* info2 = new CodeEmitInfo(info); // Clone for the second null check31343135assert(info != NULL, "must have info");3136LIRItem arg(x->argument_at(0), this);31373138arg.load_item();3139LIR_Opr klass = new_register(T_METADATA);3140__ move(new LIR_Address(arg.result(), java_lang_Class::klass_offset_in_bytes(), T_ADDRESS), klass, info);3141LIR_Opr id = new_register(T_LONG);3142ByteSize offset = KLASS_TRACE_ID_OFFSET;3143LIR_Address* trace_id_addr = new LIR_Address(klass, in_bytes(offset), T_LONG);31443145__ move(trace_id_addr, id);3146__ logical_or(id, LIR_OprFact::longConst(0x01l), id);3147__ store(id, trace_id_addr);31483149#ifdef TRACE_ID_META_BITS3150__ logical_and(id, LIR_OprFact::longConst(~TRACE_ID_META_BITS), id);3151#endif3152#ifdef TRACE_ID_SHIFT3153__ unsigned_shift_right(id, TRACE_ID_SHIFT, id);3154#endif31553156__ move(id, rlock_result(x));3157}31583159void LIRGenerator::do_getEventWriter(Intrinsic* x) {3160LabelObj* L_end = new LabelObj();31613162LIR_Address* jobj_addr = new LIR_Address(getThreadPointer(),3163in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR),3164T_OBJECT);3165LIR_Opr result = rlock_result(x);3166__ move_wide(jobj_addr, result);3167__ cmp(lir_cond_equal, result, LIR_OprFact::oopConst(NULL));3168__ branch(lir_cond_equal, T_OBJECT, L_end->label());3169__ move_wide(new LIR_Address(result, T_OBJECT), result);31703171__ branch_destination(L_end->label());3172}3173#endif31743175void LIRGenerator::do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x) {3176assert(x->number_of_arguments() == expected_arguments, "wrong type");3177LIR_Opr reg = result_register_for(x->type());3178__ call_runtime_leaf(routine, getThreadTemp(),3179reg, new LIR_OprList());3180LIR_Opr result = rlock_result(x);3181__ move(reg, result);3182}31833184#ifdef TRACE_HAVE_INTRINSICS3185void LIRGenerator::do_ThreadIDIntrinsic(Intrinsic* x) {3186LIR_Opr thread = getThreadPointer();3187LIR_Opr osthread = new_pointer_register();3188__ move(new LIR_Address(thread, in_bytes(JavaThread::osthread_offset()), osthread->type()), osthread);3189size_t thread_id_size = OSThread::thread_id_size();3190if (thread_id_size == (size_t) BytesPerLong) {3191LIR_Opr id = new_register(T_LONG);3192__ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_LONG), id);3193__ convert(Bytecodes::_l2i, id, rlock_result(x));3194} else if (thread_id_size == (size_t) BytesPerInt) {3195__ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_INT), rlock_result(x));3196} else {3197ShouldNotReachHere();3198}3199}32003201void LIRGenerator::do_ClassIDIntrinsic(Intrinsic* x) {3202CodeEmitInfo* info = state_for(x);3203CodeEmitInfo* info2 = new CodeEmitInfo(info); // Clone for the second null check3204BasicType klass_pointer_type = NOT_LP64(T_INT) LP64_ONLY(T_LONG);3205assert(info != NULL, "must have info");3206LIRItem arg(x->argument_at(1), this);3207arg.load_item();3208LIR_Opr klass = new_pointer_register();3209__ move(new LIR_Address(arg.result(), java_lang_Class::klass_offset_in_bytes(), klass_pointer_type), klass, info);3210LIR_Opr id = new_register(T_LONG);3211ByteSize offset = TRACE_ID_OFFSET;3212LIR_Address* trace_id_addr = new LIR_Address(klass, in_bytes(offset), T_LONG);3213__ move(trace_id_addr, id);3214__ logical_or(id, LIR_OprFact::longConst(0x01l), id);3215__ store(id, trace_id_addr);3216__ logical_and(id, LIR_OprFact::longConst(~0x3l), id);3217__ move(id, rlock_result(x));3218}3219#endif32203221void LIRGenerator::do_Intrinsic(Intrinsic* x) {3222switch (x->id()) {3223case vmIntrinsics::_intBitsToFloat :3224case vmIntrinsics::_doubleToRawLongBits :3225case vmIntrinsics::_longBitsToDouble :3226case vmIntrinsics::_floatToRawIntBits : {3227do_FPIntrinsics(x);3228break;3229}32303231#ifdef JFR_HAVE_INTRINSICS3232case vmIntrinsics::_getClassId:3233do_ClassIDIntrinsic(x);3234break;3235case vmIntrinsics::_getEventWriter:3236do_getEventWriter(x);3237break;3238case vmIntrinsics::_counterTime:3239do_RuntimeCall(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), 0, x);3240break;3241#endif32423243case vmIntrinsics::_currentTimeMillis:3244do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), 0, x);3245break;32463247case vmIntrinsics::_nanoTime:3248do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), 0, x);3249break;32503251case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;3252case vmIntrinsics::_isInstance: do_isInstance(x); break;3253case vmIntrinsics::_getClass: do_getClass(x); break;3254case vmIntrinsics::_currentThread: do_currentThread(x); break;32553256case vmIntrinsics::_dlog: // fall through3257case vmIntrinsics::_dlog10: // fall through3258case vmIntrinsics::_dabs: // fall through3259case vmIntrinsics::_dsqrt: // fall through3260case vmIntrinsics::_dtan: // fall through3261case vmIntrinsics::_dsin : // fall through3262case vmIntrinsics::_dcos : // fall through3263case vmIntrinsics::_dexp : // fall through3264case vmIntrinsics::_dpow : do_MathIntrinsic(x); break;3265case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break;32663267// java.nio.Buffer.checkIndex3268case vmIntrinsics::_checkIndex: do_NIOCheckIndex(x); break;32693270case vmIntrinsics::_compareAndSwapObject:3271do_CompareAndSwap(x, objectType);3272break;3273case vmIntrinsics::_compareAndSwapInt:3274do_CompareAndSwap(x, intType);3275break;3276case vmIntrinsics::_compareAndSwapLong:3277do_CompareAndSwap(x, longType);3278break;32793280case vmIntrinsics::_loadFence :3281if (os::is_MP()) __ membar_acquire();3282break;3283case vmIntrinsics::_storeFence:3284if (os::is_MP()) __ membar_release();3285break;3286case vmIntrinsics::_fullFence :3287if (os::is_MP()) __ membar();3288break;32893290case vmIntrinsics::_Reference_get:3291do_Reference_get(x);3292break;32933294case vmIntrinsics::_updateCRC32:3295case vmIntrinsics::_updateBytesCRC32:3296case vmIntrinsics::_updateByteBufferCRC32:3297do_update_CRC32(x);3298break;32993300default: ShouldNotReachHere(); break;3301}3302}33033304void LIRGenerator::profile_arguments(ProfileCall* x) {3305if (compilation()->profile_arguments()) {3306int bci = x->bci_of_invoke();3307ciMethodData* md = x->method()->method_data_or_null();3308ciProfileData* data = md->bci_to_data(bci);3309if (data != NULL) {3310if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||3311(data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {3312ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();3313int base_offset = md->byte_offset_of_slot(data, extra);3314LIR_Opr mdp = LIR_OprFact::illegalOpr;3315ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();33163317Bytecodes::Code bc = x->method()->java_code_at_bci(bci);3318int start = 0;3319int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();3320if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {3321// first argument is not profiled at call (method handle invoke)3322assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");3323start = 1;3324}3325ciSignature* callee_signature = x->callee()->signature();3326// method handle call to virtual method3327bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);3328ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);33293330bool ignored_will_link;3331ciSignature* signature_at_call = NULL;3332x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);3333ciSignatureStream signature_at_call_stream(signature_at_call);33343335// if called through method handle invoke, some arguments may have been popped3336for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) {3337int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());3338ciKlass* exact = profile_type(md, base_offset, off,3339args->type(i), x->profiled_arg_at(i+start), mdp,3340!x->arg_needs_null_check(i+start),3341signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());3342if (exact != NULL) {3343md->set_argument_type(bci, i, exact);3344}3345}3346} else {3347#ifdef ASSERT3348Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());3349int n = x->nb_profiled_args();3350assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() ||3351(x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))),3352"only at JSR292 bytecodes");3353#endif3354}3355}3356}3357}33583359// profile parameters on entry to an inlined method3360void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {3361if (compilation()->profile_parameters() && x->inlined()) {3362ciMethodData* md = x->callee()->method_data_or_null();3363if (md != NULL) {3364ciParametersTypeData* parameters_type_data = md->parameters_type_data();3365if (parameters_type_data != NULL) {3366ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();3367LIR_Opr mdp = LIR_OprFact::illegalOpr;3368bool has_receiver = !x->callee()->is_static();3369ciSignature* sig = x->callee()->signature();3370ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);3371int i = 0; // to iterate on the Instructions3372Value arg = x->recv();3373bool not_null = false;3374int bci = x->bci_of_invoke();3375Bytecodes::Code bc = x->method()->java_code_at_bci(bci);3376// The first parameter is the receiver so that's what we start3377// with if it exists. One exception is method handle call to3378// virtual method: the receiver is in the args list3379if (arg == NULL || !Bytecodes::has_receiver(bc)) {3380i = 1;3381arg = x->profiled_arg_at(0);3382not_null = !x->arg_needs_null_check(0);3383}3384int k = 0; // to iterate on the profile data3385for (;;) {3386intptr_t profiled_k = parameters->type(k);3387ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),3388in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),3389profiled_k, arg, mdp, not_null, sig_stream.next_klass(), NULL);3390// If the profile is known statically set it once for all and do not emit any code3391if (exact != NULL) {3392md->set_parameter_type(k, exact);3393}3394k++;3395if (k >= parameters_type_data->number_of_parameters()) {3396#ifdef ASSERT3397int extra = 0;3398if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&3399x->nb_profiled_args() >= TypeProfileParmsLimit &&3400x->recv() != NULL && Bytecodes::has_receiver(bc)) {3401extra += 1;3402}3403assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");3404#endif3405break;3406}3407arg = x->profiled_arg_at(i);3408not_null = !x->arg_needs_null_check(i);3409i++;3410}3411}3412}3413}3414}34153416void LIRGenerator::do_ProfileCall(ProfileCall* x) {3417// Need recv in a temporary register so it interferes with the other temporaries3418LIR_Opr recv = LIR_OprFact::illegalOpr;3419LIR_Opr mdo = new_register(T_METADATA);3420// tmp is used to hold the counters on SPARC3421LIR_Opr tmp = new_pointer_register();34223423if (x->nb_profiled_args() > 0) {3424profile_arguments(x);3425}34263427// profile parameters on inlined method entry including receiver3428if (x->recv() != NULL || x->nb_profiled_args() > 0) {3429profile_parameters_at_call(x);3430}34313432if (x->recv() != NULL) {3433LIRItem value(x->recv(), this);3434value.load_item();3435recv = new_register(T_OBJECT);3436__ move(value.result(), recv);3437}3438__ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());3439}34403441void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {3442int bci = x->bci_of_invoke();3443ciMethodData* md = x->method()->method_data_or_null();3444ciProfileData* data = md->bci_to_data(bci);3445if (data != NULL) {3446assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");3447ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();3448LIR_Opr mdp = LIR_OprFact::illegalOpr;34493450bool ignored_will_link;3451ciSignature* signature_at_call = NULL;3452x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);34533454// The offset within the MDO of the entry to update may be too large3455// to be used in load/store instructions on some platforms. So have3456// profile_type() compute the address of the profile in a register.3457ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0,3458ret->type(), x->ret(), mdp,3459!x->needs_null_check(),3460signature_at_call->return_type()->as_klass(),3461x->callee()->signature()->return_type()->as_klass());3462if (exact != NULL) {3463md->set_return_type(bci, exact);3464}3465}3466}34673468void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {3469// We can safely ignore accessors here, since c2 will inline them anyway,3470// accessors are also always mature.3471if (!x->inlinee()->is_accessor()) {3472CodeEmitInfo* info = state_for(x, x->state(), true);3473// Notify the runtime very infrequently only to take care of counter overflows3474increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);3475}3476}34773478void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) {3479int freq_log = 0;3480int level = compilation()->env()->comp_level();3481if (level == CompLevel_limited_profile) {3482freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);3483} else if (level == CompLevel_full_profile) {3484freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);3485} else {3486ShouldNotReachHere();3487}3488// Increment the appropriate invocation/backedge counter and notify the runtime.3489increment_event_counter_impl(info, info->scope()->method(), (1 << freq_log) - 1, bci, backedge, true);3490}34913492void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,3493ciMethod *method, int frequency,3494int bci, bool backedge, bool notify) {3495assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");3496int level = _compilation->env()->comp_level();3497assert(level > CompLevel_simple, "Shouldn't be here");34983499int offset = -1;3500LIR_Opr counter_holder = NULL;3501if (level == CompLevel_limited_profile) {3502MethodCounters* counters_adr = method->ensure_method_counters();3503if (counters_adr == NULL) {3504bailout("method counters allocation failed");3505return;3506}3507counter_holder = new_pointer_register();3508__ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);3509offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :3510MethodCounters::invocation_counter_offset());3511} else if (level == CompLevel_full_profile) {3512counter_holder = new_register(T_METADATA);3513offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :3514MethodData::invocation_counter_offset());3515ciMethodData* md = method->method_data_or_null();3516assert(md != NULL, "Sanity");3517__ metadata2reg(md->constant_encoding(), counter_holder);3518} else {3519ShouldNotReachHere();3520}3521LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);3522LIR_Opr result = new_register(T_INT);3523__ load(counter, result);3524__ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result);3525__ store(result, counter);3526if (notify) {3527LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT);3528LIR_Opr meth = new_register(T_METADATA);3529__ metadata2reg(method->constant_encoding(), meth);3530__ logical_and(result, mask, result);3531__ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0));3532// The bci for info can point to cmp for if's we want the if bci3533CodeStub* overflow = new CounterOverflowStub(info, bci, meth);3534__ branch(lir_cond_equal, T_INT, overflow);3535__ branch_destination(overflow->continuation());3536}3537}35383539void LIRGenerator::do_RuntimeCall(RuntimeCall* x) {3540LIR_OprList* args = new LIR_OprList(x->number_of_arguments());3541BasicTypeList* signature = new BasicTypeList(x->number_of_arguments());35423543if (x->pass_thread()) {3544signature->append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread3545args->append(getThreadPointer());3546}35473548for (int i = 0; i < x->number_of_arguments(); i++) {3549Value a = x->argument_at(i);3550LIRItem* item = new LIRItem(a, this);3551item->load_item();3552args->append(item->result());3553signature->append(as_BasicType(a->type()));3554}35553556LIR_Opr result = call_runtime(signature, args, x->entry(), x->type(), NULL);3557if (x->type() == voidType) {3558set_no_result(x);3559} else {3560__ move(result, rlock_result(x));3561}3562}35633564#ifdef ASSERT3565void LIRGenerator::do_Assert(Assert *x) {3566ValueTag tag = x->x()->type()->tag();3567If::Condition cond = x->cond();35683569LIRItem xitem(x->x(), this);3570LIRItem yitem(x->y(), this);3571LIRItem* xin = &xitem;3572LIRItem* yin = &yitem;35733574assert(tag == intTag, "Only integer assertions are valid!");35753576xin->load_item();3577yin->dont_load_item();35783579set_no_result(x);35803581LIR_Opr left = xin->result();3582LIR_Opr right = yin->result();35833584__ lir_assert(lir_cond(x->cond()), left, right, x->message(), true);3585}3586#endif35873588void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) {358935903591Instruction *a = x->x();3592Instruction *b = x->y();3593if (!a || StressRangeCheckElimination) {3594assert(!b || StressRangeCheckElimination, "B must also be null");35953596CodeEmitInfo *info = state_for(x, x->state());3597CodeStub* stub = new PredicateFailedStub(info);35983599__ jump(stub);3600} else if (a->type()->as_IntConstant() && b->type()->as_IntConstant()) {3601int a_int = a->type()->as_IntConstant()->value();3602int b_int = b->type()->as_IntConstant()->value();36033604bool ok = false;36053606switch(x->cond()) {3607case Instruction::eql: ok = (a_int == b_int); break;3608case Instruction::neq: ok = (a_int != b_int); break;3609case Instruction::lss: ok = (a_int < b_int); break;3610case Instruction::leq: ok = (a_int <= b_int); break;3611case Instruction::gtr: ok = (a_int > b_int); break;3612case Instruction::geq: ok = (a_int >= b_int); break;3613case Instruction::aeq: ok = ((unsigned int)a_int >= (unsigned int)b_int); break;3614case Instruction::beq: ok = ((unsigned int)a_int <= (unsigned int)b_int); break;3615default: ShouldNotReachHere();3616}36173618if (ok) {36193620CodeEmitInfo *info = state_for(x, x->state());3621CodeStub* stub = new PredicateFailedStub(info);36223623__ jump(stub);3624}3625} else {36263627ValueTag tag = x->x()->type()->tag();3628If::Condition cond = x->cond();3629LIRItem xitem(x->x(), this);3630LIRItem yitem(x->y(), this);3631LIRItem* xin = &xitem;3632LIRItem* yin = &yitem;36333634assert(tag == intTag, "Only integer deoptimizations are valid!");36353636xin->load_item();3637yin->dont_load_item();3638set_no_result(x);36393640LIR_Opr left = xin->result();3641LIR_Opr right = yin->result();36423643CodeEmitInfo *info = state_for(x, x->state());3644CodeStub* stub = new PredicateFailedStub(info);36453646__ cmp(lir_cond(cond), left, right);3647__ branch(lir_cond(cond), right->type(), stub);3648}3649}365036513652LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {3653LIRItemList args(1);3654LIRItem value(arg1, this);3655args.append(&value);3656BasicTypeList signature;3657signature.append(as_BasicType(arg1->type()));36583659return call_runtime(&signature, &args, entry, result_type, info);3660}366136623663LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) {3664LIRItemList args(2);3665LIRItem value1(arg1, this);3666LIRItem value2(arg2, this);3667args.append(&value1);3668args.append(&value2);3669BasicTypeList signature;3670signature.append(as_BasicType(arg1->type()));3671signature.append(as_BasicType(arg2->type()));36723673return call_runtime(&signature, &args, entry, result_type, info);3674}367536763677LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args,3678address entry, ValueType* result_type, CodeEmitInfo* info) {3679// get a result register3680LIR_Opr phys_reg = LIR_OprFact::illegalOpr;3681LIR_Opr result = LIR_OprFact::illegalOpr;3682if (result_type->tag() != voidTag) {3683result = new_register(result_type);3684phys_reg = result_register_for(result_type);3685}36863687// move the arguments into the correct location3688CallingConvention* cc = frame_map()->c_calling_convention(signature);3689assert(cc->length() == args->length(), "argument mismatch");3690for (int i = 0; i < args->length(); i++) {3691LIR_Opr arg = args->at(i);3692LIR_Opr loc = cc->at(i);3693if (loc->is_register()) {3694__ move(arg, loc);3695} else {3696LIR_Address* addr = loc->as_address_ptr();3697// if (!can_store_as_constant(arg)) {3698// LIR_Opr tmp = new_register(arg->type());3699// __ move(arg, tmp);3700// arg = tmp;3701// }3702if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {3703__ unaligned_move(arg, addr);3704} else {3705__ move(arg, addr);3706}3707}3708}37093710if (info) {3711__ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);3712} else {3713__ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());3714}3715if (result->is_valid()) {3716__ move(phys_reg, result);3717}3718return result;3719}372037213722LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args,3723address entry, ValueType* result_type, CodeEmitInfo* info) {3724// get a result register3725LIR_Opr phys_reg = LIR_OprFact::illegalOpr;3726LIR_Opr result = LIR_OprFact::illegalOpr;3727if (result_type->tag() != voidTag) {3728result = new_register(result_type);3729phys_reg = result_register_for(result_type);3730}37313732// move the arguments into the correct location3733CallingConvention* cc = frame_map()->c_calling_convention(signature);37343735assert(cc->length() == args->length(), "argument mismatch");3736for (int i = 0; i < args->length(); i++) {3737LIRItem* arg = args->at(i);3738LIR_Opr loc = cc->at(i);3739if (loc->is_register()) {3740arg->load_item_force(loc);3741} else {3742LIR_Address* addr = loc->as_address_ptr();3743arg->load_for_store(addr->type());3744if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {3745__ unaligned_move(arg->result(), addr);3746} else {3747__ move(arg->result(), addr);3748}3749}3750}37513752if (info) {3753__ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);3754} else {3755__ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());3756}3757if (result->is_valid()) {3758__ move(phys_reg, result);3759}3760return result;3761}37623763void LIRGenerator::do_MemBar(MemBar* x) {3764if (os::is_MP()) {3765LIR_Code code = x->code();3766switch(code) {3767case lir_membar_acquire : __ membar_acquire(); break;3768case lir_membar_release : __ membar_release(); break;3769case lir_membar : __ membar(); break;3770case lir_membar_loadload : __ membar_loadload(); break;3771case lir_membar_storestore: __ membar_storestore(); break;3772case lir_membar_loadstore : __ membar_loadstore(); break;3773case lir_membar_storeload : __ membar_storeload(); break;3774default : ShouldNotReachHere(); break;3775}3776}3777}37783779LIR_Opr LIRGenerator::maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {3780if (x->check_boolean()) {3781LIR_Opr value_fixed = rlock_byte(T_BYTE);3782if (TwoOperandLIRForm) {3783__ move(value, value_fixed);3784__ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed);3785} else {3786__ logical_and(value, LIR_OprFact::intConst(1), value_fixed);3787}3788LIR_Opr klass = new_register(T_METADATA);3789__ move(new LIR_Address(array, oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, null_check_info);3790null_check_info = NULL;3791LIR_Opr layout = new_register(T_INT);3792__ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);3793int diffbit = Klass::layout_helper_boolean_diffbit();3794__ logical_and(layout, LIR_OprFact::intConst(diffbit), layout);3795__ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0));3796__ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE);3797value = value_fixed;3798}3799return value;3800}380138023803