Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001.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.AllThreads;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class allthreads001 {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.AllThreads";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "allthreads001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.AllThreads";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.AllThreads;4243static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME;4445public static void main (String argv[]) {46System.exit(run(argv,System.out) + JCK_STATUS_BASE);47}4849public static int run(String argv[], PrintStream out) {50return new allthreads001().runIt(argv, out);51}5253public int runIt(String argv[], PrintStream out) {5455boolean success = true;5657try {58ArgumentHandler argumentHandler = new ArgumentHandler(argv);59Log log = new Log(out, argumentHandler);6061try {6263Binder binder = new Binder(argumentHandler, log);64log.display("Start debugee VM");65Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);66Transport transport = debugee.getTransport();67IOPipe pipe = debugee.createIOPipe();6869log.display("Waiting for VM_INIT event");70debugee.waitForVMInit();7172log.display("Querying for IDSizes");73debugee.queryForIDSizes();7475log.display("Resume debugee VM");76debugee.resume();7778log.display("Waiting for command: " + "ready");79String cmd = pipe.readln();80log.display("Received command: " + cmd);8182String classSignature = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";8384// begin test of JDWP command8586try {87CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);8889log.display("Sending command packet:\n" + command);90transport.write(command);9192log.display("Waiting for reply packet");93ReplyPacket reply = new ReplyPacket();94transport.read(reply);95log.display("Reply packet received:\n" + reply);9697log.display("Checking reply packet header");98reply.checkHeader(command.getPacketID());99100log.display("Parsing reply packet:");101reply.resetPosition();102103int threads = reply.getInt();104log.display(" threads: " + threads);105106if (threads < 0) {107log.complain("Negative number of returned threads: " + threads);108success = false;109}110111if (threads == 0) {112log.complain("No threads returned");113success = false;114}115116for (int i = 0; i < threads; i++) {117long threadID = reply.getObjectID();118log.display(" " + i + " threadID: " + threadID);119}120121if (! reply.isParsed()) {122log.complain("Extra bytes in reply packet at: "123+ reply.currentPosition());124success = false;125}126127} catch (Exception e) {128log.complain("Exception catched: " + e);129success = false;130}131132// end test of JDWP command133134log.display("Sending command: " + "quit");135pipe.println("quit");136137log.display("Waiting for debugee exits");138int code = debugee.waitFor();139if (code == JCK_STATUS_BASE + PASSED) {140log.display("Debugee PASSED: " + code);141} else {142log.complain("Debugee FAILED: " + code);143success = false;144}145146} catch (Exception e) {147log.complain("Unexpected exception: " + e);148e.printStackTrace(out);149success = false;150}151152if (!success) {153log.complain("TEST FAILED");154return FAILED;155}156157} catch (Exception e) {158out.println("Unexpected exception: " + e);159e.printStackTrace(out);160out.println("TEST FAILED");161return FAILED;162}163164out.println("TEST PASSED");165return PASSED;166167}168169}170171172