Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassUnloadEvent/classSignature/signature001a.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.classSignature;2425import java.io.*;26import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import java.lang.reflect.Method;3132// This class is the debugged application in the test3334// NOTE: Test does not check array class because of difficulty of35// providing reliable technique for unloading such class.36// So all these testcases are commented in the test.3738class signature001a {39static final int PASSED = 0;40static final int FAILED = 2;41static final int JCK_STATUS_BASE = 95;4243static final String PREFIX = "nsk.jdi.ClassUnloadEvent.classSignature";44static final String CHECKED_CLASS = PREFIX + ".signature001c";45static final String CHECKED_INTFACE = PREFIX + ".signature001b";46static final String CHECKED_ARRAY = PREFIX + ".signature001c[]";4748public static void main(String args[]) {49signature001a _signature001a = new signature001a();50System.exit(JCK_STATUS_BASE + _signature001a.run(args));51}5253int run (String args[]) {54ArgumentHandler argHandler = new ArgumentHandler(args);55IOPipe pipe = argHandler.createDebugeeIOPipe();5657// define directory to load class files58String loadClassDir = (argHandler.getArguments())[0] + File.separator + "loadclass";5960// notify debugger that debugee is ready61pipe.println(signature001.COMMAND_READY);6263// wait for a command to load checked class64String command = pipe.readln();65if (!command.equals(signature001.COMMAND_LOAD)) {66System.err.println("TEST BUG: unexpected command: " + command);67return FAILED;68}6970// load checked class for further unloading71ClassUnloader checkedClassUnloader = new ClassUnloader();72try {73checkedClassUnloader.loadClass(CHECKED_CLASS, loadClassDir);74} catch (Exception ex) {75System.err.println("Unexpected exception while loading " + CHECKED_CLASS + ":");76System.err.println(ex);77return FAILED;78}7980// load checked interface for further unloading81ClassUnloader checkedInterfaceUnloader = new ClassUnloader();82try {83checkedInterfaceUnloader.loadClass(CHECKED_INTFACE, loadClassDir);84} catch (Exception ex) {85System.err.println("Unexpected exception while loading " + CHECKED_INTFACE + ":");86System.err.println(ex);87return FAILED;88}8990/*91// to load array type92Object object1;93try {94object1 = class1.newInstance();95} catch (Throwable e) {96System.err.println("Cannot create instance of " + CHECKED_CLASS);97System.err.println("Exception/error: " + e.getMessage());98return FAILED;99}100Method method1;101try {102method1 = class1.getMethod("initArray", null);103method1.invoke(object1, null);104System.out.println("method initArray is invoked");105} catch (Exception e) {106System.out.println(e.getMessage());107}108try {109if (!(Class.forName(CHECKED_ARRAY).getClassLoader() instanceof KlassLoader)) {110System.err.println("TEST BUG: Incorrect loader of type" + CHECKED_ARRAY);111return FAILED;112}113} catch (Exception e) {114System.out.println(e.getMessage());115}116*/117118// notify debugger that checked class is loaded119pipe.println(signature001.COMMAND_LOADED);120121// turn off pipe pinging122pipe.setPingTimeout(0);123124// wait for a command to unload checked class125command = pipe.readln();126if (!command.equals(signature001.COMMAND_UNLOAD)) {127System.err.println("TEST BUG: unexpected command: " + command);128return FAILED;129}130131// try to unload checked class132boolean classes_unloaded = checkedClassUnloader.unloadClass()133&& checkedInterfaceUnloader.unloadClass();134135if (!classes_unloaded) {136pipe.println(signature001.COMMAND_LOADED);137} else {138pipe.println(signature001.COMMAND_UNLOADED);139}140141// wait for a command to exit142pipe.println(signature001.COMMAND_UNLOAD);143144command = pipe.readln();145if (!command.equals(signature001.COMMAND_QUIT)) {146System.err.println("TEST BUG: unknown command: " + command);147return FAILED;148}149return PASSED;150}151}152153154