|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Red Hat, Inc. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +package compiler.c2; |
| 25 | + |
| 26 | +import compiler.lib.ir_framework.*; |
| 27 | +import jdk.internal.misc.Unsafe; |
| 28 | + |
| 29 | +/* |
| 30 | + * @test |
| 31 | + * @bug 8343068 |
| 32 | + * @summary C2: CastX2P Ideal transformation not always applied |
| 33 | + * @modules java.base/jdk.internal.misc |
| 34 | + * @library /test/lib / |
| 35 | + * @run driver compiler.c2.TestCastX2NotProcessedIGVN |
| 36 | + */ |
| 37 | + |
| 38 | +public class TestCastX2NotProcessedIGVN { |
| 39 | + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
| 40 | + static int size = 1024; |
| 41 | + static long base = UNSAFE.allocateMemory(4 * size); |
| 42 | + |
| 43 | + |
| 44 | + public static void main(String[] args) { |
| 45 | + TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + @IR(failOn = IRNode.ADD_L, counts = {IRNode.ADD_P, "1"}) |
| 50 | + public static byte test1(long base) { |
| 51 | + int offset = 0; |
| 52 | + do { |
| 53 | + offset++; |
| 54 | + } while (offset < 100); |
| 55 | + long longOffset = ((long) offset) * 2; |
| 56 | + return UNSAFE.getByte(null, base + longOffset); |
| 57 | + } |
| 58 | + |
| 59 | + @Run(test = "test1") |
| 60 | + public static void test1Runner() { |
| 61 | + test1(base); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + @IR(counts = {IRNode.LOAD_VECTOR_I, "> 1"}) |
| 66 | + public static int test2(int stop, int[] array) { |
| 67 | + int v = 0; |
| 68 | + stop = Math.min(stop, Integer.MAX_VALUE / 4); |
| 69 | + for (int i = 0; i < stop; i++) { |
| 70 | + long offset = ((long)i) * 4; |
| 71 | + array[i] = UNSAFE.getInt(null, offset + base); |
| 72 | + } |
| 73 | + return v; |
| 74 | + } |
| 75 | + |
| 76 | + @Run(test = "test2") |
| 77 | + public static void test2Runner() { |
| 78 | + test2(size, new int[size]); |
| 79 | + } |
| 80 | +} |
0 commit comments