test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/ReplyPacket.java
author iignatyev
Wed, 30 May 2018 20:54:45 -0700
changeset 50317 cf71bff5f533
permissions -rw-r--r--
8199371: [TESTBUG] Open source vm testbase JDWP tests Reviewed-by: sspitsyn, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50317
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     1
/*
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     4
 *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     8
 *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    14
 *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    18
 *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    21
 * questions.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    22
 */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    23
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    24
package nsk.share.jdwp;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    25
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    26
import nsk.share.*;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    27
import java.util.Vector;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    28
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    29
/**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    30
 * This class represents a JDWP reply packet.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    31
 */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    32
public class ReplyPacket extends Packet {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    33
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    34
    /** Error code constant. */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    35
//    public final static int errOk               = JDWP.Error.NONE;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    36
    /** Error code constant. */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    37
//    public final static int errWrongPacketSize  = 0x400;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    38
    /** Error code constant. */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    39
//    public final static int errNotAvailable     = 0x401;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    40
    /** Error code constant. */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    41
//    public final static int errEvent            = 0x4064;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    42
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    43
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    44
     * Make empty reply packet.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    45
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    46
    public ReplyPacket() {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    47
        super();
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    48
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    49
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    50
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    51
     * Make reply packet with data from the specified byte buffer.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    52
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    53
//    public ReplyPacket(ByteBuffer packet) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    54
    public ReplyPacket(Packet packet) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    55
        super(packet);
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    56
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    57
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    58
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    59
     * Return value of the "error code" field of JDWP reply packet.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    60
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    61
    public int getErrorCode() {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    62
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    63
        int err = 0;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    64
        try {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    65
            err = (int) getID(ErrorCodeOffset, 2);
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    66
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    67
        catch (BoundException e) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    68
            throw new Failure("Caught unexpected exception while getting error code from header:\n\t"
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    69
                            + e);
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    70
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    71
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    72
        return err;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    73
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    74
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    75
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    76
     * Set value of the "error code" field of JDWP reply packet.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    77
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    78
    public void setErrorCode(long err) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    79
        try {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    80
            putID(ErrorCodeOffset, err, 2);
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    81
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    82
        catch (BoundException e) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    83
            throw new Failure("Caught unexpected exception while setting error code into header:\n\t"
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    84
                            + e);
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    85
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    86
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    87
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    88
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    89
     * Check reply packet header.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    90
     * This method check if reply packet has valid values in the header fields.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    91
     *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    92
     * @throws PacketFormatException if packet header fields have error or invalid values
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    93
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    94
/*
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    95
    protected void checkHeaderForReplyOrEvent() throws PacketFormatException {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    96
        super.checkHeader();
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    97
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    98
 */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
    99
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   100
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   101
     * Check reply packet header.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   102
     * This method check if reply packet has valid values in the header fields.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   103
     *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   104
     * @throws PacketFormatException if packet header fields have error or invalid values
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   105
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   106
    public void checkHeader() throws PacketFormatException {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   107
//        checkHeaderForReplyOrEvent();
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   108
        super.checkHeader();
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   109
        if (getFlags() != JDWP.Flag.REPLY_PACKET) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   110
            throw new PacketFormatException("Unexpected flags in reply packet header: "
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   111
                                            + "0x" + toHexDecString(getFlags(), 2));
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   112
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   113
        if (getErrorCode() != JDWP.Error.NONE) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   114
            throw new PacketFormatException("Unexpected error code in reply packet header: "
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   115
                                            + "0x" + toHexDecString(getErrorCode(), 4));
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   116
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   117
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   118
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   119
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   120
     * Check reply packet header for specified reply ID.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   121
     * This method check if reply packet has valid values in the header fields.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   122
     *
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   123
     * @throws PacketFormatException if packet header fields have error or invalid values
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   124
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   125
    public void checkHeader(int id) throws PacketFormatException {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   126
        checkHeader();
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   127
        if (getPacketID() != id) {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   128
            throw new PacketFormatException("Unexpected ID in reply packet header: "
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   129
                                            + getPacketID());
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   130
        }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   131
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   132
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   133
    /**
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   134
     * Return string representation of the reply packet header.
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   135
     */
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   136
    public String headerToString() {
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   137
        String s;
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   138
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   139
        if (getFlags() == 0)
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   140
            s = " (command)";
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   141
        else
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   142
            s = " (error)  ";
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   143
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   144
        return super.headerToString()
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   145
             + "    " + toHexString(CommandOffset,  4) + s + ": 0x" + toHexDecString(getErrorCode(), 4) + "\n";
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   146
    }
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   147
cf71bff5f533 8199371: [TESTBUG] Open source vm testbase JDWP tests
iignatyev
parents:
diff changeset
   148
}