author | thartmann |
Wed, 15 Jun 2016 07:58:56 +0200 | |
changeset 39418 | 6b03cc6f758a |
child 40059 | c2304140ed64 |
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 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
25 |
import java.util.Arrays; |
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 |
* @requires vm.gc == "Parallel" | vm.gc == "null" |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
31 |
* @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
|
32 |
* 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
|
33 |
* This test triggers the bug in about 1 out of 10 runs. |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
34 |
* @compile -XDstringConcat=inline TestStringObjectInitialization.java |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
35 |
* @run main/othervm/timeout=300 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-CompactStrings |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
36 |
* -XX:-UseG1GC -XX:+UseParallelGC TestStringObjectInitialization |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
37 |
*/ |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
38 |
public class TestStringObjectInitialization { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
39 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
40 |
String myString; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
41 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
42 |
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
|
43 |
TestStringObjectInitialization t = new TestStringObjectInitialization(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
44 |
// 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
|
45 |
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
|
46 |
(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
|
47 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
48 |
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
|
49 |
last.start(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
50 |
last.join(); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
51 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
52 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
53 |
private void add(String message) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
54 |
// 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
|
55 |
myString += message; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
56 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
57 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
58 |
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
|
59 |
// 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
|
60 |
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
|
61 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
62 |
} |
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 |
class Runner implements Runnable { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
65 |
private TestStringObjectInitialization test; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
66 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
67 |
public Runner(TestStringObjectInitialization t) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
68 |
test = t; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
69 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
70 |
|
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
71 |
public void run(){ |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
72 |
String[] array = {"a", "b", "c"}; |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
73 |
for (int i = 0; i < 10000; ++i) { |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
74 |
test.run("a", array); |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
75 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
76 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
77 |
} |
6b03cc6f758a
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
78 |