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