# HG changeset patch # User Lukas Stadler # Date 1358958171 -3600 # Node ID 263a666388b13d7a8fae16b0bcbf45b98c394ea4 # Parent 1563a48b798d049898633e8de3676262a0dcb6b4 arraycopy snippets: deopt on NPE and AIOOBE, add probabilities diff -r 1563a48b798d -r 263a666388b1 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 Wed Jan 23 17:21:07 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Wed Jan 23 17:22:51 2013 +0100 @@ -24,6 +24,7 @@ import static com.oracle.graal.api.code.DeoptimizationAction.*; import static com.oracle.graal.api.meta.DeoptimizationReason.*; import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*; +import static com.oracle.graal.snippets.nodes.BranchProbabilityNode.*; import java.lang.reflect.*; import java.util.*; @@ -88,6 +89,7 @@ long srcOffset = (long) srcPos * elementSize; long destOffset = (long) destPos * elementSize; if (src == dest && srcPos < destPos) { // bad aliased case + probability(0.1); for (long i = byteLength - elementSize; i >= byteLength - nonVectorBytes; i -= elementSize) { UnsafeStoreNode.store(dest, header, i + destOffset, UnsafeLoadNode.load(src, header, i + srcOffset, baseKind), baseKind); } @@ -108,13 +110,40 @@ } public static void checkInputs(Object src, int srcPos, Object dest, int destPos, int length) { - if (src == null || dest == null) { + if (src == null) { + probability(0.01); checkNPECounter.inc(); - throw new NullPointerException(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + } + if (dest == null) { + probability(0.01); + checkNPECounter.inc(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + } + if (srcPos < 0) { + probability(0.01); + checkAIOOBECounter.inc(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); } - if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > ArrayLengthNode.arrayLength(src) || destPos + length > ArrayLengthNode.arrayLength(dest)) { + if (destPos < 0) { + probability(0.01); + checkAIOOBECounter.inc(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + } + if (length < 0) { + probability(0.01); checkAIOOBECounter.inc(); - throw new ArrayIndexOutOfBoundsException(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + } + if (srcPos + length > ArrayLengthNode.arrayLength(src)) { + probability(0.01); + checkAIOOBECounter.inc(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + } + if (destPos + length > ArrayLengthNode.arrayLength(dest)) { + probability(0.01); + checkAIOOBECounter.inc(); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); } checkSuccessCounter.inc(); }