# HG changeset patch # User Roland Schatz # Date 1371124229 -7200 # Node ID 85f926430ae6dcd701d66cb9743b04f12c2204a9 # Parent 839791e70ff1e345e9e135540b83692bc0c386f9 Test deoptimization in DynamicNewArrayNode. diff -r 839791e70ff1 -r 85f926430ae6 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Jun 13 13:19:56 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Jun 13 13:50:29 2013 +0200 @@ -358,7 +358,7 @@ test(method, expect, Collections. emptySet(), receiver, args); } - protected void test(Method method, Result expect, Set shouldNotDeopt, Object receiver, Object... args) { + protected Result executeActualCheckDeopt(Method method, Set shouldNotDeopt, Object receiver, Object... args) { Map deoptCounts = new EnumMap<>(DeoptimizationReason.class); ProfilingInfo profile = runtime.lookupJavaMethod(method).getProfilingInfo(); for (DeoptimizationReason reason : shouldNotDeopt) { @@ -368,7 +368,10 @@ for (DeoptimizationReason reason : shouldNotDeopt) { Assert.assertEquals((int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason)); } + return actual; + } + protected void assertEquals(Result expect, Result actual) { if (expect.exception != null) { Assert.assertTrue("expected " + expect.exception, actual.exception != null); Assert.assertEquals(expect.exception.getClass(), actual.exception.getClass()); @@ -382,6 +385,11 @@ } } + protected void test(Method method, Result expect, Set shouldNotDeopt, Object receiver, Object... args) { + Result actual = executeActualCheckDeopt(method, shouldNotDeopt, receiver, args); + assertEquals(expect, actual); + } + private Map cache = new HashMap<>(); /** diff -r 839791e70ff1 -r 85f926430ae6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Thu Jun 13 13:19:56 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Thu Jun 13 13:50:29 2013 +0200 @@ -126,7 +126,7 @@ Word hub = loadWordFromObject(elementType, arrayKlassOffset()); if (hub.equal(Word.zero())) { // the array class is not yet loaded - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); + DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.Unresolved); } int layoutHelper = readLayoutHelper(hub); diff -r 839791e70ff1 -r 85f926430ae6 graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/DynamicNewArrayTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/DynamicNewArrayTest.java Thu Jun 13 13:19:56 2013 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/DynamicNewArrayTest.java Thu Jun 13 13:50:29 2013 +0200 @@ -23,9 +23,11 @@ package com.oracle.graal.replacements.test; import java.lang.reflect.*; +import java.util.*; import org.junit.*; +import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.test.*; /** @@ -33,6 +35,9 @@ */ public class DynamicNewArrayTest extends GraalCompilerTest { + private class Element { + } + @Test public void test1() { test("test1snippet"); @@ -63,6 +68,16 @@ test("dynamic", null, 5); } + @Test + public void test7() { + Method method = getMethod("dynamic"); + Result actual1 = executeActual(method, null, Element.class, 7); + Result actual2 = executeActualCheckDeopt(method, Collections. singleton(DeoptimizationReason.Unresolved), null, Element.class, 7); + Result expected = executeExpected(method, null, Element.class, 7); + assertEquals(actual1, expected); + assertEquals(actual2, expected); + } + public static Object test1snippet() { return Array.newInstance(Integer.class, 7); }