Print this page
rev 7079 : 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
Reviewed-by: kvn

Split Split Close
Expand all
Collapse all
          --- old/hotspot/src/share/vm/opto/stringopts.cpp
          +++ new/hotspot/src/share/vm/opto/stringopts.cpp
↓ open down ↓ 1499 lines elided ↑ open up ↑
1500 1500            Node* notnull = __ IfTrue(iff);
1501 1501            kit.set_control(notnull); // set control for the cast_not_null
1502 1502            arg = kit.cast_not_null(arg, false);
1503 1503            sc->set_argument(argi, arg);
1504 1504          }
1505 1505          assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity");
1506 1506          // Fallthrough to add string length.
1507 1507        }
1508 1508        case StringConcat::StringMode: {
1509 1509          const Type* type = kit.gvn().type(arg);
     1510 +        Node* count = NULL;
1510 1511          if (type == TypePtr::NULL_PTR) {
1511 1512            // replace the argument with the null checked version
1512 1513            arg = null_string;
1513 1514            sc->set_argument(argi, arg);
     1515 +          count = kit.load_String_length(kit.control(), arg);
1514 1516          } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1515 1517            // s = s != null ? s : "null";
1516 1518            // length = length + (s.count - s.offset);
1517 1519            RegionNode *r = new (C) RegionNode(3);
1518 1520            kit.gvn().set_type(r, Type::CONTROL);
1519 1521            Node *phi = new (C) PhiNode(r, type);
1520 1522            kit.gvn().set_type(phi, phi->bottom_type());
1521 1523            Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1522 1524            IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1523 1525            Node* notnull = __ IfTrue(iff);
↓ open down ↓ 2 lines elided ↑ open up ↑
1526 1528            r->init_req(1, notnull);
1527 1529            phi->init_req(1, kit.cast_not_null(arg, false));
1528 1530            r->init_req(2, isnull);
1529 1531            phi->init_req(2, null_string);
1530 1532            kit.set_control(r);
1531 1533            C->record_for_igvn(r);
1532 1534            C->record_for_igvn(phi);
1533 1535            // replace the argument with the null checked version
1534 1536            arg = phi;
1535 1537            sc->set_argument(argi, arg);
     1538 +          count = kit.load_String_length(kit.control(), arg);
     1539 +        } else {
     1540 +          // A corresponding nullcheck will be connected during IGVN MemNode::Ideal_common_DU_postCCP
     1541 +          // kit.control might be a different test, that can be hoisted above the actual nullcheck
     1542 +          // in case, that the control input is not null, Ideal_common_DU_postCCP will not look for a nullcheck.
     1543 +          count = kit.load_String_length(NULL, arg);
1536 1544          }
1537      -
1538      -        Node* count = kit.load_String_length(kit.control(), arg);
1539      -
1540 1545          length = __ AddI(length, count);
1541 1546          string_sizes->init_req(argi, NULL);
1542 1547          break;
1543 1548        }
1544 1549        case StringConcat::CharMode: {
1545 1550          // one character only
1546 1551          length = __ AddI(length, __ intcon(1));
1547 1552          break;
1548 1553        }
1549 1554        default:
↓ open down ↓ 98 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX