# HG changeset patch # User Christian Haeubl # Date 1364471713 -3600 # Node ID 02ef91b94656e3af98a1dc0bc475a96a90ce09eb # Parent 6c4db417385afa70686ead0477fd72d9b5bcbd7c finished ProfilingInfo testcases diff -r 6c4db417385a -r 02ef91b94656 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java Wed Mar 27 17:25:59 2013 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java Thu Mar 28 12:55:13 2013 +0100 @@ -40,21 +40,33 @@ public void testBranchTakenProbability() { ProfilingInfo info = profile("branchProbabilitySnippet", 0); assertEquals(0.0, info.getBranchTakenProbability(1)); - assertEquals(100, info.getExecutionCount(1)); + assertEquals(N, info.getExecutionCount(1)); assertEquals(-1.0, info.getBranchTakenProbability(8)); assertEquals(0, info.getExecutionCount(8)); info = profile("branchProbabilitySnippet", 1); assertEquals(1.0, info.getBranchTakenProbability(1)); - assertEquals(100, info.getExecutionCount(1)); + assertEquals(N, info.getExecutionCount(1)); assertEquals(0.0, info.getBranchTakenProbability(8)); - assertEquals(100, info.getExecutionCount(8)); + assertEquals(N, info.getExecutionCount(8)); info = profile("branchProbabilitySnippet", 2); assertEquals(1.0, info.getBranchTakenProbability(1)); - assertEquals(100, info.getExecutionCount(1)); + assertEquals(N, info.getExecutionCount(1)); + assertEquals(1.0, info.getBranchTakenProbability(8)); + assertEquals(N, info.getExecutionCount(8)); + + continueProfiling(3 * N, "branchProbabilitySnippet", 0); + assertEquals(0.25, info.getBranchTakenProbability(1)); + assertEquals(4 * N, info.getExecutionCount(1)); assertEquals(1.0, info.getBranchTakenProbability(8)); - assertEquals(100, info.getExecutionCount(8)); + assertEquals(N, info.getExecutionCount(8)); + + resetProfile("branchProbabilitySnippet"); + assertEquals(-1.0, info.getBranchTakenProbability(1)); + assertEquals(0, info.getExecutionCount(1)); + assertEquals(-1.0, info.getBranchTakenProbability(8)); + assertEquals(0, info.getExecutionCount(8)); } public static int branchProbabilitySnippet(int value) { @@ -77,6 +89,9 @@ info = profile("switchProbabilitySnippet", 2); assertEquals(new double[]{0.0, 0.0, 1.0}, info.getSwitchProbabilities(1)); + + resetProfile("switchProbabilitySnippet"); + assertNull(info.getSwitchProbabilities(1)); } public static int switchProbabilitySnippet(int value) { @@ -145,32 +160,52 @@ assertEquals(stringBuilderType, typeProfile.getTypes()[1].getType()); assertEquals(0.5, typeProfile.getTypes()[0].getProbability()); assertEquals(0.5, typeProfile.getTypes()[1].getProbability()); + + resetProfile(methodName); + typeProfile = info.getTypeProfile(bci); + assertNull(typeProfile); } @Test public void testExceptionSeen() { - ProfilingInfo info = profile("nullPointerExceptionSnippet", (Object) null); + // NullPointerException + ProfilingInfo info = profile("nullPointerExceptionSnippet", 5); + assertEquals(TriState.FALSE, info.getExceptionSeen(1)); + + info = profile("nullPointerExceptionSnippet", (Object) null); assertEquals(TriState.TRUE, info.getExceptionSeen(1)); - info = profile("nullPointerExceptionSnippet", 5); + resetProfile("nullPointerExceptionSnippet"); assertEquals(TriState.FALSE, info.getExceptionSeen(1)); + // ArrayOutOfBoundsException + info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[1]); + assertEquals(TriState.FALSE, info.getExceptionSeen(2)); + info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[0]); assertEquals(TriState.TRUE, info.getExceptionSeen(2)); - info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[1]); + resetProfile("arrayIndexOutOfBoundsExceptionSnippet"); assertEquals(TriState.FALSE, info.getExceptionSeen(2)); + // CheckCastException + info = profile("checkCastExceptionSnippet", "ABC"); + assertEquals(TriState.FALSE, info.getExceptionSeen(1)); + info = profile("checkCastExceptionSnippet", 5); assertEquals(TriState.TRUE, info.getExceptionSeen(1)); - info = profile("checkCastExceptionSnippet", "ABC"); + resetProfile("checkCastExceptionSnippet"); + assertEquals(TriState.FALSE, info.getExceptionSeen(1)); + + // Invoke with exception + info = profile("invokeWithExceptionSnippet", false); assertEquals(TriState.FALSE, info.getExceptionSeen(1)); info = profile("invokeWithExceptionSnippet", true); assertEquals(TriState.TRUE, info.getExceptionSeen(1)); - info = profile("invokeWithExceptionSnippet", false); + resetProfile("invokeWithExceptionSnippet"); assertEquals(TriState.FALSE, info.getExceptionSeen(1)); } @@ -228,24 +263,23 @@ continueProfiling("instanceOfSnippet", 0.0); assertEquals(TriState.TRUE, info.getNullSeen(1)); - info = profile("instanceOfSnippet", (Object) null); - assertEquals(TriState.TRUE, info.getNullSeen(1)); - } - - @Test - public void testDeoptimizationCount() { - // TODO (chaeubl): implement + resetProfile("instanceOfSnippet"); + assertEquals(TriState.FALSE, info.getNullSeen(1)); } private ProfilingInfo profile(String methodName, Object... args) { - return profile(true, methodName, args); + return profile(true, N, methodName, args); } private void continueProfiling(String methodName, Object... args) { - profile(false, methodName, args); + profile(false, N, methodName, args); } - private ProfilingInfo profile(boolean resetProfile, String methodName, Object... args) { + private void continueProfiling(int executions, String methodName, Object... args) { + profile(false, executions, methodName, args); + } + + private ProfilingInfo profile(boolean resetProfile, int executions, String methodName, Object... args) { Method method = getMethod(methodName); Assert.assertTrue(Modifier.isStatic(method.getModifiers())); @@ -254,7 +288,7 @@ javaMethod.reprofile(); } - for (int i = 0; i < N; ++i) { + for (int i = 0; i < executions; ++i) { try { method.invoke(null, args); } catch (Throwable e) { @@ -264,4 +298,9 @@ return javaMethod.getProfilingInfo(); } + + private void resetProfile(String methodName) { + ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(getMethod(methodName)); + javaMethod.reprofile(); + } } diff -r 6c4db417385a -r 02ef91b94656 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Wed Mar 27 17:25:59 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Thu Mar 28 12:55:13 2013 +0100 @@ -113,7 +113,7 @@ // Debug settings: public static boolean Debug = true; - public static boolean DebugReplacements = false; + public static boolean DebugReplacements = ____; public static boolean PerThreadDebugValues = ____; public static boolean SummarizeDebugValues = ____; public static boolean SummarizePerPhase = ____;