Search in sources :

Example 6 with ProfilingInfo

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));
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) Test(org.junit.Test)

Example 7 with ProfilingInfo

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));
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) Test(org.junit.Test)

Example 8 with ProfilingInfo

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);
}
Also used : JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 9 with ProfilingInfo

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));
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) Test(org.junit.Test)

Example 10 with ProfilingInfo

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;
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ProfilingInfo (jdk.vm.ci.meta.ProfilingInfo)10 Test (org.junit.Test)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)2 OptimisticOptimizations (org.graalvm.compiler.phases.OptimisticOptimizations)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 Suites (org.graalvm.compiler.phases.tiers.Suites)2 EnumMap (java.util.EnumMap)1 DefaultProfilingInfo (jdk.vm.ci.meta.DefaultProfilingInfo)1 DeoptimizationReason (jdk.vm.ci.meta.DeoptimizationReason)1 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)1 HotSpotProviders (org.graalvm.compiler.hotspot.meta.HotSpotProviders)1 CompilationResultBuilderFactory (org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)1