src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.jtt/src/org/graalvm/compiler/lir/jtt/SPARCBranchBailoutTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.jtt/src/org/graalvm/compiler/lir/jtt

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.jtt/src/org/graalvm/compiler/lir/jtt/SPARCBranchBailoutTest.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 package org.graalvm.compiler.lir.jtt;
  24 
  25 import org.graalvm.compiler.api.directives.GraalDirectives;
  26 import org.graalvm.compiler.core.common.PermanentBailoutException;
  27 import org.graalvm.compiler.debug.Debug;
  28 import org.graalvm.compiler.debug.DebugConfigScope;
  29 import org.graalvm.compiler.debug.GraalError;
  30 import org.graalvm.compiler.lir.LIRInstruction;
  31 import org.graalvm.compiler.lir.LIRInstructionClass;
  32 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;


  34 import org.junit.Assert;
  35 import org.junit.Assume;
  36 import org.junit.Test;
  37 
  38 import jdk.vm.ci.code.BailoutException;
  39 import jdk.vm.ci.meta.ResolvedJavaMethod;
  40 import jdk.vm.ci.meta.Value;
  41 import jdk.vm.ci.sparc.SPARC;
  42 
  43 /**
  44  * Tests the {@link BailoutException} thrown, when trying to compile huge methods, which have branch
  45  * displacements which does not fit into 19 bit signed.
  46  */
  47 public class SPARCBranchBailoutTest extends LIRTest {
  48     private static class BranchSpec extends LIRTestSpecification {
  49         private final int n;
  50 
  51         BranchSpec(int n) {
  52             super();
  53             this.n = n;


  65     @LIRIntrinsic
  66     public static int branch(@SuppressWarnings("unused") BranchSpec s, int a) {
  67         return a;
  68     }
  69 
  70     public static int testBranch(int length) {
  71         int res = 1;
  72         if (length > 0) {
  73             res = branch(spec, 1);
  74         } else {
  75             res = branch(spec, 2);
  76         }
  77         return GraalDirectives.opaque(res);
  78     }
  79 
  80     @SuppressWarnings("try")
  81     @Test
  82     public void testBailoutOnBranchOverflow() throws Throwable {
  83         Assume.assumeTrue(getBackend().getTarget().arch instanceof SPARC);
  84         ResolvedJavaMethod m = getResolvedJavaMethod("testBranch");

  85         try {
  86             try (DebugConfigScope s = Debug.setConfig(Debug.silentConfig())) {
  87                 compile(m, null);

  88             }
  89         } catch (GraalError e) {
  90             Assert.assertEquals(PermanentBailoutException.class, e.getCause().getClass());
  91         }
  92     }
  93 
  94     public static class LargeOp extends LIRInstruction {
  95         private static final LIRInstructionClass<LargeOp> TYPE = LIRInstructionClass.create(LargeOp.class);
  96         private final int n;
  97 
  98         public LargeOp(int n) {
  99             super(TYPE);
 100             this.n = n;
 101         }
 102 
 103         @Override
 104         public void emitCode(CompilationResultBuilder crb) {
 105             for (int i = 0; i < n; i++) {
 106                 crb.asm.emitInt(0);
 107             }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 package org.graalvm.compiler.lir.jtt;
  24 
  25 import org.graalvm.compiler.api.directives.GraalDirectives;
  26 import org.graalvm.compiler.core.common.PermanentBailoutException;
  27 import org.graalvm.compiler.debug.DebugContext;
  28 import org.graalvm.compiler.debug.DebugContext.Scope;
  29 import org.graalvm.compiler.debug.GraalError;
  30 import org.graalvm.compiler.lir.LIRInstruction;
  31 import org.graalvm.compiler.lir.LIRInstructionClass;
  32 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  36 import org.junit.Assert;
  37 import org.junit.Assume;
  38 import org.junit.Test;
  39 
  40 import jdk.vm.ci.code.BailoutException;
  41 import jdk.vm.ci.meta.ResolvedJavaMethod;
  42 import jdk.vm.ci.meta.Value;
  43 import jdk.vm.ci.sparc.SPARC;
  44 
  45 /**
  46  * Tests the {@link BailoutException} thrown, when trying to compile huge methods, which have branch
  47  * displacements which does not fit into 19 bit signed.
  48  */
  49 public class SPARCBranchBailoutTest extends LIRTest {
  50     private static class BranchSpec extends LIRTestSpecification {
  51         private final int n;
  52 
  53         BranchSpec(int n) {
  54             super();
  55             this.n = n;


  67     @LIRIntrinsic
  68     public static int branch(@SuppressWarnings("unused") BranchSpec s, int a) {
  69         return a;
  70     }
  71 
  72     public static int testBranch(int length) {
  73         int res = 1;
  74         if (length > 0) {
  75             res = branch(spec, 1);
  76         } else {
  77             res = branch(spec, 2);
  78         }
  79         return GraalDirectives.opaque(res);
  80     }
  81 
  82     @SuppressWarnings("try")
  83     @Test
  84     public void testBailoutOnBranchOverflow() throws Throwable {
  85         Assume.assumeTrue(getBackend().getTarget().arch instanceof SPARC);
  86         ResolvedJavaMethod m = getResolvedJavaMethod("testBranch");
  87         DebugContext debug = getDebugContext();
  88         try {
  89             try (Scope s = debug.disable()) {
  90                 StructuredGraph graph = parseEager(m, AllowAssumptions.YES, debug);
  91                 compile(m, graph);
  92             }
  93         } catch (GraalError e) {
  94             Assert.assertEquals(PermanentBailoutException.class, e.getCause().getClass());
  95         }
  96     }
  97 
  98     public static class LargeOp extends LIRInstruction {
  99         private static final LIRInstructionClass<LargeOp> TYPE = LIRInstructionClass.create(LargeOp.class);
 100         private final int n;
 101 
 102         public LargeOp(int n) {
 103             super(TYPE);
 104             this.n = n;
 105         }
 106 
 107         @Override
 108         public void emitCode(CompilationResultBuilder crb) {
 109             for (int i = 0; i < n; i++) {
 110                 crb.asm.emitInt(0);
 111             }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.jtt/src/org/graalvm/compiler/lir/jtt/SPARCBranchBailoutTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File