1 /* 2 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8308762 27 * @library /test/lib 28 * @summary Test that redefinition of class containing Throwable refs does not leak constant pool 29 * @requires os.family == "aix" 30 * @requires vm.jvmti 31 * @requires vm.flagless 32 * @modules java.base/jdk.internal.misc 33 * @modules java.instrument 34 * java.compiler 35 * @run main RedefineClassHelper 36 * @run main/othervm/timeout=6000 -javaagent:redefineagent.jar -XX:MetaspaceSize=23m -XX:MaxMetaspaceSize=23m RedefineLeakThrowable 37 */ 38 39 /* 40 * @test 41 * @bug 8308762 42 * @library /test/lib 43 * @summary Test that redefinition of class containing Throwable refs does not leak constant pool 44 * @requires os.family != "aix" 45 * @requires vm.jvmti 46 * @requires vm.flagless 47 * @modules java.base/jdk.internal.misc 48 * @modules java.instrument 49 * java.compiler 50 * @run main RedefineClassHelper 51 * @run main/othervm/timeout=6000 -javaagent:redefineagent.jar -XX:MetaspaceSize=17m -XX:MaxMetaspaceSize=17m RedefineLeakThrowable 52 */ 53 54 class Tester { 55 void test() { 56 try { 57 int i = 42; 58 } catch (Throwable t) { 59 t.printStackTrace(); 60 } 61 } 62 } 63 64 public class RedefineLeakThrowable { 65 66 static final String NEW_TESTER = 67 "class Tester {" + 68 " void test() {" + 69 " try {" + 70 " int i = 42;" + 71 " } catch (Throwable t) {" + 72 " t.printStackTrace();" + 73 " }" + 74 " }" + 75 "}"; 76 77 78 public static void main(String argv[]) throws Exception { 79 for (int i = 0; i < 700; i++) { 80 RedefineClassHelper.redefineClass(Tester.class, NEW_TESTER); 81 } 82 } 83 }