|
|
8f84c8 |
# HG changeset patch
|
|
|
8f84c8 |
# User thartmann
|
|
|
8f84c8 |
# Date 1468206230 -3600
|
|
|
8f84c8 |
# Mon Jul 11 04:03:50 2016 +0100
|
|
|
8f84c8 |
# Node ID 7c89f7f3f2c57d64970cc2ae3a81d24765830118
|
|
|
8f84c8 |
# Parent 4b40867e627dd9043bc67a4795caa9834ef69478
|
|
|
8f84c8 |
8159244, PR3074: Partially initialized string object created by C2's string concat optimization may escape
|
|
|
8f84c8 |
Summary: Emit release barrier after String creation to prevent partially initialized object from escaping.
|
|
|
8f84c8 |
Reviewed-by: kvn
|
|
|
8f84c8 |
|
|
|
8f84c8 |
diff -r 4b40867e627d -r 7c89f7f3f2c5 src/share/vm/opto/stringopts.cpp
|
|
|
8f84c8 |
--- openjdk/hotspot/src/share/vm/opto/stringopts.cpp Fri Jun 17 11:31:24 2016 +0200
|
|
|
8f84c8 |
+++ openjdk/hotspot/src/share/vm/opto/stringopts.cpp Mon Jul 11 04:03:50 2016 +0100
|
|
|
8f84c8 |
@@ -1,5 +1,5 @@
|
|
|
8f84c8 |
/*
|
|
|
8f84c8 |
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
|
8f84c8 |
+ * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
|
8f84c8 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
8f84c8 |
*
|
|
|
8f84c8 |
* This code is free software; you can redistribute it and/or modify it
|
|
|
8f84c8 |
@@ -1640,6 +1640,12 @@
|
|
|
8f84c8 |
kit.store_String_length(kit.control(), result, length);
|
|
|
8f84c8 |
}
|
|
|
8f84c8 |
kit.store_String_value(kit.control(), result, char_array);
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ // The value field is final. Emit a barrier here to ensure that the effect
|
|
|
8f84c8 |
+ // of the initialization is committed to memory before any code publishes
|
|
|
8f84c8 |
+ // a reference to the newly constructed object (see Parse::do_exits()).
|
|
|
8f84c8 |
+ assert(AllocateNode::Ideal_allocation(result, _gvn) != NULL, "should be newly allocated");
|
|
|
8f84c8 |
+ kit.insert_mem_bar(Op_MemBarRelease, result);
|
|
|
8f84c8 |
} else {
|
|
|
8f84c8 |
result = C->top();
|
|
|
8f84c8 |
}
|
|
|
8f84c8 |
diff -r 4b40867e627d -r 7c89f7f3f2c5 test/compiler/stringopts/TestStringObjectInitialization.java
|
|
|
8f84c8 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
|
|
|
8f84c8 |
+++ openjdk/hotspot/test/compiler/stringopts/TestStringObjectInitialization.java Mon Jul 11 04:03:50 2016 +0100
|
|
|
8f84c8 |
@@ -0,0 +1,78 @@
|
|
|
8f84c8 |
+/*
|
|
|
8f84c8 |
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
|
8f84c8 |
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
8f84c8 |
+ *
|
|
|
8f84c8 |
+ * This code is free software; you can redistribute it and/or modify it
|
|
|
8f84c8 |
+ * under the terms of the GNU General Public License version 2 only, as
|
|
|
8f84c8 |
+ * published by the Free Software Foundation.
|
|
|
8f84c8 |
+ *
|
|
|
8f84c8 |
+ * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
8f84c8 |
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
8f84c8 |
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
8f84c8 |
+ * version 2 for more details (a copy is included in the LICENSE file that
|
|
|
8f84c8 |
+ * accompanied this code).
|
|
|
8f84c8 |
+ *
|
|
|
8f84c8 |
+ * You should have received a copy of the GNU General Public License version
|
|
|
8f84c8 |
+ * 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
8f84c8 |
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
8f84c8 |
+ *
|
|
|
8f84c8 |
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
8f84c8 |
+ * or visit www.oracle.com if you need additional information or have any
|
|
|
8f84c8 |
+ * questions.
|
|
|
8f84c8 |
+ */
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+import java.util.Arrays;
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+/*
|
|
|
8f84c8 |
+ * @test
|
|
|
8f84c8 |
+ * @bug 8159244
|
|
|
8f84c8 |
+ * @requires vm.gc == "Parallel" | vm.gc == "null"
|
|
|
8f84c8 |
+ * @summary Verifies that no partially initialized String object escapes from
|
|
|
8f84c8 |
+ * C2's String concat optimization in a highly concurrent setting.
|
|
|
8f84c8 |
+ * This test triggers the bug in about 1 out of 10 runs.
|
|
|
8f84c8 |
+ * @compile -XDstringConcat=inline TestStringObjectInitialization.java
|
|
|
8f84c8 |
+ * @run main/othervm/timeout=300 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-CompactStrings
|
|
|
8f84c8 |
+ * -XX:-UseG1GC -XX:+UseParallelGC TestStringObjectInitialization
|
|
|
8f84c8 |
+ */
|
|
|
8f84c8 |
+public class TestStringObjectInitialization {
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ String myString;
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ public static void main(String[] args) throws Exception {
|
|
|
8f84c8 |
+ TestStringObjectInitialization t = new TestStringObjectInitialization();
|
|
|
8f84c8 |
+ // Create some threads that concurrently update 'myString'
|
|
|
8f84c8 |
+ for (int i = 0; i < 100; ++i) {
|
|
|
8f84c8 |
+ (new Thread(new Runner(t))).start();
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+ Thread last = new Thread(new Runner(t));
|
|
|
8f84c8 |
+ last.start();
|
|
|
8f84c8 |
+ last.join();
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ private void add(String message) {
|
|
|
8f84c8 |
+ // String escapes to other threads here
|
|
|
8f84c8 |
+ myString += message;
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ public void run(String s, String[] sArray) {
|
|
|
8f84c8 |
+ // Trigger C2's string concatenation optimization
|
|
|
8f84c8 |
+ add(s + Arrays.toString(sArray) + " const ");
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+}
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+class Runner implements Runnable {
|
|
|
8f84c8 |
+ private TestStringObjectInitialization test;
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ public Runner(TestStringObjectInitialization t) {
|
|
|
8f84c8 |
+ test = t;
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+
|
|
|
8f84c8 |
+ public void run(){
|
|
|
8f84c8 |
+ String[] array = {"a", "b", "c"};
|
|
|
8f84c8 |
+ for (int i = 0; i < 10000; ++i) {
|
|
|
8f84c8 |
+ test.run("a", array);
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+ }
|
|
|
8f84c8 |
+}
|
|
|
8f84c8 |
+
|