blob: 8b738c58b33311ace88ce8aa94bb876b02146210 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.management.counter.perf;
27
28import java.io.UnsupportedEncodingException;
29
30/**
31 * A typesafe enumeration for the data types supported for
32 * performance data.
33 *
34 * <p> The enumeration values for this typesafe enumeration must be
35 * kept in sychronization with the PerfDataType enum in the
36 * globalsDefinitions.hpp file in the HotSpot source base.</p>
37 *
38 * @author Brian Doherty
39 */
40class PerfDataType {
41
42 private final String name;
43 private final byte value;
44 private final int size;
45
46 public static final PerfDataType BOOLEAN = new PerfDataType("boolean", "Z", 1);
47 public static final PerfDataType CHAR = new PerfDataType("char", "C", 1);
48 public static final PerfDataType FLOAT = new PerfDataType("float", "F", 8);
49 public static final PerfDataType DOUBLE = new PerfDataType("double", "D", 8);
50 public static final PerfDataType BYTE = new PerfDataType("byte", "B", 1);
51 public static final PerfDataType SHORT = new PerfDataType("short", "S", 2);
52 public static final PerfDataType INT = new PerfDataType("int", "I", 4);
53 public static final PerfDataType LONG = new PerfDataType("long", "J", 8);
54 public static final PerfDataType ILLEGAL = new PerfDataType("illegal", "X", 0);
55
56 private static PerfDataType basicTypes[] = {
57 LONG, BYTE, BOOLEAN, CHAR, FLOAT, DOUBLE, SHORT, INT
58 };
59
60 public String toString() {
61 return name;
62 }
63
64 public byte byteValue() {
65 return value;
66 }
67
68 public int size() {
69 return size;
70 }
71
72 /**
73 * Maps an integer PerfDataType value to its corresponding PerfDataType
74 * object.
75 *
76 * @param i an integer representation of a PerfDataType
77 * @return The PerfDataType object for <code>i</code>
78 */
79 public static PerfDataType toPerfDataType(byte type) {
80 for (int j = 0; j < basicTypes.length; j++) {
81 if (basicTypes[j].byteValue() == type) {
82 return (basicTypes[j]);
83 }
84 }
85 return ILLEGAL;
86 }
87
88 private PerfDataType(String name, String c, int size) {
89 this.name = name;
90 this.size = size;
91 try {
92 byte[] b = c.getBytes("UTF-8");
93 this.value = b[0];
94 } catch (UnsupportedEncodingException e) {
95 // ignore, "UTF-8" is always a known encoding
96 throw new InternalError("Unknown encoding");
97 }
98 }
99}