Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/JDWP.java
41161 views
/*1* Copyright (c) 2001, 2021, 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 java.util.HashMap;26import java.util.HashSet;27import java.util.Hashtable;2829import nsk.share.Failure;3031/**32* This class contains JDWP constants, types and parameters.33*/34public class JDWP {3536public static class Error {3738public static final int NONE = 0;39public static final int INVALID_THREAD = 10;40public static final int INVALID_THREAD_GROUP = 11;41public static final int INVALID_PRIORITY = 12;42public static final int THREAD_NOT_SUSPENDED = 13;43public static final int THREAD_SUSPENDED = 14;44public static final int INVALID_OBJECT = 20;45public static final int INVALID_CLASS = 21;46public static final int CLASS_NOT_PREPARED = 22;47public static final int INVALID_METHODID = 23;48public static final int INVALID_LOCATION = 24;49public static final int INVALID_FIELDID = 25;50public static final int INVALID_FRAMEID = 30;51public static final int NO_MORE_FRAMES = 31;52public static final int OPAQUE_FRAME = 32;53public static final int NOT_CURRENT_FRAME = 33;54public static final int TYPE_MISMATCH = 34;55public static final int INVALID_SLOT = 35;56public static final int DUPLICATE = 40;57public static final int NOT_FOUND = 41;58public static final int INVALID_MONITOR = 50;59public static final int NOT_MONITOR_OWNER = 51;60public static final int INTERRUPT = 52;61public static final int INVALID_CLASS_FORMAT = 60;62public static final int CIRCULAR_CLASS_DEFINITION = 61;63public static final int FAILS_VERIFICATION = 62;64public static final int ADD_METHOD_NOT_IMPLEMENTED = 63;65public static final int SCHEMA_CHANGE_NOT_IMPLEMENTED = 64;66public static final int INVALID_TYPESTATE = 65;67public static final int HIERARCHY_CHANGE_NOT_IMPLEMENTED= 66;68public static final int DELETE_METHOD_NOT_IMPLEMENTED = 67;69public static final int UNSUPPORTED_VERSION = 68;70public static final int NAMES_DONT_MATCH = 69;71public static final int CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70;72public static final int METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71;73public static final int NOT_IMPLEMENTED = 99;74public static final int NULL_POINTER = 100;75public static final int ABSENT_INFORMATION = 101;76public static final int INVALID_EVENT_TYPE = 102;77public static final int ILLEGAL_ARGUMENT = 103;78public static final int OUT_OF_MEMORY = 110;79public static final int ACCESS_DENIED = 111;80public static final int VM_DEATH = 112;81public static final int INTERNAL = 113;82public static final int UNATTACHED_THREAD = 115;83public static final int INVALID_TAG = 500;84public static final int ALREADY_INVOKING = 502;85public static final int INVALID_INDEX = 503;86public static final int INVALID_LENGTH = 504;87public static final int INVALID_STRING = 506;88public static final int INVALID_CLASS_LOADER = 507;89public static final int INVALID_ARRAY = 508;90public static final int TRANSPORT_LOAD = 509;91public static final int TRANSPORT_INIT = 510;92public static final int NATIVE_METHOD = 511;93public static final int INVALID_COUNT = 512;9495}9697public static class Flag {9899public static final byte NONE = (byte)0;100public static final byte REPLY_PACKET = (byte)0x80;101public static final byte EVENT_PACKET = NONE;102103}104105public static class EventKind {106107public static final byte VM_INIT = (byte)90;108public static final byte VM_START = VM_INIT;109public static final byte VM_DISCONNECTED = (byte)100;110public static final byte VM_DEATH = (byte)99;111112public static final byte THREAD_START = (byte)6;113public static final byte THREAD_END = (byte)7;114public static final byte THREAD_DEATH = THREAD_END;115116public static final byte CLASS_PREPARE = (byte)8;117public static final byte CLASS_LOAD = (byte)10;118public static final byte CLASS_UNLOAD = (byte)9;119120public static final byte METHOD_ENTRY = (byte)40;121public static final byte METHOD_EXIT = (byte)41;122123public static final byte FIELD_ACCESS = (byte)20;124public static final byte FIELD_MODIFICATION = (byte)21;125126public static final byte EXCEPTION = (byte)4;127public static final byte EXCEPTION_CATCH = (byte)30;128129public static final byte FRAME_POP = (byte)3;130131public static final byte BREAKPOINT = (byte)2;132133public static final byte SINGLE_STEP = (byte)1;134135public static final byte USER_DEFINED = (byte)5;136137}138139public static class EventModifierKind {140141public static final byte COUNT = (byte)1;142public static final byte CONDITIONAL = (byte)2;143public static final byte THREAD_ONLY = (byte)3;144public static final byte CLASS_ONLY = (byte)4;145public static final byte CLASS_MATCH = (byte)5;146public static final byte CLASS_EXCLUDE = (byte)6;147public static final byte LOCATION_ONLY = (byte)7;148public static final byte EXCEPTION_ONLY = (byte)8;149public static final byte FIELD_ONLY = (byte)9;150public static final byte STEP = (byte)10;151public static final byte INSTANCE_ONLY = (byte)11;152};153154public static class ThreadStatus {155156public static final int ZOMBIE = 0;157public static final int RUNNING = 1;158public static final int SLEEPING = 2;159public static final int MONITOR = 3;160public static final int WAIT = 4;161162}163164public static class SuspendStatus {165166public static final int SUSPEND_STATUS_SUSPENDED = 0x1;167168}169170public static class ClassStatus {171172public static final int PREPARED = 2;173public static final int VERIFIED = 1;174public static final int INITIALIZED = 4;175public static final int ERROR = 8;176177}178179public static class TypeTag {180181public static final byte CLASS = (byte)1;182public static final byte INTERFACE = (byte)2;183public static final byte ARRAY = (byte)3;184185}186187public static class Tag {188189public static final byte ARRAY = (byte)91;190public static final byte BYTE = (byte)66;191public static final byte CHAR = (byte)67;192public static final byte OBJECT = (byte)76;193public static final byte FLOAT = (byte)70;194public static final byte DOUBLE = (byte)68;195public static final byte INT = (byte)73;196public static final byte LONG = (byte)74;197public static final byte SHORT = (byte)83;198public static final byte VOID = (byte)86;199public static final byte BOOLEAN = (byte)90;200public static final byte STRING = (byte)115;201public static final byte THREAD = (byte)116;202public static final byte THREAD_GROUP = (byte)103;203public static final byte CLASS_LOADER = (byte)108;204public static final byte CLASS_OBJECT = (byte)99;205206}207208public static class StepDepth {209210public static final int INTO = 0;211public static final int OVER = 1;212public static final int OUT = 2;213214}215216public static class StepSize {217218public static final int MIN = 0;219public static final int LINE = 1;220221}222223public static class SuspendPolicy {224225public static final byte NONE = (byte)0;226public static final byte EVENT_THREAD = (byte)1;227public static final byte ALL = (byte)2;228229}230231public static class InvokeOptions {232233public static final int INVOKE_SINGLE_THREADED = 0x01;234public static final int INVOKE_NONVIRTUAL = 0x02;235236}237238public static class TypeSize {239240// VM independent type sizes241242public static final int BYTE = 1;243public static final int BOOLEAN = 1;244public static final int CHAR = 2;245public static final int SHORT = 2;246public static final int FLOAT = 4;247public static final int INT = 4;248public static final int LONG = 8;249public static final int DOUBLE = 8;250251public static final int TAG = 1;252public static final int LOCATION_INDEX = 8;253254// basic VM specific type sizes255256public static int OBJECT_ID = 8;257public static int METHOD_ID = 4;258public static int FIELD_ID = 4;259public static int FRAME_ID = 4;260261// derivative VM specific type sizes262263public static int TAGGED_OBJECT_ID = TAG + OBJECT_ID;264265public static int THREAD_ID = OBJECT_ID;266public static int THREAD_GROUP_ID = OBJECT_ID;267public static int STRING_ID = OBJECT_ID;268public static int CLASS_LOADER_ID = OBJECT_ID;269public static int CLASS_OBJECT_ID = OBJECT_ID;270public static int REFERENCE_TYPE_ID = OBJECT_ID;271272public static int CLASS_ID = REFERENCE_TYPE_ID;273public static int INTERFACE_ID = REFERENCE_TYPE_ID;274public static int ARRAY_ID = REFERENCE_TYPE_ID;275276public static int LOCATION = TAG + CLASS_ID + METHOD_ID + LOCATION_INDEX;277278/**279* Calculate type sizes based on VM dependent basic type sizes.280*/281public static void CalculateSizes() {282283TAGGED_OBJECT_ID = TAG + OBJECT_ID;284285THREAD_ID = OBJECT_ID;286THREAD_GROUP_ID = OBJECT_ID;287STRING_ID = OBJECT_ID;288CLASS_LOADER_ID = OBJECT_ID;289CLASS_OBJECT_ID = OBJECT_ID;290REFERENCE_TYPE_ID = OBJECT_ID;291292CLASS_ID = REFERENCE_TYPE_ID;293INTERFACE_ID = REFERENCE_TYPE_ID;294ARRAY_ID = REFERENCE_TYPE_ID;295296LOCATION = TAG + CLASS_ID + METHOD_ID + LOCATION_INDEX;297}298299}300301public static class ModifierFlag {302303public static final int PUBLIC = 0x0001;304public static final int PRIVATE = 0x0002;305public static final int PROTECTED = 0x0004;306public static final int STATIC = 0x0008;307public static final int FINAL = 0x0010;308public static final int SUPER = 0x0020;309public static final int VOLATILE = 0x0040;310public static final int TRANSIENT = 0x0080;311public static final int SYNCHRONIZED = 0x0020;312public static final int NATIVE = 0x0100;313public static final int INTERFACE = 0x0200;314public static final int ABSTRACT = 0x0400;315public static final int SYNTHETIC = 0xF0000000;316317public static final int CLASS_MASK = PUBLIC | FINAL | SUPER | INTERFACE | ABSTRACT;318public static final int FIELD_MASK = PUBLIC | PRIVATE | PROTECTED | STATIC | FINAL | VOLATILE | TRANSIENT;319public static final int METHOD_MASK = PUBLIC | PRIVATE | PROTECTED | STATIC | FINAL | SYNCHRONIZED | NATIVE | ABSTRACT;320321}322323public static class CommandSet {324325public static final byte VirtualMachine = (byte)0x01;326public static final byte ReferenceType = (byte)0x02;327public static final byte ClassType = (byte)0x03;328public static final byte ArrayType = (byte)0x04;329public static final byte InterfaceType = (byte)0x05;330public static final byte Method = (byte)0x06;331public static final byte Field = (byte)0x08;332public static final byte ObjectReference = (byte)0x09;333public static final byte StringReference = (byte)0x0A;334public static final byte ThreadReference = (byte)0x0B;335public static final byte ThreadGroupReference = (byte)0x0C;336public static final byte ArrayReferemce = (byte)0x0D;337public static final byte ClassLoaderReference = (byte)0x0E;338public static final byte EventRequest = (byte)0x0F;339public static final byte StackFrame = (byte)0x10;340public static final byte ClassObjectReference = (byte)0x11;341public static final byte Event = (byte)0x40;342343}344345// command names, used only for debug output346public static HashMap<Integer, String> commandNames = new HashMap<Integer, String>();347348static349{350commandNames.put(Command.ObjectReference.ReferringObjects, "ObjectReference.ReferringObjects");351commandNames.put(Command.ReferenceType.Instances, "ReferenceType.Instances");352commandNames.put(Command.ReferenceType.ClassFileVersion, "ReferenceType.ClassFileVersion");353commandNames.put(Command.ReferenceType.ConstantPool, "ReferenceType.ConstantPool");354commandNames.put(Command.ThreadReference.OwnedMonitorsStackDepthInfo, "ThreadReference.OwnedMonitorsStackDepthInfo");355commandNames.put(Command.ThreadReference.ForceEarlyReturn, "ThreadReference.ForceEarlyReturn");356commandNames.put(Command.VirtualMachine.InstanceCounts, "VirtualMachine.InstanceCounts");357}358359public static class Command {360361public static class VirtualMachine {362363public static final int Version = 0x0101;364public static final int ClassesBySignature = 0x0102;365public static final int AllClasses = 0x0103;366public static final int AllThreads = 0x0104;367public static final int TopLevelThreadGroups = 0x0105;368public static final int Dispose = 0x0106;369public static final int IDSizes = 0x0107;370public static final int Suspend = 0x0108;371public static final int Resume = 0x0109;372public static final int Exit = 0x010A;373public static final int CreateString = 0x010B;374public static final int Capabilities = 0x010C;375public static final int ClassPaths = 0x010D;376public static final int DisposeObjects = 0x010E;377public static final int HoldEvents = 0x010F;378public static final int ReleaseEvents = 0x0110;379380// since JDK-1.4381public static final int CapabilitiesNew = 0x0111;382public static final int RedefineClasses = 0x0112;383public static final int SetDefaultStratum = 0x0113;384385// since JDK-1.5386public static final int AllClassesWithGeneric = 0x0114;387388// since JDK-1.6389public static final int InstanceCounts = 0x0115;390}391392public static class ReferenceType {393394public static final int Signature = 0x0201;395public static final int ClassLoader = 0x0202;396public static final int Modifiers = 0x0203;397public static final int Fields = 0x0204;398public static final int Methods = 0x0205;399public static final int GetValues = 0x0206;400public static final int SourceFile = 0x0207;401public static final int NestedTypes = 0x0208;402public static final int Status = 0x0209;403public static final int Interfaces = 0x020A;404public static final int ClassObject = 0x020B;405406// since JDK-1.4407public static final int SourceDebugExtension = 0x020C;408409// since JDK-1.5410public static final int SignatureWithGeneric = 0x020D;411public static final int FieldsWithGeneric = 0x020E;412public static final int MethodsWithGeneric = 0x020F;413414// since JDK-1.6415public static final int Instances = 0x0210;416public static final int ClassFileVersion = 0x0211;417public static final int ConstantPool = 0x0212;418}419420public static class ClassType {421422public static final int Superclass = 0x0301;423public static final int SetValues = 0x0302;424public static final int InvokeMethod = 0x0303;425public static final int NewInstance = 0x0304;426427}428429public static class ArrayType {430431public static final int NewInstance = 0x0401;432433}434435public static class InterfaceType {436437}438439public static class Method {440441public static final int LineTable = 0x0601;442public static final int VariableTable = 0x0602;443public static final int Bytecodes = 0x0603;444445// since JDK-1.4446public static final int IsObsolete = 0x0604;447448// since JDK-1.5449public static final int VariableTableWithGeneric = 0x0605;450451}452453public static class Field {454455}456457public static class ObjectReference {458459public static final int ReferenceType = 0x0901;460public static final int GetValues = 0x0902;461public static final int SetValues = 0x0903;462public static final int MonitorInfo = 0x0905;463public static final int InvokeMethod = 0x0906;464public static final int DisableCollection = 0x0907;465public static final int EnableCollection = 0x0908;466public static final int IsCollected = 0x0909;467468// since JDK-1.6469public static final int ReferringObjects = 0x090A;470}471472public static class StringReference {473474public static final int Value = 0x0A01;475476}477478public static class ThreadReference {479480public static final int Name = 0x0B01;481public static final int Suspend = 0x0B02;482public static final int Resume = 0x0B03;483public static final int Status = 0x0B04;484public static final int ThreadGroup = 0x0B05;485public static final int Frames = 0x0B06;486public static final int FrameCount = 0x0B07;487public static final int OwnedMonitors = 0x0B08;488public static final int CurrentContendedMonitor = 0x0B09;489public static final int Stop = 0x0B0A;490public static final int Interrupt = 0x0B0B;491public static final int SuspendCount = 0x0B0C;492public static final int PopTopFrame = 0x0B0D;493494// since JDK-1.6495public static final int OwnedMonitorsStackDepthInfo = 0x0B0D;496public static final int ForceEarlyReturn = 0x0B0E;497}498499public static class ThreadGroupReference {500501public static final int Name = 0x0C01;502public static final int Parent = 0x0C02;503public static final int Children = 0x0C03;504505}506507public static class ArrayReference {508509public static final int Length = 0x0D01;510public static final int GetValues = 0x0D02;511public static final int SetValues = 0x0D03;512513}514515public static class ClassLoaderReference {516517public static final int VisibleClasses = 0x0E01;518519}520521public static class EventRequest {522523public static final int Set = 0x0F01;524public static final int Clear = 0x0F02;525public static final int ClearAllBreakpoints = 0x0F03;526527}528529public static class StackFrame {530531public static final int GetValues = 0x1001;532public static final int SetValues = 0x1002;533public static final int ThisObject = 0x1003;534535// since JDK-1.4536public static final int PopFrames = 0x1004;537538}539540public static class ClassObjectReference {541542public static final int ReflectedType = 0x1101;543544}545546public static class Event {547548public static final int Composite = 0x4064;549550}551552} // end of class Command553554public static class Capability {555556// common capabilities557public static final int CAN_WATCH_FIELD_MODIFICATION = 0;558public static final int CAN_WATCH_FIELD_ACCESS = 1;559public static final int CAN_GET_BYTECODES = 2;560public static final int CAN_GET_SYNTHETIC_ATTRIBUTE = 3;561public static final int CAN_GET_OWNED_MONITOR_INFO = 4;562public static final int CAN_GET_CURRENT_CONTENDED_MONITOR = 5;563public static final int CAN_GET_MONITOR_INFO = 6;564565// new capabilities (since JDWP version 1.4)566public static final int CAN_REDEFINE_CLASSES = 7;567public static final int CAN_ADD_METHODR_INFO = 8;568public static final int CAN_UNRESTRICTEDLY_REDEFINE_CLASSES = 9;569public static final int CAN_POP_FRAMES = 10;570public static final int CAN_USE_INSTANCE_FILTER = 11;571public static final int CAN_GET_SOURCE_DEBUG_EXTENSION = 12;572public static final int CAN_REQUEST_VMDEATH_EVENT = 13;573public static final int CAN_SET_DEFAULT_STRATUM = 14;574}575576public static class Location extends ByteBuffer {577578public static int TAG_OFFSET = 0;579public static int CLASS_ID_OFFSET = TAG_OFFSET + JDWP.TypeSize.TAG;580public static int METHOD_ID_OFFSET = CLASS_ID_OFFSET + JDWP.TypeSize.CLASS_ID;581public static int INDEX_OFFSET = METHOD_ID_OFFSET + JDWP.TypeSize.METHOD_ID;582583private static void calculateOffsets() {584CLASS_ID_OFFSET = TAG_OFFSET + JDWP.TypeSize.TAG;585METHOD_ID_OFFSET = CLASS_ID_OFFSET + JDWP.TypeSize.CLASS_ID;586INDEX_OFFSET = METHOD_ID_OFFSET + JDWP.TypeSize.METHOD_ID;587}588589public Location(byte typeTag, long classID, long methodID, long index) {590this();591// 1 byte type tag592putTag(typeTag);593// classID594putClassID(classID);595// methodID596putMethodID(methodID);597// 8 bytes index598putIndex(index);599}600601public Location() {602super(JDWP.TypeSize.LOCATION, 0);603addBytes((byte)0, TypeSize.LOCATION);604605// calculate offsets for VM-dependent type sizes606calculateOffsets();607}608609public final byte getTag() {610try {611return getByte(TAG_OFFSET);612} catch (BoundException e) {613throw new Failure("Unable to get tag from location:\n\t" + e);614}615}616617public final long getClassID() {618try {619return getID(CLASS_ID_OFFSET, JDWP.TypeSize.CLASS_ID);620} catch (BoundException e) {621throw new Failure("Unable to get classID from location:\n\t" + e);622}623}624625public final long getMethodID() {626try {627return getID(METHOD_ID_OFFSET, JDWP.TypeSize.METHOD_ID);628} catch (BoundException e) {629throw new Failure("Unable to get methodID from location:\n\t" + e);630}631}632633public final long getIndex() {634try {635return getID(INDEX_OFFSET, JDWP.TypeSize.LOCATION_INDEX);636} catch (BoundException e) {637throw new Failure("Unable to get code index from location:\n\t" + e);638}639}640641public final void putTag(byte tag) {642try {643putByte(TAG_OFFSET, tag);644} catch (BoundException e) {645throw new Failure("Unable to put tag into location:\n\t" + e);646}647}648649public final void putClassID(long classID) {650try {651putID(CLASS_ID_OFFSET, classID, JDWP.TypeSize.CLASS_ID);652} catch (BoundException e) {653throw new Failure("Unable to put classID into location:\n\t" + e);654}655}656657public final void putMethodID(long methodID) {658try {659putID(METHOD_ID_OFFSET, methodID, JDWP.TypeSize.METHOD_ID);660} catch (BoundException e) {661throw new Failure("Unable to put methodID into location:\n\t" + e);662}663}664665public final void putIndex(long index) {666try {667putID(INDEX_OFFSET, index, JDWP.TypeSize.LOCATION_INDEX);668} catch (BoundException e) {669throw new Failure("Unable to put code index into location:\n\t" + e);670}671}672673public String toString() {674return "Location("675+ "tag=" + getTag() + ", "676+ "classID=" + getClassID() + ", "677+ "methodID=" + getMethodID() + ", "678+ "index=" + getIndex()679+ ")";680}681682} // end of class Location683684public static class UntaggedValue {685686public Object value = null;687688public UntaggedValue() {689}690691public UntaggedValue(Object value) {692this.value = value;693}694695public Object getValue() {696return value;697}698699public int length(byte tag) {700int valueSize = 0;701try {702switch (tag) {703case JDWP.Tag.BYTE: {704valueSize = JDWP.TypeSize.BYTE;705} break;706case JDWP.Tag.CHAR: {707valueSize = JDWP.TypeSize.CHAR;708} break;709case JDWP.Tag.FLOAT: {710valueSize = JDWP.TypeSize.FLOAT;711} break;712case JDWP.Tag.DOUBLE: {713valueSize = JDWP.TypeSize.DOUBLE;714} break;715case JDWP.Tag.INT: {716valueSize = JDWP.TypeSize.INT;717} break;718case JDWP.Tag.SHORT: {719valueSize = JDWP.TypeSize.SHORT;720} break;721case JDWP.Tag.BOOLEAN: {722valueSize = JDWP.TypeSize.BYTE;723} break;724case JDWP.Tag.LONG: {725valueSize = JDWP.TypeSize.LONG;726} break;727case JDWP.Tag.VOID: {728valueSize = 0;729} break;730case JDWP.Tag.ARRAY:731case JDWP.Tag.OBJECT:732case JDWP.Tag.STRING:733case JDWP.Tag.THREAD:734case JDWP.Tag.THREAD_GROUP:735case JDWP.Tag.CLASS_LOADER:736case JDWP.Tag.CLASS_OBJECT: {737valueSize = JDWP.TypeSize.OBJECT_ID;738} break;739default: {740throw new Failure("Unknown tag found while putting value into packet: " + tag);741}742}743} catch (ClassCastException e) {744throw new Failure("Wrong tag " + tag + " found while putting value to packet: " + value);745}746return JDWP.TypeSize.TAG + valueSize;747}748749public void addValueTo(Packet packet, byte tag) {750if (value == null) {751throw new Failure("Unable to put null value into packet: " + this);752}753try {754switch (tag) {755case JDWP.Tag.BYTE: {756byte castedValue = ((Byte)value).byteValue();757packet.addByte(castedValue);758} break;759case JDWP.Tag.CHAR: {760char castedValue = ((Character)value).charValue();761packet.addChar(castedValue);762} break;763case JDWP.Tag.FLOAT: {764float castedValue = ((Float)value).floatValue();765packet.addFloat(castedValue);766} break;767case JDWP.Tag.DOUBLE: {768double castedValue = ((Double)value).doubleValue();769packet.addDouble(castedValue);770} break;771case JDWP.Tag.INT: {772int castedValue = ((Integer)value).intValue();773packet.addInt(castedValue);774} break;775case JDWP.Tag.SHORT: {776short castedValue = ((Short)value).shortValue();777packet.addShort(castedValue);778} break;779case JDWP.Tag.BOOLEAN: {780boolean castedValue = ((Boolean)value).booleanValue();781packet.addByte((byte)(castedValue? 1 : 0));782} break;783case JDWP.Tag.LONG: {784long castedValue = ((Long)value).longValue();785packet.addLong(castedValue);786} break;787case JDWP.Tag.VOID: {788} break;789case JDWP.Tag.ARRAY:790case JDWP.Tag.OBJECT:791case JDWP.Tag.STRING:792case JDWP.Tag.THREAD:793case JDWP.Tag.THREAD_GROUP:794case JDWP.Tag.CLASS_LOADER:795case JDWP.Tag.CLASS_OBJECT: {796long castedValue = ((Long)value).longValue();797packet.addObjectID(castedValue);798} break;799default: {800throw new Failure("Unknown tag found while putting value into packet: " + tag);801}802}803} catch (ClassCastException e) {804throw new Failure("Wrong tag " + tag + " found while putting value to packet: " + value);805}806}807808public void getValueFrom(Packet packet, byte tag) throws BoundException {809switch (tag) {810case JDWP.Tag.BYTE: {811byte castedValue = packet.getByte();812value = Byte.valueOf(castedValue);813} break;814case JDWP.Tag.CHAR: {815char castedValue = packet.getChar();816value = Character.valueOf(castedValue);817} break;818case JDWP.Tag.FLOAT: {819float castedValue = packet.getFloat();820value = Float.valueOf(castedValue);821} break;822case JDWP.Tag.DOUBLE: {823double castedValue = packet.getDouble();824value = Double.valueOf(castedValue);825} break;826case JDWP.Tag.INT: {827int castedValue = packet.getInt();828value = Integer.valueOf(castedValue);829} break;830case JDWP.Tag.SHORT: {831short castedValue = packet.getShort();832value = Short.valueOf(castedValue);833} break;834case JDWP.Tag.BOOLEAN: {835byte castedValue = packet.getByte();836value = Boolean.valueOf(castedValue != 0);837} break;838case JDWP.Tag.LONG: {839long castedValue = packet.getLong();840value = Long.valueOf(castedValue);841} break;842case JDWP.Tag.VOID: {843value = Long.valueOf(0);844} break;845case JDWP.Tag.ARRAY:846case JDWP.Tag.OBJECT:847case JDWP.Tag.STRING:848case JDWP.Tag.THREAD:849case JDWP.Tag.THREAD_GROUP:850case JDWP.Tag.CLASS_LOADER:851case JDWP.Tag.CLASS_OBJECT: {852long castedValue = packet.getObjectID();853value = Long.valueOf(castedValue);854} break;855default: {856throw new Failure("Unknown tag found while reading value from packet: " + tag);857}858}859}860861public String toString(byte tag) {862if (value == null) {863return "null";864}865String type = null;866try {867switch (tag) {868case JDWP.Tag.BYTE: {869type = "BYTE";870} break;871case JDWP.Tag.CHAR: {872type = "CHAR";873} break;874case JDWP.Tag.FLOAT: {875type = "FLOAT";876} break;877case JDWP.Tag.DOUBLE: {878type = "DOUBLE";879} break;880case JDWP.Tag.INT: {881type = "INT";882} break;883case JDWP.Tag.SHORT: {884type = "SHORT";885} break;886case JDWP.Tag.BOOLEAN: {887type = "BOOLEAN";888} break;889case JDWP.Tag.LONG: {890type = "LONG";891} break;892case JDWP.Tag.VOID: {893type = "VOID";894} break;895case JDWP.Tag.ARRAY: {896type = "ARRAY_ID";897} break;898case JDWP.Tag.OBJECT: {899type = "OBJECT_ID";900} break;901case JDWP.Tag.STRING: {902type = "STRING_ID";903} break;904case JDWP.Tag.THREAD: {905type = "THREAD_ID";906} break;907case JDWP.Tag.THREAD_GROUP: {908type = "THREAD_GROUP_ID";909} break;910case JDWP.Tag.CLASS_LOADER: {911type = "CLASS_LOADER_ID";912} break;913case JDWP.Tag.CLASS_OBJECT: {914type = "CLASS_OBJECT_ID";915} break;916default: {917throw new Failure("Unknown tag found while converting value into string: " + tag);918}919}920return "(" + type + ")" + value;921} catch (ClassCastException e) {922throw new Failure("Wrong tag " + tag + " found while putting value to packet: " + value);923}924}925926} // end of class Value927928public static class Value extends UntaggedValue {929930public static final int TAG_OFFSET = 0;931public static final int VALUE_OFFSET = TAG_OFFSET + TypeSize.TAG;932933public byte tag = 0;934935public Value() {936}937938public Value(byte tag, Object value) {939super(value);940this.tag = tag;941}942943public byte getTag() {944return tag;945}946947public int length() {948return super.length(tag);949}950951public void addValueTo(Packet packet) {952if (value == null) {953throw new Failure("Unable to put null value into packet: " + this);954}955packet.addByte(tag);956super.addValueTo(packet, tag);957}958959public void getValueFrom(Packet packet) throws BoundException {960tag = packet.getByte();961super.getValueFrom(packet, tag);962}963964public String toString() {965return super.toString(tag);966}967968} // end of class Value969970} // end of class JDWP971972973