jdk/src/share/classes/sun/management/counter/perf/PerfDataType.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.management.counter.perf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A typesafe enumeration for the data types supported for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * performance data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p> The enumeration values for this typesafe enumeration must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * kept in sychronization with the PerfDataType enum in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * globalsDefinitions.hpp file in the HotSpot source base.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author  Brian Doherty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class PerfDataType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final byte value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static final PerfDataType BOOLEAN = new PerfDataType("boolean",  "Z", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final PerfDataType CHAR    = new PerfDataType("char",     "C", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final PerfDataType FLOAT   = new PerfDataType("float",    "F", 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final PerfDataType DOUBLE  = new PerfDataType("double",   "D", 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final PerfDataType BYTE    = new PerfDataType("byte",     "B", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final PerfDataType SHORT   = new PerfDataType("short",    "S", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final PerfDataType INT     = new PerfDataType("int",      "I", 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final PerfDataType LONG    = new PerfDataType("long",     "J", 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final PerfDataType ILLEGAL = new PerfDataType("illegal",  "X", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static PerfDataType basicTypes[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        LONG, BYTE, BOOLEAN, CHAR, FLOAT, DOUBLE, SHORT, INT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public byte byteValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Maps an integer PerfDataType value to its corresponding PerfDataType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param   i  an integer representation of a PerfDataType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return     The PerfDataType object for <code>i</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static PerfDataType toPerfDataType(byte type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        for (int j = 0; j < basicTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (basicTypes[j].byteValue() == type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                return (basicTypes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return ILLEGAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private PerfDataType(String name, String c, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            byte[] b = c.getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            this.value = b[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            // ignore, "UTF-8" is always a known encoding
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
    96
            throw new InternalError("Unknown encoding", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}