< 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 {
1089     st->print("<?>");
1090   }
1091 }
1092 #endif
1093 
1094 //=============================================================================
1095 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1096 bool CallStaticJavaNode::cmp( const Node &n ) const {
1097   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1098   return CallJavaNode::cmp(call);
1099 }
1100 
1101 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {










1102   CallGenerator* cg = generator();
1103   if (can_reshape && cg != nullptr) {
1104     assert(IncrementalInlineMH, "required");
1105     assert(cg->call_node() == this, "mismatch");
1106     assert(cg->is_mh_late_inline(), "not virtual");
1107 
1108     // Check whether this MH handle call becomes a candidate for inlining.
1109     ciMethod* callee = cg->method();
1110     vmIntrinsics::ID iid = callee->intrinsic_id();
1111     if (iid == vmIntrinsics::_invokeBasic) {
1112       if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1113         phase->C->prepend_late_inline(cg);
1114         set_generator(nullptr);
1115       }
1116     } else if (iid == vmIntrinsics::_linkToNative) {
1117       // never retry
1118     } else {
1119       assert(callee->has_member_arg(), "wrong type of call?");
1120       if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1121         phase->C->prepend_late_inline(cg);

1134 
1135 //----------------------------uncommon_trap_request----------------------------
1136 // If this is an uncommon trap, return the request code, else zero.
1137 int CallStaticJavaNode::uncommon_trap_request() const {
1138   return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1139 }
1140 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1141 #ifndef PRODUCT
1142   if (!(call->req() > TypeFunc::Parms &&
1143         call->in(TypeFunc::Parms) != nullptr &&
1144         call->in(TypeFunc::Parms)->is_Con() &&
1145         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1146     assert(in_dump() != 0, "OK if dumping");
1147     tty->print("[bad uncommon trap]");
1148     return 0;
1149   }
1150 #endif
1151   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1152 }
1153 


























































































































1154 #ifndef PRODUCT
1155 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1156   st->print("# Static ");
1157   if (_name != nullptr) {
1158     st->print("%s", _name);
1159     int trap_req = uncommon_trap_request();
1160     if (trap_req != 0) {
1161       char buf[100];
1162       st->print("(%s)",
1163                  Deoptimization::format_trap_request(buf, sizeof(buf),
1164                                                      trap_req));
1165     }
1166     st->print(" ");
1167   }
1168   CallJavaNode::dump_spec(st);
1169 }
1170 
1171 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1172   if (_method) {
1173     _method->print_short_name(st);

1238 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1239 bool CallRuntimeNode::cmp( const Node &n ) const {
1240   CallRuntimeNode &call = (CallRuntimeNode&)n;
1241   return CallNode::cmp(call) && !strcmp(_name,call._name);
1242 }
1243 #ifndef PRODUCT
1244 void CallRuntimeNode::dump_spec(outputStream *st) const {
1245   st->print("# ");
1246   st->print("%s", _name);
1247   CallNode::dump_spec(st);
1248 }
1249 #endif
1250 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1251 bool CallLeafVectorNode::cmp( const Node &n ) const {
1252   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1253   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1254 }
1255 
1256 //------------------------------calling_convention-----------------------------
1257 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







1258   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1259 }
1260 
1261 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1262 #ifdef ASSERT
1263   assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1264          "return vector size must match");
1265   const TypeTuple* d = tf()->domain();
1266   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1267     Node* arg = in(i);
1268     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1269            "vector argument size must match");
1270   }
1271 #endif
1272 
1273   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1274 }
1275 
1276 //=============================================================================
1277 //------------------------------calling_convention-----------------------------
1278 
1279 
1280 //=============================================================================
1281 #ifndef PRODUCT
1282 void CallLeafNode::dump_spec(outputStream *st) const {
1283   st->print("# ");
1284   st->print("%s", _name);
1285   CallNode::dump_spec(st);
1286 }
1287 #endif
1288 






