Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/ClassUnload/SuperDependsTest.java
32284 views
/*1* Copyright (c) 2018, 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* @modules java.base/jdk.internal.misc28* java.compiler29* @library /testlibrary /testlibrary/whitebox /runtime/testlibrary30* @build sun.hotspot.WhiteBox31* @compile p2/c2.java MyDiffClassLoader.java32* @run main ClassFileInstaller sun.hotspot.WhiteBox33* sun.hotspot.WhiteBox$WhiteBoxPermission34* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SuperDependsTest35*/36import sun.hotspot.WhiteBox;37import p2.*;3839public class SuperDependsTest {40public static WhiteBox wb = WhiteBox.getWhiteBox();41public static final String MY_TEST = "SuperDependsTest$c1s";424344// p2.c2 loads through super class and creates dependency45public static class c1s extends p2.c2 {4647private void test() throws Exception {48method2();49}5051public c1s () throws Exception {52test();53ClassUnloadCommon.triggerUnloading(); // should not unload anything54test();55}56}5758public void test() throws Throwable {5960// now use the same loader to load class MyTest61Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST);6263// Call MyTest to load p2.c2 twice and call p2.c2.method264MyTest_class.newInstance();65ClassUnloadCommon.triggerUnloading(); // should not unload anything66ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded");67ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded");68// Unless MyTest_class is referenced here, the compiler can unload it.69System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive.");70}7172public static void main(String args[]) throws Throwable {73SuperDependsTest d = new SuperDependsTest();74d.test();75ClassUnloadCommon.triggerUnloading(); // should not unload anything76System.out.println("Should unload MyTest and p2.c2 just now");77ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded");78ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded");79}80}818283