Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/sysdict/share/BTreeTest.java
41161 views
/*1* Copyright (c) 2010, 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*/2223package nsk.sysdict.share;2425import nsk.share.Denotation;26import nsk.share.Failure;27import nsk.share.TestFailure;28import nsk.share.sysdict.ClassLoadersBTree;29import nsk.share.test.Tests;3031/**32* This class is used by btree tests.33*/34public class BTreeTest extends SysDictTest {3536public BTreeTest(String[] args) {37parseArgs(args);38}3940public static void main(String args[]) {41Tests.runTest(new BTreeTest(args), args);42}43private int height;44protected int level;45String[] nodeNames;46String[] classNames;4748@Override49protected void parseArgs(String args[]) {50super.parseArgs(args);51for (int i = 0; i < args.length; i++) {52if (args[i].equals("-level")) {53level = Integer.parseInt(args[i + 1]);54}55if (args[i].equals("-height")) {56height = Integer.parseInt(args[i + 1]);57}58}59try {60// Load FatsInfo with URLClassLoader btree.jar & fats.jar should not61// present in classpath62Class info;63if (useFats) {64info = createJarLoader().loadClass(PACKAGE_PREFIX + "FatsInfo");65} else {66info = createJarLoader().loadClass(PACKAGE_PREFIX + "BTreeInfo");67}6869if (height == 0) {70height = info.getField("HEIGHT").getInt(null) - 1;71}7273if (level == 0) {74level = height - 1;75}7677if (level >= height) {78throw new Failure("Icorrect level : " + level + " .Should be less then " + height);79}8081// generate names for all nodes at the given level:82Denotation denotation = null;83if (!useFats) {84denotation = (Denotation) info.getField("nodesDenotation").get(null);85}8687// Set all classnames88String prefix = PACKAGE_PREFIX + info.getField("rootName").get(null);89nodeNames = new String[1 << level];90classNames = new String[1 << level];91for (int i = 0; i < nodeNames.length; i++) {92if (useFats) {93classNames[i] = prefix + ((String[]) info.getField("nodeNames").get(null))[height - 1];94} else {95nodeNames[i] = denotation.nameFor(level, i);96classNames[i] = prefix + nodeNames[i];97}98}99System.out.println("The level = " + level + " the height = " + height);100} catch (Exception e) {101throw new TestFailure("Can't initialize test correctly", e);102}103}104105@Override106protected final String[] getClassNames() {107return classNames;108}109110@Override111protected final ClassLoader[] createLoaders() {112ClassLoader jarLoader = createJarLoader();113ClassLoader loaders[] = new ClassLoader[nodeNames.length];114ClassLoadersBTree loadersTree = new ClassLoadersBTree(jarLoader, height);115for (int i = 0; i < loaders.length; i++) {116loaders[i] = loadersTree.getLoader(nodeNames[i]);117}118return loaders;119}120}121122123