Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/RedefineTests/RedefineDoubleDelete.java
32284 views
/*1* Copyright (c) 2017, 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 817887026* @library /testlibrary27* @summary Redefine class with CFLH twice to test deleting the cached_class_file28* @build RedefineClassHelper29* @run main RedefineClassHelper30* @run main/othervm -javaagent:redefineagent.jar RedefineDoubleDelete31*/3233public class RedefineDoubleDelete {3435// Class gets a redefinition error because it adds a data member36public static String newB =37"class RedefineDoubleDelete$B {" +38" int count1 = 0;" +39"}";4041public static String newerB =42"class RedefineDoubleDelete$B { " +43" int faa() { System.out.println(\"baa\"); return 2; }" +44"}";4546// The ClassFileLoadHook for this class turns foo into faa and prints out faa.47static class B {48int faa() { System.out.println("foo"); return 1; }49}5051public static void main(String args[]) throws Exception {5253B b = new B();54int val = b.faa();55if (val != 1) {56throw new RuntimeException("return value wrong " + val);57}5859// Redefine B twice to get cached_class_file in both B scratch classes60try {61RedefineClassHelper.redefineClass(B.class, newB);62} catch (java.lang.UnsupportedOperationException e) {63// this is expected64}65try {66RedefineClassHelper.redefineClass(B.class, newB);67} catch (java.lang.UnsupportedOperationException e) {68// this is expected69}7071// Do a full GC.72System.gc();7374// Redefine with a compatible class75RedefineClassHelper.redefineClass(B.class, newerB);76val = b.faa();77if (val != 2) {78throw new RuntimeException("return value wrong " + val);79}8081// Do another full GC to clean things up.82System.gc();83}84}858687