< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/bcEscapeAnalyzer.hpp"

  26 #include "code/vmreg.hpp"
  27 #include "compiler/compileLog.hpp"
  28 #include "compiler/oopMap.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "gc/shared/c2/barrierSetC2.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "opto/callGenerator.hpp"
  33 #include "opto/callnode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/convertnode.hpp"
  36 #include "opto/escape.hpp"

  37 #include "opto/locknode.hpp"
  38 #include "opto/machnode.hpp"
  39 #include "opto/matcher.hpp"
  40 #include "opto/parse.hpp"
  41 #include "opto/regalloc.hpp"
  42 #include "opto/regmask.hpp"
  43 #include "opto/rootnode.hpp"
  44 #include "opto/runtime.hpp"
  45 #include "runtime/sharedRuntime.hpp"

  46 #include "utilities/powerOfTwo.hpp"
  47 
  48 // Portions of code courtesy of Clifford Click
  49 
  50 // Optimization - Graph Style
  51 
  52 //=============================================================================
  53 uint StartNode::size_of() const { return sizeof(*this); }
  54 bool StartNode::cmp( const Node &n ) const
  55 { return _domain == ((StartNode&)n)._domain; }
  56 const Type *StartNode::bottom_type() const { return _domain; }
  57 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
  58 #ifndef PRODUCT
  59 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
  60 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
  61 #endif
  62 
  63 //------------------------------Ideal------------------------------------------
  64 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
  65   return remove_dead_region(phase, can_reshape) ? this : nullptr;
  66 }
  67 
  68 //------------------------------calling_convention-----------------------------
  69 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
  70   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
  71 }
  72 
  73 //------------------------------Registers--------------------------------------
  74 const RegMask &StartNode::in_RegMask(uint) const {
  75   return RegMask::EMPTY;
  76 }
  77 
  78 //------------------------------match------------------------------------------
  79 // Construct projections for incoming parameters, and their RegMask info
  80 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
  81   switch (proj->_con) {
  82   case TypeFunc::Control:
  83   case TypeFunc::I_O:
  84   case TypeFunc::Memory:
  85     return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
  86   case TypeFunc::FramePtr:
  87     return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
  88   case TypeFunc::ReturnAdr:
  89     return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
  90   case TypeFunc::Parms:
  91   default: {
  92       uint parm_num = proj->_con - TypeFunc::Parms;
  93       const Type *t = _domain->field_at(proj->_con);
  94       if (t->base() == Type::Half)  // 2nd half of Longs and Doubles
  95         return new ConNode(Type::TOP);
  96       uint ideal_reg = t->ideal_reg();
  97       RegMask &rm = match->_calling_convention_mask[parm_num];
  98       return new MachProjNode(this,proj->_con,rm,ideal_reg);
  99     }
 100   }
 101   return nullptr;
 102 }
 103 
 104 //------------------------------StartOSRNode----------------------------------
 105 // The method start node for an on stack replacement adapter
 106 
 107 //------------------------------osr_domain-----------------------------
 108 const TypeTuple *StartOSRNode::osr_domain() {
 109   const Type **fields = TypeTuple::fields(2);
 110   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
 111 
 112   return TypeTuple::make(TypeFunc::Parms+1, fields);
 113 }
 114 
 115 //=============================================================================
 116 const char * const ParmNode::names[TypeFunc::Parms+1] = {
 117   "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
 118 };
 119 
 120 #ifndef PRODUCT
 121 void ParmNode::dump_spec(outputStream *st) const {
 122   if( _con < TypeFunc::Parms ) {
 123     st->print("%s", names[_con]);
 124   } else {
 125     st->print("Parm%d: ",_con-TypeFunc::Parms);
 126     // Verbose and WizardMode dump bottom_type for all nodes
 127     if( !Verbose && !WizardMode )   bottom_type()->dump_on(st);
 128   }
 129 }
 130 
 131 void ParmNode::dump_compact_spec(outputStream *st) const {
 132   if (_con < TypeFunc::Parms) {
 133     st->print("%s", names[_con]);
 134   } else {

 482       if (cik->is_instance_klass()) {
 483         cik->print_name_on(st);
 484         iklass = cik->as_instance_klass();
 485       } else if (cik->is_type_array_klass()) {
 486         cik->as_array_klass()->base_element_type()->print_name_on(st);
 487         st->print("[%d]", spobj->n_fields());
 488       } else if (cik->is_obj_array_klass()) {
 489         ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
 490         if (cie->is_instance_klass()) {
 491           cie->print_name_on(st);
 492         } else if (cie->is_type_array_klass()) {
 493           cie->as_array_klass()->base_element_type()->print_name_on(st);
 494         } else {
 495           ShouldNotReachHere();
 496         }
 497         st->print("[%d]", spobj->n_fields());
 498         int ndim = cik->as_array_klass()->dimension() - 1;
 499         while (ndim-- > 0) {
 500           st->print("[]");
 501         }








 502       }
 503       st->print("={");
 504       uint nf = spobj->n_fields();
 505       if (nf > 0) {
 506         uint first_ind = spobj->first_index(mcall->jvms());







 507         Node* fld_node = mcall->in(first_ind);
 508         ciField* cifield;
 509         if (iklass != nullptr) {
 510           st->print(" [");
 511           cifield = iklass->nonstatic_field_at(0);
 512           cifield->print_name_on(st);
 513           format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
 514         } else {
 515           format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
 516         }
 517         for (uint j = 1; j < nf; j++) {
 518           fld_node = mcall->in(first_ind+j);
 519           if (iklass != nullptr) {
 520             st->print(", [");
 521             cifield = iklass->nonstatic_field_at(j);
 522             cifield->print_name_on(st);
 523             format_helper(regalloc, st, fld_node, ":", j, &scobjs);
 524           } else {
 525             format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
 526           }
 527         }
 528       }
 529       st->print(" }");
 530     }
 531   }
 532   st->cr();
 533   if (caller() != nullptr) caller()->format(regalloc, n, st);
 534 }
 535 
 536 
 537 void JVMState::dump_spec(outputStream *st) const {
 538   if (_method != nullptr) {
 539     bool printed = false;
 540     if (!Verbose) {
 541       // The JVMS dumps make really, really long lines.
 542       // Take out the most boring parts, which are the package prefixes.

 737     tf()->dump_on(st);
 738   }
 739   if (_cnt != COUNT_UNKNOWN) {
 740     st->print(" C=%f", _cnt);
 741   }
 742   const Node* const klass_node = in(KlassNode);
 743   if (klass_node != nullptr) {
 744     const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
 745 
 746     if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
 747       st->print(" allocationKlass:");
 748       klass_ptr->exact_klass()->print_name_on(st);
 749     }
 750   }
 751   if (jvms() != nullptr) {
 752     jvms()->dump_spec(st);
 753   }
 754 }
 755 #endif
 756 
 757 const Type *CallNode::bottom_type() const { return tf()->range(); }
 758 const Type* CallNode::Value(PhaseGVN* phase) const {
 759   if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
 760     return Type::TOP;
 761   }
 762   return tf()->range();
 763 }
 764 
 765 //------------------------------calling_convention-----------------------------
 766 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







 767   // Use the standard compiler calling convention
 768   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
 769 }
 770 
 771 
 772 //------------------------------match------------------------------------------
 773 // Construct projections for control, I/O, memory-fields, ..., and
 774 // return result(s) along with their RegMask info
 775 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
 776   switch (proj->_con) {
 777   case TypeFunc::Control:
 778   case TypeFunc::I_O:
 779   case TypeFunc::Memory:
 780     return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
 781 
 782   case TypeFunc::Parms+1:       // For LONG & DOUBLE returns
 783     assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
 784     // 2nd half of doubles and longs
 785     return new MachProjNode(this,proj->_con, RegMask::EMPTY, (uint)OptoReg::Bad);
 786 
 787   case TypeFunc::Parms: {       // Normal returns
 788     uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
 789     OptoRegPair regs = Opcode() == Op_CallLeafVector
 790       ? match->vector_return_value(ideal_reg)      // Calls into assembly vector routine
 791       : is_CallRuntime()
 792         ? match->c_return_value(ideal_reg)  // Calls into C runtime
 793         : match->  return_value(ideal_reg); // Calls into compiled Java code
 794     RegMask rm = RegMask(regs.first());
 795 
 796     if (Opcode() == Op_CallLeafVector) {
 797       // If the return is in vector, compute appropriate regmask taking into account the whole range
 798       if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
 799         if(OptoReg::is_valid(regs.second())) {
 800           for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
 801             rm.insert(r);
 802           }
 803         }









 804       }
 805     }
 806 
 807     if( OptoReg::is_valid(regs.second()) )
 808       rm.insert(regs.second());
 809     return new MachProjNode(this,proj->_con,rm,ideal_reg);
 810   }
 811 






 812   case TypeFunc::ReturnAdr:
 813   case TypeFunc::FramePtr:
 814   default:
 815     ShouldNotReachHere();
 816   }
 817   return nullptr;
 818 }
 819 
 820 // Do we Match on this edge index or not?  Match no edges
 821 uint CallNode::match_edge(uint idx) const {
 822   return 0;
 823 }
 824 
 825 //
 826 // Determine whether the call could modify the field of the specified
 827 // instance at the specified offset.
 828 //
 829 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
 830   assert((t_oop != nullptr), "sanity");
 831   if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
 832     const TypeTuple* args = _tf->domain();
 833     Node* dest = nullptr;
 834     // Stubs that can be called once an ArrayCopyNode is expanded have
 835     // different signatures. Look for the second pointer argument,
 836     // that is the destination of the copy.
 837     for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
 838       if (args->field_at(i)->isa_ptr()) {
 839         j++;
 840         if (j == 2) {
 841           dest = in(i);
 842           break;
 843         }
 844       }
 845     }
 846     guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
 847     if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
 848       return true;
 849     }
 850     return false;
 851   }
 852   if (t_oop->is_known_instance()) {

 861       Node* proj = proj_out_or_null(TypeFunc::Parms);
 862       if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
 863         return false;
 864       }
 865     }
 866     if (is_CallJava() && as_CallJava()->method() != nullptr) {
 867       ciMethod* meth = as_CallJava()->method();
 868       if (meth->is_getter()) {
 869         return false;
 870       }
 871       // May modify (by reflection) if an boxing object is passed
 872       // as argument or returned.
 873       Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
 874       if (proj != nullptr) {
 875         const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
 876         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 877                                    (inst_t->instance_klass() == boxing_klass))) {
 878           return true;
 879         }
 880       }
 881       const TypeTuple* d = tf()->domain();
 882       for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 883         const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
 884         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 885                                  (inst_t->instance_klass() == boxing_klass))) {
 886           return true;
 887         }
 888       }
 889       return false;
 890     }
 891   }
 892   return true;
 893 }
 894 
 895 // Does this call have a direct reference to n other than debug information?
 896 bool CallNode::has_non_debug_use(Node *n) {
 897   const TypeTuple * d = tf()->domain();
 898   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 899     Node *arg = in(i);
 900     if (arg == n) {
 901       return true;
 902     }
 903   }
 904   return false;
 905 }
 906 











 907 // Returns the unique CheckCastPP of a call
 908 // or 'this' if there are several CheckCastPP or unexpected uses
 909 // or returns null if there is no one.
 910 Node *CallNode::result_cast() {
 911   Node *cast = nullptr;
 912 
 913   Node *p = proj_out_or_null(TypeFunc::Parms);
 914   if (p == nullptr)
 915     return nullptr;
 916 
 917   for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
 918     Node *use = p->fast_out(i);
 919     if (use->is_CheckCastPP()) {
 920       if (cast != nullptr) {
 921         return this;  // more than 1 CheckCastPP
 922       }
 923       cast = use;
 924     } else if (!use->is_Initialize() &&
 925                !use->is_AddP() &&
 926                use->Opcode() != Op_MemBarStoreStore) {
 927       // Expected uses are restricted to a CheckCastPP, an Initialize
 928       // node, a MemBarStoreStore (clone) and AddP nodes. If we
 929       // encounter any other use (a Phi node can be seen in rare
 930       // cases) return this to prevent incorrect optimizations.
 931       return this;
 932     }
 933   }
 934   return cast;
 935 }
 936 
 937 
 938 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) const {
 939   projs->fallthrough_proj      = nullptr;
 940   projs->fallthrough_catchproj = nullptr;
 941   projs->fallthrough_ioproj    = nullptr;
 942   projs->catchall_ioproj       = nullptr;
 943   projs->catchall_catchproj    = nullptr;
 944   projs->fallthrough_memproj   = nullptr;
 945   projs->catchall_memproj      = nullptr;
 946   projs->resproj               = nullptr;
 947   projs->exobj                 = nullptr;





 948 
 949   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 950     ProjNode *pn = fast_out(i)->as_Proj();
 951     if (pn->outcnt() == 0) continue;
 952     switch (pn->_con) {
 953     case TypeFunc::Control:
 954       {
 955         // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
 956         projs->fallthrough_proj = pn;
 957         const Node* cn = pn->unique_ctrl_out_or_null();
 958         if (cn != nullptr && cn->is_Catch()) {
 959           ProjNode *cpn = nullptr;
 960           for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
 961             cpn = cn->fast_out(k)->as_Proj();
 962             assert(cpn->is_CatchProj(), "must be a CatchProjNode");
 963             if (cpn->_con == CatchProjNode::fall_through_index)
 964               projs->fallthrough_catchproj = cpn;
 965             else {
 966               assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
 967               projs->catchall_catchproj = cpn;

 973     case TypeFunc::I_O:
 974       if (pn->_is_io_use)
 975         projs->catchall_ioproj = pn;
 976       else
 977         projs->fallthrough_ioproj = pn;
 978       for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
 979         Node* e = pn->out(j);
 980         if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
 981           assert(projs->exobj == nullptr, "only one");
 982           projs->exobj = e;
 983         }
 984       }
 985       break;
 986     case TypeFunc::Memory:
 987       if (pn->_is_io_use)
 988         projs->catchall_memproj = pn;
 989       else
 990         projs->fallthrough_memproj = pn;
 991       break;
 992     case TypeFunc::Parms:
 993       projs->resproj = pn;
 994       break;
 995     default:
 996       assert(false, "unexpected projection from allocation node.");


 997     }
 998   }
 999 
1000   // The resproj may not exist because the result could be ignored
1001   // and the exception object may not exist if an exception handler
1002   // swallows the exception but all the other must exist and be found.
1003   assert(projs->fallthrough_proj      != nullptr, "must be found");
1004   do_asserts = do_asserts && !Compile::current()->inlining_incrementally();

1005   assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1006   assert(!do_asserts || projs->fallthrough_memproj   != nullptr, "must be found");
1007   assert(!do_asserts || projs->fallthrough_ioproj    != nullptr, "must be found");
1008   assert(!do_asserts || projs->catchall_catchproj    != nullptr, "must be found");
1009   if (separate_io_proj) {
1010     assert(!do_asserts || projs->catchall_memproj    != nullptr, "must be found");
1011     assert(!do_asserts || projs->catchall_ioproj     != nullptr, "must be found");
1012   }

1013 }
1014 
1015 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1016 #ifdef ASSERT
1017   // Validate attached generator
1018   CallGenerator* cg = generator();
1019   if (cg != nullptr) {
1020     assert((is_CallStaticJava()  && cg->is_mh_late_inline()) ||
1021            (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1022   }
1023 #endif // ASSERT
1024   return SafePointNode::Ideal(phase, can_reshape);
1025 }
1026 
1027 bool CallNode::is_call_to_arraycopystub() const {
1028   if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1029     return true;
1030   }
1031   return false;
1032 }
1033 
1034 //=============================================================================
1035 uint CallJavaNode::size_of() const { return sizeof(*this); }
1036 bool CallJavaNode::cmp( const Node &n ) const {
1037   CallJavaNode &call = (CallJavaNode&)n;
1038   return CallNode::cmp(call) && _method == call._method &&
1039          _override_symbolic_info == call._override_symbolic_info;
1040 }
1041 
1042 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1043   // Copy debug information and adjust JVMState information
1044   uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
1045   uint new_dbg_start = tf()->domain()->cnt();
1046   int jvms_adj  = new_dbg_start - old_dbg_start;
1047   assert (new_dbg_start == req(), "argument count mismatch");
1048   Compile* C = phase->C;
1049 
1050   // SafePointScalarObject node could be referenced several times in debug info.
1051   // Use Dict to record cloned nodes.
1052   Dict* sosn_map = new Dict(cmpkey,hashkey);
1053   for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1054     Node* old_in = sfpt->in(i);
1055     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1056     if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1057       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1058       bool new_node;
1059       Node* new_in = old_sosn->clone(sosn_map, new_node);
1060       if (new_node) { // New node?
1061         new_in->set_req(0, C->root()); // reset control edge
1062         new_in = phase->transform(new_in); // Register new node.
1063       }
1064       old_in = new_in;
1065     }
1066     add_req(old_in);
1067   }
1068 
1069   // JVMS may be shared so clone it before we modify it
1070   set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1071   for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1072     jvms->set_map(this);
1073     jvms->set_locoff(jvms->locoff()+jvms_adj);
1074     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1075     jvms->set_monoff(jvms->monoff()+jvms_adj);
1076     jvms->set_scloff(jvms->scloff()+jvms_adj);
1077     jvms->set_endoff(jvms->endoff()+jvms_adj);
1078   }
1079 }
1080 
1081 #ifdef ASSERT
1082 bool CallJavaNode::validate_symbolic_info() const {
1083   if (method() == nullptr) {
1084     return true; // call into runtime or uncommon trap
1085   }




1086   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1087   ciMethod* callee = method();
1088   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1089     assert(override_symbolic_info(), "should be set");
1090   }
1091   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1092   return true;
1093 }
1094 #endif
1095 
1096 #ifndef PRODUCT
1097 void CallJavaNode::dump_spec(outputStream* st) const {
1098   if( _method ) _method->print_short_name(st);
1099   CallNode::dump_spec(st);
1100 }
1101 
1102 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1103   if (_method) {
1104     _method->print_short_name(st);
1105   } else {

1108 }
1109 #endif
1110 
1111 void CallJavaNode::register_for_late_inline() {
1112   if (generator() != nullptr) {
1113     Compile::current()->prepend_late_inline(generator());
1114     set_generator(nullptr);
1115   } else {
1116     assert(false, "repeated inline attempt");
1117   }
1118 }
1119 
1120 //=============================================================================
1121 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1122 bool CallStaticJavaNode::cmp( const Node &n ) const {
1123   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1124   return CallJavaNode::cmp(call);
1125 }
1126 
1127 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {










1128   CallGenerator* cg = generator();
1129   if (can_reshape && cg != nullptr) {
1130     if (cg->is_mh_late_inline()) {
1131       assert(IncrementalInlineMH, "required");
1132       assert(cg->call_node() == this, "mismatch");
1133       assert(cg->method()->is_method_handle_intrinsic(), "required");
1134 
1135       // Check whether this MH handle call becomes a candidate for inlining.
1136       ciMethod* callee = cg->method();
1137       vmIntrinsics::ID iid = callee->intrinsic_id();
1138       if (iid == vmIntrinsics::_invokeBasic) {
1139         if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1140           register_for_late_inline();
1141         }
1142       } else if (iid == vmIntrinsics::_linkToNative) {
1143         // never retry
1144       } else {
1145         assert(callee->has_member_arg(), "wrong type of call?");
1146         if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1147           register_for_late_inline();

1169 
1170 //----------------------------uncommon_trap_request----------------------------
1171 // If this is an uncommon trap, return the request code, else zero.
1172 int CallStaticJavaNode::uncommon_trap_request() const {
1173   return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1174 }
1175 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1176 #ifndef PRODUCT
1177   if (!(call->req() > TypeFunc::Parms &&
1178         call->in(TypeFunc::Parms) != nullptr &&
1179         call->in(TypeFunc::Parms)->is_Con() &&
1180         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1181     assert(in_dump() != 0, "OK if dumping");
1182     tty->print("[bad uncommon trap]");
1183     return 0;
1184   }
1185 #endif
1186   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1187 }
1188 


























































































































1189 #ifndef PRODUCT
1190 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1191   st->print("# Static ");
1192   if (_name != nullptr) {
1193     st->print("%s", _name);
1194     int trap_req = uncommon_trap_request();
1195     if (trap_req != 0) {
1196       char buf[100];
1197       st->print("(%s)",
1198                  Deoptimization::format_trap_request(buf, sizeof(buf),
1199                                                      trap_req));
1200     }
1201     st->print(" ");
1202   }
1203   CallJavaNode::dump_spec(st);
1204 }
1205 
1206 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1207   if (_method) {
1208     _method->print_short_name(st);

1284 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1285 bool CallRuntimeNode::cmp( const Node &n ) const {
1286   CallRuntimeNode &call = (CallRuntimeNode&)n;
1287   return CallNode::cmp(call) && !strcmp(_name,call._name);
1288 }
1289 #ifndef PRODUCT
1290 void CallRuntimeNode::dump_spec(outputStream *st) const {
1291   st->print("# ");
1292   st->print("%s", _name);
1293   CallNode::dump_spec(st);
1294 }
1295 #endif
1296 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1297 bool CallLeafVectorNode::cmp( const Node &n ) const {
1298   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1299   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1300 }
1301 
1302 //------------------------------calling_convention-----------------------------
1303 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







1304   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1305 }
1306 
1307 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1308 #ifdef ASSERT
1309   assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1310          "return vector size must match");
1311   const TypeTuple* d = tf()->domain();
1312   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1313     Node* arg = in(i);
1314     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1315            "vector argument size must match");
1316   }
1317 #endif
1318 
1319   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1320 }
1321 
1322 //=============================================================================
1323 //------------------------------calling_convention-----------------------------
1324 
1325 
1326 //=============================================================================
1327 bool CallLeafPureNode::is_unused() const {
1328   return proj_out_or_null(TypeFunc::Parms) == nullptr;
1329 }
1330 
1331 bool CallLeafPureNode::is_dead() const {
1332   return proj_out_or_null(TypeFunc::Control) == nullptr;
1333 }
1334 
1335 /* We make a tuple of the global input state + TOP for the output values.
1336  * We use this to delete a pure function that is not used: by replacing the call with
1337  * such a tuple, we let output Proj's idealization pick the corresponding input of the
1338  * pure call, so jumping over it, and effectively, removing the call from the graph.
1339  * This avoids doing the graph surgery manually, but leaves that to IGVN
1340  * that is specialized for doing that right. We need also tuple components for output
1341  * values of the function to respect the return arity, and in case there is a projection
1342  * that would pick an output (which shouldn't happen at the moment).
1343  */
1344 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1345   // Transparently propagate input state but parameters
1346   TupleNode* tuple = TupleNode::make(
1347       tf()->range(),
1348       in(TypeFunc::Control),
1349       in(TypeFunc::I_O),
1350       in(TypeFunc::Memory),
1351       in(TypeFunc::FramePtr),
1352       in(TypeFunc::ReturnAdr));
1353 
1354   // And add TOPs for the return values
1355   for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1356     tuple->set_req(i, C->top());
1357   }
1358 
1359   return tuple;
1360 }
1361 
1362 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1363   if (is_dead()) {
1364     return nullptr;
1365   }
1366 
1367   // We need to wait until IGVN because during parsing, usages might still be missing
1368   // and we would remove the call immediately.
1369   if (can_reshape && is_unused()) {
1370     // The result is not used. We remove the call by replacing it with a tuple, that
1371     // is later disintegrated by the projections.
1372     return make_tuple_of_input_state_and_top_return_values(phase->C);
1373   }
1374 
1375   return CallRuntimeNode::Ideal(phase, can_reshape);
1376 }
1377 
1378 #ifndef PRODUCT
1379 void CallLeafNode::dump_spec(outputStream *st) const {
1380   st->print("# ");
1381   st->print("%s", _name);
1382   CallNode::dump_spec(st);
1383 }
1384 #endif
1385 