1289 //=============================================================================
1290 
1291 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1292   assert(verify_jvms(jvms), "jvms must match");
1293   int loc = jvms->locoff() + idx;
1294   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1295     // If current local idx is top then local idx - 1 could
1296     // be a long/double that needs to be killed since top could
1297     // represent the 2nd half of the long/double.
1298     uint ideal = in(loc -1)->ideal_reg();
1299     if (ideal == Op_RegD || ideal == Op_RegL) {
1300       // set other (low index) half to top
1301       set_req(loc - 1, in(loc));
1302     }
1303   }
1304   set_req(loc, c);
1305 }
1306 
1307 uint SafePointNode::size_of() const { return sizeof(*this); }
1308 bool SafePointNode::cmp( const Node &n ) const {

1319   }
1320 }
1321 
1322 
1323 //----------------------------next_exception-----------------------------------
1324 SafePointNode* SafePointNode::next_exception() const {
1325   if (len() == req()) {
1326     return nullptr;
1327   } else {
1328     Node* n = in(req());
1329     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1330     return (SafePointNode*) n;
1331   }
1332 }
1333 
1334 
1335 //------------------------------Ideal------------------------------------------
1336 // Skip over any collapsed Regions
1337 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1338   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1339   return remove_dead_region(phase, can_reshape) ? this : nullptr;













1340 }
1341 
1342 //------------------------------Identity---------------------------------------
1343 // Remove obviously duplicate safepoints
1344 Node* SafePointNode::Identity(PhaseGVN* phase) {
1345 
1346   // If you have back to back safepoints, remove one
1347   if (in(TypeFunc::Control)->is_SafePoint()) {
1348     Node* out_c = unique_ctrl_out_or_null();
1349     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1350     // outer loop's safepoint could confuse removal of the outer loop.
1351     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1352       return in(TypeFunc::Control);
1353     }
1354   }
1355 
1356   // Transforming long counted loops requires a safepoint node. Do not
1357   // eliminate a safepoint until loop opts are over.
1358   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1359     Node *n0 = in(0)->in(0);

1477 }
1478 
1479 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1480   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1481   int nb = igvn->C->root()->find_prec_edge(this);
1482   if (nb != -1) {
1483     igvn->delete_precedence_of(igvn->C->root(), nb);
1484   }
1485 }
1486 
1487 //==============  SafePointScalarObjectNode  ==============
1488 
1489 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1490   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1491   _first_index(first_index),
1492   _depth(depth),
1493   _n_fields(n_fields),
1494   _alloc(alloc)
1495 {
1496 #ifdef ASSERT
1497   if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1498     alloc->dump();
1499     assert(false, "unexpected call node");
1500   }
1501 #endif
1502   init_class_id(Class_SafePointScalarObject);
1503 }
1504 
1505 // Do not allow value-numbering for SafePointScalarObject node.
1506 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1507 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1508   return (&n == this); // Always fail except on self
1509 }
1510 
1511 uint SafePointScalarObjectNode::ideal_reg() const {
1512   return 0; // No matching to machine instruction
1513 }
1514 
1515 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1516   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1517 }

1582     new_node = false;
1583     return (SafePointScalarMergeNode*)cached;
1584   }
1585   new_node = true;
1586   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1587   sosn_map->Insert((void*)this, (void*)res);
1588   return res;
1589 }
1590 
1591 #ifndef PRODUCT
1592 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1593   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1594 }
1595 #endif
1596 
1597 //=============================================================================
1598 uint AllocateNode::size_of() const { return sizeof(*this); }
1599 
1600 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1601                            Node *ctrl, Node *mem, Node *abio,
1602                            Node *size, Node *klass_node, Node *initial_test)


