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