437 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
438 "sha512_implCompressMB",
439 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+1, ShenandoahStore }, { -1, ShenandoahNone },
440 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
441 "encodeBlock",
442 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+3, ShenandoahStore }, { -1, ShenandoahNone },
443 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
444 "decodeBlock",
445 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+3, ShenandoahStore }, { -1, ShenandoahNone },
446 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
447 "intpoly_montgomeryMult_P256",
448 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+1, ShenandoahLoad }, { TypeFunc::Parms+2, ShenandoahStore },
449 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
450 "intpoly_assign",
451 { { TypeFunc::Parms+1, ShenandoahStore }, { TypeFunc::Parms+2, ShenandoahLoad }, { -1, ShenandoahNone },
452 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
453 };
454
455 if (call->is_call_to_arraycopystub()) {
456 Node* dest = nullptr;
457 const TypeTuple* args = n->as_Call()->_tf->domain();
458 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
459 if (args->field_at(i)->isa_ptr()) {
460 j++;
461 if (j == 2) {
462 dest = n->in(i);
463 break;
464 }
465 }
466 }
467 if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahLoad, trace, barriers_used) ||
468 !verify_helper(dest, phis, visited, ShenandoahStore, trace, barriers_used)) {
469 report_verify_failure("Shenandoah verification: ArrayCopy should have barriers", n);
470 }
471 } else if (strlen(call->_name) > 5 &&
472 !strcmp(call->_name + strlen(call->_name) - 5, "_fill")) {
473 if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahStore, trace, barriers_used)) {
474 report_verify_failure("Shenandoah verification: _fill should have barriers", n);
475 }
476 } else if (!strcmp(call->_name, "shenandoah_wb_pre")) {
477 // skip
558 { { 2, ShenandoahLoad }, { 3, ShenandoahLoad } },
559 Op_VectorizedHashCode,
560 { { 2, ShenandoahLoad }, { -1, ShenandoahNone } },
561 Op_EncodeISOArray,
562 { { 2, ShenandoahLoad }, { 3, ShenandoahStore } },
563 Op_CountPositives,
564 { { 2, ShenandoahLoad }, { -1, ShenandoahNone} },
565 Op_CastP2X,
566 { { 1, ShenandoahLoad }, { -1, ShenandoahNone} },
567 Op_StrIndexOfChar,
568 { { 2, ShenandoahLoad }, { -1, ShenandoahNone } },
569 };
570
571 const int others_len = sizeof(others) / sizeof(others[0]);
572 int i = 0;
573 for (; i < others_len; i++) {
574 if (others[i].opcode == n->Opcode()) {
575 break;
576 }
577 }
578 uint stop = n->is_Call() ? n->as_Call()->tf()->domain()->cnt() : n->req();
579 if (i != others_len) {
580 const uint inputs_len = sizeof(others[0].inputs) / sizeof(others[0].inputs[0]);
581 for (uint j = 0; j < inputs_len; j++) {
582 int pos = others[i].inputs[j].pos;
583 if (pos == -1) {
584 break;
585 }
586 if (!verify_helper(n->in(pos), phis, visited, others[i].inputs[j].t, trace, barriers_used)) {
587 report_verify_failure("Shenandoah verification: intrinsic calls should have barriers", n);
588 }
589 }
590 for (uint j = 1; j < stop; j++) {
591 if (n->in(j) != nullptr && n->in(j)->bottom_type()->make_ptr() &&
592 n->in(j)->bottom_type()->make_ptr()->make_oopptr()) {
593 uint k = 0;
594 for (; k < inputs_len && others[i].inputs[k].pos != (int)j; k++);
595 if (k == inputs_len) {
596 fatal("arg %d for node %s not covered", j, n->Name());
597 }
598 }
778 mem_ctrl = phase->ctrl_or_self(mem);
779 }
780 return mem;
781 }
782
783 Node* ShenandoahBarrierC2Support::find_bottom_mem(Node* ctrl, PhaseIdealLoop* phase) {
784 Node* mem = nullptr;
785 Node* c = ctrl;
786 do {
787 if (c->is_Region()) {
788 for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax && mem == nullptr; i++) {
789 Node* u = c->fast_out(i);
790 if (u->is_Phi() && u->bottom_type() == Type::MEMORY) {
791 if (u->adr_type() == TypePtr::BOTTOM) {
792 mem = u;
793 }
794 }
795 }
796 } else {
797 if (c->is_Call() && c->as_Call()->adr_type() != nullptr) {
798 CallProjections projs;
799 c->as_Call()->extract_projections(&projs, true, false);
800 if (projs.fallthrough_memproj != nullptr) {
801 if (projs.fallthrough_memproj->adr_type() == TypePtr::BOTTOM) {
802 if (projs.catchall_memproj == nullptr) {
803 mem = projs.fallthrough_memproj;
804 } else {
805 if (phase->is_dominator(projs.fallthrough_catchproj, ctrl)) {
806 mem = projs.fallthrough_memproj;
807 } else {
808 assert(phase->is_dominator(projs.catchall_catchproj, ctrl), "one proj must dominate barrier");
809 mem = projs.catchall_memproj;
810 }
811 }
812 }
813 } else {
814 Node* proj = c->as_Call()->proj_out(TypeFunc::Memory);
815 if (proj != nullptr &&
816 proj->adr_type() == TypePtr::BOTTOM) {
817 mem = proj;
818 }
819 }
820 } else {
821 for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax; i++) {
822 Node* u = c->fast_out(i);
823 if (u->is_Proj() &&
824 u->bottom_type() == Type::MEMORY &&
825 u->adr_type() == TypePtr::BOTTOM) {
826 assert(c->is_SafePoint() || c->is_MemBar() || c->is_Start(), "");
827 assert(mem == nullptr, "only one proj");
828 mem = u;
829 }
1049 if (c != ctrl ||
1050 is_dominator_same_ctrl(old_c, barrier, u, phase) ||
1051 ShenandoahBarrierSetC2::is_shenandoah_state_load(u)) {
1052 phase->igvn().rehash_node_delayed(u);
1053 int nb = u->replace_edge(ctrl, region, &phase->igvn());
1054 if (u->is_CFG()) {
1055 if (phase->idom(u) == ctrl) {
1056 phase->set_idom(u, region, phase->dom_depth(region));
1057 }
1058 } else if (phase->get_ctrl(u) == ctrl) {
1059 assert(u != init_raw_mem, "should leave input raw mem above the barrier");
1060 uses.push(u);
1061 }
1062 assert(nb == 1, "more than 1 ctrl input?");
1063 --i, imax -= nb;
1064 }
1065 }
1066 }
1067 }
1068
1069 static Node* create_phis_on_call_return(Node* ctrl, Node* c, Node* n, Node* n_clone, const CallProjections& projs, PhaseIdealLoop* phase) {
1070 Node* region = nullptr;
1071 while (c != ctrl) {
1072 if (c->is_Region()) {
1073 region = c;
1074 }
1075 c = phase->idom(c);
1076 }
1077 assert(region != nullptr, "");
1078 Node* phi = new PhiNode(region, n->bottom_type());
1079 for (uint j = 1; j < region->req(); j++) {
1080 Node* in = region->in(j);
1081 if (phase->is_dominator(projs.fallthrough_catchproj, in)) {
1082 phi->init_req(j, n);
1083 } else if (phase->is_dominator(projs.catchall_catchproj, in)) {
1084 phi->init_req(j, n_clone);
1085 } else {
1086 phi->init_req(j, create_phis_on_call_return(ctrl, in, n, n_clone, projs, phase));
1087 }
1088 }
1089 phase->register_new_node(phi, region);
1090 return phi;
1091 }
1092
1093 void ShenandoahBarrierC2Support::pin_and_expand(PhaseIdealLoop* phase) {
1094 ShenandoahBarrierSetC2State* state = ShenandoahBarrierSetC2::bsc2()->state();
1095
1096 Unique_Node_List uses;
1097 Node_Stack stack(0);
1098 Node_List clones;
1099 for (int i = state->load_reference_barriers_count() - 1; i >= 0; i--) {
1100 ShenandoahLoadReferenceBarrierNode* lrb = state->load_reference_barrier(i);
1101
1102 Node* ctrl = phase->get_ctrl(lrb);
1103 Node* val = lrb->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
1165 if (phase->has_ctrl(in)) {
1166 if (phase->is_dominator(call, phase->get_ctrl(in))) {
1167 #ifdef ASSERT
1168 for (uint i = 0; i < stack.size(); i++) {
1169 assert(stack.node_at(i) != in, "node shouldn't have been seen yet");
1170 }
1171 #endif
1172 stack.push(in, 0);
1173 }
1174 } else {
1175 assert(phase->is_dominator(in, call->in(0)), "no dependency on the call");
1176 }
1177 }
1178 } else {
1179 phase->set_ctrl(n, call->in(0));
1180 stack.pop();
1181 }
1182 } while(stack.size() > 0);
1183 continue;
1184 }
1185 CallProjections projs;
1186 call->extract_projections(&projs, false, false);
1187
1188 #ifdef ASSERT
1189 VectorSet cloned;
1190 #endif
1191 Node* lrb_clone = lrb->clone();
1192 phase->register_new_node(lrb_clone, projs.catchall_catchproj);
1193 phase->set_ctrl(lrb, projs.fallthrough_catchproj);
1194
1195 stack.push(lrb, 0);
1196 clones.push(lrb_clone);
1197
1198 do {
1199 assert(stack.size() == clones.size(), "");
1200 Node* n = stack.node();
1201 #ifdef ASSERT
1202 if (n->is_Load()) {
1203 Node* mem = n->in(MemNode::Memory);
1204 for (DUIterator_Fast jmax, j = mem->fast_outs(jmax); j < jmax; j++) {
1205 Node* u = mem->fast_out(j);
1206 assert(!u->is_Store() || !u->is_LoadStore() || phase->get_ctrl(u) != ctrl, "anti dependent store?");
1207 }
1208 }
1209 #endif
1210 uint idx = stack.index();
1211 Node* n_clone = clones.at(clones.size()-1);
1212 if (idx < n->outcnt()) {
1213 Node* u = n->raw_out(idx);
1214 Node* c = phase->ctrl_or_self(u);
1215 if (phase->is_dominator(call, c) && phase->is_dominator(c, projs.fallthrough_proj)) {
1216 stack.set_index(idx+1);
1217 assert(!u->is_CFG(), "");
1218 stack.push(u, 0);
1219 assert(!cloned.test_set(u->_idx), "only one clone");
1220 Node* u_clone = u->clone();
1221 int nb = u_clone->replace_edge(n, n_clone, &phase->igvn());
1222 assert(nb > 0, "should have replaced some uses");
1223 phase->register_new_node(u_clone, projs.catchall_catchproj);
1224 clones.push(u_clone);
1225 phase->set_ctrl(u, projs.fallthrough_catchproj);
1226 } else {
1227 bool replaced = false;
1228 if (u->is_Phi()) {
1229 for (uint k = 1; k < u->req(); k++) {
1230 if (u->in(k) == n) {
1231 if (phase->is_dominator(projs.catchall_catchproj, u->in(0)->in(k))) {
1232 phase->igvn().replace_input_of(u, k, n_clone);
1233 replaced = true;
1234 } else if (!phase->is_dominator(projs.fallthrough_catchproj, u->in(0)->in(k))) {
1235 phase->igvn().replace_input_of(u, k, create_phis_on_call_return(ctrl, u->in(0)->in(k), n, n_clone, projs, phase));
1236 replaced = true;
1237 }
1238 }
1239 }
1240 } else {
1241 if (phase->is_dominator(projs.catchall_catchproj, c)) {
1242 phase->igvn().rehash_node_delayed(u);
1243 int nb = u->replace_edge(n, n_clone, &phase->igvn());
1244 assert(nb > 0, "should have replaced some uses");
1245 replaced = true;
1246 } else if (!phase->is_dominator(projs.fallthrough_catchproj, c)) {
1247 if (u->is_If()) {
1248 // Can't break If/Bool/Cmp chain
1249 assert(n->is_Bool(), "unexpected If shape");
1250 assert(stack.node_at(stack.size()-2)->is_Cmp(), "unexpected If shape");
1251 assert(n_clone->is_Bool(), "unexpected clone");
1252 assert(clones.at(clones.size()-2)->is_Cmp(), "unexpected clone");
1253 Node* bol_clone = n->clone();
1254 Node* cmp_clone = stack.node_at(stack.size()-2)->clone();
1255 bol_clone->set_req(1, cmp_clone);
1256
1257 Node* nn = stack.node_at(stack.size()-3);
1258 Node* nn_clone = clones.at(clones.size()-3);
1259 assert(nn->Opcode() == nn_clone->Opcode(), "mismatch");
1260
1261 int nb = cmp_clone->replace_edge(nn, create_phis_on_call_return(ctrl, c, nn, nn_clone, projs, phase),
1262 &phase->igvn());
1263 assert(nb > 0, "should have replaced some uses");
1264
1265 phase->register_new_node(bol_clone, u->in(0));
1266 phase->register_new_node(cmp_clone, u->in(0));
2047 } else {
2048 assert(c != c->in(0), "");
2049 c = c->in(0);
2050 }
2051 }
2052 }
2053 }
2054 } while (stack.size() > 0);
2055 assert(mem != nullptr, "should have found safepoint");
2056 } else {
2057 mem = phi_mem;
2058 }
2059 return mem;
2060 }
2061
2062 Node* MemoryGraphFixer::get_ctrl(Node* n) const {
2063 Node* c = _phase->get_ctrl(n);
2064 if (n->is_Proj() && n->in(0) != nullptr && n->in(0)->is_Call()) {
2065 assert(c == n->in(0), "");
2066 CallNode* call = c->as_Call();
2067 CallProjections projs;
2068 call->extract_projections(&projs, true, false);
2069 if (projs.catchall_memproj != nullptr) {
2070 if (projs.fallthrough_memproj == n) {
2071 c = projs.fallthrough_catchproj;
2072 } else {
2073 assert(projs.catchall_memproj == n, "");
2074 c = projs.catchall_catchproj;
2075 }
2076 }
2077 }
2078 return c;
2079 }
2080
2081 Node* MemoryGraphFixer::ctrl_or_self(Node* n) const {
2082 if (_phase->has_ctrl(n))
2083 return get_ctrl(n);
2084 else {
2085 assert (n->is_CFG(), "must be a CFG node");
2086 return n;
2087 }
2088 }
2089
2090 bool MemoryGraphFixer::mem_is_valid(Node* m, Node* c) const {
2091 return m != nullptr && get_ctrl(m) == c;
2092 }
2093
2094 Node* MemoryGraphFixer::find_mem(Node* ctrl, Node* n) const {
|
437 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
438 "sha512_implCompressMB",
439 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+1, ShenandoahStore }, { -1, ShenandoahNone },
440 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
441 "encodeBlock",
442 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+3, ShenandoahStore }, { -1, ShenandoahNone },
443 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
444 "decodeBlock",
445 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+3, ShenandoahStore }, { -1, ShenandoahNone },
446 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
447 "intpoly_montgomeryMult_P256",
448 { { TypeFunc::Parms, ShenandoahLoad }, { TypeFunc::Parms+1, ShenandoahLoad }, { TypeFunc::Parms+2, ShenandoahStore },
449 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
450 "intpoly_assign",
451 { { TypeFunc::Parms+1, ShenandoahStore }, { TypeFunc::Parms+2, ShenandoahLoad }, { -1, ShenandoahNone },
452 { -1, ShenandoahNone}, { -1, ShenandoahNone}, { -1, ShenandoahNone} },
453 };
454
455 if (call->is_call_to_arraycopystub()) {
456 Node* dest = nullptr;
457 const TypeTuple* args = n->as_Call()->_tf->domain_sig();
458 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
459 if (args->field_at(i)->isa_ptr()) {
460 j++;
461 if (j == 2) {
462 dest = n->in(i);
463 break;
464 }
465 }
466 }
467 if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahLoad, trace, barriers_used) ||
468 !verify_helper(dest, phis, visited, ShenandoahStore, trace, barriers_used)) {
469 report_verify_failure("Shenandoah verification: ArrayCopy should have barriers", n);
470 }
471 } else if (strlen(call->_name) > 5 &&
472 !strcmp(call->_name + strlen(call->_name) - 5, "_fill")) {
473 if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahStore, trace, barriers_used)) {
474 report_verify_failure("Shenandoah verification: _fill should have barriers", n);
475 }
476 } else if (!strcmp(call->_name, "shenandoah_wb_pre")) {
477 // skip
558 { { 2, ShenandoahLoad }, { 3, ShenandoahLoad } },
559 Op_VectorizedHashCode,
560 { { 2, ShenandoahLoad }, { -1, ShenandoahNone } },
561 Op_EncodeISOArray,
562 { { 2, ShenandoahLoad }, { 3, ShenandoahStore } },
563 Op_CountPositives,
564 { { 2, ShenandoahLoad }, { -1, ShenandoahNone} },
565 Op_CastP2X,
566 { { 1, ShenandoahLoad }, { -1, ShenandoahNone} },
567 Op_StrIndexOfChar,
568 { { 2, ShenandoahLoad }, { -1, ShenandoahNone } },
569 };
570
571 const int others_len = sizeof(others) / sizeof(others[0]);
572 int i = 0;
573 for (; i < others_len; i++) {
574 if (others[i].opcode == n->Opcode()) {
575 break;
576 }
577 }
578 uint stop = n->is_Call() ? n->as_Call()->tf()->domain_sig()->cnt() : n->req();
579 if (i != others_len) {
580 const uint inputs_len = sizeof(others[0].inputs) / sizeof(others[0].inputs[0]);
581 for (uint j = 0; j < inputs_len; j++) {
582 int pos = others[i].inputs[j].pos;
583 if (pos == -1) {
584 break;
585 }
586 if (!verify_helper(n->in(pos), phis, visited, others[i].inputs[j].t, trace, barriers_used)) {
587 report_verify_failure("Shenandoah verification: intrinsic calls should have barriers", n);
588 }
589 }
590 for (uint j = 1; j < stop; j++) {
591 if (n->in(j) != nullptr && n->in(j)->bottom_type()->make_ptr() &&
592 n->in(j)->bottom_type()->make_ptr()->make_oopptr()) {
593 uint k = 0;
594 for (; k < inputs_len && others[i].inputs[k].pos != (int)j; k++);
595 if (k == inputs_len) {
596 fatal("arg %d for node %s not covered", j, n->Name());
597 }
598 }
778 mem_ctrl = phase->ctrl_or_self(mem);
779 }
780 return mem;
781 }
782
783 Node* ShenandoahBarrierC2Support::find_bottom_mem(Node* ctrl, PhaseIdealLoop* phase) {
784 Node* mem = nullptr;
785 Node* c = ctrl;
786 do {
787 if (c->is_Region()) {
788 for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax && mem == nullptr; i++) {
789 Node* u = c->fast_out(i);
790 if (u->is_Phi() && u->bottom_type() == Type::MEMORY) {
791 if (u->adr_type() == TypePtr::BOTTOM) {
792 mem = u;
793 }
794 }
795 }
796 } else {
797 if (c->is_Call() && c->as_Call()->adr_type() != nullptr) {
798 CallProjections* projs = c->as_Call()->extract_projections(true, false);
799 if (projs->fallthrough_memproj != nullptr) {
800 if (projs->fallthrough_memproj->adr_type() == TypePtr::BOTTOM) {
801 if (projs->catchall_memproj == nullptr) {
802 mem = projs->fallthrough_memproj;
803 } else {
804 if (phase->is_dominator(projs->fallthrough_catchproj, ctrl)) {
805 mem = projs->fallthrough_memproj;
806 } else {
807 assert(phase->is_dominator(projs->catchall_catchproj, ctrl), "one proj must dominate barrier");
808 mem = projs->catchall_memproj;
809 }
810 }
811 }
812 } else {
813 Node* proj = c->as_Call()->proj_out(TypeFunc::Memory);
814 if (proj != nullptr &&
815 proj->adr_type() == TypePtr::BOTTOM) {
816 mem = proj;
817 }
818 }
819 } else {
820 for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax; i++) {
821 Node* u = c->fast_out(i);
822 if (u->is_Proj() &&
823 u->bottom_type() == Type::MEMORY &&
824 u->adr_type() == TypePtr::BOTTOM) {
825 assert(c->is_SafePoint() || c->is_MemBar() || c->is_Start(), "");
826 assert(mem == nullptr, "only one proj");
827 mem = u;
828 }
1048 if (c != ctrl ||
1049 is_dominator_same_ctrl(old_c, barrier, u, phase) ||
1050 ShenandoahBarrierSetC2::is_shenandoah_state_load(u)) {
1051 phase->igvn().rehash_node_delayed(u);
1052 int nb = u->replace_edge(ctrl, region, &phase->igvn());
1053 if (u->is_CFG()) {
1054 if (phase->idom(u) == ctrl) {
1055 phase->set_idom(u, region, phase->dom_depth(region));
1056 }
1057 } else if (phase->get_ctrl(u) == ctrl) {
1058 assert(u != init_raw_mem, "should leave input raw mem above the barrier");
1059 uses.push(u);
1060 }
1061 assert(nb == 1, "more than 1 ctrl input?");
1062 --i, imax -= nb;
1063 }
1064 }
1065 }
1066 }
1067
1068 static Node* create_phis_on_call_return(Node* ctrl, Node* c, Node* n, Node* n_clone, const CallProjections* projs, PhaseIdealLoop* phase) {
1069 Node* region = nullptr;
1070 while (c != ctrl) {
1071 if (c->is_Region()) {
1072 region = c;
1073 }
1074 c = phase->idom(c);
1075 }
1076 assert(region != nullptr, "");
1077 Node* phi = new PhiNode(region, n->bottom_type());
1078 for (uint j = 1; j < region->req(); j++) {
1079 Node* in = region->in(j);
1080 if (phase->is_dominator(projs->fallthrough_catchproj, in)) {
1081 phi->init_req(j, n);
1082 } else if (phase->is_dominator(projs->catchall_catchproj, in)) {
1083 phi->init_req(j, n_clone);
1084 } else {
1085 phi->init_req(j, create_phis_on_call_return(ctrl, in, n, n_clone, projs, phase));
1086 }
1087 }
1088 phase->register_new_node(phi, region);
1089 return phi;
1090 }
1091
1092 void ShenandoahBarrierC2Support::pin_and_expand(PhaseIdealLoop* phase) {
1093 ShenandoahBarrierSetC2State* state = ShenandoahBarrierSetC2::bsc2()->state();
1094
1095 Unique_Node_List uses;
1096 Node_Stack stack(0);
1097 Node_List clones;
1098 for (int i = state->load_reference_barriers_count() - 1; i >= 0; i--) {
1099 ShenandoahLoadReferenceBarrierNode* lrb = state->load_reference_barrier(i);
1100
1101 Node* ctrl = phase->get_ctrl(lrb);
1102 Node* val = lrb->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
1164 if (phase->has_ctrl(in)) {
1165 if (phase->is_dominator(call, phase->get_ctrl(in))) {
1166 #ifdef ASSERT
1167 for (uint i = 0; i < stack.size(); i++) {
1168 assert(stack.node_at(i) != in, "node shouldn't have been seen yet");
1169 }
1170 #endif
1171 stack.push(in, 0);
1172 }
1173 } else {
1174 assert(phase->is_dominator(in, call->in(0)), "no dependency on the call");
1175 }
1176 }
1177 } else {
1178 phase->set_ctrl(n, call->in(0));
1179 stack.pop();
1180 }
1181 } while(stack.size() > 0);
1182 continue;
1183 }
1184 CallProjections* projs = call->extract_projections(false, false);
1185 #ifdef ASSERT
1186 VectorSet cloned;
1187 #endif
1188 Node* lrb_clone = lrb->clone();
1189 phase->register_new_node(lrb_clone, projs->catchall_catchproj);
1190 phase->set_ctrl(lrb, projs->fallthrough_catchproj);
1191
1192 stack.push(lrb, 0);
1193 clones.push(lrb_clone);
1194
1195 do {
1196 assert(stack.size() == clones.size(), "");
1197 Node* n = stack.node();
1198 #ifdef ASSERT
1199 if (n->is_Load()) {
1200 Node* mem = n->in(MemNode::Memory);
1201 for (DUIterator_Fast jmax, j = mem->fast_outs(jmax); j < jmax; j++) {
1202 Node* u = mem->fast_out(j);
1203 assert(!u->is_Store() || !u->is_LoadStore() || phase->get_ctrl(u) != ctrl, "anti dependent store?");
1204 }
1205 }
1206 #endif
1207 uint idx = stack.index();
1208 Node* n_clone = clones.at(clones.size()-1);
1209 if (idx < n->outcnt()) {
1210 Node* u = n->raw_out(idx);
1211 Node* c = phase->ctrl_or_self(u);
1212 if (phase->is_dominator(call, c) && phase->is_dominator(c, projs->fallthrough_proj)) {
1213 stack.set_index(idx+1);
1214 assert(!u->is_CFG(), "");
1215 stack.push(u, 0);
1216 assert(!cloned.test_set(u->_idx), "only one clone");
1217 Node* u_clone = u->clone();
1218 int nb = u_clone->replace_edge(n, n_clone, &phase->igvn());
1219 assert(nb > 0, "should have replaced some uses");
1220 phase->register_new_node(u_clone, projs->catchall_catchproj);
1221 clones.push(u_clone);
1222 phase->set_ctrl(u, projs->fallthrough_catchproj);
1223 } else {
1224 bool replaced = false;
1225 if (u->is_Phi()) {
1226 for (uint k = 1; k < u->req(); k++) {
1227 if (u->in(k) == n) {
1228 if (phase->is_dominator(projs->catchall_catchproj, u->in(0)->in(k))) {
1229 phase->igvn().replace_input_of(u, k, n_clone);
1230 replaced = true;
1231 } else if (!phase->is_dominator(projs->fallthrough_catchproj, u->in(0)->in(k))) {
1232 phase->igvn().replace_input_of(u, k, create_phis_on_call_return(ctrl, u->in(0)->in(k), n, n_clone, projs, phase));
1233 replaced = true;
1234 }
1235 }
1236 }
1237 } else {
1238 if (phase->is_dominator(projs->catchall_catchproj, c)) {
1239 phase->igvn().rehash_node_delayed(u);
1240 int nb = u->replace_edge(n, n_clone, &phase->igvn());
1241 assert(nb > 0, "should have replaced some uses");
1242 replaced = true;
1243 } else if (!phase->is_dominator(projs->fallthrough_catchproj, c)) {
1244 if (u->is_If()) {
1245 // Can't break If/Bool/Cmp chain
1246 assert(n->is_Bool(), "unexpected If shape");
1247 assert(stack.node_at(stack.size()-2)->is_Cmp(), "unexpected If shape");
1248 assert(n_clone->is_Bool(), "unexpected clone");
1249 assert(clones.at(clones.size()-2)->is_Cmp(), "unexpected clone");
1250 Node* bol_clone = n->clone();
1251 Node* cmp_clone = stack.node_at(stack.size()-2)->clone();
1252 bol_clone->set_req(1, cmp_clone);
1253
1254 Node* nn = stack.node_at(stack.size()-3);
1255 Node* nn_clone = clones.at(clones.size()-3);
1256 assert(nn->Opcode() == nn_clone->Opcode(), "mismatch");
1257
1258 int nb = cmp_clone->replace_edge(nn, create_phis_on_call_return(ctrl, c, nn, nn_clone, projs, phase),
1259 &phase->igvn());
1260 assert(nb > 0, "should have replaced some uses");
1261
1262 phase->register_new_node(bol_clone, u->in(0));
1263 phase->register_new_node(cmp_clone, u->in(0));
2044 } else {
2045 assert(c != c->in(0), "");
2046 c = c->in(0);
2047 }
2048 }
2049 }
2050 }
2051 } while (stack.size() > 0);
2052 assert(mem != nullptr, "should have found safepoint");
2053 } else {
2054 mem = phi_mem;
2055 }
2056 return mem;
2057 }
2058
2059 Node* MemoryGraphFixer::get_ctrl(Node* n) const {
2060 Node* c = _phase->get_ctrl(n);
2061 if (n->is_Proj() && n->in(0) != nullptr && n->in(0)->is_Call()) {
2062 assert(c == n->in(0), "");
2063 CallNode* call = c->as_Call();
2064 CallProjections* projs = call->extract_projections(true, false);
2065 if (projs->catchall_memproj != nullptr) {
2066 if (projs->fallthrough_memproj == n) {
2067 c = projs->fallthrough_catchproj;
2068 } else {
2069 assert(projs->catchall_memproj == n, "");
2070 c = projs->catchall_catchproj;
2071 }
2072 }
2073 }
2074 return c;
2075 }
2076
2077 Node* MemoryGraphFixer::ctrl_or_self(Node* n) const {
2078 if (_phase->has_ctrl(n))
2079 return get_ctrl(n);
2080 else {
2081 assert (n->is_CFG(), "must be a CFG node");
2082 return n;
2083 }
2084 }
2085
2086 bool MemoryGraphFixer::mem_is_valid(Node* m, Node* c) const {
2087 return m != nullptr && get_ctrl(m) == c;
2088 }
2089
2090 Node* MemoryGraphFixer::find_mem(Node* ctrl, Node* n) const {
|