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