1386 //=============================================================================
1387 
1388 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1389   assert(verify_jvms(jvms), "jvms must match");
1390   int loc = jvms->locoff() + idx;
1391   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1392     // If current local idx is top then local idx - 1 could
1393     // be a long/double that needs to be killed since top could
1394     // represent the 2nd half of the long/double.
1395     uint ideal = in(loc -1)->ideal_reg();
1396     if (ideal == Op_RegD || ideal == Op_RegL) {
1397       // set other (low index) half to top
1398       set_req(loc - 1, in(loc));
1399     }
1400   }
1401   set_req(loc, c);
1402 }
1403 
1404 uint SafePointNode::size_of() const { return sizeof(*this); }
1405 bool SafePointNode::cmp( const Node &n ) const {

1416   }
1417 }
1418 
1419 
1420 //----------------------------next_exception-----------------------------------
1421 SafePointNode* SafePointNode::next_exception() const {
1422   if (len() == req()) {
1423     return nullptr;
1424   } else {
1425     Node* n = in(req());
1426     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1427     return (SafePointNode*) n;
1428   }
1429 }
1430 
1431 
1432 //------------------------------Ideal------------------------------------------
1433 // Skip over any collapsed Regions
1434 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1435   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1436   return remove_dead_region(phase, can_reshape) ? this : nullptr;













