Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001.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.jdwp.VirtualMachine.ClassesBySignature;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class classbysig001 {33static final int JCK_STATUS_BASE = 95;34static final int PASSED = 0;35static final int FAILED = 2;36static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.ClassesBySignature";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "classbysig001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.ClassesBySignature";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.ClassesBySignature;4243static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME;44// static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME + ";";4546public static void main (String argv[]) {47System.exit(run(argv,System.out) + JCK_STATUS_BASE);48}4950public static int run(String argv[], PrintStream out) {51return new classbysig001().runIt(argv, out);52}5354public int runIt(String argv[], PrintStream out) {5556boolean success = true;5758try {59ArgumentHandler argumentHandler = new ArgumentHandler(argv);60Log log = new Log(out, argumentHandler);6162try {6364Binder binder = new Binder(argumentHandler, log);65log.display("Start debugee VM");66Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);67Transport transport = debugee.getTransport();68IOPipe pipe = debugee.createIOPipe();6970log.display("Waiting for VM_INIT event");71debugee.waitForVMInit();7273log.display("Querying for IDSizes");74debugee.queryForIDSizes();7576log.display("Resume debugee VM");77debugee.resume();7879log.display("Waiting for command: " + "ready");80String cmd = pipe.readln();81log.display("Received command: " + cmd);8283String classSignature = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";8485// begin test of JDWP command8687try {88log.display("Create command " + JDWP_COMMAND_NAME89+ " with class signature: " + classSignature);90CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);91command.addString(classSignature);92command.setLength();9394log.display("Sending command packet:\n" + command);95transport.write(command);9697log.display("Waiting for reply packet");98ReplyPacket reply = new ReplyPacket();99transport.read(reply);100log.display("Reply packet received:\n" + reply);101102log.display("Checking reply packet header");103reply.checkHeader(command.getPacketID());104105log.display("Parsing reply packet:");106reply.resetPosition();107108int classes = reply.getInt();109log.display(" classes: " + classes);110111for (int i = 0; i < classes; i++) {112113byte refTypeTag = reply.getByte();114log.display(" " + i + " refTypeTag: " + refTypeTag);115116long typeID = reply.getReferenceTypeID();117log.display(" " + i + " typeID: " + typeID);118119int status = reply.getInt();120log.display(" " + i + " status: " + status);121}122123if (! reply.isParsed()) {124log.complain("Extra bytes in reply packet at: " + reply.currentPosition());125success = false;126}127128if (classes < 0) {129log.complain("Negative number of returned classes: " + classes);130success = false;131}132133if (classes == 0) {134log.complain("No class returned for signature: " + classSignature);135success = false;136}137138if (classes > 1) {139log.complain("Too many classes returned for signature: " + classSignature);140success = false;141}142143} catch (Exception e) {144log.complain("Exception catched: " + e);145success = false;146}147148// end test of JDWP command149150log.display("Sending command: " + "quit");151pipe.println("quit");152153log.display("Waiting for debugee exits");154int code = debugee.waitFor();155if (code == JCK_STATUS_BASE + PASSED) {156log.display("Debugee PASSED: " + code);157} else {158log.complain("Debugee FAILED: " + code);159success = false;160}161162} catch (Exception e) {163log.complain("Unexpected exception: " + e);164e.printStackTrace(out);165success = false;166}167168if (!success) {169log.complain("TEST FAILED");170return FAILED;171}172173} catch (Exception e) {174out.println("Unexpected exception: " + e);175e.printStackTrace(out);176out.println("TEST FAILED");177return FAILED;178}179180out.println("TEST PASSED");181return PASSED;182183}184185}186187188