1603   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1604 {
1605   init_class_id(Class_Allocate);
1606   init_flags(Flag_is_macro);
1607   _is_scalar_replaceable = false;
1608   _is_non_escaping = false;
1609   _is_allocation_MemBar_redundant = false;

1610   Node *topnode = C->top();
1611 
1612   init_req( TypeFunc::Control  , ctrl );
1613   init_req( TypeFunc::I_O      , abio );
1614   init_req( TypeFunc::Memory   , mem );
1615   init_req( TypeFunc::ReturnAdr, topnode );
1616   init_req( TypeFunc::FramePtr , topnode );
1617   init_req( AllocSize          , size);
1618   init_req( KlassNode          , klass_node);
1619   init_req( InitialTest        , initial_test);
1620   init_req( ALength            , topnode);
1621   init_req( ValidLengthTest    , topnode);



1622   C->add_macro_node(this);
1623 }
1624 
1625 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1626 {
1627   assert(initializer != nullptr && initializer->is_object_initializer(),

1628          "unexpected initializer method");
1629   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1630   if (analyzer == nullptr) {
1631     return;
1632   }
1633 
1634   // Allocation node is first parameter in its initializer
1635   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1636     _is_allocation_MemBar_redundant = true;
1637   }
1638 }
1639 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {

1640   Node* mark_node = nullptr;
1641   if (UseCompactObjectHeaders) {
1642     Node* klass_node = in(AllocateNode::KlassNode);
1643     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1644     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);






1645   } else {
1646     // For now only enable fast locking for non-array types
1647     mark_node = phase->MakeConX(markWord::prototype().value());
1648   }
1649   return mark_node;
1650 }
1651 
1652 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1653 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1654 // a CastII is appropriate, return null.
1655 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1656   Node *length = in(AllocateNode::ALength);
1657   assert(length != nullptr, "length is not null");
1658 
1659   const TypeInt* length_type = phase->find_int_type(length);
1660   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1661 
1662   if (ary_type != nullptr && length_type != nullptr) {
1663     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1664     if (narrow_length_type != length_type) {
1665       // Assert one of:
1666       //   - the narrow_length is 0
1667       //   - the narrow_length is not wider than length
1668       assert(narrow_length_type == TypeInt::ZERO ||
1669              (length_type->is_con() && narrow_length_type->is_con() &&

2025 
2026 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2027   st->print("%s", _kind_names[_kind]);
2028 }
2029 #endif
2030 
2031 //=============================================================================
2032 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2033 
2034   // perform any generic optimizations first (returns 'this' or null)
2035   Node *result = SafePointNode::Ideal(phase, can_reshape);
2036   if (result != nullptr)  return result;
2037   // Don't bother trying to transform a dead node
2038   if (in(0) && in(0)->is_top())  return nullptr;
2039 
2040   // Now see if we can optimize away this lock.  We don't actually
2041   // remove the locking here, we simply set the _eliminate flag which
2042   // prevents macro expansion from expanding the lock.  Since we don't
2043   // modify the graph, the value returned from this function is the
2044   // one computed above.
2045   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2046     //
2047     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2048     //
2049     ConnectionGraph *cgr = phase->C->congraph();
2050     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2051       assert(!is_eliminated() || is_coarsened(), "sanity");
2052       // The lock could be marked eliminated by lock coarsening
2053       // code during first IGVN before EA. Replace coarsened flag
2054       // to eliminate all associated locks/unlocks.
2055 #ifdef ASSERT
2056       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2057 #endif
2058       this->set_non_esc_obj();
2059       return result;
2060     }
2061 
2062     if (!phase->C->do_locks_coarsening()) {
2063       return result; // Compiling without locks coarsening
2064     }
2065     //

2226 }
2227 
2228 //=============================================================================
2229 uint UnlockNode::size_of() const { return sizeof(*this); }
2230 
2231 //=============================================================================
2232 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2233 
2234   // perform any generic optimizations first (returns 'this' or null)
2235   Node *result = SafePointNode::Ideal(phase, can_reshape);
2236   if (result != nullptr)  return result;
2237   // Don't bother trying to transform a dead node
2238   if (in(0) && in(0)->is_top())  return nullptr;
2239 
2240   // Now see if we can optimize away this unlock.  We don't actually
2241   // remove the unlocking here, we simply set the _eliminate flag which
2242   // prevents macro expansion from expanding the unlock.  Since we don't
2243   // modify the graph, the value returned from this function is the
2244   // one computed above.
2245   // Escape state is defined after Parse phase.
2246   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {

2247     //
2248     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2249     //
2250     ConnectionGraph *cgr = phase->C->congraph();
2251     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2252       assert(!is_eliminated() || is_coarsened(), "sanity");
2253       // The lock could be marked eliminated by lock coarsening
2254       // code during first IGVN before EA. Replace coarsened flag
2255       // to eliminate all associated locks/unlocks.
2256 #ifdef ASSERT
2257       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2258 #endif
2259       this->set_non_esc_obj();
2260     }
2261   }
2262   return result;
2263 }
2264 
2265 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2266   if (C == nullptr) {

2306     }
2307     // unrelated
2308     return false;
2309   }
2310 
2311   if (dest_t->isa_aryptr()) {
2312     // arraycopy or array clone
2313     if (t_oop->isa_instptr()) {
2314       return false;
2315     }
2316     if (!t_oop->isa_aryptr()) {
2317       return true;
2318     }
2319 
2320     const Type* elem = dest_t->is_aryptr()->elem();
2321     if (elem == Type::BOTTOM) {
2322       // An array but we don't know what elements are
2323       return true;
2324     }
2325 
2326     dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();

2327     uint dest_alias = phase->C->get_alias_index(dest_t);
2328     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2329 
2330     return dest_alias == t_oop_alias;
2331   }
2332 
2333   return true;
2334 }

   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         ciField* cifield;
 514         if (iklass != nullptr) {
 515           st->print(" [");
 516           if (0 < (uint)iklass->nof_nonstatic_fields()) {
 517             cifield = iklass->nonstatic_field_at(0);
 518             cifield->print_name_on(st);
 519           } else {
 520             // Must be a null marker
 521             st->print("null marker");
 522           }
 523           format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
 524         } else {
 525           format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
 526         }
 527         for (uint j = 1; j < nf; j++) {
 528           fld_node = mcall->in(first_ind+j);
 529           if (iklass != nullptr) {
 530             st->print(", [");
 531             if (j < (uint)iklass->nof_nonstatic_fields()) {
 532               cifield = iklass->nonstatic_field_at(j);
 533               cifield->print_name_on(st);
 534             } else {
 535               // Must be a null marker
 536               st->print("null marker");
 537             }
 538             format_helper(regalloc, st, fld_node, ":", j, &scobjs);
 539           } else {
 540             format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
 541           }
 542         }
 543       }
 544       st->print(" }");
 545     }
 546   }
 547   st->cr();
 548   if (caller() != nullptr) caller()->format(regalloc, n, st);
 549 }
 550 
 551 
 552 void JVMState::dump_spec(outputStream *st) const {
 553   if (_method != nullptr) {
 554     bool printed = false;
 555     if (!Verbose) {
 556       // The JVMS dumps make really, really long lines.
 557       // 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_cc(); }
 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_cc();
 763 }
 764 
 765 //------------------------------calling_convention-----------------------------
 766 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
 767   if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
 768     // The call to that stub is a special case: its inputs are
 769     // multiple values returned from a call and so it should follow
 770     // the return convention.
 771     SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
 772     return;
 773   }
 774   // Use the standard compiler calling convention
 775   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
 776 }
 777 
 778 
 779 //------------------------------match------------------------------------------
 780 // Construct projections for control, I/O, memory-fields, ..., and
 781 // return result(s) along with their RegMask info
 782 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
 783   uint con = proj->_con;
 784   const TypeTuple* range_cc = tf()->range_cc();
 785   if (con >= TypeFunc::Parms) {
 786     if (tf()->returns_inline_type_as_fields()) {
 787       // The call returns multiple values (inline type fields): we
 788       // create one projection per returned value.
 789       assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
 790       uint ideal_reg = range_cc->field_at(con)->ideal_reg();
 791       return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
 792     } else {
 793       if (con == TypeFunc::Parms) {
 794         uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
 795         OptoRegPair regs = Opcode() == Op_CallLeafVector
 796           ? match->vector_return_value(ideal_reg)      // Calls into assembly vector routine
 797           : match->c_return_value(ideal_reg);
 798         RegMask rm = RegMask(regs.first());
 799 
 800         if (Opcode() == Op_CallLeafVector) {
 801           // If the return is in vector, compute appropriate regmask taking into account the whole range
 802           if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
 803             if(OptoReg::is_valid(regs.second())) {
 804               for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
 805                 rm.Insert(r);
 806               }
 807             }

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




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

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

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

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

1037   do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1038   assert(!do_asserts || projs->fallthrough_proj      != nullptr, "must be found");
1039   assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1040   assert(!do_asserts || projs->fallthrough_memproj   != nullptr, "must be found");
1041   assert(!do_asserts || projs->fallthrough_ioproj    != nullptr, "must be found");
1042   assert(!do_asserts || projs->catchall_catchproj    != nullptr, "must be found");
1043   if (separate_io_proj) {
1044     assert(!do_asserts || projs->catchall_memproj    != nullptr, "must be found");
1045     assert(!do_asserts || projs->catchall_ioproj     != nullptr, "must be found");
1046   }
1047   return projs;
1048 }
1049 
1050 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1051 #ifdef ASSERT
1052   // Validate attached generator
1053   CallGenerator* cg = generator();
1054   if (cg != nullptr) {
1055     assert((is_CallStaticJava()  && cg->is_mh_late_inline()) ||
1056            (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1057   }
1058 #endif // ASSERT
1059   return SafePointNode::Ideal(phase, can_reshape);
1060 }
1061 
1062 bool CallNode::is_call_to_arraycopystub() const {
1063   if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1064     return true;
1065   }
1066   return false;
1067 }
1068 
1069 //=============================================================================
1070 uint CallJavaNode::size_of() const { return sizeof(*this); }
1071 bool CallJavaNode::cmp( const Node &n ) const {
1072   CallJavaNode &call = (CallJavaNode&)n;
1073   return CallNode::cmp(call) && _method == call._method &&
1074          _override_symbolic_info == call._override_symbolic_info;
1075 }
1076 
1077 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1078   // Copy debug information and adjust JVMState information
1079   uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1080   uint new_dbg_start = tf()->domain_sig()->cnt();
1081   int jvms_adj  = new_dbg_start - old_dbg_start;
1082   assert (new_dbg_start == req(), "argument count mismatch");
1083   Compile* C = phase->C;
1084 
1085   // SafePointScalarObject node could be referenced several times in debug info.
1086   // Use Dict to record cloned nodes.
1087   Dict* sosn_map = new Dict(cmpkey,hashkey);
1088   for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1089     Node* old_in = sfpt->in(i);
1090     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1091     if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1092       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1093       bool new_node;
1094       Node* new_in = old_sosn->clone(sosn_map, new_node);
1095       if (new_node) { // New node?
1096         new_in->set_req(0, C->root()); // reset control edge
1097         new_in = phase->transform(new_in); // Register new node.
1098       }
1099       old_in = new_in;
1100     }
1101     add_req(old_in);
1102   }
1103 
1104   // JVMS may be shared so clone it before we modify it
1105   set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1106   for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1107     jvms->set_map(this);
1108     jvms->set_locoff(jvms->locoff()+jvms_adj);
1109     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1110     jvms->set_monoff(jvms->monoff()+jvms_adj);
1111     jvms->set_scloff(jvms->scloff()+jvms_adj);
1112     jvms->set_endoff(jvms->endoff()+jvms_adj);
1113   }
1114 }
1115 
1116 #ifdef ASSERT
1117 bool CallJavaNode::validate_symbolic_info() const {
1118   if (method() == nullptr) {
1119     return true; // call into runtime or uncommon trap
1120   }
1121   Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1122   if (EnableValhalla && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1123     return true;
1124   }
1125   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1126   ciMethod* callee = method();
1127   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1128     assert(override_symbolic_info(), "should be set");
1129   }
1130   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1131   return true;
1132 }
1133 #endif
1134 
1135 #ifndef PRODUCT
1136 void CallJavaNode::dump_spec(outputStream* st) const {
1137   if( _method ) _method->print_short_name(st);
1138   CallNode::dump_spec(st);
1139 }
1140 
1141 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1142   if (_method) {
1143     _method->print_short_name(st);
1144   } else {
1145     st->print("<?>");
1146   }
1147 }
1148 #endif
1149 
1150 //=============================================================================
1151 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1152 bool CallStaticJavaNode::cmp( const Node &n ) const {
1153   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1154   return CallJavaNode::cmp(call);
1155 }
1156 
1157 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1158   if (can_reshape && uncommon_trap_request() != 0) {
1159     PhaseIterGVN* igvn = phase->is_IterGVN();
1160     if (remove_unknown_flat_array_load(igvn, in(0), in(TypeFunc::Memory), in(TypeFunc::Parms))) {
1161       if (!in(0)->is_Region()) {
1162         igvn->replace_input_of(this, 0, phase->C->top());
1163       }
1164       return this;
1165     }
1166   }
1167 
1168   CallGenerator* cg = generator();
1169   if (can_reshape && cg != nullptr) {
1170     assert(IncrementalInlineMH, "required");
1171     assert(cg->call_node() == this, "mismatch");
1172     assert(cg->is_mh_late_inline(), "not virtual");
1173 
1174     // Check whether this MH handle call becomes a candidate for inlining.
1175     ciMethod* callee = cg->method();
1176     vmIntrinsics::ID iid = callee->intrinsic_id();
1177     if (iid == vmIntrinsics::_invokeBasic) {
1178       if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1179         phase->C->prepend_late_inline(cg);
1180         set_generator(nullptr);
1181       }
1182     } else if (iid == vmIntrinsics::_linkToNative) {
1183       // never retry
1184     } else {
1185       assert(callee->has_member_arg(), "wrong type of call?");
1186       if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1187         phase->C->prepend_late_inline(cg);

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

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

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

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

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

1875   }

