001: /*
002: * @(#)TypeInfo.java 1.2 06/08/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jumpimpl.ixc;
028:
029: import java.util.HashMap;
030:
031: /**
032: * This little utility class is used by StubClassGenerator to hold
033: * information that's relevant to it about types (particularly
034: * primitive types and their wrappers).
035: **/
036: class TypeInfo {
037: String typeDescriptor; // 'L', 'D', ...
038: int localSlots; // Ints take 1 local slot, doubles & longs 2
039: byte loadInstruction; // iload, dload, fload, ...
040: byte returnInstruction; // ireturn, dreturn, ...
041: Class primitiveWrapper; // null for non-primitive
042: String valueMethod; // "intValue(), floatValue(), ..."
043: // A Mapping from the java.lang.Class instance for each primitive
044: // type to some information that relevant to us about these types:
045: private static HashMap primitiveMap;
046: static {
047: primitiveMap = new HashMap();
048: primitiveMap.put(Boolean.TYPE,
049: new TypeInfo("Z", 1, (byte) 0x15, (byte) 0xac,
050: Boolean.class, "booleanValue"));
051: primitiveMap.put(Byte.TYPE, new TypeInfo("B", 1, (byte) 0x15,
052: (byte) 0xac, Byte.class, "byteValue"));
053: primitiveMap
054: .put(Character.TYPE, new TypeInfo("C", 1, (byte) 0x15,
055: (byte) 0xac, Character.class, "charValue"));
056: primitiveMap.put(Integer.TYPE, new TypeInfo("I", 1,
057: (byte) 0x15, (byte) 0xac, Integer.class, "intValue"));
058: primitiveMap.put(Long.TYPE, new TypeInfo("J", 2, (byte) 0x16,
059: (byte) 0xad, Long.class, "longValue"));
060: primitiveMap.put(Short.TYPE, new TypeInfo("S", 1, (byte) 0x15,
061: (byte) 0xac, Short.class, "shortValue"));
062: primitiveMap.put(Float.TYPE, new TypeInfo("F", 1, (byte) 0x17,
063: (byte) 0xae, Float.class, "floatValue"));
064: primitiveMap.put(Double.TYPE, new TypeInfo("D", 2, (byte) 0x18,
065: (byte) 0xaf, Double.class, "doubleValue"));
066: primitiveMap.put(Void.TYPE, new TypeInfo("V", -1, (byte) 0xff,
067: (byte) 0xb1, null, null));
068: }
069:
070: TypeInfo(String typeDescriptor, int localSlots,
071: byte loadInstruction, byte returnInstruction,
072: Class primitiveWrapper, String valueMethod) {
073: this .typeDescriptor = typeDescriptor;
074: this .localSlots = localSlots;
075: this .loadInstruction = loadInstruction;
076: this .returnInstruction = returnInstruction;
077: this .primitiveWrapper = primitiveWrapper;
078: this .valueMethod = valueMethod;
079: }
080:
081: static TypeInfo get(Class type) {
082: return (TypeInfo) primitiveMap.get(type);
083: }
084:
085: static String descriptorFor(Class type) {
086: if (type.isPrimitive()) {
087: return get(type).typeDescriptor;
088: } else if (type.isArray()) {
089: return type.getName().replace('.', '/');
090: } else {
091: return "L" + type.getName().replace('.', '/') + ";";
092: }
093: }
094:
095: static int localSlotsFor(Class type) {
096: if (type.isPrimitive()) {
097: return get(type).localSlots;
098: } else {
099: return 1;
100: }
101: }
102: }
|