< 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 "compiler/compileLog.hpp"

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

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

  45 #include "utilities/powerOfTwo.hpp"
  46 #include "code/vmreg.hpp"
  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 {

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








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







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

 720     tf()->dump_on(st);
 721   }
 722   if (_cnt != COUNT_UNKNOWN) {
 723     st->print(" C=%f", _cnt);
 724   }
 725   const Node* const klass_node = in(KlassNode);
 726   if (klass_node != nullptr) {
 727     const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
 728 
 729     if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
 730       st->print(" allocationKlass:");
 731       klass_ptr->exact_klass()->print_name_on(st);
 732     }
 733   }
 734   if (jvms() != nullptr) {
 735     jvms()->dump_spec(st);
 736   }
 737 }
 738 #endif
 739 
 740 const Type *CallNode::bottom_type() const { return tf()->range(); }
 741 const Type* CallNode::Value(PhaseGVN* phase) const {
 742   if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
 743     return Type::TOP;
 744   }
 745   return tf()->range();
 746 }
 747 
 748 //------------------------------calling_convention-----------------------------
 749 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







 750   // Use the standard compiler calling convention
 751   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
 752 }
 753 
 754 
 755 //------------------------------match------------------------------------------
 756 // Construct projections for control, I/O, memory-fields, ..., and
 757 // return result(s) along with their RegMask info
 758 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
 759   switch (proj->_con) {
 760   case TypeFunc::Control:
 761   case TypeFunc::I_O:
 762   case TypeFunc::Memory:
 763     return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
 764 
 765   case TypeFunc::Parms+1:       // For LONG & DOUBLE returns
 766     assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
 767     // 2nd half of doubles and longs
 768     return new MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
 769 
 770   case TypeFunc::Parms: {       // Normal returns
 771     uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
 772     OptoRegPair regs = Opcode() == Op_CallLeafVector
 773       ? match->vector_return_value(ideal_reg)      // Calls into assembly vector routine
 774       : is_CallRuntime()
 775         ? match->c_return_value(ideal_reg)  // Calls into C runtime
 776         : match->  return_value(ideal_reg); // Calls into compiled Java code
 777     RegMask rm = RegMask(regs.first());
 778 
 779     if (Opcode() == Op_CallLeafVector) {
 780       // If the return is in vector, compute appropriate regmask taking into account the whole range
 781       if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
 782         if(OptoReg::is_valid(regs.second())) {
 783           for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
 784             rm.Insert(r);
 785           }
 786         }









 787       }
 788     }
 789 
 790     if( OptoReg::is_valid(regs.second()) )
 791       rm.Insert( regs.second() );
 792     return new MachProjNode(this,proj->_con,rm,ideal_reg);
 793   }
 794 






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

 844       Node* proj = proj_out_or_null(TypeFunc::Parms);
 845       if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
 846         return false;
 847       }
 848     }
 849     if (is_CallJava() && as_CallJava()->method() != nullptr) {
 850       ciMethod* meth = as_CallJava()->method();
 851       if (meth->is_getter()) {
 852         return false;
 853       }
 854       // May modify (by reflection) if an boxing object is passed
 855       // as argument or returned.
 856       Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
 857       if (proj != nullptr) {
 858         const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
 859         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 860                                    (inst_t->instance_klass() == boxing_klass))) {
 861           return true;
 862         }
 863       }
 864       const TypeTuple* d = tf()->domain();
 865       for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 866         const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
 867         if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
 868                                  (inst_t->instance_klass() == boxing_klass))) {
 869           return true;
 870         }
 871       }
 872       return false;
 873     }
 874   }
 875   return true;
 876 }
 877 
 878 // Does this call have a direct reference to n other than debug information?
 879 bool CallNode::has_non_debug_use(Node *n) {
 880   const TypeTuple * d = tf()->domain();
 881   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 882     Node *arg = in(i);
 883     if (arg == n) {
 884       return true;
 885     }
 886   }
 887   return false;
 888 }
 889 











 890 // Returns the unique CheckCastPP of a call
 891 // or 'this' if there are several CheckCastPP or unexpected uses
 892 // or returns null if there is no one.
 893 Node *CallNode::result_cast() {
 894   Node *cast = nullptr;
 895 
 896   Node *p = proj_out_or_null(TypeFunc::Parms);
 897   if (p == nullptr)
 898     return nullptr;
 899 
 900   for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
 901     Node *use = p->fast_out(i);
 902     if (use->is_CheckCastPP()) {
 903       if (cast != nullptr) {
 904         return this;  // more than 1 CheckCastPP
 905       }
 906       cast = use;
 907     } else if (!use->is_Initialize() &&
 908                !use->is_AddP() &&
 909                use->Opcode() != Op_MemBarStoreStore) {
 910       // Expected uses are restricted to a CheckCastPP, an Initialize
 911       // node, a MemBarStoreStore (clone) and AddP nodes. If we
 912       // encounter any other use (a Phi node can be seen in rare
 913       // cases) return this to prevent incorrect optimizations.
 914       return this;
 915     }
 916   }
 917   return cast;
 918 }
 919 
 920 
 921 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) {
 922   projs->fallthrough_proj      = nullptr;
 923   projs->fallthrough_catchproj = nullptr;
 924   projs->fallthrough_ioproj    = nullptr;
 925   projs->catchall_ioproj       = nullptr;
 926   projs->catchall_catchproj    = nullptr;
 927   projs->fallthrough_memproj   = nullptr;
 928   projs->catchall_memproj      = nullptr;
 929   projs->resproj               = nullptr;
 930   projs->exobj                 = nullptr;





 931 
 932   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 933     ProjNode *pn = fast_out(i)->as_Proj();
 934     if (pn->outcnt() == 0) continue;
 935     switch (pn->_con) {
 936     case TypeFunc::Control:
 937       {
 938         // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
 939         projs->fallthrough_proj = pn;
 940         const Node* cn = pn->unique_ctrl_out_or_null();
 941         if (cn != nullptr && cn->is_Catch()) {
 942           ProjNode *cpn = nullptr;
 943           for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
 944             cpn = cn->fast_out(k)->as_Proj();
 945             assert(cpn->is_CatchProj(), "must be a CatchProjNode");
 946             if (cpn->_con == CatchProjNode::fall_through_index)
 947               projs->fallthrough_catchproj = cpn;
 948             else {
 949               assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
 950               projs->catchall_catchproj = cpn;

 956     case TypeFunc::I_O:
 957       if (pn->_is_io_use)
 958         projs->catchall_ioproj = pn;
 959       else
 960         projs->fallthrough_ioproj = pn;
 961       for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
 962         Node* e = pn->out(j);
 963         if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
 964           assert(projs->exobj == nullptr, "only one");
 965           projs->exobj = e;
 966         }
 967       }
 968       break;
 969     case TypeFunc::Memory:
 970       if (pn->_is_io_use)
 971         projs->catchall_memproj = pn;
 972       else
 973         projs->fallthrough_memproj = pn;
 974       break;
 975     case TypeFunc::Parms:
 976       projs->resproj = pn;
 977       break;
 978     default:
 979       assert(false, "unexpected projection from allocation node.");


 980     }
 981   }
 982 
 983   // The resproj may not exist because the result could be ignored
 984   // and the exception object may not exist if an exception handler
 985   // swallows the exception but all the other must exist and be found.
 986   assert(projs->fallthrough_proj      != nullptr, "must be found");
 987   do_asserts = do_asserts && !Compile::current()->inlining_incrementally();

 988   assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
 989   assert(!do_asserts || projs->fallthrough_memproj   != nullptr, "must be found");
 990   assert(!do_asserts || projs->fallthrough_ioproj    != nullptr, "must be found");
 991   assert(!do_asserts || projs->catchall_catchproj    != nullptr, "must be found");
 992   if (separate_io_proj) {
 993     assert(!do_asserts || projs->catchall_memproj    != nullptr, "must be found");
 994     assert(!do_asserts || projs->catchall_ioproj     != nullptr, "must be found");
 995   }

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




1069   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1070   ciMethod* callee = method();
1071   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1072     assert(override_symbolic_info(), "should be set");
1073   }
1074   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1075   return true;
1076 }
1077 #endif
1078 
1079 #ifndef PRODUCT
1080 void CallJavaNode::dump_spec(outputStream* st) const {
1081   if( _method ) _method->print_short_name(st);
1082   CallNode::dump_spec(st);
1083 }
1084 
1085 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1086   if (_method) {
1087     _method->print_short_name(st);
1088   } else {

1091 }
1092 #endif
1093 
1094 void CallJavaNode::register_for_late_inline() {
1095   if (generator() != nullptr) {
1096     Compile::current()->prepend_late_inline(generator());
1097     set_generator(nullptr);
1098   } else {
1099     assert(false, "repeated inline attempt");
1100   }
1101 }
1102 
1103 //=============================================================================
1104 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1105 bool CallStaticJavaNode::cmp( const Node &n ) const {
1106   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1107   return CallJavaNode::cmp(call);
1108 }
1109 
1110 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {










1111   CallGenerator* cg = generator();
1112   if (can_reshape && cg != nullptr) {
1113     if (cg->is_mh_late_inline()) {
1114       assert(IncrementalInlineMH, "required");
1115       assert(cg->call_node() == this, "mismatch");
1116       assert(cg->method()->is_method_handle_intrinsic(), "required");
1117 
1118       // Check whether this MH handle call becomes a candidate for inlining.
1119       ciMethod* callee = cg->method();
1120       vmIntrinsics::ID iid = callee->intrinsic_id();
1121       if (iid == vmIntrinsics::_invokeBasic) {
1122         if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1123           register_for_late_inline();
1124         }
1125       } else if (iid == vmIntrinsics::_linkToNative) {
1126         // never retry
1127       } else {
1128         assert(callee->has_member_arg(), "wrong type of call?");
1129         if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1130           register_for_late_inline();

1152 
1153 //----------------------------uncommon_trap_request----------------------------
1154 // If this is an uncommon trap, return the request code, else zero.
1155 int CallStaticJavaNode::uncommon_trap_request() const {
1156   return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1157 }
1158 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1159 #ifndef PRODUCT
1160   if (!(call->req() > TypeFunc::Parms &&
1161         call->in(TypeFunc::Parms) != nullptr &&
1162         call->in(TypeFunc::Parms)->is_Con() &&
1163         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1164     assert(in_dump() != 0, "OK if dumping");
1165     tty->print("[bad uncommon trap]");
1166     return 0;
1167   }
1168 #endif
1169   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1170 }
1171 


























































































































1172 #ifndef PRODUCT
1173 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1174   st->print("# Static ");
1175   if (_name != nullptr) {
1176     st->print("%s", _name);
1177     int trap_req = uncommon_trap_request();
1178     if (trap_req != 0) {
1179       char buf[100];
1180       st->print("(%s)",
1181                  Deoptimization::format_trap_request(buf, sizeof(buf),
1182                                                      trap_req));
1183     }
1184     st->print(" ");
1185   }
1186   CallJavaNode::dump_spec(st);
1187 }
1188 
1189 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1190   if (_method) {
1191     _method->print_short_name(st);

1263 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1264 bool CallRuntimeNode::cmp( const Node &n ) const {
1265   CallRuntimeNode &call = (CallRuntimeNode&)n;
1266   return CallNode::cmp(call) && !strcmp(_name,call._name);
1267 }
1268 #ifndef PRODUCT
1269 void CallRuntimeNode::dump_spec(outputStream *st) const {
1270   st->print("# ");
1271   st->print("%s", _name);
1272   CallNode::dump_spec(st);
1273 }
1274 #endif
1275 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1276 bool CallLeafVectorNode::cmp( const Node &n ) const {
1277   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1278   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1279 }
1280 
1281 //------------------------------calling_convention-----------------------------
1282 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







1283   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1284 }
1285 
1286 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1287 #ifdef ASSERT
1288   assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1289          "return vector size must match");
1290   const TypeTuple* d = tf()->domain();
1291   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1292     Node* arg = in(i);
1293     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1294            "vector argument size must match");
1295   }
1296 #endif
1297 
1298   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1299 }
1300 
1301 //=============================================================================
1302 //------------------------------calling_convention-----------------------------
1303 
1304 
1305 //=============================================================================
1306 #ifndef PRODUCT
1307 void CallLeafNode::dump_spec(outputStream *st) const {
1308   st->print("# ");
1309   st->print("%s", _name);
1310   CallNode::dump_spec(st);
1311 }
1312 #endif
1313 






