Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/GetClassMethods/OverpassMethods.java
41153 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* @test27* @bug 821632428* @summary GetClassMethods is confused by the presence of default methods in super interfaces29* @requires vm.jvmti30* @library /test/lib31* @compile OverpassMethods.java32* @run main/othervm/native -agentlib:OverpassMethods OverpassMethods33* @run main/othervm/native -agentlib:OverpassMethods=maintain_original_method_order OverpassMethods34*/3536import java.lang.reflect.Method;37import java.util.Arrays;3839public class OverpassMethods {4041static {42try {43System.loadLibrary("OverpassMethods");44} catch (UnsatisfiedLinkError ex) {45System.err.println("Could not load OverpassMethods library");46System.err.println("java.library.path:" + System.getProperty("java.library.path"));47throw ex;48}49}5051static private void log(Object msg) {52System.out.println(String.valueOf(msg));53}5455static private native Method[] getJVMTIDeclaredMethods(Class<?> klass);5657public interface Parent {58default String def() { return "Parent.def"; }59String method0();60String method1();61}6263public interface Child extends Parent {64String method2();65}6667public static class Impl implements Child {68public String method0() { return "Impl.method0"; }69public String method1() { return "Impl.method1"; }70public String method2() { return "Impl.method2"; }71}7273public static void main(String[] args) {74new Impl(); // To get classes initialized7576Method[] reflectMethods = Child.class.getDeclaredMethods();77Method[] jvmtiMethods = getJVMTIDeclaredMethods(Child.class);7879if (jvmtiMethods == null) {80throw new RuntimeException("getJVMTIDeclaredMethods failed");81}8283log("Reflection getDeclaredMethods returned: " + Arrays.toString(reflectMethods));84log("JVMTI GetClassMethods returned: " + Arrays.toString(jvmtiMethods));8586if (reflectMethods.length != jvmtiMethods.length) {87throw new RuntimeException("OverpassMethods failed: Unexpected method count from JVMTI GetClassMethods!");88}89if (!reflectMethods[0].equals(jvmtiMethods[0])) {90throw new RuntimeException("OverpassMethods failed: Unexpected method from JVMTI GetClassMethods!");91}92log("Test passed: Got expected output from JVMTI GetClassMethods!");93}94}959697