1876 }
1877 
1878 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1879 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1880 // a CastII is appropriate, return null.
1881 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1882   Node *length = in(AllocateNode::ALength);
1883   assert(length != nullptr, "length is not null");
1884 
1885   const TypeInt* length_type = phase->find_int_type(length);
1886   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1887 
1888   if (ary_type != nullptr && length_type != nullptr) {
1889     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1890     if (narrow_length_type != length_type) {
1891       // Assert one of:
1892       //   - the narrow_length is 0
1893       //   - the narrow_length is not wider than length
1894       assert(narrow_length_type == TypeInt::ZERO ||
1895              (length_type->is_con() && narrow_length_type->is_con() &&

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

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

2534     }
2535     // unrelated
2536     return false;
2537   }
2538 
2539   if (dest_t->isa_aryptr()) {
2540     // arraycopy or array clone
2541     if (t_oop->isa_instptr()) {
2542       return false;
2543     }
2544     if (!t_oop->isa_aryptr()) {
2545       return true;
2546     }
2547 
2548     const Type* elem = dest_t->is_aryptr()->elem();
2549     if (elem == Type::BOTTOM) {
2550       // An array but we don't know what elements are
2551       return true;
2552     }
2553 
2554     dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2555     t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2556     uint dest_alias = phase->C->get_alias_index(dest_t);
2557     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2558 
2559     return dest_alias == t_oop_alias;
2560   }
2561 
2562   return true;
2563 }
< prev index next >