# HG changeset patch # User thartmann # Date 1467007851 -7200 # Node ID 173a1f83c930134bf2696680754b99162e411c63 # Parent f22b5be95347c669a1463d9e05ec3bf11420208e 8160122: Backport of JDK-8159244 used wrong version of the JDK 9 fix Summary: Correct backport of 8159244. Reviewed-by: kvn diff -r f22b5be95347 -r 173a1f83c930 src/share/vm/opto/stringopts.cpp --- a/src/share/vm/opto/stringopts.cpp Sat Jun 25 20:03:17 2016 +0100 +++ b/src/share/vm/opto/stringopts.cpp Mon Jun 27 08:10:51 2016 +0200 @@ -1641,16 +1641,11 @@ } kit.store_String_value(kit.control(), result, char_array); - // Do not let stores that initialize this object be reordered with - // a subsequent store that would make this object accessible by - // other threads. - // Record what AllocateNode this StoreStore protects so that - // escape analysis can go from the MemBarStoreStoreNode to the - // AllocateNode and eliminate the MemBarStoreStoreNode if possible - // based on the escape status of the AllocateNode. - AllocateNode* alloc = AllocateNode::Ideal_allocation(result, _gvn); - assert(alloc != NULL, "should be newly allocated"); - kit.insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); + // The value field is final. Emit a barrier here to ensure that the effect + // of the initialization is committed to memory before any code publishes + // a reference to the newly constructed object (see Parse::do_exits()). + assert(AllocateNode::Ideal_allocation(result, _gvn) != NULL, "should be newly allocated"); + kit.insert_mem_bar(Op_MemBarRelease, result); } else { result = C->top(); } diff -r f22b5be95347 -r 173a1f83c930 test/compiler/stringopts/TestStringObjectInitialization.java --- a/test/compiler/stringopts/TestStringObjectInitialization.java Sat Jun 25 20:03:17 2016 +0100 +++ b/test/compiler/stringopts/TestStringObjectInitialization.java Mon Jun 27 08:10:51 2016 +0200 @@ -27,6 +27,7 @@ /* * @test * @bug 8159244 + * @requires vm.gc == "Parallel" | vm.gc == "null" * @summary Verifies that no partially initialized String object escapes from * C2's String concat optimization in a highly concurrent setting. * This test triggers the bug in about 1 out of 10 runs.