jtulach@144: /* jtulach@144: * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. jtulach@144: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jtulach@144: * jtulach@144: * This code is free software; you can redistribute it and/or modify it jtulach@144: * under the terms of the GNU General Public License version 2 only, as jtulach@144: * published by the Free Software Foundation. Oracle designates this jtulach@144: * particular file as subject to the "Classpath" exception as provided jtulach@144: * by Oracle in the LICENSE file that accompanied this code. jtulach@144: * jtulach@144: * This code is distributed in the hope that it will be useful, but WITHOUT jtulach@144: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jtulach@144: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jtulach@144: * version 2 for more details (a copy is included in the LICENSE file that jtulach@144: * accompanied this code). jtulach@144: * jtulach@144: * You should have received a copy of the GNU General Public License version jtulach@144: * 2 along with this work; if not, write to the Free Software Foundation, jtulach@144: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jtulach@144: * jtulach@144: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jtulach@144: * or visit www.oracle.com if you need additional information or have any jtulach@144: * questions. jtulach@144: */ jtulach@144: jtulach@144: jtulach@144: package sun.tools.javap; jtulach@144: jtulach@144: jtulach@144: jtulach@144: public class Tables implements Constants { jtulach@144: /** jtulach@144: * Define mnemocodes table. jtulach@144: */ jtulach@144: static Hashtable mnemocodes = new Hashtable(301, 0.5f); jtulach@144: static String opcExtNamesTab[]=new String[128]; jtulach@144: static String opcPrivExtNamesTab[]=new String[128]; jtulach@144: static void defineNonPriv(int opc, String mnem) { jtulach@144: mnemocodes.put(opcExtNamesTab[opc]=mnem, new Integer(opc_nonpriv*256+opc)); jtulach@144: } jtulach@144: static void definePriv(int opc, String mnem) { jtulach@144: mnemocodes.put(opcPrivExtNamesTab[opc]="priv_"+mnem, new Integer(opc_priv*256+opc)); jtulach@144: } jtulach@144: static void defineExt(int opc, String mnem) { jtulach@144: defineNonPriv(opc, mnem); jtulach@144: definePriv(opc, mnem); jtulach@144: } jtulach@144: static { int k; jtulach@144: for (k=0; k>8) { jtulach@144: case 0: jtulach@144: return opcLengthsTab[opc]; jtulach@144: case opc_wide: jtulach@144: switch (opc&0xFF) { jtulach@144: case opc_aload: case opc_astore: jtulach@144: case opc_fload: case opc_fstore: jtulach@144: case opc_iload: case opc_istore: jtulach@144: case opc_lload: case opc_lstore: jtulach@144: case opc_dload: case opc_dstore: jtulach@144: case opc_ret: jtulach@144: return 4; jtulach@144: case opc_iinc: jtulach@144: return 6; jtulach@144: default: jtulach@144: throw new ArrayIndexOutOfBoundsException(); jtulach@144: } jtulach@144: case opc_nonpriv: jtulach@144: case opc_priv: jtulach@144: return 2; jtulach@144: default: jtulach@144: throw new ArrayIndexOutOfBoundsException(); jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: public static String opcName(int opc) { jtulach@144: try { jtulach@144: switch (opc>>8) { jtulach@144: case 0: jtulach@144: return opcNamesTab[opc]; jtulach@144: case opc_wide: { jtulach@144: String mnem=opcNamesTab[opc&0xFF]+"_w"; jtulach@144: if (mnemocodes.get(mnem) == null) jtulach@144: return null; // non-existent opcode jtulach@144: return mnem; jtulach@144: } jtulach@144: case opc_nonpriv: jtulach@144: return opcExtNamesTab[opc&0xFF]; jtulach@144: case opc_priv: jtulach@144: return opcPrivExtNamesTab[opc&0xFF]; jtulach@144: default: jtulach@144: return null; jtulach@144: } jtulach@144: } catch (ArrayIndexOutOfBoundsException e) { jtulach@144: switch (opc) { jtulach@144: case opc_nonpriv: jtulach@144: return "nonpriv"; jtulach@144: case opc_priv: jtulach@144: return "priv"; jtulach@144: default: jtulach@144: return null; jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: public static int opcode(String mnem) { jtulach@144: Integer Val=(Integer)(mnemocodes.get(mnem)); jtulach@144: if (Val == null) return -1; jtulach@144: return Val.intValue(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Initialized keyword and token Hashtables jtulach@144: */ jtulach@144: static Vector keywordNames = new Vector(40); jtulach@144: private static void defineKeywordName(String id, int token) { jtulach@144: jtulach@144: if (token>=keywordNames.size()) { jtulach@144: keywordNames.setSize(token+1); jtulach@144: } jtulach@144: keywordNames.setElementAt(id, token); jtulach@144: } jtulach@144: public static String keywordName(int token) { jtulach@144: if (token==-1) return "EOF"; jtulach@144: if (token>=keywordNames.size()) return null; jtulach@144: return (String)keywordNames.elementAt(token); jtulach@144: } jtulach@144: static { jtulach@144: defineKeywordName("ident", IDENT); jtulach@144: defineKeywordName("STRINGVAL", STRINGVAL); jtulach@144: defineKeywordName("intVal", INTVAL); jtulach@144: defineKeywordName("longVal", LONGVAL); jtulach@144: defineKeywordName("floatVal", FLOATVAL); jtulach@144: defineKeywordName("doubleVal", DOUBLEVAL); jtulach@144: defineKeywordName("SEMICOLON", SEMICOLON); jtulach@144: defineKeywordName("COLON", COLON); jtulach@144: defineKeywordName("LBRACE", LBRACE); jtulach@144: defineKeywordName("RBRACE", RBRACE); jtulach@144: } jtulach@144: jtulach@144: static Hashtable keywords = new Hashtable(40); jtulach@144: public static int keyword(String idValue) { jtulach@144: Integer Val=(Integer)(keywords.get(idValue)); jtulach@144: if (Val == null) return IDENT; jtulach@144: return Val.intValue(); jtulach@144: } jtulach@144: jtulach@144: private static void defineKeyword(String id, int token) { jtulach@144: keywords.put(id, new Integer(token)); jtulach@144: defineKeywordName(id, token); jtulach@144: } jtulach@144: static { jtulach@144: // Modifier keywords jtulach@144: defineKeyword("private", PRIVATE); jtulach@144: defineKeyword("public", PUBLIC); jtulach@144: defineKeyword("protected", PROTECTED); jtulach@144: defineKeyword("static", STATIC); jtulach@144: defineKeyword("transient", TRANSIENT); jtulach@144: defineKeyword("synchronized", SYNCHRONIZED); jtulach@144: defineKeyword("super", SUPER); jtulach@144: defineKeyword("native", NATIVE); jtulach@144: defineKeyword("abstract", ABSTRACT); jtulach@144: defineKeyword("volatile", VOLATILE); jtulach@144: defineKeyword("final", FINAL); jtulach@144: defineKeyword("interface",INTERFACE); jtulach@144: defineKeyword("synthetic",SYNTHETIC); jtulach@144: defineKeyword("strict",STRICT); jtulach@144: jtulach@144: // Declaration keywords jtulach@144: defineKeyword("package",PACKAGE); jtulach@144: defineKeyword("class",CLASS); jtulach@144: defineKeyword("extends",EXTENDS); jtulach@144: defineKeyword("implements",IMPLEMENTS); jtulach@144: defineKeyword("const", CONST); jtulach@144: defineKeyword("throws",THROWS); jtulach@144: defineKeyword("interface",INTERFACE); jtulach@144: defineKeyword("Method",METHODREF); jtulach@144: defineKeyword("Field",FIELDREF); jtulach@144: defineKeyword("stack",STACK); jtulach@144: defineKeyword("locals",LOCAL); jtulach@144: jtulach@144: // used in switchtables jtulach@144: defineKeyword("default", DEFAULT); jtulach@144: jtulach@144: // used in inner class declarations jtulach@144: defineKeyword("InnerClass", INNERCLASS); jtulach@144: defineKeyword("of", OF); jtulach@144: jtulach@144: // misc jtulach@144: defineKeyword("bits",BITS); jtulach@144: defineKeyword("Infinity",INF); jtulach@144: defineKeyword("Inf",INF); jtulach@144: defineKeyword("NaN",NAN); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Define tag table. jtulach@144: */ jtulach@144: private static Vector tagNames = new Vector(10); jtulach@144: private static Hashtable Tags = new Hashtable(10); jtulach@144: static { jtulach@144: defineTag("Asciz",CONSTANT_UTF8); jtulach@144: defineTag("int",CONSTANT_INTEGER); jtulach@144: defineTag("float",CONSTANT_FLOAT); jtulach@144: defineTag("long",CONSTANT_LONG); jtulach@144: defineTag("double",CONSTANT_DOUBLE); jtulach@144: defineTag("class",CONSTANT_CLASS); jtulach@144: defineTag("String",CONSTANT_STRING); jtulach@144: defineTag("Field",CONSTANT_FIELD); jtulach@144: defineTag("Method",CONSTANT_METHOD); jtulach@144: defineTag("InterfaceMethod",CONSTANT_INTERFACEMETHOD); jtulach@144: defineTag("NameAndType",CONSTANT_NAMEANDTYPE); jtulach@144: } jtulach@144: private static void defineTag(String id, int val) { jtulach@144: Tags.put(id, new Integer(val)); jtulach@144: if (val>=tagNames.size()) { jtulach@144: tagNames.setSize(val+1); jtulach@144: } jtulach@144: tagNames.setElementAt(id, val); jtulach@144: } jtulach@144: public static String tagName(int tag) { jtulach@144: if (tag>=tagNames.size()) return null; jtulach@144: return (String)tagNames.elementAt(tag); jtulach@144: } jtulach@144: public static int tagValue(String idValue) { jtulach@144: Integer Val=(Integer)(Tags.get(idValue)); jtulach@144: if (Val == null) return 0; jtulach@144: return Val.intValue(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Define type table. These types used in "newarray" instruction only. jtulach@144: */ jtulach@144: private static Vector typeNames = new Vector(10); jtulach@144: private static Hashtable Types = new Hashtable(10); jtulach@144: static { jtulach@144: defineType("int",T_INT); jtulach@144: defineType("long",T_LONG); jtulach@144: defineType("float",T_FLOAT); jtulach@144: defineType("double",T_DOUBLE); jtulach@144: defineType("class",T_CLASS); jtulach@144: defineType("boolean",T_BOOLEAN); jtulach@144: defineType("char",T_CHAR); jtulach@144: defineType("byte",T_BYTE); jtulach@144: defineType("short",T_SHORT); jtulach@144: } jtulach@144: private static void defineType(String id, int val) { jtulach@144: Types.put(id, new Integer(val)); jtulach@144: if (val>=typeNames.size()) { jtulach@144: typeNames.setSize(val+1); jtulach@144: } jtulach@144: typeNames.setElementAt(id, val); jtulach@144: } jtulach@144: public static int typeValue(String idValue) { jtulach@144: Integer Val=(Integer)(Types.get(idValue)); jtulach@144: if (Val == null) return -1; jtulach@144: return Val.intValue(); jtulach@144: } jtulach@144: public static String typeName(int type) { jtulach@144: if (type>=typeNames.size()) return null; jtulach@144: return (String)typeNames.elementAt(type); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Define MapTypes table. jtulach@144: * These constants used in stackmap tables only. jtulach@144: */ jtulach@144: private static Vector mapTypeNames = new Vector(10); jtulach@144: private static Hashtable MapTypes = new Hashtable(10); jtulach@144: static { jtulach@144: defineMapType("bogus", ITEM_Bogus); jtulach@144: defineMapType("int", ITEM_Integer); jtulach@144: defineMapType("float", ITEM_Float); jtulach@144: defineMapType("double", ITEM_Double); jtulach@144: defineMapType("long", ITEM_Long); jtulach@144: defineMapType("null", ITEM_Null); jtulach@144: defineMapType("this", ITEM_InitObject); jtulach@144: defineMapType("CP", ITEM_Object); jtulach@144: defineMapType("uninitialized", ITEM_NewObject); jtulach@144: } jtulach@144: private static void defineMapType(String id, int val) { jtulach@144: MapTypes.put(id, new Integer(val)); jtulach@144: if (val>=mapTypeNames.size()) { jtulach@144: mapTypeNames.setSize(val+1); jtulach@144: } jtulach@144: mapTypeNames.setElementAt(id, val); jtulach@144: } jtulach@144: public static int mapTypeValue(String idValue) { jtulach@144: Integer Val=(Integer)(MapTypes.get(idValue)); jtulach@144: if (Val == null) return -1; jtulach@144: return Val.intValue(); jtulach@144: } jtulach@144: public static String mapTypeName(int type) { jtulach@144: if (type>=mapTypeNames.size()) return null; jtulach@144: return (String)mapTypeNames.elementAt(type); jtulach@144: } jtulach@144: jtulach@144: }