Path: blob/master/test/hotspot/jtreg/compiler/macronodes/TestCompleteVolatileStore.java
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 823614026* @requires vm.gc.Serial27* @summary Tests proper rehashing of a captured volatile field StoreL node when completing it.28* @run main/othervm -Xbatch -XX:+UseSerialGC -XX:CompileCommand=compileonly,compiler.macronodes.TestCompleteVolatileStore::test29* compiler.macronodes.TestCompleteVolatileStore30*/3132package compiler.macronodes;3334public class TestCompleteVolatileStore {35int i1 = 4;3637public void test() {38/*39* The store to the volatile field 'l1' (StoreL) of 'a' is captured in the Initialize node of 'a'40* (i.e. additional input to it) and completed in InitializeNode::complete_stores.41* Since 'l1' is volatile, the hash of the StoreL is non-zero triggering the hash assertion failure.42*/43A a = new A();4445// Make sure that the CheckCastPP node of 'a' is used in the input chain of the Intialize node of 'b'46B b = new B(a);4748// Make sure 'b' is non-scalar-replacable to avoid eliminating all allocations49B[] arr = new B[i1];50arr[i1-3] = b;51}5253public static void main(String[] strArr) {54TestCompleteVolatileStore _instance = new TestCompleteVolatileStore();55for (int i = 0; i < 10_000; i++ ) {56_instance.test();57}58}59}6061class A {62// Needs to be volatile to have a non-zero hash for the StoreL node.63volatile long l1;6465A() {66// StoreL gets captured and is later processed in InitializeNode::complete_stores while expanding the allocation node.67this.l1 = 256;68}69}7071class B {72A a;7374B(A a) {75this.a = a;76}77}78798081