Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassLoaderReference/definedClasses/definedclasses003.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 definedclasses003 {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 = "definedclasses003";56private final static String debuggerName = prefix + className;57private final static String debuggeeName = debuggerName + "a";5859//------------------------------------------------------- test specific fields6061private final static String classLoaderName = prefix + "fields002aClassLoader";62private final static String classFieldName = "loadedClass";6364//------------------------------------------------------- immutable common methods6566public static void main(String argv[]) {67System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));68}6970private static void display(String msg) {71log.display("debugger > " + msg);72}7374private static void complain(String msg) {75log.complain("debugger FAILURE > " + msg);76}7778public static int run(String argv[], PrintStream out) {7980exitStatus = Consts.TEST_PASSED;8182argHandler = new ArgumentHandler(argv);83log = new Log(out, argHandler);84waitTime = argHandler.getWaitTime() * 60000;8586try {87debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);88debuggeeClass = debuggee.classByName(debuggeeName);89if ( debuggeeClass == null ) {90throw new Failure("Class '" + debuggeeName + "' not found.");91} else {92execTest();93}94} catch (Exception e) {95exitStatus = Consts.TEST_FAILED;96complain("Unexpected Exception: " + e.getMessage());97e.printStackTrace(out);98} finally {99debuggee.quit();100}101102return exitStatus;103}104105//------------------------------------------------------ mutable common method106107private static void execTest() {108109while (true) {110Field classField = debuggeeClass.fieldByName(classFieldName);111if ( classField == null) {112complain("Checked field is not found in the debuggee: " + classFieldName);113exitStatus = Consts.TEST_FAILED;114break;115}116117Value classValue = debuggeeClass.getValue(classField);118119ClassObjectReference classObjRef = null;120try {121classObjRef = (ClassObjectReference)classValue;122} catch (Exception e) {123complain("Unexpected exception while getting ClassObjectReference : " + e.getMessage());124exitStatus = Consts.TEST_FAILED;125break;126}127128ReferenceType refType1 = classObjRef.reflectedType();129if (!refType1.isPrepared()) {130complain("isPrepared() returned false for " + refType1);131exitStatus = Consts.TEST_FAILED;132break;133} else {134display("isPrepared() returned true for " + refType1);135}136137display("Getting ClassLoaderReference of ReferenceType: " + refType1 );138ClassLoaderReference classLoader = refType1.classLoader();139if (classLoader == null) {140complain("classLoader() method returned null for ReferenceType: " + refType1);141exitStatus = Consts.TEST_FAILED;142break;143}144145display("Getting definedClasses list.");146Iterator definedClasses = classLoader.definedClasses().iterator();147boolean found = false;148display("Searching in the list for ReferenceType : " + refType1);149while (definedClasses.hasNext()) {150ReferenceType refType = (ReferenceType)definedClasses.next();151if (refType.equals(refType1)) {152found = true;153} else {154complain("Unexpected ReferenceType : " + refType + "\n\t is found in definedClasses() list of " + classLoaderName + " mirror.");155exitStatus = Consts.TEST_FAILED;156}157}158159if (found) {160display("ReferenceType : " + refType1 + "\n\t is found in definedClasses() list of " + classLoaderName + " mirror.");161} else {162complain("ReferenceType : " + refType1 + "\n\t is NOT found in definedClasses() list of " + classLoaderName + " mirror.");163exitStatus = Consts.TEST_FAILED;164}165166break;167}168}169170//--------------------------------------------------------- test specific methods171172}173//--------------------------------------------------------- test specific classes174175176