test/hotspot/jtreg/serviceability/jdwp/JdwpCmd.java
author phedlin
Fri, 15 Nov 2019 16:39:08 +0100
changeset 59291 54cf02d52c1b
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220376: C2: Int >0 not recognized as !=0 for div by 0 check Reviewed-by: neliasso, vlivanov, mdoerr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40891
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     1
/*
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     4
 *
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     8
 *
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    13
 * accompanied this code).
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    14
 *
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    18
 *
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    21
 * questions.
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    22
 */
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    23
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    24
import java.io.IOException;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    25
import java.nio.ByteBuffer;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    26
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    27
/**
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    28
 * Generic JDWP command
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    29
 * @param <T> the corresponding JDWP reply class, to construct a reply object
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    30
 */
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    31
public abstract class JdwpCmd<T extends JdwpReply> {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    32
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    33
    private ByteBuffer data;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    34
    private static int id = 1;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    35
    private final byte FLAGS = 0;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    36
    private T reply;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    37
    private final int dataLen;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    38
    private final int HEADER_LEN = 11;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    39
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    40
    /**
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    41
     * JDWWp command
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    42
     * @param cmd command code
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    43
     * @param cmdSet command set
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    44
     * @param replyClz command reply class
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    45
     * @param dataLen length of additional data for the command
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    46
     */
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    47
    JdwpCmd(int cmd, int cmdSet, Class<T> replyClz, int dataLen) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    48
        this.dataLen = dataLen;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    49
        data = ByteBuffer.allocate(HEADER_LEN + dataLen);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    50
        data.putInt(HEADER_LEN + dataLen);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    51
        data.putInt(id++);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    52
        data.put(FLAGS);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    53
        data.put((byte) cmdSet);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    54
        data.put((byte) cmd);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    55
        if (replyClz != null) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    56
            try {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    57
                reply = replyClz.newInstance();
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    58
            } catch (Exception ex) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    59
                ex.printStackTrace();
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    60
            }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    61
        }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    62
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    63
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    64
    JdwpCmd(int cmd, int cmdSet, Class<T> replyClz) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    65
        this(cmd, cmdSet, replyClz, 0);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    66
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    67
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    68
    int getDataLength() {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    69
        return dataLen;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    70
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    71
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    72
    public final T send(JdwpChannel channel) throws IOException {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    73
        channel.write(data.array(), HEADER_LEN + getDataLength());
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    74
        if (reply != null) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    75
            reply.initFromStream(channel.getInputStream());
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    76
        }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    77
        return (T) reply;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    78
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    79
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    80
    protected void putRefId(long refId) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    81
        data.putLong(refId);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    82
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    83
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    84
    protected void putInt(int val) {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    85
        data.putInt(val);
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    86
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    87
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    88
    protected static int refLen() {
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    89
        return 8;
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    90
    }
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    91
8010999ff6d0 8148103: add more tests for task "Update JDI and JDWP for modules"
akulyakh
parents:
diff changeset
    92
}