Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassLoaderReference/visibleClasses/visibleclasses002.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.visibleClasses;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 visibleclasses002 {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.visibleClasses.";55private final static String className = "visibleclasses002";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() {105display("Getting ClassLoaderReference of debuggee's class.");106ClassLoaderReference classLoader = debuggeeClass.classLoader();107if (classLoader == null) {108complain("classLoader() method returned null for debuggee's ReferenceType.");109exitStatus = Consts.TEST_FAILED;110} else {111display("Getting visibleClasses list.");112Iterator visibleClasses = classLoader.visibleClasses().iterator();113boolean found0 = false;114boolean found1 = false;115boolean found2 = false;116display("Searching for debuggee's ReferenceType in the list...");117while (visibleClasses.hasNext()) {118ReferenceType refType = (ReferenceType)visibleClasses.next();119if (refType.equals(debuggeeClass)) {120display("visibleclasses002a ClassType is found in visibleClasses() list of ClassLoaderReference mirror.");121found0 = true;122} else if (refType instanceof ArrayType) {123Type compType;124try {125compType = ((ArrayType)refType).componentType();126if (compType instanceof ClassType && ((ReferenceType)compType).equals(debuggeeClass)) {127display("visibleclasses002a[] ArrayType is found in visibleClasses() list of ClassLoaderReference mirror.");128found1 = true;129} else if (compType instanceof ArrayType) {130compType = ((ArrayType)compType).componentType();131if (compType instanceof ClassType && ((ReferenceType)compType).equals(debuggeeClass)) {132display("visibleclasses002a[][] ArrayType is found in visibleClasses() list of ClassLoaderReference mirror.");133found2 = true;134}135}136} catch (ClassNotLoadedException e) {137throw new Failure("Unexpected ClassNotLoadedException while getting componentType() of : " + refType);138}139140}141}142if (!found0) {143complain("visibleclasses002a ReferenceType is NOT found in visibleClasses() list of ClassLoaderReference mirror.");144exitStatus = Consts.TEST_FAILED;145}146if (!found1) {147complain("visibleclasses002a[] ArrayType is NOT found in visibleClasses() list of ClassLoaderReference mirror.");148exitStatus = Consts.TEST_FAILED;149}150if (!found2) {151complain("visibleclasses002a[][] ArrayType is NOT found in visibleClasses() list of ClassLoaderReference mirror.");152exitStatus = Consts.TEST_FAILED;153}154}155}156157//--------------------------------------------------------- test specific methods158159}160//--------------------------------------------------------- test specific classes161162163