# HG changeset patch # User Lukas Stadler # Date 1340035313 -7200 # Node ID 419df70cc6a2a1f600f246815d9b9e73e6811e86 # Parent aa52cbbab5980425fb71fb32f4892fd66e0fbe55# Parent 02f76c2ee0f014cf9315a78391414c8e8c82eafe Merge. diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Mon Jun 18 18:00:06 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Mon Jun 18 18:01:53 2012 +0200 @@ -191,7 +191,7 @@ ReadHubNode objectClass = graph.add(new ReadHubNode(receiver)); IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClass, type)); FixedGuardNode guard = graph.add(new FixedGuardNode(isTypeNode, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, invoke.leafGraphId())); - AnchorNode anchor = graph.add(new AnchorNode()); + ValueAnchorNode anchor = graph.add(new ValueAnchorNode()); assert invoke.predecessor() != null; ValueNode anchoredReceiver = createAnchoredReceiver(graph, anchor, type, receiver); diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Mon Jun 18 18:00:06 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Mon Jun 18 18:01:53 2012 +0200 @@ -28,11 +28,43 @@ import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; +import com.oracle.graal.snippets.Snippet.ConstantParameter; import com.oracle.graal.snippets.Snippet.Fold; @SuppressWarnings("unused") public class ArrayCopySnippets implements SnippetsInterface{ + private static final Kind VECTOR_KIND = Kind.Long; + private static final long VECTOR_SIZE = arrayIndexScale(Kind.Long); + + //@Snippet + public static void vectorizedCopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantParameter("baseKind") Kind baseKind) { + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); + if (src == dest && srcPos < destPos) { // bad aliased case + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } + } else { + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } + } + } @Snippet public static void arraycopy(byte[] src, int srcPos, byte[] dest, int destPos, int length) { @@ -42,34 +74,30 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } - + Kind baseKind = Kind.Byte; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - if ((length & 0x04) == 0) { - copyLongsDown(src, srcPos, dest, destPos, length >> 3); - } else { - copyIntsDown(src, srcPos, dest, destPos, length >> 2); - } - } else { - copyShortsDown(src, srcPos, dest, destPos, length >> 1); - } - } else { - copyBytesDown(src, srcPos, dest, destPos, length); + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } else { - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - if ((length & 0x04) == 0) { - copyLongsUp(src, srcPos, dest, destPos, length >> 3); - } else { - copyIntsUp(src, srcPos, dest, destPos, length >> 2); - } - } else { - copyShortsUp(src, srcPos, dest, destPos, length >> 1); - } - } else { - copyBytesUp(src, srcPos, dest, destPos, length); + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } } @@ -82,25 +110,30 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Char; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - copyLongsDown(src, srcPos * 2L, dest, destPos * 2L, length >> 2); - } else { - copyIntsDown(src, srcPos * 2L, dest, destPos * 2L, length >> 1); - } - } else { - copyShortsDown(src, srcPos * 2L, dest, destPos * 2L, length); + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } else { - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - copyLongsUp(src, srcPos * 2L, dest, destPos * 2L, length >> 2); - } else { - copyIntsUp(src, srcPos * 2L, dest, destPos * 2L, length >> 1); - } - } else { - copyShortsUp(src, srcPos * 2L, dest, destPos * 2L, length); + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } } @@ -113,25 +146,30 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Short; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - copyLongsDown(src, srcPos * 2L, dest, destPos * 2L, length >> 2); - } else { - copyIntsDown(src, srcPos * 2L, dest, destPos * 2L, length >> 1); - } - } else { - copyShortsDown(src, srcPos * 2L, dest, destPos * 2L, length); + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } else { - if ((length & 0x01) == 0) { - if ((length & 0x02) == 0) { - copyLongsUp(src, srcPos * 2L, dest, destPos * 2L, length >> 2); - } else { - copyIntsUp(src, srcPos * 2L, dest, destPos * 2L, length >> 1); - } - } else { - copyShortsUp(src, srcPos * 2L, dest, destPos * 2L, length); + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } } @@ -144,17 +182,30 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Int; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - if ((length & 0x01) == 0) { - copyLongsDown(src, srcPos * 4L, dest, destPos * 4L, length >> 1); - } else { - copyIntsDown(src, srcPos * 4L, dest, destPos * 4L, length); + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } else { - if ((length & 0x01) == 0) { - copyLongsUp(src, srcPos * 4L, dest, destPos * 4L, length >> 1); - } else { - copyIntsUp(src, srcPos * 4L, dest, destPos * 4L, length); + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } } @@ -167,17 +218,30 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Float; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long nonVectorBytes = byteLength % VECTOR_SIZE; + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - if ((length & 0x01) == 0) { - copyLongsDown(src, srcPos * 4L, dest, destPos * 4L, length >> 1); - } else { - copyIntsDown(src, srcPos * 4L, dest, destPos * 4L, length); + for (long i = byteLength - 1; i > byteLength - 1 - nonVectorBytes; i--) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + long vectorLength = byteLength - nonVectorBytes; + for (long i = vectorLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } else { - if ((length & 0x01) == 0) { - copyLongsUp(src, srcPos * 4L, dest, destPos * 4L, length >> 1); - } else { - copyIntsUp(src, srcPos * 4L, dest, destPos * 4L, length); + for (long i = 0; i < nonVectorBytes; i++) { + Byte a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Byte); + UnsafeStoreNode.store(dest, header, i + destOffset, a.byteValue(), Kind.Byte); + } + for (long i = nonVectorBytes; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); } } } @@ -190,10 +254,21 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Long; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - copyLongsDown(src, srcPos * 8L, dest, destPos * 8L, length); + for (long i = byteLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } } else { - copyLongsUp(src, srcPos * 8L, dest, destPos * 8L, length); + for (long i = 0; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } } } @@ -205,10 +280,21 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + Kind baseKind = Kind.Double; + int header = arrayBaseOffset(baseKind); + long byteLength = length * arrayIndexScale(baseKind); + long srcOffset = srcPos * arrayIndexScale(baseKind); + long destOffset = destPos * arrayIndexScale(baseKind); if (src == dest && srcPos < destPos) { // bad aliased case - copyLongsDown(src, srcPos * 8L, dest, destPos * 8L, length); + for (long i = byteLength - VECTOR_SIZE; i >= 0; i -= VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } } else { - copyLongsUp(src, srcPos * 8L, dest, destPos * 8L, length); + for (long i = 0; i < byteLength; i += VECTOR_SIZE) { + Long a = UnsafeLoadNode.load(src, header, i + srcOffset, VECTOR_KIND); + UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), VECTOR_KIND); + } } } @@ -241,42 +327,6 @@ } } - @Snippet - public static void copyBytesDown(Object src, int srcPos, Object dest, int destPos, int length) { - int header = arrayBaseOffset(Kind.Byte); - for (long i = length - 1; i >= 0; i--) { - Byte a = UnsafeLoadNode.load(src, header, i + srcPos, Kind.Byte); - UnsafeStoreNode.store(dest, header, i + destPos, a.byteValue(), Kind.Byte); - } - } - - @Snippet - public static void copyShortsDown(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Short); - for (long i = (length - 1) * 2; i >= 0; i -= 2) { - Character a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Short); - UnsafeStoreNode.store(dest, header, i + destOffset, a.charValue(), Kind.Short); - } - } - - @Snippet - public static void copyIntsDown(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Int); - for (long i = (length - 1) * 4; i >= 0; i -= 4) { - Integer a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Int); - UnsafeStoreNode.store(dest, header, i + destOffset, a.intValue(), Kind.Int); - } - } - - @Snippet - public static void copyLongsDown(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Long); - for (long i = (length - 1) * 8; i >= 0; i -= 8) { - Long a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Long); - UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), Kind.Long); - } - } - // Does NOT perform store checks @Snippet public static void copyObjectsDown(Object src, long srcOffset, Object dest, long destOffset, int length) { @@ -287,57 +337,6 @@ DirectObjectStoreNode.store(dest, header, i + destOffset, a); } } - /** - * Copies {@code length} bytes from {@code src} starting at {@code srcPos} to {@code dest} starting at {@code destPos}. - * @param src source object - * @param srcPos source offset - * @param dest destination object - * @param destPos destination offset - * @param length number of bytes to copy - */ - @Snippet - public static void copyBytesUp(Object src, int srcPos, Object dest, int destPos, int length) { - int header = arrayBaseOffset(Kind.Byte); - for (long i = 0; i < length; i++) { - Byte a = UnsafeLoadNode.load(src, header, i + srcPos, Kind.Byte); - UnsafeStoreNode.store(dest, header, i + destPos, a.byteValue(), Kind.Byte); - } - } - - /** - * Copies {@code length} shorts from {@code src} starting at offset {@code srcOffset} (in bytes) to {@code dest} starting at offset {@code destOffset} (in bytes). - * @param src - * @param srcOffset (in bytes) - * @param dest - * @param destOffset (in bytes) - * @param length (in shorts) - */ - @Snippet - public static void copyShortsUp(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Short); - for (long i = 0; i < length * 2L; i += 2) { - Character a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Short); - UnsafeStoreNode.store(dest, header, i + destOffset, a.charValue(), Kind.Short); - } - } - - @Snippet - public static void copyIntsUp(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Int); - for (long i = 0; i < length * 4L; i += 4) { - Integer a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Int); - UnsafeStoreNode.store(dest, header, i + destOffset, a.intValue(), Kind.Int); - } - } - - @Snippet - public static void copyLongsUp(Object src, long srcOffset, Object dest, long destOffset, int length) { - int header = arrayBaseOffset(Kind.Long); - for (long i = 0; i < length * 8L; i += 8) { - Long a = UnsafeLoadNode.load(src, header, i + srcOffset, Kind.Long); - UnsafeStoreNode.store(dest, header, i + destOffset, a.longValue(), Kind.Long); - } - } // Does NOT perform store checks @Snippet diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/optimize/ArrayCopy04.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/optimize/ArrayCopy04.java Mon Jun 18 18:01:53 2012 +0200 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2011, 2012, 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.jtt.optimize; + +import org.junit.*; + +/* + * Tests calls to the array copy method. + */ +public class ArrayCopy04 { + + public static byte[] array = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + public static byte[] array0 = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + @Before + public void setUp() { + System.currentTimeMillis(); + for (int i = 0; i < array.length; i++) { + array[i] = array0[i]; + } + } + + public static byte[] test(int srcPos, int destPos, int length) { + System.arraycopy(array, srcPos, array, destPos, length); + return array; + } + + @Test + public void run0() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(0, 0, 0)); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run1() throws Throwable { + test(0, 0, -1); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run2() throws Throwable { + test(-1, 0, 0); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run3() throws Throwable { + test(0, -1, 0); + } + + @Test + public void run4() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(0, 0, 2)); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run5() throws Throwable { + test(0, 1, 11); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run6() throws Throwable { + test(1, 0, 11); + } + + @Test(expected = java.lang.IndexOutOfBoundsException.class) + public void run7() throws Throwable { + test(1, 1, -1); + } + + @Test + public void run8() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10}, test(0, 1, 2)); + } + + @Test + public void run9() throws Throwable { + Assert.assertArrayEquals(new byte[] {1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(1, 0, 2)); + } + + @Test + public void run10() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(1, 1, 2)); + } + + @Test + public void run11() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(0, 0, 6)); + } + + @Test + public void run12() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 0, 1, 2, 3, 4, 6, 7, 8, 9, 10}, test(0, 1, 5)); + } + + @Test + public void run13() throws Throwable { + Assert.assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10}, test(1, 0, 5)); + } + + @Test + public void run14() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(1, 1, 5)); + } + + @Test + public void run15() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, test(0, 0, 11)); + } + + @Test + public void run16() throws Throwable { + Assert.assertArrayEquals(new byte[] {0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, test(0, 1, 10)); + } + + @Test + public void run17() throws Throwable { + Assert.assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10}, test(1, 0, 10)); + } +} diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AnchorNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AnchorNode.java Mon Jun 18 18:00:06 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2009, 2011, 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.nodes; - -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; - -/** - * The {@code AnchorNode} can be used a lower bound for a guard. It can also be used as an upper bound if no other FixedNode can be used for that purpose. - * The guards that should be kept above this node need to be added to the {@link #dependencies()} collection. - */ -public final class AnchorNode extends FixedWithNextNode implements LIRLowerable, Canonicalizable { - - public AnchorNode() { - super(StampFactory.dependency()); - } - - @Override - public ValueNode canonical(CanonicalizerTool tool) { - if (this.usages().size() == 0 && dependencies().isEmpty()) { - return null; - } - return this; - } - - @Override - public void generate(LIRGeneratorTool gen) { - // Currently, there is nothing to emit since anchors are only a structural element with no execution semantics. - } -} diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java Mon Jun 18 18:00:06 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java Mon Jun 18 18:01:53 2012 +0200 @@ -93,8 +93,7 @@ @Override public void lower(CiLoweringTool tool) { - ValueAnchorNode newAnchor = graph().add(new ValueAnchorNode()); - newAnchor.addAnchoredNode(tool.createGuard(condition, deoptReason, action, negated, leafGraphId)); + ValueAnchorNode newAnchor = graph().add(new ValueAnchorNode(tool.createGuard(condition, deoptReason, action, negated, leafGraphId))); ((StructuredGraph) graph()).replaceFixedWithFixed(this, newAnchor); } diff -r aa52cbbab598 -r 419df70cc6a2 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Mon Jun 18 18:00:06 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Mon Jun 18 18:01:53 2012 +0200 @@ -52,20 +52,16 @@ } @Override - public boolean verify() { - assertTrue(usages().isEmpty(), "upwards dependencies should target BeginNodes only"); - return super.verify(); - } - - @Override public ValueNode canonical(CanonicalizerTool tool) { if (this.predecessor() instanceof ValueAnchorNode) { - // transfer values and remove ValueAnchorNode previousAnchor = (ValueAnchorNode) this.predecessor(); - for (ValueNode node : dependencies().nonNull().distinct()) { - previousAnchor.addAnchoredNode(node); + if (previousAnchor.usages().isEmpty()) { // avoid creating cycles + // transfer values and remove + for (ValueNode node : dependencies().nonNull().distinct()) { + previousAnchor.addAnchoredNode(node); + } + return previousAnchor; } - return null; } for (Node node : dependencies().nonNull().and(isNotA(BeginNode.class))) { if (node instanceof ConstantNode) { @@ -83,6 +79,9 @@ } return this; // still necessary } - return null; // no node which require an anchor found + if (usages().isEmpty()) { + return null; // no node which require an anchor found + } + return this; } }