6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/bcEscapeAnalyzer.hpp"
26 #include "code/vmreg.hpp"
27 #include "compiler/compileLog.hpp"
28 #include "compiler/oopMap.hpp"
29 #include "gc/shared/barrierSet.hpp"
30 #include "gc/shared/c2/barrierSetC2.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "opto/callGenerator.hpp"
33 #include "opto/callnode.hpp"
34 #include "opto/castnode.hpp"
35 #include "opto/convertnode.hpp"
36 #include "opto/escape.hpp"
37 #include "opto/locknode.hpp"
38 #include "opto/machnode.hpp"
39 #include "opto/matcher.hpp"
40 #include "opto/parse.hpp"
41 #include "opto/regalloc.hpp"
42 #include "opto/regmask.hpp"
43 #include "opto/rootnode.hpp"
44 #include "opto/runtime.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "utilities/powerOfTwo.hpp"
47
48 // Portions of code courtesy of Clifford Click
49
50 // Optimization - Graph Style
51
52 //=============================================================================
53 uint StartNode::size_of() const { return sizeof(*this); }
54 bool StartNode::cmp( const Node &n ) const
55 { return _domain == ((StartNode&)n)._domain; }
56 const Type *StartNode::bottom_type() const { return _domain; }
57 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
58 #ifndef PRODUCT
59 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
60 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
61 #endif
62
63 //------------------------------Ideal------------------------------------------
64 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
65 return remove_dead_region(phase, can_reshape) ? this : nullptr;
66 }
67
68 //------------------------------calling_convention-----------------------------
69 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
70 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
71 }
72
73 //------------------------------Registers--------------------------------------
74 const RegMask &StartNode::in_RegMask(uint) const {
75 return RegMask::EMPTY;
76 }
77
78 //------------------------------match------------------------------------------
79 // Construct projections for incoming parameters, and their RegMask info
80 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
81 switch (proj->_con) {
82 case TypeFunc::Control:
83 case TypeFunc::I_O:
84 case TypeFunc::Memory:
85 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
86 case TypeFunc::FramePtr:
87 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
88 case TypeFunc::ReturnAdr:
89 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
90 case TypeFunc::Parms:
91 default: {
92 uint parm_num = proj->_con - TypeFunc::Parms;
93 const Type *t = _domain->field_at(proj->_con);
94 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
95 return new ConNode(Type::TOP);
96 uint ideal_reg = t->ideal_reg();
97 RegMask &rm = match->_calling_convention_mask[parm_num];
98 return new MachProjNode(this,proj->_con,rm,ideal_reg);
99 }
100 }
101 return nullptr;
102 }
103
104 //------------------------------StartOSRNode----------------------------------
105 // The method start node for an on stack replacement adapter
106
107 //------------------------------osr_domain-----------------------------
108 const TypeTuple *StartOSRNode::osr_domain() {
109 const Type **fields = TypeTuple::fields(2);
110 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
111
112 return TypeTuple::make(TypeFunc::Parms+1, fields);
113 }
114
115 //=============================================================================
116 const char * const ParmNode::names[TypeFunc::Parms+1] = {
117 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
118 };
119
120 #ifndef PRODUCT
121 void ParmNode::dump_spec(outputStream *st) const {
122 if( _con < TypeFunc::Parms ) {
123 st->print("%s", names[_con]);
124 } else {
125 st->print("Parm%d: ",_con-TypeFunc::Parms);
126 // Verbose and WizardMode dump bottom_type for all nodes
127 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
128 }
129 }
130
131 void ParmNode::dump_compact_spec(outputStream *st) const {
132 if (_con < TypeFunc::Parms) {
133 st->print("%s", names[_con]);
134 } else {
482 if (cik->is_instance_klass()) {
483 cik->print_name_on(st);
484 iklass = cik->as_instance_klass();
485 } else if (cik->is_type_array_klass()) {
486 cik->as_array_klass()->base_element_type()->print_name_on(st);
487 st->print("[%d]", spobj->n_fields());
488 } else if (cik->is_obj_array_klass()) {
489 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
490 if (cie->is_instance_klass()) {
491 cie->print_name_on(st);
492 } else if (cie->is_type_array_klass()) {
493 cie->as_array_klass()->base_element_type()->print_name_on(st);
494 } else {
495 ShouldNotReachHere();
496 }
497 st->print("[%d]", spobj->n_fields());
498 int ndim = cik->as_array_klass()->dimension() - 1;
499 while (ndim-- > 0) {
500 st->print("[]");
501 }
502 }
503 st->print("={");
504 uint nf = spobj->n_fields();
505 if (nf > 0) {
506 uint first_ind = spobj->first_index(mcall->jvms());
507 Node* fld_node = mcall->in(first_ind);
508 ciField* cifield;
509 if (iklass != nullptr) {
510 st->print(" [");
511 cifield = iklass->nonstatic_field_at(0);
512 cifield->print_name_on(st);
513 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
514 } else {
515 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
516 }
517 for (uint j = 1; j < nf; j++) {
518 fld_node = mcall->in(first_ind+j);
519 if (iklass != nullptr) {
520 st->print(", [");
521 cifield = iklass->nonstatic_field_at(j);
522 cifield->print_name_on(st);
523 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
524 } else {
525 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
526 }
527 }
528 }
529 st->print(" }");
530 }
531 }
532 st->cr();
533 if (caller() != nullptr) caller()->format(regalloc, n, st);
534 }
535
536
537 void JVMState::dump_spec(outputStream *st) const {
538 if (_method != nullptr) {
539 bool printed = false;
540 if (!Verbose) {
541 // The JVMS dumps make really, really long lines.
542 // Take out the most boring parts, which are the package prefixes.
737 tf()->dump_on(st);
738 }
739 if (_cnt != COUNT_UNKNOWN) {
740 st->print(" C=%f", _cnt);
741 }
742 const Node* const klass_node = in(KlassNode);
743 if (klass_node != nullptr) {
744 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
745
746 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
747 st->print(" allocationKlass:");
748 klass_ptr->exact_klass()->print_name_on(st);
749 }
750 }
751 if (jvms() != nullptr) {
752 jvms()->dump_spec(st);
753 }
754 }
755 #endif
756
757 const Type *CallNode::bottom_type() const { return tf()->range(); }
758 const Type* CallNode::Value(PhaseGVN* phase) const {
759 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
760 return Type::TOP;
761 }
762 return tf()->range();
763 }
764
765 //------------------------------calling_convention-----------------------------
766 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
767 // Use the standard compiler calling convention
768 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
769 }
770
771
772 //------------------------------match------------------------------------------
773 // Construct projections for control, I/O, memory-fields, ..., and
774 // return result(s) along with their RegMask info
775 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
776 switch (proj->_con) {
777 case TypeFunc::Control:
778 case TypeFunc::I_O:
779 case TypeFunc::Memory:
780 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
781
782 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
783 assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
784 // 2nd half of doubles and longs
785 return new MachProjNode(this,proj->_con, RegMask::EMPTY, (uint)OptoReg::Bad);
786
787 case TypeFunc::Parms: { // Normal returns
788 uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
789 OptoRegPair regs = Opcode() == Op_CallLeafVector
790 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
791 : is_CallRuntime()
792 ? match->c_return_value(ideal_reg) // Calls into C runtime
793 : match-> return_value(ideal_reg); // Calls into compiled Java code
794 RegMask rm = RegMask(regs.first());
795
796 if (Opcode() == Op_CallLeafVector) {
797 // If the return is in vector, compute appropriate regmask taking into account the whole range
798 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
799 if(OptoReg::is_valid(regs.second())) {
800 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
801 rm.insert(r);
802 }
803 }
804 }
805 }
806
807 if( OptoReg::is_valid(regs.second()) )
808 rm.insert(regs.second());
809 return new MachProjNode(this,proj->_con,rm,ideal_reg);
810 }
811
812 case TypeFunc::ReturnAdr:
813 case TypeFunc::FramePtr:
814 default:
815 ShouldNotReachHere();
816 }
817 return nullptr;
818 }
819
820 // Do we Match on this edge index or not? Match no edges
821 uint CallNode::match_edge(uint idx) const {
822 return 0;
823 }
824
825 //
826 // Determine whether the call could modify the field of the specified
827 // instance at the specified offset.
828 //
829 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
830 assert((t_oop != nullptr), "sanity");
831 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
832 const TypeTuple* args = _tf->domain();
833 Node* dest = nullptr;
834 // Stubs that can be called once an ArrayCopyNode is expanded have
835 // different signatures. Look for the second pointer argument,
836 // that is the destination of the copy.
837 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
838 if (args->field_at(i)->isa_ptr()) {
839 j++;
840 if (j == 2) {
841 dest = in(i);
842 break;
843 }
844 }
845 }
846 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
847 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
848 return true;
849 }
850 return false;
851 }
852 if (t_oop->is_known_instance()) {
861 Node* proj = proj_out_or_null(TypeFunc::Parms);
862 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
863 return false;
864 }
865 }
866 if (is_CallJava() && as_CallJava()->method() != nullptr) {
867 ciMethod* meth = as_CallJava()->method();
868 if (meth->is_getter()) {
869 return false;
870 }
871 // May modify (by reflection) if an boxing object is passed
872 // as argument or returned.
873 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
874 if (proj != nullptr) {
875 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
876 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
877 (inst_t->instance_klass() == boxing_klass))) {
878 return true;
879 }
880 }
881 const TypeTuple* d = tf()->domain();
882 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
883 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
884 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
885 (inst_t->instance_klass() == boxing_klass))) {
886 return true;
887 }
888 }
889 return false;
890 }
891 }
892 return true;
893 }
894
895 // Does this call have a direct reference to n other than debug information?
896 bool CallNode::has_non_debug_use(Node *n) {
897 const TypeTuple * d = tf()->domain();
898 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
899 Node *arg = in(i);
900 if (arg == n) {
901 return true;
902 }
903 }
904 return false;
905 }
906
907 // Returns the unique CheckCastPP of a call
908 // or 'this' if there are several CheckCastPP or unexpected uses
909 // or returns null if there is no one.
910 Node *CallNode::result_cast() {
911 Node *cast = nullptr;
912
913 Node *p = proj_out_or_null(TypeFunc::Parms);
914 if (p == nullptr)
915 return nullptr;
916
917 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
918 Node *use = p->fast_out(i);
919 if (use->is_CheckCastPP()) {
920 if (cast != nullptr) {
921 return this; // more than 1 CheckCastPP
922 }
923 cast = use;
924 } else if (!use->is_Initialize() &&
925 !use->is_AddP() &&
926 use->Opcode() != Op_MemBarStoreStore) {
927 // Expected uses are restricted to a CheckCastPP, an Initialize
928 // node, a MemBarStoreStore (clone) and AddP nodes. If we
929 // encounter any other use (a Phi node can be seen in rare
930 // cases) return this to prevent incorrect optimizations.
931 return this;
932 }
933 }
934 return cast;
935 }
936
937
938 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) const {
939 projs->fallthrough_proj = nullptr;
940 projs->fallthrough_catchproj = nullptr;
941 projs->fallthrough_ioproj = nullptr;
942 projs->catchall_ioproj = nullptr;
943 projs->catchall_catchproj = nullptr;
944 projs->fallthrough_memproj = nullptr;
945 projs->catchall_memproj = nullptr;
946 projs->resproj = nullptr;
947 projs->exobj = nullptr;
948
949 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
950 ProjNode *pn = fast_out(i)->as_Proj();
951 if (pn->outcnt() == 0) continue;
952 switch (pn->_con) {
953 case TypeFunc::Control:
954 {
955 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
956 projs->fallthrough_proj = pn;
957 const Node* cn = pn->unique_ctrl_out_or_null();
958 if (cn != nullptr && cn->is_Catch()) {
959 ProjNode *cpn = nullptr;
960 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
961 cpn = cn->fast_out(k)->as_Proj();
962 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
963 if (cpn->_con == CatchProjNode::fall_through_index)
964 projs->fallthrough_catchproj = cpn;
965 else {
966 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
967 projs->catchall_catchproj = cpn;
973 case TypeFunc::I_O:
974 if (pn->_is_io_use)
975 projs->catchall_ioproj = pn;
976 else
977 projs->fallthrough_ioproj = pn;
978 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
979 Node* e = pn->out(j);
980 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
981 assert(projs->exobj == nullptr, "only one");
982 projs->exobj = e;
983 }
984 }
985 break;
986 case TypeFunc::Memory:
987 if (pn->_is_io_use)
988 projs->catchall_memproj = pn;
989 else
990 projs->fallthrough_memproj = pn;
991 break;
992 case TypeFunc::Parms:
993 projs->resproj = pn;
994 break;
995 default:
996 assert(false, "unexpected projection from allocation node.");
997 }
998 }
999
1000 // The resproj may not exist because the result could be ignored
1001 // and the exception object may not exist if an exception handler
1002 // swallows the exception but all the other must exist and be found.
1003 assert(projs->fallthrough_proj != nullptr, "must be found");
1004 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1005 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1006 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1007 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1008 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1009 if (separate_io_proj) {
1010 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1011 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1012 }
1013 }
1014
1015 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1016 #ifdef ASSERT
1017 // Validate attached generator
1018 CallGenerator* cg = generator();
1019 if (cg != nullptr) {
1020 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1021 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1022 }
1023 #endif // ASSERT
1024 return SafePointNode::Ideal(phase, can_reshape);
1025 }
1026
1027 bool CallNode::is_call_to_arraycopystub() const {
1028 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1029 return true;
1030 }
1031 return false;
1032 }
1033
1034 //=============================================================================
1035 uint CallJavaNode::size_of() const { return sizeof(*this); }
1036 bool CallJavaNode::cmp( const Node &n ) const {
1037 CallJavaNode &call = (CallJavaNode&)n;
1038 return CallNode::cmp(call) && _method == call._method &&
1039 _override_symbolic_info == call._override_symbolic_info;
1040 }
1041
1042 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1043 // Copy debug information and adjust JVMState information
1044 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
1045 uint new_dbg_start = tf()->domain()->cnt();
1046 int jvms_adj = new_dbg_start - old_dbg_start;
1047 assert (new_dbg_start == req(), "argument count mismatch");
1048 Compile* C = phase->C;
1049
1050 // SafePointScalarObject node could be referenced several times in debug info.
1051 // Use Dict to record cloned nodes.
1052 Dict* sosn_map = new Dict(cmpkey,hashkey);
1053 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1054 Node* old_in = sfpt->in(i);
1055 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1056 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1057 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1058 bool new_node;
1059 Node* new_in = old_sosn->clone(sosn_map, new_node);
1060 if (new_node) { // New node?
1061 new_in->set_req(0, C->root()); // reset control edge
1062 new_in = phase->transform(new_in); // Register new node.
1063 }
1064 old_in = new_in;
1065 }
1066 add_req(old_in);
1067 }
1068
1069 // JVMS may be shared so clone it before we modify it
1070 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1071 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1072 jvms->set_map(this);
1073 jvms->set_locoff(jvms->locoff()+jvms_adj);
1074 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1075 jvms->set_monoff(jvms->monoff()+jvms_adj);
1076 jvms->set_scloff(jvms->scloff()+jvms_adj);
1077 jvms->set_endoff(jvms->endoff()+jvms_adj);
1078 }
1079 }
1080
1081 #ifdef ASSERT
1082 bool CallJavaNode::validate_symbolic_info() const {
1083 if (method() == nullptr) {
1084 return true; // call into runtime or uncommon trap
1085 }
1086 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1087 ciMethod* callee = method();
1088 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1089 assert(override_symbolic_info(), "should be set");
1090 }
1091 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1092 return true;
1093 }
1094 #endif
1095
1096 #ifndef PRODUCT
1097 void CallJavaNode::dump_spec(outputStream* st) const {
1098 if( _method ) _method->print_short_name(st);
1099 CallNode::dump_spec(st);
1100 }
1101
1102 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1103 if (_method) {
1104 _method->print_short_name(st);
1105 } else {
1108 }
1109 #endif
1110
1111 void CallJavaNode::register_for_late_inline() {
1112 if (generator() != nullptr) {
1113 Compile::current()->prepend_late_inline(generator());
1114 set_generator(nullptr);
1115 } else {
1116 assert(false, "repeated inline attempt");
1117 }
1118 }
1119
1120 //=============================================================================
1121 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1122 bool CallStaticJavaNode::cmp( const Node &n ) const {
1123 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1124 return CallJavaNode::cmp(call);
1125 }
1126
1127 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1128 CallGenerator* cg = generator();
1129 if (can_reshape && cg != nullptr) {
1130 if (cg->is_mh_late_inline()) {
1131 assert(IncrementalInlineMH, "required");
1132 assert(cg->call_node() == this, "mismatch");
1133 assert(cg->method()->is_method_handle_intrinsic(), "required");
1134
1135 // Check whether this MH handle call becomes a candidate for inlining.
1136 ciMethod* callee = cg->method();
1137 vmIntrinsics::ID iid = callee->intrinsic_id();
1138 if (iid == vmIntrinsics::_invokeBasic) {
1139 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1140 register_for_late_inline();
1141 }
1142 } else if (iid == vmIntrinsics::_linkToNative) {
1143 // never retry
1144 } else {
1145 assert(callee->has_member_arg(), "wrong type of call?");
1146 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1147 register_for_late_inline();
1168
1169 //----------------------------uncommon_trap_request----------------------------
1170 // If this is an uncommon trap, return the request code, else zero.
1171 int CallStaticJavaNode::uncommon_trap_request() const {
1172 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1173 }
1174 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1175 #ifndef PRODUCT
1176 if (!(call->req() > TypeFunc::Parms &&
1177 call->in(TypeFunc::Parms) != nullptr &&
1178 call->in(TypeFunc::Parms)->is_Con() &&
1179 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1180 assert(in_dump() != 0, "OK if dumping");
1181 tty->print("[bad uncommon trap]");
1182 return 0;
1183 }
1184 #endif
1185 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1186 }
1187
1188 #ifndef PRODUCT
1189 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1190 st->print("# Static ");
1191 if (_name != nullptr) {
1192 st->print("%s", _name);
1193 int trap_req = uncommon_trap_request();
1194 if (trap_req != 0) {
1195 char buf[100];
1196 st->print("(%s)",
1197 Deoptimization::format_trap_request(buf, sizeof(buf),
1198 trap_req));
1199 }
1200 st->print(" ");
1201 }
1202 CallJavaNode::dump_spec(st);
1203 }
1204
1205 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1206 if (_method) {
1207 _method->print_short_name(st);
1283 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1284 bool CallRuntimeNode::cmp( const Node &n ) const {
1285 CallRuntimeNode &call = (CallRuntimeNode&)n;
1286 return CallNode::cmp(call) && !strcmp(_name,call._name);
1287 }
1288 #ifndef PRODUCT
1289 void CallRuntimeNode::dump_spec(outputStream *st) const {
1290 st->print("# ");
1291 st->print("%s", _name);
1292 CallNode::dump_spec(st);
1293 }
1294 #endif
1295 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1296 bool CallLeafVectorNode::cmp( const Node &n ) const {
1297 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1298 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1299 }
1300
1301 //------------------------------calling_convention-----------------------------
1302 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1303 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1304 }
1305
1306 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1307 #ifdef ASSERT
1308 assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1309 "return vector size must match");
1310 const TypeTuple* d = tf()->domain();
1311 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1312 Node* arg = in(i);
1313 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1314 "vector argument size must match");
1315 }
1316 #endif
1317
1318 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1319 }
1320
1321 //=============================================================================
1322 //------------------------------calling_convention-----------------------------
1323
1324
1325 //=============================================================================
1326 bool CallLeafPureNode::is_unused() const {
1327 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1328 }
1329
1330 bool CallLeafPureNode::is_dead() const {
1331 return proj_out_or_null(TypeFunc::Control) == nullptr;
1332 }
1333
1334 /* We make a tuple of the global input state + TOP for the output values.
1335 * We use this to delete a pure function that is not used: by replacing the call with
1336 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1337 * pure call, so jumping over it, and effectively, removing the call from the graph.
1338 * This avoids doing the graph surgery manually, but leaves that to IGVN
1339 * that is specialized for doing that right. We need also tuple components for output
1340 * values of the function to respect the return arity, and in case there is a projection
1341 * that would pick an output (which shouldn't happen at the moment).
1342 */
1343 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1344 // Transparently propagate input state but parameters
1345 TupleNode* tuple = TupleNode::make(
1346 tf()->range(),
1347 in(TypeFunc::Control),
1348 in(TypeFunc::I_O),
1349 in(TypeFunc::Memory),
1350 in(TypeFunc::FramePtr),
1351 in(TypeFunc::ReturnAdr));
1352
1353 // And add TOPs for the return values
1354 for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1355 tuple->set_req(i, C->top());
1356 }
1357
1358 return tuple;
1359 }
1360
1361 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1362 if (is_dead()) {
1363 return nullptr;
1364 }
1365
1366 // We need to wait until IGVN because during parsing, usages might still be missing
1367 // and we would remove the call immediately.
1368 if (can_reshape && is_unused()) {
1369 // The result is not used. We remove the call by replacing it with a tuple, that
1370 // is later disintegrated by the projections.
1371 return make_tuple_of_input_state_and_top_return_values(phase->C);
1372 }
1373
1374 return CallRuntimeNode::Ideal(phase, can_reshape);
1375 }
1376
1377 #ifndef PRODUCT
1378 void CallLeafNode::dump_spec(outputStream *st) const {
1379 st->print("# ");
1380 st->print("%s", _name);
1381 CallNode::dump_spec(st);
1382 }
1383 #endif
1384
1385 //=============================================================================
1386
1387 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1388 assert(verify_jvms(jvms), "jvms must match");
1389 int loc = jvms->locoff() + idx;
1390 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1391 // If current local idx is top then local idx - 1 could
1392 // be a long/double that needs to be killed since top could
1393 // represent the 2nd half of the long/double.
1394 uint ideal = in(loc -1)->ideal_reg();
1395 if (ideal == Op_RegD || ideal == Op_RegL) {
1396 // set other (low index) half to top
1397 set_req(loc - 1, in(loc));
1398 }
1399 }
1400 set_req(loc, c);
1401 }
1402
1403 uint SafePointNode::size_of() const { return sizeof(*this); }
1404 bool SafePointNode::cmp( const Node &n ) const {
1415 }
1416 }
1417
1418
1419 //----------------------------next_exception-----------------------------------
1420 SafePointNode* SafePointNode::next_exception() const {
1421 if (len() == req()) {
1422 return nullptr;
1423 } else {
1424 Node* n = in(req());
1425 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1426 return (SafePointNode*) n;
1427 }
1428 }
1429
1430
1431 //------------------------------Ideal------------------------------------------
1432 // Skip over any collapsed Regions
1433 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1434 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1435 return remove_dead_region(phase, can_reshape) ? this : nullptr;
1436 }
1437
1438 //------------------------------Identity---------------------------------------
1439 // Remove obviously duplicate safepoints
1440 Node* SafePointNode::Identity(PhaseGVN* phase) {
1441
1442 // If you have back to back safepoints, remove one
1443 if (in(TypeFunc::Control)->is_SafePoint()) {
1444 Node* out_c = unique_ctrl_out_or_null();
1445 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1446 // outer loop's safepoint could confuse removal of the outer loop.
1447 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1448 return in(TypeFunc::Control);
1449 }
1450 }
1451
1452 // Transforming long counted loops requires a safepoint node. Do not
1453 // eliminate a safepoint until loop opts are over.
1454 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1455 Node *n0 = in(0)->in(0);
1569 }
1570
1571 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1572 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1573 int nb = igvn->C->root()->find_prec_edge(this);
1574 if (nb != -1) {
1575 igvn->delete_precedence_of(igvn->C->root(), nb);
1576 }
1577 }
1578
1579 //============== SafePointScalarObjectNode ==============
1580
1581 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1582 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1583 _first_index(first_index),
1584 _depth(depth),
1585 _n_fields(n_fields),
1586 _alloc(alloc)
1587 {
1588 #ifdef ASSERT
1589 if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1590 alloc->dump();
1591 assert(false, "unexpected call node");
1592 }
1593 #endif
1594 init_class_id(Class_SafePointScalarObject);
1595 }
1596
1597 // Do not allow value-numbering for SafePointScalarObject node.
1598 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1599 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1600 return (&n == this); // Always fail except on self
1601 }
1602
1603 uint SafePointScalarObjectNode::ideal_reg() const {
1604 return 0; // No matching to machine instruction
1605 }
1606
1607 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1608 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1609 }
1674 new_node = false;
1675 return (SafePointScalarMergeNode*)cached;
1676 }
1677 new_node = true;
1678 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1679 sosn_map->Insert((void*)this, (void*)res);
1680 return res;
1681 }
1682
1683 #ifndef PRODUCT
1684 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1685 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1686 }
1687 #endif
1688
1689 //=============================================================================
1690 uint AllocateNode::size_of() const { return sizeof(*this); }
1691
1692 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1693 Node *ctrl, Node *mem, Node *abio,
1694 Node *size, Node *klass_node, Node *initial_test)
1695 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1696 {
1697 init_class_id(Class_Allocate);
1698 init_flags(Flag_is_macro);
1699 _is_scalar_replaceable = false;
1700 _is_non_escaping = false;
1701 _is_allocation_MemBar_redundant = false;
1702 Node *topnode = C->top();
1703
1704 init_req( TypeFunc::Control , ctrl );
1705 init_req( TypeFunc::I_O , abio );
1706 init_req( TypeFunc::Memory , mem );
1707 init_req( TypeFunc::ReturnAdr, topnode );
1708 init_req( TypeFunc::FramePtr , topnode );
1709 init_req( AllocSize , size);
1710 init_req( KlassNode , klass_node);
1711 init_req( InitialTest , initial_test);
1712 init_req( ALength , topnode);
1713 init_req( ValidLengthTest , topnode);
1714 C->add_macro_node(this);
1715 }
1716
1717 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1718 {
1719 assert(initializer != nullptr && initializer->is_object_initializer(),
1720 "unexpected initializer method");
1721 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1722 if (analyzer == nullptr) {
1723 return;
1724 }
1725
1726 // Allocation node is first parameter in its initializer
1727 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1728 _is_allocation_MemBar_redundant = true;
1729 }
1730 }
1731 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1732 Node* mark_node = nullptr;
1733 if (UseCompactObjectHeaders) {
1734 Node* klass_node = in(AllocateNode::KlassNode);
1735 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1736 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1737 } else {
1738 // For now only enable fast locking for non-array types
1739 mark_node = phase->MakeConX(markWord::prototype().value());
1740 }
1741 return mark_node;
1742 }
1743
1744 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1745 // CastII, if appropriate. If we are not allowed to create new nodes, and
1746 // a CastII is appropriate, return null.
1747 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1748 Node *length = in(AllocateNode::ALength);
1749 assert(length != nullptr, "length is not null");
1750
1751 const TypeInt* length_type = phase->find_int_type(length);
1752 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1753
1754 if (ary_type != nullptr && length_type != nullptr) {
1755 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1756 if (narrow_length_type != length_type) {
1757 // Assert one of:
1758 // - the narrow_length is 0
1759 // - the narrow_length is not wider than length
1760 assert(narrow_length_type == TypeInt::ZERO ||
1761 (length_type->is_con() && narrow_length_type->is_con() &&
2117
2118 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2119 st->print("%s", _kind_names[_kind]);
2120 }
2121 #endif
2122
2123 //=============================================================================
2124 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2125
2126 // perform any generic optimizations first (returns 'this' or null)
2127 Node *result = SafePointNode::Ideal(phase, can_reshape);
2128 if (result != nullptr) return result;
2129 // Don't bother trying to transform a dead node
2130 if (in(0) && in(0)->is_top()) return nullptr;
2131
2132 // Now see if we can optimize away this lock. We don't actually
2133 // remove the locking here, we simply set the _eliminate flag which
2134 // prevents macro expansion from expanding the lock. Since we don't
2135 // modify the graph, the value returned from this function is the
2136 // one computed above.
2137 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2138 //
2139 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2140 //
2141 ConnectionGraph *cgr = phase->C->congraph();
2142 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2143 assert(!is_eliminated() || is_coarsened(), "sanity");
2144 // The lock could be marked eliminated by lock coarsening
2145 // code during first IGVN before EA. Replace coarsened flag
2146 // to eliminate all associated locks/unlocks.
2147 #ifdef ASSERT
2148 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2149 #endif
2150 this->set_non_esc_obj();
2151 return result;
2152 }
2153
2154 if (!phase->C->do_locks_coarsening()) {
2155 return result; // Compiling without locks coarsening
2156 }
2157 //
2318 }
2319
2320 //=============================================================================
2321 uint UnlockNode::size_of() const { return sizeof(*this); }
2322
2323 //=============================================================================
2324 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2325
2326 // perform any generic optimizations first (returns 'this' or null)
2327 Node *result = SafePointNode::Ideal(phase, can_reshape);
2328 if (result != nullptr) return result;
2329 // Don't bother trying to transform a dead node
2330 if (in(0) && in(0)->is_top()) return nullptr;
2331
2332 // Now see if we can optimize away this unlock. We don't actually
2333 // remove the unlocking here, we simply set the _eliminate flag which
2334 // prevents macro expansion from expanding the unlock. Since we don't
2335 // modify the graph, the value returned from this function is the
2336 // one computed above.
2337 // Escape state is defined after Parse phase.
2338 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2339 //
2340 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2341 //
2342 ConnectionGraph *cgr = phase->C->congraph();
2343 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2344 assert(!is_eliminated() || is_coarsened(), "sanity");
2345 // The lock could be marked eliminated by lock coarsening
2346 // code during first IGVN before EA. Replace coarsened flag
2347 // to eliminate all associated locks/unlocks.
2348 #ifdef ASSERT
2349 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2350 #endif
2351 this->set_non_esc_obj();
2352 }
2353 }
2354 return result;
2355 }
2356
2357 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2358 if (C == nullptr) {
2398 }
2399 // unrelated
2400 return false;
2401 }
2402
2403 if (dest_t->isa_aryptr()) {
2404 // arraycopy or array clone
2405 if (t_oop->isa_instptr()) {
2406 return false;
2407 }
2408 if (!t_oop->isa_aryptr()) {
2409 return true;
2410 }
2411
2412 const Type* elem = dest_t->is_aryptr()->elem();
2413 if (elem == Type::BOTTOM) {
2414 // An array but we don't know what elements are
2415 return true;
2416 }
2417
2418 dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2419 uint dest_alias = phase->C->get_alias_index(dest_t);
2420 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2421
2422 return dest_alias == t_oop_alias;
2423 }
2424
2425 return true;
2426 }
|
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/movenode.hpp"
44 #include "opto/parse.hpp"
45 #include "opto/regalloc.hpp"
46 #include "opto/regmask.hpp"
47 #include "opto/rootnode.hpp"
48 #include "opto/runtime.hpp"
49 #include "runtime/arguments.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "runtime/stubRoutines.hpp"
52 #include "utilities/powerOfTwo.hpp"
53
54 // Portions of code courtesy of Clifford Click
55
56 // Optimization - Graph Style
57
58 //=============================================================================
59 uint StartNode::size_of() const { return sizeof(*this); }
60 bool StartNode::cmp( const Node &n ) const
61 { return _domain == ((StartNode&)n)._domain; }
62 const Type *StartNode::bottom_type() const { return _domain; }
63 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
64 #ifndef PRODUCT
65 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
66 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
67 #endif
68
69 //------------------------------Ideal------------------------------------------
70 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
71 return remove_dead_region(phase, can_reshape) ? this : nullptr;
72 }
73
74 //------------------------------calling_convention-----------------------------
75 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
76 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
77 }
78
79 //------------------------------Registers--------------------------------------
80 const RegMask &StartNode::in_RegMask(uint) const {
81 return RegMask::EMPTY;
82 }
83
84 //------------------------------match------------------------------------------
85 // Construct projections for incoming parameters, and their RegMask info
86 Node *StartNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
87 switch (proj->_con) {
88 case TypeFunc::Control:
89 case TypeFunc::I_O:
90 case TypeFunc::Memory:
91 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
92 case TypeFunc::FramePtr:
93 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
94 case TypeFunc::ReturnAdr:
95 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
96 case TypeFunc::Parms:
97 default: {
98 uint parm_num = proj->_con - TypeFunc::Parms;
99 const Type *t = _domain->field_at(proj->_con);
100 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
101 return new ConNode(Type::TOP);
102 uint ideal_reg = t->ideal_reg();
103 RegMask &rm = match->_calling_convention_mask[parm_num];
104 return new MachProjNode(this,proj->_con,rm,ideal_reg);
105 }
106 }
107 return nullptr;
108 }
109
110 //=============================================================================
111 const char * const ParmNode::names[TypeFunc::Parms+1] = {
112 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
113 };
114
115 #ifndef PRODUCT
116 void ParmNode::dump_spec(outputStream *st) const {
117 if( _con < TypeFunc::Parms ) {
118 st->print("%s", names[_con]);
119 } else {
120 st->print("Parm%d: ",_con-TypeFunc::Parms);
121 // Verbose and WizardMode dump bottom_type for all nodes
122 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
123 }
124 }
125
126 void ParmNode::dump_compact_spec(outputStream *st) const {
127 if (_con < TypeFunc::Parms) {
128 st->print("%s", names[_con]);
129 } else {
477 if (cik->is_instance_klass()) {
478 cik->print_name_on(st);
479 iklass = cik->as_instance_klass();
480 } else if (cik->is_type_array_klass()) {
481 cik->as_array_klass()->base_element_type()->print_name_on(st);
482 st->print("[%d]", spobj->n_fields());
483 } else if (cik->is_obj_array_klass()) {
484 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
485 if (cie->is_instance_klass()) {
486 cie->print_name_on(st);
487 } else if (cie->is_type_array_klass()) {
488 cie->as_array_klass()->base_element_type()->print_name_on(st);
489 } else {
490 ShouldNotReachHere();
491 }
492 st->print("[%d]", spobj->n_fields());
493 int ndim = cik->as_array_klass()->dimension() - 1;
494 while (ndim-- > 0) {
495 st->print("[]");
496 }
497 } else if (cik->is_flat_array_klass()) {
498 ciKlass* cie = cik->as_flat_array_klass()->base_element_klass();
499 cie->print_name_on(st);
500 st->print("[%d]", spobj->n_fields());
501 int ndim = cik->as_array_klass()->dimension() - 1;
502 while (ndim-- > 0) {
503 st->print("[]");
504 }
505 }
506 st->print("={");
507 uint nf = spobj->n_fields();
508 if (nf > 0) {
509 uint first_ind = spobj->first_index(mcall->jvms());
510 if (iklass != nullptr && iklass->is_inlinetype()) {
511 Node* null_marker = mcall->in(first_ind++);
512 if (!null_marker->is_top()) {
513 st->print(" [null marker");
514 format_helper(regalloc, st, null_marker, ":", -1, nullptr);
515 }
516 }
517 Node* fld_node = mcall->in(first_ind);
518 if (iklass != nullptr) {
519 st->print(" [");
520 iklass->nonstatic_field_at(0)->print_name_on(st);
521 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
522 } else {
523 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
524 }
525 for (uint j = 1; j < nf; j++) {
526 fld_node = mcall->in(first_ind+j);
527 if (iklass != nullptr) {
528 st->print(", [");
529 iklass->nonstatic_field_at(j)->print_name_on(st);
530 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
531 } else {
532 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
533 }
534 }
535 }
536 st->print(" }");
537 }
538 }
539 st->cr();
540 if (caller() != nullptr) caller()->format(regalloc, n, st);
541 }
542
543
544 void JVMState::dump_spec(outputStream *st) const {
545 if (_method != nullptr) {
546 bool printed = false;
547 if (!Verbose) {
548 // The JVMS dumps make really, really long lines.
549 // Take out the most boring parts, which are the package prefixes.
744 tf()->dump_on(st);
745 }
746 if (_cnt != COUNT_UNKNOWN) {
747 st->print(" C=%f", _cnt);
748 }
749 const Node* const klass_node = in(KlassNode);
750 if (klass_node != nullptr) {
751 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
752
753 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
754 st->print(" allocationKlass:");
755 klass_ptr->exact_klass()->print_name_on(st);
756 }
757 }
758 if (jvms() != nullptr) {
759 jvms()->dump_spec(st);
760 }
761 }
762 #endif
763
764 const Type *CallNode::bottom_type() const { return tf()->range_cc(); }
765 const Type* CallNode::Value(PhaseGVN* phase) const {
766 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
767 return Type::TOP;
768 }
769 return tf()->range_cc();
770 }
771
772 //------------------------------calling_convention-----------------------------
773 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
774 if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
775 // The call to that stub is a special case: its inputs are
776 // multiple values returned from a call and so it should follow
777 // the return convention.
778 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
779 return;
780 }
781 // Use the standard compiler calling convention
782 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
783 }
784
785
786 //------------------------------match------------------------------------------
787 // Construct projections for control, I/O, memory-fields, ..., and
788 // return result(s) along with their RegMask info
789 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
790 uint con = proj->_con;
791 const TypeTuple* range_cc = tf()->range_cc();
792 if (con >= TypeFunc::Parms) {
793 if (tf()->returns_inline_type_as_fields()) {
794 // The call returns multiple values (inline type fields): we
795 // create one projection per returned value.
796 assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
797 uint ideal_reg = range_cc->field_at(con)->ideal_reg();
798 return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
799 } else {
800 if (con == TypeFunc::Parms) {
801 uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
802 OptoRegPair regs = Opcode() == Op_CallLeafVector
803 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
804 : match->c_return_value(ideal_reg);
805 RegMask rm = RegMask(regs.first());
806
807 if (Opcode() == Op_CallLeafVector) {
808 // If the return is in vector, compute appropriate regmask taking into account the whole range
809 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
810 if(OptoReg::is_valid(regs.second())) {
811 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
812 rm.insert(r);
813 }
814 }
815 }
816 }
817
818 if (OptoReg::is_valid(regs.second())) {
819 rm.insert(regs.second());
820 }
821 return new MachProjNode(this,con,rm,ideal_reg);
822 } else {
823 assert(con == TypeFunc::Parms+1, "only one return value");
824 assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
825 return new MachProjNode(this,con, RegMask::EMPTY, (uint)OptoReg::Bad);
826 }
827 }
828 }
829
830 switch (con) {
831 case TypeFunc::Control:
832 case TypeFunc::I_O:
833 case TypeFunc::Memory:
834 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
835
836 case TypeFunc::ReturnAdr:
837 case TypeFunc::FramePtr:
838 default:
839 ShouldNotReachHere();
840 }
841 return nullptr;
842 }
843
844 // Do we Match on this edge index or not? Match no edges
845 uint CallNode::match_edge(uint idx) const {
846 return 0;
847 }
848
849 //
850 // Determine whether the call could modify the field of the specified
851 // instance at the specified offset.
852 //
853 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
854 assert((t_oop != nullptr), "sanity");
855 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
856 const TypeTuple* args = _tf->domain_sig();
857 Node* dest = nullptr;
858 // Stubs that can be called once an ArrayCopyNode is expanded have
859 // different signatures. Look for the second pointer argument,
860 // that is the destination of the copy.
861 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
862 if (args->field_at(i)->isa_ptr()) {
863 j++;
864 if (j == 2) {
865 dest = in(i);
866 break;
867 }
868 }
869 }
870 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
871 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
872 return true;
873 }
874 return false;
875 }
876 if (t_oop->is_known_instance()) {
885 Node* proj = proj_out_or_null(TypeFunc::Parms);
886 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
887 return false;
888 }
889 }
890 if (is_CallJava() && as_CallJava()->method() != nullptr) {
891 ciMethod* meth = as_CallJava()->method();
892 if (meth->is_getter()) {
893 return false;
894 }
895 // May modify (by reflection) if an boxing object is passed
896 // as argument or returned.
897 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
898 if (proj != nullptr) {
899 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
900 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
901 (inst_t->instance_klass() == boxing_klass))) {
902 return true;
903 }
904 }
905 const TypeTuple* d = tf()->domain_cc();
906 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
907 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
908 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
909 (inst_t->instance_klass() == boxing_klass))) {
910 return true;
911 }
912 }
913 return false;
914 }
915 }
916 return true;
917 }
918
919 // Does this call have a direct reference to n other than debug information?
920 bool CallNode::has_non_debug_use(Node* n) {
921 const TypeTuple* d = tf()->domain_cc();
922 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
923 if (in(i) == n) {
924 return true;
925 }
926 }
927 return false;
928 }
929
930 bool CallNode::has_debug_use(Node* n) {
931 if (jvms() != nullptr) {
932 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
933 if (in(i) == n) {
934 return true;
935 }
936 }
937 }
938 return false;
939 }
940
941 // Returns the unique CheckCastPP of a call
942 // or 'this' if there are several CheckCastPP or unexpected uses
943 // or returns null if there is no one.
944 Node *CallNode::result_cast() {
945 Node *cast = nullptr;
946
947 Node *p = proj_out_or_null(TypeFunc::Parms);
948 if (p == nullptr)
949 return nullptr;
950
951 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
952 Node *use = p->fast_out(i);
953 if (use->is_CheckCastPP()) {
954 if (cast != nullptr) {
955 return this; // more than 1 CheckCastPP
956 }
957 cast = use;
958 } else if (!use->is_Initialize() &&
959 !use->is_AddP() &&
960 use->Opcode() != Op_MemBarStoreStore) {
961 // Expected uses are restricted to a CheckCastPP, an Initialize
962 // node, a MemBarStoreStore (clone) and AddP nodes. If we
963 // encounter any other use (a Phi node can be seen in rare
964 // cases) return this to prevent incorrect optimizations.
965 return this;
966 }
967 }
968 return cast;
969 }
970
971
972 CallProjections* CallNode::extract_projections(bool separate_io_proj, bool do_asserts) const {
973 uint max_res = TypeFunc::Parms-1;
974 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
975 ProjNode *pn = fast_out(i)->as_Proj();
976 max_res = MAX2(max_res, pn->_con);
977 }
978
979 assert(max_res < _tf->range_cc()->cnt(), "result out of bounds");
980
981 uint projs_size = sizeof(CallProjections);
982 if (max_res > TypeFunc::Parms) {
983 projs_size += (max_res-TypeFunc::Parms)*sizeof(Node*);
984 }
985 char* projs_storage = resource_allocate_bytes(projs_size);
986 CallProjections* projs = new(projs_storage)CallProjections(max_res - TypeFunc::Parms + 1);
987
988 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
989 ProjNode *pn = fast_out(i)->as_Proj();
990 if (pn->outcnt() == 0) continue;
991 switch (pn->_con) {
992 case TypeFunc::Control:
993 {
994 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
995 projs->fallthrough_proj = pn;
996 const Node* cn = pn->unique_ctrl_out_or_null();
997 if (cn != nullptr && cn->is_Catch()) {
998 ProjNode *cpn = nullptr;
999 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
1000 cpn = cn->fast_out(k)->as_Proj();
1001 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
1002 if (cpn->_con == CatchProjNode::fall_through_index)
1003 projs->fallthrough_catchproj = cpn;
1004 else {
1005 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
1006 projs->catchall_catchproj = cpn;
1012 case TypeFunc::I_O:
1013 if (pn->_is_io_use)
1014 projs->catchall_ioproj = pn;
1015 else
1016 projs->fallthrough_ioproj = pn;
1017 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
1018 Node* e = pn->out(j);
1019 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
1020 assert(projs->exobj == nullptr, "only one");
1021 projs->exobj = e;
1022 }
1023 }
1024 break;
1025 case TypeFunc::Memory:
1026 if (pn->_is_io_use)
1027 projs->catchall_memproj = pn;
1028 else
1029 projs->fallthrough_memproj = pn;
1030 break;
1031 case TypeFunc::Parms:
1032 projs->resproj[0] = pn;
1033 break;
1034 default:
1035 assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1036 projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1037 break;
1038 }
1039 }
1040
1041 // The resproj may not exist because the result could be ignored
1042 // and the exception object may not exist if an exception handler
1043 // swallows the exception but all the other must exist and be found.
1044 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1045 assert(!do_asserts || projs->fallthrough_proj != nullptr, "must be found");
1046 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1047 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1048 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1049 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1050 if (separate_io_proj) {
1051 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1052 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1053 }
1054 return projs;
1055 }
1056
1057 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1058 #ifdef ASSERT
1059 // Validate attached generator
1060 CallGenerator* cg = generator();
1061 if (cg != nullptr) {
1062 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1063 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1064 }
1065 #endif // ASSERT
1066 return SafePointNode::Ideal(phase, can_reshape);
1067 }
1068
1069 bool CallNode::is_call_to_arraycopystub() const {
1070 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1071 return true;
1072 }
1073 return false;
1074 }
1075
1076 //=============================================================================
1077 uint CallJavaNode::size_of() const { return sizeof(*this); }
1078 bool CallJavaNode::cmp( const Node &n ) const {
1079 CallJavaNode &call = (CallJavaNode&)n;
1080 return CallNode::cmp(call) && _method == call._method &&
1081 _override_symbolic_info == call._override_symbolic_info;
1082 }
1083
1084 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1085 // Copy debug information and adjust JVMState information
1086 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1087 uint new_dbg_start = tf()->domain_sig()->cnt();
1088 int jvms_adj = new_dbg_start - old_dbg_start;
1089 assert (new_dbg_start == req(), "argument count mismatch");
1090 Compile* C = phase->C;
1091
1092 // SafePointScalarObject node could be referenced several times in debug info.
1093 // Use Dict to record cloned nodes.
1094 Dict* sosn_map = new Dict(cmpkey,hashkey);
1095 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1096 Node* old_in = sfpt->in(i);
1097 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1098 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1099 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1100 bool new_node;
1101 Node* new_in = old_sosn->clone(sosn_map, new_node);
1102 if (new_node) { // New node?
1103 new_in->set_req(0, C->root()); // reset control edge
1104 new_in = phase->transform(new_in); // Register new node.
1105 }
1106 old_in = new_in;
1107 }
1108 add_req(old_in);
1109 }
1110
1111 // JVMS may be shared so clone it before we modify it
1112 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1113 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1114 jvms->set_map(this);
1115 jvms->set_locoff(jvms->locoff()+jvms_adj);
1116 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1117 jvms->set_monoff(jvms->monoff()+jvms_adj);
1118 jvms->set_scloff(jvms->scloff()+jvms_adj);
1119 jvms->set_endoff(jvms->endoff()+jvms_adj);
1120 }
1121 }
1122
1123 #ifdef ASSERT
1124 bool CallJavaNode::validate_symbolic_info() const {
1125 if (method() == nullptr) {
1126 return true; // call into runtime or uncommon trap
1127 }
1128 Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1129 if (Arguments::is_valhalla_enabled() && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1130 return true;
1131 }
1132 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1133 ciMethod* callee = method();
1134 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1135 assert(override_symbolic_info(), "should be set");
1136 }
1137 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1138 return true;
1139 }
1140 #endif
1141
1142 #ifndef PRODUCT
1143 void CallJavaNode::dump_spec(outputStream* st) const {
1144 if( _method ) _method->print_short_name(st);
1145 CallNode::dump_spec(st);
1146 }
1147
1148 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1149 if (_method) {
1150 _method->print_short_name(st);
1151 } else {
1154 }
1155 #endif
1156
1157 void CallJavaNode::register_for_late_inline() {
1158 if (generator() != nullptr) {
1159 Compile::current()->prepend_late_inline(generator());
1160 set_generator(nullptr);
1161 } else {
1162 assert(false, "repeated inline attempt");
1163 }
1164 }
1165
1166 //=============================================================================
1167 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1168 bool CallStaticJavaNode::cmp( const Node &n ) const {
1169 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1170 return CallJavaNode::cmp(call);
1171 }
1172
1173 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1174 if (can_reshape && uncommon_trap_request() != 0) {
1175 PhaseIterGVN* igvn = phase->is_IterGVN();
1176 if (remove_unknown_flat_array_load(igvn, control(), memory(), in(TypeFunc::Parms))) {
1177 if (!control()->is_Region()) {
1178 igvn->replace_input_of(this, 0, phase->C->top());
1179 }
1180 return this;
1181 }
1182 }
1183
1184 // Try to replace the runtime call to the substitutability test emitted by acmp if (at least) one operand is a known type
1185 if (can_reshape && !control()->is_top() && method() != nullptr && method()->holder() == phase->C->env()->ValueObjectMethods_klass() &&
1186 (method()->name() == ciSymbols::isSubstitutableAlt_name() || method()->name() == ciSymbols::isSubstitutable_name())) {
1187 Node* left = in(TypeFunc::Parms);
1188 Node* right = in(TypeFunc::Parms + 1);
1189 if (!left->is_top() && !right->is_top() && (left->is_InlineType() || right->is_InlineType())) {
1190 if (!left->is_InlineType()) {
1191 swap(left, right);
1192 }
1193 InlineTypeNode* vt = left->as_InlineType();
1194
1195 // Check if the field layout can be optimized
1196 if (vt->can_emit_substitutability_check(right)) {
1197 PhaseIterGVN* igvn = phase->is_IterGVN();
1198
1199 Node* ctrl = control();
1200 RegionNode* region = new RegionNode(1);
1201 Node* phi = new PhiNode(region, TypeInt::POS);
1202
1203 Node* base = right;
1204 Node* ptr = right;
1205 if (!base->is_InlineType()) {
1206 // Parse time checks guarantee that both operands are non-null and have the same type
1207 base = igvn->register_new_node_with_optimizer(new CheckCastPPNode(ctrl, base, vt->bottom_type()));
1208 ptr = base;
1209 }
1210 // Emit IR for field-wise comparison
1211 vt->check_substitutability(igvn, region, phi, &ctrl, in(MemNode::Memory), base, ptr);
1212
1213 // Equals
1214 region->add_req(ctrl);
1215 phi->add_req(igvn->intcon(1));
1216
1217 ctrl = igvn->register_new_node_with_optimizer(region);
1218 Node* res = igvn->register_new_node_with_optimizer(phi);
1219
1220 // Kill exception projections and return a tuple that will replace the call
1221 CallProjections* projs = extract_projections(false /*separate_io_proj*/);
1222 if (projs->fallthrough_catchproj != nullptr) {
1223 igvn->replace_node(projs->fallthrough_catchproj, ctrl);
1224 }
1225 if (projs->catchall_memproj != nullptr) {
1226 igvn->replace_node(projs->catchall_memproj, igvn->C->top());
1227 }
1228 if (projs->catchall_ioproj != nullptr) {
1229 igvn->replace_node(projs->catchall_ioproj, igvn->C->top());
1230 }
1231 if (projs->catchall_catchproj != nullptr) {
1232 igvn->replace_node(projs->catchall_catchproj, igvn->C->top());
1233 }
1234 return TupleNode::make(tf()->range_cc(), ctrl, i_o(), memory(), frameptr(), returnadr(), res);
1235 }
1236 }
1237 }
1238
1239 CallGenerator* cg = generator();
1240 if (can_reshape && cg != nullptr) {
1241 if (cg->is_mh_late_inline()) {
1242 assert(IncrementalInlineMH, "required");
1243 assert(cg->call_node() == this, "mismatch");
1244 assert(cg->method()->is_method_handle_intrinsic(), "required");
1245
1246 // Check whether this MH handle call becomes a candidate for inlining.
1247 ciMethod* callee = cg->method();
1248 vmIntrinsics::ID iid = callee->intrinsic_id();
1249 if (iid == vmIntrinsics::_invokeBasic) {
1250 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1251 register_for_late_inline();
1252 }
1253 } else if (iid == vmIntrinsics::_linkToNative) {
1254 // never retry
1255 } else {
1256 assert(callee->has_member_arg(), "wrong type of call?");
1257 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1258 register_for_late_inline();
1279
1280 //----------------------------uncommon_trap_request----------------------------
1281 // If this is an uncommon trap, return the request code, else zero.
1282 int CallStaticJavaNode::uncommon_trap_request() const {
1283 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1284 }
1285 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1286 #ifndef PRODUCT
1287 if (!(call->req() > TypeFunc::Parms &&
1288 call->in(TypeFunc::Parms) != nullptr &&
1289 call->in(TypeFunc::Parms)->is_Con() &&
1290 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1291 assert(in_dump() != 0, "OK if dumping");
1292 tty->print("[bad uncommon trap]");
1293 return 0;
1294 }
1295 #endif
1296 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1297 }
1298
1299 // Split if can cause the flat array branch of an array load with unknown type (see
1300 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1301 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1302 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1303 if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1304 return false;
1305 }
1306 if (ctl->is_Region()) {
1307 bool res = false;
1308 for (uint i = 1; i < ctl->req(); i++) {
1309 MergeMemNode* mm = mem->clone()->as_MergeMem();
1310 for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1311 Node* m = mms.memory();
1312 if (m->is_Phi() && m->in(0) == ctl) {
1313 mms.set_memory(m->in(i));
1314 }
1315 }
1316 if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1317 res = true;
1318 if (!ctl->in(i)->is_Region()) {
1319 igvn->replace_input_of(ctl, i, igvn->C->top());
1320 }
1321 }
1322 igvn->remove_dead_node(mm);
1323 }
1324 return res;
1325 }
1326 // Verify the control flow is ok
1327 Node* call = ctl;
1328 MemBarNode* membar = nullptr;
1329 for (;;) {
1330 if (call == nullptr || call->is_top()) {
1331 return false;
1332 }
1333 if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1334 call = call->in(0);
1335 } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1336 call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1337 assert(call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar(), "missing membar");
1338 membar = call->in(0)->in(0)->as_MemBar();
1339 break;
1340 } else {
1341 return false;
1342 }
1343 }
1344
1345 JVMState* jvms = call->jvms();
1346 if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1347 return false;
1348 }
1349
1350 Node* call_mem = call->in(TypeFunc::Memory);
1351 if (call_mem == nullptr || call_mem->is_top()) {
1352 return false;
1353 }
1354 if (!call_mem->is_MergeMem()) {
1355 call_mem = MergeMemNode::make(call_mem);
1356 igvn->register_new_node_with_optimizer(call_mem);
1357 }
1358
1359 // Verify that there's no unexpected side effect
1360 for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1361 Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1362 Node* m2 = mms2.memory2();
1363
1364 for (uint i = 0; i < 100; i++) {
1365 if (m1 == m2) {
1366 break;
1367 } else if (m1->is_Proj()) {
1368 m1 = m1->in(0);
1369 } else if (m1->is_MemBar()) {
1370 m1 = m1->in(TypeFunc::Memory);
1371 } else if (m1->Opcode() == Op_CallStaticJava &&
1372 m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1373 if (m1 != call) {
1374 return false;
1375 }
1376 break;
1377 } else if (m1->is_MergeMem()) {
1378 MergeMemNode* mm = m1->as_MergeMem();
1379 int idx = mms2.alias_idx();
1380 if (idx == Compile::AliasIdxBot) {
1381 m1 = mm->base_memory();
1382 } else {
1383 m1 = mm->memory_at(idx);
1384 }
1385 } else {
1386 return false;
1387 }
1388 }
1389 }
1390 if (call_mem->outcnt() == 0) {
1391 igvn->remove_dead_node(call_mem);
1392 }
1393
1394 // Remove membar preceding the call
1395 membar->remove(igvn);
1396
1397 address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1398 CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1399 unc->init_req(TypeFunc::Control, call->in(0));
1400 unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1401 unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1402 unc->init_req(TypeFunc::FramePtr, call->in(TypeFunc::FramePtr));
1403 unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1404 unc->init_req(TypeFunc::Parms+0, unc_arg);
1405 unc->set_cnt(PROB_UNLIKELY_MAG(4));
1406 unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1407
1408 // Replace the call with an uncommon trap
1409 igvn->replace_input_of(call, 0, igvn->C->top());
1410
1411 igvn->register_new_node_with_optimizer(unc);
1412
1413 Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1414 Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1415 igvn->add_input_to(igvn->C->root(), halt);
1416
1417 return true;
1418 }
1419
1420
1421 #ifndef PRODUCT
1422 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1423 st->print("# Static ");
1424 if (_name != nullptr) {
1425 st->print("%s", _name);
1426 int trap_req = uncommon_trap_request();
1427 if (trap_req != 0) {
1428 char buf[100];
1429 st->print("(%s)",
1430 Deoptimization::format_trap_request(buf, sizeof(buf),
1431 trap_req));
1432 }
1433 st->print(" ");
1434 }
1435 CallJavaNode::dump_spec(st);
1436 }
1437
1438 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1439 if (_method) {
1440 _method->print_short_name(st);
1516 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1517 bool CallRuntimeNode::cmp( const Node &n ) const {
1518 CallRuntimeNode &call = (CallRuntimeNode&)n;
1519 return CallNode::cmp(call) && !strcmp(_name,call._name);
1520 }
1521 #ifndef PRODUCT
1522 void CallRuntimeNode::dump_spec(outputStream *st) const {
1523 st->print("# ");
1524 st->print("%s", _name);
1525 CallNode::dump_spec(st);
1526 }
1527 #endif
1528 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1529 bool CallLeafVectorNode::cmp( const Node &n ) const {
1530 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1531 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1532 }
1533
1534 //------------------------------calling_convention-----------------------------
1535 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1536 if (_entry_point == nullptr) {
1537 // The call to that stub is a special case: its inputs are
1538 // multiple values returned from a call and so it should follow
1539 // the return convention.
1540 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1541 return;
1542 }
1543 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1544 }
1545
1546 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1547 #ifdef ASSERT
1548 assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1549 "return vector size must match");
1550 const TypeTuple* d = tf()->domain_sig();
1551 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1552 Node* arg = in(i);
1553 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1554 "vector argument size must match");
1555 }
1556 #endif
1557
1558 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1559 }
1560
1561 //=============================================================================
1562 //------------------------------calling_convention-----------------------------
1563
1564
1565 //=============================================================================
1566 bool CallLeafPureNode::is_unused() const {
1567 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1568 }
1569
1570 bool CallLeafPureNode::is_dead() const {
1571 return proj_out_or_null(TypeFunc::Control) == nullptr;
1572 }
1573
1574 /* We make a tuple of the global input state + TOP for the output values.
1575 * We use this to delete a pure function that is not used: by replacing the call with
1576 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1577 * pure call, so jumping over it, and effectively, removing the call from the graph.
1578 * This avoids doing the graph surgery manually, but leaves that to IGVN
1579 * that is specialized for doing that right. We need also tuple components for output
1580 * values of the function to respect the return arity, and in case there is a projection
1581 * that would pick an output (which shouldn't happen at the moment).
1582 */
1583 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1584 // Transparently propagate input state but parameters
1585 TupleNode* tuple = TupleNode::make(
1586 tf()->range_cc(),
1587 in(TypeFunc::Control),
1588 in(TypeFunc::I_O),
1589 in(TypeFunc::Memory),
1590 in(TypeFunc::FramePtr),
1591 in(TypeFunc::ReturnAdr));
1592
1593 // And add TOPs for the return values
1594 for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1595 tuple->set_req(i, C->top());
1596 }
1597
1598 return tuple;
1599 }
1600
1601 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1602 if (is_dead()) {
1603 return nullptr;
1604 }
1605
1606 // We need to wait until IGVN because during parsing, usages might still be missing
1607 // and we would remove the call immediately.
1608 if (can_reshape && is_unused()) {
1609 // The result is not used. We remove the call by replacing it with a tuple, that
1610 // is later disintegrated by the projections.
1611 return make_tuple_of_input_state_and_top_return_values(phase->C);
1612 }
1613
1614 return CallRuntimeNode::Ideal(phase, can_reshape);
1615 }
1616
1617 #ifndef PRODUCT
1618 void CallLeafNode::dump_spec(outputStream *st) const {
1619 st->print("# ");
1620 st->print("%s", _name);
1621 CallNode::dump_spec(st);
1622 }
1623 #endif
1624
1625 uint CallLeafNoFPNode::match_edge(uint idx) const {
1626 // Null entry point is a special case for which the target is in a
1627 // register. Need to match that edge.
1628 return entry_point() == nullptr && idx == TypeFunc::Parms;
1629 }
1630
1631 //=============================================================================
1632
1633 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1634 assert(verify_jvms(jvms), "jvms must match");
1635 int loc = jvms->locoff() + idx;
1636 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1637 // If current local idx is top then local idx - 1 could
1638 // be a long/double that needs to be killed since top could
1639 // represent the 2nd half of the long/double.
1640 uint ideal = in(loc -1)->ideal_reg();
1641 if (ideal == Op_RegD || ideal == Op_RegL) {
1642 // set other (low index) half to top
1643 set_req(loc - 1, in(loc));
1644 }
1645 }
1646 set_req(loc, c);
1647 }
1648
1649 uint SafePointNode::size_of() const { return sizeof(*this); }
1650 bool SafePointNode::cmp( const Node &n ) const {
1661 }
1662 }
1663
1664
1665 //----------------------------next_exception-----------------------------------
1666 SafePointNode* SafePointNode::next_exception() const {
1667 if (len() == req()) {
1668 return nullptr;
1669 } else {
1670 Node* n = in(req());
1671 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1672 return (SafePointNode*) n;
1673 }
1674 }
1675
1676
1677 //------------------------------Ideal------------------------------------------
1678 // Skip over any collapsed Regions
1679 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1680 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1681 if (remove_dead_region(phase, can_reshape)) {
1682 return this;
1683 }
1684 // Scalarize inline types in safepoint debug info.
1685 // Delay this until all inlining is over to avoid getting inconsistent debug info.
1686 if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1687 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1688 Node* n = in(i)->uncast();
1689 if (n->is_InlineType()) {
1690 n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1691 }
1692 }
1693 }
1694 return nullptr;
1695 }
1696
1697 //------------------------------Identity---------------------------------------
1698 // Remove obviously duplicate safepoints
1699 Node* SafePointNode::Identity(PhaseGVN* phase) {
1700
1701 // If you have back to back safepoints, remove one
1702 if (in(TypeFunc::Control)->is_SafePoint()) {
1703 Node* out_c = unique_ctrl_out_or_null();
1704 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1705 // outer loop's safepoint could confuse removal of the outer loop.
1706 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1707 return in(TypeFunc::Control);
1708 }
1709 }
1710
1711 // Transforming long counted loops requires a safepoint node. Do not
1712 // eliminate a safepoint until loop opts are over.
1713 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1714 Node *n0 = in(0)->in(0);
1828 }
1829
1830 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1831 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1832 int nb = igvn->C->root()->find_prec_edge(this);
1833 if (nb != -1) {
1834 igvn->delete_precedence_of(igvn->C->root(), nb);
1835 }
1836 }
1837
1838 //============== SafePointScalarObjectNode ==============
1839
1840 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1841 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1842 _first_index(first_index),
1843 _depth(depth),
1844 _n_fields(n_fields),
1845 _alloc(alloc)
1846 {
1847 #ifdef ASSERT
1848 if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1849 alloc->dump();
1850 assert(false, "unexpected call node");
1851 }
1852 #endif
1853 init_class_id(Class_SafePointScalarObject);
1854 }
1855
1856 // Do not allow value-numbering for SafePointScalarObject node.
1857 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1858 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1859 return (&n == this); // Always fail except on self
1860 }
1861
1862 uint SafePointScalarObjectNode::ideal_reg() const {
1863 return 0; // No matching to machine instruction
1864 }
1865
1866 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1867 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1868 }
1933 new_node = false;
1934 return (SafePointScalarMergeNode*)cached;
1935 }
1936 new_node = true;
1937 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1938 sosn_map->Insert((void*)this, (void*)res);
1939 return res;
1940 }
1941
1942 #ifndef PRODUCT
1943 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1944 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1945 }
1946 #endif
1947
1948 //=============================================================================
1949 uint AllocateNode::size_of() const { return sizeof(*this); }
1950
1951 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1952 Node *ctrl, Node *mem, Node *abio,
1953 Node *size, Node *klass_node,
1954 Node* initial_test,
1955 InlineTypeNode* inline_type_node)
1956 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1957 {
1958 init_class_id(Class_Allocate);
1959 init_flags(Flag_is_macro);
1960 _is_scalar_replaceable = false;
1961 _is_non_escaping = false;
1962 _is_allocation_MemBar_redundant = false;
1963 _larval = false;
1964 Node *topnode = C->top();
1965
1966 init_req( TypeFunc::Control , ctrl );
1967 init_req( TypeFunc::I_O , abio );
1968 init_req( TypeFunc::Memory , mem );
1969 init_req( TypeFunc::ReturnAdr, topnode );
1970 init_req( TypeFunc::FramePtr , topnode );
1971 init_req( AllocSize , size);
1972 init_req( KlassNode , klass_node);
1973 init_req( InitialTest , initial_test);
1974 init_req( ALength , topnode);
1975 init_req( ValidLengthTest , topnode);
1976 init_req( InlineType , inline_type_node);
1977 // DefaultValue defaults to nullptr
1978 // RawDefaultValue defaults to nullptr
1979 C->add_macro_node(this);
1980 }
1981
1982 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1983 {
1984 assert(initializer != nullptr &&
1985 (initializer->is_object_constructor() || initializer->is_class_initializer()),
1986 "unexpected initializer method");
1987 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1988 if (analyzer == nullptr) {
1989 return;
1990 }
1991
1992 // Allocation node is first parameter in its initializer
1993 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1994 _is_allocation_MemBar_redundant = true;
1995 }
1996 }
1997
1998 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
1999 Node* mark_node = nullptr;
2000 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
2001 Node* klass_node = in(AllocateNode::KlassNode);
2002 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
2003 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
2004 if (Arguments::is_valhalla_enabled()) {
2005 mark_node = phase->transform(mark_node);
2006 // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
2007 mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
2008 }
2009 return mark_node;
2010 } else {
2011 return phase->MakeConX(markWord::prototype().value());
2012 }
2013 }
2014
2015 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
2016 // CastII, if appropriate. If we are not allowed to create new nodes, and
2017 // a CastII is appropriate, return null.
2018 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
2019 Node *length = in(AllocateNode::ALength);
2020 assert(length != nullptr, "length is not null");
2021
2022 const TypeInt* length_type = phase->find_int_type(length);
2023 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
2024
2025 if (ary_type != nullptr && length_type != nullptr) {
2026 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
2027 if (narrow_length_type != length_type) {
2028 // Assert one of:
2029 // - the narrow_length is 0
2030 // - the narrow_length is not wider than length
2031 assert(narrow_length_type == TypeInt::ZERO ||
2032 (length_type->is_con() && narrow_length_type->is_con() &&
2388
2389 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2390 st->print("%s", _kind_names[_kind]);
2391 }
2392 #endif
2393
2394 //=============================================================================
2395 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2396
2397 // perform any generic optimizations first (returns 'this' or null)
2398 Node *result = SafePointNode::Ideal(phase, can_reshape);
2399 if (result != nullptr) return result;
2400 // Don't bother trying to transform a dead node
2401 if (in(0) && in(0)->is_top()) return nullptr;
2402
2403 // Now see if we can optimize away this lock. We don't actually
2404 // remove the locking here, we simply set the _eliminate flag which
2405 // prevents macro expansion from expanding the lock. Since we don't
2406 // modify the graph, the value returned from this function is the
2407 // one computed above.
2408 const Type* obj_type = phase->type(obj_node());
2409 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2410 //
2411 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2412 //
2413 ConnectionGraph *cgr = phase->C->congraph();
2414 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2415 assert(!is_eliminated() || is_coarsened(), "sanity");
2416 // The lock could be marked eliminated by lock coarsening
2417 // code during first IGVN before EA. Replace coarsened flag
2418 // to eliminate all associated locks/unlocks.
2419 #ifdef ASSERT
2420 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2421 #endif
2422 this->set_non_esc_obj();
2423 return result;
2424 }
2425
2426 if (!phase->C->do_locks_coarsening()) {
2427 return result; // Compiling without locks coarsening
2428 }
2429 //
2590 }
2591
2592 //=============================================================================
2593 uint UnlockNode::size_of() const { return sizeof(*this); }
2594
2595 //=============================================================================
2596 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2597
2598 // perform any generic optimizations first (returns 'this' or null)
2599 Node *result = SafePointNode::Ideal(phase, can_reshape);
2600 if (result != nullptr) return result;
2601 // Don't bother trying to transform a dead node
2602 if (in(0) && in(0)->is_top()) return nullptr;
2603
2604 // Now see if we can optimize away this unlock. We don't actually
2605 // remove the unlocking here, we simply set the _eliminate flag which
2606 // prevents macro expansion from expanding the unlock. Since we don't
2607 // modify the graph, the value returned from this function is the
2608 // one computed above.
2609 // Escape state is defined after Parse phase.
2610 const Type* obj_type = phase->type(obj_node());
2611 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2612 //
2613 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2614 //
2615 ConnectionGraph *cgr = phase->C->congraph();
2616 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2617 assert(!is_eliminated() || is_coarsened(), "sanity");
2618 // The lock could be marked eliminated by lock coarsening
2619 // code during first IGVN before EA. Replace coarsened flag
2620 // to eliminate all associated locks/unlocks.
2621 #ifdef ASSERT
2622 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2623 #endif
2624 this->set_non_esc_obj();
2625 }
2626 }
2627 return result;
2628 }
2629
2630 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2631 if (C == nullptr) {
2671 }
2672 // unrelated
2673 return false;
2674 }
2675
2676 if (dest_t->isa_aryptr()) {
2677 // arraycopy or array clone
2678 if (t_oop->isa_instptr()) {
2679 return false;
2680 }
2681 if (!t_oop->isa_aryptr()) {
2682 return true;
2683 }
2684
2685 const Type* elem = dest_t->is_aryptr()->elem();
2686 if (elem == Type::BOTTOM) {
2687 // An array but we don't know what elements are
2688 return true;
2689 }
2690
2691 dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2692 t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2693 uint dest_alias = phase->C->get_alias_index(dest_t);
2694 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2695
2696 return dest_alias == t_oop_alias;
2697 }
2698
2699 return true;
2700 }
|