annotate agent/src/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java @ 12226:7944aba7ba41

8015107: NPG: Use consistent naming for metaspace concepts Reviewed-by: coleenp, mgerdin, hseigel
author ehelin
date Mon, 12 Aug 2013 17:37:02 +0200
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class PerfDataEntry extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static JIntField entryLengthField;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static JIntField nameOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static JIntField vectorLengthField;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static JByteField dataTypeField;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static JByteField flagsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static JByteField dataUnitsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static JByteField dataVariabilityField;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static JIntField dataOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 });
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Type type = db.lookupType("PerfDataEntry");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 entryLengthField = type.getJIntField("entry_length");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 nameOffsetField = type.getJIntField("name_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 vectorLengthField = type.getJIntField("vector_length");
a61af66fc99e Initial load
duke
parents:
diff changeset
56 dataTypeField = type.getJByteField("data_type");
a61af66fc99e Initial load
duke
parents:
diff changeset
57 flagsField = type.getJByteField("flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 dataUnitsField = type.getJByteField("data_units");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 dataVariabilityField = type.getJByteField("data_variability");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 dataOffsetField = type.getJIntField("data_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public PerfDataEntry(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public int entryLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return (int) entryLengthField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public int nameOffset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return (int) nameOffsetField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public int vectorLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return (int) vectorLengthField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // returns one of the constants in BasicType class
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public int dataType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 char ch = (char) (byte) dataTypeField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return BasicType.charToType(ch);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public byte flags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return (byte) flagsField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public boolean supported() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return (flags() & 0x1) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // NOTE: Keep this in sync with PerfData::Units enum in VM code
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public interface PerfDataUnits {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public static final int U_None = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public static final int U_Bytes = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public static final int U_Ticks = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public static final int U_Events = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public static final int U_String = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public static final int U_Hertz = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // returns one of the constants in PerfDataUnits
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public int dataUnits() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return (int) dataUnitsField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // NOTE: Keep this in sync with PerfData::Variability enum in VM code
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public interface PerfDataVariability {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public static final int V_Constant = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public static final int V_Monotonic = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public static final int V_Variable = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // returns one of the constants in PerfDataVariability
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public int dataVariability() {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return (int) dataVariabilityField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public int dataOffset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return (int) dataOffsetField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public String name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 int off = nameOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return CStringUtilities.getString(addr.addOffsetTo(off));
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public boolean booleanValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
134 dataType() == BasicType.tBoolean, "not a boolean");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return addr.getJBooleanAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public char charValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
142 dataType() == BasicType.tChar, "not a char");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return addr.getJCharAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public byte byteValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
150 dataType() == BasicType.tByte, "not a byte");
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return addr.getJByteAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public short shortValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
159 dataType() == BasicType.tShort, "not a short");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return addr.getJShortAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 public int intValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
167 dataType() == BasicType.tInt, "not an int");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return addr.getJIntAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public long longValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
175 dataType() == BasicType.tLong, "not a long");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return addr.getJLongAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 public float floatValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
183 dataType() == BasicType.tFloat, "not a float");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return addr.getJFloatAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 public double doubleValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 Assert.that(vectorLength() == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
191 dataType() == BasicType.tDouble, "not a double");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return addr.getJDoubleAt(dataOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public boolean[] booleanArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
200 dataType() == BasicType.tBoolean, "not a boolean vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 boolean[] res = new boolean[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
203 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 final long size = getHeap().getBooleanSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 res[i] = addr.getJBooleanAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public char[] charArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
215 dataType() == BasicType.tChar, "not a char vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 char[] res = new char[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
218 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 final long size = getHeap().getCharSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 res[i] = addr.getJCharAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 public byte[] byteArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
230 dataType() == BasicType.tByte, "not a byte vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 byte[] res = new byte[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
233 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 final long size = getHeap().getByteSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
235 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 res[i] = addr.getJByteAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public short[] shortArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
245 dataType() == BasicType.tShort, "not a short vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 short[] res = new short[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
248 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
249 final long size = getHeap().getShortSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 res[i] = addr.getJShortAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public int[] intArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
260 dataType() == BasicType.tInt, "not an int vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 int[] res = new int[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
263 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 final long size = getHeap().getIntSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 res[i] = addr.getJIntAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 public long[] longArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
275 dataType() == BasicType.tLong, "not a long vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 long[] res = new long[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
278 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
279 final long size = getHeap().getLongSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 res[i] = addr.getJLongAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 public float[] floatArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
290 dataType() == BasicType.tFloat, "not a float vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 float[] res = new float[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
293 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 final long size = getHeap().getFloatSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 res[i] = addr.getJFloatAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 public double[] doubleArrayValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 Assert.that(len > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
305 dataType() == BasicType.tDouble, "not a double vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 double[] res = new double[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
308 final int off = dataOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 final long size = getHeap().getDoubleSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 res[i] = addr.getJDoubleAt(off + i * size);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // value as String
a61af66fc99e Initial load
duke
parents:
diff changeset
317 public String valueAsString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int dataType = dataType();
a61af66fc99e Initial load
duke
parents:
diff changeset
319 int len = vectorLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 String str = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (len == 0) { // scalar
a61af66fc99e Initial load
duke
parents:
diff changeset
322 switch (dataType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 case BasicType.tBoolean:
a61af66fc99e Initial load
duke
parents:
diff changeset
324 str = Boolean.toString(booleanValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 case BasicType.tChar:
a61af66fc99e Initial load
duke
parents:
diff changeset
327 str = "'" + Character.toString(charValue()) + "'";
a61af66fc99e Initial load
duke
parents:
diff changeset
328 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 case BasicType.tByte:
a61af66fc99e Initial load
duke
parents:
diff changeset
330 str = Byte.toString(byteValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
331 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 case BasicType.tShort:
a61af66fc99e Initial load
duke
parents:
diff changeset
333 str = Short.toString(shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
334 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 case BasicType.tInt:
a61af66fc99e Initial load
duke
parents:
diff changeset
336 str = Integer.toString(intValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
337 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 case BasicType.tLong:
a61af66fc99e Initial load
duke
parents:
diff changeset
339 str = Long.toString(longValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
340 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 case BasicType.tFloat:
a61af66fc99e Initial load
duke
parents:
diff changeset
342 str = Float.toString(floatValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
343 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 case BasicType.tDouble:
a61af66fc99e Initial load
duke
parents:
diff changeset
345 str = Double.toString(doubleValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
346 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
348 str = "<unknown scalar value>";
a61af66fc99e Initial load
duke
parents:
diff changeset
349 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 } else { // vector
a61af66fc99e Initial load
duke
parents:
diff changeset
352 switch (dataType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 case BasicType.tBoolean: {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 boolean[] res = booleanArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
355 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
357 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 buf.append(Boolean.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
359 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
362 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 case BasicType.tChar: {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // char[] is returned as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
368 str = new String(charArrayValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 case BasicType.tByte: {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // byte[] is returned as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
374 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 str = new String(byteArrayValue(), "US-ASCII");
a61af66fc99e Initial load
duke
parents:
diff changeset
376 } catch (java.io.UnsupportedEncodingException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 str = "can't decode string : " + e.getMessage();
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 case BasicType.tShort: {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 short[] res = shortArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
384 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 buf.append(Short.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
388 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
391 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 case BasicType.tInt: {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 int[] res = intArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
397 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
398 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
399 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 buf.append(Integer.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
401 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
404 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
405 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 case BasicType.tLong: {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 long[] res = longArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
410 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
411 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
412 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 buf.append(Long.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
414 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
417 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
418 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 case BasicType.tFloat: {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 float[] res = floatArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
423 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
425 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 buf.append(Float.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
427 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
430 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
431 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 case BasicType.tDouble: {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 double[] res = doubleArrayValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 buf.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
438 for (int i = 0; i < res.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 buf.append(Double.toString(res[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
440 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 buf.append(']');
a61af66fc99e Initial load
duke
parents:
diff changeset
443 str = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
448 str = "<unknown vector value>";
a61af66fc99e Initial load
duke
parents:
diff changeset
449 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // add units
a61af66fc99e Initial load
duke
parents:
diff changeset
454 switch (dataUnits()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 case PerfDataUnits.U_None:
a61af66fc99e Initial load
duke
parents:
diff changeset
456 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 case PerfDataUnits.U_Bytes:
a61af66fc99e Initial load
duke
parents:
diff changeset
458 str += " byte(s)";
a61af66fc99e Initial load
duke
parents:
diff changeset
459 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 case PerfDataUnits.U_Ticks:
a61af66fc99e Initial load
duke
parents:
diff changeset
461 str += " tick(s)";
a61af66fc99e Initial load
duke
parents:
diff changeset
462 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 case PerfDataUnits.U_Events:
a61af66fc99e Initial load
duke
parents:
diff changeset
464 str += " event(s)";
a61af66fc99e Initial load
duke
parents:
diff changeset
465 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 case PerfDataUnits.U_String:
a61af66fc99e Initial load
duke
parents:
diff changeset
467 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 case PerfDataUnits.U_Hertz:
a61af66fc99e Initial load
duke
parents:
diff changeset
469 str += " Hz";
a61af66fc99e Initial load
duke
parents:
diff changeset
470 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 return str;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // -- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
477 private ObjectHeap getHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 return VM.getVM().getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }