From b0639e28978885a75add627ff83fe22a8521ab1c Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Wed, 13 Mar 2024 09:57:54 +0100 Subject: [PATCH 1/4] 8327012 --- ...TestEliminationOfAllocationWithoutUse.java | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java diff --git a/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java b/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java new file mode 100644 index 0000000000000..1b3c9b01b7e69 --- /dev/null +++ b/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2024, 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 8327012 + * @summary Revealed issue where hook_memory_on_init links some array slice to the rawptr slice. + * Now that array slice depends on the rawslice. And then when the Initialize MemBar gets + * removed in expand_allocate_common, the rawslice sees that it has now no effect, looks + * through the MergeMem and sees the initial stae. That way, also the linked array slice + * goes to the initial state, even if before the allocation there were stores on the array + * slice. This leads to a messed up memory graph, and missing stores in the generated code. + * + * @run main/othervm -Xcomp -XX:-TieredCompilation + * -XX:CompileCommand=compileonly,compiler.macronodes.TestEliminationOfAllocationWithoutUse::test* + * compiler.macronodes.TestEliminationOfAllocationWithoutUse + */ + +package compiler.macronodes; + +public class TestEliminationOfAllocationWithoutUse { + + static public void main(String[] args) { + int failures = 0; + failures += run1(); + failures += run2(); + failures += run3(); + if (failures != 0) { + throw new RuntimeException("Had test failures: " + failures); + } + } + + static public int run1() { + int size = 10; + double[] arr1 = new double[size]; + double[] arr2 = new double[size]; + test1(arr1, arr2); + + double sum = 0; + for(int i = 0; i < arr1.length; ++i) { + sum += arr1[i] - arr2[i]; + } + + if (sum != (double)(size)) { + System.out.println("test1: wrong result: " + sum + " vs expected: " + size); + return 1; + } + return 0; + } + + // Simplified from JDK-8327012 regression test. + public static void test1(double[] arr1, double[] arr2) { + for(int i = 0; i < arr1.length; ++i) { + // stores on double[] slice + arr1[i] = (double)(i + 2); + arr2[i] = (double)(i + 1); + // Allocation without use: but Initialize MemBar tangles the rawptr and double[] slices + double[] tmp = new double[100]; + // When the Initialize MemBar is removed, the rawptr slice sees that there is no effect + // and takes the initial state. The double[] slice is hooked on to the rawptr slice, and + // also thinks it has the initial state, ignoring the double[] stores above. + } + } + + static public int run2() { + int size = 10; + double[] arr1 = new double[size]; + test2(arr1); + + double sum = 0; + for(int i = 0; i < arr1.length; ++i) { + sum += arr1[i]; + } + + if (sum != (double)(size)) { + System.out.println("test2: wrong result: " + sum + " vs expected: " + size); + return 1; + } + return 0; + } + + // Simplified from test1 + public static void test2(double[] arr1) { + for(int i = 0; i < arr1.length; ++i) { + arr1[i] = 1; + double[] tmp = new double[100]; + } + } + + static public int run3() { + int size = 10; + int[] arr1 = new int[size]; + test3(arr1); + + int sum = 0; + for(int i = 0; i < arr1.length; ++i) { + sum += arr1[i]; + } + + if (sum != size) { + System.out.println("test3: wrong result: " + sum + " vs expected: " + size); + return 1; + } + return 0; + } + + // Modified from test2 + public static void test3(int[] arr1) { + for(int i = 0; i < arr1.length; ++i) { + arr1[i] = 1; + int[] tmp = new int[100]; + } + } + +} From 05395d7204bc8a43f8628b911f11d4399169e115 Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Wed, 13 Mar 2024 10:06:48 +0100 Subject: [PATCH 2/4] test4 --- ...TestEliminationOfAllocationWithoutUse.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java b/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java index 1b3c9b01b7e69..9e1216b4874e8 100644 --- a/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java +++ b/test/hotspot/jtreg/compiler/macronodes/TestEliminationOfAllocationWithoutUse.java @@ -45,6 +45,7 @@ static public void main(String[] args) { failures += run1(); failures += run2(); failures += run3(); + failures += run4(); if (failures != 0) { throw new RuntimeException("Had test failures: " + failures); } @@ -132,4 +133,27 @@ public static void test3(int[] arr1) { } } + // From TestIncorrectResult.java in JDK-8324739 + static int test4(int l2) { + int[] tmp = new int[20]; + + for (int j = 0; j < l2; ++j) { + tmp[j] = 42; + int[] unused_but_necessary = new int[400]; + } + + return tmp[0]; + } + + public static int run4() { + for (int i = 0; i < 100; ++i) { + long res = test4(20); + + if (res != 42) { + System.out.println("test4: wrong result: " + res + " vs expected: 42"); + return 1; + } + } + return 0; + } } From 2c0349f9330a83d73985e6054b5604c63bfa02b7 Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Wed, 24 Apr 2024 21:53:58 +0200 Subject: [PATCH 3/4] initializing store capturing: test stub --- .../TestInitializingStoreCapturing.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java diff --git a/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java b/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java new file mode 100644 index 0000000000000..e4955fe0c1089 --- /dev/null +++ b/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, 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 8327012 + * @summary Test that initializing store gets captured, i.e. moved before the InitializeNode + * and made into a raw-store. + * + * @run driver compiler.macronodes.TestInitializingStoreCapturing + */ + +package compiler.macronodes; + +public class TestInitializingStoreCapturing { + + static public void main(String[] args) { + } + +} + From 675eebb9d46bc3f8f4f2165a559ef067bd5f8290 Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Thu, 25 Apr 2024 09:26:13 +0200 Subject: [PATCH 4/4] more tests, WIP --- .../TestInitializingStoreCapturing.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java b/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java index e4955fe0c1089..8d93e9b99ffb3 100644 --- a/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java +++ b/test/hotspot/jtreg/compiler/macronodes/TestInitializingStoreCapturing.java @@ -26,16 +26,35 @@ * @bug 8327012 * @summary Test that initializing store gets captured, i.e. moved before the InitializeNode * and made into a raw-store. - * + * @library /test/lib / * @run driver compiler.macronodes.TestInitializingStoreCapturing */ package compiler.macronodes; +import compiler.lib.ir_framework.*; + public class TestInitializingStoreCapturing { + static class A { + float value; + A(float v) { value = v; } + }; + static public void main(String[] args) { + TestFramework.run(); } + @Test + @IR(counts = {IRNode.STE, "= 0"}) + static A testInitializeField() { + return new A(4.2f); + } + + @Test + @IR(counts = {IRNode.STORE, "= 0"}) + static float[] testInitializeArray() { + return new float[] {4.2f}; + } }