Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineInterfaceMethods.java
41153 views
/*1* Copyright (c) 2016, 2019, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8081800 801031926* @summary Redefine private and default interface methods27* @requires vm.jvmti28* @library /test/lib29* @modules java.base/jdk.internal.misc30* @modules java.compiler31* java.instrument32* jdk.jartool/sun.tools.jar33* @run main RedefineClassHelper34* @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineInterfaceMethods35*/3637// package access top-level class to avoid problem with RedefineClassHelper38// and nested types.3940interface RedefineInterfaceMethods_B {41int ORIGINAL_RETURN = 1;42int NEW_RETURN = 2;43private int privateMethod() {44return ORIGINAL_RETURN;45}46public default int defaultMethod() {47return privateMethod();48}49}5051public class RedefineInterfaceMethods {5253static final int RET = -2;5455public static String redefinedPrivateMethod =56"interface RedefineInterfaceMethods_B {" +57" int ORIGINAL_RETURN = 1;" +58" int NEW_RETURN = 2;" +59" private int privateMethod() {" +60" return NEW_RETURN;" +61" }" +62" public default int defaultMethod() {" +63" return privateMethod();" +64" }" +65"}";6667public static String redefinedDefaultMethod =68"interface RedefineInterfaceMethods_B {" +69" int ORIGINAL_RETURN = 1;" +70" int NEW_RETURN = 2;" +71" private int privateMethod() {" +72" return ORIGINAL_RETURN;" +73" }" +74" public default int defaultMethod() {" +75" return RedefineInterfaceMethods.RET;" +76" }" +77"}";7879static class Impl implements RedefineInterfaceMethods_B {80}818283public static void main(String[] args) throws Exception {8485Impl impl = new Impl();8687int res = impl.defaultMethod();88if (res != RedefineInterfaceMethods_B.ORIGINAL_RETURN)89throw new Error("defaultMethod returned " + res +90" expected " + RedefineInterfaceMethods_B.ORIGINAL_RETURN);9192RedefineClassHelper.redefineClass(RedefineInterfaceMethods_B.class, redefinedPrivateMethod);9394res = impl.defaultMethod();95if (res != RedefineInterfaceMethods_B.NEW_RETURN)96throw new Error("defaultMethod returned " + res +97" expected " + RedefineInterfaceMethods_B.NEW_RETURN);9899System.gc();100101RedefineClassHelper.redefineClass(RedefineInterfaceMethods_B.class, redefinedDefaultMethod);102103res = impl.defaultMethod();104if (res != RET)105throw new Error("defaultMethod returned " + res +106" expected " + RET);107}108}109110111