Path: blob/master/test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java
40942 views
/*1* Copyright (c) 2018, 2021, 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* @test SuperDependsTest25* @bug 821009426* @summary Create ClassLoader dependency from initiating loader to class loader through subclassing27* @requires vm.opt.final.ClassUnloading28* @modules java.base/jdk.internal.misc29* java.compiler30* @library /test/lib31* @build sun.hotspot.WhiteBox32* @compile p2/c2.java MyDiffClassLoader.java33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI SuperDependsTest35*/3637import sun.hotspot.WhiteBox;38import p2.*;39import jdk.test.lib.classloader.ClassUnloadCommon;4041public class SuperDependsTest {42public static WhiteBox wb = WhiteBox.getWhiteBox();43public static final String MY_TEST = "SuperDependsTest$c1s";444546// p2.c2 loads through super class and creates dependency47public static class c1s extends p2.c2 {4849private void test() throws Exception {50method2();51}5253public c1s () throws Exception {54test();55ClassUnloadCommon.triggerUnloading(); // should not unload anything56test();57}58}5960public void test() throws Throwable {6162// now use the same loader to load class MyTest63Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST);6465// Call MyTest to load p2.c2 twice and call p2.c2.method266MyTest_class.newInstance();67ClassUnloadCommon.triggerUnloading(); // should not unload anything68ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded");69ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded");70// Unless MyTest_class is referenced here, the compiler can unload it.71System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive.");72}7374public static void main(String args[]) throws Throwable {75SuperDependsTest d = new SuperDependsTest();76d.test();77ClassUnloadCommon.triggerUnloading(); // should not unload anything78System.out.println("Should unload MyTest and p2.c2 just now");79ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded");80ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded");81}82}838485