--- /dev/null 2015-06-17 17:39:34.064603000 +0200 +++ new/test/compiler/intrinsics/unsafe/TestUnalignedStoreIThenStoreB.java 2015-09-16 10:30:34.183946606 +0200 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test + * @bug 8136473 + * @summary Mismatched stores on same slice possible with Unsafe.Put*Unaligned methods + * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation TestUnalignedStoreIThenStoreB + * + */ + +import java.lang.reflect.*; +import sun.misc.Unsafe; + +public class TestUnalignedStoreIThenStoreB { + + private static final Unsafe UNSAFE; + + static { + try { + Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + UNSAFE = (Unsafe) unsafeField.get(null); + } + catch (Exception e) { + throw new AssertionError(e); + } + } + + static void test(byte[] array) { + array[0] = 0; + UNSAFE.putIntUnaligned(array, UNSAFE.ARRAY_BYTE_BASE_OFFSET, 0); + array[0] = 0; + } + + + static public void main(String[] args) { + byte[] array = new byte[10]; + for (int i = 0; i < 20000; i++) { + test(array); + } + } +} --- old/src/share/vm/opto/memnode.cpp 2015-09-16 10:30:34.456196540 +0200 +++ new/src/share/vm/opto/memnode.cpp 2015-09-16 10:30:34.158133719 +0200 @@ -2363,6 +2363,16 @@ return NO_HASH; } +#ifdef ASSERT +static bool maybe_unaligned_store(Node* n) { + StoreNode* st = n->as_Store(); + return st->Opcode() == Op_StoreL || + st->Opcode() == Op_StoreI || + st->Opcode() == Op_StoreB || + st->Opcode() == Op_StoreC; +} +#endif + //------------------------------Ideal------------------------------------------ // Change back-to-back Store(, p, x) -> Store(m, p, y) to Store(m, p, x). // When a store immediately follows a relevant allocation/initialization, @@ -2393,7 +2403,8 @@ st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || - (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI), // expanded ClearArrayNode + (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || // expanded ClearArrayNode + (UseUnalignedAccesses && (maybe_unaligned_store(st) || maybe_unaligned_store(this))), err_msg_res("no mismatched stores, except on raw memory: %s %s", NodeClassNames[Opcode()], NodeClassNames[st->Opcode()])); if (st->in(MemNode::Address)->eqv_uncast(address) &&