1314 //=============================================================================
1315 
1316 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1317   assert(verify_jvms(jvms), "jvms must match");
1318   int loc = jvms->locoff() + idx;
1319   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1320     // If current local idx is top then local idx - 1 could
1321     // be a long/double that needs to be killed since top could
1322     // represent the 2nd half of the long/double.
1323     uint ideal = in(loc -1)->ideal_reg();
1324     if (ideal == Op_RegD || ideal == Op_RegL) {
1325       // set other (low index) half to top
1326       set_req(loc - 1, in(loc));
1327     }
1328   }
1329   set_req(loc, c);
1330 }
1331 
1332 uint SafePointNode::size_of() const { return sizeof(*this); }
1333 bool SafePointNode::cmp( const Node &n ) const {

1344   }
1345 }
1346 
1347 
1348 //----------------------------next_exception-----------------------------------
1349 SafePointNode* SafePointNode::next_exception() const {
1350   if (len() == req()) {
1351     return nullptr;
1352   } else {
1353     Node* n = in(req());
1354     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1355     return (SafePointNode*) n;
1356   }
1357 }
1358 
1359 
1360 //------------------------------Ideal------------------------------------------
1361 // Skip over any collapsed Regions
1362 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1363   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1364   return remove_dead_region(phase, can_reshape) ? this : nullptr;













