src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java

Print this page

        

*** 21,43 **** * questions. */ package org.graalvm.compiler.hotspot.test; ! import org.junit.Assert; import org.graalvm.compiler.bytecode.Bytecode; 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.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 jdk.vm.ci.code.Architecture; import jdk.vm.ci.hotspot.HotSpotCompilationRequest; import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; --- 21,47 ---- * questions. */ package org.graalvm.compiler.hotspot.test; ! 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; import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
*** 45,73 **** import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaMethod; public abstract class GraalOSRTestBase extends GraalCompilerTest { ! protected void testOSR(String methodName) { ResolvedJavaMethod method = getResolvedJavaMethod(methodName); ! testOSR(method); } ! protected void testOSR(ResolvedJavaMethod method) { // invalidate any existing compiled code method.reprofile(); ! compileOSR(method); ! Result result = executeExpected(method, null); checkResult(result); } ! private static void compile(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); HotSpotCompilationRequestResult result = task.runCompilation(); if (result.getFailure() != null) { throw new GraalError(result.getFailureMessage()); } } --- 49,81 ---- import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaMethod; public abstract class GraalOSRTestBase extends GraalCompilerTest { ! protected void testOSR(OptionValues options, String methodName) { ! testOSR(options, methodName, null); ! } ! ! 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(options, method); ! Result result = executeExpected(method, receiver, args); checkResult(result); } ! 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, options); HotSpotCompilationRequestResult result = task.runCompilation(); if (result.getFailure() != null) { throw new GraalError(result.getFailureMessage()); } }
*** 77,120 **** * on-stack-replacement in case the backedge counter overflows. */ 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; 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; } } } return -1; } private static void checkResult(Result result) { Assert.assertNull("Unexpected exception", result.exception); Assert.assertNotNull(result.returnValue); Assert.assertTrue(result.returnValue instanceof ReturnValue); Assert.assertEquals(ReturnValue.SUCCESS, result.returnValue); } ! private void compileOSR(ResolvedJavaMethod method) { int bci = getBackedgeBCI(method); assert bci != -1; // ensure eager resolving ! parseEager(method, AllowAssumptions.YES); ! compile(method, bci); } protected enum ReturnValue { SUCCESS, ! FAILURE } public GraalOSRTestBase() { super(); } --- 85,136 ---- * on-stack-replacement in case the backedge counter overflows. */ private static int getBackedgeBCI(ResolvedJavaMethod method) { Bytecode code = new ResolvedJavaMethodBytecode(method); BytecodeStream stream = new BytecodeStream(code.getCode()); ! BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, getInitialOptions()); for (BciBlock block : bciBlockMapping.getBlocks()) { + 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; } private static void checkResult(Result result) { Assert.assertNull("Unexpected exception", result.exception); Assert.assertNotNull(result.returnValue); Assert.assertTrue(result.returnValue instanceof ReturnValue); Assert.assertEquals(ReturnValue.SUCCESS, result.returnValue); } ! 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, options); ! compile(options, method, bci); } protected enum ReturnValue { SUCCESS, ! FAILURE, ! SIDE } public GraalOSRTestBase() { super(); }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File