AsResolvedJavaMethodTest.java revision 12748:fbb9c8026495
1130803Smarcel/* 2130803Smarcel * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3130803Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4130803Smarcel * 5130803Smarcel * This code is free software; you can redistribute it and/or modify it 6130803Smarcel * under the terms of the GNU General Public License version 2 only, as 7130803Smarcel * published by the Free Software Foundation. 8130803Smarcel * 9130803Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 10130803Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11130803Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12130803Smarcel * version 2 for more details (a copy is included in the LICENSE file that 13130803Smarcel * accompanied this code). 14130803Smarcel * 15130803Smarcel * You should have received a copy of the GNU General Public License version 16130803Smarcel * 2 along with this work; if not, write to the Free Software Foundation, 17130803Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18130803Smarcel * 19130803Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20130803Smarcel * or visit www.oracle.com if you need additional information or have any 21130803Smarcel * questions. 22130803Smarcel */ 23130803Smarcel 24130803Smarcel/** 25130803Smarcel * @test 26130803Smarcel * @bug 8136421 27130803Smarcel * @requires vm.jvmci 28130803Smarcel * @library /test/lib / 29130803Smarcel * @library ../common/patches 30130803Smarcel * @modules java.base/jdk.internal.misc 31130803Smarcel * @modules java.base/jdk.internal.org.objectweb.asm 32130803Smarcel * java.base/jdk.internal.org.objectweb.asm.tree 33130803Smarcel * jdk.internal.vm.ci/jdk.vm.ci.hotspot 34130803Smarcel * jdk.internal.vm.ci/jdk.vm.ci.code 35130803Smarcel * jdk.internal.vm.ci/jdk.vm.ci.meta 36130803Smarcel * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper 37130803Smarcel * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Djvmci.Compiler=null 38130803Smarcel * compiler.jvmci.compilerToVM.AsResolvedJavaMethodTest 39130803Smarcel */ 40130803Smarcel 41130803Smarcelpackage compiler.jvmci.compilerToVM; 42130803Smarcel 43130803Smarcelimport jdk.test.lib.Asserts; 44130803Smarcelimport jdk.vm.ci.hotspot.CompilerToVMHelper; 45130803Smarcelimport jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 46130803Smarcel 47130803Smarcelimport java.lang.reflect.Executable; 48130803Smarcelimport java.util.Arrays; 49130803Smarcelimport java.util.ArrayList; 50130803Smarcelimport java.util.List; 51130803Smarcel 52130803Smarcelpublic class AsResolvedJavaMethodTest { 53130803Smarcel 54130803Smarcel private static class A { 55130803Smarcel { 56130803Smarcel System.out.println("Dummy"); 57130803Smarcel } 58130803Smarcel public void f1() {} 59130803Smarcel public int f2() { return 0; } 60130803Smarcel public String f3() { return ""; } 61130803Smarcel } 62130803Smarcel 63130803Smarcel 64130803Smarcel private static class S { 65130803Smarcel static { 66130803Smarcel System.out.println("Dummy static"); 67130803Smarcel } 68130803Smarcel public S() {} 69130803Smarcel public void f1() {} 70130803Smarcel public int f2() { return 0; } 71130803Smarcel public String f3() { return ""; } 72130803Smarcel } 73130803Smarcel 74130803Smarcel private class B extends A { 75130803Smarcel public void f4() {} 76130803Smarcel } 77130803Smarcel 78130803Smarcel private interface I { 79130803Smarcel void f1(); 80130803Smarcel int f2(); 81130803Smarcel String f3(); 82130803Smarcel } 83130803Smarcel 84130803Smarcel public static void main(String[] args) { 85130803Smarcel List<Class<?>> testCases = getTestCases(); 86130803Smarcel testCases.forEach(AsResolvedJavaMethodTest::test); 87130803Smarcel } 88130803Smarcel 89130803Smarcel private static List<Class<?>> getTestCases() { 90130803Smarcel List<Class<?>> testCases = new ArrayList<>(); 91130803Smarcel testCases.add(A.class); 92130803Smarcel testCases.add(S.class); 93130803Smarcel testCases.add(I.class); 94130803Smarcel testCases.add(B.class); 95130803Smarcel return testCases; 96130803Smarcel } 97130803Smarcel 98130803Smarcel private static void test(Class<?> aClass) { 99130803Smarcel testCorrectMethods(aClass); 100130803Smarcel } 101130803Smarcel 102130803Smarcel private static void testCorrectMethods(Class<?> holder) { 103130803Smarcel List<Executable> executables = new ArrayList<>(); 104130803Smarcel executables.addAll(Arrays.asList(holder.getDeclaredMethods())); 105130803Smarcel executables.addAll(Arrays.asList(holder.getDeclaredConstructors())); 106130803Smarcel for (Executable executable : executables) { 107130803Smarcel HotSpotResolvedJavaMethod method = CompilerToVMHelper 108130803Smarcel .asResolvedJavaMethod(executable); 109130803Smarcel Asserts.assertNotNull(method, "could not convert " + method); 110130803Smarcel } 111130803Smarcel } 112130803Smarcel} 113