1365 }
1366 
1367 //------------------------------Identity---------------------------------------
1368 // Remove obviously duplicate safepoints
1369 Node* SafePointNode::Identity(PhaseGVN* phase) {
1370 
1371   // If you have back to back safepoints, remove one
1372   if (in(TypeFunc::Control)->is_SafePoint()) {
1373     Node* out_c = unique_ctrl_out_or_null();
1374     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1375     // outer loop's safepoint could confuse removal of the outer loop.
1376     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1377       return in(TypeFunc::Control);
1378     }
1379   }
1380 
1381   // Transforming long counted loops requires a safepoint node. Do not
1382   // eliminate a safepoint until loop opts are over.
1383   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1384     Node *n0 = in(0)->in(0);

1502 }
1503 
1504 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1505   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1506   int nb = igvn->C->root()->find_prec_edge(this);
1507   if (nb != -1) {
1508     igvn->delete_precedence_of(igvn->C->root(), nb);
1509   }
1510 }
1511 
1512 //==============  SafePointScalarObjectNode  ==============
1513 
1514 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1515   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1516   _first_index(first_index),
1517   _depth(depth),
1518   _n_fields(n_fields),
1519   _alloc(alloc)
1520 {
1521 #ifdef ASSERT
1522   if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1523     alloc->dump();
1524     assert(false, "unexpected call node");
1525   }
1526 #endif
1527   init_class_id(Class_SafePointScalarObject);
1528 }
1529 
1530 // Do not allow value-numbering for SafePointScalarObject node.
1531 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1532 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1533   return (&n == this); // Always fail except on self
1534 }
1535 
1536 uint SafePointScalarObjectNode::ideal_reg() const {
1537   return 0; // No matching to machine instruction
1538 }
1539 
1540 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1541   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1542 }

