Mercurial > hg > graal-jvmci-8
annotate test/compiler/stringopts/TestStringObjectInitialization.java @ 24155:88bd5f7522a1 jvmci-0.30
update hgignore and undo change to hotspot/.project
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 07 Jul 2017 15:08:58 +0200 |
parents | 173a1f83c930 |
children |
rev | line source |
---|---|
24016
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
1 /* |
3e2abbf1320d
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. |
3e2abbf1320d
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. |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
4 * |
3e2abbf1320d
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 |
3e2abbf1320d
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 |
3e2abbf1320d
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. |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
8 * |
3e2abbf1320d
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 |
3e2abbf1320d
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 |
3e2abbf1320d
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 |
3e2abbf1320d
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 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
13 * accompanied this code). |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
14 * |
3e2abbf1320d
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 |
3e2abbf1320d
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, |
3e2abbf1320d
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. |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
18 * |
3e2abbf1320d
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 |
3e2abbf1320d
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 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
21 * questions. |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
22 */ |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
23 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
24 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
25 import java.util.Arrays; |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
26 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
27 /* |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
28 * @test |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
29 * @bug 8159244 |
24023
173a1f83c930
8160122: Backport of JDK-8159244 used wrong version of the JDK 9 fix
thartmann
parents:
24016
diff
changeset
|
30 * @requires vm.gc == "Parallel" | vm.gc == "null" |
24016
3e2abbf1320d
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 |
3e2abbf1320d
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. |
3e2abbf1320d
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. |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
34 * @compile -XDstringConcat=inline TestStringObjectInitialization.java |
3e2abbf1320d
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 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
36 * -XX:-UseG1GC -XX:+UseParallelGC TestStringObjectInitialization |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
37 */ |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
38 public class TestStringObjectInitialization { |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
39 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
40 String myString; |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
41 |
3e2abbf1320d
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 { |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
43 TestStringObjectInitialization t = new TestStringObjectInitialization(); |
3e2abbf1320d
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' |
3e2abbf1320d
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) { |
3e2abbf1320d
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(); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
47 } |
3e2abbf1320d
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)); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
49 last.start(); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
50 last.join(); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
51 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
52 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
53 private void add(String message) { |
3e2abbf1320d
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 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
55 myString += message; |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
56 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
57 |
3e2abbf1320d
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) { |
3e2abbf1320d
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 |
3e2abbf1320d
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 "); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
61 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
62 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
63 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
64 class Runner implements Runnable { |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
65 private TestStringObjectInitialization test; |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
66 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
67 public Runner(TestStringObjectInitialization t) { |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
68 test = t; |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
69 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
70 |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
71 public void run(){ |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
72 String[] array = {"a", "b", "c"}; |
3e2abbf1320d
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) { |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
74 test.run("a", array); |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
75 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
76 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
77 } |
3e2abbf1320d
8159244: Partially initialized string object created by C2's string concat optimization may escape
thartmann
parents:
diff
changeset
|
78 |