Path: blob/master/test/hotspot/jtreg/vmTestbase/metaspace/stressHierarchy/common/StressHierarchy2.java
41161 views
/*1* Copyright (c) 2013, 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*/22package metaspace.stressHierarchy.common;2324import metaspace.stressHierarchy.common.classloader.tree.Tree;25import metaspace.stressHierarchy.common.exceptions.ClassNotUnloadedException;26import nsk.share.test.ExecutionController;27import nsk.share.test.Tests;2829/**30* Test case checks that presence of ancestors does not prevent descenders of being reclaimed.31* We create hierarchy of classes, each loaded by dedicated classloader. Then we start the following32* routine in loop: release references to classes in bottom level, provoke unloading and check33* 1) that classes in bottom level were unloaded and34* 2) that next to bottom level was NOT unloaded.35*/36public class StressHierarchy2 extends StressHierarchyBaseClass {3738public static void main(String[] args) {39try {40StressHierarchyBaseClass.args = args;41Tests.runTest(new StressHierarchy2(), args);42} catch (OutOfMemoryError error) {43System.out.print("Got OOME: " + error.getMessage());44}45}4647@Override48protected void runTestLogic(Tree tree, ExecutionController stresser)49throws Throwable {5051for (int cleanupLevel = tree.getMaxLevel(); cleanupLevel >= 0; cleanupLevel-- ) {52tree.cleanupLevel(cleanupLevel);53log.info("cleanupLevel=" + cleanupLevel);54triggerUnloadingHelper.triggerUnloading(stresser);55if (!stresser.continueExecution()) {56return;57}58if (cleanupLevel > 0) {59performChecksHelper.checkLevelAlive(tree, cleanupLevel - 1);60}61if (!stresser.continueExecution()) {62return;63}6465try {66performChecksHelper.checkLevelReclaimed(tree, cleanupLevel);67} catch (ClassNotUnloadedException exception) {68log.error("Class was not unloaded." + exception.toString());69setFailed(true);70throw exception;71}72}73}7475}767778