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
24
25 package org.graalvm.compiler.lir.jtt;
26
27 import org.graalvm.compiler.api.directives.GraalDirectives;
28 import org.graalvm.compiler.core.common.PermanentBailoutException;
29 import org.graalvm.compiler.debug.DebugContext;
30 import org.graalvm.compiler.debug.DebugContext.Scope;
31 import org.graalvm.compiler.debug.GraalError;
32 import org.graalvm.compiler.lir.LIRInstruction;
33 import org.graalvm.compiler.lir.LIRInstructionClass;
34 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
35 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
36 import org.graalvm.compiler.nodes.StructuredGraph;
37 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
38 import org.junit.Assert;
39 import org.junit.Assume;
40 import org.junit.Test;
41
42 import jdk.vm.ci.code.BailoutException;
43 import jdk.vm.ci.meta.ResolvedJavaMethod;
44 import jdk.vm.ci.meta.Value;
45 import jdk.vm.ci.sparc.SPARC;
46
47 /**
48 * Tests the {@link BailoutException} thrown, when trying to compile huge methods, which have branch
49 * displacements which does not fit into 19 bit signed.
50 */
51 public class SPARCBranchBailoutTest extends LIRTest {
52 private static class BranchSpec extends LIRTestSpecification {
53 private final int n;
54
55 BranchSpec(int n) {
56 super();
57 this.n = n;
58 }
65 }
66
67 private static final BranchSpec spec = new BranchSpec(1 << 20);
68
69 @LIRIntrinsic
70 public static int branch(@SuppressWarnings("unused") BranchSpec s, int a) {
71 return a;
72 }
73
74 public static int testBranch(int length) {
75 int res = 1;
76 if (length > 0) {
77 res = branch(spec, 1);
78 } else {
79 res = branch(spec, 2);
80 }
81 return GraalDirectives.opaque(res);
82 }
83
84 @SuppressWarnings("try")
85 @Test
86 public void testBailoutOnBranchOverflow() throws Throwable {
87 Assume.assumeTrue(getBackend().getTarget().arch instanceof SPARC);
88 ResolvedJavaMethod m = getResolvedJavaMethod("testBranch");
89 DebugContext debug = getDebugContext();
90 try {
91 try (Scope s = debug.disable()) {
92 StructuredGraph graph = parseEager(m, AllowAssumptions.YES, debug);
93 compile(m, graph);
94 }
95 } catch (GraalError e) {
96 Assert.assertEquals(PermanentBailoutException.class, e.getCause().getClass());
97 }
98 }
99
100 public static class LargeOp extends LIRInstruction {
101 private static final LIRInstructionClass<LargeOp> TYPE = LIRInstructionClass.create(LargeOp.class);
102 private final int n;
103
104 public LargeOp(int n) {
105 super(TYPE);
106 this.n = n;
107 }
108
109 @Override
110 public void emitCode(CompilationResultBuilder crb) {
111 for (int i = 0; i < n; i++) {
112 crb.asm.emitInt(0);
113 }
114 }
115 }
116 }
|
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
24
25 package org.graalvm.compiler.lir.jtt;
26
27 import org.graalvm.compiler.api.directives.GraalDirectives;
28 import org.graalvm.compiler.asm.BranchTargetOutOfBoundsException;
29 import org.graalvm.compiler.debug.DebugContext;
30 import org.graalvm.compiler.debug.DebugContext.Scope;
31 import org.graalvm.compiler.lir.LIRInstruction;
32 import org.graalvm.compiler.lir.LIRInstructionClass;
33 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
34 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
35 import org.graalvm.compiler.nodes.StructuredGraph;
36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
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;
56 }
63 }
64
65 private static final BranchSpec spec = new BranchSpec(1 << 20);
66
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(expected = BranchTargetOutOfBoundsException.class)
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 (Scope s = debug.disable()) {
89 StructuredGraph graph = parseEager(m, AllowAssumptions.YES, debug);
90 compile(m, graph);
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 }
108 }
109 }
110 }
|