1437 }
1438 
1439 //------------------------------Identity---------------------------------------
1440 // Remove obviously duplicate safepoints
1441 Node* SafePointNode::Identity(PhaseGVN* phase) {
1442 
1443   // If you have back to back safepoints, remove one
1444   if (in(TypeFunc::Control)->is_SafePoint()) {
1445     Node* out_c = unique_ctrl_out_or_null();
1446     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1447     // outer loop's safepoint could confuse removal of the outer loop.
1448     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1449       return in(TypeFunc::Control);
1450     }
1451   }
1452 
1453   // Transforming long counted loops requires a safepoint node. Do not
1454   // eliminate a safepoint until loop opts are over.
1455   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1456     Node *n0 = in(0)->in(0);

1570 }
1571 
1572 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1573   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1574   int nb = igvn->C->root()->find_prec_edge(this);
1575   if (nb != -1) {
1576     igvn->delete_precedence_of(igvn->C->root(), nb);
1577   }
1578 }
1579 
1580 //==============  SafePointScalarObjectNode  ==============
1581 
1582 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1583   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1584   _first_index(first_index),
1585   _depth(depth),
1586   _n_fields(n_fields),
1587   _alloc(alloc)
1588 {
1589 #ifdef ASSERT
1590   if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1591     alloc->dump();
1592     assert(false, "unexpected call node");
1593   }
1594 #endif
1595   init_class_id(Class_SafePointScalarObject);
1596 }
1597 
1598 // Do not allow value-numbering for SafePointScalarObject node.
1599 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1600 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1601   return (&n == this); // Always fail except on self
1602 }
1603 
1604 uint SafePointScalarObjectNode::ideal_reg() const {
1605   return 0; // No matching to machine instruction
1606 }
1607 
1608 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1609   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1610 }

1675     new_node = false;
1676     return (SafePointScalarMergeNode*)cached;
1677   }
1678   new_node = true;
1679   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1680   sosn_map->Insert((void*)this, (void*)res);
1681   return res;
1682 }
1683 
1684 #ifndef PRODUCT
1685 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1686   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1687 }
1688 #endif
1689 
1690 //=============================================================================
1691 uint AllocateNode::size_of() const { return sizeof(*this); }
1692 
1693 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1694                            Node *ctrl, Node *mem, Node *abio,
1695                            Node *size, Node *klass_node, Node *initial_test)


