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 "runtime/stubRoutines.hpp"
47 #include "utilities/powerOfTwo.hpp"
48
49 // Portions of code courtesy of Clifford Click
50
51 // Optimization - Graph Style
52
53 //=============================================================================
54 uint StartNode::size_of() const { return sizeof(*this); }
55 bool StartNode::cmp( const Node &n ) const
56 { return _domain == ((StartNode&)n)._domain; }
57 const Type *StartNode::bottom_type() const { return _domain; }
58 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
59 #ifndef PRODUCT
60 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
61 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
62 #endif
63
64 //------------------------------Ideal------------------------------------------
65 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
66 return remove_dead_region(phase, can_reshape) ? this : nullptr;
67 }
68
69 //------------------------------calling_convention-----------------------------
70 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
71 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
72 }
73
74 //------------------------------Registers--------------------------------------
75 const RegMask &StartNode::in_RegMask(uint) const {
76 return RegMask::EMPTY;
77 }
78
79 //------------------------------match------------------------------------------
80 // Construct projections for incoming parameters, and their RegMask info
81 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
82 switch (proj->_con) {
83 case TypeFunc::Control:
84 case TypeFunc::I_O:
85 case TypeFunc::Memory:
86 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
87 case TypeFunc::FramePtr:
88 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
89 case TypeFunc::ReturnAdr:
90 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
91 case TypeFunc::Parms:
92 default: {
93 uint parm_num = proj->_con - TypeFunc::Parms;
94 const Type *t = _domain->field_at(proj->_con);
95 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
96 return new ConNode(Type::TOP);
97 uint ideal_reg = t->ideal_reg();
98 RegMask &rm = match->_calling_convention_mask[parm_num];
99 return new MachProjNode(this,proj->_con,rm,ideal_reg);
100 }
101 }
102 return nullptr;
103 }
104
105 //------------------------------StartOSRNode----------------------------------
106 // The method start node for an on stack replacement adapter
107
108 //------------------------------osr_domain-----------------------------
109 const TypeTuple *StartOSRNode::osr_domain() {
110 const Type **fields = TypeTuple::fields(2);
111 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
112
113 return TypeTuple::make(TypeFunc::Parms+1, fields);
114 }
115
116 //=============================================================================
117 const char * const ParmNode::names[TypeFunc::Parms+1] = {
118 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
119 };
120
121 #ifndef PRODUCT
122 void ParmNode::dump_spec(outputStream *st) const {
123 if( _con < TypeFunc::Parms ) {
124 st->print("%s", names[_con]);
125 } else {
126 st->print("Parm%d: ",_con-TypeFunc::Parms);
127 // Verbose and WizardMode dump bottom_type for all nodes
128 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
129 }
130 }
131
132 void ParmNode::dump_compact_spec(outputStream *st) const {
133 if (_con < TypeFunc::Parms) {
134 st->print("%s", names[_con]);
135 } else {
483 if (cik->is_instance_klass()) {
484 cik->print_name_on(st);
485 iklass = cik->as_instance_klass();
486 } else if (cik->is_type_array_klass()) {
487 cik->as_array_klass()->base_element_type()->print_name_on(st);
488 st->print("[%d]", spobj->n_fields());
489 } else if (cik->is_obj_array_klass()) {
490 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
491 if (cie->is_instance_klass()) {
492 cie->print_name_on(st);
493 } else if (cie->is_type_array_klass()) {
494 cie->as_array_klass()->base_element_type()->print_name_on(st);
495 } else {
496 ShouldNotReachHere();
497 }
498 st->print("[%d]", spobj->n_fields());
499 int ndim = cik->as_array_klass()->dimension() - 1;
500 while (ndim-- > 0) {
501 st->print("[]");
502 }
503 }
504 st->print("={");
505 uint nf = spobj->n_fields();
506 if (nf > 0) {
507 uint first_ind = spobj->first_index(mcall->jvms());
508 Node* fld_node = mcall->in(first_ind);
509 ciField* cifield;
510 if (iklass != nullptr) {
511 st->print(" [");
512 cifield = iklass->nonstatic_field_at(0);
513 cifield->print_name_on(st);
514 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
515 } else {
516 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
517 }
518 for (uint j = 1; j < nf; j++) {
519 fld_node = mcall->in(first_ind+j);
520 if (iklass != nullptr) {
521 st->print(", [");
522 cifield = iklass->nonstatic_field_at(j);
523 cifield->print_name_on(st);
524 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
525 } else {
526 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
527 }
528 }
529 }
530 st->print(" }");
531 }
532 }
533 st->cr();
534 if (caller() != nullptr) caller()->format(regalloc, n, st);
535 }
536
537
538 void JVMState::dump_spec(outputStream *st) const {
539 if (_method != nullptr) {
540 bool printed = false;
541 if (!Verbose) {
542 // The JVMS dumps make really, really long lines.
543 // Take out the most boring parts, which are the package prefixes.
738 tf()->dump_on(st);
739 }
740 if (_cnt != COUNT_UNKNOWN) {
741 st->print(" C=%f", _cnt);
742 }
743 const Node* const klass_node = in(KlassNode);
744 if (klass_node != nullptr) {
745 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
746
747 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
748 st->print(" allocationKlass:");
749 klass_ptr->exact_klass()->print_name_on(st);
750 }
751 }
752 if (jvms() != nullptr) {
753 jvms()->dump_spec(st);
754 }
755 }
756 #endif
757
758 const Type *CallNode::bottom_type() const { return tf()->range(); }
759 const Type* CallNode::Value(PhaseGVN* phase) const {
760 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
761 return Type::TOP;
762 }
763 return tf()->range();
764 }
765
766 //------------------------------calling_convention-----------------------------
767 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
768 // Use the standard compiler calling convention
769 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
770 }
771
772
773 //------------------------------match------------------------------------------
774 // Construct projections for control, I/O, memory-fields, ..., and
775 // return result(s) along with their RegMask info
776 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
777 switch (proj->_con) {
778 case TypeFunc::Control:
779 case TypeFunc::I_O:
780 case TypeFunc::Memory:
781 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
782
783 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
784 assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
785 // 2nd half of doubles and longs
786 return new MachProjNode(this,proj->_con, RegMask::EMPTY, (uint)OptoReg::Bad);
787
788 case TypeFunc::Parms: { // Normal returns
789 uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
790 OptoRegPair regs = Opcode() == Op_CallLeafVector
791 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
792 : is_CallRuntime()
793 ? match->c_return_value(ideal_reg) // Calls into C runtime
794 : match-> return_value(ideal_reg); // Calls into compiled Java code
795 RegMask rm = RegMask(regs.first());
796
797 if (Opcode() == Op_CallLeafVector) {
798 // If the return is in vector, compute appropriate regmask taking into account the whole range
799 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
800 if(OptoReg::is_valid(regs.second())) {
801 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
802 rm.insert(r);
803 }
804 }
805 }
806 }
807
808 if( OptoReg::is_valid(regs.second()) )
809 rm.insert(regs.second());
810 return new MachProjNode(this,proj->_con,rm,ideal_reg);
811 }
812
813 case TypeFunc::ReturnAdr:
814 case TypeFunc::FramePtr:
815 default:
816 ShouldNotReachHere();
817 }
818 return nullptr;
819 }
820
821 // Do we Match on this edge index or not? Match no edges
822 uint CallNode::match_edge(uint idx) const {
823 return 0;
824 }
825
826 //
827 // Determine whether the call could modify the field of the specified
828 // instance at the specified offset.
829 //
830 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) const {
831 assert((t_oop != nullptr), "sanity");
832 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
833 const TypeTuple* args = _tf->domain();
834 Node* dest = nullptr;
835 // Stubs that can be called once an ArrayCopyNode is expanded have
836 // different signatures. Look for the second pointer argument,
837 // that is the destination of the copy.
838 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
839 if (args->field_at(i)->isa_ptr()) {
840 j++;
841 if (j == 2) {
842 dest = in(i);
843 break;
844 }
845 }
846 }
847 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
848 if (phase->type(dest)->isa_rawptr()) {
849 // may happen for an arraycopy that initializes a newly allocated object. Conservatively return true;
850 return true;
851 }
852 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
853 return true;
866 Node* proj = proj_out_or_null(TypeFunc::Parms);
867 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
868 return false;
869 }
870 }
871 if (is_CallJava() && as_CallJava()->method() != nullptr) {
872 ciMethod* meth = as_CallJava()->method();
873 if (meth->is_getter()) {
874 return false;
875 }
876 // May modify (by reflection) if an boxing object is passed
877 // as argument or returned.
878 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
879 if (proj != nullptr) {
880 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
881 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
882 (inst_t->instance_klass() == boxing_klass))) {
883 return true;
884 }
885 }
886 const TypeTuple* d = tf()->domain();
887 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
888 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
889 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
890 (inst_t->instance_klass() == boxing_klass))) {
891 return true;
892 }
893 }
894 return false;
895 }
896 }
897 return true;
898 }
899
900 // Does this call have a direct reference to n other than debug information?
901 bool CallNode::has_non_debug_use(const Node *n) {
902 const TypeTuple * d = tf()->domain();
903 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
904 Node *arg = in(i);
905 if (arg == n) {
906 return true;
907 }
908 }
909 return false;
910 }
911
912 // Returns the unique CheckCastPP of a call
913 // or 'this' if there are several CheckCastPP or unexpected uses
914 // or returns null if there is no one.
915 Node *CallNode::result_cast() {
916 Node *cast = nullptr;
917
918 Node *p = proj_out_or_null(TypeFunc::Parms);
919 if (p == nullptr)
920 return nullptr;
921
922 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
923 Node *use = p->fast_out(i);
924 if (use->is_CheckCastPP()) {
925 if (cast != nullptr) {
926 return this; // more than 1 CheckCastPP
927 }
928 cast = use;
929 } else if (!use->is_Initialize() &&
930 !use->is_AddP() &&
931 use->Opcode() != Op_MemBarStoreStore) {
932 // Expected uses are restricted to a CheckCastPP, an Initialize
933 // node, a MemBarStoreStore (clone) and AddP nodes. If we
934 // encounter any other use (a Phi node can be seen in rare
935 // cases) return this to prevent incorrect optimizations.
936 return this;
937 }
938 }
939 return cast;
940 }
941
942
943 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts, bool allow_handlers) const {
944 projs->fallthrough_proj = nullptr;
945 projs->fallthrough_catchproj = nullptr;
946 projs->fallthrough_ioproj = nullptr;
947 projs->catchall_ioproj = nullptr;
948 projs->catchall_catchproj = nullptr;
949 projs->fallthrough_memproj = nullptr;
950 projs->catchall_memproj = nullptr;
951 projs->resproj = nullptr;
952 projs->exobj = nullptr;
953
954 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
955 ProjNode *pn = fast_out(i)->as_Proj();
956 if (pn->outcnt() == 0) continue;
957 switch (pn->_con) {
958 case TypeFunc::Control:
959 {
960 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
961 projs->fallthrough_proj = pn;
962 const Node* cn = pn->unique_ctrl_out_or_null();
963 if (cn != nullptr && cn->is_Catch()) {
964 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
965 CatchProjNode* cpn = cn->fast_out(k)->as_CatchProj();
966 assert(allow_handlers || !cpn->is_handler_proj(), "not allowed");
967 if (cpn->_con == CatchProjNode::fall_through_index) {
968 assert(cpn->handler_bci() == CatchProjNode::no_handler_bci, "");
969 projs->fallthrough_catchproj = cpn;
970 } else if (!cpn->is_handler_proj()) {
971 projs->catchall_catchproj = cpn;
972 }
982 }
983 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
984 Node* e = pn->out(j);
985 if (e->Opcode() == Op_CreateEx && e->outcnt() > 0) {
986 CatchProjNode* ecpn = e->in(0)->isa_CatchProj();
987 assert(allow_handlers || ecpn == nullptr || !ecpn->is_handler_proj(), "not allowed");
988 if (ecpn != nullptr && ecpn->_con != CatchProjNode::fall_through_index && !ecpn->is_handler_proj()) {
989 assert(projs->exobj == nullptr, "only one");
990 projs->exobj = e;
991 }
992 }
993 }
994 break;
995 case TypeFunc::Memory:
996 if (pn->_is_io_use)
997 projs->catchall_memproj = pn;
998 else
999 projs->fallthrough_memproj = pn;
1000 break;
1001 case TypeFunc::Parms:
1002 projs->resproj = pn;
1003 break;
1004 default:
1005 assert(false, "unexpected projection from allocation node.");
1006 }
1007 }
1008
1009 // The resproj may not exist because the result could be ignored
1010 // and the exception object may not exist if an exception handler
1011 // swallows the exception but all the other must exist and be found.
1012 assert(projs->fallthrough_proj != nullptr, "must be found");
1013 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1014 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1015 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1016 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1017 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1018 if (separate_io_proj) {
1019 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1020 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1021 }
1022 }
1023
1024 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1025 #ifdef ASSERT
1026 // Validate attached generator
1027 CallGenerator* cg = generator();
1028 if (cg != nullptr) {
1029 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1030 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1031 }
1032 #endif // ASSERT
1033 return SafePointNode::Ideal(phase, can_reshape);
1034 }
1035
1036 bool CallNode::is_call_to_arraycopystub() const {
1037 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1038 return true;
1039 }
1040 return false;
1041 }
1042
1043 bool CallNode::is_call_to_multianewarray_stub() const {
1044 if (_name != nullptr &&
1045 strstr(_name, "multianewarray") != nullptr &&
1046 strstr(_name, "C2 runtime") != nullptr) {
1047 return true;
1048 }
1049 return false;
1050 }
1051
1052 //=============================================================================
1053 uint CallJavaNode::size_of() const { return sizeof(*this); }
1054 bool CallJavaNode::cmp( const Node &n ) const {
1055 CallJavaNode &call = (CallJavaNode&)n;
1056 return CallNode::cmp(call) && _method == call._method &&
1057 _override_symbolic_info == call._override_symbolic_info;
1058 }
1059
1060 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1061 // Copy debug information and adjust JVMState information
1062 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
1063 uint new_dbg_start = tf()->domain()->cnt();
1064 int jvms_adj = new_dbg_start - old_dbg_start;
1065 assert (new_dbg_start == req(), "argument count mismatch");
1066 Compile* C = phase->C;
1067
1068 // SafePointScalarObject node could be referenced several times in debug info.
1069 // Use Dict to record cloned nodes.
1070 Dict* sosn_map = new Dict(cmpkey,hashkey);
1071 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1072 Node* old_in = sfpt->in(i);
1073 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1074 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1075 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1076 bool new_node;
1077 Node* new_in = old_sosn->clone(sosn_map, new_node);
1078 if (new_node) { // New node?
1079 new_in->set_req(0, C->root()); // reset control edge
1080 new_in = phase->transform(new_in); // Register new node.
1081 }
1082 old_in = new_in;
1083 }
1084 add_req(old_in);
1085 }
1086
1087 // JVMS may be shared so clone it before we modify it
1088 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1089 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1090 jvms->set_map(this);
1091 jvms->set_locoff(jvms->locoff()+jvms_adj);
1092 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1093 jvms->set_monoff(jvms->monoff()+jvms_adj);
1094 jvms->set_scloff(jvms->scloff()+jvms_adj);
1095 jvms->set_endoff(jvms->endoff()+jvms_adj);
1096 }
1097 }
1098
1099 #ifdef ASSERT
1100 bool CallJavaNode::validate_symbolic_info() const {
1101 if (method() == nullptr) {
1102 return true; // call into runtime or uncommon trap
1103 }
1104 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1105 ciMethod* callee = method();
1106 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1107 assert(override_symbolic_info(), "should be set");
1108 }
1109 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1110 return true;
1111 }
1112 #endif
1113
1114 #ifndef PRODUCT
1115 void CallJavaNode::dump_spec(outputStream* st) const {
1116 if( _method ) _method->print_short_name(st);
1117 CallNode::dump_spec(st);
1118 }
1119
1120 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1121 if (_method) {
1122 _method->print_short_name(st);
1123 } else {
1126 }
1127 #endif
1128
1129 void CallJavaNode::register_for_late_inline() {
1130 if (generator() != nullptr) {
1131 Compile::current()->prepend_late_inline(generator());
1132 set_generator(nullptr);
1133 } else {
1134 assert(false, "repeated inline attempt");
1135 }
1136 }
1137
1138 //=============================================================================
1139 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1140 bool CallStaticJavaNode::cmp( const Node &n ) const {
1141 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1142 return CallJavaNode::cmp(call);
1143 }
1144
1145 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1146 CallGenerator* cg = generator();
1147 if (can_reshape && cg != nullptr) {
1148 if (cg->is_mh_late_inline()) {
1149 assert(IncrementalInlineMH, "required");
1150 assert(cg->call_node() == this, "mismatch");
1151 assert(cg->method()->is_method_handle_intrinsic(), "required");
1152
1153 // Check whether this MH handle call becomes a candidate for inlining.
1154 ciMethod* callee = cg->method();
1155 vmIntrinsics::ID iid = callee->intrinsic_id();
1156 if (iid == vmIntrinsics::_invokeBasic) {
1157 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1158 register_for_late_inline();
1159 }
1160 } else if (iid == vmIntrinsics::_linkToNative) {
1161 // never retry
1162 } else {
1163 assert(callee->has_member_arg(), "wrong type of call?");
1164 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1165 register_for_late_inline();
1186
1187 //----------------------------uncommon_trap_request----------------------------
1188 // If this is an uncommon trap, return the request code, else zero.
1189 int CallStaticJavaNode::uncommon_trap_request() const {
1190 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1191 }
1192 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1193 #ifndef PRODUCT
1194 if (!(call->req() > TypeFunc::Parms &&
1195 call->in(TypeFunc::Parms) != nullptr &&
1196 call->in(TypeFunc::Parms)->is_Con() &&
1197 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1198 assert(in_dump() != 0, "OK if dumping");
1199 tty->print("[bad uncommon trap]");
1200 return 0;
1201 }
1202 #endif
1203 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1204 }
1205
1206 #ifndef PRODUCT
1207 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1208 st->print("# Static ");
1209 if (_name != nullptr) {
1210 st->print("%s", _name);
1211 int trap_req = uncommon_trap_request();
1212 if (trap_req != 0) {
1213 char buf[100];
1214 st->print("(%s)",
1215 Deoptimization::format_trap_request(buf, sizeof(buf),
1216 trap_req));
1217 }
1218 st->print(" ");
1219 }
1220 CallJavaNode::dump_spec(st);
1221 }
1222
1223 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1224 if (_method) {
1225 _method->print_short_name(st);
1301 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1302 bool CallRuntimeNode::cmp( const Node &n ) const {
1303 CallRuntimeNode &call = (CallRuntimeNode&)n;
1304 return CallNode::cmp(call) && !strcmp(_name,call._name);
1305 }
1306 #ifndef PRODUCT
1307 void CallRuntimeNode::dump_spec(outputStream *st) const {
1308 st->print("# ");
1309 st->print("%s", _name);
1310 CallNode::dump_spec(st);
1311 }
1312 #endif
1313 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1314 bool CallLeafVectorNode::cmp( const Node &n ) const {
1315 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1316 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1317 }
1318
1319 //------------------------------calling_convention-----------------------------
1320 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1321 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1322 }
1323
1324 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1325 #ifdef ASSERT
1326 assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1327 "return vector size must match");
1328 const TypeTuple* d = tf()->domain();
1329 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1330 Node* arg = in(i);
1331 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1332 "vector argument size must match");
1333 }
1334 #endif
1335
1336 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1337 }
1338
1339 //=============================================================================
1340 //------------------------------calling_convention-----------------------------
1341
1342
1343 //=============================================================================
1344 bool CallLeafPureNode::is_unused() const {
1345 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1346 }
1347
1348 bool CallLeafPureNode::is_dead() const {
1349 return proj_out_or_null(TypeFunc::Control) == nullptr;
1350 }
1351
1352 /* We make a tuple of the global input state + TOP for the output values.
1353 * We use this to delete a pure function that is not used: by replacing the call with
1354 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1355 * pure call, so jumping over it, and effectively, removing the call from the graph.
1356 * This avoids doing the graph surgery manually, but leaves that to IGVN
1357 * that is specialized for doing that right. We need also tuple components for output
1358 * values of the function to respect the return arity, and in case there is a projection
1359 * that would pick an output (which shouldn't happen at the moment).
1360 */
1361 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1362 // Transparently propagate input state but parameters
1363 TupleNode* tuple = TupleNode::make(
1364 tf()->range(),
1365 in(TypeFunc::Control),
1366 in(TypeFunc::I_O),
1367 in(TypeFunc::Memory),
1368 in(TypeFunc::FramePtr),
1369 in(TypeFunc::ReturnAdr));
1370
1371 // And add TOPs for the return values
1372 for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1373 tuple->set_req(i, C->top());
1374 }
1375
1376 return tuple;
1377 }
1378
1379 CallLeafPureNode* CallLeafPureNode::inline_call_leaf_pure_node(Node* control) const {
1380 Node* top = Compile::current()->top();
1381 if (control == nullptr) {
1382 control = in(TypeFunc::Control);
1383 }
1384
1385 CallLeafPureNode* call = new CallLeafPureNode(tf(), entry_point(), _name);
1386 call->init_req(TypeFunc::Control, control);
1387 call->init_req(TypeFunc::I_O, top);
1388 call->init_req(TypeFunc::Memory, top);
1389 call->init_req(TypeFunc::ReturnAdr, top);
1390 call->init_req(TypeFunc::FramePtr, top);
1391 for (unsigned int i = 0; i < tf()->domain()->cnt() - TypeFunc::Parms; i++) {
1392 call->init_req(TypeFunc::Parms + i, in(TypeFunc::Parms + i));
1393 }
1394
1395 return call;
1396 }
1397
1398 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1399 if (is_dead()) {
1400 return nullptr;
1401 }
1402
1403 // We need to wait until IGVN because during parsing, usages might still be missing
1404 // and we would remove the call immediately.
1405 if (can_reshape && is_unused()) {
1406 // The result is not used. We remove the call by replacing it with a tuple, that
1407 // is later disintegrated by the projections.
1408 return make_tuple_of_input_state_and_top_return_values(phase->C);
1409 }
1410
1411 return CallRuntimeNode::Ideal(phase, can_reshape);
1412 }
1413
1414 #ifndef PRODUCT
1415 void CallLeafNode::dump_spec(outputStream *st) const {
1416 st->print("# ");
1417 st->print("%s", _name);
1418 CallNode::dump_spec(st);
1419 }
1420 #endif
1421
1422 //=============================================================================
1423
1424 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1425 assert(verify_jvms(jvms), "jvms must match");
1426 int loc = jvms->locoff() + idx;
1427 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1428 // If current local idx is top then local idx - 1 could
1429 // be a long/double that needs to be killed since top could
1430 // represent the 2nd half of the long/double.
1431 uint ideal = in(loc -1)->ideal_reg();
1432 if (ideal == Op_RegD || ideal == Op_RegL) {
1433 // set other (low index) half to top
1434 set_req(loc - 1, in(loc));
1435 }
1436 }
1437 set_req(loc, c);
1438 }
1439
1440 uint SafePointNode::size_of() const { return sizeof(*this); }
1441 bool SafePointNode::cmp( const Node &n ) const {
1452 }
1453 }
1454
1455
1456 //----------------------------next_exception-----------------------------------
1457 SafePointNode* SafePointNode::next_exception() const {
1458 if (len() == req()) {
1459 return nullptr;
1460 } else {
1461 Node* n = in(req());
1462 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1463 return (SafePointNode*) n;
1464 }
1465 }
1466
1467
1468 //------------------------------Ideal------------------------------------------
1469 // Skip over any collapsed Regions
1470 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1471 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1472 return remove_dead_region(phase, can_reshape) ? this : nullptr;
1473 }
1474
1475 //------------------------------Identity---------------------------------------
1476 // Remove obviously duplicate safepoints
1477 Node* SafePointNode::Identity(PhaseGVN* phase) {
1478
1479 // If you have back to back safepoints, remove one
1480 if (in(TypeFunc::Control)->is_SafePoint()) {
1481 Node* out_c = unique_ctrl_out_or_null();
1482 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1483 // outer loop's safepoint could confuse removal of the outer loop.
1484 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1485 return in(TypeFunc::Control);
1486 }
1487 }
1488
1489 // Transforming long counted loops requires a safepoint node. Do not
1490 // eliminate a safepoint until loop opts are over.
1491 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1492 Node *n0 = in(0)->in(0);
1633
1634 while (!non_debug_edges.is_empty()) {
1635 Node* non_debug_edge = non_debug_edges.pop();
1636 add_req(non_debug_edge);
1637 }
1638
1639 assert(non_debug_edges.is_empty(), "edges not processed");
1640 DEBUG_ONLY(non_debug_edges._state = NodeEdgeTempStorage::state_processed);
1641 }
1642
1643 //============== SafePointScalarObjectNode ==============
1644
1645 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1646 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1647 _first_index(first_index),
1648 _depth(depth),
1649 _n_fields(n_fields),
1650 _alloc(alloc)
1651 {
1652 #ifdef ASSERT
1653 if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1654 alloc->dump();
1655 assert(false, "unexpected call node");
1656 }
1657 #endif
1658 init_class_id(Class_SafePointScalarObject);
1659 }
1660
1661 // Do not allow value-numbering for SafePointScalarObject node.
1662 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1663 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1664 return (&n == this); // Always fail except on self
1665 }
1666
1667 uint SafePointScalarObjectNode::ideal_reg() const {
1668 return 0; // No matching to machine instruction
1669 }
1670
1671 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1672 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1673 }
1738 new_node = false;
1739 return (SafePointScalarMergeNode*)cached;
1740 }
1741 new_node = true;
1742 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1743 sosn_map->Insert((void*)this, (void*)res);
1744 return res;
1745 }
1746
1747 #ifndef PRODUCT
1748 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1749 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1750 }
1751 #endif
1752
1753 //=============================================================================
1754 uint AllocateNode::size_of() const { return sizeof(*this); }
1755
1756 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1757 Node *ctrl, Node *mem, Node *abio,
1758 Node *size, Node *klass_node, Node *initial_test)
1759 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1760 {
1761 init_class_id(Class_Allocate);
1762 init_flags(Flag_is_macro);
1763 _is_scalar_replaceable = false;
1764 _is_non_escaping = false;
1765 _is_allocation_MemBar_redundant = false;
1766 Node *topnode = C->top();
1767
1768 init_req( TypeFunc::Control , ctrl );
1769 init_req( TypeFunc::I_O , abio );
1770 init_req( TypeFunc::Memory , mem );
1771 init_req( TypeFunc::ReturnAdr, topnode );
1772 init_req( TypeFunc::FramePtr , topnode );
1773 init_req( AllocSize , size);
1774 init_req( KlassNode , klass_node);
1775 init_req( InitialTest , initial_test);
1776 init_req( ALength , topnode);
1777 init_req( ValidLengthTest , topnode);
1778 C->add_macro_node(this);
1779 }
1780
1781 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1782 {
1783 assert(initializer != nullptr && initializer->is_object_initializer(),
1784 "unexpected initializer method");
1785 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1786 if (analyzer == nullptr) {
1787 return;
1788 }
1789
1790 // Allocation node is first parameter in its initializer
1791 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1792 _is_allocation_MemBar_redundant = true;
1793 }
1794 }
1795 Node *AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
1796 Node* mark_node = nullptr;
1797 if (UseCompactObjectHeaders) {
1798 Node* klass_node = in(AllocateNode::KlassNode);
1799 Node* proto_adr = phase->transform(AddPNode::make_off_heap(klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1800 mark_node = LoadNode::make(*phase, control, mem, proto_adr, phase->type(proto_adr)->is_ptr(), TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1801 } else {
1802 // For now only enable fast locking for non-array types
1803 mark_node = phase->MakeConX(markWord::prototype().value());
1804 }
1805 return mark_node;
1806 }
1807
1808 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1809 // CastII, if appropriate. If we are not allowed to create new nodes, and
1810 // a CastII is appropriate, return null.
1811 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1812 Node *length = in(AllocateNode::ALength);
1813 assert(length != nullptr, "length is not null");
1814
1815 const TypeInt* length_type = phase->find_int_type(length);
1816 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1817
1818 if (ary_type != nullptr && length_type != nullptr) {
1819 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
2181
2182 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2183 st->print("%s", _kind_names[_kind]);
2184 }
2185 #endif
2186
2187 //=============================================================================
2188 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2189
2190 // perform any generic optimizations first (returns 'this' or null)
2191 Node *result = SafePointNode::Ideal(phase, can_reshape);
2192 if (result != nullptr) return result;
2193 // Don't bother trying to transform a dead node
2194 if (in(0) && in(0)->is_top()) return nullptr;
2195
2196 // Now see if we can optimize away this lock. We don't actually
2197 // remove the locking here, we simply set the _eliminate flag which
2198 // prevents macro expansion from expanding the lock. Since we don't
2199 // modify the graph, the value returned from this function is the
2200 // one computed above.
2201 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2202 //
2203 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2204 //
2205 ConnectionGraph *cgr = phase->C->congraph();
2206 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2207 assert(!is_eliminated() || is_coarsened(), "sanity");
2208 // The lock could be marked eliminated by lock coarsening
2209 // code during first IGVN before EA. Replace coarsened flag
2210 // to eliminate all associated locks/unlocks.
2211 #ifdef ASSERT
2212 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2213 #endif
2214 this->set_non_esc_obj();
2215 return result;
2216 }
2217
2218 if (!phase->C->do_locks_coarsening()) {
2219 return result; // Compiling without locks coarsening
2220 }
2221 //
2382 }
2383
2384 //=============================================================================
2385 uint UnlockNode::size_of() const { return sizeof(*this); }
2386
2387 //=============================================================================
2388 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2389
2390 // perform any generic optimizations first (returns 'this' or null)
2391 Node *result = SafePointNode::Ideal(phase, can_reshape);
2392 if (result != nullptr) return result;
2393 // Don't bother trying to transform a dead node
2394 if (in(0) && in(0)->is_top()) return nullptr;
2395
2396 // Now see if we can optimize away this unlock. We don't actually
2397 // remove the unlocking here, we simply set the _eliminate flag which
2398 // prevents macro expansion from expanding the unlock. Since we don't
2399 // modify the graph, the value returned from this function is the
2400 // one computed above.
2401 // Escape state is defined after Parse phase.
2402 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2403 //
2404 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2405 //
2406 ConnectionGraph *cgr = phase->C->congraph();
2407 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2408 assert(!is_eliminated() || is_coarsened(), "sanity");
2409 // The lock could be marked eliminated by lock coarsening
2410 // code during first IGVN before EA. Replace coarsened flag
2411 // to eliminate all associated locks/unlocks.
2412 #ifdef ASSERT
2413 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2414 #endif
2415 this->set_non_esc_obj();
2416 }
2417 }
2418 return result;
2419 }
2420
2421 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2422 if (C == nullptr) {
2462 }
2463 // unrelated
2464 return false;
2465 }
2466
2467 if (dest_t->isa_aryptr()) {
2468 // arraycopy or array clone
2469 if (t_oop->isa_instptr()) {
2470 return false;
2471 }
2472 if (!t_oop->isa_aryptr()) {
2473 return true;
2474 }
2475
2476 const Type* elem = dest_t->is_aryptr()->elem();
2477 if (elem == Type::BOTTOM) {
2478 // An array but we don't know what elements are
2479 return true;
2480 }
2481
2482 dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2483 uint dest_alias = phase->C->get_alias_index(dest_t);
2484 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2485
2486 return dest_alias == t_oop_alias;
2487 }
2488
2489 return true;
2490 }
2491
2492 PowDNode::PowDNode(Compile* C, Node* base, Node* exp)
2493 : CallLeafPureNode(
2494 OptoRuntime::Math_DD_D_Type(),
2495 StubRoutines::dpow() != nullptr ? StubRoutines::dpow() : CAST_FROM_FN_PTR(address, SharedRuntime::dpow),
2496 "pow") {
2497 add_flag(Flag_is_macro);
2498 C->add_macro_node(this);
2499
2500 init_req(TypeFunc::Parms + 0, base);
2501 init_req(TypeFunc::Parms + 1, C->top()); // double slot padding
2502 init_req(TypeFunc::Parms + 2, exp);
2528 // i.e., pow(x, +/-0.0D) => 1.0
2529 if (e == 0.0) { // true for both -0.0 and +0.0
2530 result_t = TypeD::ONE;
2531 }
2532
2533 // If the second argument is NaN, then the result is NaN.
2534 // i.e., pow(x, NaN) => NaN
2535 if (g_isnan(e)) {
2536 result_t = TypeD::make(NAN);
2537 }
2538 }
2539
2540 if (result_t != nullptr) {
2541 // We can't simply return a TypeD here, it must be a tuple type to be compatible with call nodes.
2542 const Type** fields = TypeTuple::fields(2);
2543 fields[TypeFunc::Parms + 0] = result_t;
2544 fields[TypeFunc::Parms + 1] = Type::HALF;
2545 return TypeTuple::make(TypeFunc::Parms + 2, fields);
2546 }
2547
2548 return tf()->range();
2549 }
2550
2551 Node* PowDNode::Ideal(PhaseGVN* phase, bool can_reshape) {
2552 if (!can_reshape) {
2553 return nullptr; // wait for igvn
2554 }
2555
2556 PhaseIterGVN* igvn = phase->is_IterGVN();
2557 Node* base = this->base();
2558 Node* exp = this->exp();
2559
2560 const Type* t_exp = phase->type(exp);
2561 const TypeD* exp_con = t_exp->isa_double_constant();
2562
2563 // Special cases when only the exponent is known:
2564 if (exp_con != nullptr) {
2565 double e = exp_con->getd();
2566
2567 // If the second argument is 1.0, then the result is the same as the first argument.
2568 // i.e., pow(x, 1.0) => x
2615
2616 igvn->C->set_has_split_ifs(true); // Has chance for split-if optimization
2617
2618 return make_tuple_of_input_state_and_result(igvn, phi, region);
2619 }
2620 }
2621
2622 return CallLeafPureNode::Ideal(phase, can_reshape);
2623 }
2624
2625 // We can't simply have Ideal() returning a Con or MulNode since the users are still expecting a Call node, but we could
2626 // produce a tuple that follows the same pattern so users can still get control, io, memory, etc..
2627 TupleNode* PowDNode::make_tuple_of_input_state_and_result(PhaseIterGVN* phase, Node* result, Node* control) {
2628 if (control == nullptr) {
2629 control = in(TypeFunc::Control);
2630 }
2631
2632 Compile* C = phase->C;
2633 C->remove_macro_node(this);
2634 TupleNode* tuple = TupleNode::make(
2635 tf()->range(),
2636 control,
2637 in(TypeFunc::I_O),
2638 in(TypeFunc::Memory),
2639 in(TypeFunc::FramePtr),
2640 in(TypeFunc::ReturnAdr),
2641 result,
2642 C->top());
2643 return tuple;
2644 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/bcEscapeAnalyzer.hpp"
26 #include "ci/ciFlatArrayKlass.hpp"
27 #include "ci/ciSymbols.hpp"
28 #include "code/vmreg.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "compiler/oopMap.hpp"
31 #include "gc/shared/barrierSet.hpp"
32 #include "gc/shared/c2/barrierSetC2.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "opto/callGenerator.hpp"
35 #include "opto/callnode.hpp"
36 #include "opto/castnode.hpp"
37 #include "opto/convertnode.hpp"
38 #include "opto/escape.hpp"
39 #include "opto/inlinetypenode.hpp"
40 #include "opto/locknode.hpp"
41 #include "opto/machnode.hpp"
42 #include "opto/matcher.hpp"
43 #include "opto/memnode.hpp"
44 #include "opto/movenode.hpp"
45 #include "opto/parse.hpp"
46 #include "opto/regalloc.hpp"
47 #include "opto/regmask.hpp"
48 #include "opto/rootnode.hpp"
49 #include "opto/runtime.hpp"
50 #include "opto/type.hpp"
51 #include "runtime/arguments.hpp"
52 #include "runtime/sharedRuntime.hpp"
53 #include "runtime/stubRoutines.hpp"
54 #include "utilities/powerOfTwo.hpp"
55
56 // Portions of code courtesy of Clifford Click
57
58 // Optimization - Graph Style
59
60 //=============================================================================
61 uint StartNode::size_of() const { return sizeof(*this); }
62 bool StartNode::cmp( const Node &n ) const
63 { return _domain == ((StartNode&)n)._domain; }
64 const Type *StartNode::bottom_type() const { return _domain; }
65 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
66 #ifndef PRODUCT
67 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
68 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
69 #endif
70
71 //------------------------------Ideal------------------------------------------
72 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
73 return remove_dead_region(phase, can_reshape) ? this : nullptr;
74 }
75
76 //------------------------------calling_convention-----------------------------
77 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
78 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
79 }
80
81 //------------------------------Registers--------------------------------------
82 const RegMask &StartNode::in_RegMask(uint) const {
83 return RegMask::EMPTY;
84 }
85
86 //------------------------------match------------------------------------------
87 // Construct projections for incoming parameters, and their RegMask info
88 Node *StartNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
89 switch (proj->_con) {
90 case TypeFunc::Control:
91 case TypeFunc::I_O:
92 case TypeFunc::Memory:
93 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
94 case TypeFunc::FramePtr:
95 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
96 case TypeFunc::ReturnAdr:
97 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
98 case TypeFunc::Parms:
99 default: {
100 uint parm_num = proj->_con - TypeFunc::Parms;
101 const Type *t = _domain->field_at(proj->_con);
102 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
103 return new ConNode(Type::TOP);
104 uint ideal_reg = t->ideal_reg();
105 RegMask &rm = match->_calling_convention_mask[parm_num];
106 return new MachProjNode(this,proj->_con,rm,ideal_reg);
107 }
108 }
109 return nullptr;
110 }
111
112 //=============================================================================
113 const char * const ParmNode::names[TypeFunc::Parms+1] = {
114 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
115 };
116
117 #ifndef PRODUCT
118 void ParmNode::dump_spec(outputStream *st) const {
119 if( _con < TypeFunc::Parms ) {
120 st->print("%s", names[_con]);
121 } else {
122 st->print("Parm%d: ",_con-TypeFunc::Parms);
123 // Verbose and WizardMode dump bottom_type for all nodes
124 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
125 }
126 }
127
128 void ParmNode::dump_compact_spec(outputStream *st) const {
129 if (_con < TypeFunc::Parms) {
130 st->print("%s", names[_con]);
131 } else {
479 if (cik->is_instance_klass()) {
480 cik->print_name_on(st);
481 iklass = cik->as_instance_klass();
482 } else if (cik->is_type_array_klass()) {
483 cik->as_array_klass()->base_element_type()->print_name_on(st);
484 st->print("[%d]", spobj->n_fields());
485 } else if (cik->is_obj_array_klass()) {
486 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
487 if (cie->is_instance_klass()) {
488 cie->print_name_on(st);
489 } else if (cie->is_type_array_klass()) {
490 cie->as_array_klass()->base_element_type()->print_name_on(st);
491 } else {
492 ShouldNotReachHere();
493 }
494 st->print("[%d]", spobj->n_fields());
495 int ndim = cik->as_array_klass()->dimension() - 1;
496 while (ndim-- > 0) {
497 st->print("[]");
498 }
499 } else {
500 assert(false, "unexpected type %s", cik->name()->as_utf8());
501 }
502 st->print("={");
503 uint nf = spobj->n_fields();
504 if (nf > 0) {
505 uint first_ind = spobj->first_index(mcall->jvms());
506 if (iklass != nullptr && iklass->is_inlinetype()) {
507 Node* null_marker = mcall->in(first_ind++);
508 if (!null_marker->is_top()) {
509 st->print(" [null marker");
510 format_helper(regalloc, st, null_marker, ":", -1, nullptr);
511 }
512 }
513 Node* fld_node = mcall->in(first_ind);
514 if (iklass != nullptr) {
515 st->print(" [");
516 iklass->nonstatic_field_at(0)->print_name_on(st);
517 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
518 } else {
519 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
520 }
521 for (uint j = 1; j < nf; j++) {
522 fld_node = mcall->in(first_ind+j);
523 if (iklass != nullptr) {
524 st->print(", [");
525 iklass->nonstatic_field_at(j)->print_name_on(st);
526 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
527 } else {
528 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
529 }
530 }
531 }
532 st->print(" }");
533 }
534 }
535 st->cr();
536 if (caller() != nullptr) caller()->format(regalloc, n, st);
537 }
538
539
540 void JVMState::dump_spec(outputStream *st) const {
541 if (_method != nullptr) {
542 bool printed = false;
543 if (!Verbose) {
544 // The JVMS dumps make really, really long lines.
545 // Take out the most boring parts, which are the package prefixes.
740 tf()->dump_on(st);
741 }
742 if (_cnt != COUNT_UNKNOWN) {
743 st->print(" C=%f", _cnt);
744 }
745 const Node* const klass_node = in(KlassNode);
746 if (klass_node != nullptr) {
747 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
748
749 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
750 st->print(" allocationKlass:");
751 klass_ptr->exact_klass()->print_name_on(st);
752 }
753 }
754 if (jvms() != nullptr) {
755 jvms()->dump_spec(st);
756 }
757 }
758 #endif
759
760 const Type *CallNode::bottom_type() const { return tf()->range_cc(); }
761 const Type* CallNode::Value(PhaseGVN* phase) const {
762 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
763 return Type::TOP;
764 }
765 return tf()->range_cc();
766 }
767
768 //------------------------------calling_convention-----------------------------
769 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
770 if (_entry_point == StubRoutines::store_inline_type_fields_to_buf()) {
771 // The call to that stub is a special case: its inputs are
772 // multiple values returned from a call and so it should follow
773 // the return convention.
774 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
775 return;
776 }
777 // Use the standard compiler calling convention
778 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
779 }
780
781
782 //------------------------------match------------------------------------------
783 // Construct projections for control, I/O, memory-fields, ..., and
784 // return result(s) along with their RegMask info
785 Node *CallNode::match(const ProjNode *proj, const Matcher *match, const RegMask* mask) {
786 uint con = proj->_con;
787 const TypeTuple* range_cc = tf()->range_cc();
788 if (con >= TypeFunc::Parms) {
789 if (tf()->returns_inline_type_as_fields()) {
790 // The call returns multiple values (inline type fields): we
791 // create one projection per returned value.
792 assert(con <= TypeFunc::Parms+1 || InlineTypeReturnedAsFields, "only for multi value return");
793 uint ideal_reg = range_cc->field_at(con)->ideal_reg();
794 return new MachProjNode(this, con, mask[con-TypeFunc::Parms], ideal_reg);
795 } else {
796 if (con == TypeFunc::Parms) {
797 uint ideal_reg = range_cc->field_at(TypeFunc::Parms)->ideal_reg();
798 OptoRegPair regs = Opcode() == Op_CallLeafVector
799 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
800 : match->c_return_value(ideal_reg);
801 RegMask rm = RegMask(regs.first());
802
803 if (Opcode() == Op_CallLeafVector) {
804 // If the return is in vector, compute appropriate regmask taking into account the whole range
805 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
806 if(OptoReg::is_valid(regs.second())) {
807 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
808 rm.insert(r);
809 }
810 }
811 }
812 }
813
814 if (OptoReg::is_valid(regs.second())) {
815 rm.insert(regs.second());
816 }
817 return new MachProjNode(this,con,rm,ideal_reg);
818 } else {
819 assert(con == TypeFunc::Parms+1, "only one return value");
820 assert(range_cc->field_at(TypeFunc::Parms+1) == Type::HALF, "");
821 return new MachProjNode(this,con, RegMask::EMPTY, (uint)OptoReg::Bad);
822 }
823 }
824 }
825
826 switch (con) {
827 case TypeFunc::Control:
828 case TypeFunc::I_O:
829 case TypeFunc::Memory:
830 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
831
832 case TypeFunc::ReturnAdr:
833 case TypeFunc::FramePtr:
834 default:
835 ShouldNotReachHere();
836 }
837 return nullptr;
838 }
839
840 // Do we Match on this edge index or not? Match no edges
841 uint CallNode::match_edge(uint idx) const {
842 return 0;
843 }
844
845 //
846 // Determine whether the call could modify the field of the specified
847 // instance at the specified offset.
848 //
849 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) const {
850 assert((t_oop != nullptr), "sanity");
851 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
852 const TypeTuple* args = _tf->domain_sig();
853 Node* dest = nullptr;
854 // Stubs that can be called once an ArrayCopyNode is expanded have
855 // different signatures. Look for the second pointer argument,
856 // that is the destination of the copy.
857 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
858 if (args->field_at(i)->isa_ptr()) {
859 j++;
860 if (j == 2) {
861 dest = in(i);
862 break;
863 }
864 }
865 }
866 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
867 if (phase->type(dest)->isa_rawptr()) {
868 // may happen for an arraycopy that initializes a newly allocated object. Conservatively return true;
869 return true;
870 }
871 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
872 return true;
885 Node* proj = proj_out_or_null(TypeFunc::Parms);
886 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
887 return false;
888 }
889 }
890 if (is_CallJava() && as_CallJava()->method() != nullptr) {
891 ciMethod* meth = as_CallJava()->method();
892 if (meth->is_getter()) {
893 return false;
894 }
895 // May modify (by reflection) if an boxing object is passed
896 // as argument or returned.
897 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
898 if (proj != nullptr) {
899 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
900 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
901 (inst_t->instance_klass() == boxing_klass))) {
902 return true;
903 }
904 }
905 const TypeTuple* d = tf()->domain_cc();
906 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
907 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
908 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
909 (inst_t->instance_klass() == boxing_klass))) {
910 return true;
911 }
912 }
913 return false;
914 }
915 }
916 return true;
917 }
918
919 // Does this call have a direct reference to n other than debug information?
920 bool CallNode::has_non_debug_use(const Node* n) {
921 const TypeTuple* d = tf()->domain_cc();
922 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
923 if (in(i) == n) {
924 return true;
925 }
926 }
927 return false;
928 }
929
930 bool CallNode::has_debug_use(const Node* n) const {
931 if (jvms() != nullptr) {
932 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
933 if (in(i) == n) {
934 return true;
935 }
936 }
937 }
938 return false;
939 }
940
941 // Returns the unique CheckCastPP of a call
942 // or 'this' if there are several CheckCastPP or unexpected uses
943 // or returns null if there is no one.
944 Node *CallNode::result_cast() {
945 Node *cast = nullptr;
946
947 Node *p = proj_out_or_null(TypeFunc::Parms);
948 if (p == nullptr)
949 return nullptr;
950
951 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
952 Node *use = p->fast_out(i);
953 if (use->is_CheckCastPP()) {
954 if (cast != nullptr) {
955 return this; // more than 1 CheckCastPP
956 }
957 cast = use;
958 } else if (!use->is_Initialize() &&
959 !use->is_AddP() &&
960 use->Opcode() != Op_MemBarStoreStore) {
961 // Expected uses are restricted to a CheckCastPP, an Initialize
962 // node, a MemBarStoreStore (clone) and AddP nodes. If we
963 // encounter any other use (a Phi node can be seen in rare
964 // cases) return this to prevent incorrect optimizations.
965 return this;
966 }
967 }
968 return cast;
969 }
970
971
972 CallProjections* CallNode::extract_projections(bool separate_io_proj, bool do_asserts, bool allow_handlers) const {
973 uint max_res = TypeFunc::Parms-1;
974 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
975 ProjNode *pn = fast_out(i)->as_Proj();
976 max_res = MAX2(max_res, pn->_con);
977 }
978
979 assert(max_res < _tf->range_cc()->cnt(), "result out of bounds");
980
981 uint projs_size = sizeof(CallProjections);
982 if (max_res > TypeFunc::Parms) {
983 projs_size += (max_res-TypeFunc::Parms)*sizeof(Node*);
984 }
985 char* projs_storage = resource_allocate_bytes(projs_size);
986 CallProjections* projs = new(projs_storage)CallProjections(max_res - TypeFunc::Parms + 1);
987
988 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
989 ProjNode *pn = fast_out(i)->as_Proj();
990 if (pn->outcnt() == 0) continue;
991 switch (pn->_con) {
992 case TypeFunc::Control:
993 {
994 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
995 projs->fallthrough_proj = pn;
996 const Node* cn = pn->unique_ctrl_out_or_null();
997 if (cn != nullptr && cn->is_Catch()) {
998 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
999 CatchProjNode* cpn = cn->fast_out(k)->as_CatchProj();
1000 assert(allow_handlers || !cpn->is_handler_proj(), "not allowed");
1001 if (cpn->_con == CatchProjNode::fall_through_index) {
1002 assert(cpn->handler_bci() == CatchProjNode::no_handler_bci, "");
1003 projs->fallthrough_catchproj = cpn;
1004 } else if (!cpn->is_handler_proj()) {
1005 projs->catchall_catchproj = cpn;
1006 }
1016 }
1017 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
1018 Node* e = pn->out(j);
1019 if (e->Opcode() == Op_CreateEx && e->outcnt() > 0) {
1020 CatchProjNode* ecpn = e->in(0)->isa_CatchProj();
1021 assert(allow_handlers || ecpn == nullptr || !ecpn->is_handler_proj(), "not allowed");
1022 if (ecpn != nullptr && ecpn->_con != CatchProjNode::fall_through_index && !ecpn->is_handler_proj()) {
1023 assert(projs->exobj == nullptr, "only one");
1024 projs->exobj = e;
1025 }
1026 }
1027 }
1028 break;
1029 case TypeFunc::Memory:
1030 if (pn->_is_io_use)
1031 projs->catchall_memproj = pn;
1032 else
1033 projs->fallthrough_memproj = pn;
1034 break;
1035 case TypeFunc::Parms:
1036 projs->resproj[0] = pn;
1037 break;
1038 default:
1039 assert(pn->_con <= max_res, "unexpected projection from allocation node.");
1040 projs->resproj[pn->_con-TypeFunc::Parms] = pn;
1041 break;
1042 }
1043 }
1044
1045 // The resproj may not exist because the result could be ignored
1046 // and the exception object may not exist if an exception handler
1047 // swallows the exception but all the other must exist and be found.
1048 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1049 assert(!do_asserts || projs->fallthrough_proj != nullptr, "must be found");
1050 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1051 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1052 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1053 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1054 if (separate_io_proj) {
1055 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1056 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1057 }
1058 return projs;
1059 }
1060
1061 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1062 #ifdef ASSERT
1063 // Validate attached generator
1064 CallGenerator* cg = generator();
1065 if (cg != nullptr) {
1066 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1067 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1068 }
1069 #endif // ASSERT
1070 return SafePointNode::Ideal(phase, can_reshape);
1071 }
1072
1073 bool CallNode::is_call_to_arraycopystub() const {
1074 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1075 return true;
1076 }
1077 return false;
1078 }
1079
1080 bool CallNode::is_call_to_multianewarray_stub() const {
1081 if (_name != nullptr &&
1082 strstr(_name, "multianewarray") != nullptr &&
1083 strstr(_name, "C2 runtime") != nullptr) {
1084 return true;
1085 }
1086 return false;
1087 }
1088
1089 //=============================================================================
1090 uint CallJavaNode::size_of() const { return sizeof(*this); }
1091 bool CallJavaNode::cmp( const Node &n ) const {
1092 CallJavaNode &call = (CallJavaNode&)n;
1093 return CallNode::cmp(call) && _method == call._method &&
1094 _override_symbolic_info == call._override_symbolic_info;
1095 }
1096
1097 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1098 // Copy debug information and adjust JVMState information
1099 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain_sig()->cnt() : (uint)TypeFunc::Parms+1;
1100 uint new_dbg_start = tf()->domain_sig()->cnt();
1101 int jvms_adj = new_dbg_start - old_dbg_start;
1102 assert (new_dbg_start == req(), "argument count mismatch");
1103 Compile* C = phase->C;
1104
1105 // SafePointScalarObject node could be referenced several times in debug info.
1106 // Use Dict to record cloned nodes.
1107 Dict* sosn_map = new Dict(cmpkey,hashkey);
1108 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1109 Node* old_in = sfpt->in(i);
1110 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1111 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1112 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1113 bool new_node;
1114 Node* new_in = old_sosn->clone(sosn_map, new_node);
1115 if (new_node) { // New node?
1116 new_in->set_req(0, C->root()); // reset control edge
1117 new_in = phase->transform(new_in); // Register new node.
1118 }
1119 old_in = new_in;
1120 }
1121 add_req(old_in);
1122 }
1123
1124 // JVMS may be shared so clone it before we modify it
1125 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1126 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1127 jvms->set_map(this);
1128 jvms->set_locoff(jvms->locoff()+jvms_adj);
1129 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1130 jvms->set_monoff(jvms->monoff()+jvms_adj);
1131 jvms->set_scloff(jvms->scloff()+jvms_adj);
1132 jvms->set_endoff(jvms->endoff()+jvms_adj);
1133 }
1134 }
1135
1136 #ifdef ASSERT
1137 bool CallJavaNode::validate_symbolic_info() const {
1138 if (method() == nullptr) {
1139 return true; // call into runtime or uncommon trap
1140 }
1141 Bytecodes::Code bc = jvms()->method()->java_code_at_bci(jvms()->bci());
1142 if (Arguments::is_valhalla_enabled() && (bc == Bytecodes::_if_acmpeq || bc == Bytecodes::_if_acmpne)) {
1143 return true;
1144 }
1145 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1146 ciMethod* callee = method();
1147 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1148 assert(override_symbolic_info(), "should be set");
1149 }
1150 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1151 return true;
1152 }
1153 #endif
1154
1155 #ifndef PRODUCT
1156 void CallJavaNode::dump_spec(outputStream* st) const {
1157 if( _method ) _method->print_short_name(st);
1158 CallNode::dump_spec(st);
1159 }
1160
1161 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1162 if (_method) {
1163 _method->print_short_name(st);
1164 } else {
1167 }
1168 #endif
1169
1170 void CallJavaNode::register_for_late_inline() {
1171 if (generator() != nullptr) {
1172 Compile::current()->prepend_late_inline(generator());
1173 set_generator(nullptr);
1174 } else {
1175 assert(false, "repeated inline attempt");
1176 }
1177 }
1178
1179 //=============================================================================
1180 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1181 bool CallStaticJavaNode::cmp( const Node &n ) const {
1182 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1183 return CallJavaNode::cmp(call);
1184 }
1185
1186 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1187 if (can_reshape && uncommon_trap_request() != 0) {
1188 PhaseIterGVN* igvn = phase->is_IterGVN();
1189 if (remove_unknown_flat_array_load(igvn, control(), memory(), in(TypeFunc::Parms))) {
1190 if (!control()->is_Region()) {
1191 igvn->replace_input_of(this, 0, phase->C->top());
1192 }
1193 return this;
1194 }
1195 }
1196
1197 // Try to replace the runtime call to the substitutability test emitted by acmp if we can reason
1198 // about the operands
1199 if (can_reshape && !control()->is_top() && method() != nullptr &&
1200 method()->holder() == phase->C->env()->ValueObjectMethods_klass() &&
1201 method()->name() == ciSymbols::isSubstitutable_name()) {
1202 Node* res = replace_is_substitutable(phase->is_IterGVN());
1203 if (res != nullptr) {
1204 return res;
1205 }
1206 }
1207
1208 CallGenerator* cg = generator();
1209 if (can_reshape && cg != nullptr) {
1210 if (cg->is_mh_late_inline()) {
1211 assert(IncrementalInlineMH, "required");
1212 assert(cg->call_node() == this, "mismatch");
1213 assert(cg->method()->is_method_handle_intrinsic(), "required");
1214
1215 // Check whether this MH handle call becomes a candidate for inlining.
1216 ciMethod* callee = cg->method();
1217 vmIntrinsics::ID iid = callee->intrinsic_id();
1218 if (iid == vmIntrinsics::_invokeBasic) {
1219 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1220 register_for_late_inline();
1221 }
1222 } else if (iid == vmIntrinsics::_linkToNative) {
1223 // never retry
1224 } else {
1225 assert(callee->has_member_arg(), "wrong type of call?");
1226 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1227 register_for_late_inline();
1248
1249 //----------------------------uncommon_trap_request----------------------------
1250 // If this is an uncommon trap, return the request code, else zero.
1251 int CallStaticJavaNode::uncommon_trap_request() const {
1252 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1253 }
1254 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1255 #ifndef PRODUCT
1256 if (!(call->req() > TypeFunc::Parms &&
1257 call->in(TypeFunc::Parms) != nullptr &&
1258 call->in(TypeFunc::Parms)->is_Con() &&
1259 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1260 assert(in_dump() != 0, "OK if dumping");
1261 tty->print("[bad uncommon trap]");
1262 return 0;
1263 }
1264 #endif
1265 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1266 }
1267
1268 // Split if can cause the flat array branch of an array load with unknown type (see
1269 // Parse::array_load) to end in an uncommon trap. In that case, the call to
1270 // 'load_unknown_inline' is useless. Replace it with an uncommon trap with the same JVMState.
1271 bool CallStaticJavaNode::remove_unknown_flat_array_load(PhaseIterGVN* igvn, Node* ctl, Node* mem, Node* unc_arg) {
1272 if (ctl == nullptr || ctl->is_top() || mem == nullptr || mem->is_top() || !mem->is_MergeMem()) {
1273 return false;
1274 }
1275 if (ctl->is_Region()) {
1276 bool res = false;
1277 for (uint i = 1; i < ctl->req(); i++) {
1278 MergeMemNode* mm = mem->clone()->as_MergeMem();
1279 for (MergeMemStream mms(mm); mms.next_non_empty(); ) {
1280 Node* m = mms.memory();
1281 if (m->is_Phi() && m->in(0) == ctl) {
1282 mms.set_memory(m->in(i));
1283 }
1284 }
1285 if (remove_unknown_flat_array_load(igvn, ctl->in(i), mm, unc_arg)) {
1286 res = true;
1287 if (!ctl->in(i)->is_Region()) {
1288 igvn->replace_input_of(ctl, i, igvn->C->top());
1289 }
1290 }
1291 igvn->remove_dead_node(mm, PhaseIterGVN::NodeOrigin::Speculative);
1292 }
1293 return res;
1294 }
1295 // Verify the control flow is ok
1296 Node* call = ctl;
1297 MemBarNode* membar = nullptr;
1298 for (;;) {
1299 if (call == nullptr || call->is_top()) {
1300 return false;
1301 }
1302 if (call->is_Proj() || call->is_Catch() || call->is_MemBar()) {
1303 call = call->in(0);
1304 } else if (call->Opcode() == Op_CallStaticJava && !call->in(0)->is_top() &&
1305 call->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1306 // If there is no explicit flat array accesses in the compilation unit, there would be no
1307 // membar here
1308 if (call->in(0)->is_Proj() && call->in(0)->in(0)->is_MemBar()) {
1309 membar = call->in(0)->in(0)->as_MemBar();
1310 }
1311 break;
1312 } else {
1313 return false;
1314 }
1315 }
1316
1317 JVMState* jvms = call->jvms();
1318 if (igvn->C->too_many_traps(jvms->method(), jvms->bci(), Deoptimization::trap_request_reason(uncommon_trap_request()))) {
1319 return false;
1320 }
1321
1322 Node* call_mem = call->in(TypeFunc::Memory);
1323 if (call_mem == nullptr || call_mem->is_top()) {
1324 return false;
1325 }
1326 if (!call_mem->is_MergeMem()) {
1327 call_mem = MergeMemNode::make(call_mem);
1328 igvn->register_new_node_with_optimizer(call_mem);
1329 }
1330
1331 // Verify that there's no unexpected side effect
1332 for (MergeMemStream mms2(mem->as_MergeMem(), call_mem->as_MergeMem()); mms2.next_non_empty2(); ) {
1333 Node* m1 = mms2.is_empty() ? mms2.base_memory() : mms2.memory();
1334 Node* m2 = mms2.memory2();
1335
1336 for (uint i = 0; i < 100; i++) {
1337 if (m1 == m2) {
1338 break;
1339 } else if (m1->is_Proj()) {
1340 m1 = m1->in(0);
1341 } else if (m1->is_MemBar()) {
1342 m1 = m1->in(TypeFunc::Memory);
1343 } else if (m1->Opcode() == Op_CallStaticJava &&
1344 m1->as_Call()->entry_point() == OptoRuntime::load_unknown_inline_Java()) {
1345 if (m1 != call) {
1346 if (call_mem->outcnt() == 0) {
1347 igvn->remove_dead_node(call_mem, PhaseIterGVN::NodeOrigin::Speculative);
1348 }
1349 return false;
1350 }
1351 break;
1352 } else if (m1->is_MergeMem()) {
1353 MergeMemNode* mm = m1->as_MergeMem();
1354 int idx = mms2.alias_idx();
1355 if (idx == Compile::AliasIdxBot) {
1356 m1 = mm->base_memory();
1357 } else {
1358 m1 = mm->memory_at(idx);
1359 }
1360 } else {
1361 if (call_mem->outcnt() == 0) {
1362 igvn->remove_dead_node(call_mem, PhaseIterGVN::NodeOrigin::Speculative);
1363 }
1364 return false;
1365 }
1366 }
1367 }
1368 if (call_mem->outcnt() == 0) {
1369 igvn->remove_dead_node(call_mem, PhaseIterGVN::NodeOrigin::Speculative);
1370 }
1371
1372 // Remove membar preceding the call
1373 if (membar != nullptr) {
1374 membar->remove(igvn);
1375 }
1376
1377 address call_addr = OptoRuntime::uncommon_trap_blob()->entry_point();
1378 CallNode* unc = new CallStaticJavaNode(OptoRuntime::uncommon_trap_Type(), call_addr, "uncommon_trap", nullptr);
1379 unc->init_req(TypeFunc::Control, call->in(0));
1380 unc->init_req(TypeFunc::I_O, call->in(TypeFunc::I_O));
1381 unc->init_req(TypeFunc::Memory, call->in(TypeFunc::Memory));
1382 unc->init_req(TypeFunc::FramePtr, call->in(TypeFunc::FramePtr));
1383 unc->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
1384 unc->init_req(TypeFunc::Parms+0, unc_arg);
1385 unc->set_cnt(PROB_UNLIKELY_MAG(4));
1386 unc->copy_call_debug_info(igvn, call->as_CallStaticJava());
1387
1388 // Replace the call with an uncommon trap
1389 igvn->replace_input_of(call, 0, igvn->C->top());
1390
1391 igvn->register_new_node_with_optimizer(unc);
1392
1393 Node* ctrl = igvn->transform(new ProjNode(unc, TypeFunc::Control));
1394 Node* halt = igvn->transform(new HaltNode(ctrl, call->in(TypeFunc::FramePtr), "uncommon trap returned which should never happen"));
1395 igvn->add_input_to(igvn->C->root(), halt);
1396
1397 return true;
1398 }
1399
1400 // Try to replace a runtime call to the substitutability test by either a simple pointer comparison
1401 // if either operand is not a value object, or comparing their fields if either operand is an
1402 // object of a known value type
1403 Node* CallStaticJavaNode::replace_is_substitutable(PhaseIterGVN* igvn) {
1404 Node* left = in(TypeFunc::Parms);
1405 Node* right = in(TypeFunc::Parms + 1);
1406 if (!InlineTypeNode::can_emit_substitutability_check(left, right)) {
1407 return nullptr;
1408 }
1409
1410 // Delay IGVN during macro expansion
1411 assert(!igvn->delay_transform(), "must not delay during Ideal");
1412 igvn->set_delay_transform(true);
1413 GraphKit kit(this, *igvn);
1414
1415 Node* replace = InlineTypeNode::emit_substitutability_check(&kit, left, right);
1416 igvn->set_delay_transform(false);
1417 assert(replace != nullptr, "must succeed");
1418
1419 if (UseAcmpFastPath) {
1420 // Sabotage the fast acmp path
1421 IfNode* fast_path_if = Parse::acmp_fast_path_if_from_substitutable_call(igvn, this);
1422 if (fast_path_if != nullptr) {
1423 fast_path_if->set_req(1, igvn->intcon(1));
1424 igvn->_worklist.push(fast_path_if);
1425 }
1426 }
1427
1428 // Kill exception projections and return a tuple that will replace the call
1429 CallProjections* projs = extract_projections(false /*separate_io_proj*/);
1430 if (projs->fallthrough_catchproj != nullptr) {
1431 igvn->replace_node(projs->fallthrough_catchproj, kit.control());
1432 }
1433 if (projs->catchall_memproj != nullptr) {
1434 igvn->replace_node(projs->catchall_memproj, igvn->C->top());
1435 }
1436 if (projs->catchall_ioproj != nullptr) {
1437 igvn->replace_node(projs->catchall_ioproj, igvn->C->top());
1438 }
1439 if (projs->catchall_catchproj != nullptr) {
1440 igvn->replace_node(projs->catchall_catchproj, igvn->C->top());
1441 }
1442 Node* new_mem = kit.reset_memory();
1443 assert(in(TypeFunc::Memory) == new_mem, "must not modify memory");
1444 return TupleNode::make(tf()->range_cc(), igvn->C->top(), kit.i_o(), new_mem, kit.frameptr(), kit.returnadr(), replace);
1445 }
1446
1447 #ifndef PRODUCT
1448 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1449 st->print("# Static ");
1450 if (_name != nullptr) {
1451 st->print("%s", _name);
1452 int trap_req = uncommon_trap_request();
1453 if (trap_req != 0) {
1454 char buf[100];
1455 st->print("(%s)",
1456 Deoptimization::format_trap_request(buf, sizeof(buf),
1457 trap_req));
1458 }
1459 st->print(" ");
1460 }
1461 CallJavaNode::dump_spec(st);
1462 }
1463
1464 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1465 if (_method) {
1466 _method->print_short_name(st);
1542 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1543 bool CallRuntimeNode::cmp( const Node &n ) const {
1544 CallRuntimeNode &call = (CallRuntimeNode&)n;
1545 return CallNode::cmp(call) && !strcmp(_name,call._name);
1546 }
1547 #ifndef PRODUCT
1548 void CallRuntimeNode::dump_spec(outputStream *st) const {
1549 st->print("# ");
1550 st->print("%s", _name);
1551 CallNode::dump_spec(st);
1552 }
1553 #endif
1554 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1555 bool CallLeafVectorNode::cmp( const Node &n ) const {
1556 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1557 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1558 }
1559
1560 //------------------------------calling_convention-----------------------------
1561 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1562 if (_entry_point == nullptr) {
1563 // The call to that stub is a special case: its inputs are
1564 // multiple values returned from a call and so it should follow
1565 // the return convention.
1566 SharedRuntime::java_return_convention(sig_bt, parm_regs, argcnt);
1567 return;
1568 }
1569 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1570 }
1571
1572 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1573 #ifdef ASSERT
1574 assert(tf()->range_sig()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1575 "return vector size must match");
1576 const TypeTuple* d = tf()->domain_sig();
1577 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1578 Node* arg = in(i);
1579 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1580 "vector argument size must match");
1581 }
1582 #endif
1583
1584 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1585 }
1586
1587 //=============================================================================
1588 //------------------------------calling_convention-----------------------------
1589
1590
1591 //=============================================================================
1592 bool CallLeafPureNode::is_unused() const {
1593 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1594 }
1595
1596 bool CallLeafPureNode::is_dead() const {
1597 return proj_out_or_null(TypeFunc::Control) == nullptr;
1598 }
1599
1600 /* We make a tuple of the global input state + TOP for the output values.
1601 * We use this to delete a pure function that is not used: by replacing the call with
1602 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1603 * pure call, so jumping over it, and effectively, removing the call from the graph.
1604 * This avoids doing the graph surgery manually, but leaves that to IGVN
1605 * that is specialized for doing that right. We need also tuple components for output
1606 * values of the function to respect the return arity, and in case there is a projection
1607 * that would pick an output (which shouldn't happen at the moment).
1608 */
1609 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1610 // Transparently propagate input state but parameters
1611 TupleNode* tuple = TupleNode::make(
1612 tf()->range_cc(),
1613 in(TypeFunc::Control),
1614 in(TypeFunc::I_O),
1615 in(TypeFunc::Memory),
1616 in(TypeFunc::FramePtr),
1617 in(TypeFunc::ReturnAdr));
1618
1619 // And add TOPs for the return values
1620 for (uint i = TypeFunc::Parms; i < tf()->range_cc()->cnt(); i++) {
1621 tuple->set_req(i, C->top());
1622 }
1623
1624 return tuple;
1625 }
1626
1627 CallLeafPureNode* CallLeafPureNode::inline_call_leaf_pure_node(Node* control) const {
1628 Node* top = Compile::current()->top();
1629 if (control == nullptr) {
1630 control = in(TypeFunc::Control);
1631 }
1632
1633 CallLeafPureNode* call = new CallLeafPureNode(tf(), entry_point(), _name);
1634 call->init_req(TypeFunc::Control, control);
1635 call->init_req(TypeFunc::I_O, top);
1636 call->init_req(TypeFunc::Memory, top);
1637 call->init_req(TypeFunc::ReturnAdr, top);
1638 call->init_req(TypeFunc::FramePtr, top);
1639 for (unsigned int i = 0; i < tf()->domain_cc()->cnt() - TypeFunc::Parms; i++) {
1640 call->init_req(TypeFunc::Parms + i, in(TypeFunc::Parms + i));
1641 }
1642
1643 return call;
1644 }
1645
1646 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1647 if (is_dead()) {
1648 return nullptr;
1649 }
1650
1651 // We need to wait until IGVN because during parsing, usages might still be missing
1652 // and we would remove the call immediately.
1653 if (can_reshape && is_unused()) {
1654 // The result is not used. We remove the call by replacing it with a tuple, that
1655 // is later disintegrated by the projections.
1656 return make_tuple_of_input_state_and_top_return_values(phase->C);
1657 }
1658
1659 return CallRuntimeNode::Ideal(phase, can_reshape);
1660 }
1661
1662 #ifndef PRODUCT
1663 void CallLeafNode::dump_spec(outputStream *st) const {
1664 st->print("# ");
1665 st->print("%s", _name);
1666 CallNode::dump_spec(st);
1667 }
1668 #endif
1669
1670 uint CallLeafNoFPNode::match_edge(uint idx) const {
1671 // Null entry point is a special case for which the target is in a
1672 // register. Need to match that edge.
1673 return entry_point() == nullptr && idx == TypeFunc::Parms;
1674 }
1675
1676 //=============================================================================
1677
1678 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1679 assert(verify_jvms(jvms), "jvms must match");
1680 int loc = jvms->locoff() + idx;
1681 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1682 // If current local idx is top then local idx - 1 could
1683 // be a long/double that needs to be killed since top could
1684 // represent the 2nd half of the long/double.
1685 uint ideal = in(loc -1)->ideal_reg();
1686 if (ideal == Op_RegD || ideal == Op_RegL) {
1687 // set other (low index) half to top
1688 set_req(loc - 1, in(loc));
1689 }
1690 }
1691 set_req(loc, c);
1692 }
1693
1694 uint SafePointNode::size_of() const { return sizeof(*this); }
1695 bool SafePointNode::cmp( const Node &n ) const {
1706 }
1707 }
1708
1709
1710 //----------------------------next_exception-----------------------------------
1711 SafePointNode* SafePointNode::next_exception() const {
1712 if (len() == req()) {
1713 return nullptr;
1714 } else {
1715 Node* n = in(req());
1716 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1717 return (SafePointNode*) n;
1718 }
1719 }
1720
1721
1722 //------------------------------Ideal------------------------------------------
1723 // Skip over any collapsed Regions
1724 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1725 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1726 if (remove_dead_region(phase, can_reshape)) {
1727 return this;
1728 }
1729 // Scalarize inline types in safepoint debug info.
1730 // Delay this until all inlining is over to avoid getting inconsistent debug info.
1731 if (phase->C->scalarize_in_safepoints() && can_reshape && jvms() != nullptr) {
1732 for (uint i = jvms()->debug_start(); i < jvms()->debug_end(); i++) {
1733 Node* n = in(i)->uncast();
1734 if (n->is_InlineType()) {
1735 n->as_InlineType()->make_scalar_in_safepoints(phase->is_IterGVN());
1736 }
1737 }
1738 }
1739 return nullptr;
1740 }
1741
1742 //------------------------------Identity---------------------------------------
1743 // Remove obviously duplicate safepoints
1744 Node* SafePointNode::Identity(PhaseGVN* phase) {
1745
1746 // If you have back to back safepoints, remove one
1747 if (in(TypeFunc::Control)->is_SafePoint()) {
1748 Node* out_c = unique_ctrl_out_or_null();
1749 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1750 // outer loop's safepoint could confuse removal of the outer loop.
1751 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1752 return in(TypeFunc::Control);
1753 }
1754 }
1755
1756 // Transforming long counted loops requires a safepoint node. Do not
1757 // eliminate a safepoint until loop opts are over.
1758 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1759 Node *n0 = in(0)->in(0);
1900
1901 while (!non_debug_edges.is_empty()) {
1902 Node* non_debug_edge = non_debug_edges.pop();
1903 add_req(non_debug_edge);
1904 }
1905
1906 assert(non_debug_edges.is_empty(), "edges not processed");
1907 DEBUG_ONLY(non_debug_edges._state = NodeEdgeTempStorage::state_processed);
1908 }
1909
1910 //============== SafePointScalarObjectNode ==============
1911
1912 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1913 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1914 _first_index(first_index),
1915 _depth(depth),
1916 _n_fields(n_fields),
1917 _alloc(alloc)
1918 {
1919 #ifdef ASSERT
1920 if (alloc != nullptr && !alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1921 alloc->dump();
1922 assert(false, "unexpected call node");
1923 }
1924 #endif
1925 init_class_id(Class_SafePointScalarObject);
1926 }
1927
1928 // Do not allow value-numbering for SafePointScalarObject node.
1929 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1930 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1931 return (&n == this); // Always fail except on self
1932 }
1933
1934 uint SafePointScalarObjectNode::ideal_reg() const {
1935 return 0; // No matching to machine instruction
1936 }
1937
1938 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1939 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1940 }
2005 new_node = false;
2006 return (SafePointScalarMergeNode*)cached;
2007 }
2008 new_node = true;
2009 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
2010 sosn_map->Insert((void*)this, (void*)res);
2011 return res;
2012 }
2013
2014 #ifndef PRODUCT
2015 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
2016 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
2017 }
2018 #endif
2019
2020 //=============================================================================
2021 uint AllocateNode::size_of() const { return sizeof(*this); }
2022
2023 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
2024 Node *ctrl, Node *mem, Node *abio,
2025 Node *size, Node *klass_node,
2026 Node* initial_test,
2027 InlineTypeNode* inline_type_node)
2028 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
2029 {
2030 init_class_id(Class_Allocate);
2031 init_flags(Flag_is_macro);
2032 _is_scalar_replaceable = false;
2033 _is_non_escaping = false;
2034 _is_allocation_MemBar_redundant = false;
2035 Node *topnode = C->top();
2036
2037 init_req( TypeFunc::Control , ctrl );
2038 init_req( TypeFunc::I_O , abio );
2039 init_req( TypeFunc::Memory , mem );
2040 init_req( TypeFunc::ReturnAdr, topnode );
2041 init_req( TypeFunc::FramePtr , topnode );
2042 init_req( AllocSize , size);
2043 init_req( KlassNode , klass_node);
2044 init_req( InitialTest , initial_test);
2045 init_req( ALength , topnode);
2046 init_req( ValidLengthTest , topnode);
2047 init_req( InlineType , inline_type_node);
2048 // DefaultValue defaults to nullptr
2049 // RawDefaultValue defaults to nullptr
2050 C->add_macro_node(this);
2051 }
2052
2053 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
2054 {
2055 assert(initializer != nullptr &&
2056 (initializer->is_object_constructor() || initializer->is_class_initializer()),
2057 "unexpected initializer method");
2058 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
2059 if (analyzer == nullptr) {
2060 return;
2061 }
2062
2063 // Allocation node is first parameter in its initializer
2064 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
2065 _is_allocation_MemBar_redundant = true;
2066 }
2067 }
2068
2069 Node* AllocateNode::make_ideal_mark(PhaseGVN* phase, Node* control, Node* mem) {
2070 Node* mark_node = nullptr;
2071 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
2072 Node* klass_node = in(AllocateNode::KlassNode);
2073 Node* proto_adr = phase->transform(AddPNode::make_with_base(phase->C->top(), klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
2074 mark_node = LoadNode::make(*phase, control, mem, proto_adr, phase->type(proto_adr)->is_ptr(), TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
2075 } else {
2076 // For now only enable fast locking for non-array types
2077 mark_node = phase->MakeConX(markWord::prototype().value());
2078 }
2079 return mark_node;
2080 }
2081
2082 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
2083 // CastII, if appropriate. If we are not allowed to create new nodes, and
2084 // a CastII is appropriate, return null.
2085 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
2086 Node *length = in(AllocateNode::ALength);
2087 assert(length != nullptr, "length is not null");
2088
2089 const TypeInt* length_type = phase->find_int_type(length);
2090 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
2091
2092 if (ary_type != nullptr && length_type != nullptr) {
2093 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
2455
2456 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2457 st->print("%s", _kind_names[_kind]);
2458 }
2459 #endif
2460
2461 //=============================================================================
2462 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2463
2464 // perform any generic optimizations first (returns 'this' or null)
2465 Node *result = SafePointNode::Ideal(phase, can_reshape);
2466 if (result != nullptr) return result;
2467 // Don't bother trying to transform a dead node
2468 if (in(0) && in(0)->is_top()) return nullptr;
2469
2470 // Now see if we can optimize away this lock. We don't actually
2471 // remove the locking here, we simply set the _eliminate flag which
2472 // prevents macro expansion from expanding the lock. Since we don't
2473 // modify the graph, the value returned from this function is the
2474 // one computed above.
2475 const Type* obj_type = phase->type(obj_node());
2476 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2477 //
2478 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2479 //
2480 ConnectionGraph *cgr = phase->C->congraph();
2481 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2482 assert(!is_eliminated() || is_coarsened(), "sanity");
2483 // The lock could be marked eliminated by lock coarsening
2484 // code during first IGVN before EA. Replace coarsened flag
2485 // to eliminate all associated locks/unlocks.
2486 #ifdef ASSERT
2487 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2488 #endif
2489 this->set_non_esc_obj();
2490 return result;
2491 }
2492
2493 if (!phase->C->do_locks_coarsening()) {
2494 return result; // Compiling without locks coarsening
2495 }
2496 //
2657 }
2658
2659 //=============================================================================
2660 uint UnlockNode::size_of() const { return sizeof(*this); }
2661
2662 //=============================================================================
2663 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2664
2665 // perform any generic optimizations first (returns 'this' or null)
2666 Node *result = SafePointNode::Ideal(phase, can_reshape);
2667 if (result != nullptr) return result;
2668 // Don't bother trying to transform a dead node
2669 if (in(0) && in(0)->is_top()) return nullptr;
2670
2671 // Now see if we can optimize away this unlock. We don't actually
2672 // remove the unlocking here, we simply set the _eliminate flag which
2673 // prevents macro expansion from expanding the unlock. Since we don't
2674 // modify the graph, the value returned from this function is the
2675 // one computed above.
2676 // Escape state is defined after Parse phase.
2677 const Type* obj_type = phase->type(obj_node());
2678 if (can_reshape && EliminateLocks && !is_non_esc_obj() && !obj_type->is_inlinetypeptr()) {
2679 //
2680 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2681 //
2682 ConnectionGraph *cgr = phase->C->congraph();
2683 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2684 assert(!is_eliminated() || is_coarsened(), "sanity");
2685 // The lock could be marked eliminated by lock coarsening
2686 // code during first IGVN before EA. Replace coarsened flag
2687 // to eliminate all associated locks/unlocks.
2688 #ifdef ASSERT
2689 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2690 #endif
2691 this->set_non_esc_obj();
2692 }
2693 }
2694 return result;
2695 }
2696
2697 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2698 if (C == nullptr) {
2738 }
2739 // unrelated
2740 return false;
2741 }
2742
2743 if (dest_t->isa_aryptr()) {
2744 // arraycopy or array clone
2745 if (t_oop->isa_instptr()) {
2746 return false;
2747 }
2748 if (!t_oop->isa_aryptr()) {
2749 return true;
2750 }
2751
2752 const Type* elem = dest_t->is_aryptr()->elem();
2753 if (elem == Type::BOTTOM) {
2754 // An array but we don't know what elements are
2755 return true;
2756 }
2757
2758 dest_t = dest_t->is_aryptr()->with_field_offset(Type::OffsetBot)->add_offset(Type::OffsetBot)->is_oopptr();
2759 t_oop = t_oop->is_aryptr()->with_field_offset(Type::OffsetBot);
2760 uint dest_alias = phase->C->get_alias_index(dest_t);
2761 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2762
2763 return dest_alias == t_oop_alias;
2764 }
2765
2766 return true;
2767 }
2768
2769 PowDNode::PowDNode(Compile* C, Node* base, Node* exp)
2770 : CallLeafPureNode(
2771 OptoRuntime::Math_DD_D_Type(),
2772 StubRoutines::dpow() != nullptr ? StubRoutines::dpow() : CAST_FROM_FN_PTR(address, SharedRuntime::dpow),
2773 "pow") {
2774 add_flag(Flag_is_macro);
2775 C->add_macro_node(this);
2776
2777 init_req(TypeFunc::Parms + 0, base);
2778 init_req(TypeFunc::Parms + 1, C->top()); // double slot padding
2779 init_req(TypeFunc::Parms + 2, exp);
2805 // i.e., pow(x, +/-0.0D) => 1.0
2806 if (e == 0.0) { // true for both -0.0 and +0.0
2807 result_t = TypeD::ONE;
2808 }
2809
2810 // If the second argument is NaN, then the result is NaN.
2811 // i.e., pow(x, NaN) => NaN
2812 if (g_isnan(e)) {
2813 result_t = TypeD::make(NAN);
2814 }
2815 }
2816
2817 if (result_t != nullptr) {
2818 // We can't simply return a TypeD here, it must be a tuple type to be compatible with call nodes.
2819 const Type** fields = TypeTuple::fields(2);
2820 fields[TypeFunc::Parms + 0] = result_t;
2821 fields[TypeFunc::Parms + 1] = Type::HALF;
2822 return TypeTuple::make(TypeFunc::Parms + 2, fields);
2823 }
2824
2825 return tf()->range_cc();
2826 }
2827
2828 Node* PowDNode::Ideal(PhaseGVN* phase, bool can_reshape) {
2829 if (!can_reshape) {
2830 return nullptr; // wait for igvn
2831 }
2832
2833 PhaseIterGVN* igvn = phase->is_IterGVN();
2834 Node* base = this->base();
2835 Node* exp = this->exp();
2836
2837 const Type* t_exp = phase->type(exp);
2838 const TypeD* exp_con = t_exp->isa_double_constant();
2839
2840 // Special cases when only the exponent is known:
2841 if (exp_con != nullptr) {
2842 double e = exp_con->getd();
2843
2844 // If the second argument is 1.0, then the result is the same as the first argument.
2845 // i.e., pow(x, 1.0) => x
2892
2893 igvn->C->set_has_split_ifs(true); // Has chance for split-if optimization
2894
2895 return make_tuple_of_input_state_and_result(igvn, phi, region);
2896 }
2897 }
2898
2899 return CallLeafPureNode::Ideal(phase, can_reshape);
2900 }
2901
2902 // We can't simply have Ideal() returning a Con or MulNode since the users are still expecting a Call node, but we could
2903 // produce a tuple that follows the same pattern so users can still get control, io, memory, etc..
2904 TupleNode* PowDNode::make_tuple_of_input_state_and_result(PhaseIterGVN* phase, Node* result, Node* control) {
2905 if (control == nullptr) {
2906 control = in(TypeFunc::Control);
2907 }
2908
2909 Compile* C = phase->C;
2910 C->remove_macro_node(this);
2911 TupleNode* tuple = TupleNode::make(
2912 tf()->range_cc(),
2913 control,
2914 in(TypeFunc::I_O),
2915 in(TypeFunc::Memory),
2916 in(TypeFunc::FramePtr),
2917 in(TypeFunc::ReturnAdr),
2918 result,
2919 C->top());
2920 return tuple;
2921 }
|