Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001.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.StringReference.Value;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;30import java.util.*;3132public class value001 {33static final int JCK_STATUS_BASE = 95;34static final int PASSED = 0;35static final int FAILED = 2;36static final String PACKAGE_NAME = "nsk.jdwp.StringReference.Value";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "value001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "StringReference.Value";41static final int JDWP_COMMAND_ID = JDWP.Command.StringReference.Value;4243public static void main (String argv[]) {44System.exit(run(argv,System.out) + JCK_STATUS_BASE);45}4647public static int run(String argv[], PrintStream out) {48return new value001().runIt(argv, out);49}5051public int runIt(String argv[], PrintStream out) {5253boolean success = true;5455try {56ArgumentHandler argumentHandler = new ArgumentHandler(argv);57Log log = new Log(out, argumentHandler);5859try {6061Binder binder = new Binder(argumentHandler, log);62log.display("Start debugee VM");63Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);64Transport transport = debugee.getTransport();65IOPipe pipe = debugee.createIOPipe();6667log.display("Waiting for VM_INIT event");68debugee.waitForVMInit();6970log.display("Querying for IDSizes");71debugee.queryForIDSizes();7273log.display("Resume debugee VM");74debugee.resume();7576log.display("Waiting for command: " + "ready");77String cmd = pipe.readln();78log.display("Received command: " + cmd);7980try {8182// create string in debugee8384String originalStringValue = "Testing string value";85long stringID = 0;8687{88// Suspend debuggee to avoid GC89log.display("Suspending debuggee");90debugee.suspend();91log.display("Debuggee suspended");9293log.display("Create command packet" + "CreateString"94+ " with string value: " + originalStringValue);95CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.CreateString);96command.addString(originalStringValue);97command.setLength();9899log.display("Waiting for reply to command");100ReplyPacket reply = debugee.receiveReplyFor(command);101log.display("Valid reply packet received");102103log.display("Parsing reply packet");104reply.resetPosition();105106stringID = reply.getObjectID();107log.display(" stringID: " + stringID);108109// Disable garbage collection of the String110log.display("Disabling collection of String object");111command = new CommandPacket(JDWP.Command.ObjectReference.DisableCollection);112command.addObjectID(stringID);113command.setLength();114reply = debugee.receiveReplyFor(command);115reply.resetPosition();116log.display("Collection disabled");117118// Resume debugee now that we have disabled collection of the String119log.display("Resuming debuggee");120debugee.resume();121log.display("Debuggee resumed");122}123124// begint test of JDWP command125126log.display("Create command packet" + JDWP_COMMAND_NAME127+ "with stringID: " + stringID);128CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);129command.addObjectID(stringID);130command.setLength();131132log.display("Sending command packet:\n" + command);133transport.write(command);134135log.display("Waiting for reply packet");136ReplyPacket reply = new ReplyPacket();137transport.read(reply);138log.display("Reply packet received:\n" + reply);139140log.display("Checking reply packet header");141reply.checkHeader(command.getPacketID());142143log.display("Parsing reply packet:");144reply.resetPosition();145146String stringValue = reply.getString();147log.display(" stringValue: " + stringValue);148149if (! stringValue.equals(originalStringValue)) {150log.complain("Received value does not equals original value:"151+ originalStringValue);152success = false;153}154155if (! reply.isParsed()) {156log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition());157success = false;158} else {159log.display("Reply packet parsed successfully");160}161162// end test of JDWP command163164// Re-enable garbage collection of the String165log.display("Enabling collection of String object");166command = new CommandPacket(JDWP.Command.ObjectReference.EnableCollection);167command.addObjectID(stringID);168command.setLength();169reply = debugee.receiveReplyFor(command);170reply.resetPosition();171log.display("Collection enabled");172173} catch (Exception e) {174log.complain("Caught exception while testing JDWP command: " + e);175success = false;176} finally {177log.display("Sending command: " + "quit");178pipe.println("quit");179180log.display("Waiting for debugee exits");181int code = debugee.waitFor();182if (code == JCK_STATUS_BASE + PASSED) {183log.display("Debugee PASSED with exit code: " + code);184} else {185log.complain("Debugee FAILED with exit code: " + code);186success = false;187}188}189190} catch (Exception e) {191log.complain("Caught unexpected exception while communicating with debugee: " + e);192e.printStackTrace(out);193success = false;194}195196if (!success) {197log.complain("TEST FAILED");198return FAILED;199}200201} catch (Exception e) {202out.println("Caught unexpected exception while starting the test: " + e);203e.printStackTrace(out);204out.println("TEST FAILED");205return FAILED;206}207208out.println("TEST PASSED");209return PASSED;210211}212213}214215216