Path: blob/master/src/hotspot/share/opto/callnode.cpp
40930 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "compiler/compileLog.hpp"26#include "ci/bcEscapeAnalyzer.hpp"27#include "compiler/oopMap.hpp"28#include "gc/shared/barrierSet.hpp"29#include "gc/shared/c2/barrierSetC2.hpp"30#include "interpreter/interpreter.hpp"31#include "opto/callGenerator.hpp"32#include "opto/callnode.hpp"33#include "opto/castnode.hpp"34#include "opto/convertnode.hpp"35#include "opto/escape.hpp"36#include "opto/locknode.hpp"37#include "opto/machnode.hpp"38#include "opto/matcher.hpp"39#include "opto/parse.hpp"40#include "opto/regalloc.hpp"41#include "opto/regmask.hpp"42#include "opto/rootnode.hpp"43#include "opto/runtime.hpp"44#include "runtime/sharedRuntime.hpp"45#include "utilities/powerOfTwo.hpp"46#include "code/vmreg.hpp"4748// Portions of code courtesy of Clifford Click4950// Optimization - Graph Style5152//=============================================================================53uint StartNode::size_of() const { return sizeof(*this); }54bool StartNode::cmp( const Node &n ) const55{ return _domain == ((StartNode&)n)._domain; }56const Type *StartNode::bottom_type() const { return _domain; }57const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }58#ifndef PRODUCT59void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}60void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }61#endif6263//------------------------------Ideal------------------------------------------64Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){65return remove_dead_region(phase, can_reshape) ? this : NULL;66}6768//------------------------------calling_convention-----------------------------69void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {70SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);71}7273//------------------------------Registers--------------------------------------74const RegMask &StartNode::in_RegMask(uint) const {75return RegMask::Empty;76}7778//------------------------------match------------------------------------------79// Construct projections for incoming parameters, and their RegMask info80Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {81switch (proj->_con) {82case TypeFunc::Control:83case TypeFunc::I_O:84case TypeFunc::Memory:85return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);86case TypeFunc::FramePtr:87return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);88case TypeFunc::ReturnAdr:89return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);90case TypeFunc::Parms:91default: {92uint parm_num = proj->_con - TypeFunc::Parms;93const Type *t = _domain->field_at(proj->_con);94if (t->base() == Type::Half) // 2nd half of Longs and Doubles95return new ConNode(Type::TOP);96uint ideal_reg = t->ideal_reg();97RegMask &rm = match->_calling_convention_mask[parm_num];98return new MachProjNode(this,proj->_con,rm,ideal_reg);99}100}101return NULL;102}103104//------------------------------StartOSRNode----------------------------------105// The method start node for an on stack replacement adapter106107//------------------------------osr_domain-----------------------------108const TypeTuple *StartOSRNode::osr_domain() {109const Type **fields = TypeTuple::fields(2);110fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer111112return TypeTuple::make(TypeFunc::Parms+1, fields);113}114115//=============================================================================116const char * const ParmNode::names[TypeFunc::Parms+1] = {117"Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"118};119120#ifndef PRODUCT121void ParmNode::dump_spec(outputStream *st) const {122if( _con < TypeFunc::Parms ) {123st->print("%s", names[_con]);124} else {125st->print("Parm%d: ",_con-TypeFunc::Parms);126// Verbose and WizardMode dump bottom_type for all nodes127if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);128}129}130131void ParmNode::dump_compact_spec(outputStream *st) const {132if (_con < TypeFunc::Parms) {133st->print("%s", names[_con]);134} else {135st->print("%d:", _con-TypeFunc::Parms);136// unconditionally dump bottom_type137bottom_type()->dump_on(st);138}139}140141// For a ParmNode, all immediate inputs and outputs are considered relevant142// both in compact and standard representation.143void ParmNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {144this->collect_nodes(in_rel, 1, false, false);145this->collect_nodes(out_rel, -1, false, false);146}147#endif148149uint ParmNode::ideal_reg() const {150switch( _con ) {151case TypeFunc::Control : // fall through152case TypeFunc::I_O : // fall through153case TypeFunc::Memory : return 0;154case TypeFunc::FramePtr : // fall through155case TypeFunc::ReturnAdr: return Op_RegP;156default : assert( _con > TypeFunc::Parms, "" );157// fall through158case TypeFunc::Parms : {159// Type of argument being passed160const Type *t = in(0)->as_Start()->_domain->field_at(_con);161return t->ideal_reg();162}163}164ShouldNotReachHere();165return 0;166}167168//=============================================================================169ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {170init_req(TypeFunc::Control,cntrl);171init_req(TypeFunc::I_O,i_o);172init_req(TypeFunc::Memory,memory);173init_req(TypeFunc::FramePtr,frameptr);174init_req(TypeFunc::ReturnAdr,retadr);175}176177Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){178return remove_dead_region(phase, can_reshape) ? this : NULL;179}180181const Type* ReturnNode::Value(PhaseGVN* phase) const {182return ( phase->type(in(TypeFunc::Control)) == Type::TOP)183? Type::TOP184: Type::BOTTOM;185}186187// Do we Match on this edge index or not? No edges on return nodes188uint ReturnNode::match_edge(uint idx) const {189return 0;190}191192193#ifndef PRODUCT194void ReturnNode::dump_req(outputStream *st) const {195// Dump the required inputs, enclosed in '(' and ')'196uint i; // Exit value of loop197for (i = 0; i < req(); i++) { // For all required inputs198if (i == TypeFunc::Parms) st->print("returns");199if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);200else st->print("_ ");201}202}203#endif204205//=============================================================================206RethrowNode::RethrowNode(207Node* cntrl,208Node* i_o,209Node* memory,210Node* frameptr,211Node* ret_adr,212Node* exception213) : Node(TypeFunc::Parms + 1) {214init_req(TypeFunc::Control , cntrl );215init_req(TypeFunc::I_O , i_o );216init_req(TypeFunc::Memory , memory );217init_req(TypeFunc::FramePtr , frameptr );218init_req(TypeFunc::ReturnAdr, ret_adr);219init_req(TypeFunc::Parms , exception);220}221222Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){223return remove_dead_region(phase, can_reshape) ? this : NULL;224}225226const Type* RethrowNode::Value(PhaseGVN* phase) const {227return (phase->type(in(TypeFunc::Control)) == Type::TOP)228? Type::TOP229: Type::BOTTOM;230}231232uint RethrowNode::match_edge(uint idx) const {233return 0;234}235236#ifndef PRODUCT237void RethrowNode::dump_req(outputStream *st) const {238// Dump the required inputs, enclosed in '(' and ')'239uint i; // Exit value of loop240for (i = 0; i < req(); i++) { // For all required inputs241if (i == TypeFunc::Parms) st->print("exception");242if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);243else st->print("_ ");244}245}246#endif247248//=============================================================================249// Do we Match on this edge index or not? Match only target address & method250uint TailCallNode::match_edge(uint idx) const {251return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;252}253254//=============================================================================255// Do we Match on this edge index or not? Match only target address & oop256uint TailJumpNode::match_edge(uint idx) const {257return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;258}259260//=============================================================================261JVMState::JVMState(ciMethod* method, JVMState* caller) :262_method(method) {263assert(method != NULL, "must be valid call site");264_bci = InvocationEntryBci;265_reexecute = Reexecute_Undefined;266debug_only(_bci = -99); // random garbage value267debug_only(_map = (SafePointNode*)-1);268_caller = caller;269_depth = 1 + (caller == NULL ? 0 : caller->depth());270_locoff = TypeFunc::Parms;271_stkoff = _locoff + _method->max_locals();272_monoff = _stkoff + _method->max_stack();273_scloff = _monoff;274_endoff = _monoff;275_sp = 0;276}277JVMState::JVMState(int stack_size) :278_method(NULL) {279_bci = InvocationEntryBci;280_reexecute = Reexecute_Undefined;281debug_only(_map = (SafePointNode*)-1);282_caller = NULL;283_depth = 1;284_locoff = TypeFunc::Parms;285_stkoff = _locoff;286_monoff = _stkoff + stack_size;287_scloff = _monoff;288_endoff = _monoff;289_sp = 0;290}291292//--------------------------------of_depth-------------------------------------293JVMState* JVMState::of_depth(int d) const {294const JVMState* jvmp = this;295assert(0 < d && (uint)d <= depth(), "oob");296for (int skip = depth() - d; skip > 0; skip--) {297jvmp = jvmp->caller();298}299assert(jvmp->depth() == (uint)d, "found the right one");300return (JVMState*)jvmp;301}302303//-----------------------------same_calls_as-----------------------------------304bool JVMState::same_calls_as(const JVMState* that) const {305if (this == that) return true;306if (this->depth() != that->depth()) return false;307const JVMState* p = this;308const JVMState* q = that;309for (;;) {310if (p->_method != q->_method) return false;311if (p->_method == NULL) return true; // bci is irrelevant312if (p->_bci != q->_bci) return false;313if (p->_reexecute != q->_reexecute) return false;314p = p->caller();315q = q->caller();316if (p == q) return true;317assert(p != NULL && q != NULL, "depth check ensures we don't run off end");318}319}320321//------------------------------debug_start------------------------------------322uint JVMState::debug_start() const {323debug_only(JVMState* jvmroot = of_depth(1));324assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");325return of_depth(1)->locoff();326}327328//-------------------------------debug_end-------------------------------------329uint JVMState::debug_end() const {330debug_only(JVMState* jvmroot = of_depth(1));331assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");332return endoff();333}334335//------------------------------debug_depth------------------------------------336uint JVMState::debug_depth() const {337uint total = 0;338for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {339total += jvmp->debug_size();340}341return total;342}343344#ifndef PRODUCT345346//------------------------------format_helper----------------------------------347// Given an allocation (a Chaitin object) and a Node decide if the Node carries348// any defined value or not. If it does, print out the register or constant.349static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {350if (n == NULL) { st->print(" NULL"); return; }351if (n->is_SafePointScalarObject()) {352// Scalar replacement.353SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();354scobjs->append_if_missing(spobj);355int sco_n = scobjs->find(spobj);356assert(sco_n >= 0, "");357st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);358return;359}360if (regalloc->node_regs_max_index() > 0 &&361OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined362char buf[50];363regalloc->dump_register(n,buf);364st->print(" %s%d]=%s",msg,i,buf);365} else { // No register, but might be constant366const Type *t = n->bottom_type();367switch (t->base()) {368case Type::Int:369st->print(" %s%d]=#" INT32_FORMAT,msg,i,t->is_int()->get_con());370break;371case Type::AnyPtr:372assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );373st->print(" %s%d]=#NULL",msg,i);374break;375case Type::AryPtr:376case Type::InstPtr:377st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));378break;379case Type::KlassPtr:380st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->klass()));381break;382case Type::MetadataPtr:383st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));384break;385case Type::NarrowOop:386st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));387break;388case Type::RawPtr:389st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));390break;391case Type::DoubleCon:392st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);393break;394case Type::FloatCon:395st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);396break;397case Type::Long:398st->print(" %s%d]=#" INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));399break;400case Type::Half:401case Type::Top:402st->print(" %s%d]=_",msg,i);403break;404default: ShouldNotReachHere();405}406}407}408409//---------------------print_method_with_lineno--------------------------------410void JVMState::print_method_with_lineno(outputStream* st, bool show_name) const {411if (show_name) _method->print_short_name(st);412413int lineno = _method->line_number_from_bci(_bci);414if (lineno != -1) {415st->print(" @ bci:%d (line %d)", _bci, lineno);416} else {417st->print(" @ bci:%d", _bci);418}419}420421//------------------------------format-----------------------------------------422void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {423st->print(" #");424if (_method) {425print_method_with_lineno(st, true);426} else {427st->print_cr(" runtime stub ");428return;429}430if (n->is_MachSafePoint()) {431GrowableArray<SafePointScalarObjectNode*> scobjs;432MachSafePointNode *mcall = n->as_MachSafePoint();433uint i;434// Print locals435for (i = 0; i < (uint)loc_size(); i++)436format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);437// Print stack438for (i = 0; i < (uint)stk_size(); i++) {439if ((uint)(_stkoff + i) >= mcall->len())440st->print(" oob ");441else442format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);443}444for (i = 0; (int)i < nof_monitors(); i++) {445Node *box = mcall->monitor_box(this, i);446Node *obj = mcall->monitor_obj(this, i);447if (regalloc->node_regs_max_index() > 0 &&448OptoReg::is_valid(regalloc->get_reg_first(box))) {449box = BoxLockNode::box_node(box);450format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);451} else {452OptoReg::Name box_reg = BoxLockNode::reg(box);453st->print(" MON-BOX%d=%s+%d",454i,455OptoReg::regname(OptoReg::c_frame_pointer),456regalloc->reg2offset(box_reg));457}458const char* obj_msg = "MON-OBJ[";459if (EliminateLocks) {460if (BoxLockNode::box_node(box)->is_eliminated())461obj_msg = "MON-OBJ(LOCK ELIMINATED)[";462}463format_helper(regalloc, st, obj, obj_msg, i, &scobjs);464}465466for (i = 0; i < (uint)scobjs.length(); i++) {467// Scalar replaced objects.468st->cr();469st->print(" # ScObj" INT32_FORMAT " ", i);470SafePointScalarObjectNode* spobj = scobjs.at(i);471ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass();472assert(cik->is_instance_klass() ||473cik->is_array_klass(), "Not supported allocation.");474ciInstanceKlass *iklass = NULL;475if (cik->is_instance_klass()) {476cik->print_name_on(st);477iklass = cik->as_instance_klass();478} else if (cik->is_type_array_klass()) {479cik->as_array_klass()->base_element_type()->print_name_on(st);480st->print("[%d]", spobj->n_fields());481} else if (cik->is_obj_array_klass()) {482ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();483if (cie->is_instance_klass()) {484cie->print_name_on(st);485} else if (cie->is_type_array_klass()) {486cie->as_array_klass()->base_element_type()->print_name_on(st);487} else {488ShouldNotReachHere();489}490st->print("[%d]", spobj->n_fields());491int ndim = cik->as_array_klass()->dimension() - 1;492while (ndim-- > 0) {493st->print("[]");494}495}496st->print("={");497uint nf = spobj->n_fields();498if (nf > 0) {499uint first_ind = spobj->first_index(mcall->jvms());500Node* fld_node = mcall->in(first_ind);501ciField* cifield;502if (iklass != NULL) {503st->print(" [");504cifield = iklass->nonstatic_field_at(0);505cifield->print_name_on(st);506format_helper(regalloc, st, fld_node, ":", 0, &scobjs);507} else {508format_helper(regalloc, st, fld_node, "[", 0, &scobjs);509}510for (uint j = 1; j < nf; j++) {511fld_node = mcall->in(first_ind+j);512if (iklass != NULL) {513st->print(", [");514cifield = iklass->nonstatic_field_at(j);515cifield->print_name_on(st);516format_helper(regalloc, st, fld_node, ":", j, &scobjs);517} else {518format_helper(regalloc, st, fld_node, ", [", j, &scobjs);519}520}521}522st->print(" }");523}524}525st->cr();526if (caller() != NULL) caller()->format(regalloc, n, st);527}528529530void JVMState::dump_spec(outputStream *st) const {531if (_method != NULL) {532bool printed = false;533if (!Verbose) {534// The JVMS dumps make really, really long lines.535// Take out the most boring parts, which are the package prefixes.536char buf[500];537stringStream namest(buf, sizeof(buf));538_method->print_short_name(&namest);539if (namest.count() < sizeof(buf)) {540const char* name = namest.base();541if (name[0] == ' ') ++name;542const char* endcn = strchr(name, ':'); // end of class name543if (endcn == NULL) endcn = strchr(name, '(');544if (endcn == NULL) endcn = name + strlen(name);545while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')546--endcn;547st->print(" %s", endcn);548printed = true;549}550}551print_method_with_lineno(st, !printed);552if(_reexecute == Reexecute_True)553st->print(" reexecute");554} else {555st->print(" runtime stub");556}557if (caller() != NULL) caller()->dump_spec(st);558}559560561void JVMState::dump_on(outputStream* st) const {562bool print_map = _map && !((uintptr_t)_map & 1) &&563((caller() == NULL) || (caller()->map() != _map));564if (print_map) {565if (_map->len() > _map->req()) { // _map->has_exceptions()566Node* ex = _map->in(_map->req()); // _map->next_exception()567// skip the first one; it's already being printed568while (ex != NULL && ex->len() > ex->req()) {569ex = ex->in(ex->req()); // ex->next_exception()570ex->dump(1);571}572}573_map->dump(Verbose ? 2 : 1);574}575if (caller() != NULL) {576caller()->dump_on(st);577}578st->print("JVMS depth=%d loc=%d stk=%d arg=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d reexecute=%s method=",579depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");580if (_method == NULL) {581st->print_cr("(none)");582} else {583_method->print_name(st);584st->cr();585if (bci() >= 0 && bci() < _method->code_size()) {586st->print(" bc: ");587_method->print_codes_on(bci(), bci()+1, st);588}589}590}591592// Extra way to dump a jvms from the debugger,593// to avoid a bug with C++ member function calls.594void dump_jvms(JVMState* jvms) {595jvms->dump();596}597#endif598599//--------------------------clone_shallow--------------------------------------600JVMState* JVMState::clone_shallow(Compile* C) const {601JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);602n->set_bci(_bci);603n->_reexecute = _reexecute;604n->set_locoff(_locoff);605n->set_stkoff(_stkoff);606n->set_monoff(_monoff);607n->set_scloff(_scloff);608n->set_endoff(_endoff);609n->set_sp(_sp);610n->set_map(_map);611return n;612}613614//---------------------------clone_deep----------------------------------------615JVMState* JVMState::clone_deep(Compile* C) const {616JVMState* n = clone_shallow(C);617for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {618p->_caller = p->_caller->clone_shallow(C);619}620assert(n->depth() == depth(), "sanity");621assert(n->debug_depth() == debug_depth(), "sanity");622return n;623}624625/**626* Reset map for all callers627*/628void JVMState::set_map_deep(SafePointNode* map) {629for (JVMState* p = this; p != NULL; p = p->_caller) {630p->set_map(map);631}632}633634// unlike set_map(), this is two-way setting.635void JVMState::bind_map(SafePointNode* map) {636set_map(map);637_map->set_jvms(this);638}639640// Adapt offsets in in-array after adding or removing an edge.641// Prerequisite is that the JVMState is used by only one node.642void JVMState::adapt_position(int delta) {643for (JVMState* jvms = this; jvms != NULL; jvms = jvms->caller()) {644jvms->set_locoff(jvms->locoff() + delta);645jvms->set_stkoff(jvms->stkoff() + delta);646jvms->set_monoff(jvms->monoff() + delta);647jvms->set_scloff(jvms->scloff() + delta);648jvms->set_endoff(jvms->endoff() + delta);649}650}651652// Mirror the stack size calculation in the deopt code653// How much stack space would we need at this point in the program in654// case of deoptimization?655int JVMState::interpreter_frame_size() const {656const JVMState* jvms = this;657int size = 0;658int callee_parameters = 0;659int callee_locals = 0;660int extra_args = method()->max_stack() - stk_size();661662while (jvms != NULL) {663int locks = jvms->nof_monitors();664int temps = jvms->stk_size();665bool is_top_frame = (jvms == this);666ciMethod* method = jvms->method();667668int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),669temps + callee_parameters,670extra_args,671locks,672callee_parameters,673callee_locals,674is_top_frame);675size += frame_size;676677callee_parameters = method->size_of_parameters();678callee_locals = method->max_locals();679extra_args = 0;680jvms = jvms->caller();681}682return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;683}684685//=============================================================================686bool CallNode::cmp( const Node &n ) const687{ return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }688#ifndef PRODUCT689void CallNode::dump_req(outputStream *st) const {690// Dump the required inputs, enclosed in '(' and ')'691uint i; // Exit value of loop692for (i = 0; i < req(); i++) { // For all required inputs693if (i == TypeFunc::Parms) st->print("(");694if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);695else st->print("_ ");696}697st->print(")");698}699700void CallNode::dump_spec(outputStream *st) const {701st->print(" ");702if (tf() != NULL) tf()->dump_on(st);703if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);704if (jvms() != NULL) jvms()->dump_spec(st);705}706#endif707708const Type *CallNode::bottom_type() const { return tf()->range(); }709const Type* CallNode::Value(PhaseGVN* phase) const {710if (phase->type(in(0)) == Type::TOP) return Type::TOP;711return tf()->range();712}713714//------------------------------calling_convention-----------------------------715void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {716// Use the standard compiler calling convention717SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);718}719720721//------------------------------match------------------------------------------722// Construct projections for control, I/O, memory-fields, ..., and723// return result(s) along with their RegMask info724Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {725switch (proj->_con) {726case TypeFunc::Control:727case TypeFunc::I_O:728case TypeFunc::Memory:729return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);730731case TypeFunc::Parms+1: // For LONG & DOUBLE returns732assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");733// 2nd half of doubles and longs734return new MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);735736case TypeFunc::Parms: { // Normal returns737uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();738OptoRegPair regs = Opcode() == Op_CallLeafVector739? match->vector_return_value(ideal_reg) // Calls into assembly vector routine740: is_CallRuntime()741? match->c_return_value(ideal_reg) // Calls into C runtime742: match-> return_value(ideal_reg); // Calls into compiled Java code743RegMask rm = RegMask(regs.first());744745if (Opcode() == Op_CallLeafVector) {746// If the return is in vector, compute appropriate regmask taking into account the whole range747if(ideal_reg >= Op_VecS && ideal_reg <= Op_VecZ) {748if(OptoReg::is_valid(regs.second())) {749for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {750rm.Insert(r);751}752}753}754}755756if( OptoReg::is_valid(regs.second()) )757rm.Insert( regs.second() );758return new MachProjNode(this,proj->_con,rm,ideal_reg);759}760761case TypeFunc::ReturnAdr:762case TypeFunc::FramePtr:763default:764ShouldNotReachHere();765}766return NULL;767}768769// Do we Match on this edge index or not? Match no edges770uint CallNode::match_edge(uint idx) const {771return 0;772}773774//775// Determine whether the call could modify the field of the specified776// instance at the specified offset.777//778bool CallNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {779assert((t_oop != NULL), "sanity");780if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {781const TypeTuple* args = _tf->domain();782Node* dest = NULL;783// Stubs that can be called once an ArrayCopyNode is expanded have784// different signatures. Look for the second pointer argument,785// that is the destination of the copy.786for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {787if (args->field_at(i)->isa_ptr()) {788j++;789if (j == 2) {790dest = in(i);791break;792}793}794}795guarantee(dest != NULL, "Call had only one ptr in, broken IR!");796if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {797return true;798}799return false;800}801if (t_oop->is_known_instance()) {802// The instance_id is set only for scalar-replaceable allocations which803// are not passed as arguments according to Escape Analysis.804return false;805}806if (t_oop->is_ptr_to_boxed_value()) {807ciKlass* boxing_klass = t_oop->klass();808if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {809// Skip unrelated boxing methods.810Node* proj = proj_out_or_null(TypeFunc::Parms);811if ((proj == NULL) || (phase->type(proj)->is_instptr()->klass() != boxing_klass)) {812return false;813}814}815if (is_CallJava() && as_CallJava()->method() != NULL) {816ciMethod* meth = as_CallJava()->method();817if (meth->is_getter()) {818return false;819}820// May modify (by reflection) if an boxing object is passed821// as argument or returned.822Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : NULL;823if (proj != NULL) {824const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();825if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||826(inst_t->klass() == boxing_klass))) {827return true;828}829}830const TypeTuple* d = tf()->domain();831for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {832const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();833if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||834(inst_t->klass() == boxing_klass))) {835return true;836}837}838return false;839}840}841return true;842}843844// Does this call have a direct reference to n other than debug information?845bool CallNode::has_non_debug_use(Node *n) {846const TypeTuple * d = tf()->domain();847for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {848Node *arg = in(i);849if (arg == n) {850return true;851}852}853return false;854}855856// Returns the unique CheckCastPP of a call857// or 'this' if there are several CheckCastPP or unexpected uses858// or returns NULL if there is no one.859Node *CallNode::result_cast() {860Node *cast = NULL;861862Node *p = proj_out_or_null(TypeFunc::Parms);863if (p == NULL)864return NULL;865866for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {867Node *use = p->fast_out(i);868if (use->is_CheckCastPP()) {869if (cast != NULL) {870return this; // more than 1 CheckCastPP871}872cast = use;873} else if (!use->is_Initialize() &&874!use->is_AddP() &&875use->Opcode() != Op_MemBarStoreStore) {876// Expected uses are restricted to a CheckCastPP, an Initialize877// node, a MemBarStoreStore (clone) and AddP nodes. If we878// encounter any other use (a Phi node can be seen in rare879// cases) return this to prevent incorrect optimizations.880return this;881}882}883return cast;884}885886887void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) {888projs->fallthrough_proj = NULL;889projs->fallthrough_catchproj = NULL;890projs->fallthrough_ioproj = NULL;891projs->catchall_ioproj = NULL;892projs->catchall_catchproj = NULL;893projs->fallthrough_memproj = NULL;894projs->catchall_memproj = NULL;895projs->resproj = NULL;896projs->exobj = NULL;897898for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {899ProjNode *pn = fast_out(i)->as_Proj();900if (pn->outcnt() == 0) continue;901switch (pn->_con) {902case TypeFunc::Control:903{904// For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj905projs->fallthrough_proj = pn;906const Node *cn = pn->unique_ctrl_out();907if (cn != NULL && cn->is_Catch()) {908ProjNode *cpn = NULL;909for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {910cpn = cn->fast_out(k)->as_Proj();911assert(cpn->is_CatchProj(), "must be a CatchProjNode");912if (cpn->_con == CatchProjNode::fall_through_index)913projs->fallthrough_catchproj = cpn;914else {915assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");916projs->catchall_catchproj = cpn;917}918}919}920break;921}922case TypeFunc::I_O:923if (pn->_is_io_use)924projs->catchall_ioproj = pn;925else926projs->fallthrough_ioproj = pn;927for (DUIterator j = pn->outs(); pn->has_out(j); j++) {928Node* e = pn->out(j);929if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {930assert(projs->exobj == NULL, "only one");931projs->exobj = e;932}933}934break;935case TypeFunc::Memory:936if (pn->_is_io_use)937projs->catchall_memproj = pn;938else939projs->fallthrough_memproj = pn;940break;941case TypeFunc::Parms:942projs->resproj = pn;943break;944default:945assert(false, "unexpected projection from allocation node.");946}947}948949// The resproj may not exist because the result could be ignored950// and the exception object may not exist if an exception handler951// swallows the exception but all the other must exist and be found.952assert(projs->fallthrough_proj != NULL, "must be found");953do_asserts = do_asserts && !Compile::current()->inlining_incrementally();954assert(!do_asserts || projs->fallthrough_catchproj != NULL, "must be found");955assert(!do_asserts || projs->fallthrough_memproj != NULL, "must be found");956assert(!do_asserts || projs->fallthrough_ioproj != NULL, "must be found");957assert(!do_asserts || projs->catchall_catchproj != NULL, "must be found");958if (separate_io_proj) {959assert(!do_asserts || projs->catchall_memproj != NULL, "must be found");960assert(!do_asserts || projs->catchall_ioproj != NULL, "must be found");961}962}963964Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {965#ifdef ASSERT966// Validate attached generator967CallGenerator* cg = generator();968if (cg != NULL) {969assert(is_CallStaticJava() && cg->is_mh_late_inline() ||970is_CallDynamicJava() && cg->is_virtual_late_inline(), "mismatch");971}972#endif // ASSERT973return SafePointNode::Ideal(phase, can_reshape);974}975976bool CallNode::is_call_to_arraycopystub() const {977if (_name != NULL && strstr(_name, "arraycopy") != 0) {978return true;979}980return false;981}982983//=============================================================================984uint CallJavaNode::size_of() const { return sizeof(*this); }985bool CallJavaNode::cmp( const Node &n ) const {986CallJavaNode &call = (CallJavaNode&)n;987return CallNode::cmp(call) && _method == call._method &&988_override_symbolic_info == call._override_symbolic_info;989}990991void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {992// Copy debug information and adjust JVMState information993uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;994uint new_dbg_start = tf()->domain()->cnt();995int jvms_adj = new_dbg_start - old_dbg_start;996assert (new_dbg_start == req(), "argument count mismatch");997Compile* C = phase->C;998999// SafePointScalarObject node could be referenced several times in debug info.1000// Use Dict to record cloned nodes.1001Dict* sosn_map = new Dict(cmpkey,hashkey);1002for (uint i = old_dbg_start; i < sfpt->req(); i++) {1003Node* old_in = sfpt->in(i);1004// Clone old SafePointScalarObjectNodes, adjusting their field contents.1005if (old_in != NULL && old_in->is_SafePointScalarObject()) {1006SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();1007bool new_node;1008Node* new_in = old_sosn->clone(sosn_map, new_node);1009if (new_node) { // New node?1010new_in->set_req(0, C->root()); // reset control edge1011new_in = phase->transform(new_in); // Register new node.1012}1013old_in = new_in;1014}1015add_req(old_in);1016}10171018// JVMS may be shared so clone it before we modify it1019set_jvms(sfpt->jvms() != NULL ? sfpt->jvms()->clone_deep(C) : NULL);1020for (JVMState *jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {1021jvms->set_map(this);1022jvms->set_locoff(jvms->locoff()+jvms_adj);1023jvms->set_stkoff(jvms->stkoff()+jvms_adj);1024jvms->set_monoff(jvms->monoff()+jvms_adj);1025jvms->set_scloff(jvms->scloff()+jvms_adj);1026jvms->set_endoff(jvms->endoff()+jvms_adj);1027}1028}10291030#ifdef ASSERT1031bool CallJavaNode::validate_symbolic_info() const {1032if (method() == NULL) {1033return true; // call into runtime or uncommon trap1034}1035ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());1036ciMethod* callee = method();1037if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {1038assert(override_symbolic_info(), "should be set");1039}1040assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");1041return true;1042}1043#endif10441045#ifndef PRODUCT1046void CallJavaNode::dump_spec(outputStream* st) const {1047if( _method ) _method->print_short_name(st);1048CallNode::dump_spec(st);1049}10501051void CallJavaNode::dump_compact_spec(outputStream* st) const {1052if (_method) {1053_method->print_short_name(st);1054} else {1055st->print("<?>");1056}1057}1058#endif10591060//=============================================================================1061uint CallStaticJavaNode::size_of() const { return sizeof(*this); }1062bool CallStaticJavaNode::cmp( const Node &n ) const {1063CallStaticJavaNode &call = (CallStaticJavaNode&)n;1064return CallJavaNode::cmp(call);1065}10661067Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {1068CallGenerator* cg = generator();1069if (can_reshape && cg != NULL) {1070assert(IncrementalInlineMH, "required");1071assert(cg->call_node() == this, "mismatch");1072assert(cg->is_mh_late_inline(), "not virtual");10731074// Check whether this MH handle call becomes a candidate for inlining.1075ciMethod* callee = cg->method();1076vmIntrinsics::ID iid = callee->intrinsic_id();1077if (iid == vmIntrinsics::_invokeBasic) {1078if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {1079phase->C->prepend_late_inline(cg);1080set_generator(NULL);1081}1082} else if (iid == vmIntrinsics::_linkToNative) {1083if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP /* NEP */1084&& in(TypeFunc::Parms + 1)->Opcode() == Op_ConL /* address */) {1085phase->C->prepend_late_inline(cg);1086set_generator(NULL);1087}1088} else {1089assert(callee->has_member_arg(), "wrong type of call?");1090if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {1091phase->C->prepend_late_inline(cg);1092set_generator(NULL);1093}1094}1095}1096return CallNode::Ideal(phase, can_reshape);1097}10981099//----------------------------uncommon_trap_request----------------------------1100// If this is an uncommon trap, return the request code, else zero.1101int CallStaticJavaNode::uncommon_trap_request() const {1102if (_name != NULL && !strcmp(_name, "uncommon_trap")) {1103return extract_uncommon_trap_request(this);1104}1105return 0;1106}1107int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {1108#ifndef PRODUCT1109if (!(call->req() > TypeFunc::Parms &&1110call->in(TypeFunc::Parms) != NULL &&1111call->in(TypeFunc::Parms)->is_Con() &&1112call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {1113assert(in_dump() != 0, "OK if dumping");1114tty->print("[bad uncommon trap]");1115return 0;1116}1117#endif1118return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();1119}11201121#ifndef PRODUCT1122void CallStaticJavaNode::dump_spec(outputStream *st) const {1123st->print("# Static ");1124if (_name != NULL) {1125st->print("%s", _name);1126int trap_req = uncommon_trap_request();1127if (trap_req != 0) {1128char buf[100];1129st->print("(%s)",1130Deoptimization::format_trap_request(buf, sizeof(buf),1131trap_req));1132}1133st->print(" ");1134}1135CallJavaNode::dump_spec(st);1136}11371138void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {1139if (_method) {1140_method->print_short_name(st);1141} else if (_name) {1142st->print("%s", _name);1143} else {1144st->print("<?>");1145}1146}1147#endif11481149//=============================================================================1150uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }1151bool CallDynamicJavaNode::cmp( const Node &n ) const {1152CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;1153return CallJavaNode::cmp(call);1154}11551156Node* CallDynamicJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {1157CallGenerator* cg = generator();1158if (can_reshape && cg != NULL) {1159assert(IncrementalInlineVirtual, "required");1160assert(cg->call_node() == this, "mismatch");1161assert(cg->is_virtual_late_inline(), "not virtual");11621163// Recover symbolic info for method resolution.1164ciMethod* caller = jvms()->method();1165ciBytecodeStream iter(caller);1166iter.force_bci(jvms()->bci());11671168bool not_used1;1169ciSignature* not_used2;1170ciMethod* orig_callee = iter.get_method(not_used1, ¬_used2); // callee in the bytecode1171ciKlass* holder = iter.get_declared_method_holder();1172if (orig_callee->is_method_handle_intrinsic()) {1173assert(_override_symbolic_info, "required");1174orig_callee = method();1175holder = method()->holder();1176}11771178ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);11791180Node* receiver_node = in(TypeFunc::Parms);1181const TypeOopPtr* receiver_type = phase->type(receiver_node)->isa_oopptr();11821183int not_used3;1184bool call_does_dispatch;1185ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true /*is_virtual*/,1186call_does_dispatch, not_used3); // out-parameters1187if (!call_does_dispatch) {1188// Register for late inlining.1189cg->set_callee_method(callee);1190phase->C->prepend_late_inline(cg); // MH late inlining prepends to the list, so do the same1191set_generator(NULL);1192}1193}1194return CallNode::Ideal(phase, can_reshape);1195}11961197#ifndef PRODUCT1198void CallDynamicJavaNode::dump_spec(outputStream *st) const {1199st->print("# Dynamic ");1200CallJavaNode::dump_spec(st);1201}1202#endif12031204//=============================================================================1205uint CallRuntimeNode::size_of() const { return sizeof(*this); }1206bool CallRuntimeNode::cmp( const Node &n ) const {1207CallRuntimeNode &call = (CallRuntimeNode&)n;1208return CallNode::cmp(call) && !strcmp(_name,call._name);1209}1210#ifndef PRODUCT1211void CallRuntimeNode::dump_spec(outputStream *st) const {1212st->print("# ");1213st->print("%s", _name);1214CallNode::dump_spec(st);1215}1216#endif1217uint CallLeafVectorNode::size_of() const { return sizeof(*this); }1218bool CallLeafVectorNode::cmp( const Node &n ) const {1219CallLeafVectorNode &call = (CallLeafVectorNode&)n;1220return CallLeafNode::cmp(call) && _num_bits == call._num_bits;1221}12221223//=============================================================================1224uint CallNativeNode::size_of() const { return sizeof(*this); }1225bool CallNativeNode::cmp( const Node &n ) const {1226CallNativeNode &call = (CallNativeNode&)n;1227return CallNode::cmp(call) && !strcmp(_name,call._name)1228&& _arg_regs == call._arg_regs && _ret_regs == call._ret_regs;1229}1230Node* CallNativeNode::match(const ProjNode *proj, const Matcher *matcher) {1231switch (proj->_con) {1232case TypeFunc::Control:1233case TypeFunc::I_O:1234case TypeFunc::Memory:1235return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);1236case TypeFunc::ReturnAdr:1237case TypeFunc::FramePtr:1238ShouldNotReachHere();1239case TypeFunc::Parms: {1240const Type* field_at_con = tf()->range()->field_at(proj->_con);1241const BasicType bt = field_at_con->basic_type();1242OptoReg::Name optoreg = OptoReg::as_OptoReg(_ret_regs.at(proj->_con - TypeFunc::Parms));1243OptoRegPair regs;1244if (bt == T_DOUBLE || bt == T_LONG) {1245regs.set2(optoreg);1246} else {1247regs.set1(optoreg);1248}1249RegMask rm = RegMask(regs.first());1250if(OptoReg::is_valid(regs.second()))1251rm.Insert(regs.second());1252return new MachProjNode(this, proj->_con, rm, field_at_con->ideal_reg());1253}1254case TypeFunc::Parms + 1: {1255assert(tf()->range()->field_at(proj->_con) == Type::HALF, "Expected HALF");1256assert(_ret_regs.at(proj->_con - TypeFunc::Parms) == VMRegImpl::Bad(), "Unexpected register for Type::HALF");1257// 2nd half of doubles and longs1258return new MachProjNode(this, proj->_con, RegMask::Empty, (uint) OptoReg::Bad);1259}1260default:1261ShouldNotReachHere();1262}1263return NULL;1264}1265#ifndef PRODUCT1266void CallNativeNode::print_regs(const GrowableArray<VMReg>& regs, outputStream* st) {1267st->print("{ ");1268for (int i = 0; i < regs.length(); i++) {1269regs.at(i)->print_on(st);1270if (i < regs.length() - 1) {1271st->print(", ");1272}1273}1274st->print(" } ");1275}12761277void CallNativeNode::dump_spec(outputStream *st) const {1278st->print("# ");1279st->print("%s ", _name);1280st->print("_arg_regs: ");1281print_regs(_arg_regs, st);1282st->print("_ret_regs: ");1283print_regs(_ret_regs, st);1284CallNode::dump_spec(st);1285}1286#endif12871288//------------------------------calling_convention-----------------------------1289void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {1290SharedRuntime::c_calling_convention(sig_bt, parm_regs, /*regs2=*/nullptr, argcnt);1291}12921293void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {1294#ifdef ASSERT1295assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,1296"return vector size must match");1297const TypeTuple* d = tf()->domain();1298for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {1299Node* arg = in(i);1300assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,1301"vector argument size must match");1302}1303#endif13041305SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);1306}13071308void CallNativeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {1309assert((tf()->domain()->cnt() - TypeFunc::Parms) == argcnt, "arg counts must match!");1310#ifdef ASSERT1311for (uint i = 0; i < argcnt; i++) {1312assert(tf()->domain()->field_at(TypeFunc::Parms + i)->basic_type() == sig_bt[i], "types must match!");1313}1314#endif1315for (uint i = 0; i < argcnt; i++) {1316switch (sig_bt[i]) {1317case T_BOOLEAN:1318case T_CHAR:1319case T_BYTE:1320case T_SHORT:1321case T_INT:1322case T_FLOAT:1323parm_regs[i].set1(_arg_regs.at(i));1324break;1325case T_LONG:1326case T_DOUBLE:1327assert((i + 1) < argcnt && sig_bt[i + 1] == T_VOID, "expecting half");1328parm_regs[i].set2(_arg_regs.at(i));1329break;1330case T_VOID: // Halves of longs and doubles1331assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");1332assert(_arg_regs.at(i) == VMRegImpl::Bad(), "expecting bad reg");1333parm_regs[i].set_bad();1334break;1335default:1336ShouldNotReachHere();1337break;1338}1339}1340}13411342//=============================================================================1343//------------------------------calling_convention-----------------------------134413451346//=============================================================================1347#ifndef PRODUCT1348void CallLeafNode::dump_spec(outputStream *st) const {1349st->print("# ");1350st->print("%s", _name);1351CallNode::dump_spec(st);1352}1353#endif13541355//=============================================================================13561357void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {1358assert(verify_jvms(jvms), "jvms must match");1359int loc = jvms->locoff() + idx;1360if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {1361// If current local idx is top then local idx - 1 could1362// be a long/double that needs to be killed since top could1363// represent the 2nd half ofthe long/double.1364uint ideal = in(loc -1)->ideal_reg();1365if (ideal == Op_RegD || ideal == Op_RegL) {1366// set other (low index) half to top1367set_req(loc - 1, in(loc));1368}1369}1370set_req(loc, c);1371}13721373uint SafePointNode::size_of() const { return sizeof(*this); }1374bool SafePointNode::cmp( const Node &n ) const {1375return (&n == this); // Always fail except on self1376}13771378//-------------------------set_next_exception----------------------------------1379void SafePointNode::set_next_exception(SafePointNode* n) {1380assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");1381if (len() == req()) {1382if (n != NULL) add_prec(n);1383} else {1384set_prec(req(), n);1385}1386}138713881389//----------------------------next_exception-----------------------------------1390SafePointNode* SafePointNode::next_exception() const {1391if (len() == req()) {1392return NULL;1393} else {1394Node* n = in(req());1395assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");1396return (SafePointNode*) n;1397}1398}139914001401//------------------------------Ideal------------------------------------------1402// Skip over any collapsed Regions1403Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {1404assert(_jvms == NULL || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");1405return remove_dead_region(phase, can_reshape) ? this : NULL;1406}14071408//------------------------------Identity---------------------------------------1409// Remove obviously duplicate safepoints1410Node* SafePointNode::Identity(PhaseGVN* phase) {14111412// If you have back to back safepoints, remove one1413if( in(TypeFunc::Control)->is_SafePoint() )1414return in(TypeFunc::Control);14151416// Transforming long counted loops requires a safepoint node. Do not1417// eliminate a safepoint until loop opts are over.1418if (in(0)->is_Proj() && !phase->C->major_progress()) {1419Node *n0 = in(0)->in(0);1420// Check if he is a call projection (except Leaf Call)1421if( n0->is_Catch() ) {1422n0 = n0->in(0)->in(0);1423assert( n0->is_Call(), "expect a call here" );1424}1425if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {1426// Don't remove a safepoint belonging to an OuterStripMinedLoopEndNode.1427// If the loop dies, they will be removed together.1428if (has_out_with(Op_OuterStripMinedLoopEnd)) {1429return this;1430}1431// Useless Safepoint, so remove it1432return in(TypeFunc::Control);1433}1434}14351436return this;1437}14381439//------------------------------Value------------------------------------------1440const Type* SafePointNode::Value(PhaseGVN* phase) const {1441if (phase->type(in(0)) == Type::TOP) {1442return Type::TOP;1443}1444if (in(0) == this) {1445return Type::TOP; // Dead infinite loop1446}1447return Type::CONTROL;1448}14491450#ifndef PRODUCT1451void SafePointNode::dump_spec(outputStream *st) const {1452st->print(" SafePoint ");1453_replaced_nodes.dump(st);1454}14551456// The related nodes of a SafepointNode are all data inputs, excluding the1457// control boundary, as well as all outputs till level 2 (to include projection1458// nodes and targets). In compact mode, just include inputs till level 1 and1459// outputs as before.1460void SafePointNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {1461if (compact) {1462this->collect_nodes(in_rel, 1, false, false);1463} else {1464this->collect_nodes_in_all_data(in_rel, false);1465}1466this->collect_nodes(out_rel, -2, false, false);1467}1468#endif14691470const RegMask &SafePointNode::in_RegMask(uint idx) const {1471if( idx < TypeFunc::Parms ) return RegMask::Empty;1472// Values outside the domain represent debug info1473return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);1474}1475const RegMask &SafePointNode::out_RegMask() const {1476return RegMask::Empty;1477}147814791480void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {1481assert((int)grow_by > 0, "sanity");1482int monoff = jvms->monoff();1483int scloff = jvms->scloff();1484int endoff = jvms->endoff();1485assert(endoff == (int)req(), "no other states or debug info after me");1486Node* top = Compile::current()->top();1487for (uint i = 0; i < grow_by; i++) {1488ins_req(monoff, top);1489}1490jvms->set_monoff(monoff + grow_by);1491jvms->set_scloff(scloff + grow_by);1492jvms->set_endoff(endoff + grow_by);1493}14941495void SafePointNode::push_monitor(const FastLockNode *lock) {1496// Add a LockNode, which points to both the original BoxLockNode (the1497// stack space for the monitor) and the Object being locked.1498const int MonitorEdges = 2;1499assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");1500assert(req() == jvms()->endoff(), "correct sizing");1501int nextmon = jvms()->scloff();1502if (GenerateSynchronizationCode) {1503ins_req(nextmon, lock->box_node());1504ins_req(nextmon+1, lock->obj_node());1505} else {1506Node* top = Compile::current()->top();1507ins_req(nextmon, top);1508ins_req(nextmon, top);1509}1510jvms()->set_scloff(nextmon + MonitorEdges);1511jvms()->set_endoff(req());1512}15131514void SafePointNode::pop_monitor() {1515// Delete last monitor from debug info1516debug_only(int num_before_pop = jvms()->nof_monitors());1517const int MonitorEdges = 2;1518assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");1519int scloff = jvms()->scloff();1520int endoff = jvms()->endoff();1521int new_scloff = scloff - MonitorEdges;1522int new_endoff = endoff - MonitorEdges;1523jvms()->set_scloff(new_scloff);1524jvms()->set_endoff(new_endoff);1525while (scloff > new_scloff) del_req_ordered(--scloff);1526assert(jvms()->nof_monitors() == num_before_pop-1, "");1527}15281529Node *SafePointNode::peek_monitor_box() const {1530int mon = jvms()->nof_monitors() - 1;1531assert(mon >= 0, "must have a monitor");1532return monitor_box(jvms(), mon);1533}15341535Node *SafePointNode::peek_monitor_obj() const {1536int mon = jvms()->nof_monitors() - 1;1537assert(mon >= 0, "must have a monitor");1538return monitor_obj(jvms(), mon);1539}15401541// Do we Match on this edge index or not? Match no edges1542uint SafePointNode::match_edge(uint idx) const {1543return (TypeFunc::Parms == idx);1544}15451546void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {1547assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");1548int nb = igvn->C->root()->find_prec_edge(this);1549if (nb != -1) {1550igvn->C->root()->rm_prec(nb);1551}1552}15531554//============== SafePointScalarObjectNode ==============15551556SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,1557#ifdef ASSERT1558Node* alloc,1559#endif1560uint first_index,1561uint n_fields,1562bool is_auto_box) :1563TypeNode(tp, 1), // 1 control input -- seems required. Get from root.1564_first_index(first_index),1565_n_fields(n_fields),1566_is_auto_box(is_auto_box)1567#ifdef ASSERT1568, _alloc(alloc)1569#endif1570{1571#ifdef ASSERT1572if (!alloc->is_Allocate()1573&& !(alloc->Opcode() == Op_VectorBox)1574&& (!alloc->is_CallStaticJava() || !alloc->as_CallStaticJava()->is_boxing_method())) {1575alloc->dump();1576assert(false, "unexpected call node");1577}1578#endif1579init_class_id(Class_SafePointScalarObject);1580}15811582// Do not allow value-numbering for SafePointScalarObject node.1583uint SafePointScalarObjectNode::hash() const { return NO_HASH; }1584bool SafePointScalarObjectNode::cmp( const Node &n ) const {1585return (&n == this); // Always fail except on self1586}15871588uint SafePointScalarObjectNode::ideal_reg() const {1589return 0; // No matching to machine instruction1590}15911592const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {1593return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);1594}15951596const RegMask &SafePointScalarObjectNode::out_RegMask() const {1597return RegMask::Empty;1598}15991600uint SafePointScalarObjectNode::match_edge(uint idx) const {1601return 0;1602}16031604SafePointScalarObjectNode*1605SafePointScalarObjectNode::clone(Dict* sosn_map, bool& new_node) const {1606void* cached = (*sosn_map)[(void*)this];1607if (cached != NULL) {1608new_node = false;1609return (SafePointScalarObjectNode*)cached;1610}1611new_node = true;1612SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();1613sosn_map->Insert((void*)this, (void*)res);1614return res;1615}161616171618#ifndef PRODUCT1619void SafePointScalarObjectNode::dump_spec(outputStream *st) const {1620st->print(" # fields@[%d..%d]", first_index(),1621first_index() + n_fields() - 1);1622}16231624#endif16251626//=============================================================================1627uint AllocateNode::size_of() const { return sizeof(*this); }16281629AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,1630Node *ctrl, Node *mem, Node *abio,1631Node *size, Node *klass_node, Node *initial_test)1632: CallNode(atype, NULL, TypeRawPtr::BOTTOM)1633{1634init_class_id(Class_Allocate);1635init_flags(Flag_is_macro);1636_is_scalar_replaceable = false;1637_is_non_escaping = false;1638_is_allocation_MemBar_redundant = false;1639Node *topnode = C->top();16401641init_req( TypeFunc::Control , ctrl );1642init_req( TypeFunc::I_O , abio );1643init_req( TypeFunc::Memory , mem );1644init_req( TypeFunc::ReturnAdr, topnode );1645init_req( TypeFunc::FramePtr , topnode );1646init_req( AllocSize , size);1647init_req( KlassNode , klass_node);1648init_req( InitialTest , initial_test);1649init_req( ALength , topnode);1650C->add_macro_node(this);1651}16521653void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)1654{1655assert(initializer != NULL &&1656initializer->is_initializer() &&1657!initializer->is_static(),1658"unexpected initializer method");1659BCEscapeAnalyzer* analyzer = initializer->get_bcea();1660if (analyzer == NULL) {1661return;1662}16631664// Allocation node is first parameter in its initializer1665if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {1666_is_allocation_MemBar_redundant = true;1667}1668}1669Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {1670Node* mark_node = NULL;1671// For now only enable fast locking for non-array types1672if (UseBiasedLocking && Opcode() == Op_Allocate) {1673Node* klass_node = in(AllocateNode::KlassNode);1674Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));1675mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);1676} else {1677mark_node = phase->MakeConX(markWord::prototype().value());1678}1679return mark_node;1680}16811682//=============================================================================1683Node* AllocateArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) {1684if (remove_dead_region(phase, can_reshape)) return this;1685// Don't bother trying to transform a dead node1686if (in(0) && in(0)->is_top()) return NULL;16871688const Type* type = phase->type(Ideal_length());1689if (type->isa_int() && type->is_int()->_hi < 0) {1690if (can_reshape) {1691PhaseIterGVN *igvn = phase->is_IterGVN();1692// Unreachable fall through path (negative array length),1693// the allocation can only throw so disconnect it.1694Node* proj = proj_out_or_null(TypeFunc::Control);1695Node* catchproj = NULL;1696if (proj != NULL) {1697for (DUIterator_Fast imax, i = proj->fast_outs(imax); i < imax; i++) {1698Node *cn = proj->fast_out(i);1699if (cn->is_Catch()) {1700catchproj = cn->as_Multi()->proj_out_or_null(CatchProjNode::fall_through_index);1701break;1702}1703}1704}1705if (catchproj != NULL && catchproj->outcnt() > 0 &&1706(catchproj->outcnt() > 1 ||1707catchproj->unique_out()->Opcode() != Op_Halt)) {1708assert(catchproj->is_CatchProj(), "must be a CatchProjNode");1709Node* nproj = catchproj->clone();1710igvn->register_new_node_with_optimizer(nproj);17111712Node *frame = new ParmNode( phase->C->start(), TypeFunc::FramePtr );1713frame = phase->transform(frame);1714// Halt & Catch Fire1715Node* halt = new HaltNode(nproj, frame, "unexpected negative array length");1716phase->C->root()->add_req(halt);1717phase->transform(halt);17181719igvn->replace_node(catchproj, phase->C->top());1720return this;1721}1722} else {1723// Can't correct it during regular GVN so register for IGVN1724phase->C->record_for_igvn(this);1725}1726}1727return NULL;1728}17291730// Retrieve the length from the AllocateArrayNode. Narrow the type with a1731// CastII, if appropriate. If we are not allowed to create new nodes, and1732// a CastII is appropriate, return NULL.1733Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {1734Node *length = in(AllocateNode::ALength);1735assert(length != NULL, "length is not null");17361737const TypeInt* length_type = phase->find_int_type(length);1738const TypeAryPtr* ary_type = oop_type->isa_aryptr();17391740if (ary_type != NULL && length_type != NULL) {1741const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);1742if (narrow_length_type != length_type) {1743// Assert one of:1744// - the narrow_length is 01745// - the narrow_length is not wider than length1746assert(narrow_length_type == TypeInt::ZERO ||1747length_type->is_con() && narrow_length_type->is_con() &&1748(narrow_length_type->_hi <= length_type->_lo) ||1749(narrow_length_type->_hi <= length_type->_hi &&1750narrow_length_type->_lo >= length_type->_lo),1751"narrow type must be narrower than length type");17521753// Return NULL if new nodes are not allowed1754if (!allow_new_nodes) return NULL;1755// Create a cast which is control dependent on the initialization to1756// propagate the fact that the array length must be positive.1757InitializeNode* init = initialization();1758assert(init != NULL, "initialization not found");1759length = new CastIINode(length, narrow_length_type);1760length->set_req(0, init->proj_out_or_null(0));1761}1762}17631764return length;1765}17661767//=============================================================================1768uint LockNode::size_of() const { return sizeof(*this); }17691770// Redundant lock elimination1771//1772// There are various patterns of locking where we release and1773// immediately reacquire a lock in a piece of code where no operations1774// occur in between that would be observable. In those cases we can1775// skip releasing and reacquiring the lock without violating any1776// fairness requirements. Doing this around a loop could cause a lock1777// to be held for a very long time so we concentrate on non-looping1778// control flow. We also require that the operations are fully1779// redundant meaning that we don't introduce new lock operations on1780// some paths so to be able to eliminate it on others ala PRE. This1781// would probably require some more extensive graph manipulation to1782// guarantee that the memory edges were all handled correctly.1783//1784// Assuming p is a simple predicate which can't trap in any way and s1785// is a synchronized method consider this code:1786//1787// s();1788// if (p)1789// s();1790// else1791// s();1792// s();1793//1794// 1. The unlocks of the first call to s can be eliminated if the1795// locks inside the then and else branches are eliminated.1796//1797// 2. The unlocks of the then and else branches can be eliminated if1798// the lock of the final call to s is eliminated.1799//1800// Either of these cases subsumes the simple case of sequential control flow1801//1802// Addtionally we can eliminate versions without the else case:1803//1804// s();1805// if (p)1806// s();1807// s();1808//1809// 3. In this case we eliminate the unlock of the first s, the lock1810// and unlock in the then case and the lock in the final s.1811//1812// Note also that in all these cases the then/else pieces don't have1813// to be trivial as long as they begin and end with synchronization1814// operations.1815//1816// s();1817// if (p)1818// s();1819// f();1820// s();1821// s();1822//1823// The code will work properly for this case, leaving in the unlock1824// before the call to f and the relock after it.1825//1826// A potentially interesting case which isn't handled here is when the1827// locking is partially redundant.1828//1829// s();1830// if (p)1831// s();1832//1833// This could be eliminated putting unlocking on the else case and1834// eliminating the first unlock and the lock in the then side.1835// Alternatively the unlock could be moved out of the then side so it1836// was after the merge and the first unlock and second lock1837// eliminated. This might require less manipulation of the memory1838// state to get correct.1839//1840// Additionally we might allow work between a unlock and lock before1841// giving up eliminating the locks. The current code disallows any1842// conditional control flow between these operations. A formulation1843// similar to partial redundancy elimination computing the1844// availability of unlocking and the anticipatability of locking at a1845// program point would allow detection of fully redundant locking with1846// some amount of work in between. I'm not sure how often I really1847// think that would occur though. Most of the cases I've seen1848// indicate it's likely non-trivial work would occur in between.1849// There may be other more complicated constructs where we could1850// eliminate locking but I haven't seen any others appear as hot or1851// interesting.1852//1853// Locking and unlocking have a canonical form in ideal that looks1854// roughly like this:1855//1856// <obj>1857// | \\------+1858// | \ \1859// | BoxLock \1860// | | | \1861// | | \ \1862// | | FastLock1863// | | /1864// | | /1865// | | |1866//1867// Lock1868// |1869// Proj #01870// |1871// MembarAcquire1872// |1873// Proj #01874//1875// MembarRelease1876// |1877// Proj #01878// |1879// Unlock1880// |1881// Proj #01882//1883//1884// This code proceeds by processing Lock nodes during PhaseIterGVN1885// and searching back through its control for the proper code1886// patterns. Once it finds a set of lock and unlock operations to1887// eliminate they are marked as eliminatable which causes the1888// expansion of the Lock and Unlock macro nodes to make the operation a NOP1889//1890//=============================================================================18911892//1893// Utility function to skip over uninteresting control nodes. Nodes skipped are:1894// - copy regions. (These may not have been optimized away yet.)1895// - eliminated locking nodes1896//1897static Node *next_control(Node *ctrl) {1898if (ctrl == NULL)1899return NULL;1900while (1) {1901if (ctrl->is_Region()) {1902RegionNode *r = ctrl->as_Region();1903Node *n = r->is_copy();1904if (n == NULL)1905break; // hit a region, return it1906else1907ctrl = n;1908} else if (ctrl->is_Proj()) {1909Node *in0 = ctrl->in(0);1910if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {1911ctrl = in0->in(0);1912} else {1913break;1914}1915} else {1916break; // found an interesting control1917}1918}1919return ctrl;1920}1921//1922// Given a control, see if it's the control projection of an Unlock which1923// operating on the same object as lock.1924//1925bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,1926GrowableArray<AbstractLockNode*> &lock_ops) {1927ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;1928if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {1929Node *n = ctrl_proj->in(0);1930if (n != NULL && n->is_Unlock()) {1931UnlockNode *unlock = n->as_Unlock();1932BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();1933Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());1934Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());1935if (lock_obj->eqv_uncast(unlock_obj) &&1936BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&1937!unlock->is_eliminated()) {1938lock_ops.append(unlock);1939return true;1940}1941}1942}1943return false;1944}19451946//1947// Find the lock matching an unlock. Returns null if a safepoint1948// or complicated control is encountered first.1949LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {1950LockNode *lock_result = NULL;1951// find the matching lock, or an intervening safepoint1952Node *ctrl = next_control(unlock->in(0));1953while (1) {1954assert(ctrl != NULL, "invalid control graph");1955assert(!ctrl->is_Start(), "missing lock for unlock");1956if (ctrl->is_top()) break; // dead control path1957if (ctrl->is_Proj()) ctrl = ctrl->in(0);1958if (ctrl->is_SafePoint()) {1959break; // found a safepoint (may be the lock we are searching for)1960} else if (ctrl->is_Region()) {1961// Check for a simple diamond pattern. Punt on anything more complicated1962if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {1963Node *in1 = next_control(ctrl->in(1));1964Node *in2 = next_control(ctrl->in(2));1965if (((in1->is_IfTrue() && in2->is_IfFalse()) ||1966(in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {1967ctrl = next_control(in1->in(0)->in(0));1968} else {1969break;1970}1971} else {1972break;1973}1974} else {1975ctrl = next_control(ctrl->in(0)); // keep searching1976}1977}1978if (ctrl->is_Lock()) {1979LockNode *lock = ctrl->as_Lock();1980BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();1981Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());1982Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());1983if (lock_obj->eqv_uncast(unlock_obj) &&1984BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {1985lock_result = lock;1986}1987}1988return lock_result;1989}19901991// This code corresponds to case 3 above.19921993bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,1994GrowableArray<AbstractLockNode*> &lock_ops) {1995Node* if_node = node->in(0);1996bool if_true = node->is_IfTrue();19971998if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {1999Node *lock_ctrl = next_control(if_node->in(0));2000if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {2001Node* lock1_node = NULL;2002ProjNode* proj = if_node->as_If()->proj_out(!if_true);2003if (if_true) {2004if (proj->is_IfFalse() && proj->outcnt() == 1) {2005lock1_node = proj->unique_out();2006}2007} else {2008if (proj->is_IfTrue() && proj->outcnt() == 1) {2009lock1_node = proj->unique_out();2010}2011}2012if (lock1_node != NULL && lock1_node->is_Lock()) {2013LockNode *lock1 = lock1_node->as_Lock();2014BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();2015Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());2016Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());2017if (lock_obj->eqv_uncast(lock1_obj) &&2018BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&2019!lock1->is_eliminated()) {2020lock_ops.append(lock1);2021return true;2022}2023}2024}2025}20262027lock_ops.trunc_to(0);2028return false;2029}20302031bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,2032GrowableArray<AbstractLockNode*> &lock_ops) {2033// check each control merging at this point for a matching unlock.2034// in(0) should be self edge so skip it.2035for (int i = 1; i < (int)region->req(); i++) {2036Node *in_node = next_control(region->in(i));2037if (in_node != NULL) {2038if (find_matching_unlock(in_node, lock, lock_ops)) {2039// found a match so keep on checking.2040continue;2041} else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {2042continue;2043}20442045// If we fall through to here then it was some kind of node we2046// don't understand or there wasn't a matching unlock, so give2047// up trying to merge locks.2048lock_ops.trunc_to(0);2049return false;2050}2051}2052return true;20532054}20552056#ifndef PRODUCT2057//2058// Create a counter which counts the number of times this lock is acquired2059//2060void AbstractLockNode::create_lock_counter(JVMState* state) {2061_counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);2062}20632064void AbstractLockNode::set_eliminated_lock_counter() {2065if (_counter) {2066// Update the counter to indicate that this lock was eliminated.2067// The counter update code will stay around even though the2068// optimizer will eliminate the lock operation itself.2069_counter->set_tag(NamedCounter::EliminatedLockCounter);2070}2071}20722073const char* AbstractLockNode::_kind_names[] = {"Regular", "NonEscObj", "Coarsened", "Nested"};20742075void AbstractLockNode::dump_spec(outputStream* st) const {2076st->print("%s ", _kind_names[_kind]);2077CallNode::dump_spec(st);2078}20792080void AbstractLockNode::dump_compact_spec(outputStream* st) const {2081st->print("%s", _kind_names[_kind]);2082}20832084// The related set of lock nodes includes the control boundary.2085void AbstractLockNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {2086if (compact) {2087this->collect_nodes(in_rel, 1, false, false);2088} else {2089this->collect_nodes_in_all_data(in_rel, true);2090}2091this->collect_nodes(out_rel, -2, false, false);2092}2093#endif20942095//=============================================================================2096Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {20972098// perform any generic optimizations first (returns 'this' or NULL)2099Node *result = SafePointNode::Ideal(phase, can_reshape);2100if (result != NULL) return result;2101// Don't bother trying to transform a dead node2102if (in(0) && in(0)->is_top()) return NULL;21032104// Now see if we can optimize away this lock. We don't actually2105// remove the locking here, we simply set the _eliminate flag which2106// prevents macro expansion from expanding the lock. Since we don't2107// modify the graph, the value returned from this function is the2108// one computed above.2109if (can_reshape && EliminateLocks && !is_non_esc_obj()) {2110//2111// If we are locking an non-escaped object, the lock/unlock is unnecessary2112//2113ConnectionGraph *cgr = phase->C->congraph();2114if (cgr != NULL && cgr->not_global_escape(obj_node())) {2115assert(!is_eliminated() || is_coarsened(), "sanity");2116// The lock could be marked eliminated by lock coarsening2117// code during first IGVN before EA. Replace coarsened flag2118// to eliminate all associated locks/unlocks.2119#ifdef ASSERT2120this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");2121#endif2122this->set_non_esc_obj();2123return result;2124}21252126//2127// Try lock coarsening2128//2129PhaseIterGVN* iter = phase->is_IterGVN();2130if (iter != NULL && !is_eliminated()) {21312132GrowableArray<AbstractLockNode*> lock_ops;21332134Node *ctrl = next_control(in(0));21352136// now search back for a matching Unlock2137if (find_matching_unlock(ctrl, this, lock_ops)) {2138// found an unlock directly preceding this lock. This is the2139// case of single unlock directly control dependent on a2140// single lock which is the trivial version of case 1 or 2.2141} else if (ctrl->is_Region() ) {2142if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {2143// found lock preceded by multiple unlocks along all paths2144// joining at this point which is case 3 in description above.2145}2146} else {2147// see if this lock comes from either half of an if and the2148// predecessors merges unlocks and the other half of the if2149// performs a lock.2150if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {2151// found unlock splitting to an if with locks on both branches.2152}2153}21542155if (lock_ops.length() > 0) {2156// add ourselves to the list of locks to be eliminated.2157lock_ops.append(this);21582159#ifndef PRODUCT2160if (PrintEliminateLocks) {2161int locks = 0;2162int unlocks = 0;2163for (int i = 0; i < lock_ops.length(); i++) {2164AbstractLockNode* lock = lock_ops.at(i);2165if (lock->Opcode() == Op_Lock)2166locks++;2167else2168unlocks++;2169if (Verbose) {2170lock->dump(1);2171}2172}2173tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks);2174}2175#endif21762177// for each of the identified locks, mark them2178// as eliminatable2179for (int i = 0; i < lock_ops.length(); i++) {2180AbstractLockNode* lock = lock_ops.at(i);21812182// Mark it eliminated by coarsening and update any counters2183#ifdef ASSERT2184lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");2185#endif2186lock->set_coarsened();2187}2188} else if (ctrl->is_Region() &&2189iter->_worklist.member(ctrl)) {2190// We weren't able to find any opportunities but the region this2191// lock is control dependent on hasn't been processed yet so put2192// this lock back on the worklist so we can check again once any2193// region simplification has occurred.2194iter->_worklist.push(this);2195}2196}2197}21982199return result;2200}22012202//=============================================================================2203bool LockNode::is_nested_lock_region() {2204return is_nested_lock_region(NULL);2205}22062207// p is used for access to compilation log; no logging if NULL2208bool LockNode::is_nested_lock_region(Compile * c) {2209BoxLockNode* box = box_node()->as_BoxLock();2210int stk_slot = box->stack_slot();2211if (stk_slot <= 0) {2212#ifdef ASSERT2213this->log_lock_optimization(c, "eliminate_lock_INLR_1");2214#endif2215return false; // External lock or it is not Box (Phi node).2216}22172218// Ignore complex cases: merged locks or multiple locks.2219Node* obj = obj_node();2220LockNode* unique_lock = NULL;2221if (!box->is_simple_lock_region(&unique_lock, obj)) {2222#ifdef ASSERT2223this->log_lock_optimization(c, "eliminate_lock_INLR_2a");2224#endif2225return false;2226}2227if (unique_lock != this) {2228#ifdef ASSERT2229this->log_lock_optimization(c, "eliminate_lock_INLR_2b");2230#endif2231return false;2232}22332234BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();2235obj = bs->step_over_gc_barrier(obj);2236// Look for external lock for the same object.2237SafePointNode* sfn = this->as_SafePoint();2238JVMState* youngest_jvms = sfn->jvms();2239int max_depth = youngest_jvms->depth();2240for (int depth = 1; depth <= max_depth; depth++) {2241JVMState* jvms = youngest_jvms->of_depth(depth);2242int num_mon = jvms->nof_monitors();2243// Loop over monitors2244for (int idx = 0; idx < num_mon; idx++) {2245Node* obj_node = sfn->monitor_obj(jvms, idx);2246obj_node = bs->step_over_gc_barrier(obj_node);2247BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();2248if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {2249return true;2250}2251}2252}2253#ifdef ASSERT2254this->log_lock_optimization(c, "eliminate_lock_INLR_3");2255#endif2256return false;2257}22582259//=============================================================================2260uint UnlockNode::size_of() const { return sizeof(*this); }22612262//=============================================================================2263Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {22642265// perform any generic optimizations first (returns 'this' or NULL)2266Node *result = SafePointNode::Ideal(phase, can_reshape);2267if (result != NULL) return result;2268// Don't bother trying to transform a dead node2269if (in(0) && in(0)->is_top()) return NULL;22702271// Now see if we can optimize away this unlock. We don't actually2272// remove the unlocking here, we simply set the _eliminate flag which2273// prevents macro expansion from expanding the unlock. Since we don't2274// modify the graph, the value returned from this function is the2275// one computed above.2276// Escape state is defined after Parse phase.2277if (can_reshape && EliminateLocks && !is_non_esc_obj()) {2278//2279// If we are unlocking an non-escaped object, the lock/unlock is unnecessary.2280//2281ConnectionGraph *cgr = phase->C->congraph();2282if (cgr != NULL && cgr->not_global_escape(obj_node())) {2283assert(!is_eliminated() || is_coarsened(), "sanity");2284// The lock could be marked eliminated by lock coarsening2285// code during first IGVN before EA. Replace coarsened flag2286// to eliminate all associated locks/unlocks.2287#ifdef ASSERT2288this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");2289#endif2290this->set_non_esc_obj();2291}2292}2293return result;2294}22952296const char * AbstractLockNode::kind_as_string() const {2297return is_coarsened() ? "coarsened" :2298is_nested() ? "nested" :2299is_non_esc_obj() ? "non_escaping" :2300"?";2301}23022303void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag) const {2304if (C == NULL) {2305return;2306}2307CompileLog* log = C->log();2308if (log != NULL) {2309log->begin_head("%s lock='%d' compile_id='%d' class_id='%s' kind='%s'",2310tag, is_Lock(), C->compile_id(),2311is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",2312kind_as_string());2313log->stamp();2314log->end_head();2315JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();2316while (p != NULL) {2317log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));2318p = p->caller();2319}2320log->tail(tag);2321}2322}23232324bool CallNode::may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr *t_oop, PhaseTransform *phase) {2325if (dest_t->is_known_instance() && t_oop->is_known_instance()) {2326return dest_t->instance_id() == t_oop->instance_id();2327}23282329if (dest_t->isa_instptr() && !dest_t->klass()->equals(phase->C->env()->Object_klass())) {2330// clone2331if (t_oop->isa_aryptr()) {2332return false;2333}2334if (!t_oop->isa_instptr()) {2335return true;2336}2337if (dest_t->klass()->is_subtype_of(t_oop->klass()) || t_oop->klass()->is_subtype_of(dest_t->klass())) {2338return true;2339}2340// unrelated2341return false;2342}23432344if (dest_t->isa_aryptr()) {2345// arraycopy or array clone2346if (t_oop->isa_instptr()) {2347return false;2348}2349if (!t_oop->isa_aryptr()) {2350return true;2351}23522353const Type* elem = dest_t->is_aryptr()->elem();2354if (elem == Type::BOTTOM) {2355// An array but we don't know what elements are2356return true;2357}23582359dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();2360uint dest_alias = phase->C->get_alias_index(dest_t);2361uint t_oop_alias = phase->C->get_alias_index(t_oop);23622363return dest_alias == t_oop_alias;2364}23652366return true;2367}236823692370