test/hotspot/jtreg/vmTestbase/nsk/sysdict/share/BTreeTest.java
changeset 50154 d2d6bc39ea88
equal deleted inserted replaced
50152:b5023063346d 50154:d2d6bc39ea88
       
     1 /*
       
     2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package nsk.sysdict.share;
       
    25 
       
    26 import nsk.share.Denotation;
       
    27 import nsk.share.Failure;
       
    28 import nsk.share.TestFailure;
       
    29 import nsk.share.sysdict.ClassLoadersBTree;
       
    30 import nsk.share.test.Tests;
       
    31 
       
    32 /**
       
    33  * This class is used by btree tests.
       
    34  */
       
    35 public class BTreeTest extends SysDictTest {
       
    36 
       
    37     public BTreeTest(String[] args) {
       
    38         parseArgs(args);
       
    39     }
       
    40 
       
    41     public static void main(String args[]) {
       
    42         Tests.runTest(new BTreeTest(args), args);
       
    43     }
       
    44     private int height;
       
    45     protected int level;
       
    46     String[] nodeNames;
       
    47     String[] classNames;
       
    48 
       
    49     @Override
       
    50     protected void parseArgs(String args[]) {
       
    51         super.parseArgs(args);
       
    52         for (int i = 0; i < args.length; i++) {
       
    53             if (args[i].equals("-level")) {
       
    54                 level = Integer.parseInt(args[i + 1]);
       
    55             }
       
    56             if (args[i].equals("-height")) {
       
    57                 height = Integer.parseInt(args[i + 1]);
       
    58             }
       
    59         }
       
    60         try {
       
    61             // Load FatsInfo with URLClassLoader btree.jar & fats.jar should not
       
    62             // present in classpath
       
    63             Class info;
       
    64             if (useFats) {
       
    65                 info = createJarLoader().loadClass(PACKAGE_PREFIX + "FatsInfo");
       
    66             } else {
       
    67                 info = createJarLoader().loadClass(PACKAGE_PREFIX + "BTreeInfo");
       
    68             }
       
    69 
       
    70             if (height == 0) {
       
    71                 height = info.getField("HEIGHT").getInt(null) - 1;
       
    72             }
       
    73 
       
    74             if (level == 0) {
       
    75                 level = height - 1;
       
    76             }
       
    77 
       
    78             if (level >= height) {
       
    79                 throw new Failure("Icorrect level : " + level + " .Should be less then " + height);
       
    80             }
       
    81 
       
    82             // generate names for all nodes at the given level:
       
    83             Denotation denotation = null;
       
    84             if (!useFats) {
       
    85                 denotation = (Denotation) info.getField("nodesDenotation").get(null);
       
    86             }
       
    87 
       
    88             // Set all classnames
       
    89             String prefix = PACKAGE_PREFIX + info.getField("rootName").get(null);
       
    90             nodeNames = new String[1 << level];
       
    91             classNames = new String[1 << level];
       
    92             for (int i = 0; i < nodeNames.length; i++) {
       
    93                 if (useFats) {
       
    94                     classNames[i] = prefix + ((String[]) info.getField("nodeNames").get(null))[height - 1];
       
    95                 } else {
       
    96                     nodeNames[i] = denotation.nameFor(level, i);
       
    97                     classNames[i] = prefix + nodeNames[i];
       
    98                 }
       
    99             }
       
   100             System.out.println("The level = " + level + " the height = " + height);
       
   101         } catch (Exception e) {
       
   102             throw new TestFailure("Can't initialize test correctly", e);
       
   103         }
       
   104     }
       
   105 
       
   106     @Override
       
   107     protected final String[] getClassNames() {
       
   108         return classNames;
       
   109     }
       
   110 
       
   111     @Override
       
   112     protected final ClassLoader[] createLoaders() {
       
   113         ClassLoader jarLoader = createJarLoader();
       
   114         ClassLoader loaders[] = new ClassLoader[nodeNames.length];
       
   115         ClassLoadersBTree loadersTree = new ClassLoadersBTree(jarLoader, height);
       
   116         for (int i = 0; i < loaders.length; i++) {
       
   117             loaders[i] = loadersTree.getLoader(nodeNames[i]);
       
   118         }
       
   119         return loaders;
       
   120     }
       
   121 }