< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page

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


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

  37 #include "opto/locknode.hpp"
  38 #include "opto/machnode.hpp"
  39 #include "opto/matcher.hpp"


  40 #include "opto/parse.hpp"
  41 #include "opto/regalloc.hpp"
  42 #include "opto/regmask.hpp"
  43 #include "opto/rootnode.hpp"
  44 #include "opto/runtime.hpp"

  45 #include "runtime/sharedRuntime.hpp"

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

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


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







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

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







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









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






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

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











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





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

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


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

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

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




1095   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1096   ciMethod* callee = method();
1097   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1098     assert(override_symbolic_info(), "should be set");
1099   }
1100   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1101   return true;
1102 }
1103 #endif
1104 
1105 #ifndef PRODUCT
1106 void CallJavaNode::dump_spec(outputStream* st) const {
1107   if( _method ) _method->print_short_name(st);
1108   CallNode::dump_spec(st);
1109 }
1110 
1111 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1112   if (_method) {
1113     _method->print_short_name(st);
1114   } else {

1117 }
1118 #endif
1119 
1120 void CallJavaNode::register_for_late_inline() {
1121   if (generator() != nullptr) {
1122     Compile::current()->prepend_late_inline(generator());
1123     set_generator(nullptr);
1124   } else {
1125     assert(false, "repeated inline attempt");
1126   }
1127 }
1128 
1129 //=============================================================================
1130 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1131 bool CallStaticJavaNode::cmp( const Node &n ) const {
1132   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1133   return CallJavaNode::cmp(call);
1134 }
1135 
1136 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {





















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

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













































































































































































1197 #ifndef PRODUCT
1198 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1199   st->print("# Static ");
1200   if (_name != nullptr) {
1201     st->print("%s", _name);
1202     int trap_req = uncommon_trap_request();
1203     if (trap_req != 0) {
1204       char buf[100];
1205       st->print("(%s)",
1206                  Deoptimization::format_trap_request(buf, sizeof(buf),
1207                                                      trap_req));
1208     }
1209     st->print(" ");
1210   }
1211   CallJavaNode::dump_spec(st);
1212 }
1213 
1214 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1215   if (_method) {
1216     _method->print_short_name(st);

1292 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1293 bool CallRuntimeNode::cmp( const Node &n ) const {
1294   CallRuntimeNode &call = (CallRuntimeNode&)n;
1295   return CallNode::cmp(call) && !strcmp(_name,call._name);
1296 }
1297 #ifndef PRODUCT
1298 void CallRuntimeNode::dump_spec(outputStream *st) const {
1299   st->print("# ");
1300   st->print("%s", _name);
1301   CallNode::dump_spec(st);
1302 }
1303 #endif
1304 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1305 bool CallLeafVectorNode::cmp( const Node &n ) const {
1306   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1307   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1308 }
1309 
1310 //------------------------------calling_convention-----------------------------
1311 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {







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






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

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













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

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

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


1704   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1705 {
1706   init_class_id(Class_Allocate);
1707   init_flags(Flag_is_macro);
1708   _is_scalar_replaceable = false;
1709   _is_non_escaping = false;
1710   _is_allocation_MemBar_redundant = false;

1711   Node *topnode = C->top();
1712 
1713   init_req( TypeFunc::Control  , ctrl );
1714   init_req( TypeFunc::I_O      , abio );
1715   init_req( TypeFunc::Memory   , mem );
1716   init_req( TypeFunc::ReturnAdr, topnode );
1717   init_req( TypeFunc::FramePtr , topnode );
1718   init_req( AllocSize          , size);
1719   init_req( KlassNode          , klass_node);
1720   init_req( InitialTest        , initial_test);
1721   init_req( ALength            , topnode);
1722   init_req( ValidLengthTest    , topnode);



1723   C->add_macro_node(this);
1724 }
1725 
1726 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1727 {
1728   assert(initializer != nullptr && initializer->is_object_initializer(),

1729          "unexpected initializer method");
1730   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1731   if (analyzer == nullptr) {
1732     return;
1733   }
1734 
1735   // Allocation node is first parameter in its initializer
1736   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1737     _is_allocation_MemBar_redundant = true;
1738   }
1739 }
1740 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {

1741   Node* mark_node = nullptr;
1742   if (UseCompactObjectHeaders) {
1743     Node* klass_node = in(AllocateNode::KlassNode);
1744     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1745     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);






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

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

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

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

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

2407     }
2408     // unrelated
2409     return false;
2410   }
2411 
2412   if (dest_t->isa_aryptr()) {
2413     // arraycopy or array clone
2414     if (t_oop->isa_instptr()) {
2415       return false;
2416     }
2417     if (!t_oop->isa_aryptr()) {
2418       return true;
2419     }
2420 
2421     const Type* elem = dest_t->is_aryptr()->elem();
2422     if (elem == Type::BOTTOM) {
2423       // An array but we don't know what elements are
2424       return true;
2425     }
2426 
2427     dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();

2428     uint dest_alias = phase->C->get_alias_index(dest_t);
2429     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2430 
2431     return dest_alias == t_oop_alias;
2432   }
2433 
2434   return true;
2435 }

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











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

 478       if (cik->is_instance_klass()) {
 479         cik->print_name_on(st);
 480         iklass = cik->as_instance_klass();
 481       } else if (cik->is_type_array_klass()) {
 482         cik->as_array_klass()->base_element_type()->print_name_on(st);
 483         st->print("[%d]", spobj->n_fields());
 484       } else if (cik->is_obj_array_klass()) {
 485         ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
 486         if (cie->is_instance_klass()) {
 487           cie->print_name_on(st);
 488         } else if (cie->is_type_array_klass()) {
 489           cie->as_array_klass()->base_element_type()->print_name_on(st);
 490         } else {
 491           ShouldNotReachHere();
 492         }
 493         st->print("[%d]", spobj->n_fields());
 494         int ndim = cik->as_array_klass()->dimension() - 1;
 495         while (ndim-- > 0) {
 496           st->print("[]");
 497         }
 498       } else {
 499         assert(false, "unexpected type %s", cik->name()->as_utf8());
 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* null_marker = mcall->in(first_ind++);
 507           if (!null_marker->is_top()) {
 508             st->print(" [null marker");
 509             format_helper(regalloc, st, null_marker, ":", -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.

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

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




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

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

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

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

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

1158 }
1159 #endif
1160 
1161 void CallJavaNode::register_for_late_inline() {
1162   if (generator() != nullptr) {
1163     Compile::current()->prepend_late_inline(generator());
1164     set_generator(nullptr);
1165   } else {
1166     assert(false, "repeated inline attempt");
1167   }
1168 }
1169 
1170 //=============================================================================
1171 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1172 bool CallStaticJavaNode::cmp( const Node &n ) const {
1173   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1174   return CallJavaNode::cmp(call);
1175 }
1176 
1177 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1178   if (can_reshape && uncommon_trap_request() != 0) {
1179     PhaseIterGVN* igvn = phase->is_IterGVN();
1180     if (remove_unknown_flat_array_load(igvn, control(), memory(), in(TypeFunc::Parms))) {
1181       if (!control()->is_Region()) {
1182         igvn->replace_input_of(this, 0, phase->C->top());
1183       }
1184       return this;
1185     }
1186   }
1187 
1188   // Try to replace the runtime call to the substitutability test emitted by acmp if we can reason
1189   // about the operands
1190   if (can_reshape && !control()->is_top() && method() != nullptr &&
1191       method()->holder() == phase->C->env()->ValueObjectMethods_klass() &&
1192       method()->name() == ciSymbols::isSubstitutable_name()) {
1193     Node* res = replace_is_substitutable(phase->is_IterGVN());
1194     if (res != nullptr) {
1195       return res;
1196     }
1197   }
1198 
1199   CallGenerator* cg = generator();
1200   if (can_reshape && cg != nullptr) {
1201     if (cg->is_mh_late_inline()) {
1202       assert(IncrementalInlineMH, "required");
1203       assert(cg->call_node() == this, "mismatch");
1204       assert(cg->method()->is_method_handle_intrinsic(), "required");
1205 
1206       // Check whether this MH handle call becomes a candidate for inlining.
1207       ciMethod* callee = cg->method();
1208       vmIntrinsics::ID iid = callee->intrinsic_id();
1209       if (iid == vmIntrinsics::_invokeBasic) {
1210         if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1211           register_for_late_inline();
1212         }
1213       } else if (iid == vmIntrinsics::_linkToNative) {
1214         // never retry
1215       } else {
1216         assert(callee->has_member_arg(), "wrong type of call?");
1217         if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1218           register_for_late_inline();

1239 
1240 //----------------------------uncommon_trap_request----------------------------
1241 // If this is an uncommon trap, return the request code, else zero.
1242 int CallStaticJavaNode::uncommon_trap_request() const {
1243   return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1244 }
1245 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1246 #ifndef PRODUCT
1247   if (!(call->req() > TypeFunc::Parms &&
1248         call->in(TypeFunc::Parms) != nullptr &&
1249         call->in(TypeFunc::Parms)->is_Con() &&
1250         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1251     assert(in_dump() != 0, "OK if dumping");
1252     tty->print("[bad uncommon trap]");
1253     return 0;
1254   }
1255 #endif
1256   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1257 }
1258 
1259 // Split if can cause the flat array branch of an array load with unknown type (see
1260 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1261 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1262 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1263   if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1264     return false;
1265   }
1266   if (ctl->is_Region()) {
1267     bool res = false;
1268     for (uint i = 1; i < ctl->req(); i++) {
1269       MergeMemNode* mm = mem->clone()->as_MergeMem();
1270       for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1271         Node* m = mms.memory();
1272         if (m->is_Phi() && m->in(0) == ctl) {
1273           mms.set_memory(m->in(i));
1274         }
1275       }
1276       if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1277         res = true;
1278         if (!ctl->in(i)->is_Region()) {
1279           igvn->replace_input_of(ctl, i, igvn->C->top());
1280         }
1281       }
1282       igvn->remove_dead_node(mm);
1283     }
1284     return res;
1285   }
1286   // Verify the control flow is ok
1287   Node* call = ctl;
1288   MemBarNode* membar = nullptr;
1289   for (;;) {
1290     if (call == nullptr || call->is_top()) {
1291       return false;
1292     }
1293     if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1294       call = call->in(0);
1295     } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1296                call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1297       // If there is no explicit flat array accesses in the compilation unit, there would be no
1298       // membar here
1299       if (call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar()) {
1300         membar = call->in(0)->in(0)->as_MemBar();
1301       }
1302       break;
1303     } else {
1304       return false;
1305     }
1306   }
1307 
1308   JVMState* jvms = call->jvms();
1309   if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1310     return false;
1311   }
1312 
1313   Node* call_mem = call->in(TypeFunc::Memory);
1314   if (call_mem == nullptr || call_mem->is_top()) {
1315     return false;
1316   }
1317   if (!call_mem->is_MergeMem()) {
1318     call_mem = MergeMemNode::make(call_mem);
1319     igvn->register_new_node_with_optimizer(call_mem);
1320   }
1321 
1322   // Verify that there's no unexpected side effect
1323   for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1324     Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1325     Node* m2 = mms2.memory2();
1326 
1327     for (uint i = 0; i < 100; i++) {
1328       if (m1 == m2) {
1329         break;
1330       } else if (m1->is_Proj()) {
1331         m1 = m1->in(0);
1332       } else if (m1->is_MemBar()) {
1333         m1 = m1->in(TypeFunc::Memory);
1334       } else if (m1->Opcode() == Op_CallStaticJava &&
1335                  m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1336         if (m1 != call) {
1337           return false;
1338         }
1339         break;
1340       } else if (m1->is_MergeMem()) {
1341         MergeMemNode* mm = m1->as_MergeMem();
1342         int idx = mms2.alias_idx();
1343         if (idx == Compile::AliasIdxBot) {
1344           m1 = mm->base_memory();
1345         } else {
1346           m1 = mm->memory_at(idx);
1347         }
1348       } else {
1349         return false;
1350       }
1351     }
1352   }
1353   if (call_mem->outcnt() == 0) {
1354     igvn->remove_dead_node(call_mem);
1355   }
1356 
1357   // Remove membar preceding the call
1358   if (membar != nullptr) {
1359     membar->remove(igvn);
1360   }
1361 
1362   address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1363   CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1364   unc->init_req(TypeFunc::Control, call->in(0));
1365   unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1366   unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1367   unc->init_req(TypeFunc::FramePtr,  call->in(TypeFunc::FramePtr));
1368   unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1369   unc->init_req(TypeFunc::Parms+0, unc_arg);
1370   unc->set_cnt(PROB_UNLIKELY_MAG(4));
1371   unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1372 
1373   // Replace the call with an uncommon trap
1374   igvn->replace_input_of(call, 0, igvn->C->top());
1375 
1376   igvn->register_new_node_with_optimizer(unc);
1377 
1378   Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1379   Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1380   igvn->add_input_to(igvn->C->root(), halt);
1381 
1382   return true;
1383 }
1384 
1385 // Try to replace a runtime call to the substitutability test by either a simple pointer comparison
1386 // if either operand is not a value object, or comparing their fields if either operand is an
1387 // object of a known value type
1388 Node* CallStaticJavaNode::replace_is_substitutable(PhaseIterGVN* igvn) {
1389   // Delay IGVN during macro expansion
1390   assert(!igvn->delay_transform(), "must not delay during Ideal");
1391   igvn->set_delay_transform(true);
1392 
1393   // Prepare to inline, clone the jvms
1394   JVMState* jvms = this->jvms()->clone_shallow(igvn->C);
1395   assert(jvms->map()->next_exception() == nullptr, "this call does not throw");
1396   SafePointNode* map = new SafePointNode(req(), jvms);
1397   igvn->register_new_node_with_optimizer(map);
1398   for (uint i = 0; i < req(); i++) {
1399     map->init_req(i, in(i));
1400   }
1401   MergeMemNode* mem = MergeMemNode::make(map->memory());
1402   igvn->register_new_node_with_optimizer(mem);
1403   map->set_memory(mem);
1404   jvms->set_map(map);
1405   GraphKit kit(jvms, igvn);
1406 
1407   Node* left = in(TypeFunc::Parms);
1408   Node* right = in(TypeFunc::Parms + 1);
1409   Node* replace = InlineTypeNode::emit_substitutability_check(&kit, left, right);
1410   igvn->set_delay_transform(false);
1411   if (replace == nullptr) {
1412     return nullptr;
1413   }
1414 
1415   // Kill exception projections and return a tuple that will replace the call
1416   CallProjections* projs = extract_projections(false /*separate_io_proj*/);
1417   if (projs->fallthrough_catchproj != nullptr) {
1418     igvn->replace_node(projs->fallthrough_catchproj, kit.control());
1419   }
1420   if (projs->catchall_memproj != nullptr) {
1421     igvn->replace_node(projs->catchall_memproj, igvn->C->top());
1422   }
1423   if (projs->catchall_ioproj != nullptr) {
1424     igvn->replace_node(projs->catchall_ioproj, igvn->C->top());
1425   }
1426   if (projs->catchall_catchproj != nullptr) {
1427     igvn->replace_node(projs->catchall_catchproj, igvn->C->top());
1428   }
1429   return TupleNode::make(tf()->range_cc(), igvn->C->top(), kit.i_o(), kit.reset_memory(), kit.frameptr(), kit.returnadr(), replace);
1430 }
1431 
1432 #ifndef PRODUCT
1433 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1434   st->print("# Static ");
1435   if (_name != nullptr) {
1436     st->print("%s", _name);
1437     int trap_req = uncommon_trap_request();
1438     if (trap_req != 0) {
1439       char buf[100];
1440       st->print("(%s)",
1441                  Deoptimization::format_trap_request(buf, sizeof(buf),
1442                                                      trap_req));
1443     }
1444     st->print(" ");
1445   }
1446   CallJavaNode::dump_spec(st);
1447 }
1448 
1449 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1450   if (_method) {
1451     _method->print_short_name(st);

1527 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1528 bool CallRuntimeNode::cmp( const Node &n ) const {
1529   CallRuntimeNode &call = (CallRuntimeNode&)n;
1530   return CallNode::cmp(call) && !strcmp(_name,call._name);
1531 }
1532 #ifndef PRODUCT
1533 void CallRuntimeNode::dump_spec(outputStream *st) const {
1534   st->print("# ");
1535   st->print("%s", _name);
1536   CallNode::dump_spec(st);
1537 }
1538 #endif
1539 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1540 bool CallLeafVectorNode::cmp( const Node &n ) const {
1541   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1542   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1543 }
1544 
1545 //------------------------------calling_convention-----------------------------
1546 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1547   if (_entry_point == nullptr) {
1548     // The call to that stub is a special case: its inputs are
1549     // multiple values returned from a call and so it should follow
1550     // the return convention.
1551     SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1552     return;
1553   }
1554   SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1555 }
1556 
1557 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1558 #ifdef ASSERT
1559   assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1560          "return vector size must match");
1561   const TypeTuple* d = tf()->domain_sig();
1562   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1563     Node* arg = in(i);
1564     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1565            "vector argument size must match");
1566   }
1567 #endif
1568 
1569   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1570 }
1571 
1572 //=============================================================================
1573 //------------------------------calling_convention-----------------------------
1574 
1575 
1576 //=============================================================================
1577 bool CallLeafPureNode::is_unused() const {
1578   return proj_out_or_null(TypeFunc::Parms) == nullptr;
1579 }
1580 
1581 bool CallLeafPureNode::is_dead() const {
1582   return proj_out_or_null(TypeFunc::Control) == nullptr;
1583 }
1584 
1585 /* We make a tuple of the global input state + TOP for the output values.
1586  * We use this to delete a pure function that is not used: by replacing the call with
1587  * such a tuple, we let output Proj's idealization pick the corresponding input of the
1588  * pure call, so jumping over it, and effectively, removing the call from the graph.
1589  * This avoids doing the graph surgery manually, but leaves that to IGVN
1590  * that is specialized for doing that right. We need also tuple components for output
1591  * values of the function to respect the return arity, and in case there is a projection
1592  * that would pick an output (which shouldn't happen at the moment).
1593  */
1594 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1595   // Transparently propagate input state but parameters
1596   TupleNode* tuple = TupleNode::make(
1597       tf()->range_cc(),
1598       in(TypeFunc::Control),
1599       in(TypeFunc::I_O),
1600       in(TypeFunc::Memory),
1601       in(TypeFunc::FramePtr),
1602       in(TypeFunc::ReturnAdr));
1603 
1604   // And add TOPs for the return values
1605   for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1606     tuple->set_req(i, C->top());
1607   }
1608 
1609   return tuple;
1610 }
1611 
1612 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1613   if (is_dead()) {
1614     return nullptr;
1615   }
1616 
1617   // We need to wait until IGVN because during parsing, usages might still be missing
1618   // and we would remove the call immediately.
1619   if (can_reshape && is_unused()) {
1620     // The result is not used. We remove the call by replacing it with a tuple, that
1621     // is later disintegrated by the projections.
1622     return make_tuple_of_input_state_and_top_return_values(phase->C);
1623   }
1624 
1625   return CallRuntimeNode::Ideal(phase, can_reshape);
1626 }
1627 
1628 #ifndef PRODUCT
1629 void CallLeafNode::dump_spec(outputStream *st) const {
1630   st->print("# ");
1631   st->print("%s", _name);
1632   CallNode::dump_spec(st);
1633 }
1634 #endif
1635 
1636 uint CallLeafNoFPNode::match_edge(uint idx) const {
1637   // Null entry point is a special case for which the target is in a
1638   // register. Need to match that edge.
1639   return entry_point() == nullptr && idx == TypeFunc::Parms;
1640 }
1641 
1642 //=============================================================================
1643 
1644 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1645   assert(verify_jvms(jvms), "jvms must match");
1646   int loc = jvms->locoff() + idx;
1647   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1648     // If current local idx is top then local idx - 1 could
1649     // be a long/double that needs to be killed since top could
1650     // represent the 2nd half of the long/double.
1651     uint ideal = in(loc -1)->ideal_reg();
1652     if (ideal == Op_RegD || ideal == Op_RegL) {
1653       // set other (low index) half to top
1654       set_req(loc - 1, in(loc));
1655     }
1656   }
1657   set_req(loc, c);
1658 }
1659 
1660 uint SafePointNode::size_of() const { return sizeof(*this); }
1661 bool SafePointNode::cmp( const Node &n ) const {

1672   }
1673 }
1674 
1675 
1676 //----------------------------next_exception-----------------------------------
1677 SafePointNode* SafePointNode::next_exception() const {
1678   if (len() == req()) {
1679     return nullptr;
1680   } else {
1681     Node* n = in(req());
1682     assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1683     return (SafePointNode*) n;
1684   }
1685 }
1686 
1687 
1688 //------------------------------Ideal------------------------------------------
1689 // Skip over any collapsed Regions
1690 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1691   assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1692   if (remove_dead_region(phase, can_reshape)) {
1693     return this;
1694   }
1695   // Scalarize inline types in safepoint debug info.
1696   // Delay this until all inlining is over to avoid getting inconsistent debug info.
1697   if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1698     for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1699       Node* n = in(i)->uncast();
1700       if (n->is_InlineType()) {
1701         n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1702       }
1703     }
1704   }
1705   return nullptr;
1706 }
1707 
1708 //------------------------------Identity---------------------------------------
1709 // Remove obviously duplicate safepoints
1710 Node* SafePointNode::Identity(PhaseGVN* phase) {
1711 
1712   // If you have back to back safepoints, remove one
1713   if (in(TypeFunc::Control)->is_SafePoint()) {
1714     Node* out_c = unique_ctrl_out_or_null();
1715     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1716     // outer loop's safepoint could confuse removal of the outer loop.
1717     if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1718       return in(TypeFunc::Control);
1719     }
1720   }
1721 
1722   // Transforming long counted loops requires a safepoint node. Do not
1723   // eliminate a safepoint until loop opts are over.
1724   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1725     Node *n0 = in(0)->in(0);

