Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/CommandPacket.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.share.jdwp;2425import nsk.share.*;2627/**28* This class represents a JDWP command packet.29*/30public class CommandPacket extends Packet {3132/**33* Static counter for enumeration of the command packets.34*/35private static int nextID = 1;3637/**38* Return next free number for enumeration of the command packets.39*/40public static int getLastID() {41return (nextID - 1);42}4344/**45* Make JDWP command packet for specified command.46*/47public CommandPacket(int fullCommand) {48super();4950setPacketID(nextID++);51setFlags(JDWP.Flag.NONE);52setFullCommand(fullCommand);53}5455/**56* Make JDWP command packet for specified command.57*/58public CommandPacket(int fullCommand, int id) {59super();6061setPacketID(id);62setFlags(JDWP.Flag.NONE);63setFullCommand(fullCommand);64}6566/**67* Make command packet with data from the specified byte buffer.68*/69// public CommandPacket(ByteBuffer packet) {70public CommandPacket(Packet packet) {71super(packet);72}7374/**75* Return full command number for this packet.76*/77public int getFullCommand() {78int id = 0;7980try {81id = (int) getID(FullCommandOffset, 2);82}83catch (BoundException e) {84throw new Failure("Caught unexpected exception while getting command number from header:\n\t"85+ e);86}8788return id;89}9091/**92* Return short command number for this packet.93*/94public byte getCommand() {95byte id = 0;9697try {98id = getByte(CommandOffset);99}100catch (BoundException e) {101throw new Failure("Caught unexpected exception while getting command number from header:\n\t"102+ e);103}104105return id;106}107108/**109* Return command set number for this packet.110*/111public byte getCommandSet() {112byte id = 0;113114try {115id = getByte(CommandSetOffset);116}117catch (BoundException e) {118throw new Failure("Caught unexpected exception while getting command number from header:\n\t"119+ e);120}121122return id;123}124125/**126* Assign command number for this packet.127*/128public void setFullCommand(int fullCommand) {129try {130putID(FullCommandOffset, fullCommand, 2);131}132catch (BoundException e) {133throw new Failure("Caught unexpected exception while setting command number into header: "134+ e);135}136}137138/**139* Return string representation of the command packet header.140*/141public String headerToString() {142return super.headerToString()143+ " " + toHexString(CommandSetOffset, 4) + " (cmd set): 0x" + toHexDecString(getCommandSet(), 2) + "\n"144+ " " + toHexString(CommandOffset, 4) + " (command): 0x" + toHexDecString(getCommand(), 2) + "\n";145}146147}148149150