Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineDoubleDelete.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 8178870 801031926* @summary Redefine class with CFLH twice to test deleting the cached_class_file27* @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/native -Xlog:redefine+class+load+exceptions -agentlib:RedefineDoubleDelete -javaagent:redefineagent.jar RedefineDoubleDelete35*/3637// package access top-level class to avoid problem with RedefineClassHelper38// and nested types.3940// The ClassFileLoadHook for this class turns foo into faa and prints out faa.41class RedefineDoubleDelete_B {42int faa() { System.out.println("foo"); return 1; }43}4445public class RedefineDoubleDelete {4647// Class gets a redefinition error because it adds a data member48public static String newB =49"class RedefineDoubleDelete_B {" +50" int count1 = 0;" +51"}";5253public static String newerB =54"class RedefineDoubleDelete_B { " +55" int faa() { System.out.println(\"baa\"); return 2; }" +56"}";5758public static void main(String args[]) throws Exception {5960RedefineDoubleDelete_B b = new RedefineDoubleDelete_B();61int val = b.faa();62if (val != 1) {63throw new RuntimeException("return value wrong " + val);64}6566// Redefine B twice to get cached_class_file in both B scratch classes67try {68RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newB);69} catch (java.lang.UnsupportedOperationException e) {70// this is expected71}72try {73RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newB);74} catch (java.lang.UnsupportedOperationException e) {75// this is expected76}7778// Do a full GC.79System.gc();8081// Redefine with a compatible class82RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newerB);83val = b.faa();84if (val != 2) {85throw new RuntimeException("return value wrong " + val);86}8788// Do another full GC to clean things up.89System.gc();90}91}929394