1696   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1697 {
1698   init_class_id(Class_Allocate);
1699   init_flags(Flag_is_macro);
1700   _is_scalar_replaceable = false;
1701   _is_non_escaping = false;
1702   _is_allocation_MemBar_redundant = false;

1703   Node *topnode = C->top();
1704 
1705   init_req( TypeFunc::Control  , ctrl );
1706   init_req( TypeFunc::I_O      , abio );
1707   init_req( TypeFunc::Memory   , mem );
1708   init_req( TypeFunc::ReturnAdr, topnode );
1709   init_req( TypeFunc::FramePtr , topnode );
1710   init_req( AllocSize          , size);
1711   init_req( KlassNode          , klass_node);
1712   init_req( InitialTest        , initial_test);
1713   init_req( ALength            , topnode);
1714   init_req( ValidLengthTest    , topnode);



1715   C->add_macro_node(this);
1716 }
1717 
1718 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1719 {
1720   assert(initializer != nullptr && initializer->is_object_initializer(),

1721          "unexpected initializer method");
1722   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1723   if (analyzer == nullptr) {
1724     return;
1725   }
1726 
1727   // Allocation node is first parameter in its initializer
1728   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1729     _is_allocation_MemBar_redundant = true;
1730   }
1731 }
1732 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {

1733   Node* mark_node = nullptr;
1734   if (UseCompactObjectHeaders) {
1735     Node* klass_node = in(AllocateNode::KlassNode);
1736     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1737     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);






1738   } else {
1739     // For now only enable fast locking for non-array types
1740     mark_node = phase->MakeConX(markWord::prototype().value());
1741   }
1742   return mark_node;
1743 }
1744 
1745 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1746 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1747 // a CastII is appropriate, return null.
1748 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1749   Node *length = in(AllocateNode::ALength);
1750   assert(length != nullptr, "length is not null");
1751 
1752   const TypeInt* length_type = phase->find_int_type(length);
1753   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1754 
1755   if (ary_type != nullptr && length_type != nullptr) {
1756     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1757     if (narrow_length_type != length_type) {
1758       // Assert one of:
1759       //   - the narrow_length is 0
1760       //   - the narrow_length is not wider than length
1761       assert(narrow_length_type == TypeInt::ZERO ||
1762              (length_type->is_con() && narrow_length_type->is_con() &&

2118 
2119 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2120   st->print("%s", _kind_names[_kind]);
2121 }
2122 #endif
2123 
2124 //=============================================================================
2125 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2126 
2127   // perform any generic optimizations first (returns 'this' or null)
2128   Node *result = SafePointNode::Ideal(phase, can_reshape);
2129   if (result != nullptr)  return result;
2130   // Don't bother trying to transform a dead node
2131   if (in(0) && in(0)->is_top())  return nullptr;
2132 
2133   // Now see if we can optimize away this lock.  We don't actually
2134   // remove the locking here, we simply set the _eliminate flag which
2135   // prevents macro expansion from expanding the lock.  Since we don't
2136   // modify the graph, the value returned from this function is the
2137   // one computed above.
2138   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2139     //
2140     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2141     //
2142     ConnectionGraph *cgr = phase->C->congraph();
2143     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2144       assert(!is_eliminated() || is_coarsened(), "sanity");
2145       // The lock could be marked eliminated by lock coarsening
2146       // code during first IGVN before EA. Replace coarsened flag
2147       // to eliminate all associated locks/unlocks.
2148 #ifdef ASSERT
2149       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2150 #endif
2151       this->set_non_esc_obj();
2152       return result;
2153     }
2154 
2155     if (!phase->C->do_locks_coarsening()) {
2156       return result; // Compiling without locks coarsening
2157     }
2158     //

2319 }
2320 
2321 //=============================================================================
2322 uint UnlockNode::size_of() const { return sizeof(*this); }
2323 
2324 //=============================================================================
2325 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2326 
2327   // perform any generic optimizations first (returns 'this' or null)
2328   Node *result = SafePointNode::Ideal(phase, can_reshape);
2329   if (result != nullptr)  return result;
2330   // Don't bother trying to transform a dead node
2331   if (in(0) && in(0)->is_top())  return nullptr;
2332 
2333   // Now see if we can optimize away this unlock.  We don't actually
2334   // remove the unlocking here, we simply set the _eliminate flag which
2335   // prevents macro expansion from expanding the unlock.  Since we don't
2336   // modify the graph, the value returned from this function is the
2337   // one computed above.
2338   // Escape state is defined after Parse phase.
2339   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2340     //
2341     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2342     //
2343     ConnectionGraph *cgr = phase->C->congraph();
2344     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2345       assert(!is_eliminated() || is_coarsened(), "sanity");
2346       // The lock could be marked eliminated by lock coarsening
2347       // code during first IGVN before EA. Replace coarsened flag
2348       // to eliminate all associated locks/unlocks.
2349 #ifdef ASSERT
2350       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2351 #endif
2352       this->set_non_esc_obj();
2353     }
2354   }
2355   return result;
2356 }
2357 
2358 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2359   if (C == nullptr) {

2399     }
2400     // unrelated
2401     return false;
2402   }
2403 
2404   if (dest_t->isa_aryptr()) {
2405     // arraycopy or array clone
2406     if (t_oop->isa_instptr()) {
2407       return false;
2408     }
2409     if (!t_oop->isa_aryptr()) {
2410       return true;
2411     }
2412 
2413     const Type* elem = dest_t->is_aryptr()->elem();
2414     if (elem == Type::BOTTOM) {
2415       // An array but we don't know what elements are
2416       return true;
2417     }
2418 
2419     dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();

2420     uint dest_alias = phase->C->get_alias_index(dest_t);
2421     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2422 
2423     return dest_alias == t_oop_alias;
2424   }
2425 
2426   return true;
2427 }

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/bcEscapeAnalyzer.hpp"
  26 #include "ci/ciFlatArrayKlass.hpp"
  27 #include "code/vmreg.hpp"
  28 #include "compiler/compileLog.hpp"
  29 #include "compiler/oopMap.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/c2/barrierSetC2.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "opto/callGenerator.hpp"
  34 #include "opto/callnode.hpp"
  35 #include "opto/castnode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/escape.hpp"
  38 #include "opto/inlinetypenode.hpp"
  39 #include "opto/locknode.hpp"
  40 #include "opto/machnode.hpp"
  41 #include "opto/matcher.hpp"
  42 #include "opto/parse.hpp"
  43 #include "opto/regalloc.hpp"
  44 #include "opto/regmask.hpp"
  45 #include "opto/rootnode.hpp"
  46 #include "opto/runtime.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #include "runtime/stubRoutines.hpp"
  49 #include "utilities/powerOfTwo.hpp"
  50 
  51 // Portions of code courtesy of Clifford Click
  52 
  53 // Optimization - Graph Style
  54 
  55 //=============================================================================
  56 uint StartNode::size_of() const { return sizeof(*this); }
  57 bool StartNode::cmp( const Node &n ) const
  58 { return _domain == ((StartNode&)n)._domain; }
  59 const Type *StartNode::bottom_type() const { return _domain; }
  60 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
  61 #ifndef PRODUCT
  62 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
  63 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
  64 #endif
  65 
  66 //------------------------------Ideal------------------------------------------
  67 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
  68   return remove_dead_region(phase, can_reshape) ? this : nullptr;
  69 }
  70 
  71 //------------------------------calling_convention-----------------------------
  72 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
  73   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
  74 }
  75 
  76 //------------------------------Registers--------------------------------------
  77 const RegMask &StartNode::in_RegMask(uint) const {
  78   return RegMask::EMPTY;
  79 }
  80 
  81 //------------------------------match------------------------------------------
  82 // Construct projections for incoming parameters, and their RegMask info
  83 Node *StartNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
  84   switch (proj->_con) {
  85   case TypeFunc::Control:
  86   case TypeFunc::I_O:
  87   case TypeFunc::Memory:
  88     return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
  89   case TypeFunc::FramePtr:
  90     return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
  91   case TypeFunc::ReturnAdr:
  92     return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
  93   case TypeFunc::Parms:
  94   default: {
  95       uint parm_num = proj->_con - TypeFunc::Parms;
  96       const Type *t = _domain->field_at(proj->_con);
  97       if (t->base() == Type::Half)  // 2nd half of Longs and Doubles
  98         return new ConNode(Type::TOP);
  99       uint ideal_reg = t->ideal_reg();
 100       RegMask &rm = match->_calling_convention_mask[parm_num];
 101       return new MachProjNode(this,proj->_con,rm,ideal_reg);
 102     }
 103   }
 104   return nullptr;
 105 }
 106 











 107 //=============================================================================
 108 const char * const ParmNode::names[TypeFunc::Parms+1] = {
 109   "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
 110 };
 111 
 112 #ifndef PRODUCT
 113 void ParmNode::dump_spec(outputStream *st) const {
 114   if( _con < TypeFunc::Parms ) {
 115     st->print("%s", names[_con]);
 116   } else {
 117     st->print("Parm%d: ",_con-TypeFunc::Parms);
 118     // Verbose and WizardMode dump bottom_type for all nodes
 119     if( !Verbose && !WizardMode )   bottom_type()->dump_on(st);
 120   }
 121 }
 122 
 123 void ParmNode::dump_compact_spec(outputStream *st) const {
 124   if (_con < TypeFunc::Parms) {
 125     st->print("%s", names[_con]);
 126   } else {

 474       if (cik->is_instance_klass()) {
 475         cik->print_name_on(st);
 476         iklass = cik->as_instance_klass();
 477       } else if (cik->is_type_array_klass()) {
 478         cik->as_array_klass()->base_element_type()->print_name_on(st);
 479         st->print("[%d]", spobj->n_fields());
 480       } else if (cik->is_obj_array_klass()) {
 481         ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
 482         if (cie->is_instance_klass()) {
 483           cie->print_name_on(st);
 484         } else if (cie->is_type_array_klass()) {
 485           cie->as_array_klass()->base_element_type()->print_name_on(st);
 486         } else {
 487           ShouldNotReachHere();
 488         }
 489         st->print("[%d]", spobj->n_fields());
 490         int ndim = cik->as_array_klass()->dimension() - 1;
 491         while (ndim-- > 0) {
 492           st->print("[]");
 493         }
 494       } else if (cik->is_flat_array_klass()) {
 495         ciKlass* cie = cik->as_flat_array_klass()->base_element_klass();
 496         cie->print_name_on(st);
 497         st->print("[%d]", spobj->n_fields());
 498         int ndim = cik->as_array_klass()->dimension() - 1;
 499         while (ndim-- > 0) {
 500           st->print("[]");
 501         }
 502       }
 503       st->print("={");
 504       uint nf = spobj->n_fields();
 505       if (nf > 0) {
 506         uint first_ind = spobj->first_index(mcall->jvms());
 507         if (iklass != nullptr && iklass->is_inlinetype()) {
 508           Node* null_marker = mcall->in(first_ind++);
 509           if (!null_marker->is_top()) {
 510             st->print(" [null marker");
 511             format_helper(regalloc, st, null_marker, ":", -1, nullptr);
 512           }
 513         }
 514         Node* fld_node = mcall->in(first_ind);

 515         if (iklass != nullptr) {
 516           st->print(" [");
 517           iklass->nonstatic_field_at(0)->print_name_on(st);

 518           format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
 519         } else {
 520           format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
 521         }
 522         for (uint j = 1; j < nf; j++) {
 523           fld_node = mcall->in(first_ind+j);
 524           if (iklass != nullptr) {
 525             st->print(", [");
 526             iklass->nonstatic_field_at(j)->print_name_on(st);

 527             format_helper(regalloc, st, fld_node, ":", j, &scobjs);
 528           } else {
 529             format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
 530           }
 531         }
 532       }
 533       st->print(" }");
 534     }
 535   }
 536   st->cr();
 537   if (caller() != nullptr) caller()->format(regalloc, n, st);
 538 }
 539 
 540 
 541 void JVMState::dump_spec(outputStream *st) const {
 542   if (_method != nullptr) {
 543     bool printed = false;
 544     if (!Verbose) {
 545       // The JVMS dumps make really, really long lines.
 546       // Take out the most boring parts, which are the package prefixes.

 741     tf()->dump_on(st);
 742   }
 743   if (_cnt != COUNT_UNKNOWN) {
 744     st->print(" C=%f", _cnt);
 745   }
 746   const Node* const klass_node = in(KlassNode);
 747   if (klass_node != nullptr) {
 748     const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
 749 
 750     if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
 751       st->print(" allocationKlass:");
 752       klass_ptr->exact_klass()->print_name_on(st);
 753     }
 754   }
 755   if (jvms() != nullptr) {
 756     jvms()->dump_spec(st);
 757   }
 758 }
 759 #endif
 760 
 761 const Type *CallNode::bottom_type() const { return tf()->range_cc(); }
 762 const Type* CallNode::Value(PhaseGVN* phase) const {
 763   if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
 764     return Type::TOP;
 765   }
 766   return tf()->range_cc();
 767 }
 768 
 769 //------------------------------calling_convention-----------------------------
 770 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
 771   if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
 772     // The call to that stub is a special case: its inputs are
 773     // multiple values returned from a call and so it should follow
 774     // the return convention.
 775     SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
 776     return;
 777   }
 778   // Use the standard compiler calling convention
 779   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
 780 }
 781 
 782 
 783 //------------------------------match------------------------------------------
 784 // Construct projections for control, I/O, memory-fields, ..., and
 785 // return result(s) along with their RegMask info
 786 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
 787   uint con = proj->_con;
 788   const TypeTuple* range_cc = tf()->range_cc();
 789   if (con >= TypeFunc::Parms) {
 790     if (tf()->returns_inline_type_as_fields()) {
 791       // The call returns multiple values (inline type fields): we
 792       // create one projection per returned value.
 793       assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
 794       uint ideal_reg = range_cc->field_at(con)->ideal_reg();
 795       return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
 796     } else {
 797       if (con == TypeFunc::Parms) {
 798         uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
 799         OptoRegPair regs = Opcode() == Op_CallLeafVector
 800           ? match->vector_return_value(ideal_reg)      // Calls into assembly vector routine
 801           : match->c_return_value(ideal_reg);
 802         RegMask rm = RegMask(regs.first());
 803 
 804         if (Opcode() == Op_CallLeafVector) {
 805           // If the return is in vector, compute appropriate regmask taking into account the whole range
 806           if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
 807             if(OptoReg::is_valid(regs.second())) {
 808               for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
 809                 rm.insert(r);
 810               }
 811             }

 812           }
 813         }
 814 
 815         if (OptoReg::is_valid(regs.second())) {
 816           rm.insert(regs.second());
 817         }
 818         return new MachProjNode(this,con,rm,ideal_reg);
 819       } else {
 820         assert(con == TypeFunc::Parms+1, "only one return value");
 821         assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
 822         return new MachProjNode(this,con, RegMask::EMPTY, (uint)OptoReg::Bad);
 823       }
 824     }




 825   }
 826 
 827   switch (con) {
 828   case TypeFunc::Control:
 829   case TypeFunc::I_O:
 830   case TypeFunc::Memory:
 831     return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
 832 
 833   case TypeFunc::ReturnAdr:
 834   case TypeFunc::FramePtr:
 835   default:
 836     ShouldNotReachHere();
 837   }
 838   return nullptr;
 839 }
 840 
 841 // Do we Match on this edge index or not?  Match no edges
 842 uint CallNode::match_edge(uint idx) const {
 843   return 0;
 844 }
 845 
 846 //
 847 // Determine whether the call could modify the field of the specified
 848 // instance at the specified offset.
 849 //
 850 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
 851   assert((t_oop != nullptr), "sanity");
 852   if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
 853     const TypeTuple* args = _tf->domain_sig();
 854     Node* dest = nullptr;
 855     // Stubs that can be called once an ArrayCopyNode is expanded have
 856     // different signatures. Look for the second pointer argument,
 857     // that is the destination of the copy.
 858     for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
 859       if (args->field_at(i)->isa_ptr()) {
 860         j++;
 861         if (j == 2) {
 862           dest = in(i);
 863           break;
 864         }
 865       }
 866     }
 867     guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
 868     if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
 869       return true;
 870     }
 871     return false;
 872   }
 873   if (t_oop->is_known_instance()) {

 882       Node* proj = proj_out_or_null(TypeFunc::Parms);
 883       if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
 884         return false;
 885       }
 886     }
 887     if (is_CallJava() && as_CallJava()->method() != nullptr) {
 888       ciMethod* meth = as_CallJava()->method();
 889       if (meth->is_getter()) {
 890         return false;
 891       }
 892       // May modify (by reflection) if an boxing object is passed
 893       // as argument or returned.
 894       Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
 895       if (proj != nullptr) {
 896         const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
 897         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 898                                    (inst_t->instance_klass() == boxing_klass))) {
 899           return true;
 900         }
 901       }
 902       const TypeTuple* d = tf()->domain_cc();
 903       for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 904         const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
 905         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 906                                  (inst_t->instance_klass() == boxing_klass))) {
 907           return true;
 908         }
 909       }
 910       return false;
 911     }
 912   }
 913   return true;
 914 }
 915 
 916 // Does this call have a direct reference to n other than debug information?
 917 bool CallNode::has_non_debug_use(Node* n) {
 918   const TypeTuple* d = tf()->domain_cc();
 919   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 920     if (in(i) == n) {

 921       return true;
 922     }
 923   }
 924   return false;
 925 }
 926 
 927 bool CallNode::has_debug_use(Node* n) {
 928   if (jvms() != nullptr) {
 929     for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
 930       if (in(i) == n) {
 931         return true;
 932       }
 933     }
 934   }
 935   return false;
 936 }
 937 
 938 // Returns the unique CheckCastPP of a call
 939 // or 'this' if there are several CheckCastPP or unexpected uses
 940 // or returns null if there is no one.
 941 Node *CallNode::result_cast() {
 942   Node *cast = nullptr;
 943 
 944   Node *p = proj_out_or_null(TypeFunc::Parms);
 945   if (p == nullptr)
 946     return nullptr;
 947 
 948   for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
 949     Node *use = p->fast_out(i);
 950     if (use->is_CheckCastPP()) {
 951       if (cast != nullptr) {
 952         return this;  // more than 1 CheckCastPP
 953       }
 954       cast = use;
 955     } else if (!use->is_Initialize() &&
 956                !use->is_AddP() &&
 957                use->Opcode() != Op_MemBarStoreStore) {
 958       // Expected uses are restricted to a CheckCastPP, an Initialize
 959       // node, a MemBarStoreStore (clone) and AddP nodes. If we
 960       // encounter any other use (a Phi node can be seen in rare
 961       // cases) return this to prevent incorrect optimizations.
 962       return this;
 963     }
 964   }
 965   return cast;
 966 }
 967 
 968 
 969 CallProjections* CallNode::extract_projections(bool separate_io_proj, bool do_asserts) const {
 970   uint max_res = TypeFunc::Parms-1;
 971   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 972     ProjNode *pn = fast_out(i)->as_Proj();
 973     max_res = MAX2(max_res, pn->_con);
 974   }
 975 
 976   assert(max_res < _tf->range_cc()->cnt(), "result out of bounds");
 977 
 978   uint projs_size = sizeof(CallProjections);
 979   if (max_res > TypeFunc::Parms) {
 980     projs_size += (max_res-TypeFunc::Parms)*sizeof(Node*);
 981   }
 982   char* projs_storage = resource_allocate_bytes(projs_size);
 983   CallProjections* projs = new(projs_storage)CallProjections(max_res - TypeFunc::Parms + 1);
 984 
 985   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 986     ProjNode *pn = fast_out(i)->as_Proj();
 987     if (pn->outcnt() == 0) continue;
 988     switch (pn->_con) {
 989     case TypeFunc::Control:
 990       {
 991         // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
 992         projs->fallthrough_proj = pn;
 993         const Node* cn = pn->unique_ctrl_out_or_null();
 994         if (cn != nullptr && cn->is_Catch()) {
 995           ProjNode *cpn = nullptr;
 996           for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
 997             cpn = cn->fast_out(k)->as_Proj();
 998             assert(cpn->is_CatchProj(), "must be a CatchProjNode");
 999             if (cpn->_con == CatchProjNode::fall_through_index)
1000               projs->fallthrough_catchproj = cpn;
1001             else {
1002               assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
1003               projs->catchall_catchproj = cpn;

1009     case TypeFunc::I_O:
1010       if (pn->_is_io_use)
1011         projs->catchall_ioproj = pn;
1012       else
1013         projs->fallthrough_ioproj = pn;
1014       for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
1015         Node* e = pn->out(j);
1016         if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
1017           assert(projs->exobj == nullptr, "only one");
1018           projs->exobj = e;
1019         }
1020       }
1021       break;
1022     case TypeFunc::Memory:
1023       if (pn->_is_io_use)
1024         projs->catchall_memproj = pn;
1025       else
1026         projs->fallthrough_memproj = pn;
1027       break;
1028     case TypeFunc::Parms:
1029       projs->resproj[0] = pn;
1030       break;
1031     default:
1032       assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1033       projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1034       break;
1035     }
1036   }
1037 
1038   // The resproj may not exist because the result could be ignored
1039   // and the exception object may not exist if an exception handler
1040   // swallows the exception but all the other must exist and be found.

