Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassUnloadEvent/className/classname001a.java
41161 views
/*1* Copyright (c) 2001, 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.ClassUnloadEvent.className;2425import java.io.*;26import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;293031// This class is the debugged application in the test3233class classname001a {34static final int PASSED = 0;35static final int FAILED = 2;36static final int JCK_STATUS_BASE = 95;3738static final String PREFIX = "nsk.jdi.ClassUnloadEvent.className";39static final String CHECKED_CLASS = PREFIX + ".classname001b";4041public static void main(String args[]) {42classname001a _classname001a = new classname001a();43System.exit(JCK_STATUS_BASE + _classname001a.run(args));44}4546int run (String args[]) {47ArgumentHandler argHandler = new ArgumentHandler(args);48IOPipe pipe = argHandler.createDebugeeIOPipe();4950// define directory to class files51String loadClassDir = (argHandler.getArguments())[0] + File.separator + "loadclass";5253// notify debugger that debugee is ready54pipe.println(classname001.COMMAND_READY);5556// wait for a command to load checked class57String command = pipe.readln();58if (!command.equals(classname001.COMMAND_LOAD)) {59System.err.println("TEST BUG: unexpected command: " + command);60return FAILED;61}6263// load class for further unloading64ClassUnloader classUnloader = new ClassUnloader();65try {66classUnloader.loadClass(CHECKED_CLASS, loadClassDir);67} catch (Exception ex) {68System.err.println("Unexpected exception while loading classname001b:");69System.err.println(ex);70return FAILED;71}7273// notify debugger that checked class is loaded74pipe.println(classname001.COMMAND_LOADED);7576// turn off pipe pinging77pipe.setPingTimeout(0);7879// wait for a command to unload checked class80command = pipe.readln();81if (!command.equals(classname001.COMMAND_UNLOAD)) {82System.err.println("TEST BUG: unexpected command: " + command);83return FAILED;84}8586// try to unload checked class87boolean unloaded = classUnloader.unloadClass();8889if (!unloaded) {90pipe.println(classname001.COMMAND_LOADED);91} else {92pipe.println(classname001.COMMAND_UNLOADED);93}9495// wait for a command to exit96command = pipe.readln();97if (!command.equals(classname001.COMMAND_QUIT)) {98System.err.println("TEST BUG: unknown command: " + command);99return FAILED;100}101return PASSED;102}103}104105106