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 }
|
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 {
498 assert(false, "unexpected type %s", cik->name()->as_utf8());
499 }
500 st->print("={");
501 uint nf = spobj->n_fields();
502 if (nf > 0) {
503 uint first_ind = spobj->first_index(mcall->jvms());
504 if (iklass != nullptr && iklass->is_inlinetype()) {
505 Node* null_marker = mcall->in(first_ind++);
506 if (!null_marker->is_top()) {
507 st->print(" [null marker");
508 format_helper(regalloc, st, null_marker, ":", -1, nullptr);
509 }
510 }
511 Node* fld_node = mcall->in(first_ind);
512 if (iklass != nullptr) {
513 st->print(" [");
514 iklass->nonstatic_field_at(0)->print_name_on(st);
515 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
516 } else {
517 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
518 }
519 for (uint j = 1; j < nf; j++) {
520 fld_node = mcall->in(first_ind+j);
521 if (iklass != nullptr) {
522 st->print(", [");
523 iklass->nonstatic_field_at(j)->print_name_on(st);
524 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
525 } else {
526 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
527 }
528 }
529 }
530 st->print(" }");
531 }
532 }
533 st->cr();
534 if (caller() != nullptr) caller()->format(regalloc, n, st);
535 }
536
537
538 void JVMState::dump_spec(outputStream *st) const {
539 if (_method != nullptr) {
540 bool printed = false;
541 if (!Verbose) {
542 // The JVMS dumps make really, really long lines.
543 // Take out the most boring parts, which are the package prefixes.
738 tf()->dump_on(st);
739 }
740 if (_cnt != COUNT_UNKNOWN) {
741 st->print(" C=%f", _cnt);
742 }
743 const Node* const klass_node = in(KlassNode);
744 if (klass_node != nullptr) {
745 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
746
747 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
748 st->print(" allocationKlass:");
749 klass_ptr->exact_klass()->print_name_on(st);
750 }
751 }
752 if (jvms() != nullptr) {
753 jvms()->dump_spec(st);
754 }
755 }
756 #endif
757
758 const Type *CallNode::bottom_type() const { return tf()->range_cc(); }
759 const Type* CallNode::Value(PhaseGVN* phase) const {
760 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
761 return Type::TOP;
762 }
763 return tf()->range_cc();
764 }
765
766 //------------------------------calling_convention-----------------------------
767 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
768 if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
769 // The call to that stub is a special case: its inputs are
770 // multiple values returned from a call and so it should follow
771 // the return convention.
772 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
773 return;
774 }
775 // Use the standard compiler calling convention
776 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
777 }
778
779
780 //------------------------------match------------------------------------------
781 // Construct projections for control, I/O, memory-fields, ..., and
782 // return result(s) along with their RegMask info
783 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
784 uint con = proj->_con;
785 const TypeTuple* range_cc = tf()->range_cc();
786 if (con >= TypeFunc::Parms) {
787 if (tf()->returns_inline_type_as_fields()) {
788 // The call returns multiple values (inline type fields): we
789 // create one projection per returned value.
790 assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
791 uint ideal_reg = range_cc->field_at(con)->ideal_reg();
792 return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
793 } else {
794 if (con == TypeFunc::Parms) {
795 uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
796 OptoRegPair regs = Opcode() == Op_CallLeafVector
797 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
798 : match->c_return_value(ideal_reg);
799 RegMask rm = RegMask(regs.first());
800
801 if (Opcode() == Op_CallLeafVector) {
802 // If the return is in vector, compute appropriate regmask taking into account the whole range
803 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
804 if(OptoReg::is_valid(regs.second())) {
805 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
806 rm.insert(r);
807 }
808 }
809 }
810 }
811
812 if (OptoReg::is_valid(regs.second())) {
813 rm.insert(regs.second());
814 }
815 return new MachProjNode(this,con,rm,ideal_reg);
816 } else {
817 assert(con == TypeFunc::Parms+1, "only one return value");
818 assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
819 return new MachProjNode(this,con, RegMask::EMPTY, (uint)OptoReg::Bad);
820 }
821 }
822 }
823
824 switch (con) {
825 case TypeFunc::Control:
826 case TypeFunc::I_O:
827 case TypeFunc::Memory:
828 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
829
830 case TypeFunc::ReturnAdr:
831 case TypeFunc::FramePtr:
832 default:
833 ShouldNotReachHere();
834 }
835 return nullptr;
836 }
837
838 // Do we Match on this edge index or not? Match no edges
839 uint CallNode::match_edge(uint idx) const {
840 return 0;
841 }
842
843 //
844 // Determine whether the call could modify the field of the specified
845 // instance at the specified offset.
846 //
847 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
848 assert((t_oop != nullptr), "sanity");
849 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
850 const TypeTuple* args = _tf->domain_sig();
851 Node* dest = nullptr;
852 // Stubs that can be called once an ArrayCopyNode is expanded have
853 // different signatures. Look for the second pointer argument,
854 // that is the destination of the copy.
855 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
856 if (args->field_at(i)->isa_ptr()) {
857 j++;
858 if (j == 2) {
859 dest = in(i);
860 break;
861 }
862 }
863 }
864 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
865 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
866 return true;
867 }
868 return false;
869 }
870 if (t_oop->is_known_instance()) {
879 Node* proj = proj_out_or_null(TypeFunc::Parms);
880 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
881 return false;
882 }
883 }
884 if (is_CallJava() && as_CallJava()->method() != nullptr) {
885 ciMethod* meth = as_CallJava()->method();
886 if (meth->is_getter()) {
887 return false;
888 }
889 // May modify (by reflection) if an boxing object is passed
890 // as argument or returned.
891 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
892 if (proj != nullptr) {
893 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
894 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
895 (inst_t->instance_klass() == boxing_klass))) {
896 return true;
897 }
898 }
899 const TypeTuple* d = tf()->domain_cc();
900 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
901 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
902 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
903 (inst_t->instance_klass() == boxing_klass))) {
904 return true;
905 }
906 }
907 return false;
908 }
909 }
910 return true;
911 }
912
913 // Does this call have a direct reference to n other than debug information?
914 bool CallNode::has_non_debug_use(Node* n) {
915 const TypeTuple* d = tf()->domain_cc();
916 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
917 if (in(i) == n) {
918 return true;
919 }
920 }
921 return false;
922 }
923
924 bool CallNode::has_debug_use(Node* n) {
925 if (jvms() != nullptr) {
926 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
927 if (in(i) == n) {
928 return true;
929 }
930 }
931 }
932 return false;
933 }
934
935 // Returns the unique CheckCastPP of a call
936 // or 'this' if there are several CheckCastPP or unexpected uses
937 // or returns null if there is no one.
938 Node *CallNode::result_cast() {
939 Node *cast = nullptr;
940
941 Node *p = proj_out_or_null(TypeFunc::Parms);
942 if (p == nullptr)
943 return nullptr;
944
945 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
946 Node *use = p->fast_out(i);
947 if (use->is_CheckCastPP()) {
948 if (cast != nullptr) {
949 return this; // more than 1 CheckCastPP
950 }
951 cast = use;
952 } else if (!use->is_Initialize() &&
953 !use->is_AddP() &&
954 use->Opcode() != Op_MemBarStoreStore) {
955 // Expected uses are restricted to a CheckCastPP, an Initialize
956 // node, a MemBarStoreStore (clone) and AddP nodes. If we
957 // encounter any other use (a Phi node can be seen in rare
958 // cases) return this to prevent incorrect optimizations.
959 return this;
960 }
961 }
962 return cast;
963 }
964
965
966 CallProjections* CallNode::extract_projections(bool separate_io_proj, bool do_asserts) const {
967 uint max_res = TypeFunc::Parms-1;
968 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
969 ProjNode *pn = fast_out(i)->as_Proj();
970 max_res = MAX2(max_res, pn->_con);
971 }
972
973 assert(max_res < _tf->range_cc()->cnt(), "result out of bounds");
974
975 uint projs_size = sizeof(CallProjections);
976 if (max_res > TypeFunc::Parms) {
977 projs_size += (max_res-TypeFunc::Parms)*sizeof(Node*);
978 }
979 char* projs_storage = resource_allocate_bytes(projs_size);
980 CallProjections* projs = new(projs_storage)CallProjections(max_res - TypeFunc::Parms + 1);
981
982 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
983 ProjNode *pn = fast_out(i)->as_Proj();
984 if (pn->outcnt() == 0) continue;
985 switch (pn->_con) {
986 case TypeFunc::Control:
987 {
988 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
989 projs->fallthrough_proj = pn;
990 const Node* cn = pn->unique_ctrl_out_or_null();
991 if (cn != nullptr && cn->is_Catch()) {
992 ProjNode *cpn = nullptr;
993 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
994 cpn = cn->fast_out(k)->as_Proj();
995 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
996 if (cpn->_con == CatchProjNode::fall_through_index)
997 projs->fallthrough_catchproj = cpn;
998 else {
999 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
1000 projs->catchall_catchproj = cpn;
1006 case TypeFunc::I_O:
1007 if (pn->_is_io_use)
1008 projs->catchall_ioproj = pn;
1009 else
1010 projs->fallthrough_ioproj = pn;
1011 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
1012 Node* e = pn->out(j);
1013 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
1014 assert(projs->exobj == nullptr, "only one");
1015 projs->exobj = e;
1016 }
1017 }
1018 break;
1019 case TypeFunc::Memory:
1020 if (pn->_is_io_use)
1021 projs->catchall_memproj = pn;
1022 else
1023 projs->fallthrough_memproj = pn;
1024 break;
1025 case TypeFunc::Parms:
1026 projs->resproj[0] = pn;
1027 break;
1028 default:
1029 assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1030 projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1031 break;
1032 }
1033 }
1034
1035 // The resproj may not exist because the result could be ignored
1036 // and the exception object may not exist if an exception handler
1037 // swallows the exception but all the other must exist and be found.
1038 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1039 assert(!do_asserts || projs->fallthrough_proj != nullptr, "must be found");
1040 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1041 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1042 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1043 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1044 if (separate_io_proj) {
1045 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1046 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1047 }
1048 return projs;
1049 }
1050
1051 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1052 #ifdef ASSERT
1053 // Validate attached generator
1054 CallGenerator* cg = generator();
1055 if (cg != nullptr) {
1056 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1057 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1058 }
1059 #endif // ASSERT
1060 return SafePointNode::Ideal(phase, can_reshape);
1061 }
1062
1063 bool CallNode::is_call_to_arraycopystub() const {
1064 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1065 return true;
1066 }
1067 return false;
1068 }
1069
1070 bool CallNode::is_call_to_multianewarray_stub() const {
1071 if (_name != nullptr &&
1072 strstr(_name, "multianewarray") != nullptr &&
1073 strstr(_name, "C2 runtime") != nullptr) {
1074 return true;
1075 }
1076 return false;
1077 }
1078
1079 //=============================================================================
1080 uint CallJavaNode::size_of() const { return sizeof(*this); }
1081 bool CallJavaNode::cmp( const Node &n ) const {
1082 CallJavaNode &call = (CallJavaNode&)n;
1083 return CallNode::cmp(call) && _method == call._method &&
1084 _override_symbolic_info == call._override_symbolic_info;
1085 }
1086
1087 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1088 // Copy debug information and adjust JVMState information
1089 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1090 uint new_dbg_start = tf()->domain_sig()->cnt();
1091 int jvms_adj = new_dbg_start - old_dbg_start;
1092 assert (new_dbg_start == req(), "argument count mismatch");
1093 Compile* C = phase->C;
1094
1095 // SafePointScalarObject node could be referenced several times in debug info.
1096 // Use Dict to record cloned nodes.
1097 Dict* sosn_map = new Dict(cmpkey,hashkey);
1098 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1099 Node* old_in = sfpt->in(i);
1100 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1101 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1102 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1103 bool new_node;
1104 Node* new_in = old_sosn->clone(sosn_map, new_node);
1105 if (new_node) { // New node?
1106 new_in->set_req(0, C->root()); // reset control edge
1107 new_in = phase->transform(new_in); // Register new node.
1108 }
1109 old_in = new_in;
1110 }
1111 add_req(old_in);
1112 }
1113
1114 // JVMS may be shared so clone it before we modify it
1115 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1116 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1117 jvms->set_map(this);
1118 jvms->set_locoff(jvms->locoff()+jvms_adj);
1119 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1120 jvms->set_monoff(jvms->monoff()+jvms_adj);
1121 jvms->set_scloff(jvms->scloff()+jvms_adj);
1122 jvms->set_endoff(jvms->endoff()+jvms_adj);
1123 }
1124 }
1125
1126 #ifdef ASSERT
1127 bool CallJavaNode::validate_symbolic_info() const {
1128 if (method() == nullptr) {
1129 return true; // call into runtime or uncommon trap
1130 }
1131 Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1132 if (Arguments::is_valhalla_enabled() && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1133 return true;
1134 }
1135 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1136 ciMethod* callee = method();
1137 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1138 assert(override_symbolic_info(), "should be set");
1139 }
1140 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1141 return true;
1142 }
1143 #endif
1144
1145 #ifndef PRODUCT
1146 void CallJavaNode::dump_spec(outputStream* st) const {
1147 if( _method ) _method->print_short_name(st);
1148 CallNode::dump_spec(st);
1149 }
1150
1151 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1152 if (_method) {
1153 _method->print_short_name(st);
1154 } else {
1157 }
1158 #endif
1159
1160 void CallJavaNode::register_for_late_inline() {
1161 if (generator() != nullptr) {
1162 Compile::current()->prepend_late_inline(generator());
1163 set_generator(nullptr);
1164 } else {
1165 assert(false, "repeated inline attempt");
1166 }
1167 }
1168
1169 //=============================================================================
1170 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1171 bool CallStaticJavaNode::cmp( const Node &n ) const {
1172 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1173 return CallJavaNode::cmp(call);
1174 }
1175
1176 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1177 if (can_reshape && uncommon_trap_request() != 0) {
1178 PhaseIterGVN* igvn = phase->is_IterGVN();
1179 if (remove_unknown_flat_array_load(igvn, control(), memory(), in(TypeFunc::Parms))) {
1180 if (!control()->is_Region()) {
1181 igvn->replace_input_of(this, 0, phase->C->top());
1182 }
1183 return this;
1184 }
1185 }
1186
1187 // Try to replace the runtime call to the substitutability test emitted by acmp if (at least) one operand is a known type
1188 if (can_reshape && !control()->is_top() && method() != nullptr && method()->holder() == phase->C->env()->ValueObjectMethods_klass() &&
1189 (method()->name() == ciSymbols::isSubstitutableAlt_name() || method()->name() == ciSymbols::isSubstitutable_name())) {
1190 Node* left = in(TypeFunc::Parms);
1191 Node* right = in(TypeFunc::Parms + 1);
1192 if (!left->is_top() && !right->is_top() && (left->is_InlineType() || right->is_InlineType())) {
1193 if (!left->is_InlineType()) {
1194 swap(left, right);
1195 }
1196 InlineTypeNode* vt = left->as_InlineType();
1197
1198 // Check if the field layout can be optimized
1199 if (vt->can_emit_substitutability_check(right)) {
1200 PhaseIterGVN* igvn = phase->is_IterGVN();
1201
1202 Node* ctrl = control();
1203 RegionNode* region = new RegionNode(1);
1204 Node* phi = new PhiNode(region, TypeInt::POS);
1205
1206 Node* base = right;
1207 Node* ptr = right;
1208 if (!base->is_InlineType()) {
1209 // Parse time checks guarantee that both operands are non-null and have the same type
1210 base = igvn->register_new_node_with_optimizer(new CheckCastPPNode(ctrl, base, vt->bottom_type()));
1211 ptr = base;
1212 }
1213 // Emit IR for field-wise comparison
1214 vt->check_substitutability(igvn, region, phi, &ctrl, in(MemNode::Memory), base, ptr);
1215
1216 // Equals
1217 region->add_req(ctrl);
1218 phi->add_req(igvn->intcon(1));
1219
1220 ctrl = igvn->register_new_node_with_optimizer(region);
1221 Node* res = igvn->register_new_node_with_optimizer(phi);
1222
1223 // Kill exception projections and return a tuple that will replace the call
1224 CallProjections* projs = extract_projections(false /*separate_io_proj*/);
1225 if (projs->fallthrough_catchproj != nullptr) {
1226 igvn->replace_node(projs->fallthrough_catchproj, ctrl);
1227 }
1228 if (projs->catchall_memproj != nullptr) {
1229 igvn->replace_node(projs->catchall_memproj, igvn->C->top());
1230 }
1231 if (projs->catchall_ioproj != nullptr) {
1232 igvn->replace_node(projs->catchall_ioproj, igvn->C->top());
1233 }
1234 if (projs->catchall_catchproj != nullptr) {
1235 igvn->replace_node(projs->catchall_catchproj, igvn->C->top());
1236 }
1237 return TupleNode::make(tf()->range_cc(), ctrl, i_o(), memory(), frameptr(), returnadr(), res);
1238 }
1239 }
1240 }
1241
1242 CallGenerator* cg = generator();
1243 if (can_reshape && cg != nullptr) {
1244 if (cg->is_mh_late_inline()) {
1245 assert(IncrementalInlineMH, "required");
1246 assert(cg->call_node() == this, "mismatch");
1247 assert(cg->method()->is_method_handle_intrinsic(), "required");
1248
1249 // Check whether this MH handle call becomes a candidate for inlining.
1250 ciMethod* callee = cg->method();
1251 vmIntrinsics::ID iid = callee->intrinsic_id();
1252 if (iid == vmIntrinsics::_invokeBasic) {
1253 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1254 register_for_late_inline();
1255 }
1256 } else if (iid == vmIntrinsics::_linkToNative) {
1257 // never retry
1258 } else {
1259 assert(callee->has_member_arg(), "wrong type of call?");
1260 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1261 register_for_late_inline();
1282
1283 //----------------------------uncommon_trap_request----------------------------
1284 // If this is an uncommon trap, return the request code, else zero.
1285 int CallStaticJavaNode::uncommon_trap_request() const {
1286 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1287 }
1288 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1289 #ifndef PRODUCT
1290 if (!(call->req() > TypeFunc::Parms &&
1291 call->in(TypeFunc::Parms) != nullptr &&
1292 call->in(TypeFunc::Parms)->is_Con() &&
1293 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1294 assert(in_dump() != 0, "OK if dumping");
1295 tty->print("[bad uncommon trap]");
1296 return 0;
1297 }
1298 #endif
1299 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1300 }
1301
1302 // Split if can cause the flat array branch of an array load with unknown type (see
1303 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1304 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1305 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1306 if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1307 return false;
1308 }
1309 if (ctl->is_Region()) {
1310 bool res = false;
1311 for (uint i = 1; i < ctl->req(); i++) {
1312 MergeMemNode* mm = mem->clone()->as_MergeMem();
1313 for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1314 Node* m = mms.memory();
1315 if (m->is_Phi() && m->in(0) == ctl) {
1316 mms.set_memory(m->in(i));
1317 }
1318 }
1319 if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1320 res = true;
1321 if (!ctl->in(i)->is_Region()) {
1322 igvn->replace_input_of(ctl, i, igvn->C->top());
1323 }
1324 }
1325 igvn->remove_dead_node(mm);
1326 }
1327 return res;
1328 }
1329 // Verify the control flow is ok
1330 Node* call = ctl;
1331 MemBarNode* membar = nullptr;
1332 for (;;) {
1333 if (call == nullptr || call->is_top()) {
1334 return false;
1335 }
1336 if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1337 call = call->in(0);
1338 } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1339 call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1340 // If there is no explicit flat array accesses in the compilation unit, there would be no
1341 // membar here
1342 if (call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar()) {
1343 membar = call->in(0)->in(0)->as_MemBar();
1344 }
1345 break;
1346 } else {
1347 return false;
1348 }
1349 }
1350
1351 JVMState* jvms = call->jvms();
1352 if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1353 return false;
1354 }
1355
1356 Node* call_mem = call->in(TypeFunc::Memory);
1357 if (call_mem == nullptr || call_mem->is_top()) {
1358 return false;
1359 }
1360 if (!call_mem->is_MergeMem()) {
1361 call_mem = MergeMemNode::make(call_mem);
1362 igvn->register_new_node_with_optimizer(call_mem);
1363 }
1364
1365 // Verify that there's no unexpected side effect
1366 for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1367 Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1368 Node* m2 = mms2.memory2();
1369
1370 for (uint i = 0; i < 100; i++) {
1371 if (m1 == m2) {
1372 break;
1373 } else if (m1->is_Proj()) {
1374 m1 = m1->in(0);
1375 } else if (m1->is_MemBar()) {
1376 m1 = m1->in(TypeFunc::Memory);
1377 } else if (m1->Opcode() == Op_CallStaticJava &&
1378 m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1379 if (m1 != call) {
1380 return false;
1381 }
1382 break;
1383 } else if (m1->is_MergeMem()) {
1384 MergeMemNode* mm = m1->as_MergeMem();
1385 int idx = mms2.alias_idx();
1386 if (idx == Compile::AliasIdxBot) {
1387 m1 = mm->base_memory();
1388 } else {
1389 m1 = mm->memory_at(idx);
1390 }
1391 } else {
1392 return false;
1393 }
1394 }
1395 }
1396 if (call_mem->outcnt() == 0) {
1397 igvn->remove_dead_node(call_mem);
1398 }
1399
1400 // Remove membar preceding the call
1401 if (membar != nullptr) {
1402 membar->remove(igvn);
1403 }
1404
1405 address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1406 CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1407 unc->init_req(TypeFunc::Control, call->in(0));
1408 unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1409 unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1410 unc->init_req(TypeFunc::FramePtr, call->in(TypeFunc::FramePtr));
1411 unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1412 unc->init_req(TypeFunc::Parms+0, unc_arg);
1413 unc->set_cnt(PROB_UNLIKELY_MAG(4));
1414 unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1415
1416 // Replace the call with an uncommon trap
1417 igvn->replace_input_of(call, 0, igvn->C->top());
1418
1419 igvn->register_new_node_with_optimizer(unc);
1420
1421 Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1422 Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1423 igvn->add_input_to(igvn->C->root(), halt);
1424
1425 return true;
1426 }
1427
1428
1429 #ifndef PRODUCT
1430 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1431 st->print("# Static ");
1432 if (_name != nullptr) {
1433 st->print("%s", _name);
1434 int trap_req = uncommon_trap_request();
1435 if (trap_req != 0) {
1436 char buf[100];
1437 st->print("(%s)",
1438 Deoptimization::format_trap_request(buf, sizeof(buf),
1439 trap_req));
1440 }
1441 st->print(" ");
1442 }
1443 CallJavaNode::dump_spec(st);
1444 }
1445
1446 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1447 if (_method) {
1448 _method->print_short_name(st);
1524 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1525 bool CallRuntimeNode::cmp( const Node &n ) const {
1526 CallRuntimeNode &call = (CallRuntimeNode&)n;
1527 return CallNode::cmp(call) && !strcmp(_name,call._name);
1528 }
1529 #ifndef PRODUCT
1530 void CallRuntimeNode::dump_spec(outputStream *st) const {
1531 st->print("# ");
1532 st->print("%s", _name);
1533 CallNode::dump_spec(st);
1534 }
1535 #endif
1536 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1537 bool CallLeafVectorNode::cmp( const Node &n ) const {
1538 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1539 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1540 }
1541
1542 //------------------------------calling_convention-----------------------------
1543 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1544 if (_entry_point == nullptr) {
1545 // The call to that stub is a special case: its inputs are
1546 // multiple values returned from a call and so it should follow
1547 // the return convention.
1548 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1549 return;
1550 }
1551 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1552 }
1553
1554 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1555 #ifdef ASSERT
1556 assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1557 "return vector size must match");
1558 const TypeTuple* d = tf()->domain_sig();
1559 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1560 Node* arg = in(i);
1561 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1562 "vector argument size must match");
1563 }
1564 #endif
1565
1566 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1567 }
1568
1569 //=============================================================================
1570 //------------------------------calling_convention-----------------------------
1571
1572
1573 //=============================================================================
1574 bool CallLeafPureNode::is_unused() const {
1575 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1576 }
1577
1578 bool CallLeafPureNode::is_dead() const {
1579 return proj_out_or_null(TypeFunc::Control) == nullptr;
1580 }
1581
1582 /* We make a tuple of the global input state + TOP for the output values.
1583 * We use this to delete a pure function that is not used: by replacing the call with
1584 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1585 * pure call, so jumping over it, and effectively, removing the call from the graph.
1586 * This avoids doing the graph surgery manually, but leaves that to IGVN
1587 * that is specialized for doing that right. We need also tuple components for output
1588 * values of the function to respect the return arity, and in case there is a projection
1589 * that would pick an output (which shouldn't happen at the moment).
1590 */
1591 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1592 // Transparently propagate input state but parameters
1593 TupleNode* tuple = TupleNode::make(
1594 tf()->range_cc(),
1595 in(TypeFunc::Control),
1596 in(TypeFunc::I_O),
1597 in(TypeFunc::Memory),
1598 in(TypeFunc::FramePtr),
1599 in(TypeFunc::ReturnAdr));
1600
1601 // And add TOPs for the return values
1602 for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1603 tuple->set_req(i, C->top());
1604 }
1605
1606 return tuple;
1607 }
1608
1609 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1610 if (is_dead()) {
1611 return nullptr;
1612 }
1613
1614 // We need to wait until IGVN because during parsing, usages might still be missing
1615 // and we would remove the call immediately.
1616 if (can_reshape && is_unused()) {
1617 // The result is not used. We remove the call by replacing it with a tuple, that
1618 // is later disintegrated by the projections.
1619 return make_tuple_of_input_state_and_top_return_values(phase->C);
1620 }
1621
1622 return CallRuntimeNode::Ideal(phase, can_reshape);
1623 }
1624
1625 #ifndef PRODUCT
1626 void CallLeafNode::dump_spec(outputStream *st) const {
1627 st->print("# ");
1628 st->print("%s", _name);
1629 CallNode::dump_spec(st);
1630 }
1631 #endif
1632
1633 uint CallLeafNoFPNode::match_edge(uint idx) const {
1634 // Null entry point is a special case for which the target is in a
1635 // register. Need to match that edge.
1636 return entry_point() == nullptr && idx == TypeFunc::Parms;
1637 }
1638
1639 //=============================================================================
1640
1641 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1642 assert(verify_jvms(jvms), "jvms must match");
1643 int loc = jvms->locoff() + idx;
1644 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1645 // If current local idx is top then local idx - 1 could
1646 // be a long/double that needs to be killed since top could
1647 // represent the 2nd half of the long/double.
1648 uint ideal = in(loc -1)->ideal_reg();
1649 if (ideal == Op_RegD || ideal == Op_RegL) {
1650 // set other (low index) half to top
1651 set_req(loc - 1, in(loc));
1652 }
1653 }
1654 set_req(loc, c);
1655 }
1656
1657 uint SafePointNode::size_of() const { return sizeof(*this); }
1658 bool SafePointNode::cmp( const Node &n ) const {
1669 }
1670 }
1671
1672
1673 //----------------------------next_exception-----------------------------------
1674 SafePointNode* SafePointNode::next_exception() const {
1675 if (len() == req()) {
1676 return nullptr;
1677 } else {
1678 Node* n = in(req());
1679 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1680 return (SafePointNode*) n;
1681 }
1682 }
1683
1684
1685 //------------------------------Ideal------------------------------------------
1686 // Skip over any collapsed Regions
1687 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1688 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1689 if (remove_dead_region(phase, can_reshape)) {
1690 return this;
1691 }
1692 // Scalarize inline types in safepoint debug info.
1693 // Delay this until all inlining is over to avoid getting inconsistent debug info.
1694 if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1695 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1696 Node* n = in(i)->uncast();
1697 if (n->is_InlineType()) {
1698 n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1699 }
1700 }
1701 }
1702 return nullptr;
1703 }
1704
1705 //------------------------------Identity---------------------------------------
1706 // Remove obviously duplicate safepoints
1707 Node* SafePointNode::Identity(PhaseGVN* phase) {
1708
1709 // If you have back to back safepoints, remove one
1710 if (in(TypeFunc::Control)->is_SafePoint()) {
1711 Node* out_c = unique_ctrl_out_or_null();
1712 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1713 // outer loop's safepoint could confuse removal of the outer loop.
1714 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1715 return in(TypeFunc::Control);
1716 }
1717 }
1718
1719 // Transforming long counted loops requires a safepoint node. Do not
1720 // eliminate a safepoint until loop opts are over.
1721 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1722 Node *n0 = in(0)->in(0);
1836 }
1837
1838 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1839 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1840 int nb = igvn->C->root()->find_prec_edge(this);
1841 if (nb != -1) {
1842 igvn->delete_precedence_of(igvn->C->root(), nb);
1843 }
1844 }
1845
1846 //============== SafePointScalarObjectNode ==============
1847
1848 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1849 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1850 _first_index(first_index),
1851 _depth(depth),
1852 _n_fields(n_fields),
1853 _alloc(alloc)
1854 {
1855 #ifdef ASSERT
1856 if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1857 alloc->dump();
1858 assert(false, "unexpected call node");
1859 }
1860 #endif
1861 init_class_id(Class_SafePointScalarObject);
1862 }
1863
1864 // Do not allow value-numbering for SafePointScalarObject node.
1865 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1866 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1867 return (&n == this); // Always fail except on self
1868 }
1869
1870 uint SafePointScalarObjectNode::ideal_reg() const {
1871 return 0; // No matching to machine instruction
1872 }
1873
1874 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1875 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1876 }
1941 new_node = false;
1942 return (SafePointScalarMergeNode*)cached;
1943 }
1944 new_node = true;
1945 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1946 sosn_map->Insert((void*)this, (void*)res);
1947 return res;
1948 }
1949
1950 #ifndef PRODUCT
1951 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1952 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1953 }
1954 #endif
1955
1956 //=============================================================================
1957 uint AllocateNode::size_of() const { return sizeof(*this); }
1958
1959 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1960 Node *ctrl, Node *mem, Node *abio,
1961 Node *size, Node *klass_node,
1962 Node* initial_test,
1963 InlineTypeNode* inline_type_node)
1964 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1965 {
1966 init_class_id(Class_Allocate);
1967 init_flags(Flag_is_macro);
1968 _is_scalar_replaceable = false;
1969 _is_non_escaping = false;
1970 _is_allocation_MemBar_redundant = false;
1971 _larval = false;
1972 Node *topnode = C->top();
1973
1974 init_req( TypeFunc::Control , ctrl );
1975 init_req( TypeFunc::I_O , abio );
1976 init_req( TypeFunc::Memory , mem );
1977 init_req( TypeFunc::ReturnAdr, topnode );
1978 init_req( TypeFunc::FramePtr , topnode );
1979 init_req( AllocSize , size);
1980 init_req( KlassNode , klass_node);
1981 init_req( InitialTest , initial_test);
1982 init_req( ALength , topnode);
1983 init_req( ValidLengthTest , topnode);
1984 init_req( InlineType , inline_type_node);
1985 // DefaultValue defaults to nullptr
1986 // RawDefaultValue defaults to nullptr
1987 C->add_macro_node(this);
1988 }
1989
1990 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1991 {
1992 assert(initializer != nullptr &&
1993 (initializer->is_object_constructor() || initializer->is_class_initializer()),
1994 "unexpected initializer method");
1995 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1996 if (analyzer == nullptr) {
1997 return;
1998 }
1999
2000 // Allocation node is first parameter in its initializer
2001 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
2002 _is_allocation_MemBar_redundant = true;
2003 }
2004 }
2005
2006 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
2007 Node* mark_node = nullptr;
2008 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
2009 Node* klass_node = in(AllocateNode::KlassNode);
2010 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
2011 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
2012 if (Arguments::is_valhalla_enabled()) {
2013 mark_node = phase->transform(mark_node);
2014 // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
2015 mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
2016 }
2017 return mark_node;
2018 } else {
2019 return phase->MakeConX(markWord::prototype().value());
2020 }
2021 }
2022
2023 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
2024 // CastII, if appropriate. If we are not allowed to create new nodes, and
2025 // a CastII is appropriate, return null.
2026 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
2027 Node *length = in(AllocateNode::ALength);
2028 assert(length != nullptr, "length is not null");
2029
2030 const TypeInt* length_type = phase->find_int_type(length);
2031 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
2032
2033 if (ary_type != nullptr && length_type != nullptr) {
2034 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
2035 if (narrow_length_type != length_type) {
2036 // Assert one of:
2037 // - the narrow_length is 0
2038 // - the narrow_length is not wider than length
2039 assert(narrow_length_type == TypeInt::ZERO ||
2040 (length_type->is_con() && narrow_length_type->is_con() &&
2396
2397 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2398 st->print("%s", _kind_names[_kind]);
2399 }
2400 #endif
2401
2402 //=============================================================================
2403 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2404
2405 // perform any generic optimizations first (returns 'this' or null)
2406 Node *result = SafePointNode::Ideal(phase, can_reshape);
2407 if (result != nullptr) return result;
2408 // Don't bother trying to transform a dead node
2409 if (in(0) && in(0)->is_top()) return nullptr;
2410
2411 // Now see if we can optimize away this lock. We don't actually
2412 // remove the locking here, we simply set the _eliminate flag which
2413 // prevents macro expansion from expanding the lock. Since we don't
2414 // modify the graph, the value returned from this function is the
2415 // one computed above.
2416 const Type* obj_type = phase->type(obj_node());
2417 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2418 //
2419 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2420 //
2421 ConnectionGraph *cgr = phase->C->congraph();
2422 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2423 assert(!is_eliminated() || is_coarsened(), "sanity");
2424 // The lock could be marked eliminated by lock coarsening
2425 // code during first IGVN before EA. Replace coarsened flag
2426 // to eliminate all associated locks/unlocks.
2427 #ifdef ASSERT
2428 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2429 #endif
2430 this->set_non_esc_obj();
2431 return result;
2432 }
2433
2434 if (!phase->C->do_locks_coarsening()) {
2435 return result; // Compiling without locks coarsening
2436 }
2437 //
2598 }
2599
2600 //=============================================================================
2601 uint UnlockNode::size_of() const { return sizeof(*this); }
2602
2603 //=============================================================================
2604 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2605
2606 // perform any generic optimizations first (returns 'this' or null)
2607 Node *result = SafePointNode::Ideal(phase, can_reshape);
2608 if (result != nullptr) return result;
2609 // Don't bother trying to transform a dead node
2610 if (in(0) && in(0)->is_top()) return nullptr;
2611
2612 // Now see if we can optimize away this unlock. We don't actually
2613 // remove the unlocking here, we simply set the _eliminate flag which
2614 // prevents macro expansion from expanding the unlock. Since we don't
2615 // modify the graph, the value returned from this function is the
2616 // one computed above.
2617 // Escape state is defined after Parse phase.
2618 const Type* obj_type = phase->type(obj_node());
2619 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2620 //
2621 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2622 //
2623 ConnectionGraph *cgr = phase->C->congraph();
2624 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2625 assert(!is_eliminated() || is_coarsened(), "sanity");
2626 // The lock could be marked eliminated by lock coarsening
2627 // code during first IGVN before EA. Replace coarsened flag
2628 // to eliminate all associated locks/unlocks.
2629 #ifdef ASSERT
2630 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2631 #endif
2632 this->set_non_esc_obj();
2633 }
2634 }
2635 return result;
2636 }
2637
2638 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2639 if (C == nullptr) {
2679 }
2680 // unrelated
2681 return false;
2682 }
2683
2684 if (dest_t->isa_aryptr()) {
2685 // arraycopy or array clone
2686 if (t_oop->isa_instptr()) {
2687 return false;
2688 }
2689 if (!t_oop->isa_aryptr()) {
2690 return true;
2691 }
2692
2693 const Type* elem = dest_t->is_aryptr()->elem();
2694 if (elem == Type::BOTTOM) {
2695 // An array but we don't know what elements are
2696 return true;
2697 }
2698
2699 dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2700 t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2701 uint dest_alias = phase->C->get_alias_index(dest_t);
2702 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2703
2704 return dest_alias == t_oop_alias;
2705 }
2706
2707 return true;
2708 }
|