Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassLoaderReference/definedClasses/definedclasses004.java
41161 views
/*1* Copyright (c) 2002, 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.jdi.ClassLoaderReference.definedClasses;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.connect.*;31import java.io.*;32import java.util.*;33import java.util.jar.*;3435/**36*/37public class definedclasses004 {3839//------------------------------------------------------- immutable common fields4041final static String SIGNAL_READY = "ready";42final static String SIGNAL_GO = "go";43final static String SIGNAL_QUIT = "quit";4445private static int waitTime;46private static int exitStatus;47private static ArgumentHandler argHandler;48private static Log log;49private static Debugee debuggee;50private static ReferenceType debuggeeClass;5152//------------------------------------------------------- mutable common fields5354private final static String prefix = "nsk.jdi.ClassLoaderReference.definedClasses.";55private final static String className = "definedclasses004";56private final static String debuggerName = prefix + className;57private final static String debuggeeName = debuggerName + "a";5859//------------------------------------------------------- test specific fields6061//------------------------------------------------------- immutable common methods6263public static void main(String argv[]) {64System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));65}6667private static void display(String msg) {68log.display("debugger > " + msg);69}7071private static void complain(String msg) {72log.complain("debugger FAILURE > " + msg);73}7475public static int run(String argv[], PrintStream out) {7677exitStatus = Consts.TEST_PASSED;7879argHandler = new ArgumentHandler(argv);80log = new Log(out, argHandler);81waitTime = argHandler.getWaitTime() * 60000;8283try {84debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);85debuggeeClass = debuggee.classByName(debuggeeName);86if ( debuggeeClass == null ) {87throw new Failure("Class '" + debuggeeName + "' not found.");88} else {89execTest();90}91} catch (Exception e) {92exitStatus = Consts.TEST_FAILED;93complain("Unexpected Exception: " + e.getMessage());94e.printStackTrace(out);95} finally {96debuggee.quit();97}9899return exitStatus;100}101102//------------------------------------------------------ mutable common method103104private static void execTest() {105106display("Getting ClassLoaderReference of class : " + debuggeeName);107ClassLoaderReference classLoader = debuggeeClass.classLoader();108if (classLoader == null) {109complain("classLoader() method returned null for ReferenceType mirror of : " + debuggeeName);110exitStatus = Consts.TEST_FAILED;111} else {112display("Getting definedClasses() list of : " + classLoader );113Iterator definedClasses = classLoader.definedClasses().iterator();114display("Checking isPrepared() result for ReferenceType's in the list...");115int count = 0;116while (definedClasses.hasNext()) {117ReferenceType refType = (ReferenceType)definedClasses.next();118count++;119if (!(refType instanceof ArrayType)) {120if (!refType.isPrepared()) {121complain("isPrepared() returned false for : " + refType);122exitStatus = Consts.TEST_FAILED;123}124}125}126display("Total number of items in definedClasses() list : " + count);127}128}129130//--------------------------------------------------------- test specific methods131132}133//--------------------------------------------------------- test specific classes134135136