--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTest.java 2017-03-20 17:38:21.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTest.java 2017-03-20 17:38:21.000000000 -0700 @@ -22,9 +22,9 @@ */ package org.graalvm.compiler.hotspot.test; -import org.junit.Test; - import org.graalvm.compiler.api.directives.GraalDirectives; +import org.junit.Assert; +import org.junit.Test; /** * Test on-stack-replacement with Graal. The test manually triggers a Graal OSR-compilation which is @@ -33,13 +33,29 @@ public class GraalOSRTest extends GraalOSRTestBase { @Test - public void testOSR() { - testOSR("test"); + public void testOSR01() { + try { + testOSR(getInitialOptions(), "testReduceLoop"); + } catch (Throwable t) { + Assert.assertEquals("OSR compilation without OSR entry loop.", t.getMessage()); + } + } + + @Test + public void testOSR02() { + testOSR(getInitialOptions(), "testSequentialLoop"); + } + + @Test + public void testOSR03() { + testOSR(getInitialOptions(), "testNonReduceLoop"); } static int limit = 10000; - public static ReturnValue test() { + public static int sideEffect; + + public static ReturnValue testReduceLoop() { for (int i = 0; i < limit * limit; i++) { GraalDirectives.blackhole(i); if (GraalDirectives.inCompiledCode()) { @@ -49,4 +65,38 @@ return ReturnValue.FAILURE; } + public static ReturnValue testSequentialLoop() { + ReturnValue ret = ReturnValue.FAILURE; + for (int i = 1; i < limit * limit; i++) { + GraalDirectives.blackhole(i); + if (i % 7 == 0) { + ret = ReturnValue.SUCCESS; + } + } + GraalDirectives.controlFlowAnchor(); + if (sideEffect == 123) { + return ReturnValue.SIDE; + } + for (int i = 1; i < limit * limit; i++) { + GraalDirectives.blackhole(i); + if (i % 33 == 0) { + ret = ReturnValue.SUCCESS; + } + } + GraalDirectives.controlFlowAnchor(); + return ret; + } + + public static ReturnValue testNonReduceLoop() { + ReturnValue ret = ReturnValue.FAILURE; + for (int i = 0; i < limit * limit; i++) { + GraalDirectives.blackhole(i); + if (i % 33 == 0) { + ret = ReturnValue.SUCCESS; + } + } + GraalDirectives.controlFlowAnchor(); + return ret; + } + }