annotate graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/JTTTest.java @ 13614:0774f3303c2e

rename LocalNode to ParameterNode
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 13 Jan 2014 13:20:30 +0100
parents 23ccaa863eda
children c700811a2814
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.jtt;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.api.meta.MetaUtil.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import static java.lang.reflect.Modifier.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.lang.reflect.*;
9682
86d24f120b78 Allow tests to check for deoptimizations, provide Method object in before hook.
Roland Schatz <roland.schatz@oracle.com>
parents: 9438
diff changeset
29 import java.util.*;
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import org.junit.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.api.code.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.api.meta.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.compiler.test.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.*;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 /**
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 * Base class for the JTT tests.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 * <p>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
41 * These tests are executed twice: once with arguments passed to the execution and once with the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
42 * arguments bound to the test's parameters during compilation. The latter is a good test of
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
43 * canonicalization.
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 */
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 public class JTTTest extends GraalCompilerTest {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 /**
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 * The arguments which, if non-null, will replace the Locals in the test method's graph.
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 */
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 Object[] argsToBind;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51
8232
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
52 public JTTTest() {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11405
diff changeset
53 Assert.assertNotNull(getCodeCache());
8232
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
54 }
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
55
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 @Override
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 protected StructuredGraph parse(Method m) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 StructuredGraph graph = super.parse(m);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 if (argsToBind != null) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 Object receiver = isStatic(m.getModifiers()) ? null : this;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 Object[] args = argsWithReceiver(receiver, argsToBind);
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11405
diff changeset
62 JavaType[] parameterTypes = signatureToTypes(getMetaAccess().lookupJavaMethod(m));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7282
diff changeset
63 assert parameterTypes.length == args.length;
9438
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
64 for (int i = 0; i < args.length; i++) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 11959
diff changeset
65 ParameterNode param = graph.getParameter(i);
9438
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
66 Constant c = Constant.forBoxed(parameterTypes[i].getKind(), args[i]);
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11405
diff changeset
67 ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 11959
diff changeset
68 param.replaceAtUsages(replacement);
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 return graph;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 @Override
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 return super.getCode(method, graph, argsToBind != null);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 Double delta;
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 @Override
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 protected void assertEquals(Object expected, Object actual) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 if (delta != null) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 Assert.assertEquals(((Number) expected).doubleValue(), ((Number) actual).doubleValue(), delta);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 } else {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86 super.assertEquals(expected, actual);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 @SuppressWarnings("hiding")
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 protected void runTestWithDelta(double delta, String name, Object... args) {
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 this.delta = Double.valueOf(delta);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 runTest(name, args);
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 protected void runTest(String name, Object... args) {
9682
86d24f120b78 Allow tests to check for deoptimizations, provide Method object in before hook.
Roland Schatz <roland.schatz@oracle.com>
parents: 9438
diff changeset
97 runTest(Collections.<DeoptimizationReason> emptySet(), name, args);
86d24f120b78 Allow tests to check for deoptimizations, provide Method object in before hook.
Roland Schatz <roland.schatz@oracle.com>
parents: 9438
diff changeset
98 }
86d24f120b78 Allow tests to check for deoptimizations, provide Method object in before hook.
Roland Schatz <roland.schatz@oracle.com>
parents: 9438
diff changeset
99
10887
f11a4e137aed fix spelling
Doug Simon <doug.simon@oracle.com>
parents: 9682
diff changeset
100 protected void runTest(Set<DeoptimizationReason> shouldNotDeopt, String name, Object... args) {
8232
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
101 Method method = getMethod(name);
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
102 Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this;
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
103
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
104 Result expect = executeExpected(method, receiver, args);
ab374f69e4e8 JTTTest gets the expeted result only once
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7530
diff changeset
105
11405
25161615539b method rename to avoid ambiguous overloading
Doug Simon <doug.simon@oracle.com>
parents: 10887
diff changeset
106 testAgainstExpected(method, expect, shouldNotDeopt, receiver, args);
9438
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
107 if (args.length > 0) {
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
108 this.argsToBind = args;
11405
25161615539b method rename to avoid ambiguous overloading
Doug Simon <doug.simon@oracle.com>
parents: 10887
diff changeset
109 testAgainstExpected(method, expect, shouldNotDeopt, receiver, args);
9438
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
110 this.argsToBind = null;
3e884486cc8a Fix non-static args binding in JTT
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8233
diff changeset
111 }
7282
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 }
390448a6b535 converted the JTT tests to use the GraalCompilerTest framework which offers more control over what is compiled and executed
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 }