1041   do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1042   assert(!do_asserts || projs->fallthrough_proj      != nullptr, "must be found");
1043   assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1044   assert(!do_asserts || projs->fallthrough_memproj   != nullptr, "must be found");
1045   assert(!do_asserts || projs->fallthrough_ioproj    != nullptr, "must be found");
1046   assert(!do_asserts || projs->catchall_catchproj    != nullptr, "must be found");
1047   if (separate_io_proj) {
1048     assert(!do_asserts || projs->catchall_memproj    != nullptr, "must be found");
1049     assert(!do_asserts || projs->catchall_ioproj     != nullptr, "must be found");
1050   }
1051   return projs;
1052 }
1053 
1054 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1055 #ifdef ASSERT
1056   // Validate attached generator
1057   CallGenerator* cg = generator();
1058   if (cg != nullptr) {
1059     assert((is_CallStaticJava()  && cg->is_mh_late_inline()) ||
1060            (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1061   }
1062 #endif // ASSERT
1063   return SafePointNode::Ideal(phase, can_reshape);
1064 }
1065 
1066 bool CallNode::is_call_to_arraycopystub() const {
1067   if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1068     return true;
1069   }
1070   return false;
1071 }
1072 
1073 //=============================================================================
1074 uint CallJavaNode::size_of() const { return sizeof(*this); }
1075 bool CallJavaNode::cmp( const Node &n ) const {
1076   CallJavaNode &call = (CallJavaNode&)n;
1077   return CallNode::cmp(call) && _method == call._method &&
1078          _override_symbolic_info == call._override_symbolic_info;
1079 }
1080 
1081 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1082   // Copy debug information and adjust JVMState information
1083   uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1084   uint new_dbg_start = tf()->domain_sig()->cnt();
1085   int jvms_adj  = new_dbg_start - old_dbg_start;
1086   assert (new_dbg_start == req(), "argument count mismatch");
1087   Compile* C = phase->C;
1088 
1089   // SafePointScalarObject node could be referenced several times in debug info.
1090   // Use Dict to record cloned nodes.
1091   Dict* sosn_map = new Dict(cmpkey,hashkey);
1092   for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1093     Node* old_in = sfpt->in(i);
1094     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1095     if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1096       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1097       bool new_node;
1098       Node* new_in = old_sosn->clone(sosn_map, new_node);
1099       if (new_node) { // New node?
1100         new_in->set_req(0, C->root()); // reset control edge
1101         new_in = phase->transform(new_in); // Register new node.
1102       }
1103       old_in = new_in;
1104     }
1105     add_req(old_in);
1106   }
1107 
1108   // JVMS may be shared so clone it before we modify it
1109   set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1110   for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1111     jvms->set_map(this);
1112     jvms->set_locoff(jvms->locoff()+jvms_adj);
1113     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1114     jvms->set_monoff(jvms->monoff()+jvms_adj);
1115     jvms->set_scloff(jvms->scloff()+jvms_adj);
1116     jvms->set_endoff(jvms->endoff()+jvms_adj);
1117   }
1118 }
1119 
1120 #ifdef ASSERT
1121 bool CallJavaNode::validate_symbolic_info() const {
1122   if (method() == nullptr) {
1123     return true; // call into runtime or uncommon trap
1124   }
1125   Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1126   if (EnableValhalla && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1127     return true;
1128   }
1129   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1130   ciMethod* callee = method();
1131   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1132     assert(override_symbolic_info(), "should be set");
1133   }
1134   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1135   return true;
1136 }
1137 #endif
1138 
1139 #ifndef PRODUCT
1140 void CallJavaNode::dump_spec(outputStream* st) const {
1141   if( _method ) _method->print_short_name(st);
1142   CallNode::dump_spec(st);
1143 }
1144 
1145 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1146   if (_method) {
1147     _method->print_short_name(st);
1148   } else {

1151 }
1152 #endif
1153 
1154 void CallJavaNode::register_for_late_inline() {
1155   if (generator() != nullptr) {
1156     Compile::current()->prepend_late_inline(generator());
1157     set_generator(nullptr);
1158   } else {
1159     assert(false, "repeated inline attempt");
1160   }
1161 }
1162 
1163 //=============================================================================
1164 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1165 bool CallStaticJavaNode::cmp( const Node &n ) const {
1166   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1167   return CallJavaNode::cmp(call);
1168 }
1169 
1170 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1171   if (can_reshape && uncommon_trap_request() != 0) {
1172     PhaseIterGVN* igvn = phase->is_IterGVN();
1173     if (remove_unknown_flat_array_load(igvn, in(0), in(TypeFunc::Memory), in(TypeFunc::Parms))) {
1174       if (!in(0)->is_Region()) {
1175         igvn->replace_input_of(this, 0, phase->C->top());
1176       }
1177       return this;
1178     }
1179   }
1180 
1181   CallGenerator* cg = generator();
1182   if (can_reshape && cg != nullptr) {
1183     if (cg->is_mh_late_inline()) {
1184       assert(IncrementalInlineMH, "required");
1185       assert(cg->call_node() == this, "mismatch");
1186       assert(cg->method()->is_method_handle_intrinsic(), "required");
1187 
1188       // Check whether this MH handle call becomes a candidate for inlining.
1189       ciMethod* callee = cg->method();
1190       vmIntrinsics::ID iid = callee->intrinsic_id();
1191       if (iid == vmIntrinsics::_invokeBasic) {
1192         if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1193           register_for_late_inline();
1194         }
1195       } else if (iid == vmIntrinsics::_linkToNative) {
1196         // never retry
1197       } else {
1198         assert(callee->has_member_arg(), "wrong type of call?");
1199         if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1200           register_for_late_inline();

1222 
1223 //----------------------------uncommon_trap_request----------------------------
1224 // If this is an uncommon trap, return the request code, else zero.
1225 int CallStaticJavaNode::uncommon_trap_request() const {
1226   return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1227 }
1228 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1229 #ifndef PRODUCT
1230   if (!(call->req() > TypeFunc::Parms &&
1231         call->in(TypeFunc::Parms) != nullptr &&
1232         call->in(TypeFunc::Parms)->is_Con() &&
1233         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1234     assert(in_dump() != 0, "OK if dumping");
1235     tty->print("[bad uncommon trap]");
1236     return 0;
1237   }
1238 #endif
1239   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1240 }
1241 
1242 // Split if can cause the flat array branch of an array load with unknown type (see
1243 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1244 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1245 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1246   if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1247     return false;
1248   }
1249   if (ctl->is_Region()) {
1250     bool res = false;
1251     for (uint i = 1; i < ctl->req(); i++) {
1252       MergeMemNode* mm = mem->clone()->as_MergeMem();
1253       for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1254         Node* m = mms.memory();
1255         if (m->is_Phi() && m->in(0) == ctl) {
1256           mms.set_memory(m->in(i));
1257         }
1258       }
1259       if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1260         res = true;
1261         if (!ctl->in(i)->is_Region()) {
1262           igvn->replace_input_of(ctl, i, igvn->C->top());
1263         }
1264       }
1265       igvn->remove_dead_node(mm);
1266     }
1267     return res;
1268   }
1269   // Verify the control flow is ok
1270   Node* call = ctl;
1271   MemBarNode* membar = nullptr;
1272   for (;;) {
1273     if (call == nullptr || call->is_top()) {
1274       return false;
1275     }
1276     if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1277       call = call->in(0);
1278     } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1279                call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1280       assert(call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar(), "missing membar");
1281       membar = call->in(0)->in(0)->as_MemBar();
1282       break;
1283     } else {
1284       return false;
1285     }
1286   }
1287 
1288   JVMState* jvms = call->jvms();
1289   if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1290     return false;
1291   }
1292 
1293   Node* call_mem = call->in(TypeFunc::Memory);
1294   if (call_mem == nullptr || call_mem->is_top()) {
1295     return false;
1296   }
1297   if (!call_mem->is_MergeMem()) {
1298     call_mem = MergeMemNode::make(call_mem);
1299     igvn->register_new_node_with_optimizer(call_mem);
1300   }
1301 
1302   // Verify that there's no unexpected side effect
1303   for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1304     Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1305     Node* m2 = mms2.memory2();
1306 
1307     for (uint i = 0; i < 100; i++) {
1308       if (m1 == m2) {
1309         break;
1310       } else if (m1->is_Proj()) {
1311         m1 = m1->in(0);
1312       } else if (m1->is_MemBar()) {
1313         m1 = m1->in(TypeFunc::Memory);
1314       } else if (m1->Opcode() == Op_CallStaticJava &&
1315                  m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1316         if (m1 != call) {
1317           return false;
1318         }
1319         break;
1320       } else if (m1->is_MergeMem()) {
1321         MergeMemNode* mm = m1->as_MergeMem();
1322         int idx = mms2.alias_idx();
1323         if (idx == Compile::AliasIdxBot) {
1324           m1 = mm->base_memory();
1325         } else {
1326           m1 = mm->memory_at(idx);
1327         }
1328       } else {
1329         return false;
1330       }
1331     }
1332   }
1333   if (call_mem->outcnt() == 0) {
1334     igvn->remove_dead_node(call_mem);
1335   }
1336 
1337   // Remove membar preceding the call
1338   membar->remove(igvn);
1339 
1340   address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1341   CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1342   unc->init_req(TypeFunc::Control, call->in(0));
1343   unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1344   unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1345   unc->init_req(TypeFunc::FramePtr,  call->in(TypeFunc::FramePtr));
1346   unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1347   unc->init_req(TypeFunc::Parms+0, unc_arg);
1348   unc->set_cnt(PROB_UNLIKELY_MAG(4));
1349   unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1350 
1351   // Replace the call with an uncommon trap
1352   igvn->replace_input_of(call, 0, igvn->C->top());
1353 
1354   igvn->register_new_node_with_optimizer(unc);
1355 
1356   Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1357   Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1358   igvn->add_input_to(igvn->C->root(), halt);
1359 
1360   return true;
1361 }
1362 
1363 
1364 #ifndef PRODUCT
1365 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1366   st->print("# Static ");
1367   if (_name != nullptr) {
1368     st->print("%s", _name);
1369     int trap_req = uncommon_trap_request();
1370     if (trap_req != 0) {
1371       char buf[100];
1372       st->print("(%s)",
1373                  Deoptimization::format_trap_request(buf, sizeof(buf),
1374                                                      trap_req));
1375     }
1376     st->print(" ");
1377   }
1378   CallJavaNode::dump_spec(st);
1379 }
1380 
1381 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1382   if (_method) {
1383     _method->print_short_name(st);

1459 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1460 bool CallRuntimeNode::cmp( const Node &n ) const {
1461   CallRuntimeNode &call = (CallRuntimeNode&)n;
1462   return CallNode::cmp(call) && !strcmp(_name,call._name);
1463 }
1464 #ifndef PRODUCT
1465 void CallRuntimeNode::dump_spec(outputStream *st) const {
1466   st->print("# ");
1467   st->print("%s", _name);
1468   CallNode::dump_spec(st);
1469 }
1470 #endif
1471 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1472 bool CallLeafVectorNode::cmp( const Node &n ) const {
1473   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1474   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1475 }
1476 
1477 //------------------------------calling_convention-----------------------------
1478 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1479   if (_entry_point == nullptr) {
1480     // The call to that stub is a special case: its inputs are
1481     // multiple values returned from a call and so it should follow
1482     // the return convention.
1483     SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1484     return;
1485   }
1486   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1487 }
1488 
1489 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1490 #ifdef ASSERT
1491   assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1492          "return vector size must match");
1493   const TypeTuple* d = tf()->domain_sig();
1494   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1495     Node* arg = in(i);
1496     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1497            "vector argument size must match");
1498   }
1499 #endif
1500 
1501   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1502 }
1503 
1504 //=============================================================================
1505 //------------------------------calling_convention-----------------------------
1506 
1507 
1508 //=============================================================================
1509 bool CallLeafPureNode::is_unused() const {
1510   return proj_out_or_null(TypeFunc::Parms) == nullptr;
1511 }
1512 
1513 bool CallLeafPureNode::is_dead() const {
1514   return proj_out_or_null(TypeFunc::Control) == nullptr;
1515 }
1516 
1517 /* We make a tuple of the global input state + TOP for the output values.
1518  * We use this to delete a pure function that is not used: by replacing the call with
1519  * such a tuple, we let output Proj's idealization pick the corresponding input of the
1520  * pure call, so jumping over it, and effectively, removing the call from the graph.
1521  * This avoids doing the graph surgery manually, but leaves that to IGVN
1522  * that is specialized for doing that right. We need also tuple components for output
1523  * values of the function to respect the return arity, and in case there is a projection
1524  * that would pick an output (which shouldn't happen at the moment).
1525  */
1526 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1527   // Transparently propagate input state but parameters
1528   TupleNode* tuple = TupleNode::make(
1529       tf()->range_cc(),
1530       in(TypeFunc::Control),
1531       in(TypeFunc::I_O),
1532       in(TypeFunc::Memory),
1533       in(TypeFunc::FramePtr),
1534       in(TypeFunc::ReturnAdr));
1535 
1536   // And add TOPs for the return values
1537   for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1538     tuple->set_req(i, C->top());
1539   }
1540 
1541   return tuple;
1542 }
1543 
1544 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1545   if (is_dead()) {
1546     return nullptr;
1547   }
1548 
1549   // We need to wait until IGVN because during parsing, usages might still be missing
1550   // and we would remove the call immediately.
1551   if (can_reshape && is_unused()) {
1552     // The result is not used. We remove the call by replacing it with a tuple, that
1553     // is later disintegrated by the projections.
1554     return make_tuple_of_input_state_and_top_return_values(phase->C);
1555   }
1556 
1557   return CallRuntimeNode::Ideal(phase, can_reshape);
1558 }
1559 
1560 #ifndef PRODUCT
1561 void CallLeafNode::dump_spec(outputStream *st) const {
1562   st->print("# ");
1563   st->print("%s", _name);
1564   CallNode::dump_spec(st);
1565 }
1566 #endif
1567 
1568 uint CallLeafNoFPNode::match_edge(uint idx) const {
1569   // Null entry point is a special case for which the target is in a
1570   // register. Need to match that edge.
1571   return entry_point() == nullptr && idx == TypeFunc::Parms;
1572 }
1573 
1574 //=============================================================================
1575 
1576 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1577   assert(verify_jvms(jvms), "jvms must match");
1578   int loc = jvms->locoff() + idx;
1579   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1580     // If current local idx is top then local idx - 1 could
1581     // be a long/double that needs to be killed since top could
1582     // represent the 2nd half of the long/double.
1583     uint ideal = in(loc -1)->ideal_reg();
1584     if (ideal == Op_RegD || ideal == Op_RegL) {
1585       // set other (low index) half to top
1586       set_req(loc - 1, in(loc));
1587     }
1588   }
1589   set_req(loc, c);
1590 }
1591 
1592 uint SafePointNode::size_of() const { return sizeof(*this); }
1593 bool SafePointNode::cmp( const Node &n ) const {

1604   }
1605 }
1606 
1607 
1608 //----------------------------next_exception-----------------------------------
1609 SafePointNode* SafePointNode::next_exception() const {
1610   if (len() == req()) {
1611     return nullptr;
1612   } else {
1613     Node* n = in(req());
1614     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1615     return (SafePointNode*) n;
1616   }
1617 }
1618 
1619 
1620 //------------------------------Ideal------------------------------------------
1621 // Skip over any collapsed Regions
1622 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1623   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1624   if (remove_dead_region(phase, can_reshape)) {
1625     return this;
1626   }
1627   // Scalarize inline types in safepoint debug info.
1628   // Delay this until all inlining is over to avoid getting inconsistent debug info.
1629   if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1630     for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1631       Node* n = in(i)->uncast();
1632       if (n->is_InlineType()) {
1633         n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1634       }
1635     }
1636   }
1637   return nullptr;
1638 }
1639 
1640 //------------------------------Identity---------------------------------------
1641 // Remove obviously duplicate safepoints
1642 Node* SafePointNode::Identity(PhaseGVN* phase) {
1643 
1644   // If you have back to back safepoints, remove one
1645   if (in(TypeFunc::Control)->is_SafePoint()) {
1646     Node* out_c = unique_ctrl_out_or_null();
1647     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1648     // outer loop's safepoint could confuse removal of the outer loop.
1649     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1650       return in(TypeFunc::Control);
1651     }
1652   }
1653 
1654   // Transforming long counted loops requires a safepoint node. Do not
1655   // eliminate a safepoint until loop opts are over.
1656   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1657     Node *n0 = in(0)->in(0);

