# HG changeset patch # User Tom Rodriguez # Date 1430937869 25200 # Node ID 8bae587f0efe954a95390ccf006b6c4e0a7d1c71 # Parent 0777c3a7800df53f401ee6e7145c2c5d868944f8 Add test exercising virtualization of copyOf diff -r 0777c3a7800d -r 8bae587f0efe graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TestCopyOfVirtualization.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TestCopyOfVirtualization.java Wed May 06 11:44:29 2015 -0700 @@ -0,0 +1,152 @@ +/* + * 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. + */ + +package com.oracle.graal.compiler.test; + +import java.util.*; + +import org.junit.*; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.java.*; + +public class TestCopyOfVirtualization extends GraalCompilerTest { + + @Override + protected boolean checkMidTierGraph(StructuredGraph graph) { + assertTrue(graph.getNodes().filter(node -> node instanceof NewArrayNode).count() == 0, "shouldn't require allocation in %s", graph); + return super.checkMidTierGraph(graph); + } + + public byte byteCopyOfVirtualization(int index) { + byte[] array = new byte[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public short shortCopyOfVirtualization(int index) { + short[] array = new short[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public char charCopyOfVirtualization(int index) { + char[] array = new char[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public int intCopyOfVirtualization(int index) { + int[] array = new int[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public long longCopyOfVirtualization(int index) { + long[] array = new long[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public float floatCopyOfVirtualization(int index) { + float[] array = new float[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public double doubleCopyOfVirtualization(int index) { + double[] array = new double[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + public Object objectCopyOfVirtualization(int index) { + Object[] array = new Object[]{1, 2, 3, 4}; + return Arrays.copyOf(array, array.length)[index]; + } + + // @Test + public void testCopyOfVirtualization() { + test("byteCopyOfVirtualization", 3); + test("shortCopyOfVirtualization", 3); + test("charCopyOfVirtualization", 3); + test("intCopyOfVirtualization", 3); + test("longCopyOfVirtualization", 3); + test("floatCopyOfVirtualization", 3); + test("doubleCopyOfVirtualization", 3); + test("objectCopyOfVirtualization", 3); + } + + static final byte[] byteArray = new byte[]{1, 2, 3, 4}; + + public byte byteCopyOfVirtualizableAllocation() { + return Arrays.copyOf(byteArray, byteArray.length)[3]; + } + + static final short[] shortArray = new short[]{1, 2, 3, 4}; + + public short shortCopyOfVirtualizableAllocation() { + return Arrays.copyOf(shortArray, shortArray.length)[3]; + } + + static final char[] charArray = new char[]{1, 2, 3, 4}; + + public char charCopyOfVirtualizableAllocation() { + return Arrays.copyOf(charArray, charArray.length)[3]; + } + + static final int[] intArray = new int[]{1, 2, 3, 4}; + + public int intCopyOfVirtualizableAllocation() { + return Arrays.copyOf(intArray, intArray.length)[3]; + } + + static final long[] longArray = new long[]{1, 2, 3, 4}; + + public long longCopyOfVirtualizableAllocation() { + return Arrays.copyOf(longArray, longArray.length)[3]; + } + + static final float[] floatArray = new float[]{1, 2, 3, 4}; + + public float floatCopyOfVirtualizableAllocation() { + return Arrays.copyOf(floatArray, floatArray.length)[3]; + } + + static final double[] doubleArray = new double[]{1, 2, 3, 4}; + + public double doubleCopyOfVirtualizableAllocation() { + return Arrays.copyOf(doubleArray, doubleArray.length)[3]; + } + + static final Object[] objectArray = new Object[]{1, 2, 3, 4}; + + public Object objectCopyOfVirtualizableAllocation() { + return Arrays.copyOf(objectArray, objectArray.length)[3]; + } + + @Test + public void testCopyOfVirtualizableAllocation() { + test("byteCopyOfVirtualizableAllocation"); + test("shortCopyOfVirtualizableAllocation"); + test("charCopyOfVirtualizableAllocation"); + test("intCopyOfVirtualizableAllocation"); + test("longCopyOfVirtualizableAllocation"); + test("floatCopyOfVirtualizableAllocation"); + test("doubleCopyOfVirtualizableAllocation"); + test("objectCopyOfVirtualizableAllocation"); + } +}