Skip to content

Commit e35d5b5

Browse files
committed
8357105: C2: compilation fails with "assert(false) failed: empty program detected during loop optimization"
Backport-of: a300c356555019a42c19bf0c16184f6dee4ad96e
1 parent 914318d commit e35d5b5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
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+
* @test
26+
* @bug 8357105
27+
* @summary Test stacked string concatenations where the toString result
28+
* of the first StringBuilder chain is wired into an uncommon trap
29+
* located in the second one.
30+
* @run main/othervm compiler.stringopts.TestStackedConcatsAppendUncommonTrap
31+
* @run main/othervm -XX:-TieredCompilation -Xbatch
32+
* -XX:CompileOnly=compiler.stringopts.TestStackedConcatsAppendUncommonTrap::*
33+
* compiler.stringopts.TestStackedConcatsAppendUncommonTrap
34+
*/
35+
36+
package compiler.stringopts;
37+
38+
public class TestStackedConcatsAppendUncommonTrap {
39+
40+
public static void main (String... args) {
41+
for (int i = 0; i < 10000; i++) {
42+
String s = f(" ");
43+
if (!s.equals(" ")) {
44+
throw new RuntimeException("wrong result.");
45+
}
46+
}
47+
}
48+
49+
static String f(String c) {
50+
String s = " ";
51+
s = new StringBuilder().append(s).append(s).toString();
52+
s = new StringBuilder().append(s).append(s == c ? s : " ").toString();
53+
return s;
54+
}
55+
}

0 commit comments

Comments
 (0)