1607     new_node = false;
1608     return (SafePointScalarMergeNode*)cached;
1609   }
1610   new_node = true;
1611   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1612   sosn_map->Insert((void*)this, (void*)res);
1613   return res;
1614 }
1615 
1616 #ifndef PRODUCT
1617 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1618   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1619 }
1620 #endif
1621 
1622 //=============================================================================
1623 uint AllocateNode::size_of() const { return sizeof(*this); }
1624 
1625 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1626                            Node *ctrl, Node *mem, Node *abio,
1627                            Node *size, Node *klass_node, Node *initial_test)


1628   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1629 {
1630   init_class_id(Class_Allocate);
1631   init_flags(Flag_is_macro);
1632   _is_scalar_replaceable = false;
1633   _is_non_escaping = false;
1634   _is_allocation_MemBar_redundant = false;

1635   Node *topnode = C->top();
1636 
1637   init_req( TypeFunc::Control  , ctrl );
1638   init_req( TypeFunc::I_O      , abio );
1639   init_req( TypeFunc::Memory   , mem );
1640   init_req( TypeFunc::ReturnAdr, topnode );
1641   init_req( TypeFunc::FramePtr , topnode );
1642   init_req( AllocSize          , size);
1643   init_req( KlassNode          , klass_node);
1644   init_req( InitialTest        , initial_test);
1645   init_req( ALength            , topnode);
1646   init_req( ValidLengthTest    , topnode);



1647   C->add_macro_node(this);
1648 }
1649 
1650 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1651 {
1652   assert(initializer != nullptr && initializer->is_object_initializer(),

1653          "unexpected initializer method");
1654   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1655   if (analyzer == nullptr) {
1656     return;
1657   }
1658 
1659   // Allocation node is first parameter in its initializer
1660   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1661     _is_allocation_MemBar_redundant = true;
1662   }
1663 }
1664 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {

1665   Node* mark_node = nullptr;
1666   if (UseCompactObjectHeaders) {
1667     Node* klass_node = in(AllocateNode::KlassNode);
1668     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1669     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);






1670   } else {
1671     // For now only enable fast locking for non-array types
1672     mark_node = phase->MakeConX(markWord::prototype().value());
1673   }
1674   return mark_node;
1675 }
1676 
1677 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1678 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1679 // a CastII is appropriate, return null.
1680 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1681   Node *length = in(AllocateNode::ALength);
1682   assert(length != nullptr, "length is not null");
1683 
1684   const TypeInt* length_type = phase->find_int_type(length);
1685   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1686 
1687   if (ary_type != nullptr && length_type != nullptr) {
1688     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1689     if (narrow_length_type != length_type) {
1690       // Assert one of:
1691       //   - the narrow_length is 0
1692       //   - the narrow_length is not wider than length
1693       assert(narrow_length_type == TypeInt::ZERO ||
1694              (length_type->is_con() && narrow_length_type->is_con() &&

2050 
2051 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2052   st->print("%s", _kind_names[_kind]);
2053 }
2054 #endif
2055 
2056 //=============================================================================
2057 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2058 
2059   // perform any generic optimizations first (returns 'this' or null)
2060   Node *result = SafePointNode::Ideal(phase, can_reshape);
2061   if (result != nullptr)  return result;
2062   // Don't bother trying to transform a dead node
2063   if (in(0) && in(0)->is_top())  return nullptr;
2064 
2065   // Now see if we can optimize away this lock.  We don't actually
2066   // remove the locking here, we simply set the _eliminate flag which
2067   // prevents macro expansion from expanding the lock.  Since we don't
2068   // modify the graph, the value returned from this function is the
2069   // one computed above.
2070   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2071     //
2072     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2073     //
2074     ConnectionGraph *cgr = phase->C->congraph();
2075     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2076       assert(!is_eliminated() || is_coarsened(), "sanity");
2077       // The lock could be marked eliminated by lock coarsening
2078       // code during first IGVN before EA. Replace coarsened flag
2079       // to eliminate all associated locks/unlocks.
2080 #ifdef ASSERT
2081       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2082 #endif
2083       this->set_non_esc_obj();
2084       return result;
2085     }
2086 
2087     if (!phase->C->do_locks_coarsening()) {
2088       return result; // Compiling without locks coarsening
2089     }
2090     //

2251 }
2252 
2253 //=============================================================================
2254 uint UnlockNode::size_of() const { return sizeof(*this); }
2255 
2256 //=============================================================================
2257 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2258 
2259   // perform any generic optimizations first (returns 'this' or null)
2260   Node *result = SafePointNode::Ideal(phase, can_reshape);
2261   if (result != nullptr)  return result;
2262   // Don't bother trying to transform a dead node
2263   if (in(0) && in(0)->is_top())  return nullptr;
2264 
2265   // Now see if we can optimize away this unlock.  We don't actually
2266   // remove the unlocking here, we simply set the _eliminate flag which
2267   // prevents macro expansion from expanding the unlock.  Since we don't
2268   // modify the graph, the value returned from this function is the
2269   // one computed above.
2270   // Escape state is defined after Parse phase.
2271   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2272     //
2273     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2274     //
2275     ConnectionGraph *cgr = phase->C->congraph();
2276     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2277       assert(!is_eliminated() || is_coarsened(), "sanity");
2278       // The lock could be marked eliminated by lock coarsening
2279       // code during first IGVN before EA. Replace coarsened flag
2280       // to eliminate all associated locks/unlocks.
2281 #ifdef ASSERT
2282       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2283 #endif
2284       this->set_non_esc_obj();
2285     }
2286   }
2287   return result;
2288 }
2289 
2290 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2291   if (C == nullptr) {

2331     }
2332     // unrelated
2333     return false;
2334   }
2335 
2336   if (dest_t->isa_aryptr()) {
2337     // arraycopy or array clone
2338     if (t_oop->isa_instptr()) {
2339       return false;
2340     }
2341     if (!t_oop->isa_aryptr()) {
2342       return true;
2343     }
2344 
2345     const Type* elem = dest_t->is_aryptr()->elem();
2346     if (elem == Type::BOTTOM) {
2347       // An array but we don't know what elements are
2348       return true;
2349     }
2350 
2351     dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();

2352     uint dest_alias = phase->C->get_alias_index(dest_t);
2353     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2354 
2355     return dest_alias == t_oop_alias;
2356   }
2357 
2358   return true;
2359 }

   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 "compiler/compileLog.hpp"
  26 #include "ci/ciFlatArrayKlass.hpp"
  27 #include "ci/bcEscapeAnalyzer.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/inlinetypenode.hpp"
  38 #include "opto/locknode.hpp"
  39 #include "opto/machnode.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/parse.hpp"
  42 #include "opto/regalloc.hpp"
  43 #include "opto/regmask.hpp"
  44 #include "opto/rootnode.hpp"
  45 #include "opto/runtime.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/stubRoutines.hpp"
  48 #include "utilities/powerOfTwo.hpp"
  49 #include "code/vmreg.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 {

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

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

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

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

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

 795           }
 796         }
 797 
 798         if (OptoReg::is_valid(regs.second())) {
 799           rm.Insert(regs.second());
 800         }
 801         return new MachProjNode(this,con,rm,ideal_reg);
 802       } else {
 803         assert(con == TypeFunc::Parms+1, "only one return value");
 804         assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
 805         return new MachProjNode(this,con, RegMask::Empty, (uint)OptoReg::Bad);
 806       }
 807     }




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

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

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

 992     case TypeFunc::I_O:
 993       if (pn->_is_io_use)
 994         projs->catchall_ioproj = pn;
 995       else
 996         projs->fallthrough_ioproj = pn;
 997       for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
 998         Node* e = pn->out(j);
 999         if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
