1 /* 2 * Copyright (c) 2011, 2018, 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 package org.graalvm.compiler.replacements.test; 26 27 import org.junit.Test; 28 29 import org.graalvm.compiler.core.test.GraalCompilerTest; 30 import org.graalvm.compiler.phases.common.AbstractInliningPhase; 31 32 /** 33 * Tests the implementation of the snippets for lowering the INVOKE* instructions. 34 */ 35 public class InvokeTest extends GraalCompilerTest { 36 InvokeTest()37 public InvokeTest() { 38 createSuites(getInitialOptions()).getHighTier().findPhase(AbstractInliningPhase.class).remove(); 39 } 40 41 public interface I { 42 virtualMethod(String s)43 String virtualMethod(String s); 44 } 45 46 public static class A implements I { 47 48 final String name = "A"; 49 50 @Override virtualMethod(String s)51 public String virtualMethod(String s) { 52 return name + s; 53 } 54 } 55 56 @SuppressWarnings("static-method") privateMethod(String s)57 private String privateMethod(String s) { 58 return s; 59 } 60 61 @Test test1()62 public void test1() { 63 test("invokestatic", "a string"); 64 test("invokespecialConstructor", "a string"); 65 test("invokespecial", this, "a string"); 66 test("invokevirtual", new A(), "a string"); 67 test("invokevirtual2", new A(), "a string"); 68 test("invokeinterface", new A(), "a string"); 69 Object[] args = {null}; 70 test("invokestatic", args); 71 test("invokespecialConstructor", args); 72 test("invokespecial", null, null); 73 test("invokevirtual", null, null); 74 test("invokevirtual2", null, null); 75 test("invokeinterface", null, null); 76 } 77 invokestatic(String s)78 public static String invokestatic(String s) { 79 return staticMethod(s); 80 } 81 staticMethod(String s)82 public static String staticMethod(String s) { 83 return s; 84 } 85 invokespecialConstructor(String s)86 public static String invokespecialConstructor(String s) { 87 return new A().virtualMethod(s); 88 } 89 invokespecial(InvokeTest a, String s)90 public static String invokespecial(InvokeTest a, String s) { 91 return a.privateMethod(s); 92 } 93 invokevirtual(A a, String s)94 public static String invokevirtual(A a, String s) { 95 return a.virtualMethod(s); 96 } 97 invokevirtual2(A a, String s)98 public static String invokevirtual2(A a, String s) { 99 a.virtualMethod(s); 100 return a.virtualMethod(s); 101 } 102 invokeinterface(I i, String s)103 public static String invokeinterface(I i, String s) { 104 return i.virtualMethod(s); 105 } 106 } 107