< prev index next >

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

Print this page




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.graalvm.compiler.hotspot.test;
  25 
  26 import java.util.Arrays;
  27 
  28 import org.graalvm.compiler.bytecode.Bytecode;
  29 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
  30 import org.graalvm.compiler.bytecode.BytecodeStream;
  31 import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
  32 import org.graalvm.compiler.core.target.Backend;
  33 import org.graalvm.compiler.core.test.GraalCompilerTest;
  34 import org.graalvm.compiler.debug.DebugContext;
  35 import org.graalvm.compiler.debug.GraalError;
  36 import org.graalvm.compiler.debug.TTY;
  37 import org.graalvm.compiler.hotspot.CompilationTask;

  38 import org.graalvm.compiler.hotspot.HotSpotGraalCompiler;

  39 import org.graalvm.compiler.java.BciBlockMapping;
  40 import org.graalvm.compiler.java.BciBlockMapping.BciBlock;
  41 import org.graalvm.compiler.nodes.StructuredGraph;
  42 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  43 import org.graalvm.compiler.options.OptionValues;
  44 import org.junit.Assert;
  45 
  46 import jdk.vm.ci.code.Architecture;
  47 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  48 import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
  49 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  50 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider;
  51 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  52 import jdk.vm.ci.meta.ResolvedJavaMethod;
  53 
  54 public abstract class GraalOSRTestBase extends GraalCompilerTest {
  55 
  56     protected void testOSR(OptionValues options, String methodName) {
  57         testOSR(options, methodName, null);
  58     }
  59 
  60     protected void testOSR(OptionValues options, String methodName, Object receiver, Object... args) {
  61         ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
  62         testOSR(options, method, receiver, args);
  63     }
  64 
  65     protected void testOSR(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) {
  66         // invalidate any existing compiled code
  67         method.reprofile();
  68         compileOSR(options, method);
  69         Result result = executeExpected(method, receiver, args);
  70         checkResult(result);
  71     }
  72 
  73     protected static void compile(DebugContext debug, ResolvedJavaMethod method, int bci) {
  74         HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime();
  75         long jvmciEnv = 0L;
  76         HotSpotCompilationRequest request = new HotSpotCompilationRequest((HotSpotResolvedJavaMethod) method, bci, jvmciEnv);
  77         HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
  78         CompilationTask task = new CompilationTask(runtime, compiler, request, true, true, debug.getOptions());







  79         HotSpotCompilationRequestResult result = task.runCompilation(debug);
  80         if (result.getFailure() != null) {
  81             throw new GraalError(result.getFailureMessage());
  82         }
  83     }
  84 
  85     /**
  86      * Returns the target BCI of the first bytecode backedge. This is where HotSpot triggers
  87      * on-stack-replacement in case the backedge counter overflows.
  88      */
  89     private static int getBackedgeBCI(DebugContext debug, ResolvedJavaMethod method) {
  90         Bytecode code = new ResolvedJavaMethodBytecode(method);
  91         BytecodeStream stream = new BytecodeStream(code.getCode());
  92         OptionValues options = debug.getOptions();
  93         BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, options, debug);
  94 
  95         for (BciBlock block : bciBlockMapping.getBlocks()) {
  96             if (block.startBci != -1) {
  97                 int bci = block.startBci;
  98                 for (BciBlock succ : block.getSuccessors()) {




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.graalvm.compiler.hotspot.test;
  25 
  26 import java.util.Arrays;
  27 
  28 import org.graalvm.compiler.bytecode.Bytecode;
  29 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
  30 import org.graalvm.compiler.bytecode.BytecodeStream;
  31 import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
  32 import org.graalvm.compiler.core.target.Backend;
  33 import org.graalvm.compiler.core.test.GraalCompilerTest;
  34 import org.graalvm.compiler.debug.DebugContext;
  35 import org.graalvm.compiler.debug.GraalError;
  36 import org.graalvm.compiler.debug.TTY;
  37 import org.graalvm.compiler.hotspot.CompilationTask;
  38 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  39 import org.graalvm.compiler.hotspot.HotSpotGraalCompiler;
  40 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  41 import org.graalvm.compiler.java.BciBlockMapping;
  42 import org.graalvm.compiler.java.BciBlockMapping.BciBlock;
  43 import org.graalvm.compiler.nodes.StructuredGraph;
  44 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  45 import org.graalvm.compiler.options.OptionValues;
  46 import org.junit.Assert;
  47 
  48 import jdk.vm.ci.code.Architecture;
  49 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  50 import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
  51 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  52 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider;
  53 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  54 import jdk.vm.ci.meta.ResolvedJavaMethod;
  55 
  56 public abstract class GraalOSRTestBase extends GraalCompilerTest {
  57 
  58     protected void testOSR(OptionValues options, String methodName) {
  59         testOSR(options, methodName, null);
  60     }
  61 
  62     protected void testOSR(OptionValues options, String methodName, Object receiver, Object... args) {
  63         ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
  64         testOSR(options, method, receiver, args);
  65     }
  66 
  67     protected void testOSR(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) {
  68         // invalidate any existing compiled code
  69         method.reprofile();
  70         compileOSR(options, method);
  71         Result result = executeExpected(method, receiver, args);
  72         checkResult(result);
  73     }
  74 
  75     protected static void compile(DebugContext debug, ResolvedJavaMethod method, int bci) {
  76         HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime();
  77         long jvmciEnv = 0L;
  78         HotSpotCompilationRequest request = new HotSpotCompilationRequest((HotSpotResolvedJavaMethod) method, bci, jvmciEnv);
  79         HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
  80         CompilationTask task = new CompilationTask(runtime, compiler, request, true, true, debug.getOptions());
  81         if (method instanceof HotSpotResolvedJavaMethod) {
  82             HotSpotGraalRuntimeProvider graalRuntime = compiler.getGraalRuntime();
  83             GraalHotSpotVMConfig config = graalRuntime.getVMConfig();
  84             if (((HotSpotResolvedJavaMethod) method).hasCodeAtLevel(bci, config.compilationLevelFullOptimization)) {
  85                 return;
  86             }
  87         }
  88         HotSpotCompilationRequestResult result = task.runCompilation(debug);
  89         if (result.getFailure() != null) {
  90             throw new GraalError(result.getFailureMessage());
  91         }
  92     }
  93 
  94     /**
  95      * Returns the target BCI of the first bytecode backedge. This is where HotSpot triggers
  96      * on-stack-replacement in case the backedge counter overflows.
  97      */
  98     private static int getBackedgeBCI(DebugContext debug, ResolvedJavaMethod method) {
  99         Bytecode code = new ResolvedJavaMethodBytecode(method);
 100         BytecodeStream stream = new BytecodeStream(code.getCode());
 101         OptionValues options = debug.getOptions();
 102         BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, options, debug);
 103 
 104         for (BciBlock block : bciBlockMapping.getBlocks()) {
 105             if (block.startBci != -1) {
 106                 int bci = block.startBci;
 107                 for (BciBlock succ : block.getSuccessors()) {


< prev index next >