hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java
changeset 46344 694c102fd8ed
parent 43972 1ade39b8381b
child 46640 70bdce04c59b
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java	Mon Dec 12 16:16:27 2016 +0300
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java	Wed Mar 22 13:42:45 2017 -0700
@@ -23,19 +23,23 @@
 
 package org.graalvm.compiler.hotspot.test;
 
-import org.junit.Assert;
+import java.util.Arrays;
 
 import org.graalvm.compiler.bytecode.Bytecode;
+import org.graalvm.compiler.bytecode.BytecodeDisassembler;
 import org.graalvm.compiler.bytecode.BytecodeStream;
 import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
 import org.graalvm.compiler.core.target.Backend;
 import org.graalvm.compiler.core.test.GraalCompilerTest;
 import org.graalvm.compiler.debug.GraalError;
+import org.graalvm.compiler.debug.TTY;
 import org.graalvm.compiler.hotspot.CompilationTask;
 import org.graalvm.compiler.hotspot.HotSpotGraalCompiler;
 import org.graalvm.compiler.java.BciBlockMapping;
 import org.graalvm.compiler.java.BciBlockMapping.BciBlock;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
+import org.graalvm.compiler.options.OptionValues;
+import org.junit.Assert;
 
 import jdk.vm.ci.code.Architecture;
 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
@@ -47,25 +51,29 @@
 
 public abstract class GraalOSRTestBase extends GraalCompilerTest {
 
-    protected void testOSR(String methodName) {
-        ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
-        testOSR(method);
+    protected void testOSR(OptionValues options, String methodName) {
+        testOSR(options, methodName, null);
     }
 
-    protected void testOSR(ResolvedJavaMethod method) {
+    protected void testOSR(OptionValues options, String methodName, Object receiver, Object... args) {
+        ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
+        testOSR(options, method, receiver, args);
+    }
+
+    protected void testOSR(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) {
         // invalidate any existing compiled code
         method.reprofile();
-        compileOSR(method);
-        Result result = executeExpected(method, null);
+        compileOSR(options, method);
+        Result result = executeExpected(method, receiver, args);
         checkResult(result);
     }
 
-    private static void compile(ResolvedJavaMethod method, int bci) {
+    protected static void compile(OptionValues options, ResolvedJavaMethod method, int bci) {
         HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime();
         long jvmciEnv = 0L;
         HotSpotCompilationRequest request = new HotSpotCompilationRequest((HotSpotResolvedJavaMethod) method, bci, jvmciEnv);
         HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
-        CompilationTask task = new CompilationTask(runtime, compiler, request, true, true);
+        CompilationTask task = new CompilationTask(runtime, compiler, request, true, true, options);
         HotSpotCompilationRequestResult result = task.runCompilation();
         if (result.getFailure() != null) {
             throw new GraalError(result.getFailureMessage());
@@ -79,19 +87,24 @@
     private static int getBackedgeBCI(ResolvedJavaMethod method) {
         Bytecode code = new ResolvedJavaMethodBytecode(method);
         BytecodeStream stream = new BytecodeStream(code.getCode());
-        BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code);
-        assert bciBlockMapping.getLoopCount() == 1 : "Expected exactly one loop " + method;
+        BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, getInitialOptions());
 
         for (BciBlock block : bciBlockMapping.getBlocks()) {
-            int bci = block.startBci;
-            for (BciBlock succ : block.getSuccessors()) {
-                int succBci = succ.startBci;
-                if (succBci < bci) {
-                    // back edge
-                    return succBci;
+            if (block.startBci != -1) {
+                int bci = block.startBci;
+                for (BciBlock succ : block.getSuccessors()) {
+                    if (succ.startBci != -1) {
+                        int succBci = succ.startBci;
+                        if (succBci < bci) {
+                            // back edge
+                            return succBci;
+                        }
+                    }
                 }
             }
         }
+        TTY.println("Cannot find loop back edge with bytecode loops at:%s", Arrays.toString(bciBlockMapping.getLoopHeaders()));
+        TTY.println(new BytecodeDisassembler().disassemble(code));
         return -1;
     }
 
@@ -102,17 +115,20 @@
         Assert.assertEquals(ReturnValue.SUCCESS, result.returnValue);
     }
 
-    private void compileOSR(ResolvedJavaMethod method) {
+    private void compileOSR(OptionValues options, ResolvedJavaMethod method) {
+        // ensure eager resolving
+        parseEager(method, AllowAssumptions.YES, options);
         int bci = getBackedgeBCI(method);
         assert bci != -1;
         // ensure eager resolving
-        parseEager(method, AllowAssumptions.YES);
-        compile(method, bci);
+        parseEager(method, AllowAssumptions.YES, options);
+        compile(options, method, bci);
     }
 
     protected enum ReturnValue {
         SUCCESS,
-        FAILURE
+        FAILURE,
+        SIDE
     }
 
     public GraalOSRTestBase() {