1000           assert(projs->exobj == nullptr, "only one");
1001           projs->exobj = e;
1002         }
1003       }
1004       break;
1005     case TypeFunc::Memory:
1006       if (pn->_is_io_use)
1007         projs->catchall_memproj = pn;
1008       else
1009         projs->fallthrough_memproj = pn;
1010       break;
1011     case TypeFunc::Parms:
1012       projs->resproj[0] = pn;
1013       break;
1014     default:
1015       assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1016       projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1017       break;
1018     }
1019   }
1020 
1021   // The resproj may not exist because the result could be ignored
1022   // and the exception object may not exist if an exception handler
1023   // swallows the exception but all the other must exist and be found.

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

1134 }
1135 #endif
1136 
1137 void CallJavaNode::register_for_late_inline() {
1138   if (generator() != nullptr) {
1139     Compile::current()->prepend_late_inline(generator());
1140     set_generator(nullptr);
1141   } else {
1142     assert(false, "repeated inline attempt");
1143   }
1144 }
1145 
1146 //=============================================================================
1147 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1148 bool CallStaticJavaNode::cmp( const Node &n ) const {
1149   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1150   return CallJavaNode::cmp(call);
1151 }
1152 
1153 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1154   if (can_reshape && uncommon_trap_request() != 0) {
1155     PhaseIterGVN* igvn = phase->is_IterGVN();
1156     if (remove_unknown_flat_array_load(igvn, in(0), in(TypeFunc::Memory), in(TypeFunc::Parms))) {
1157       if (!in(0)->is_Region()) {
1158         igvn->replace_input_of(this, 0, phase->C->top());
1159       }
1160       return this;
1161     }
1162   }
1163 
1164   CallGenerator* cg = generator();
1165   if (can_reshape && cg != nullptr) {
1166     if (cg->is_mh_late_inline()) {
1167       assert(IncrementalInlineMH, "required");
1168       assert(cg->call_node() == this, "mismatch");
1169       assert(cg->method()->is_method_handle_intrinsic(), "required");
1170 
1171       // Check whether this MH handle call becomes a candidate for inlining.
1172       ciMethod* callee = cg->method();
1173       vmIntrinsics::ID iid = callee->intrinsic_id();
1174       if (iid == vmIntrinsics::_invokeBasic) {
1175         if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1176           register_for_late_inline();
1177         }
1178       } else if (iid == vmIntrinsics::_linkToNative) {
1179         // never retry
1180       } else {
1181         assert(callee->has_member_arg(), "wrong type of call?");
1182         if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1183           register_for_late_inline();

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

1438 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1439 bool CallRuntimeNode::cmp( const Node &n ) const {
1440   CallRuntimeNode &call = (CallRuntimeNode&)n;
1441   return CallNode::cmp(call) && !strcmp(_name,call._name);
1442 }
1443 #ifndef PRODUCT
1444 void CallRuntimeNode::dump_spec(outputStream *st) const {
1445   st->print("# ");
1446   st->print("%s", _name);
1447   CallNode::dump_spec(st);
1448 }
1449 #endif
1450 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1451 bool CallLeafVectorNode::cmp( const Node &n ) const {
1452   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1453   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1454 }
1455 
1456 //------------------------------calling_convention-----------------------------
1457 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1458   if (_entry_point == nullptr) {
1459     // The call to that stub is a special case: its inputs are
1460     // multiple values returned from a call and so it should follow
1461     // the return convention.
1462     SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1463     return;
1464   }
1465   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1466 }
1467 
1468 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1469 #ifdef ASSERT
1470   assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1471          "return vector size must match");
1472   const TypeTuple* d = tf()->domain_sig();
1473   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1474     Node* arg = in(i);
1475     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1476            "vector argument size must match");
1477   }
1478 #endif
1479 
1480   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1481 }
1482 
1483 //=============================================================================
1484 //------------------------------calling_convention-----------------------------
1485 
1486 
1487 //=============================================================================
1488 #ifndef PRODUCT
1489 void CallLeafNode::dump_spec(outputStream *st) const {
1490   st->print("# ");
1491   st->print("%s", _name);
1492   CallNode::dump_spec(st);
1493 }
1494 #endif
1495 
1496 uint CallLeafNoFPNode::match_edge(uint idx) const {
1497   // Null entry point is a special case for which the target is in a
1498   // register. Need to match that edge.
1499   return entry_point() == nullptr && idx == TypeFunc::Parms;
1500 }
1501 
1502 //=============================================================================
1503 
1504 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1505   assert(verify_jvms(jvms), "jvms must match");
1506   int loc = jvms->locoff() + idx;
1507   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1508     // If current local idx is top then local idx - 1 could
1509     // be a long/double that needs to be killed since top could
1510     // represent the 2nd half of the long/double.
1511     uint ideal = in(loc -1)->ideal_reg();
1512     if (ideal == Op_RegD || ideal == Op_RegL) {
1513       // set other (low index) half to top
1514       set_req(loc - 1, in(loc));
1515     }
1516   }
1517   set_req(loc, c);
1518 }
1519 
1520 uint SafePointNode::size_of() const { return sizeof(*this); }
1521 bool SafePointNode::cmp( const Node &n ) const {

1532   }
1533 }
1534 
1535 
1536 //----------------------------next_exception-----------------------------------
1537 SafePointNode* SafePointNode::next_exception() const {
1538   if (len() == req()) {
1539     return nullptr;
1540   } else {
1541     Node* n = in(req());
1542     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1543     return (SafePointNode*) n;
1544   }
1545 }
1546 
1547 
1548 //------------------------------Ideal------------------------------------------
1549 // Skip over any collapsed Regions
1550 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1551   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1552   if (remove_dead_region(phase, can_reshape)) {
1553     return this;
1554   }
1555   // Scalarize inline types in safepoint debug info.
1556   // Delay this until all inlining is over to avoid getting inconsistent debug info.
1557   if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1558     for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1559       Node* n = in(i)->uncast();
1560       if (n->is_InlineType()) {
1561         n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1562       }
1563     }
1564   }
1565   return nullptr;
1566 }
1567 
1568 //------------------------------Identity---------------------------------------
1569 // Remove obviously duplicate safepoints
1570 Node* SafePointNode::Identity(PhaseGVN* phase) {
1571 
1572   // If you have back to back safepoints, remove one
1573   if (in(TypeFunc::Control)->is_SafePoint()) {
1574     Node* out_c = unique_ctrl_out_or_null();
1575     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1576     // outer loop's safepoint could confuse removal of the outer loop.
1577     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1578       return in(TypeFunc::Control);
1579     }
1580   }
1581 
1582   // Transforming long counted loops requires a safepoint node. Do not
1583   // eliminate a safepoint until loop opts are over.
1584   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1585     Node *n0 = in(0)->in(0);

