--- old/src/share/vm/opto/stringopts.cpp 2015-09-18 11:03:45.557264949 +0200 +++ new/src/share/vm/opto/stringopts.cpp 2015-09-18 11:03:45.469264947 +0200 @@ -822,11 +822,12 @@ } } else if (ctrl->is_IfTrue()) { // null checks, class checks iff = ctrl->in(0)->as_If(); - assert(iff->is_If(), "must be if"); // Verify that the other arm is an uncommon trap - Node* otherproj = iff->proj_out(1 - ctrl->as_Proj()->_con); - CallStaticJavaNode* call = otherproj->unique_out()->isa_CallStaticJava(); - assert(strcmp(call->_name, "uncommon_trap") == 0, "must be uncommond trap"); + if (iff->outcnt() == 2) { + Node* otherproj = iff->proj_out(1 - ctrl->as_Proj()->_con); + CallStaticJavaNode* call = otherproj->unique_out()->isa_CallStaticJava(); + assert(strcmp(call->_name, "uncommon_trap") == 0, "must be uncommon trap"); + } ctrl = iff->in(0); } else { break; @@ -911,9 +912,18 @@ assert(ctrl_path.member(ptr), "should be a known piece of control"); } else if (ptr->is_IfTrue()) { IfNode* iff = ptr->in(0)->as_If(); - BoolNode* b = iff->in(1)->isa_Bool(); + // Skip dead test + if (iff->in(1)->is_Con()) { + ptr = ptr->in(0)->in(0); + continue; + } + BoolNode* b = iff->in(1)->isa_Bool(); if (b == NULL) { +#ifndef PRODUCT + iff->in(1)->dump(); + assert(false, "Unexpected input to IfNode"); +#endif fail = true; break; } --- /dev/null 2015-09-18 08:01:11.771996015 +0200 +++ new/test/compiler/stringopts/TestPresizedStringBuilder.java 2015-09-18 11:03:45.781264956 +0200 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8136469 + * @summary C2's string concatenation optimization fails with pre-sized StringBuilder + * @run main/othervm -XX:CompileCommand=dontinline,TestPresizedStringBuilder::test TestPresizedStringBuilder + */ +public class TestPresizedStringBuilder { + + static final boolean count; + static { + count = true; + } + + public static void main(String[] args) { + for (int i = 0; i < 100_000; ++i) { + test(); + } + } + + public static String test() { + return new StringBuilder(count ? 1 : 2).toString(); + } +} +