Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/EventPacket.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.share.jdwp;2425import nsk.share.*;2627import java.util.Vector;2829/**30* This class represents a JDWP event packet.31*/32public class EventPacket extends CommandPacket {3334/** Offset of the "suspendPolicy" field in a JDWP event packet. */35public final static int SuspendPolicyOffset = DataOffset;3637/** Offset of the "eventsCount" field in a JDWP event packet. */38public final static int EventsCountOffset = SuspendPolicyOffset + JDWP.TypeSize.BYTE;3940/** Offset of the first "eventKind" field in a JDWP event packet. */41public final static int FirstEventKindOffset = EventsCountOffset + JDWP.TypeSize.INT;4243/**44* Make an empty event packet.45*/46public EventPacket() {47super(JDWP.Command.Event.Composite, 0);48}4950/**51* Make event packet with data from the specified byte buffer.52*/53// public EventPacket(ByteBuffer packet) {54public EventPacket(Packet packet) {55super(packet);56}5758/**59* Return suspend policy of the events in the packet.60*61* throws BoundException if event packet structure is not valid62*/63public byte getSuspendPolicy() {64try {65return getByte(SuspendPolicyOffset);66}67catch (BoundException e) {68throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"69+ e);70}71}7273/**74* Return number of events in the packet.75*76* throws BoundException if event packet structure is not valid77*/78public int getEventsCount() {79try {80return getInt(EventsCountOffset);81}82catch (BoundException e) {83throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"84+ e);85}86}8788/**89* Return constant indicates kind of the first event in the packet.90*91* throws BoundException if event packet structure is not valid92*/93public int getEventKind() {94try {95return getByte(FirstEventKindOffset);96}97catch (BoundException e) {98throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"99+ e);100}101}102103/**104* Check event packet header.105* This method check if event packet has valid values in the header fields.106*107* @throws PacketFormatException if packet header fields have error or invalid values108*/109public void checkHeader() throws PacketFormatException {110super.checkHeader();111if (getFullCommand() != JDWP.Command.Event.Composite) {112throw new PacketFormatException("Not Event.Composite command in the event packet header: "113+ "0x" + toHexDecString(getFullCommand(), 4) );114}115if (getFlags() != JDWP.Flag.EVENT_PACKET) {116throw new PacketFormatException("Unexpected flags in the event packet header: "117+ "0x" + toHexDecString(getFlags(), 2));118}119/*120if (getPacketID() != 0) {121throw new PacketFormatException("Non-zero packet ID in the event packet header: "122+ getPacketID());123}124*/125}126127/**128* Check event packet header for only one event of specified kind.129* This method check if event packet has valid values in the header fields.130*131* @throws PacketFormatException if packet header fields have error or invalid values132*/133public void checkHeader(int eventKind) throws PacketFormatException {134checkHeader();135if (getEventsCount() != 1) {136throw new PacketFormatException("Not a single event in the event packet: "137+ getEventsCount() + " events");138}139if (getEventKind() != eventKind) {140throw new PacketFormatException("Unexpected event kind in the event packet: "141+ "0x" + toHexDecString(getEventKind(), 2));142}143}144145/**146* Return string representation of the event packet header.147*/148public String headerToString() {149return super.headerToString()150+ " " + toHexString(SuspendPolicyOffset, 4) + " (policy): 0x" + toHexDecString(getSuspendPolicy(), 2) + "\n"151+ " " + toHexString(EventsCountOffset, 4) + " (events): 0x" + toHexDecString(getEventsCount(), 8) + "\n"152+ " " + toHexString(FirstEventKindOffset, 4) + " (kind): 0x" + toHexDecString(getEventKind(), 2) + "\n";153}154155}156157158