author | iklam |
Tue, 28 Nov 2017 09:47:04 -0800 (2017-11-28) | |
changeset 48155 | 551de50b4ff7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
1 |
/* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
4 |
* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
8 |
* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
13 |
* accompanied this code). |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
14 |
* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
18 |
* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
21 |
* questions. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
22 |
*/ |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
23 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
24 |
|
40059 | 25 |
|
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
26 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
27 |
/* |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
28 |
* @test |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
29 |
* @bug 8159244 |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
30 |
* @summary Verifies that no partially initialized String object escapes from |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
31 |
* C2's String concat optimization in a highly concurrent setting. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
32 |
* This test triggers the bug in about 1 out of 10 runs. |
40059 | 33 |
* @requires vm.gc == "Parallel" | vm.gc == "null" |
34 |
* |
|
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
35 |
* @compile -XDstringConcat=inline TestStringObjectInitialization.java |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
36 |
* @run main/othervm/timeout=300 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-CompactStrings |
40059 | 37 |
* -XX:-UseG1GC -XX:+UseParallelGC |
38 |
* compiler.stringopts.TestStringObjectInitialization |
|
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
39 |
*/ |
40059 | 40 |
|
41 |
package compiler.stringopts; |
|
42 |
||
43 |
import java.util.Arrays; |
|
44 |
||
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
45 |
public class TestStringObjectInitialization { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
46 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
47 |
String myString; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
48 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
49 |
public static void main(String[] args) throws Exception { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
50 |
TestStringObjectInitialization t = new TestStringObjectInitialization(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
51 |
// Create some threads that concurrently update 'myString' |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
52 |
for (int i = 0; i < 100; ++i) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
53 |
(new Thread(new Runner(t))).start(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
54 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
55 |
Thread last = new Thread(new Runner(t)); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
56 |
last.start(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
57 |
last.join(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
58 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
59 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
60 |
private void add(String message) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
61 |
// String escapes to other threads here |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
62 |
myString += message; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
63 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
64 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
65 |
public void run(String s, String[] sArray) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
66 |
// Trigger C2's string concatenation optimization |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
67 |
add(s + Arrays.toString(sArray) + " const "); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
68 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
69 |
|
41332
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
70 |
public void reset() { |
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
71 |
// Reset string to avoid OOMEs |
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
72 |
myString = ""; |
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
73 |
} |
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
74 |
|
40059 | 75 |
private static class Runner implements Runnable { |
76 |
private TestStringObjectInitialization test; |
|
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
77 |
|
40059 | 78 |
public Runner(TestStringObjectInitialization t) { |
79 |
test = t; |
|
80 |
} |
|
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
81 |
|
40059 | 82 |
public void run() { |
83 |
String[] array = {"a", "b", "c"}; |
|
41332
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
84 |
for (int i = 0; i < 100_000; ++i) { |
40059 | 85 |
test.run("a", array); |
41332
a1ff82a6136a
8166046: [TESTBUG] compiler/stringopts/TestStringObjectInitialization.java fails with OOME
thartmann
parents:
40059
diff
changeset
|
86 |
test.reset(); |
40059 | 87 |
} |
39418
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
88 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
89 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
90 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
91 |