InvokeTest.java revision 12651:6ef01bd40ce2
1/*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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 */
23package org.graalvm.compiler.replacements.test;
24
25import org.junit.Test;
26
27import org.graalvm.compiler.core.test.GraalCompilerTest;
28import org.graalvm.compiler.phases.common.AbstractInliningPhase;
29
30/**
31 * Tests the implementation of the snippets for lowering the INVOKE* instructions.
32 */
33public class InvokeTest extends GraalCompilerTest {
34
35    public InvokeTest() {
36        getSuites().getHighTier().findPhase(AbstractInliningPhase.class).remove();
37    }
38
39    public interface I {
40
41        String virtualMethod(String s);
42    }
43
44    public static class A implements I {
45
46        final String name = "A";
47
48        @Override
49        public String virtualMethod(String s) {
50            return name + s;
51        }
52    }
53
54    @SuppressWarnings("static-method")
55    private String privateMethod(String s) {
56        return s;
57    }
58
59    @Test
60    public void test1() {
61        test("invokestatic", "a string");
62        test("invokespecialConstructor", "a string");
63        test("invokespecial", this, "a string");
64        test("invokevirtual", new A(), "a string");
65        test("invokevirtual2", new A(), "a string");
66        test("invokeinterface", new A(), "a string");
67        Object[] args = {null};
68        test("invokestatic", args);
69        test("invokespecialConstructor", args);
70        test("invokespecial", null, null);
71        test("invokevirtual", null, null);
72        test("invokevirtual2", null, null);
73        test("invokeinterface", null, null);
74    }
75
76    public static String invokestatic(String s) {
77        return staticMethod(s);
78    }
79
80    public static String staticMethod(String s) {
81        return s;
82    }
83
84    public static String invokespecialConstructor(String s) {
85        return new A().virtualMethod(s);
86    }
87
88    public static String invokespecial(InvokeTest a, String s) {
89        return a.privateMethod(s);
90    }
91
92    public static String invokevirtual(A a, String s) {
93        return a.virtualMethod(s);
94    }
95
96    public static String invokevirtual2(A a, String s) {
97        a.virtualMethod(s);
98        return a.virtualMethod(s);
99    }
100
101    public static String invokeinterface(I i, String s) {
102        return i.virtualMethod(s);
103    }
104}
105