1771 }
1772 
1773 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1774   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1775   int nb = igvn->C->root()->find_prec_edge(this);
1776   if (nb != -1) {
1777     igvn->delete_precedence_of(igvn->C->root(), nb);
1778   }
1779 }
1780 
1781 //==============  SafePointScalarObjectNode  ==============
1782 
1783 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1784   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1785   _first_index(first_index),
1786   _depth(depth),
1787   _n_fields(n_fields),
1788   _alloc(alloc)
1789 {
1790 #ifdef ASSERT
1791   if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1792     alloc->dump();
1793     assert(false, "unexpected call node");
1794   }
1795 #endif
1796   init_class_id(Class_SafePointScalarObject);
1797 }
1798 
1799 // Do not allow value-numbering for SafePointScalarObject node.
1800 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1801 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1802   return (&n == this); // Always fail except on self
1803 }
1804 
1805 uint SafePointScalarObjectNode::ideal_reg() const {
1806   return 0; // No matching to machine instruction
1807 }
1808 
1809 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1810   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1811 }

1876     new_node = false;
1877     return (SafePointScalarMergeNode*)cached;
1878   }
1879   new_node = true;
1880   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1881   sosn_map->Insert((void*)this, (void*)res);
1882   return res;
1883 }
1884 
1885 #ifndef PRODUCT
1886 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1887   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1888 }
1889 #endif
1890 
1891 //=============================================================================
1892 uint AllocateNode::size_of() const { return sizeof(*this); }
1893 
1894 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1895                            Node *ctrl, Node *mem, Node *abio,
1896                            Node *size, Node *klass_node,
1897                            Node* initial_test,
1898                            InlineTypeNode* inline_type_node)
1899   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1900 {
1901   init_class_id(Class_Allocate);
1902   init_flags(Flag_is_macro);
1903   _is_scalar_replaceable = false;
1904   _is_non_escaping = false;
1905   _is_allocation_MemBar_redundant = false;
1906   _larval = false;
1907   Node *topnode = C->top();
1908 
1909   init_req( TypeFunc::Control  , ctrl );
1910   init_req( TypeFunc::I_O      , abio );
1911   init_req( TypeFunc::Memory   , mem );
1912   init_req( TypeFunc::ReturnAdr, topnode );
1913   init_req( TypeFunc::FramePtr , topnode );
1914   init_req( AllocSize          , size);
1915   init_req( KlassNode          , klass_node);
1916   init_req( InitialTest        , initial_test);
1917   init_req( ALength            , topnode);
1918   init_req( ValidLengthTest    , topnode);
1919   init_req( InlineType     , inline_type_node);
1920   // DefaultValue defaults to nullptr
1921   // RawDefaultValue defaults to nullptr
1922   C->add_macro_node(this);
1923 }
1924 
1925 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1926 {
1927   assert(initializer != nullptr &&
1928          (initializer->is_object_constructor() || initializer->is_class_initializer()),
1929          "unexpected initializer method");
1930   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1931   if (analyzer == nullptr) {
1932     return;
1933   }
1934 
1935   // Allocation node is first parameter in its initializer
1936   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1937     _is_allocation_MemBar_redundant = true;
1938   }
1939 }
1940 
1941 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
1942   Node* mark_node = nullptr;
1943   if (UseCompactObjectHeaders || EnableValhalla) {
1944     Node* klass_node = in(AllocateNode::KlassNode);
1945     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1946     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1947     if (EnableValhalla) {
1948       mark_node = phase->transform(mark_node);
1949       // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
1950       mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
1951     }
1952     return mark_node;
1953   } else {
1954     return phase->MakeConX(markWord::prototype().value());

1955   }

