Path: blob/master/test/hotspot/jtreg/vmTestbase/metaspace/stressHierarchy/common/StressHierarchyBaseClass.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 java.net.MalformedURLException;2526import vm.share.gc.TriggerUnloadingByFillingMetaspace;27import vm.share.gc.TriggerUnloadingHelper;28import vm.share.gc.TriggerUnloadingWithWhiteBox;2930import metaspace.stressHierarchy.common.classloader.tree.Node;31import metaspace.stressHierarchy.common.classloader.tree.Tree;32import metaspace.stressHierarchy.common.exceptions.GotWrongOOMEException;33import metaspace.stressHierarchy.common.exceptions.TimeIsOverException;34import metaspace.stressHierarchy.common.generateHierarchy.GenerateHierarchyHelper;35import metaspace.stressHierarchy.common.generateHierarchy.GenerateHierarchyHelper.Type;36import metaspace.stressHierarchy.common.generateHierarchy.NodeDescriptor;37import metaspace.stressHierarchy.common.generateHierarchy.TreeDescriptor;38import nsk.share.test.ExecutionController;39import nsk.share.test.Stresser;40import nsk.share.test.TestBase;414243/**44* Superclass for StressHierarchy* tests. It provides util methods to create and load45* classes hierarchy and perform checks.46*/47abstract public class StressHierarchyBaseClass extends TestBase {4849protected static String[] args;5051protected TriggerUnloadingHelper triggerUnloadingHelper = new TriggerUnloadingWithWhiteBox(); //default helper5253protected PerformChecksHelper performChecksHelper = null;5455private int treeDepth;5657private int minLevelSize;5859private int maxLevelSize;6061private Type hierarchyType;6263public void run() {64try {65int attemptsLimit = -1; // -1 means using default value defined in PerformChecksHelper66long unloadingPause = -1; // -1 means the same67int pausesLimit = -1; // -1 means the same6869for (int ind = 0; ind < args.length; ind++ ) {70if ("-triggerUnloadingByFillingMetaspace".equals(args[ind])) {71log.info("using TriggerUnloadingByFillingMetaspace");72triggerUnloadingHelper = new TriggerUnloadingByFillingMetaspace();73} else if ("-treeDepth".equals(args[ind])) {74this.treeDepth = Integer.parseInt(args[ind + 1]);75} else if ("-minLevelSize".equals(args[ind])) {76this.minLevelSize = Integer.parseInt(args[ind + 1]);77} else if ("-maxLevelSize".equals(args[ind])) {78this.maxLevelSize = Integer.parseInt(args[ind + 1]);79} else if ("-attemptsLimit".equals(args[ind])) {80attemptsLimit = Integer.valueOf(args[ind + 1]);81} else if ("-unloadingPause".equals(args[ind])) {82unloadingPause = Long.valueOf(args[ind + 1]);83} else if ("-pausesLimit".equals(args[ind])) {84pausesLimit = Integer.valueOf(args[ind + 1]);85} else if ("-hierarchyType".equals(args[ind])) {86String s = args[ind + 1];87hierarchyType = Type.CLASSES.toString().equals(s) ? Type.CLASSES :88(Type.INTERFACES.toString().equals(s) ? Type.INTERFACES : Type.MIXED);89System.out.println("hierarchyType = " + hierarchyType);90} else if (args[ind].startsWith("-") && !args[ind].equals("-stressTime")) {91throw new RuntimeException("Unknown option " + args[ind]);92}93}94performChecksHelper = new PerformChecksHelper(triggerUnloadingHelper, attemptsLimit, unloadingPause, pausesLimit);95log.info("treeDepth=" + treeDepth + ", minLevelSize=" + minLevelSize + ", maxLevelSize=" + maxLevelSize + ", hierarchyType=" + hierarchyType +96", triggerUnloadingHelper.getClass().getName()=" + triggerUnloadingHelper.getClass().getName());9798long startTimeStamp = System.currentTimeMillis();99ExecutionController stresser = new Stresser(args);100stresser.start(1);101TreeDescriptor treeDescriptor = GenerateHierarchyHelper.generateHierarchy(treeDepth, minLevelSize, maxLevelSize, hierarchyType);102Tree tree = buildTree(treeDescriptor);103System.out.println("Generating took " + ((System.currentTimeMillis() - startTimeStamp)/1000) +" sec");104105performChecksHelper.setStresser(stresser);106107runTestLogic(tree, stresser);108109System.out.println("Whole test took " + ((System.currentTimeMillis() - startTimeStamp)/1000/60.0) +" min");110log.info("Test PASSED");111} catch (GotWrongOOMEException e) {112log.info("GotWrongOOMEExc: " + e.getMessage());113log.info("Got wrong type of OOME. We are passing test as it breaks test logic. We have dedicated test configurations" +114" for each OOME type provoking class unloading, that's why we are not missing test coverage here.");115} catch (OutOfMemoryError e) {116log.info("Got OOME.");117} catch (TimeIsOverException e) {118log.info("Time is over. That's okay. Passing test");119} catch (Throwable throwable) {120//Throw runtime exception. nsk framework will catch it, log and set appropriate exit code121log.error("Test failed. Exception catched.");122throwable.printStackTrace();123throw new RuntimeException(throwable);124}125}126127abstract protected void runTestLogic(Tree tree, ExecutionController stresser) throws Throwable;128129private Tree buildTree(TreeDescriptor treeDescriptor) throws MalformedURLException,130ClassNotFoundException, InstantiationException,131IllegalAccessException {132log.info("Create tree");133Tree tree = new Tree();134for (NodeDescriptor nodeDescriptor : treeDescriptor.nodeDescriptorList) {135tree.addNode(nodeDescriptor);136}137138log.info("Load classes and instantiate objects");139for (Node node : tree.getNodes()) {140node.loadClasses();141node.instantiateObjects();142}143return tree;144}145146}147148149