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();
1169
1170 //----------------------------uncommon_trap_request----------------------------
1171 // If this is an uncommon trap, return the request code, else zero.
1172 int CallStaticJavaNode::uncommon_trap_request() const {
1173 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1174 }
1175 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1176 #ifndef PRODUCT
1177 if (!(call->req() > TypeFunc::Parms &&
1178 call->in(TypeFunc::Parms) != nullptr &&
1179 call->in(TypeFunc::Parms)->is_Con() &&
1180 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1181 assert(in_dump() != 0, "OK if dumping");
1182 tty->print("[bad uncommon trap]");
1183 return 0;
1184 }
1185 #endif
1186 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1187 }
1188
1189 #ifndef PRODUCT
1190 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1191 st->print("# Static ");
1192 if (_name != nullptr) {
1193 st->print("%s", _name);
1194 int trap_req = uncommon_trap_request();
1195 if (trap_req != 0) {
1196 char buf[100];
1197 st->print("(%s)",
1198 Deoptimization::format_trap_request(buf, sizeof(buf),
1199 trap_req));
1200 }
1201 st->print(" ");
1202 }
1203 CallJavaNode::dump_spec(st);
1204 }
1205
1206 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1207 if (_method) {
1208 _method->print_short_name(st);
1280 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1281 bool CallRuntimeNode::cmp( const Node &n ) const {
1282 CallRuntimeNode &call = (CallRuntimeNode&)n;
1283 return CallNode::cmp(call) && !strcmp(_name,call._name);
1284 }
1285 #ifndef PRODUCT
1286 void CallRuntimeNode::dump_spec(outputStream *st) const {
1287 st->print("# ");
1288 st->print("%s", _name);
1289 CallNode::dump_spec(st);
1290 }
1291 #endif
1292 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1293 bool CallLeafVectorNode::cmp( const Node &n ) const {
1294 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1295 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1296 }
1297
1298 //------------------------------calling_convention-----------------------------
1299 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1300 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1301 }
1302
1303 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1304 #ifdef ASSERT
1305 assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1306 "return vector size must match");
1307 const TypeTuple* d = tf()->domain();
1308 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1309 Node* arg = in(i);
1310 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1311 "vector argument size must match");
1312 }
1313 #endif
1314
1315 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1316 }
1317
1318 //=============================================================================
1319 //------------------------------calling_convention-----------------------------
1320
1321
1322 //=============================================================================
1323 bool CallLeafPureNode::is_unused() const {
1324 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1325 }
1326
1327 bool CallLeafPureNode::is_dead() const {
1328 return proj_out_or_null(TypeFunc::Control) == nullptr;
1329 }
1330
1331 /* We make a tuple of the global input state + TOP for the output values.
1332 * We use this to delete a pure function that is not used: by replacing the call with
1333 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1334 * pure call, so jumping over it, and effectively, removing the call from the graph.
1335 * This avoids doing the graph surgery manually, but leaves that to IGVN
1336 * that is specialized for doing that right. We need also tuple components for output
1337 * values of the function to respect the return arity, and in case there is a projection
1338 * that would pick an output (which shouldn't happen at the moment).
1339 */
1340 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1341 // Transparently propagate input state but parameters
1342 TupleNode* tuple = TupleNode::make(
1343 tf()->range(),
1344 in(TypeFunc::Control),
1345 in(TypeFunc::I_O),
1346 in(TypeFunc::Memory),
1347 in(TypeFunc::FramePtr),
1348 in(TypeFunc::ReturnAdr));
1349
1350 // And add TOPs for the return values
1351 for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1352 tuple->set_req(i, C->top());
1353 }
1354
1355 return tuple;
1356 }
1357
1358 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1359 if (is_dead()) {
1360 return nullptr;
1361 }
1362
1363 // We need to wait until IGVN because during parsing, usages might still be missing
1364 // and we would remove the call immediately.
1365 if (can_reshape && is_unused()) {
1366 // The result is not used. We remove the call by replacing it with a tuple, that
1367 // is later disintegrated by the projections.
1368 return make_tuple_of_input_state_and_top_return_values(phase->C);
1369 }
1370
1371 return CallRuntimeNode::Ideal(phase, can_reshape);
1372 }
1373
1374 #ifndef PRODUCT
1375 void CallLeafNode::dump_spec(outputStream *st) const {
1376 st->print("# ");
1377 st->print("%s", _name);
1378 CallNode::dump_spec(st);
1379 }
1380 #endif
1381
1382 //=============================================================================
1383
1384 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1385 assert(verify_jvms(jvms), "jvms must match");
1386 int loc = jvms->locoff() + idx;
1387 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1388 // If current local idx is top then local idx - 1 could
1389 // be a long/double that needs to be killed since top could
1390 // represent the 2nd half of the long/double.
1391 uint ideal = in(loc -1)->ideal_reg();
1392 if (ideal == Op_RegD || ideal == Op_RegL) {
1393 // set other (low index) half to top
1394 set_req(loc - 1, in(loc));
1395 }
1396 }
1397 set_req(loc, c);
1398 }
1399
1400 uint SafePointNode::size_of() const { return sizeof(*this); }
1401 bool SafePointNode::cmp( const Node &n ) const {
1412 }
1413 }
1414
1415
1416 //----------------------------next_exception-----------------------------------
1417 SafePointNode* SafePointNode::next_exception() const {
1418 if (len() == req()) {
1419 return nullptr;
1420 } else {
1421 Node* n = in(req());
1422 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1423 return (SafePointNode*) n;
1424 }
1425 }
1426
1427
1428 //------------------------------Ideal------------------------------------------
1429 // Skip over any collapsed Regions
1430 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1431 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1432 return remove_dead_region(phase, can_reshape) ? this : nullptr;
1433 }
1434
1435 //------------------------------Identity---------------------------------------
1436 // Remove obviously duplicate safepoints
1437 Node* SafePointNode::Identity(PhaseGVN* phase) {
1438
1439 // If you have back to back safepoints, remove one
1440 if (in(TypeFunc::Control)->is_SafePoint()) {
1441 Node* out_c = unique_ctrl_out_or_null();
1442 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1443 // outer loop's safepoint could confuse removal of the outer loop.
1444 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1445 return in(TypeFunc::Control);
1446 }
1447 }
1448
1449 // Transforming long counted loops requires a safepoint node. Do not
1450 // eliminate a safepoint until loop opts are over.
1451 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1452 Node *n0 = in(0)->in(0);
1564 }
1565
1566 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1567 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1568 int nb = igvn->C->root()->find_prec_edge(this);
1569 if (nb != -1) {
1570 igvn->delete_precedence_of(igvn->C->root(), nb);
1571 }
1572 }
1573
1574 //============== SafePointScalarObjectNode ==============
1575
1576 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1577 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1578 _first_index(first_index),
1579 _depth(depth),
1580 _n_fields(n_fields),
1581 _alloc(alloc)
1582 {
1583 #ifdef ASSERT
1584 if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1585 alloc->dump();
1586 assert(false, "unexpected call node");
1587 }
1588 #endif
1589 init_class_id(Class_SafePointScalarObject);
1590 }
1591
1592 // Do not allow value-numbering for SafePointScalarObject node.
1593 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1594 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1595 return (&n == this); // Always fail except on self
1596 }
1597
1598 uint SafePointScalarObjectNode::ideal_reg() const {
1599 return 0; // No matching to machine instruction
1600 }
1601
1602 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1603 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1604 }
1669 new_node = false;
1670 return (SafePointScalarMergeNode*)cached;
1671 }
1672 new_node = true;
1673 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1674 sosn_map->Insert((void*)this, (void*)res);
1675 return res;
1676 }
1677
1678 #ifndef PRODUCT
1679 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1680 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1681 }
1682 #endif
1683
1684 //=============================================================================
1685 uint AllocateNode::size_of() const { return sizeof(*this); }
1686
1687 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1688 Node *ctrl, Node *mem, Node *abio,
1689 Node *size, Node *klass_node, Node *initial_test)
1690 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1691 {
1692 init_class_id(Class_Allocate);
1693 init_flags(Flag_is_macro);
1694 _is_scalar_replaceable = false;
1695 _is_non_escaping = false;
1696 _is_allocation_MemBar_redundant = false;
1697 Node *topnode = C->top();
1698
1699 init_req( TypeFunc::Control , ctrl );
1700 init_req( TypeFunc::I_O , abio );
1701 init_req( TypeFunc::Memory , mem );
1702 init_req( TypeFunc::ReturnAdr, topnode );
1703 init_req( TypeFunc::FramePtr , topnode );
1704 init_req( AllocSize , size);
1705 init_req( KlassNode , klass_node);
1706 init_req( InitialTest , initial_test);
1707 init_req( ALength , topnode);
1708 init_req( ValidLengthTest , topnode);
1709 C->add_macro_node(this);
1710 }
1711
1712 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1713 {
1714 assert(initializer != nullptr && initializer->is_object_initializer(),
1715 "unexpected initializer method");
1716 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1717 if (analyzer == nullptr) {
1718 return;
1719 }
1720
1721 // Allocation node is first parameter in its initializer
1722 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1723 _is_allocation_MemBar_redundant = true;
1724 }
1725 }
1726 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1727 Node* mark_node = nullptr;
1728 if (UseCompactObjectHeaders) {
1729 Node* klass_node = in(AllocateNode::KlassNode);
1730 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1731 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1732 } else {
1733 // For now only enable fast locking for non-array types
1734 mark_node = phase->MakeConX(markWord::prototype().value());
1735 }
1736 return mark_node;
1737 }
1738
1739 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1740 // CastII, if appropriate. If we are not allowed to create new nodes, and
1741 // a CastII is appropriate, return null.
1742 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1743 Node *length = in(AllocateNode::ALength);
1744 assert(length != nullptr, "length is not null");
1745
1746 const TypeInt* length_type = phase->find_int_type(length);
1747 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1748
1749 if (ary_type != nullptr && length_type != nullptr) {
1750 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1751 if (narrow_length_type != length_type) {
1752 // Assert one of:
1753 // - the narrow_length is 0
1754 // - the narrow_length is not wider than length
1755 assert(narrow_length_type == TypeInt::ZERO ||
1756 (length_type->is_con() && narrow_length_type->is_con() &&
2112
2113 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2114 st->print("%s", _kind_names[_kind]);
2115 }
2116 #endif
2117
2118 //=============================================================================
2119 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2120
2121 // perform any generic optimizations first (returns 'this' or null)
2122 Node *result = SafePointNode::Ideal(phase, can_reshape);
2123 if (result != nullptr) return result;
2124 // Don't bother trying to transform a dead node
2125 if (in(0) && in(0)->is_top()) return nullptr;
2126
2127 // Now see if we can optimize away this lock. We don't actually
2128 // remove the locking here, we simply set the _eliminate flag which
2129 // prevents macro expansion from expanding the lock. Since we don't
2130 // modify the graph, the value returned from this function is the
2131 // one computed above.
2132 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2133 //
2134 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2135 //
2136 ConnectionGraph *cgr = phase->C->congraph();
2137 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2138 assert(!is_eliminated() || is_coarsened(), "sanity");
2139 // The lock could be marked eliminated by lock coarsening
2140 // code during first IGVN before EA. Replace coarsened flag
2141 // to eliminate all associated locks/unlocks.
2142 #ifdef ASSERT
2143 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2144 #endif
2145 this->set_non_esc_obj();
2146 return result;
2147 }
2148
2149 if (!phase->C->do_locks_coarsening()) {
2150 return result; // Compiling without locks coarsening
2151 }
2152 //
2313 }
2314
2315 //=============================================================================
2316 uint UnlockNode::size_of() const { return sizeof(*this); }
2317
2318 //=============================================================================
2319 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2320
2321 // perform any generic optimizations first (returns 'this' or null)
2322 Node *result = SafePointNode::Ideal(phase, can_reshape);
2323 if (result != nullptr) return result;
2324 // Don't bother trying to transform a dead node
2325 if (in(0) && in(0)->is_top()) return nullptr;
2326
2327 // Now see if we can optimize away this unlock. We don't actually
2328 // remove the unlocking here, we simply set the _eliminate flag which
2329 // prevents macro expansion from expanding the unlock. Since we don't
2330 // modify the graph, the value returned from this function is the
2331 // one computed above.
2332 // Escape state is defined after Parse phase.
2333 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2334 //
2335 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2336 //
2337 ConnectionGraph *cgr = phase->C->congraph();
2338 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2339 assert(!is_eliminated() || is_coarsened(), "sanity");
2340 // The lock could be marked eliminated by lock coarsening
2341 // code during first IGVN before EA. Replace coarsened flag
2342 // to eliminate all associated locks/unlocks.
2343 #ifdef ASSERT
2344 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2345 #endif
2346 this->set_non_esc_obj();
2347 }
2348 }
2349 return result;
2350 }
2351
2352 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2353 if (C == nullptr) {
2393 }
2394 // unrelated
2395 return false;
2396 }
2397
2398 if (dest_t->isa_aryptr()) {
2399 // arraycopy or array clone
2400 if (t_oop->isa_instptr()) {
2401 return false;
2402 }
2403 if (!t_oop->isa_aryptr()) {
2404 return true;
2405 }
2406
2407 const Type* elem = dest_t->is_aryptr()->elem();
2408 if (elem == Type::BOTTOM) {
2409 // An array but we don't know what elements are
2410 return true;
2411 }
2412
2413 dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2414 uint dest_alias = phase->C->get_alias_index(dest_t);
2415 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2416
2417 return dest_alias == t_oop_alias;
2418 }
2419
2420 return true;
2421 }
|
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 "code/vmreg.hpp"
28 #include "compiler/compileLog.hpp"
29 #include "compiler/oopMap.hpp"
30 #include "gc/shared/barrierSet.hpp"
31 #include "gc/shared/c2/barrierSetC2.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "opto/callGenerator.hpp"
34 #include "opto/callnode.hpp"
35 #include "opto/castnode.hpp"
36 #include "opto/convertnode.hpp"
37 #include "opto/escape.hpp"
38 #include "opto/inlinetypenode.hpp"
39 #include "opto/locknode.hpp"
40 #include "opto/machnode.hpp"
41 #include "opto/matcher.hpp"
42 #include "opto/parse.hpp"
43 #include "opto/regalloc.hpp"
44 #include "opto/regmask.hpp"
45 #include "opto/rootnode.hpp"
46 #include "opto/runtime.hpp"
47 #include "runtime/sharedRuntime.hpp"
48 #include "runtime/stubRoutines.hpp"
49 #include "utilities/powerOfTwo.hpp"
50
51 // Portions of code courtesy of Clifford Click
52
53 // Optimization - Graph Style
54
55 //=============================================================================
56 uint StartNode::size_of() const { return sizeof(*this); }
57 bool StartNode::cmp( const Node &n ) const
58 { return _domain == ((StartNode&)n)._domain; }
59 const Type *StartNode::bottom_type() const { return _domain; }
60 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
61 #ifndef PRODUCT
62 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
63 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
64 #endif
65
66 //------------------------------Ideal------------------------------------------
67 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
68 return remove_dead_region(phase, can_reshape) ? this : nullptr;
69 }
70
71 //------------------------------calling_convention-----------------------------
72 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
73 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
74 }
75
76 //------------------------------Registers--------------------------------------
77 const RegMask &StartNode::in_RegMask(uint) const {
78 return RegMask::Empty;
79 }
80
81 //------------------------------match------------------------------------------
82 // Construct projections for incoming parameters, and their RegMask info
83 Node *StartNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
84 switch (proj->_con) {
85 case TypeFunc::Control:
86 case TypeFunc::I_O:
87 case TypeFunc::Memory:
88 return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
89 case TypeFunc::FramePtr:
90 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
91 case TypeFunc::ReturnAdr:
92 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
93 case TypeFunc::Parms:
94 default: {
95 uint parm_num = proj->_con - TypeFunc::Parms;
96 const Type *t = _domain->field_at(proj->_con);
97 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
98 return new ConNode(Type::TOP);
99 uint ideal_reg = t->ideal_reg();
100 RegMask &rm = match->_calling_convention_mask[parm_num];
101 return new MachProjNode(this,proj->_con,rm,ideal_reg);
102 }
103 }
104 return nullptr;
105 }
106
107 //=============================================================================
108 const char * const ParmNode::names[TypeFunc::Parms+1] = {
109 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
110 };
111
112 #ifndef PRODUCT
113 void ParmNode::dump_spec(outputStream *st) const {
114 if( _con < TypeFunc::Parms ) {
115 st->print("%s", names[_con]);
116 } else {
117 st->print("Parm%d: ",_con-TypeFunc::Parms);
118 // Verbose and WizardMode dump bottom_type for all nodes
119 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
120 }
121 }
122
123 void ParmNode::dump_compact_spec(outputStream *st) const {
124 if (_con < TypeFunc::Parms) {
125 st->print("%s", names[_con]);
126 } else {
474 if (cik->is_instance_klass()) {
475 cik->print_name_on(st);
476 iklass = cik->as_instance_klass();
477 } else if (cik->is_type_array_klass()) {
478 cik->as_array_klass()->base_element_type()->print_name_on(st);
479 st->print("[%d]", spobj->n_fields());
480 } else if (cik->is_obj_array_klass()) {
481 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
482 if (cie->is_instance_klass()) {
483 cie->print_name_on(st);
484 } else if (cie->is_type_array_klass()) {
485 cie->as_array_klass()->base_element_type()->print_name_on(st);
486 } else {
487 ShouldNotReachHere();
488 }
489 st->print("[%d]", spobj->n_fields());
490 int ndim = cik->as_array_klass()->dimension() - 1;
491 while (ndim-- > 0) {
492 st->print("[]");
493 }
494 } else if (cik->is_flat_array_klass()) {
495 ciKlass* cie = cik->as_flat_array_klass()->base_element_klass();
496 cie->print_name_on(st);
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 if (iklass != nullptr && iklass->is_inlinetype()) {
508 Node* null_marker = mcall->in(first_ind++);
509 if (!null_marker->is_top()) {
510 st->print(" [null marker");
511 format_helper(regalloc, st, null_marker, ":", -1, nullptr);
512 }
513 }
514 Node* fld_node = mcall->in(first_ind);
515 if (iklass != nullptr) {
516 st->print(" [");
517 iklass->nonstatic_field_at(0)->print_name_on(st);
518 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
519 } else {
520 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
521 }
522 for (uint j = 1; j < nf; j++) {
523 fld_node = mcall->in(first_ind+j);
524 if (iklass != nullptr) {
525 st->print(", [");
526 iklass->nonstatic_field_at(j)->print_name_on(st);
527 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
528 } else {
529 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
530 }
531 }
532 }
533 st->print(" }");
534 }
535 }
536 st->cr();
537 if (caller() != nullptr) caller()->format(regalloc, n, st);
538 }
539
540
541 void JVMState::dump_spec(outputStream *st) const {
542 if (_method != nullptr) {
543 bool printed = false;
544 if (!Verbose) {
545 // The JVMS dumps make really, really long lines.
546 // Take out the most boring parts, which are the package prefixes.
741 tf()->dump_on(st);
742 }
743 if (_cnt != COUNT_UNKNOWN) {
744 st->print(" C=%f", _cnt);
745 }
746 const Node* const klass_node = in(KlassNode);
747 if (klass_node != nullptr) {
748 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
749
750 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
751 st->print(" allocationKlass:");
752 klass_ptr->exact_klass()->print_name_on(st);
753 }
754 }
755 if (jvms() != nullptr) {
756 jvms()->dump_spec(st);
757 }
758 }
759 #endif
760
761 const Type *CallNode::bottom_type() const { return tf()->range_cc(); }
762 const Type* CallNode::Value(PhaseGVN* phase) const {
763 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
764 return Type::TOP;
765 }
766 return tf()->range_cc();
767 }
768
769 //------------------------------calling_convention-----------------------------
770 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
771 if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
772 // The call to that stub is a special case: its inputs are
773 // multiple values returned from a call and so it should follow
774 // the return convention.
775 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
776 return;
777 }
778 // Use the standard compiler calling convention
779 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
780 }
781
782
783 //------------------------------match------------------------------------------
784 // Construct projections for control, I/O, memory-fields, ..., and
785 // return result(s) along with their RegMask info
786 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
787 uint con = proj->_con;
788 const TypeTuple* range_cc = tf()->range_cc();
789 if (con >= TypeFunc::Parms) {
790 if (tf()->returns_inline_type_as_fields()) {
791 // The call returns multiple values (inline type fields): we
792 // create one projection per returned value.
793 assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
794 uint ideal_reg = range_cc->field_at(con)->ideal_reg();
795 return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
796 } else {
797 if (con == TypeFunc::Parms) {
798 uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
799 OptoRegPair regs = Opcode() == Op_CallLeafVector
800 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
801 : match->c_return_value(ideal_reg);
802 RegMask rm = RegMask(regs.first());
803
804 if (Opcode() == Op_CallLeafVector) {
805 // If the return is in vector, compute appropriate regmask taking into account the whole range
806 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
807 if(OptoReg::is_valid(regs.second())) {
808 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
809 rm.Insert(r);
810 }
811 }
812 }
813 }
814
815 if (OptoReg::is_valid(regs.second())) {
816 rm.Insert(regs.second());
817 }
818 return new MachProjNode(this,con,rm,ideal_reg);
819 } else {
820 assert(con == TypeFunc::Parms+1, "only one return value");
821 assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
822 return new MachProjNode(this,con, RegMask::Empty, (uint)OptoReg::Bad);
823 }
824 }
825 }
826
827 switch (con) {
828 case TypeFunc::Control:
829 case TypeFunc::I_O:
830 case TypeFunc::Memory:
831 return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
832
833 case TypeFunc::ReturnAdr:
834 case TypeFunc::FramePtr:
835 default:
836 ShouldNotReachHere();
837 }
838 return nullptr;
839 }
840
841 // Do we Match on this edge index or not? Match no edges
842 uint CallNode::match_edge(uint idx) const {
843 return 0;
844 }
845
846 //
847 // Determine whether the call could modify the field of the specified
848 // instance at the specified offset.
849 //
850 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
851 assert((t_oop != nullptr), "sanity");
852 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
853 const TypeTuple* args = _tf->domain_sig();
854 Node* dest = nullptr;
855 // Stubs that can be called once an ArrayCopyNode is expanded have
856 // different signatures. Look for the second pointer argument,
857 // that is the destination of the copy.
858 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
859 if (args->field_at(i)->isa_ptr()) {
860 j++;
861 if (j == 2) {
862 dest = in(i);
863 break;
864 }
865 }
866 }
867 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
868 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
869 return true;
870 }
871 return false;
872 }
873 if (t_oop->is_known_instance()) {
882 Node* proj = proj_out_or_null(TypeFunc::Parms);
883 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
884 return false;
885 }
886 }
887 if (is_CallJava() && as_CallJava()->method() != nullptr) {
888 ciMethod* meth = as_CallJava()->method();
889 if (meth->is_getter()) {
890 return false;
891 }
892 // May modify (by reflection) if an boxing object is passed
893 // as argument or returned.
894 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
895 if (proj != nullptr) {
896 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
897 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
898 (inst_t->instance_klass() == boxing_klass))) {
899 return true;
900 }
901 }
902 const TypeTuple* d = tf()->domain_cc();
903 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
904 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
905 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
906 (inst_t->instance_klass() == boxing_klass))) {
907 return true;
908 }
909 }
910 return false;
911 }
912 }
913 return true;
914 }
915
916 // Does this call have a direct reference to n other than debug information?
917 bool CallNode::has_non_debug_use(Node* n) {
918 const TypeTuple* d = tf()->domain_cc();
919 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
920 if (in(i) == n) {
921 return true;
922 }
923 }
924 return false;
925 }
926
927 bool CallNode::has_debug_use(Node* n) {
928 if (jvms() != nullptr) {
929 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
930 if (in(i) == n) {
931 return true;
932 }
933 }
934 }
935 return false;
936 }
937
938 // Returns the unique CheckCastPP of a call
939 // or 'this' if there are several CheckCastPP or unexpected uses
940 // or returns null if there is no one.
941 Node *CallNode::result_cast() {
942 Node *cast = nullptr;
943
944 Node *p = proj_out_or_null(TypeFunc::Parms);
945 if (p == nullptr)
946 return nullptr;
947
948 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
949 Node *use = p->fast_out(i);
950 if (use->is_CheckCastPP()) {
951 if (cast != nullptr) {
952 return this; // more than 1 CheckCastPP
953 }
954 cast = use;
955 } else if (!use->is_Initialize() &&
956 !use->is_AddP() &&
957 use->Opcode() != Op_MemBarStoreStore) {
958 // Expected uses are restricted to a CheckCastPP, an Initialize
959 // node, a MemBarStoreStore (clone) and AddP nodes. If we
960 // encounter any other use (a Phi node can be seen in rare
961 // cases) return this to prevent incorrect optimizations.
962 return this;
963 }
964 }
965 return cast;
966 }
967
968
969 CallProjections* CallNode::extract_projections(bool separate_io_proj, bool do_asserts) const {
970 uint max_res = TypeFunc::Parms-1;
971 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
972 ProjNode *pn = fast_out(i)->as_Proj();
973 max_res = MAX2(max_res, pn->_con);
974 }
975
976 assert(max_res < _tf->range_cc()->cnt(), "result out of bounds");
977
978 uint projs_size = sizeof(CallProjections);
979 if (max_res > TypeFunc::Parms) {
980 projs_size += (max_res-TypeFunc::Parms)*sizeof(Node*);
981 }
982 char* projs_storage = resource_allocate_bytes(projs_size);
983 CallProjections* projs = new(projs_storage)CallProjections(max_res - TypeFunc::Parms + 1);
984
985 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
986 ProjNode *pn = fast_out(i)->as_Proj();
987 if (pn->outcnt() == 0) continue;
988 switch (pn->_con) {
989 case TypeFunc::Control:
990 {
991 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
992 projs->fallthrough_proj = pn;
993 const Node* cn = pn->unique_ctrl_out_or_null();
994 if (cn != nullptr && cn->is_Catch()) {
995 ProjNode *cpn = nullptr;
996 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
997 cpn = cn->fast_out(k)->as_Proj();
998 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
999 if (cpn->_con == CatchProjNode::fall_through_index)
1000 projs->fallthrough_catchproj = cpn;
1001 else {
1002 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
1003 projs->catchall_catchproj = cpn;
1009 case TypeFunc::I_O:
1010 if (pn->_is_io_use)
1011 projs->catchall_ioproj = pn;
1012 else
1013 projs->fallthrough_ioproj = pn;
1014 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
1015 Node* e = pn->out(j);
1016 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
1017 assert(projs->exobj == nullptr, "only one");
1018 projs->exobj = e;
1019 }
1020 }
1021 break;
1022 case TypeFunc::Memory:
1023 if (pn->_is_io_use)
1024 projs->catchall_memproj = pn;
1025 else
1026 projs->fallthrough_memproj = pn;
1027 break;
1028 case TypeFunc::Parms:
1029 projs->resproj[0] = pn;
1030 break;
1031 default:
1032 assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1033 projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1034 break;
1035 }
1036 }
1037
1038 // The resproj may not exist because the result could be ignored
1039 // and the exception object may not exist if an exception handler
1040 // swallows the exception but all the other must exist and be found.
1041 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1042 assert(!do_asserts || projs->fallthrough_proj != nullptr, "must be found");
1043 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1044 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1045 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1046 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1047 if (separate_io_proj) {
1048 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1049 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1050 }
1051 return projs;
1052 }
1053
1054 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1055 #ifdef ASSERT
1056 // Validate attached generator
1057 CallGenerator* cg = generator();
1058 if (cg != nullptr) {
1059 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1060 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1061 }
1062 #endif // ASSERT
1063 return SafePointNode::Ideal(phase, can_reshape);
1064 }
1065
1066 bool CallNode::is_call_to_arraycopystub() const {
1067 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1068 return true;
1069 }
1070 return false;
1071 }
1072
1073 //=============================================================================
1074 uint CallJavaNode::size_of() const { return sizeof(*this); }
1075 bool CallJavaNode::cmp( const Node &n ) const {
1076 CallJavaNode &call = (CallJavaNode&)n;
1077 return CallNode::cmp(call) && _method == call._method &&
1078 _override_symbolic_info == call._override_symbolic_info;
1079 }
1080
1081 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1082 // Copy debug information and adjust JVMState information
1083 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1084 uint new_dbg_start = tf()->domain_sig()->cnt();
1085 int jvms_adj = new_dbg_start - old_dbg_start;
1086 assert (new_dbg_start == req(), "argument count mismatch");
1087 Compile* C = phase->C;
1088
1089 // SafePointScalarObject node could be referenced several times in debug info.
1090 // Use Dict to record cloned nodes.
1091 Dict* sosn_map = new Dict(cmpkey,hashkey);
1092 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1093 Node* old_in = sfpt->in(i);
1094 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1095 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1096 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1097 bool new_node;
1098 Node* new_in = old_sosn->clone(sosn_map, new_node);
1099 if (new_node) { // New node?
1100 new_in->set_req(0, C->root()); // reset control edge
1101 new_in = phase->transform(new_in); // Register new node.
1102 }
1103 old_in = new_in;
1104 }
1105 add_req(old_in);
1106 }
1107
1108 // JVMS may be shared so clone it before we modify it
1109 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1110 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1111 jvms->set_map(this);
1112 jvms->set_locoff(jvms->locoff()+jvms_adj);
1113 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1114 jvms->set_monoff(jvms->monoff()+jvms_adj);
1115 jvms->set_scloff(jvms->scloff()+jvms_adj);
1116 jvms->set_endoff(jvms->endoff()+jvms_adj);
1117 }
1118 }
1119
1120 #ifdef ASSERT
1121 bool CallJavaNode::validate_symbolic_info() const {
1122 if (method() == nullptr) {
1123 return true; // call into runtime or uncommon trap
1124 }
1125 Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1126 if (EnableValhalla && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1127 return true;
1128 }
1129 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1130 ciMethod* callee = method();
1131 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1132 assert(override_symbolic_info(), "should be set");
1133 }
1134 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1135 return true;
1136 }
1137 #endif
1138
1139 #ifndef PRODUCT
1140 void CallJavaNode::dump_spec(outputStream* st) const {
1141 if( _method ) _method->print_short_name(st);
1142 CallNode::dump_spec(st);
1143 }
1144
1145 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1146 if (_method) {
1147 _method->print_short_name(st);
1148 } else {
1151 }
1152 #endif
1153
1154 void CallJavaNode::register_for_late_inline() {
1155 if (generator() != nullptr) {
1156 Compile::current()->prepend_late_inline(generator());
1157 set_generator(nullptr);
1158 } else {
1159 assert(false, "repeated inline attempt");
1160 }
1161 }
1162
1163 //=============================================================================
1164 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1165 bool CallStaticJavaNode::cmp( const Node &n ) const {
1166 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1167 return CallJavaNode::cmp(call);
1168 }
1169
1170 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1171 if (can_reshape && uncommon_trap_request() != 0) {
1172 PhaseIterGVN* igvn = phase->is_IterGVN();
1173 if (remove_unknown_flat_array_load(igvn, in(0), in(TypeFunc::Memory), in(TypeFunc::Parms))) {
1174 if (!in(0)->is_Region()) {
1175 igvn->replace_input_of(this, 0, phase->C->top());
1176 }
1177 return this;
1178 }
1179 }
1180
1181 CallGenerator* cg = generator();
1182 if (can_reshape && cg != nullptr) {
1183 if (cg->is_mh_late_inline()) {
1184 assert(IncrementalInlineMH, "required");
1185 assert(cg->call_node() == this, "mismatch");
1186 assert(cg->method()->is_method_handle_intrinsic(), "required");
1187
1188 // Check whether this MH handle call becomes a candidate for inlining.
1189 ciMethod* callee = cg->method();
1190 vmIntrinsics::ID iid = callee->intrinsic_id();
1191 if (iid == vmIntrinsics::_invokeBasic) {
1192 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1193 register_for_late_inline();
1194 }
1195 } else if (iid == vmIntrinsics::_linkToNative) {
1196 // never retry
1197 } else {
1198 assert(callee->has_member_arg(), "wrong type of call?");
1199 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1200 register_for_late_inline();
1222
1223 //----------------------------uncommon_trap_request----------------------------
1224 // If this is an uncommon trap, return the request code, else zero.
1225 int CallStaticJavaNode::uncommon_trap_request() const {
1226 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1227 }
1228 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1229 #ifndef PRODUCT
1230 if (!(call->req() > TypeFunc::Parms &&
1231 call->in(TypeFunc::Parms) != nullptr &&
1232 call->in(TypeFunc::Parms)->is_Con() &&
1233 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1234 assert(in_dump() != 0, "OK if dumping");
1235 tty->print("[bad uncommon trap]");
1236 return 0;
1237 }
1238 #endif
1239 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1240 }
1241
1242 // Split if can cause the flat array branch of an array load with unknown type (see
1243 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1244 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1245 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1246 if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1247 return false;
1248 }
1249 if (ctl->is_Region()) {
1250 bool res = false;
1251 for (uint i = 1; i < ctl->req(); i++) {
1252 MergeMemNode* mm = mem->clone()->as_MergeMem();
1253 for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1254 Node* m = mms.memory();
1255 if (m->is_Phi() && m->in(0) == ctl) {
1256 mms.set_memory(m->in(i));
1257 }
1258 }
1259 if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1260 res = true;
1261 if (!ctl->in(i)->is_Region()) {
1262 igvn->replace_input_of(ctl, i, igvn->C->top());
1263 }
1264 }
1265 igvn->remove_dead_node(mm);
1266 }
1267 return res;
1268 }
1269 // Verify the control flow is ok
1270 Node* call = ctl;
1271 MemBarNode* membar = nullptr;
1272 for (;;) {
1273 if (call == nullptr || call->is_top()) {
1274 return false;
1275 }
1276 if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1277 call = call->in(0);
1278 } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1279 call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1280 assert(call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar(), "missing membar");
1281 membar = call->in(0)->in(0)->as_MemBar();
1282 break;
1283 } else {
1284 return false;
1285 }
1286 }
1287
1288 JVMState* jvms = call->jvms();
1289 if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1290 return false;
1291 }
1292
1293 Node* call_mem = call->in(TypeFunc::Memory);
1294 if (call_mem == nullptr || call_mem->is_top()) {
1295 return false;
1296 }
1297 if (!call_mem->is_MergeMem()) {
1298 call_mem = MergeMemNode::make(call_mem);
1299 igvn->register_new_node_with_optimizer(call_mem);
1300 }
1301
1302 // Verify that there's no unexpected side effect
1303 for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1304 Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1305 Node* m2 = mms2.memory2();
1306
1307 for (uint i = 0; i < 100; i++) {
1308 if (m1 == m2) {
1309 break;
1310 } else if (m1->is_Proj()) {
1311 m1 = m1->in(0);
1312 } else if (m1->is_MemBar()) {
1313 m1 = m1->in(TypeFunc::Memory);
1314 } else if (m1->Opcode() == Op_CallStaticJava &&
1315 m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1316 if (m1 != call) {
1317 return false;
1318 }
1319 break;
1320 } else if (m1->is_MergeMem()) {
1321 MergeMemNode* mm = m1->as_MergeMem();
1322 int idx = mms2.alias_idx();
1323 if (idx == Compile::AliasIdxBot) {
1324 m1 = mm->base_memory();
1325 } else {
1326 m1 = mm->memory_at(idx);
1327 }
1328 } else {
1329 return false;
1330 }
1331 }
1332 }
1333 if (call_mem->outcnt() == 0) {
1334 igvn->remove_dead_node(call_mem);
1335 }
1336
1337 // Remove membar preceding the call
1338 membar->remove(igvn);
1339
1340 address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1341 CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1342 unc->init_req(TypeFunc::Control, call->in(0));
1343 unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1344 unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1345 unc->init_req(TypeFunc::FramePtr, call->in(TypeFunc::FramePtr));
1346 unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1347 unc->init_req(TypeFunc::Parms+0, unc_arg);
1348 unc->set_cnt(PROB_UNLIKELY_MAG(4));
1349 unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1350
1351 // Replace the call with an uncommon trap
1352 igvn->replace_input_of(call, 0, igvn->C->top());
1353
1354 igvn->register_new_node_with_optimizer(unc);
1355
1356 Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1357 Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1358 igvn->add_input_to(igvn->C->root(), halt);
1359
1360 return true;
1361 }
1362
1363
1364 #ifndef PRODUCT
1365 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1366 st->print("# Static ");
1367 if (_name != nullptr) {
1368 st->print("%s", _name);
1369 int trap_req = uncommon_trap_request();
1370 if (trap_req != 0) {
1371 char buf[100];
1372 st->print("(%s)",
1373 Deoptimization::format_trap_request(buf, sizeof(buf),
1374 trap_req));
1375 }
1376 st->print(" ");
1377 }
1378 CallJavaNode::dump_spec(st);
1379 }
1380
1381 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1382 if (_method) {
1383 _method->print_short_name(st);
1455 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1456 bool CallRuntimeNode::cmp( const Node &n ) const {
1457 CallRuntimeNode &call = (CallRuntimeNode&)n;
1458 return CallNode::cmp(call) && !strcmp(_name,call._name);
1459 }
1460 #ifndef PRODUCT
1461 void CallRuntimeNode::dump_spec(outputStream *st) const {
1462 st->print("# ");
1463 st->print("%s", _name);
1464 CallNode::dump_spec(st);
1465 }
1466 #endif
1467 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1468 bool CallLeafVectorNode::cmp( const Node &n ) const {
1469 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1470 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1471 }
1472
1473 //------------------------------calling_convention-----------------------------
1474 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1475 if (_entry_point == nullptr) {
1476 // The call to that stub is a special case: its inputs are
1477 // multiple values returned from a call and so it should follow
1478 // the return convention.
1479 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1480 return;
1481 }
1482 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1483 }
1484
1485 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1486 #ifdef ASSERT
1487 assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1488 "return vector size must match");
1489 const TypeTuple* d = tf()->domain_sig();
1490 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1491 Node* arg = in(i);
1492 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1493 "vector argument size must match");
1494 }
1495 #endif
1496
1497 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1498 }
1499
1500 //=============================================================================
1501 //------------------------------calling_convention-----------------------------
1502
1503
1504 //=============================================================================
1505 bool CallLeafPureNode::is_unused() const {
1506 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1507 }
1508
1509 bool CallLeafPureNode::is_dead() const {
1510 return proj_out_or_null(TypeFunc::Control) == nullptr;
1511 }
1512
1513 /* We make a tuple of the global input state + TOP for the output values.
1514 * We use this to delete a pure function that is not used: by replacing the call with
1515 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1516 * pure call, so jumping over it, and effectively, removing the call from the graph.
1517 * This avoids doing the graph surgery manually, but leaves that to IGVN
1518 * that is specialized for doing that right. We need also tuple components for output
1519 * values of the function to respect the return arity, and in case there is a projection
1520 * that would pick an output (which shouldn't happen at the moment).
1521 */
1522 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1523 // Transparently propagate input state but parameters
1524 TupleNode* tuple = TupleNode::make(
1525 tf()->range_cc(),
1526 in(TypeFunc::Control),
1527 in(TypeFunc::I_O),
1528 in(TypeFunc::Memory),
1529 in(TypeFunc::FramePtr),
1530 in(TypeFunc::ReturnAdr));
1531
1532 // And add TOPs for the return values
1533 for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1534 tuple->set_req(i, C->top());
1535 }
1536
1537 return tuple;
1538 }
1539
1540 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1541 if (is_dead()) {
1542 return nullptr;
1543 }
1544
1545 // We need to wait until IGVN because during parsing, usages might still be missing
1546 // and we would remove the call immediately.
1547 if (can_reshape && is_unused()) {
1548 // The result is not used. We remove the call by replacing it with a tuple, that
1549 // is later disintegrated by the projections.
1550 return make_tuple_of_input_state_and_top_return_values(phase->C);
1551 }
1552
1553 return CallRuntimeNode::Ideal(phase, can_reshape);
1554 }
1555
1556 #ifndef PRODUCT
1557 void CallLeafNode::dump_spec(outputStream *st) const {
1558 st->print("# ");
1559 st->print("%s", _name);
1560 CallNode::dump_spec(st);
1561 }
1562 #endif
1563
1564 uint CallLeafNoFPNode::match_edge(uint idx) const {
1565 // Null entry point is a special case for which the target is in a
1566 // register. Need to match that edge.
1567 return entry_point() == nullptr && idx == TypeFunc::Parms;
1568 }
1569
1570 //=============================================================================
1571
1572 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1573 assert(verify_jvms(jvms), "jvms must match");
1574 int loc = jvms->locoff() + idx;
1575 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1576 // If current local idx is top then local idx - 1 could
1577 // be a long/double that needs to be killed since top could
1578 // represent the 2nd half of the long/double.
1579 uint ideal = in(loc -1)->ideal_reg();
1580 if (ideal == Op_RegD || ideal == Op_RegL) {
1581 // set other (low index) half to top
1582 set_req(loc - 1, in(loc));
1583 }
1584 }
1585 set_req(loc, c);
1586 }
1587
1588 uint SafePointNode::size_of() const { return sizeof(*this); }
1589 bool SafePointNode::cmp( const Node &n ) const {
1600 }
1601 }
1602
1603
1604 //----------------------------next_exception-----------------------------------
1605 SafePointNode* SafePointNode::next_exception() const {
1606 if (len() == req()) {
1607 return nullptr;
1608 } else {
1609 Node* n = in(req());
1610 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1611 return (SafePointNode*) n;
1612 }
1613 }
1614
1615
1616 //------------------------------Ideal------------------------------------------
1617 // Skip over any collapsed Regions
1618 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1619 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1620 if (remove_dead_region(phase, can_reshape)) {
1621 return this;
1622 }
1623 // Scalarize inline types in safepoint debug info.
1624 // Delay this until all inlining is over to avoid getting inconsistent debug info.
1625 if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1626 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1627 Node* n = in(i)->uncast();
1628 if (n->is_InlineType()) {
1629 n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1630 }
1631 }
1632 }
1633 return nullptr;
1634 }
1635
1636 //------------------------------Identity---------------------------------------
1637 // Remove obviously duplicate safepoints
1638 Node* SafePointNode::Identity(PhaseGVN* phase) {
1639
1640 // If you have back to back safepoints, remove one
1641 if (in(TypeFunc::Control)->is_SafePoint()) {
1642 Node* out_c = unique_ctrl_out_or_null();
1643 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1644 // outer loop's safepoint could confuse removal of the outer loop.
1645 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1646 return in(TypeFunc::Control);
1647 }
1648 }
1649
1650 // Transforming long counted loops requires a safepoint node. Do not
1651 // eliminate a safepoint until loop opts are over.
1652 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1653 Node *n0 = in(0)->in(0);
1765 }
1766
1767 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1768 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1769 int nb = igvn->C->root()->find_prec_edge(this);
1770 if (nb != -1) {
1771 igvn->delete_precedence_of(igvn->C->root(), nb);
1772 }
1773 }
1774
1775 //============== SafePointScalarObjectNode ==============
1776
1777 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1778 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1779 _first_index(first_index),
1780 _depth(depth),
1781 _n_fields(n_fields),
1782 _alloc(alloc)
1783 {
1784 #ifdef ASSERT
1785 if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1786 alloc->dump();
1787 assert(false, "unexpected call node");
1788 }
1789 #endif
1790 init_class_id(Class_SafePointScalarObject);
1791 }
1792
1793 // Do not allow value-numbering for SafePointScalarObject node.
1794 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1795 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1796 return (&n == this); // Always fail except on self
1797 }
1798
1799 uint SafePointScalarObjectNode::ideal_reg() const {
1800 return 0; // No matching to machine instruction
1801 }
1802
1803 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1804 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1805 }
1870 new_node = false;
1871 return (SafePointScalarMergeNode*)cached;
1872 }
1873 new_node = true;
1874 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1875 sosn_map->Insert((void*)this, (void*)res);
1876 return res;
1877 }
1878
1879 #ifndef PRODUCT
1880 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1881 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1882 }
1883 #endif
1884
1885 //=============================================================================
1886 uint AllocateNode::size_of() const { return sizeof(*this); }
1887
1888 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1889 Node *ctrl, Node *mem, Node *abio,
1890 Node *size, Node *klass_node,
1891 Node* initial_test,
1892 InlineTypeNode* inline_type_node)
1893 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1894 {
1895 init_class_id(Class_Allocate);
1896 init_flags(Flag_is_macro);
1897 _is_scalar_replaceable = false;
1898 _is_non_escaping = false;
1899 _is_allocation_MemBar_redundant = false;
1900 _larval = false;
1901 Node *topnode = C->top();
1902
1903 init_req( TypeFunc::Control , ctrl );
1904 init_req( TypeFunc::I_O , abio );
1905 init_req( TypeFunc::Memory , mem );
1906 init_req( TypeFunc::ReturnAdr, topnode );
1907 init_req( TypeFunc::FramePtr , topnode );
1908 init_req( AllocSize , size);
1909 init_req( KlassNode , klass_node);
1910 init_req( InitialTest , initial_test);
1911 init_req( ALength , topnode);
1912 init_req( ValidLengthTest , topnode);
1913 init_req( InlineType , inline_type_node);
1914 // DefaultValue defaults to nullptr
1915 // RawDefaultValue defaults to nullptr
1916 C->add_macro_node(this);
1917 }
1918
1919 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1920 {
1921 assert(initializer != nullptr &&
1922 (initializer->is_object_constructor() || initializer->is_class_initializer()),
1923 "unexpected initializer method");
1924 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1925 if (analyzer == nullptr) {
1926 return;
1927 }
1928
1929 // Allocation node is first parameter in its initializer
1930 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1931 _is_allocation_MemBar_redundant = true;
1932 }
1933 }
1934
1935 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
1936 Node* mark_node = nullptr;
1937 if (UseCompactObjectHeaders || EnableValhalla) {
1938 Node* klass_node = in(AllocateNode::KlassNode);
1939 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1940 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1941 if (EnableValhalla) {
1942 mark_node = phase->transform(mark_node);
1943 // Avoid returning a constant (old node) here because this method is used by LoadNode::Ideal
1944 mark_node = new OrXNode(mark_node, phase->MakeConX(_larval ? markWord::larval_bit_in_place : 0));
1945 }
1946 return mark_node;
1947 } else {
1948 return phase->MakeConX(markWord::prototype().value());
1949 }
1950 }
1951
1952 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1953 // CastII, if appropriate. If we are not allowed to create new nodes, and
1954 // a CastII is appropriate, return null.
1955 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1956 Node *length = in(AllocateNode::ALength);
1957 assert(length != nullptr, "length is not null");
1958
1959 const TypeInt* length_type = phase->find_int_type(length);
1960 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1961
1962 if (ary_type != nullptr && length_type != nullptr) {
1963 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1964 if (narrow_length_type != length_type) {
1965 // Assert one of:
1966 // - the narrow_length is 0
1967 // - the narrow_length is not wider than length
1968 assert(narrow_length_type == TypeInt::ZERO ||
1969 (length_type->is_con() && narrow_length_type->is_con() &&
2325
2326 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2327 st->print("%s", _kind_names[_kind]);
2328 }
2329 #endif
2330
2331 //=============================================================================
2332 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2333
2334 // perform any generic optimizations first (returns 'this' or null)
2335 Node *result = SafePointNode::Ideal(phase, can_reshape);
2336 if (result != nullptr) return result;
2337 // Don't bother trying to transform a dead node
2338 if (in(0) && in(0)->is_top()) return nullptr;
2339
2340 // Now see if we can optimize away this lock. We don't actually
2341 // remove the locking here, we simply set the _eliminate flag which
2342 // prevents macro expansion from expanding the lock. Since we don't
2343 // modify the graph, the value returned from this function is the
2344 // one computed above.
2345 const Type* obj_type = phase->type(obj_node());
2346 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2347 //
2348 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2349 //
2350 ConnectionGraph *cgr = phase->C->congraph();
2351 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2352 assert(!is_eliminated() || is_coarsened(), "sanity");
2353 // The lock could be marked eliminated by lock coarsening
2354 // code during first IGVN before EA. Replace coarsened flag
2355 // to eliminate all associated locks/unlocks.
2356 #ifdef ASSERT
2357 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2358 #endif
2359 this->set_non_esc_obj();
2360 return result;
2361 }
2362
2363 if (!phase->C->do_locks_coarsening()) {
2364 return result; // Compiling without locks coarsening
2365 }
2366 //
2527 }
2528
2529 //=============================================================================
2530 uint UnlockNode::size_of() const { return sizeof(*this); }
2531
2532 //=============================================================================
2533 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2534
2535 // perform any generic optimizations first (returns 'this' or null)
2536 Node *result = SafePointNode::Ideal(phase, can_reshape);
2537 if (result != nullptr) return result;
2538 // Don't bother trying to transform a dead node
2539 if (in(0) && in(0)->is_top()) return nullptr;
2540
2541 // Now see if we can optimize away this unlock. We don't actually
2542 // remove the unlocking here, we simply set the _eliminate flag which
2543 // prevents macro expansion from expanding the unlock. Since we don't
2544 // modify the graph, the value returned from this function is the
2545 // one computed above.
2546 // Escape state is defined after Parse phase.
2547 const Type* obj_type = phase->type(obj_node());
2548 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2549 //
2550 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2551 //
2552 ConnectionGraph *cgr = phase->C->congraph();
2553 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2554 assert(!is_eliminated() || is_coarsened(), "sanity");
2555 // The lock could be marked eliminated by lock coarsening
2556 // code during first IGVN before EA. Replace coarsened flag
2557 // to eliminate all associated locks/unlocks.
2558 #ifdef ASSERT
2559 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2560 #endif
2561 this->set_non_esc_obj();
2562 }
2563 }
2564 return result;
2565 }
2566
2567 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2568 if (C == nullptr) {
2608 }
2609 // unrelated
2610 return false;
2611 }
2612
2613 if (dest_t->isa_aryptr()) {
2614 // arraycopy or array clone
2615 if (t_oop->isa_instptr()) {
2616 return false;
2617 }
2618 if (!t_oop->isa_aryptr()) {
2619 return true;
2620 }
2621
2622 const Type* elem = dest_t->is_aryptr()->elem();
2623 if (elem == Type::BOTTOM) {
2624 // An array but we don't know what elements are
2625 return true;
2626 }
2627
2628 dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2629 t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2630 uint dest_alias = phase->C->get_alias_index(dest_t);
2631 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2632
2633 return dest_alias == t_oop_alias;
2634 }
2635
2636 return true;
2637 }
|