1703 }
1704 
1705 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1706   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1707   int nb = igvn->C->root()->find_prec_edge(this);
1708   if (nb != -1) {
1709     igvn->delete_precedence_of(igvn->C->root(), nb);
1710   }
1711 }
1712 
1713 //==============  SafePointScalarObjectNode  ==============
1714 
1715 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1716   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1717   _first_index(first_index),
1718   _depth(depth),
1719   _n_fields(n_fields),
1720   _alloc(alloc)
1721 {
1722 #ifdef ASSERT
1723   if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1724     alloc->dump();
1725     assert(false, "unexpected call node");
1726   }
1727 #endif
1728   init_class_id(Class_SafePointScalarObject);
1729 }
1730 
1731 // Do not allow value-numbering for SafePointScalarObject node.
1732 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1733 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1734   return (&n == this); // Always fail except on self
1735 }
1736 
1737 uint SafePointScalarObjectNode::ideal_reg() const {
1738   return 0; // No matching to machine instruction
1739 }
1740 
1741 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1742   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1743 }

1808     new_node = false;
1809     return (SafePointScalarMergeNode*)cached;
1810   }
1811   new_node = true;
1812   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1813   sosn_map->Insert((void*)this, (void*)res);
1814   return res;
1815 }
1816 
1817 #ifndef PRODUCT
1818 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1819   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1820 }
1821 #endif
1822 
1823 //=============================================================================
1824 uint AllocateNode::size_of() const { return sizeof(*this); }
1825 
1826 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1827                            Node *ctrl, Node *mem, Node *abio,
1828                            Node *size, Node *klass_node,
1829                            Node* initial_test,
1830                            InlineTypeNode* inline_type_node)
1831   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1832 {
1833   init_class_id(Class_Allocate);
1834   init_flags(Flag_is_macro);
1835   _is_scalar_replaceable = false;
1836   _is_non_escaping = false;
1837   _is_allocation_MemBar_redundant = false;
1838   _larval = false;
1839   Node *topnode = C->top();
1840 
1841   init_req( TypeFunc::Control  , ctrl );
1842   init_req( TypeFunc::I_O      , abio );
1843   init_req( TypeFunc::Memory   , mem );
1844   init_req( TypeFunc::ReturnAdr, topnode );
1845   init_req( TypeFunc::FramePtr , topnode );
1846   init_req( AllocSize          , size);
1847   init_req( KlassNode          , klass_node);
1848   init_req( InitialTest        , initial_test);
1849   init_req( ALength            , topnode);
1850   init_req( ValidLengthTest    , topnode);
1851   init_req( InlineType     , inline_type_node);
1852   // DefaultValue defaults to nullptr
1853   // RawDefaultValue defaults to nullptr
1854   C->add_macro_node(this);
1855 }
1856 
1857 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1858 {
1859   assert(initializer != nullptr &&
1860          (initializer->is_object_constructor() || initializer->is_class_initializer()),
1861          "unexpected initializer method");
1862   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1863   if (analyzer == nullptr) {
1864     return;
1865   }
1866 
1867   // Allocation node is first parameter in its initializer
1868   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1869     _is_allocation_MemBar_redundant = true;
1870   }
1871 }
1872 
1873 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
1874   Node* mark_node = nullptr;
1875   if (UseCompactObjectHeaders || EnableValhalla) {
1876     Node* klass_node = in(AllocateNode::KlassNode);
1877     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1878     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1879     if (EnableValhalla) {
1880       mark_node = phase->transform(mark_node);
1881       // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
1882       mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
1883     }
1884     return mark_node;
1885   } else {
1886     return phase->MakeConX(markWord::prototype().value());

1887   }

