annotate graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/CompiledExceptionHandlerTest.java @ 8944:e7766460ddb3

Move tests into *.test packages.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 09 Apr 2013 15:26:29 +0200
parents graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/CompiledExceptionHandlerTest.java@0235a3230877
children 5fa54bf57f8c
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 java.lang.reflect.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import org.junit.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.compiler.test.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.java.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.phases.*;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.phases.common.*;
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 /**
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 * Tests compilation of a hot exception handler.
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 */
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 public class CompiledExceptionHandlerTest extends GraalCompilerTest {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 @Override
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 protected void editPhasePlan(ResolvedJavaMethod method, StructuredGraph graph, PhasePlan phasePlan) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 phasePlan.disablePhase(InliningPhase.class);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 @Override
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 protected StructuredGraph parse(Method m) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 StructuredGraph graph = super.parse(m);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 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
50 Assert.assertEquals(1, handlers);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 return graph;
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 private static void raiseException(String s) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 throw new RuntimeException(s);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 @Test
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 public void test1() {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 // Ensure the profile shows a hot exception
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 for (int i = 0; i < 10000; i++) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 test1Snippet("");
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 test1Snippet(null);
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 test("test1Snippet", "a string");
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 public static String test1Snippet(String message) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 if (message != null) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 try {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 raiseException(message);
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 } catch (Exception e) {
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 return message;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 return null;
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 }
0235a3230877 added test for a compiled exception handler
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 }