annotate graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/CompiledExceptionHandlerTest.java @ 18120:86ec7f6f71b3

refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
author Doug Simon <doug.simon@oracle.com>
date Sat, 18 Oct 2014 00:08:19 +0200
parents 1668de777c42
children 8ab925a6f724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
8944
e7766460ddb3 Move tests into *.test packages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8640
diff changeset
23 package com.oracle.graal.replacements.test;
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import org.junit.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
18120
86ec7f6f71b3 refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents: 16714
diff changeset
27 import com.oracle.graal.api.meta.*;
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.compiler.test.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.java.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.phases.common.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 /**
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 * Tests compilation of a hot exception handler.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 */
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 public class CompiledExceptionHandlerTest extends GraalCompilerTest {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37
10935
2da7f2efe6e2 Move inlining phases to HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 9820
diff changeset
38 public CompiledExceptionHandlerTest() {
12456
f87c68d79f07 improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents: 10936
diff changeset
39 getSuites().getHighTier().findPhase(AbstractInliningPhase.class).remove();
10935
2da7f2efe6e2 Move inlining phases to HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 9820
diff changeset
40 }
2da7f2efe6e2 Move inlining phases to HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 9820
diff changeset
41
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 @Override
18120
86ec7f6f71b3 refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents: 16714
diff changeset
43 protected StructuredGraph parseEager(ResolvedJavaMethod m) {
16714
1668de777c42 renamed GraalCompilerTest.parse to GraalCompilerTest.parseEager and improved javadoc for all parse* methods
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
44 StructuredGraph graph = super.parseEager(m);
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 int handlers = graph.getNodes().filter(ExceptionObjectNode.class).count();
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 Assert.assertEquals(1, handlers);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 return graph;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 private static void raiseException(String s) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 throw new RuntimeException(s);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 @Test
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 public void test1() {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 // Ensure the profile shows a hot exception
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 for (int i = 0; i < 10000; i++) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 test1Snippet("");
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 test1Snippet(null);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 test("test1Snippet", "a string");
9471
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
63 test("test1Snippet", (String) null);
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 public static String test1Snippet(String message) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 if (message != null) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 try {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 raiseException(message);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 } catch (Exception e) {
9820
1b60f639ac4b implemented alternative implementation for loading the exception object from the thread at the start of an exception dispatcher
Doug Simon <doug.simon@oracle.com>
parents: 9471
diff changeset
71 return message + e.getMessage();
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 return null;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }
9471
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
76
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
77 private static void raiseException(String m1, String m2, String m3, String m4, String m5) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
78 throw new RuntimeException(m1 + m2 + m3 + m4 + m5);
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
79 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
80
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
81 @Test
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
82 public void test2() {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
83 // Ensure the profile shows a hot exception
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
84 for (int i = 0; i < 10000; i++) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
85 test2Snippet("m1", "m2", "m3", "m4", "m5");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
86 test2Snippet(null, "m2", "m3", "m4", "m5");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
87 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
88
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
89 test("test2Snippet", "m1", "m2", "m3", "m4", "m5");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
90 test("test2Snippet", null, "m2", "m3", "m4", "m5");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
91 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
92
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
93 public static String test2Snippet(String m1, String m2, String m3, String m4, String m5) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
94 if (m1 != null) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
95 try {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
96 raiseException(m1, m2, m3, m4, m5);
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
97 } catch (Exception e) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
98 return m5 + m4 + m3 + m2 + m1;
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
99 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
100 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
101 return m4 + m3;
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
102 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
103
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
104 @Test
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
105 public void test3() {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
106 // Ensure the profile shows a hot exception
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
107 for (int i = 0; i < 10000; i++) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
108 test3Snippet("object1", "object2");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
109 test3Snippet(null, "object2");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
110 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
111
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
112 test("test3Snippet", (Object) null, "object2");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
113 test("test3Snippet", "object1", "object2");
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
114 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
115
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
116 public static String test3Snippet(Object o, Object o2) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
117 try {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
118 return o.toString();
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
119 } catch (NullPointerException e) {
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
120 return String.valueOf(o2);
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
121 }
5fa54bf57f8c replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 8944
diff changeset
122 }
8640
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
123 }