1956 }
1957 
1958 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1959 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1960 // a CastII is appropriate, return null.
1961 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1962   Node *length = in(AllocateNode::ALength);
1963   assert(length != nullptr, "length is not null");
1964 
1965   const TypeInt* length_type = phase->find_int_type(length);
1966   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1967 
1968   if (ary_type != nullptr && length_type != nullptr) {
1969     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1970     if (narrow_length_type != length_type) {
1971       // Assert one of:
1972       //   - the narrow_length is 0
1973       //   - the narrow_length is not wider than length
1974       assert(narrow_length_type == TypeInt::ZERO ||
1975              (length_type->is_con() && narrow_length_type->is_con() &&

2331 
2332 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2333   st->print("%s", _kind_names[_kind]);
2334 }
2335 #endif
2336 
2337 //=============================================================================
2338 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2339 
2340   // perform any generic optimizations first (returns 'this' or null)
2341   Node *result = SafePointNode::Ideal(phase, can_reshape);
2342   if (result != nullptr)  return result;
2343   // Don't bother trying to transform a dead node
2344   if (in(0) && in(0)->is_top())  return nullptr;
2345 
2346   // Now see if we can optimize away this lock.  We don't actually
2347   // remove the locking here, we simply set the _eliminate flag which
2348   // prevents macro expansion from expanding the lock.  Since we don't
2349   // modify the graph, the value returned from this function is the
2350   // one computed above.
2351   const Type* obj_type = phase->type(obj_node());
2352   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2353     //
2354     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2355     //
2356     ConnectionGraph *cgr = phase->C->congraph();
2357     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2358       assert(!is_eliminated() || is_coarsened(), "sanity");
2359       // The lock could be marked eliminated by lock coarsening
2360       // code during first IGVN before EA. Replace coarsened flag
2361       // to eliminate all associated locks/unlocks.
2362 #ifdef ASSERT
2363       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2364 #endif
2365       this->set_non_esc_obj();
2366       return result;
2367     }
2368 
2369     if (!phase->C->do_locks_coarsening()) {
2370       return result; // Compiling without locks coarsening
2371     }
2372     //

2533 }
2534 
2535 //=============================================================================
2536 uint UnlockNode::size_of() const { return sizeof(*this); }
2537 
2538 //=============================================================================
2539 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2540 
2541   // perform any generic optimizations first (returns 'this' or null)
2542   Node *result = SafePointNode::Ideal(phase, can_reshape);
2543   if (result != nullptr)  return result;
2544   // Don't bother trying to transform a dead node
2545   if (in(0) && in(0)->is_top())  return nullptr;
2546 
2547   // Now see if we can optimize away this unlock.  We don't actually
2548   // remove the unlocking here, we simply set the _eliminate flag which
2549   // prevents macro expansion from expanding the unlock.  Since we don't
2550   // modify the graph, the value returned from this function is the
2551   // one computed above.
2552   // Escape state is defined after Parse phase.
2553   const Type* obj_type = phase->type(obj_node());
2554   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2555     //
2556     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2557     //
2558     ConnectionGraph *cgr = phase->C->congraph();
2559     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2560       assert(!is_eliminated() || is_coarsened(), "sanity");
2561       // The lock could be marked eliminated by lock coarsening
2562       // code during first IGVN before EA. Replace coarsened flag
2563       // to eliminate all associated locks/unlocks.
2564 #ifdef ASSERT
2565       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2566 #endif
2567       this->set_non_esc_obj();
2568     }
2569   }
2570   return result;
2571 }
2572 
2573 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2574   if (C == nullptr) {

2614     }
2615     // unrelated
2616     return false;
2617   }
2618 
2619   if (dest_t->isa_aryptr()) {
2620     // arraycopy or array clone
2621     if (t_oop->isa_instptr()) {
2622       return false;
2623     }
2624     if (!t_oop->isa_aryptr()) {
2625       return true;
2626     }
2627 
2628     const Type* elem = dest_t->is_aryptr()->elem();
2629     if (elem == Type::BOTTOM) {
2630       // An array but we don't know what elements are
2631       return true;
2632     }
2633 
2634     dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2635     t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2636     uint dest_alias = phase->C->get_alias_index(dest_t);
2637     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2638 
2639     return dest_alias == t_oop_alias;
2640   }
2641 
2642   return true;
2643 }
< prev index next >