< prev index next >

hotspot/src/share/vm/opto/stringopts.cpp

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


1490         const Type* type = kit.gvn().type(arg);
1491         assert(type != TypePtr::NULL_PTR, "missing check");
1492         if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1493           // Null check with uncommont trap since
1494           // StringBuilder(null) throws exception.
1495           // Use special uncommon trap instead of
1496           // calling normal do_null_check().
1497           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1498           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1499           overflow->add_req(__ IfFalse(iff));
1500           Node* notnull = __ IfTrue(iff);
1501           kit.set_control(notnull); // set control for the cast_not_null
1502           arg = kit.cast_not_null(arg, false);
1503           sc->set_argument(argi, arg);
1504         }
1505         assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity");
1506         // Fallthrough to add string length.
1507       }
1508       case StringConcat::StringMode: {
1509         const Type* type = kit.gvn().type(arg);

1510         if (type == TypePtr::NULL_PTR) {
1511           // replace the argument with the null checked version
1512           arg = null_string;
1513           sc->set_argument(argi, arg);

1514         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1515           // s = s != null ? s : "null";
1516           // length = length + (s.count - s.offset);
1517           RegionNode *r = new (C) RegionNode(3);
1518           kit.gvn().set_type(r, Type::CONTROL);
1519           Node *phi = new (C) PhiNode(r, type);
1520           kit.gvn().set_type(phi, phi->bottom_type());
1521           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1522           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1523           Node* notnull = __ IfTrue(iff);
1524           Node* isnull =  __ IfFalse(iff);
1525           kit.set_control(notnull); // set control for the cast_not_null
1526           r->init_req(1, notnull);
1527           phi->init_req(1, kit.cast_not_null(arg, false));
1528           r->init_req(2, isnull);
1529           phi->init_req(2, null_string);
1530           kit.set_control(r);
1531           C->record_for_igvn(r);
1532           C->record_for_igvn(phi);
1533           // replace the argument with the null checked version
1534           arg = phi;
1535           sc->set_argument(argi, arg);






1536         }
1537 
1538         Node* count = kit.load_String_length(kit.control(), arg);
1539 
1540         length = __ AddI(length, count);
1541         string_sizes->init_req(argi, NULL);
1542         break;
1543       }
1544       case StringConcat::CharMode: {
1545         // one character only
1546         length = __ AddI(length, __ intcon(1));
1547         break;
1548       }
1549       default:
1550         ShouldNotReachHere();
1551     }
1552     if (argi > 0) {
1553       // Check that the sum hasn't overflowed
1554       IfNode* iff = kit.create_and_map_if(kit.control(),
1555                                           __ Bool(__ CmpI(length, __ intcon(0)), BoolTest::lt),
1556                                           PROB_MIN, COUNT_UNKNOWN);
1557       kit.set_control(__ IfFalse(iff));
1558       overflow->set_req(argi, __ IfTrue(iff));
1559     }




1490         const Type* type = kit.gvn().type(arg);
1491         assert(type != TypePtr::NULL_PTR, "missing check");
1492         if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1493           // Null check with uncommont trap since
1494           // StringBuilder(null) throws exception.
1495           // Use special uncommon trap instead of
1496           // calling normal do_null_check().
1497           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1498           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1499           overflow->add_req(__ IfFalse(iff));
1500           Node* notnull = __ IfTrue(iff);
1501           kit.set_control(notnull); // set control for the cast_not_null
1502           arg = kit.cast_not_null(arg, false);
1503           sc->set_argument(argi, arg);
1504         }
1505         assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity");
1506         // Fallthrough to add string length.
1507       }
1508       case StringConcat::StringMode: {
1509         const Type* type = kit.gvn().type(arg);
1510         Node* count = NULL;
1511         if (type == TypePtr::NULL_PTR) {
1512           // replace the argument with the null checked version
1513           arg = null_string;
1514           sc->set_argument(argi, arg);
1515           count = kit.load_String_length(kit.control(), arg);
1516         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1517           // s = s != null ? s : "null";
1518           // length = length + (s.count - s.offset);
1519           RegionNode *r = new (C) RegionNode(3);
1520           kit.gvn().set_type(r, Type::CONTROL);
1521           Node *phi = new (C) PhiNode(r, type);
1522           kit.gvn().set_type(phi, phi->bottom_type());
1523           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1524           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1525           Node* notnull = __ IfTrue(iff);
1526           Node* isnull =  __ IfFalse(iff);
1527           kit.set_control(notnull); // set control for the cast_not_null
1528           r->init_req(1, notnull);
1529           phi->init_req(1, kit.cast_not_null(arg, false));
1530           r->init_req(2, isnull);
1531           phi->init_req(2, null_string);
1532           kit.set_control(r);
1533           C->record_for_igvn(r);
1534           C->record_for_igvn(phi);
1535           // replace the argument with the null checked version
1536           arg = phi;
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);
1544         }



1545         length = __ AddI(length, count);
1546         string_sizes->init_req(argi, NULL);
1547         break;
1548       }
1549       case StringConcat::CharMode: {
1550         // one character only
1551         length = __ AddI(length, __ intcon(1));
1552         break;
1553       }
1554       default:
1555         ShouldNotReachHere();
1556     }
1557     if (argi > 0) {
1558       // Check that the sum hasn't overflowed
1559       IfNode* iff = kit.create_and_map_if(kit.control(),
1560                                           __ Bool(__ CmpI(length, __ intcon(0)), BoolTest::lt),
1561                                           PROB_MIN, COUNT_UNKNOWN);
1562       kit.set_control(__ IfFalse(iff));
1563       overflow->set_req(argi, __ IfTrue(iff));
1564     }


< prev index next >