1839 }
1840 
1841 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1842   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1843   int nb = igvn->C->root()->find_prec_edge(this);
1844   if (nb != -1) {
1845     igvn->delete_precedence_of(igvn->C->root(), nb);
1846   }
1847 }
1848 
1849 //==============  SafePointScalarObjectNode  ==============
1850 
1851 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1852   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1853   _first_index(first_index),
1854   _depth(depth),
1855   _n_fields(n_fields),
1856   _alloc(alloc)
1857 {
1858 #ifdef ASSERT
1859   if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1860     alloc->dump();
1861     assert(false, "unexpected call node");
1862   }
1863 #endif
1864   init_class_id(Class_SafePointScalarObject);
1865 }
1866 
1867 // Do not allow value-numbering for SafePointScalarObject node.
1868 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1869 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1870   return (&n == this); // Always fail except on self
1871 }
1872 
1873 uint SafePointScalarObjectNode::ideal_reg() const {
1874   return 0; // No matching to machine instruction
1875 }
1876 
1877 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1878   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1879 }

1944     new_node = false;
1945     return (SafePointScalarMergeNode*)cached;
1946   }
1947   new_node = true;
1948   SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1949   sosn_map->Insert((void*)this, (void*)res);
1950   return res;
1951 }
1952 
1953 #ifndef PRODUCT
1954 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1955   st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1956 }
1957 #endif
1958 
1959 //=============================================================================
1960 uint AllocateNode::size_of() const { return sizeof(*this); }
1961 
1962 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1963                            Node *ctrl, Node *mem, Node *abio,
1964                            Node *size, Node *klass_node,
1965                            Node* initial_test,
1966                            InlineTypeNode* inline_type_node)
1967   : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1968 {
1969   init_class_id(Class_Allocate);
1970   init_flags(Flag_is_macro);
1971   _is_scalar_replaceable = false;
1972   _is_non_escaping = false;
1973   _is_allocation_MemBar_redundant = false;
1974   _larval = false;
1975   Node *topnode = C->top();
1976 
1977   init_req( TypeFunc::Control  , ctrl );
1978   init_req( TypeFunc::I_O      , abio );
1979   init_req( TypeFunc::Memory   , mem );
1980   init_req( TypeFunc::ReturnAdr, topnode );
1981   init_req( TypeFunc::FramePtr , topnode );
1982   init_req( AllocSize          , size);
1983   init_req( KlassNode          , klass_node);
1984   init_req( InitialTest        , initial_test);
1985   init_req( ALength            , topnode);
1986   init_req( ValidLengthTest    , topnode);
1987   init_req( InlineType     , inline_type_node);
1988   // DefaultValue defaults to nullptr
1989   // RawDefaultValue defaults to nullptr
1990   C->add_macro_node(this);
1991 }
1992 
1993 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1994 {
1995   assert(initializer != nullptr &&
1996          (initializer->is_object_constructor() || initializer->is_class_initializer()),
1997          "unexpected initializer method");
1998   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1999   if (analyzer == nullptr) {
2000     return;
2001   }
2002 
2003   // Allocation node is first parameter in its initializer
2004   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
2005     _is_allocation_MemBar_redundant = true;
2006   }
2007 }
2008 
2009 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
2010   Node* mark_node = nullptr;
2011   if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
2012     Node* klass_node = in(AllocateNode::KlassNode);
2013     Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
2014     mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
2015     if (Arguments::is_valhalla_enabled()) {
2016       mark_node = phase->transform(mark_node);
2017       // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
2018       mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
2019     }
2020     return mark_node;
2021   } else {
2022     return phase->MakeConX(markWord::prototype().value());

2023   }

