src/jdk.jdi/share/classes/com/sun/tools/jdi/PacketStream.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/PacketStream.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    29
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    30
import java.util.List;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    31
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    32
import com.sun.jdi.BooleanValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    33
import com.sun.jdi.ByteValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    34
import com.sun.jdi.CharValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    35
import com.sun.jdi.ClassType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    36
import com.sun.jdi.DoubleValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    37
import com.sun.jdi.Field;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    38
import com.sun.jdi.FloatValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    39
import com.sun.jdi.IntegerValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    40
import com.sun.jdi.InterfaceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    41
import com.sun.jdi.InternalException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    42
import com.sun.jdi.InvalidTypeException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    43
import com.sun.jdi.Location;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    44
import com.sun.jdi.LongValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    45
import com.sun.jdi.ObjectReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    46
import com.sun.jdi.PrimitiveValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    47
import com.sun.jdi.ShortValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    48
import com.sun.jdi.Value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class PacketStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    final VirtualMachineImpl vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int inCursor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    final Packet pkt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private boolean isCommitted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    PacketStream(VirtualMachineImpl vm, int cmdSet, int cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.vm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.pkt = new Packet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        pkt.cmdSet = (short)cmdSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        pkt.cmd = (short)cmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    PacketStream(VirtualMachineImpl vm, Packet pkt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.vm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.pkt = pkt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.isCommitted = true; /* read only stream */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    int id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return pkt.id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    void send() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (!isCommitted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            pkt.data = dataStream.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            vm.sendToTarget(pkt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            isCommitted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    void waitForReply() throws JDWPException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (!isCommitted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new InternalException("waitForReply without send");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        vm.waitForTargetReply(pkt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (pkt.errorCode != Packet.ReplyNoError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new JDWPException(pkt.errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    void writeBoolean(boolean data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if(data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            dataStream.write( 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            dataStream.write( 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    void writeByte(byte data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        dataStream.write( data );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    void writeChar(char data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        dataStream.write( (byte)((data >>> 8) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        dataStream.write( (byte)((data >>> 0) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    void writeShort(short data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        dataStream.write( (byte)((data >>> 8) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        dataStream.write( (byte)((data >>> 0) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    void writeInt(int data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        dataStream.write( (byte)((data >>> 24) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        dataStream.write( (byte)((data >>> 16) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        dataStream.write( (byte)((data >>> 8) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        dataStream.write( (byte)((data >>> 0) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    void writeLong(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        dataStream.write( (byte)((data >>> 56) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        dataStream.write( (byte)((data >>> 48) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        dataStream.write( (byte)((data >>> 40) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        dataStream.write( (byte)((data >>> 32) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        dataStream.write( (byte)((data >>> 24) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        dataStream.write( (byte)((data >>> 16) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        dataStream.write( (byte)((data >>> 8) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        dataStream.write( (byte)((data >>> 0) & 0xFF) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    void writeFloat(float data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        writeInt(Float.floatToIntBits(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    void writeDouble(double data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        writeLong(Double.doubleToLongBits(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    void writeID(int size, long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                writeLong(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                writeInt((int)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                writeShort((short)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                throw new UnsupportedOperationException("JDWP: ID size not supported: " + size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void writeNullObjectRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        writeObjectRef(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    void writeObjectRef(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        writeID(vm.sizeofObjectRef, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    void writeClassRef(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        writeID(vm.sizeofClassRef, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    void writeMethodRef(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        writeID(vm.sizeofMethodRef, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   175
    void writeModuleRef(long data) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   176
        writeID(vm.sizeofModuleRef, data);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   177
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   178
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    void writeFieldRef(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        writeID(vm.sizeofFieldRef, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    void writeFrameRef(long data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        writeID(vm.sizeofFrameRef, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    void writeByteArray(byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        dataStream.write(data, 0, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    void writeString(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            byte[] stringBytes = string.getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            writeInt(stringBytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            writeByteArray(stringBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } catch (java.io.UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throw new InternalException("Cannot convert string to UTF8 bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    void writeLocation(Location location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        ReferenceTypeImpl refType = (ReferenceTypeImpl)location.declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        byte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (refType instanceof ClassType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            tag = JDWP.TypeTag.CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } else if (refType instanceof InterfaceType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // It's possible to have executable code in an interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            tag = JDWP.TypeTag.INTERFACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            throw new InternalException("Invalid Location");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        writeByte(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        writeClassRef(refType.ref());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        writeMethodRef(((MethodImpl)location.method()).ref());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        writeLong(location.codeIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    void writeValue(Value val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            writeValueChecked(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } catch (InvalidTypeException exc) {  // should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                "Internal error: Invalid Tag/Type pair");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    void writeValueChecked(Value val) throws InvalidTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        writeByte(ValueImpl.typeValueKey(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        writeUntaggedValue(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    void writeUntaggedValue(Value val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            writeUntaggedValueChecked(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } catch (InvalidTypeException exc) {  // should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                "Internal error: Invalid Tag/Type pair");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    void writeUntaggedValueChecked(Value val) throws InvalidTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        byte tag = ValueImpl.typeValueKey(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (isObjectTag(tag)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                 writeObjectRef(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (!(val instanceof ObjectReference)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                writeObjectRef(((ObjectReferenceImpl)val).ref());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                case JDWP.Tag.BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    if(!(val instanceof ByteValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    writeByte(((PrimitiveValue)val).byteValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                case JDWP.Tag.CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    if(!(val instanceof CharValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    writeChar(((PrimitiveValue)val).charValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                case JDWP.Tag.FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    if(!(val instanceof FloatValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    writeFloat(((PrimitiveValue)val).floatValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                case JDWP.Tag.DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    if(!(val instanceof DoubleValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    writeDouble(((PrimitiveValue)val).doubleValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                case JDWP.Tag.INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if(!(val instanceof IntegerValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    writeInt(((PrimitiveValue)val).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                case JDWP.Tag.LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    if(!(val instanceof LongValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    writeLong(((PrimitiveValue)val).longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                case JDWP.Tag.SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    if(!(val instanceof ShortValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    writeShort(((PrimitiveValue)val).shortValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                case JDWP.Tag.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    if(!(val instanceof BooleanValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        throw new InvalidTypeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    writeBoolean(((PrimitiveValue)val).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Read byte represented as one bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    byte readByte() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        byte ret = pkt.data[inCursor];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        inCursor += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Read boolean represented as one byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    boolean readBoolean() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        byte ret = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return (ret != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Read char represented as two bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    char readChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        int b1, b2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        b1 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        b2 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return (char)((b1 << 8) + b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Read short represented as two bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    short readShort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        int b1, b2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        b1 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        b2 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return (short)((b1 << 8) + b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Read int represented as four bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    int readInt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int b1,b2,b3,b4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        b1 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        b2 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        b3 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        b4 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Read long represented as eight bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    long readLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        long b1,b2,b3,b4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        long b5,b6,b7,b8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        b1 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        b2 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        b3 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        b4 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        b5 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        b6 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        b7 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        b8 = pkt.data[inCursor++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return ((b1 << 56) + (b2 << 48) + (b3 << 40) + (b4 << 32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                + (b5 << 24) + (b6 << 16) + (b7 << 8) + b8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Read float represented as four bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    float readFloat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return Float.intBitsToFloat(readInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Read double represented as eight bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    double readDouble() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return Double.longBitsToDouble(readLong());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Read string represented as four byte length followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * characters of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    String readString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int len = readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            ret = new String(pkt.data, inCursor, len, "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } catch(java.io.UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            System.err.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            ret = "Conversion error!";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        inCursor += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private long readID(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
          case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
              return readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
          case 4:
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   426
              return readInt();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
          case 2:
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   428
              return readShort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
              throw new UnsupportedOperationException("JDWP: ID size not supported: " + size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Read object represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    long readObjectRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return readID(vm.sizeofObjectRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    long readClassRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return readID(vm.sizeofClassRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    ObjectReferenceImpl readTaggedObjectReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        byte typeKey = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return vm.objectMirror(readObjectRef(), typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    ObjectReferenceImpl readObjectReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return vm.objectMirror(readObjectRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    StringReferenceImpl readStringReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return vm.stringMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    ArrayReferenceImpl readArrayReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return vm.arrayMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    ThreadReferenceImpl readThreadReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return vm.threadMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    ThreadGroupReferenceImpl readThreadGroupReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return vm.threadGroupMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    ClassLoaderReferenceImpl readClassLoaderReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        return vm.classLoaderMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    ClassObjectReferenceImpl readClassObjectReference() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return vm.classObjectMirror(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    ReferenceTypeImpl readReferenceType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        byte tag = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        long ref = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return vm.referenceType(ref, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   490
    ModuleReferenceImpl readModule() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   491
        long ref = readModuleRef();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   492
        return vm.moduleMirror(ref);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   493
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   494
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Read method reference represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    long readMethodRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return readID(vm.sizeofMethodRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   503
     * Read module reference represented as vm specific byte sequence.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   504
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   505
    long readModuleRef() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   506
        return readID(vm.sizeofModuleRef);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   507
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   508
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   509
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Read field reference represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    long readFieldRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return readID(vm.sizeofFieldRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Read field represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    Field readField() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   520
        ReferenceTypeImpl refType = readReferenceType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        long fieldRef = readFieldRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return refType.getFieldMirror(fieldRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Read frame represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    long readFrameRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return readID(vm.sizeofFrameRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Read a value, first byte describes type of value to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    ValueImpl readValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        byte typeKey = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        return readUntaggedValue(typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    ValueImpl readUntaggedValue(byte typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        ValueImpl val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            val = vm.objectMirror(readObjectRef(), typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            switch(typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                case JDWP.Tag.BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    val = new ByteValueImpl(vm, readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                case JDWP.Tag.CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    val = new CharValueImpl(vm, readChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                case JDWP.Tag.FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    val = new FloatValueImpl(vm, readFloat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                case JDWP.Tag.DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    val = new DoubleValueImpl(vm, readDouble());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                case JDWP.Tag.INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    val = new IntegerValueImpl(vm, readInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                case JDWP.Tag.LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    val = new LongValueImpl(vm, readLong());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                case JDWP.Tag.SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    val = new ShortValueImpl(vm, readShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                case JDWP.Tag.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    val = new BooleanValueImpl(vm, readBoolean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                case JDWP.Tag.VOID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    val = new VoidValueImpl(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Read location represented as vm specific byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    Location readLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        byte tag = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        long classRef = readObjectRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        long methodRef = readMethodRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        long codeIndex = readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (classRef != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            /* Valid location */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            ReferenceTypeImpl refType = vm.referenceType(classRef, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            return new LocationImpl(vm, refType, methodRef, codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            /* Null location (example: uncaught exception) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
           return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    byte[] readByteArray(int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        byte[] array = new byte[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        System.arraycopy(pkt.data, inCursor, array, 0, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        inCursor += length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    List<Value> readArrayRegion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        byte typeKey = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        int length = readInt();
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   615
        List<Value> list = new ArrayList<>(length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        boolean gettingObjects = isObjectTag(typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
             * Each object comes back with a type key which might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
             * identify a more specific type than the type key we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
             * passed in, so we use it in the decodeValue call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
             * (For primitives, we just use the original one)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            if (gettingObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                typeKey = readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            Value value = readUntaggedValue(typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            list.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    void writeArrayRegion(List<Value> srcValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        writeInt(srcValues.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        for (int i = 0; i < srcValues.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            Value value = srcValues.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            writeUntaggedValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    int skipBytes(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        inCursor += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    byte command() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return (byte)pkt.cmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    static boolean isObjectTag(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return (tag == JDWP.Tag.OBJECT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
               (tag == JDWP.Tag.ARRAY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
               (tag == JDWP.Tag.STRING) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
               (tag == JDWP.Tag.THREAD) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
               (tag == JDWP.Tag.THREAD_GROUP) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
               (tag == JDWP.Tag.CLASS_LOADER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
               (tag == JDWP.Tag.CLASS_OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
}