Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/sysdict/share/ChainTest.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 java.lang.reflect.Field;26import nsk.share.Failure;27import nsk.share.TestFailure;28import nsk.share.sysdict.ClassLoadersChain;29import nsk.share.test.Tests;3031/**32* This is a main class for all chain tests.33*/34public class ChainTest extends SysDictTest {3536public ChainTest(String[] args) {37parseArgs(args);38}3940public static void main(String args[]) {41Tests.runTest(new ChainTest(args), args);42}43private static final int NxM_FACTOR = 450;44private int classesHeight;45private int loadersHeight;46String[] classNames;4748@Override49protected void parseArgs(String args[]) {50super.parseArgs(args);51boolean isLoaderHeightDefault = true;52boolean isHeightDefault = true;53for (int i = 0; i < args.length; i++) {54if (args[i].equals("-classloaderHeight")) {55loadersHeight = Integer.parseInt(args[i + 1]);56if (loadersHeight > 0) {57isLoaderHeightDefault = false;58}59}60if (args[i].equals("-height")) {61classesHeight = Integer.parseInt(args[i + 1]);62if (classesHeight > 0) {63isHeightDefault = false;64}65}66}6768Class info;69try {70if (useFats) {71info = createJarLoader().loadClass(PACKAGE_PREFIX + "FatsInfo");72} else {73info = createJarLoader().loadClass(PACKAGE_PREFIX + "LeansInfo");74}75System.out.println("name=" + info.getName());76for (Field field : info.getDeclaredFields()) {77System.err.println("field = " + field.getName());78}79if (isHeightDefault) {80classesHeight = info.getField("HEIGHT").getInt(null);81}828384if (isLoaderHeightDefault) {85loadersHeight = NxM_FACTOR / classesHeight;86}8788if (loadersHeight * classesHeight != NxM_FACTOR) {89throw new Failure("classes height must divide " + NxM_FACTOR);90}9192if (loadersHeight == 0) {93throw new Failure("loaders height should be positive");94}95if (classesHeight == 0) {96throw new Failure("classes height should be positive");97}98classNames = new String[classesHeight];99for (int i = 0; i < classesHeight; i++) {100classNames[i] = PACKAGE_PREFIX + info.getField("rootName").get(null)101+ ((String[]) info.getField("nodeNames").get(null))[i];102}103if (classNames == null || classNames.length == 0) {104throw new TestFailure("No classes names for loading");105}106System.out.println("The classHeight = " + classesHeight + " the loadersHeight = " + loadersHeight);107} catch (Exception e) {108throw new TestFailure("Can't initialize test correctly", e);109}110111}112113@Override114String[] getClassNames() {115return classNames;116}117118@Override119ClassLoader[] createLoaders() {120ClassLoader loaders[] = new ClassLoader[loadersHeight];121ClassLoader jarLoader = createJarLoader();122ClassLoadersChain loadersChain =123new ClassLoadersChain(jarLoader, loadersHeight);124// direct ordering: root loader first125for (int i = 0; i < loadersHeight; i++) {126loaders[i] = loadersChain.getLoader(loadersHeight - 1 - i);127}128return loaders;129}130}131132133