Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/EventPacket.java
41161 views
1
/*
2
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package nsk.share.jdwp;
25
26
import nsk.share.*;
27
28
import java.util.Vector;
29
30
/**
31
* This class represents a JDWP event packet.
32
*/
33
public class EventPacket extends CommandPacket {
34
35
/** Offset of the "suspendPolicy" field in a JDWP event packet. */
36
public final static int SuspendPolicyOffset = DataOffset;
37
38
/** Offset of the "eventsCount" field in a JDWP event packet. */
39
public final static int EventsCountOffset = SuspendPolicyOffset + JDWP.TypeSize.BYTE;
40
41
/** Offset of the first "eventKind" field in a JDWP event packet. */
42
public final static int FirstEventKindOffset = EventsCountOffset + JDWP.TypeSize.INT;
43
44
/**
45
* Make an empty event packet.
46
*/
47
public EventPacket() {
48
super(JDWP.Command.Event.Composite, 0);
49
}
50
51
/**
52
* Make event packet with data from the specified byte buffer.
53
*/
54
// public EventPacket(ByteBuffer packet) {
55
public EventPacket(Packet packet) {
56
super(packet);
57
}
58
59
/**
60
* Return suspend policy of the events in the packet.
61
*
62
* throws BoundException if event packet structure is not valid
63
*/
64
public byte getSuspendPolicy() {
65
try {
66
return getByte(SuspendPolicyOffset);
67
}
68
catch (BoundException e) {
69
throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"
70
+ e);
71
}
72
}
73
74
/**
75
* Return number of events in the packet.
76
*
77
* throws BoundException if event packet structure is not valid
78
*/
79
public int getEventsCount() {
80
try {
81
return getInt(EventsCountOffset);
82
}
83
catch (BoundException e) {
84
throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"
85
+ e);
86
}
87
}
88
89
/**
90
* Return constant indicates kind of the first event in the packet.
91
*
92
* throws BoundException if event packet structure is not valid
93
*/
94
public int getEventKind() {
95
try {
96
return getByte(FirstEventKindOffset);
97
}
98
catch (BoundException e) {
99
throw new Failure("Caught unexpected exception while getting event kind from header:\n\t"
100
+ e);
101
}
102
}
103
104
/**
105
* Check event packet header.
106
* This method check if event packet has valid values in the header fields.
107
*
108
* @throws PacketFormatException if packet header fields have error or invalid values
109
*/
110
public void checkHeader() throws PacketFormatException {
111
super.checkHeader();
112
if (getFullCommand() != JDWP.Command.Event.Composite) {
113
throw new PacketFormatException("Not Event.Composite command in the event packet header: "
114
+ "0x" + toHexDecString(getFullCommand(), 4) );
115
}
116
if (getFlags() != JDWP.Flag.EVENT_PACKET) {
117
throw new PacketFormatException("Unexpected flags in the event packet header: "
118
+ "0x" + toHexDecString(getFlags(), 2));
119
}
120
/*
121
if (getPacketID() != 0) {
122
throw new PacketFormatException("Non-zero packet ID in the event packet header: "
123
+ getPacketID());
124
}
125
*/
126
}
127
128
/**
129
* Check event packet header for only one event of specified kind.
130
* This method check if event packet has valid values in the header fields.
131
*
132
* @throws PacketFormatException if packet header fields have error or invalid values
133
*/
134
public void checkHeader(int eventKind) throws PacketFormatException {
135
checkHeader();
136
if (getEventsCount() != 1) {
137
throw new PacketFormatException("Not a single event in the event packet: "
138
+ getEventsCount() + " events");
139
}
140
if (getEventKind() != eventKind) {
141
throw new PacketFormatException("Unexpected event kind in the event packet: "
142
+ "0x" + toHexDecString(getEventKind(), 2));
143
}
144
}
145
146
/**
147
* Return string representation of the event packet header.
148
*/
149
public String headerToString() {
150
return super.headerToString()
151
+ " " + toHexString(SuspendPolicyOffset, 4) + " (policy): 0x" + toHexDecString(getSuspendPolicy(), 2) + "\n"
152
+ " " + toHexString(EventsCountOffset, 4) + " (events): 0x" + toHexDecString(getEventsCount(), 8) + "\n"
153
+ " " + toHexString(FirstEventKindOffset, 4) + " (kind): 0x" + toHexDecString(getEventKind(), 2) + "\n";
154
}
155
156
}
157
158