test/runtime/RedefineTests/RedefineDoubleDelete.java

Thu, 26 Sep 2019 06:56:38 +0100

author
zgu
date
Thu, 26 Sep 2019 06:56:38 +0100
changeset 9754
4170228e11e6
parent 9748
628176d22495
permissions
-rw-r--r--

8231463: Fix runtime/RedefineTests/RedefineDoubleDelete.java test in 8u
Reviewed-by: andrew

zgu@9748 1 /*
zgu@9748 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
zgu@9748 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@9748 4 *
zgu@9748 5 * This code is free software; you can redistribute it and/or modify it
zgu@9748 6 * under the terms of the GNU General Public License version 2 only, as
zgu@9748 7 * published by the Free Software Foundation.
zgu@9748 8 *
zgu@9748 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@9748 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@9748 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@9748 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@9748 13 * accompanied this code).
zgu@9748 14 *
zgu@9748 15 * You should have received a copy of the GNU General Public License version
zgu@9748 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@9748 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@9748 18 *
zgu@9748 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@9748 20 * or visit www.oracle.com if you need additional information or have any
zgu@9748 21 * questions.
zgu@9748 22 */
zgu@9748 23
zgu@9748 24 /*
zgu@9748 25 * @test
zgu@9748 26 * @bug 8178870
zgu@9754 27 * @library /testlibrary
zgu@9748 28 * @summary Redefine class with CFLH twice to test deleting the cached_class_file
zgu@9754 29 * @build RedefineClassHelper
zgu@9754 30 * @run main RedefineClassHelper
zgu@9754 31 * @run main/othervm -javaagent:redefineagent.jar RedefineDoubleDelete
zgu@9748 32 */
zgu@9748 33
zgu@9748 34 public class RedefineDoubleDelete {
zgu@9748 35
zgu@9748 36 // Class gets a redefinition error because it adds a data member
zgu@9748 37 public static String newB =
zgu@9748 38 "class RedefineDoubleDelete$B {" +
zgu@9748 39 " int count1 = 0;" +
zgu@9748 40 "}";
zgu@9748 41
zgu@9748 42 public static String newerB =
zgu@9748 43 "class RedefineDoubleDelete$B { " +
zgu@9748 44 " int faa() { System.out.println(\"baa\"); return 2; }" +
zgu@9748 45 "}";
zgu@9748 46
zgu@9748 47 // The ClassFileLoadHook for this class turns foo into faa and prints out faa.
zgu@9748 48 static class B {
zgu@9748 49 int faa() { System.out.println("foo"); return 1; }
zgu@9748 50 }
zgu@9748 51
zgu@9748 52 public static void main(String args[]) throws Exception {
zgu@9748 53
zgu@9748 54 B b = new B();
zgu@9748 55 int val = b.faa();
zgu@9748 56 if (val != 1) {
zgu@9748 57 throw new RuntimeException("return value wrong " + val);
zgu@9748 58 }
zgu@9748 59
zgu@9748 60 // Redefine B twice to get cached_class_file in both B scratch classes
zgu@9748 61 try {
zgu@9748 62 RedefineClassHelper.redefineClass(B.class, newB);
zgu@9748 63 } catch (java.lang.UnsupportedOperationException e) {
zgu@9748 64 // this is expected
zgu@9748 65 }
zgu@9748 66 try {
zgu@9748 67 RedefineClassHelper.redefineClass(B.class, newB);
zgu@9748 68 } catch (java.lang.UnsupportedOperationException e) {
zgu@9748 69 // this is expected
zgu@9748 70 }
zgu@9748 71
zgu@9748 72 // Do a full GC.
zgu@9748 73 System.gc();
zgu@9748 74
zgu@9748 75 // Redefine with a compatible class
zgu@9748 76 RedefineClassHelper.redefineClass(B.class, newerB);
zgu@9748 77 val = b.faa();
zgu@9748 78 if (val != 2) {
zgu@9748 79 throw new RuntimeException("return value wrong " + val);
zgu@9748 80 }
zgu@9748 81
zgu@9748 82 // Do another full GC to clean things up.
zgu@9748 83 System.gc();
zgu@9748 84 }
zgu@9748 85 }

mercurial