1888 }
1889 
1890 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1891 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1892 // a CastII is appropriate, return null.
1893 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1894   Node *length = in(AllocateNode::ALength);
1895   assert(length != nullptr, "length is not null");
1896 
1897   const TypeInt* length_type = phase->find_int_type(length);
1898   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1899 
1900   if (ary_type != nullptr && length_type != nullptr) {
1901     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1902     if (narrow_length_type != length_type) {
1903       // Assert one of:
1904       //   - the narrow_length is 0
1905       //   - the narrow_length is not wider than length
1906       assert(narrow_length_type == TypeInt::ZERO ||
1907              (length_type->is_con() && narrow_length_type->is_con() &&

2263 
2264 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2265   st->print("%s", _kind_names[_kind]);
2266 }
2267 #endif
2268 
2269 //=============================================================================
2270 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2271 
2272   // perform any generic optimizations first (returns 'this' or null)
2273   Node *result = SafePointNode::Ideal(phase, can_reshape);
2274   if (result != nullptr)  return result;
2275   // Don't bother trying to transform a dead node
2276   if (in(0) && in(0)->is_top())  return nullptr;
2277 
2278   // Now see if we can optimize away this lock.  We don't actually
2279   // remove the locking here, we simply set the _eliminate flag which
2280   // prevents macro expansion from expanding the lock.  Since we don't
2281   // modify the graph, the value returned from this function is the
2282   // one computed above.
2283   const Type* obj_type = phase->type(obj_node());
2284   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2285     //
2286     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2287     //
2288     ConnectionGraph *cgr = phase->C->congraph();
2289     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2290       assert(!is_eliminated() || is_coarsened(), "sanity");
2291       // The lock could be marked eliminated by lock coarsening
2292       // code during first IGVN before EA. Replace coarsened flag
2293       // to eliminate all associated locks/unlocks.
2294 #ifdef ASSERT
2295       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2296 #endif
2297       this->set_non_esc_obj();
2298       return result;
2299     }
2300 
2301     if (!phase->C->do_locks_coarsening()) {
2302       return result; // Compiling without locks coarsening
2303     }
2304     //

2465 }
2466 
2467 //=============================================================================
2468 uint UnlockNode::size_of() const { return sizeof(*this); }
2469 
2470 //=============================================================================
2471 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2472 
2473   // perform any generic optimizations first (returns 'this' or null)
2474   Node *result = SafePointNode::Ideal(phase, can_reshape);
2475   if (result != nullptr)  return result;
2476   // Don't bother trying to transform a dead node
2477   if (in(0) && in(0)->is_top())  return nullptr;
2478 
2479   // Now see if we can optimize away this unlock.  We don't actually
2480   // remove the unlocking here, we simply set the _eliminate flag which
2481   // prevents macro expansion from expanding the unlock.  Since we don't
2482   // modify the graph, the value returned from this function is the
2483   // one computed above.
2484   // Escape state is defined after Parse phase.
2485   const Type* obj_type = phase->type(obj_node());
2486   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2487     //
2488     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2489     //
2490     ConnectionGraph *cgr = phase->C->congraph();
2491     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2492       assert(!is_eliminated() || is_coarsened(), "sanity");
2493       // The lock could be marked eliminated by lock coarsening
2494       // code during first IGVN before EA. Replace coarsened flag
2495       // to eliminate all associated locks/unlocks.
2496 #ifdef ASSERT
2497       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2498 #endif
2499       this->set_non_esc_obj();
2500     }
2501   }
2502   return result;
2503 }
2504 
2505 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2506   if (C == nullptr) {

2546     }
2547     // unrelated
2548     return false;
2549   }
2550 
2551   if (dest_t->isa_aryptr()) {
2552     // arraycopy or array clone
2553     if (t_oop->isa_instptr()) {
2554       return false;
2555     }
2556     if (!t_oop->isa_aryptr()) {
2557       return true;
2558     }
2559 
2560     const Type* elem = dest_t->is_aryptr()->elem();
2561     if (elem == Type::BOTTOM) {
2562       // An array but we don't know what elements are
2563       return true;
2564     }
2565 
2566     dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2567     t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2568     uint dest_alias = phase->C->get_alias_index(dest_t);
2569     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2570 
2571     return dest_alias == t_oop_alias;
2572   }
2573 
2574   return true;
2575 }
< prev index next >