use of jdk.vm.ci.meta.ProfilingInfo in project graal by oracle.
the class ProfilingInfoTest method testBranchTakenProbability.
@Test
public void testBranchTakenProbability() {
ProfilingInfo info = profile("branchProbabilitySnippet", 0);
Assert.assertEquals(0.0, info.getBranchTakenProbability(1), DELTA);
Assert.assertEquals(N, info.getExecutionCount(1));
Assert.assertEquals(-1.0, info.getBranchTakenProbability(8), DELTA);
Assert.assertEquals(0, info.getExecutionCount(8));
info = profile("branchProbabilitySnippet", 1);
Assert.assertEquals(1.0, info.getBranchTakenProbability(1), DELTA);
Assert.assertEquals(N, info.getExecutionCount(1));
Assert.assertEquals(0.0, info.getBranchTakenProbability(8), DELTA);
Assert.assertEquals(N, info.getExecutionCount(8));
info = profile("branchProbabilitySnippet", 2);
Assert.assertEquals(1.0, info.getBranchTakenProbability(1), DELTA);
Assert.assertEquals(N, info.getExecutionCount(1));
Assert.assertEquals(1.0, info.getBranchTakenProbability(8), DELTA);
Assert.assertEquals(N, info.getExecutionCount(8));
continueProfiling(3 * N, "branchProbabilitySnippet", 0);
Assert.assertEquals(0.25, info.getBranchTakenProbability(1), DELTA);
Assert.assertEquals(4 * N, info.getExecutionCount(1));
Assert.assertEquals(1.0, info.getBranchTakenProbability(8), DELTA);
Assert.assertEquals(N, info.getExecutionCount(8));
resetProfile("branchProbabilitySnippet");
Assert.assertEquals(-1.0, info.getBranchTakenProbability(1), DELTA);
Assert.assertEquals(0, info.getExecutionCount(1));
Assert.assertEquals(-1.0, info.getBranchTakenProbability(8), DELTA);
Assert.assertEquals(0, info.getExecutionCount(8));
}
use of jdk.vm.ci.meta.ProfilingInfo in project graal by oracle.
the class ProfilingInfoTest method testSwitchProbabilities.
@Test
public void testSwitchProbabilities() {
ProfilingInfo info = profile("switchProbabilitySnippet", 0);
Assert.assertArrayEquals(new double[] { 1.0, 0.0, 0.0 }, info.getSwitchProbabilities(1), DELTA);
info = profile("switchProbabilitySnippet", 1);
Assert.assertArrayEquals(new double[] { 0.0, 1.0, 0.0 }, info.getSwitchProbabilities(1), DELTA);
info = profile("switchProbabilitySnippet", 2);
Assert.assertArrayEquals(new double[] { 0.0, 0.0, 1.0 }, info.getSwitchProbabilities(1), DELTA);
resetProfile("switchProbabilitySnippet");
Assert.assertNull(info.getSwitchProbabilities(1));
}
use of jdk.vm.ci.meta.ProfilingInfo in project graal by oracle.
the class ProfilingInfoTest method testTypeProfile.
private void testTypeProfile(String testSnippet, int bci) {
ResolvedJavaType stringType = getMetaAccess().lookupJavaType(String.class);
ResolvedJavaType stringBuilderType = getMetaAccess().lookupJavaType(StringBuilder.class);
ProfilingInfo info = profile(testSnippet, "ABC");
JavaTypeProfile typeProfile = info.getTypeProfile(bci);
Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
Assert.assertEquals(1, typeProfile.getTypes().length);
Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
Assert.assertEquals(1.0, typeProfile.getTypes()[0].getProbability(), DELTA);
continueProfiling(testSnippet, new StringBuilder());
typeProfile = info.getTypeProfile(bci);
Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
Assert.assertEquals(2, typeProfile.getTypes().length);
Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
Assert.assertEquals(stringBuilderType, typeProfile.getTypes()[1].getType());
Assert.assertEquals(0.5, typeProfile.getTypes()[0].getProbability(), DELTA);
Assert.assertEquals(0.5, typeProfile.getTypes()[1].getProbability(), DELTA);
resetProfile(testSnippet);
typeProfile = info.getTypeProfile(bci);
Assert.assertNull(typeProfile);
}
use of jdk.vm.ci.meta.ProfilingInfo in project graal by oracle.
the class ProfilingInfoTest method testExceptionSeen.
@Test
public void testExceptionSeen() {
// NullPointerException
ProfilingInfo info = profile("nullPointerExceptionSnippet", 5);
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
info = profile("nullPointerExceptionSnippet", (Object) null);
Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
resetProfile("nullPointerExceptionSnippet");
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
// ArrayOutOfBoundsException
info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[1]);
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(2));
info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[0]);
Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(2));
resetProfile("arrayIndexOutOfBoundsExceptionSnippet");
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(2));
// CheckCastException
info = profile("checkCastExceptionSnippet", "ABC");
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
info = profile("checkCastExceptionSnippet", 5);
Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
resetProfile("checkCastExceptionSnippet");
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
// Invoke with exception
info = profile("invokeWithExceptionSnippet", false);
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
info = profile("invokeWithExceptionSnippet", true);
Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
resetProfile("invokeWithExceptionSnippet");
Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
}
use of jdk.vm.ci.meta.ProfilingInfo in project graal by oracle.
the class ProfilingInfoTest method profile.
private ProfilingInfo profile(boolean resetProfile, int executions, String methodName, Object... args) {
ResolvedJavaMethod javaMethod = getResolvedJavaMethod(methodName);
Assert.assertTrue(javaMethod.isStatic());
if (resetProfile) {
javaMethod.reprofile();
}
for (int i = 0; i < executions; ++i) {
try {
invoke(javaMethod, null, args);
} catch (Throwable e) {
Assert.fail("method should not throw an exception: " + e.toString());
}
}
ProfilingInfo info = javaMethod.getProfilingInfo();
// The execution counts are low so force maturity
info.setMature();
return info;
}
Aggregations