001/* 002 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.replacements.test; 024 025import org.junit.*; 026 027import com.oracle.graal.compiler.test.*; 028import com.oracle.graal.phases.common.*; 029 030/** 031 * Tests the implementation of the snippets for lowering the INVOKE* instructions. 032 */ 033public class InvokeTest extends GraalCompilerTest { 034 035 public InvokeTest() { 036 getSuites().getHighTier().findPhase(AbstractInliningPhase.class).remove(); 037 } 038 039 public interface I { 040 041 String virtualMethod(String s); 042 } 043 044 public static class A implements I { 045 046 final String name = "A"; 047 048 public String virtualMethod(String s) { 049 return name + s; 050 } 051 } 052 053 @SuppressWarnings("static-method") 054 private String privateMethod(String s) { 055 return s; 056 } 057 058 @Test 059 public void test1() { 060 test("invokestatic", "a string"); 061 test("invokespecialConstructor", "a string"); 062 test("invokespecial", this, "a string"); 063 test("invokevirtual", new A(), "a string"); 064 test("invokevirtual2", new A(), "a string"); 065 test("invokeinterface", new A(), "a string"); 066 Object[] args = {null}; 067 test("invokestatic", args); 068 test("invokespecialConstructor", args); 069 test("invokespecial", null, null); 070 test("invokevirtual", null, null); 071 test("invokevirtual2", null, null); 072 test("invokeinterface", null, null); 073 } 074 075 public static String invokestatic(String s) { 076 return staticMethod(s); 077 } 078 079 public static String staticMethod(String s) { 080 return s; 081 } 082 083 public static String invokespecialConstructor(String s) { 084 return new A().virtualMethod(s); 085 } 086 087 public static String invokespecial(InvokeTest a, String s) { 088 return a.privateMethod(s); 089 } 090 091 public static String invokevirtual(A a, String s) { 092 return a.virtualMethod(s); 093 } 094 095 public static String invokevirtual2(A a, String s) { 096 a.virtualMethod(s); 097 return a.virtualMethod(s); 098 } 099 100 public static String invokeinterface(I i, String s) { 101 return i.virtualMethod(s); 102 } 103}