2024 }
2025 
2026 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
2027 // CastII, if appropriate.  If we are not allowed to create new nodes, and
2028 // a CastII is appropriate, return null.
2029 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
2030   Node *length = in(AllocateNode::ALength);
2031   assert(length != nullptr, "length is not null");
2032 
2033   const TypeInt* length_type = phase->find_int_type(length);
2034   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
2035 
2036   if (ary_type != nullptr && length_type != nullptr) {
2037     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
2038     if (narrow_length_type != length_type) {
2039       // Assert one of:
2040       //   - the narrow_length is 0
2041       //   - the narrow_length is not wider than length
2042       assert(narrow_length_type == TypeInt::ZERO ||
2043              (length_type->is_con() && narrow_length_type->is_con() &&

2399 
2400 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2401   st->print("%s", _kind_names[_kind]);
2402 }
2403 #endif
2404 
2405 //=============================================================================
2406 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2407 
2408   // perform any generic optimizations first (returns 'this' or null)
2409   Node *result = SafePointNode::Ideal(phase, can_reshape);
2410   if (result != nullptr)  return result;
2411   // Don't bother trying to transform a dead node
2412   if (in(0) && in(0)->is_top())  return nullptr;
2413 
2414   // Now see if we can optimize away this lock.  We don't actually
2415   // remove the locking here, we simply set the _eliminate flag which
2416   // prevents macro expansion from expanding the lock.  Since we don't
2417   // modify the graph, the value returned from this function is the
2418   // one computed above.
2419   const Type* obj_type = phase->type(obj_node());
2420   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2421     //
2422     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2423     //
2424     ConnectionGraph *cgr = phase->C->congraph();
2425     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2426       assert(!is_eliminated() || is_coarsened(), "sanity");
2427       // The lock could be marked eliminated by lock coarsening
2428       // code during first IGVN before EA. Replace coarsened flag
2429       // to eliminate all associated locks/unlocks.
2430 #ifdef ASSERT
2431       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2432 #endif
2433       this->set_non_esc_obj();
2434       return result;
2435     }
2436 
2437     if (!phase->C->do_locks_coarsening()) {
2438       return result; // Compiling without locks coarsening
2439     }
2440     //

2601 }
2602 
2603 //=============================================================================
2604 uint UnlockNode::size_of() const { return sizeof(*this); }
2605 
2606 //=============================================================================
2607 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2608 
2609   // perform any generic optimizations first (returns 'this' or null)
2610   Node *result = SafePointNode::Ideal(phase, can_reshape);
2611   if (result != nullptr)  return result;
2612   // Don't bother trying to transform a dead node
2613   if (in(0) && in(0)->is_top())  return nullptr;
2614 
2615   // Now see if we can optimize away this unlock.  We don't actually
2616   // remove the unlocking here, we simply set the _eliminate flag which
2617   // prevents macro expansion from expanding the unlock.  Since we don't
2618   // modify the graph, the value returned from this function is the
2619   // one computed above.
2620   // Escape state is defined after Parse phase.
2621   const Type* obj_type = phase->type(obj_node());
2622   if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2623     //
2624     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2625     //
2626     ConnectionGraph *cgr = phase->C->congraph();
2627     if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2628       assert(!is_eliminated() || is_coarsened(), "sanity");
2629       // The lock could be marked eliminated by lock coarsening
2630       // code during first IGVN before EA. Replace coarsened flag
2631       // to eliminate all associated locks/unlocks.
2632 #ifdef ASSERT
2633       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2634 #endif
2635       this->set_non_esc_obj();
2636     }
2637   }
2638   return result;
2639 }
2640 
2641 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2642   if (C == nullptr) {

2682     }
2683     // unrelated
2684     return false;
2685   }
2686 
2687   if (dest_t->isa_aryptr()) {
2688     // arraycopy or array clone
2689     if (t_oop->isa_instptr()) {
2690       return false;
2691     }
2692     if (!t_oop->isa_aryptr()) {
2693       return true;
2694     }
2695 
2696     const Type* elem = dest_t->is_aryptr()->elem();
2697     if (elem == Type::BOTTOM) {
2698       // An array but we don't know what elements are
2699       return true;
2700     }
2701 
2702     dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2703     t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2704     uint dest_alias = phase->C->get_alias_index(dest_t);
2705     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2706 
2707     return dest_alias == t_oop_alias;
2708   }
2709 
2710   return true;
2711 }
< prev index next >