1 /*
2  * Copyright (c) 2007, 2012, 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  */
23 /*
24  */
25 
26 
27 package org.graalvm.compiler.jtt.micro;
28 
29 import org.junit.Test;
30 
31 import org.graalvm.compiler.jtt.JTTTest;
32 
33 public class InvokeVirtual_01 extends JTTTest {
34 
35     static class A {
36 
plus(int a)37         int plus(int a) {
38             return a;
39         }
40     }
41 
42     static class B extends A {
43 
44         @Override
plus(int a)45         int plus(int a) {
46             return a + 10;
47         }
48     }
49 
50     static class C extends A {
51 
52         @Override
plus(int a)53         int plus(int a) {
54             return a + 20;
55         }
56     }
57 
58     static A aObject = new A();
59     static A bObject = new B();
60     static A cObject = new C();
61 
test(int a)62     public static int test(int a) {
63         if (a == 0) {
64             return aObject.plus(a);
65         }
66         if (a == 1) {
67             return bObject.plus(a);
68         }
69         if (a == 2) {
70             return cObject.plus(a);
71         }
72         return 42;
73     }
74 
75     @Test
run0()76     public void run0() throws Throwable {
77         runTest("test", 0);
78     }
79 
80     @Test
run1()81     public void run1() throws Throwable {
82         runTest("test", 1);
83     }
84 
85     @Test
run2()86     public void run2() throws Throwable {
87         runTest("test", 2);
88     }
89 
90     @Test
run3()91     public void run3() throws Throwable {
92         runTest("test", 3);
93     }
94 
95 }
96