Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineInterfaceCall.java
41153 views
/*1* Copyright (c) 2017, 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 8174962 801031926* @summary Redefine class with interface method call27* @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+update*=trace RedefineInterfaceCall35*/3637import static jdk.test.lib.Asserts.assertEquals;3839interface I1 { default int m() { return 0; } }40interface I2 extends I1 {}4142// package access top-level class to avoid problem with RedefineClassHelper43// and nested types.44class RedefineInterfaceCall_C implements I2 {45public int test(I2 i) {46return i.m(); // invokeinterface cpCacheEntry47}48}4950public class RedefineInterfaceCall {5152static String newI1 =53"interface I1 { default int m() { return 1; } }";5455static String newC =56"class RedefineInterfaceCall_C implements I2 { " +57" public int test(I2 i) { " +58" return i.m(); " +59" } " +60"} ";6162static int test(I2 i) {63return i.m(); // invokeinterface cpCacheEntry64}6566public static void main(String[] args) throws Exception {67RedefineInterfaceCall_C c = new RedefineInterfaceCall_C();6869assertEquals(test(c), 0);70assertEquals(c.test(c), 0);7172RedefineClassHelper.redefineClass(RedefineInterfaceCall_C.class, newC);7374assertEquals(c.test(c), 0);7576RedefineClassHelper.redefineClass(I1.class, newI1);7778assertEquals(test(c), 1);79assertEquals(c.test(c), 1);8081RedefineClassHelper.redefineClass(RedefineInterfaceCall_C.class, newC);8283assertEquals(c.test(c), 1);84}85}868788