1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/javap/src/main/java/org/apidesign/javap/AnnotationParser.java Fri Nov 16 08:08:36 2012 +0100
1.3 @@ -0,0 +1,98 @@
1.4 +/*
1.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +package org.apidesign.javap;
1.29 +
1.30 +import java.io.ByteArrayInputStream;
1.31 +import java.io.DataInputStream;
1.32 +import java.io.IOException;
1.33 +
1.34 +/** An abstract parser for annotation definitions. Analyses the bytes and
1.35 + * performs some callbacks to the overriden parser methods.
1.36 + *
1.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.38 + */
1.39 +public class AnnotationParser {
1.40 + protected AnnotationParser() {
1.41 + }
1.42 +
1.43 + protected void visitAttr(String type, String attr, String value) {
1.44 + }
1.45 +
1.46 + /** Initialize the parsing with constant pool from <code>cd</code>.
1.47 + *
1.48 + * @param attr the attribute defining annotations
1.49 + * @param cd constant pool
1.50 + * @throws IOException in case I/O fails
1.51 + */
1.52 + public final void parse(byte[] attr, ClassData cd) throws IOException {
1.53 + ByteArrayInputStream is = new ByteArrayInputStream(attr);
1.54 + DataInputStream dis = new DataInputStream(is);
1.55 + try {
1.56 + read(dis, cd);
1.57 + } finally {
1.58 + is.close();
1.59 + }
1.60 + }
1.61 +
1.62 + private void read(DataInputStream dis, ClassData cd) throws IOException {
1.63 + int cnt = dis.readUnsignedShort();
1.64 + for (int i = 0; i < cnt; i++) {
1.65 + readAnno(dis, cd);
1.66 + }
1.67 + }
1.68 +
1.69 + private void readAnno(DataInputStream dis, ClassData cd) throws IOException {
1.70 + int type = dis.readUnsignedShort();
1.71 + String typeName = cd.StringValue(type);
1.72 + int cnt = dis.readUnsignedShort();
1.73 + for (int i = 0; i < cnt; i++) {
1.74 + String attrName = cd.StringValue(dis.readUnsignedShort());
1.75 + readValue(dis, cd, typeName, attrName);
1.76 + }
1.77 + }
1.78 +
1.79 + private void readValue(DataInputStream dis, ClassData cd, String typeName, String attrName)
1.80 + throws IOException {
1.81 + char type = (char)dis.readByte();
1.82 + if (type == '@') {
1.83 + readAnno(dis, cd);
1.84 + } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
1.85 + int primitive = dis.readUnsignedShort();
1.86 + visitAttr(typeName, attrName, cd.StringValue(primitive));
1.87 + } else if (type == 'c') {
1.88 + int cls = dis.readUnsignedShort();
1.89 + } else if (type == '[') {
1.90 + int cnt = dis.readUnsignedShort();
1.91 + for (int i = 0; i < cnt; i++) {
1.92 + readValue(dis, cd, typeName, attrName);
1.93 + }
1.94 + } else if (type == 'e') {
1.95 + int enumT = dis.readUnsignedShort();
1.96 + int enumN = dis.readUnsignedShort();
1.97 + } else {
1.98 + throw new IOException("Unknown type " + type);
1.99 + }
1.100 + }
1.101 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/javap/src/main/java/org/apidesign/javap/AttrData.java Fri Nov 16 08:08:36 2012 +0100
2.3 @@ -0,0 +1,77 @@
2.4 +/*
2.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 + *
2.8 + * This code is free software; you can redistribute it and/or modify it
2.9 + * under the terms of the GNU General Public License version 2 only, as
2.10 + * published by the Free Software Foundation. Oracle designates this
2.11 + * particular file as subject to the "Classpath" exception as provided
2.12 + * by Oracle in the LICENSE file that accompanied this code.
2.13 + *
2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.17 + * version 2 for more details (a copy is included in the LICENSE file that
2.18 + * accompanied this code).
2.19 + *
2.20 + * You should have received a copy of the GNU General Public License version
2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.23 + *
2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2.25 + * or visit www.oracle.com if you need additional information or have any
2.26 + * questions.
2.27 + */
2.28 +
2.29 +
2.30 +
2.31 +package org.apidesign.javap;
2.32 +
2.33 +import java.io.*;
2.34 +
2.35 +/**
2.36 + * Reads and stores attribute information.
2.37 + *
2.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
2.39 + */
2.40 +class AttrData {
2.41 + ClassData cls;
2.42 + int name_cpx;
2.43 + int datalen;
2.44 + byte data[];
2.45 +
2.46 + public AttrData (ClassData cls) {
2.47 + this.cls=cls;
2.48 + }
2.49 +
2.50 + /**
2.51 + * Reads unknown attribute.
2.52 + */
2.53 + public void read(int name_cpx, DataInputStream in) throws IOException {
2.54 + this.name_cpx=name_cpx;
2.55 + datalen=in.readInt();
2.56 + data=new byte[datalen];
2.57 + in.readFully(data);
2.58 + }
2.59 +
2.60 + /**
2.61 + * Reads just the name of known attribute.
2.62 + */
2.63 + public void read(int name_cpx){
2.64 + this.name_cpx=name_cpx;
2.65 + }
2.66 +
2.67 + /**
2.68 + * Returns attribute name.
2.69 + */
2.70 + public String getAttrName(){
2.71 + return cls.getString(name_cpx);
2.72 + }
2.73 +
2.74 + /**
2.75 + * Returns attribute data.
2.76 + */
2.77 + public byte[] getData(){
2.78 + return data;
2.79 + }
2.80 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX.java Fri Nov 16 08:08:36 2012 +0100
3.3 @@ -0,0 +1,40 @@
3.4 +/*
3.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.7 + *
3.8 + * This code is free software; you can redistribute it and/or modify it
3.9 + * under the terms of the GNU General Public License version 2 only, as
3.10 + * published by the Free Software Foundation. Oracle designates this
3.11 + * particular file as subject to the "Classpath" exception as provided
3.12 + * by Oracle in the LICENSE file that accompanied this code.
3.13 + *
3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3.17 + * version 2 for more details (a copy is included in the LICENSE file that
3.18 + * accompanied this code).
3.19 + *
3.20 + * You should have received a copy of the GNU General Public License version
3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3.23 + *
3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3.25 + * or visit www.oracle.com if you need additional information or have any
3.26 + * questions.
3.27 + */
3.28 +
3.29 +
3.30 +package org.apidesign.javap;
3.31 +
3.32 +/**
3.33 + * Stores constant pool entry information with one field.
3.34 + *
3.35 + * @author Sucheta Dambalkar (Adopted code from jdis)
3.36 + */
3.37 +class CPX {
3.38 + int cpx;
3.39 +
3.40 + CPX (int cpx) {
3.41 + this.cpx=cpx;
3.42 + }
3.43 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX2.java Fri Nov 16 08:08:36 2012 +0100
4.3 @@ -0,0 +1,41 @@
4.4 +/*
4.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +
4.30 +package org.apidesign.javap;
4.31 +
4.32 +/**
4.33 + * Stores constant pool entry information with two fields.
4.34 + *
4.35 + * @author Sucheta Dambalkar (Adopted code from jdis)
4.36 + */
4.37 +class CPX2 {
4.38 + int cpx1,cpx2;
4.39 +
4.40 + CPX2 (int cpx1, int cpx2) {
4.41 + this.cpx1=cpx1;
4.42 + this.cpx2=cpx2;
4.43 + }
4.44 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/javap/src/main/java/org/apidesign/javap/ClassData.java Fri Nov 16 08:08:36 2012 +0100
5.3 @@ -0,0 +1,718 @@
5.4 +/*
5.5 + * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +
5.30 +package org.apidesign.javap;
5.31 +
5.32 +import java.io.*;
5.33 +
5.34 +/**
5.35 + * Central data repository of the Java Disassembler.
5.36 + * Stores all the information in java class file.
5.37 + *
5.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
5.39 + */
5.40 +public final class ClassData implements RuntimeConstants {
5.41 +
5.42 + private int magic;
5.43 + private int minor_version;
5.44 + private int major_version;
5.45 + private int cpool_count;
5.46 + private Object cpool[];
5.47 + private int access;
5.48 + private int this_class = 0;;
5.49 + private int super_class;
5.50 + private int interfaces_count;
5.51 + private int[] interfaces = new int[0];;
5.52 + private int fields_count;
5.53 + private FieldData[] fields;
5.54 + private int methods_count;
5.55 + private MethodData[] methods;
5.56 + private InnerClassData[] innerClasses;
5.57 + private int attributes_count;
5.58 + private AttrData[] attrs;
5.59 + private String classname;
5.60 + private String superclassname;
5.61 + private int source_cpx=0;
5.62 + private byte tags[];
5.63 + private Hashtable indexHashAscii = new Hashtable();
5.64 + private String pkgPrefix="";
5.65 + private int pkgPrefixLen=0;
5.66 +
5.67 + /**
5.68 + * Read classfile to disassemble.
5.69 + */
5.70 + public ClassData(InputStream infile) throws IOException {
5.71 + this.read(new DataInputStream(infile));
5.72 + }
5.73 +
5.74 + /**
5.75 + * Reads and stores class file information.
5.76 + */
5.77 + public void read(DataInputStream in) throws IOException {
5.78 + // Read the header
5.79 + magic = in.readInt();
5.80 + if (magic != JAVA_MAGIC) {
5.81 + throw new ClassFormatError("wrong magic: " +
5.82 + toHex(magic) + ", expected " +
5.83 + toHex(JAVA_MAGIC));
5.84 + }
5.85 + minor_version = in.readShort();
5.86 + major_version = in.readShort();
5.87 + if (major_version != JAVA_VERSION) {
5.88 + }
5.89 +
5.90 + // Read the constant pool
5.91 + readCP(in);
5.92 + access = in.readUnsignedShort();
5.93 + this_class = in.readUnsignedShort();
5.94 + super_class = in.readUnsignedShort();
5.95 +
5.96 + //Read interfaces.
5.97 + interfaces_count = in.readUnsignedShort();
5.98 + if(interfaces_count > 0){
5.99 + interfaces = new int[interfaces_count];
5.100 + }
5.101 + for (int i = 0; i < interfaces_count; i++) {
5.102 + interfaces[i]=in.readShort();
5.103 + }
5.104 +
5.105 + // Read the fields
5.106 + readFields(in);
5.107 +
5.108 + // Read the methods
5.109 + readMethods(in);
5.110 +
5.111 + // Read the attributes
5.112 + attributes_count = in.readUnsignedShort();
5.113 + attrs=new AttrData[attributes_count];
5.114 + for (int k = 0; k < attributes_count; k++) {
5.115 + int name_cpx=in.readUnsignedShort();
5.116 + if (getTag(name_cpx)==CONSTANT_UTF8
5.117 + && getString(name_cpx).equals("SourceFile")
5.118 + ){ if (in.readInt()!=2)
5.119 + throw new ClassFormatError("invalid attr length");
5.120 + source_cpx=in.readUnsignedShort();
5.121 + AttrData attr=new AttrData(this);
5.122 + attr.read(name_cpx);
5.123 + attrs[k]=attr;
5.124 +
5.125 + } else if (getTag(name_cpx)==CONSTANT_UTF8
5.126 + && getString(name_cpx).equals("InnerClasses")
5.127 + ){ int length=in.readInt();
5.128 + int num=in.readUnsignedShort();
5.129 + if (2+num*8 != length)
5.130 + throw new ClassFormatError("invalid attr length");
5.131 + innerClasses=new InnerClassData[num];
5.132 + for (int j = 0; j < num; j++) {
5.133 + InnerClassData innerClass=new InnerClassData(this);
5.134 + innerClass.read(in);
5.135 + innerClasses[j]=innerClass;
5.136 + }
5.137 + AttrData attr=new AttrData(this);
5.138 + attr.read(name_cpx);
5.139 + attrs[k]=attr;
5.140 + } else {
5.141 + AttrData attr=new AttrData(this);
5.142 + attr.read(name_cpx, in);
5.143 + attrs[k]=attr;
5.144 + }
5.145 + }
5.146 + in.close();
5.147 + } // end ClassData.read()
5.148 +
5.149 + /**
5.150 + * Reads and stores constant pool info.
5.151 + */
5.152 + void readCP(DataInputStream in) throws IOException {
5.153 + cpool_count = in.readUnsignedShort();
5.154 + tags = new byte[cpool_count];
5.155 + cpool = new Object[cpool_count];
5.156 + for (int i = 1; i < cpool_count; i++) {
5.157 + byte tag = in.readByte();
5.158 +
5.159 + switch(tags[i] = tag) {
5.160 + case CONSTANT_UTF8:
5.161 + String str=in.readUTF();
5.162 + indexHashAscii.put(cpool[i] = str, new Integer(i));
5.163 + break;
5.164 + case CONSTANT_INTEGER:
5.165 + cpool[i] = new Integer(in.readInt());
5.166 + break;
5.167 + case CONSTANT_FLOAT:
5.168 + cpool[i] = new Float(in.readFloat());
5.169 + break;
5.170 + case CONSTANT_LONG:
5.171 + cpool[i++] = new Long(in.readLong());
5.172 + break;
5.173 + case CONSTANT_DOUBLE:
5.174 + cpool[i++] = new Double(in.readDouble());
5.175 + break;
5.176 + case CONSTANT_CLASS:
5.177 + case CONSTANT_STRING:
5.178 + cpool[i] = new CPX(in.readUnsignedShort());
5.179 + break;
5.180 +
5.181 + case CONSTANT_FIELD:
5.182 + case CONSTANT_METHOD:
5.183 + case CONSTANT_INTERFACEMETHOD:
5.184 + case CONSTANT_NAMEANDTYPE:
5.185 + cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
5.186 + break;
5.187 +
5.188 + case 0:
5.189 + default:
5.190 + throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
5.191 + }
5.192 + }
5.193 + }
5.194 +
5.195 + /**
5.196 + * Reads and strores field info.
5.197 + */
5.198 + protected void readFields(DataInputStream in) throws IOException {
5.199 + int fields_count = in.readUnsignedShort();
5.200 + fields=new FieldData[fields_count];
5.201 + for (int k = 0; k < fields_count; k++) {
5.202 + FieldData field=new FieldData(this);
5.203 + field.read(in);
5.204 + fields[k]=field;
5.205 + }
5.206 + }
5.207 +
5.208 + /**
5.209 + * Reads and strores Method info.
5.210 + */
5.211 + protected void readMethods(DataInputStream in) throws IOException {
5.212 + int methods_count = in.readUnsignedShort();
5.213 + methods=new MethodData[methods_count];
5.214 + for (int k = 0; k < methods_count ; k++) {
5.215 + MethodData method=new MethodData(this);
5.216 + method.read(in);
5.217 + methods[k]=method;
5.218 + }
5.219 + }
5.220 +
5.221 + /**
5.222 + * get a string
5.223 + */
5.224 + public String getString(int n) {
5.225 + if (n == 0) {
5.226 + return null;
5.227 + } else {
5.228 + return (String)cpool[n];
5.229 + }
5.230 + }
5.231 +
5.232 + /**
5.233 + * get the type of constant given an index
5.234 + */
5.235 + public byte getTag(int n) {
5.236 + try{
5.237 + return tags[n];
5.238 + } catch (ArrayIndexOutOfBoundsException e) {
5.239 + return (byte)100;
5.240 + }
5.241 + }
5.242 +
5.243 + static final String hexString="0123456789ABCDEF";
5.244 +
5.245 + public static char hexTable[]=hexString.toCharArray();
5.246 +
5.247 + static String toHex(long val, int width) {
5.248 + StringBuffer s = new StringBuffer();
5.249 + for (int i=width-1; i>=0; i--)
5.250 + s.append(hexTable[((int)(val>>(4*i)))&0xF]);
5.251 + return "0x"+s.toString();
5.252 + }
5.253 +
5.254 + static String toHex(long val) {
5.255 + int width;
5.256 + for (width=16; width>0; width--) {
5.257 + if ((val>>(width-1)*4)!=0) break;
5.258 + }
5.259 + return toHex(val, width);
5.260 + }
5.261 +
5.262 + static String toHex(int val) {
5.263 + int width;
5.264 + for (width=8; width>0; width--) {
5.265 + if ((val>>(width-1)*4)!=0) break;
5.266 + }
5.267 + return toHex(val, width);
5.268 + }
5.269 +
5.270 + /**
5.271 + * Returns the name of this class.
5.272 + */
5.273 + public String getClassName() {
5.274 + String res=null;
5.275 + if (this_class==0) {
5.276 + return res;
5.277 + }
5.278 + int tcpx;
5.279 + try {
5.280 + if (tags[this_class]!=CONSTANT_CLASS) {
5.281 + return res; //"<CP["+cpx+"] is not a Class> ";
5.282 + }
5.283 + tcpx=((CPX)cpool[this_class]).cpx;
5.284 + } catch (ArrayIndexOutOfBoundsException e) {
5.285 + return res; // "#"+cpx+"// invalid constant pool index";
5.286 + } catch (Throwable e) {
5.287 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.288 + }
5.289 +
5.290 + try {
5.291 + return (String)(cpool[tcpx]);
5.292 + } catch (ArrayIndexOutOfBoundsException e) {
5.293 + return res; // "class #"+scpx+"// invalid constant pool index";
5.294 + } catch (ClassCastException e) {
5.295 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.296 + } catch (Throwable e) {
5.297 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.298 + }
5.299 +
5.300 + }
5.301 +
5.302 + /**
5.303 + * Returns the name of class at perticular index.
5.304 + */
5.305 + public String getClassName(int cpx) {
5.306 + String res="#"+cpx;
5.307 + if (cpx==0) {
5.308 + return res;
5.309 + }
5.310 + int scpx;
5.311 + try {
5.312 + if (tags[cpx]!=CONSTANT_CLASS) {
5.313 + return res; //"<CP["+cpx+"] is not a Class> ";
5.314 + }
5.315 + scpx=((CPX)cpool[cpx]).cpx;
5.316 + } catch (ArrayIndexOutOfBoundsException e) {
5.317 + return res; // "#"+cpx+"// invalid constant pool index";
5.318 + } catch (Throwable e) {
5.319 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.320 + }
5.321 + res="#"+scpx;
5.322 + try {
5.323 + return (String)(cpool[scpx]);
5.324 + } catch (ArrayIndexOutOfBoundsException e) {
5.325 + return res; // "class #"+scpx+"// invalid constant pool index";
5.326 + } catch (ClassCastException e) {
5.327 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.328 + } catch (Throwable e) {
5.329 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.330 + }
5.331 + }
5.332 +
5.333 + /**
5.334 + * Returns true if it is a class
5.335 + */
5.336 + public boolean isClass() {
5.337 + if((access & ACC_INTERFACE) == 0) return true;
5.338 + return false;
5.339 + }
5.340 +
5.341 + /**
5.342 + * Returns true if it is a interface.
5.343 + */
5.344 + public boolean isInterface(){
5.345 + if((access & ACC_INTERFACE) != 0) return true;
5.346 + return false;
5.347 + }
5.348 +
5.349 + /**
5.350 + * Returns true if this member is public, false otherwise.
5.351 + */
5.352 + public boolean isPublic(){
5.353 + return (access & ACC_PUBLIC) != 0;
5.354 + }
5.355 +
5.356 + /**
5.357 + * Returns the access of this class or interface.
5.358 + */
5.359 + public String[] getAccess(){
5.360 + Vector v = new Vector();
5.361 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
5.362 + if ((access & ACC_FINAL) !=0) v.addElement("final");
5.363 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
5.364 + String[] accflags = new String[v.size()];
5.365 + v.copyInto(accflags);
5.366 + return accflags;
5.367 + }
5.368 +
5.369 + /**
5.370 + * Returns list of innerclasses.
5.371 + */
5.372 + public InnerClassData[] getInnerClasses(){
5.373 + return innerClasses;
5.374 + }
5.375 +
5.376 + /**
5.377 + * Returns list of attributes.
5.378 + */
5.379 + final AttrData[] getAttributes(){
5.380 + return attrs;
5.381 + }
5.382 +
5.383 + public byte[] findAnnotationData(boolean classRetention) {
5.384 + String n = classRetention ?
5.385 + "RuntimeInvisibleAnnotations" : // NOI18N
5.386 + "RuntimeVisibleAnnotations"; // NOI18N
5.387 + return findAttr(n, attrs);
5.388 + }
5.389 +
5.390 + /**
5.391 + * Returns true if superbit is set.
5.392 + */
5.393 + public boolean isSuperSet(){
5.394 + if ((access & ACC_SUPER) !=0) return true;
5.395 + return false;
5.396 + }
5.397 +
5.398 + /**
5.399 + * Returns super class name.
5.400 + */
5.401 + public String getSuperClassName(){
5.402 + String res=null;
5.403 + if (super_class==0) {
5.404 + return res;
5.405 + }
5.406 + int scpx;
5.407 + try {
5.408 + if (tags[super_class]!=CONSTANT_CLASS) {
5.409 + return res; //"<CP["+cpx+"] is not a Class> ";
5.410 + }
5.411 + scpx=((CPX)cpool[super_class]).cpx;
5.412 + } catch (ArrayIndexOutOfBoundsException e) {
5.413 + return res; // "#"+cpx+"// invalid constant pool index";
5.414 + } catch (Throwable e) {
5.415 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.416 + }
5.417 +
5.418 + try {
5.419 + return (String)(cpool[scpx]);
5.420 + } catch (ArrayIndexOutOfBoundsException e) {
5.421 + return res; // "class #"+scpx+"// invalid constant pool index";
5.422 + } catch (ClassCastException e) {
5.423 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.424 + } catch (Throwable e) {
5.425 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.426 + }
5.427 + }
5.428 +
5.429 + /**
5.430 + * Returns list of super interfaces.
5.431 + */
5.432 + public String[] getSuperInterfaces(){
5.433 + String interfacenames[] = new String[interfaces.length];
5.434 + int interfacecpx = -1;
5.435 + for(int i = 0; i < interfaces.length; i++){
5.436 + interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
5.437 + interfacenames[i] = (String)(cpool[interfacecpx]);
5.438 + }
5.439 + return interfacenames;
5.440 + }
5.441 +
5.442 + /**
5.443 + * Returns string at prticular constant pool index.
5.444 + */
5.445 + public String getStringValue(int cpoolx) {
5.446 + try {
5.447 + return ((String)cpool[cpoolx]);
5.448 + } catch (ArrayIndexOutOfBoundsException e) {
5.449 + return "//invalid constant pool index:"+cpoolx;
5.450 + } catch (ClassCastException e) {
5.451 + return "//invalid constant pool ref:"+cpoolx;
5.452 + }
5.453 + }
5.454 +
5.455 + /**
5.456 + * Returns list of field info.
5.457 + */
5.458 + public FieldData[] getFields(){
5.459 + return fields;
5.460 + }
5.461 +
5.462 + /**
5.463 + * Returns list of method info.
5.464 + */
5.465 + public MethodData[] getMethods(){
5.466 + return methods;
5.467 + }
5.468 +
5.469 + /**
5.470 + * Returns constant pool entry at that index.
5.471 + */
5.472 + public CPX2 getCpoolEntry(int cpx){
5.473 + return ((CPX2)(cpool[cpx]));
5.474 + }
5.475 +
5.476 + public Object getCpoolEntryobj(int cpx){
5.477 + return (cpool[cpx]);
5.478 + }
5.479 +
5.480 + /**
5.481 + * Returns index of this class.
5.482 + */
5.483 + public int getthis_cpx(){
5.484 + return this_class;
5.485 + }
5.486 +
5.487 + public String TagString (int tag) {
5.488 + String res=Tables.tagName(tag);
5.489 + if (res==null) return "BOGUS_TAG:"+tag;
5.490 + return res;
5.491 + }
5.492 +
5.493 + /**
5.494 + * Returns string at that index.
5.495 + */
5.496 + public String StringValue(int cpx) {
5.497 + return stringValue(cpx, false);
5.498 + }
5.499 + public String stringValue(int cpx, boolean textual) {
5.500 + if (cpx==0) return "#0";
5.501 + int tag;
5.502 + Object x;
5.503 + String suffix="";
5.504 + try {
5.505 + tag=tags[cpx];
5.506 + x=cpool[cpx];
5.507 + } catch (IndexOutOfBoundsException e) {
5.508 + return "<Incorrect CP index:"+cpx+">";
5.509 + }
5.510 +
5.511 + if (x==null) return "<NULL>";
5.512 + switch (tag) {
5.513 + case CONSTANT_UTF8: {
5.514 + if (!textual) {
5.515 + return (String)x;
5.516 + }
5.517 + StringBuilder sb=new StringBuilder();
5.518 + String s=(String)x;
5.519 + for (int k=0; k<s.length(); k++) {
5.520 + char c=s.charAt(k);
5.521 + switch (c) {
5.522 + case '\\': sb.append('\\').append('\\'); break;
5.523 + case '\t': sb.append('\\').append('t'); break;
5.524 + case '\n': sb.append('\\').append('n'); break;
5.525 + case '\r': sb.append('\\').append('r'); break;
5.526 + case '\"': sb.append('\\').append('\"'); break;
5.527 + default: sb.append(c);
5.528 + }
5.529 + }
5.530 + return sb.toString();
5.531 + }
5.532 + case CONSTANT_DOUBLE: {
5.533 + Double d=(Double)x;
5.534 + String sd=d.toString();
5.535 + if (textual) {
5.536 + return sd;
5.537 + }
5.538 + return sd+"d";
5.539 + }
5.540 + case CONSTANT_FLOAT: {
5.541 + Float f=(Float)x;
5.542 + String sf=(f).toString();
5.543 + if (textual) {
5.544 + return sf;
5.545 + }
5.546 + return sf+"f";
5.547 + }
5.548 + case CONSTANT_LONG: {
5.549 + Long ln = (Long)x;
5.550 + if (textual) {
5.551 + return ln.toString();
5.552 + }
5.553 + return ln.toString()+'l';
5.554 + }
5.555 + case CONSTANT_INTEGER: {
5.556 + Integer in = (Integer)x;
5.557 + return in.toString();
5.558 + }
5.559 + case CONSTANT_CLASS:
5.560 + if (textual) {
5.561 + return "new java_lang_Class"; // XXX temporary JS
5.562 + }
5.563 + return javaName(getClassName(cpx));
5.564 + case CONSTANT_STRING:
5.565 + String sv = stringValue(((CPX)x).cpx, textual);
5.566 + if (textual) {
5.567 + return '"' + sv + '"';
5.568 + } else {
5.569 + return sv;
5.570 + }
5.571 + case CONSTANT_FIELD:
5.572 + case CONSTANT_METHOD:
5.573 + case CONSTANT_INTERFACEMETHOD:
5.574 + //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
5.575 + return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
5.576 +
5.577 + case CONSTANT_NAMEANDTYPE:
5.578 + return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
5.579 + default:
5.580 + return "UnknownTag"; //TBD
5.581 + }
5.582 + }
5.583 +
5.584 + /**
5.585 + * Returns resolved java type name.
5.586 + */
5.587 + public String javaName(String name) {
5.588 + if( name==null) return "null";
5.589 + int len=name.length();
5.590 + if (len==0) return "\"\"";
5.591 + int cc='/';
5.592 + fullname: { // xxx/yyy/zzz
5.593 + int cp;
5.594 + for (int k=0; k<len; k += Character.charCount(cp)) {
5.595 + cp=name.codePointAt(k);
5.596 + if (cc=='/') {
5.597 + if (!isJavaIdentifierStart(cp)) break fullname;
5.598 + } else if (cp!='/') {
5.599 + if (!isJavaIdentifierPart(cp)) break fullname;
5.600 + }
5.601 + cc=cp;
5.602 + }
5.603 + return name;
5.604 + }
5.605 + return "\""+name+"\"";
5.606 + }
5.607 +
5.608 + public String getName(int cpx) {
5.609 + String res;
5.610 + try {
5.611 + return javaName((String)cpool[cpx]); //.replace('/','.');
5.612 + } catch (ArrayIndexOutOfBoundsException e) {
5.613 + return "<invalid constant pool index:"+cpx+">";
5.614 + } catch (ClassCastException e) {
5.615 + return "<invalid constant pool ref:"+cpx+">";
5.616 + }
5.617 + }
5.618 +
5.619 + /**
5.620 + * Returns unqualified class name.
5.621 + */
5.622 + public String getShortClassName(int cpx) {
5.623 + String classname=javaName(getClassName(cpx));
5.624 + pkgPrefixLen=classname.lastIndexOf("/")+1;
5.625 + if (pkgPrefixLen!=0) {
5.626 + pkgPrefix=classname.substring(0,pkgPrefixLen);
5.627 + if (classname.startsWith(pkgPrefix)) {
5.628 + return classname.substring(pkgPrefixLen);
5.629 + }
5.630 + }
5.631 + return classname;
5.632 + }
5.633 +
5.634 + /**
5.635 + * Returns source file name.
5.636 + */
5.637 + public String getSourceName(){
5.638 + return getName(source_cpx);
5.639 + }
5.640 +
5.641 + /**
5.642 + * Returns package name.
5.643 + */
5.644 + public String getPkgName(){
5.645 + String classname=getClassName(this_class);
5.646 + pkgPrefixLen=classname.lastIndexOf("/")+1;
5.647 + if (pkgPrefixLen!=0) {
5.648 + pkgPrefix=classname.substring(0,pkgPrefixLen);
5.649 + return("package "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
5.650 + }else return null;
5.651 + }
5.652 +
5.653 + /**
5.654 + * Returns total constant pool entry count.
5.655 + */
5.656 + public int getCpoolCount(){
5.657 + return cpool_count;
5.658 + }
5.659 +
5.660 + public String StringTag(int cpx) {
5.661 + byte tag=0;
5.662 + String str=null;
5.663 + try {
5.664 + if (cpx==0) throw new IndexOutOfBoundsException();
5.665 + tag=tags[cpx];
5.666 + return TagString(tag);
5.667 + } catch (IndexOutOfBoundsException e) {
5.668 + str="Incorrect CP index:"+cpx;
5.669 + }
5.670 + return str;
5.671 + }
5.672 +
5.673 + /**
5.674 + * Returns minor version of class file.
5.675 + */
5.676 + public int getMinor_version(){
5.677 + return minor_version;
5.678 + }
5.679 +
5.680 + /**
5.681 + * Returns major version of class file.
5.682 + */
5.683 + public int getMajor_version(){
5.684 + return major_version;
5.685 + }
5.686 +
5.687 + private boolean isJavaIdentifierStart(int cp) {
5.688 + return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
5.689 + }
5.690 +
5.691 + private boolean isJavaIdentifierPart(int cp) {
5.692 + return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
5.693 + }
5.694 +
5.695 + public String[] getNameAndType(int indx) {
5.696 + return getNameAndType(indx, 0, new String[2]);
5.697 + }
5.698 +
5.699 + private String[] getNameAndType(int indx, int at, String[] arr) {
5.700 + CPX2 c2 = getCpoolEntry(indx);
5.701 + arr[at] = StringValue(c2.cpx1);
5.702 + arr[at + 1] = StringValue(c2.cpx2);
5.703 + return arr;
5.704 + }
5.705 +
5.706 + public String[] getFieldInfoName(int indx) {
5.707 + CPX2 c2 = getCpoolEntry(indx);
5.708 + String[] arr = new String[3];
5.709 + arr[0] = getClassName(c2.cpx1);
5.710 + return getNameAndType(c2.cpx2, 1, arr);
5.711 + }
5.712 +
5.713 + static byte[] findAttr(String n, AttrData[] attrs) {
5.714 + for (AttrData ad : attrs) {
5.715 + if (n.equals(ad.getAttrName())) {
5.716 + return ad.getData();
5.717 + }
5.718 + }
5.719 + return null;
5.720 + }
5.721 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/javap/src/main/java/org/apidesign/javap/Constants.java Fri Nov 16 08:08:36 2012 +0100
6.3 @@ -0,0 +1,372 @@
6.4 +/*
6.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +
6.30 +
6.31 +package org.apidesign.javap;
6.32 +
6.33 +/**
6.34 + * This interface defines constant that are used
6.35 + * throughout the compiler. It inherits from RuntimeConstants,
6.36 + * which is an autogenerated class that contains contstants
6.37 + * defined in the interpreter.
6.38 + */
6.39 +
6.40 +public
6.41 +interface Constants extends RuntimeConstants {
6.42 +
6.43 + /**
6.44 + * End of input
6.45 + */
6.46 + public static final int EOF = -1;
6.47 +
6.48 + /*
6.49 + * Flags
6.50 + */
6.51 + public static final int F_VERBOSE = 1 << 0;
6.52 + public static final int F_DUMP = 1 << 1;
6.53 + public static final int F_WARNINGS = 1 << 2;
6.54 + public static final int F_DEBUG = 1 << 3;
6.55 + public static final int F_OPTIMIZE = 1 << 4;
6.56 + public static final int F_DEPENDENCIES = 1 << 5;
6.57 +
6.58 + /*
6.59 + * Type codes
6.60 + */
6.61 + public static final int TC_BOOLEAN = 0;
6.62 + public static final int TC_BYTE = 1;
6.63 + public static final int TC_CHAR = 2;
6.64 + public static final int TC_SHORT = 3;
6.65 + public static final int TC_INT = 4;
6.66 + public static final int TC_LONG = 5;
6.67 + public static final int TC_FLOAT = 6;
6.68 + public static final int TC_DOUBLE = 7;
6.69 + public static final int TC_NULL = 8;
6.70 + public static final int TC_ARRAY = 9;
6.71 + public static final int TC_CLASS = 10;
6.72 + public static final int TC_VOID = 11;
6.73 + public static final int TC_METHOD = 12;
6.74 + public static final int TC_ERROR = 13;
6.75 +
6.76 + /*
6.77 + * Type Masks
6.78 + */
6.79 + public static final int TM_NULL = 1 << TC_NULL;
6.80 + public static final int TM_VOID = 1 << TC_VOID;
6.81 + public static final int TM_BOOLEAN = 1 << TC_BOOLEAN;
6.82 + public static final int TM_BYTE = 1 << TC_BYTE;
6.83 + public static final int TM_CHAR = 1 << TC_CHAR;
6.84 + public static final int TM_SHORT = 1 << TC_SHORT;
6.85 + public static final int TM_INT = 1 << TC_INT;
6.86 + public static final int TM_LONG = 1 << TC_LONG;
6.87 + public static final int TM_FLOAT = 1 << TC_FLOAT;
6.88 + public static final int TM_DOUBLE = 1 << TC_DOUBLE;
6.89 + public static final int TM_ARRAY = 1 << TC_ARRAY;
6.90 + public static final int TM_CLASS = 1 << TC_CLASS;
6.91 + public static final int TM_METHOD = 1 << TC_METHOD;
6.92 + public static final int TM_ERROR = 1 << TC_ERROR;
6.93 +
6.94 + public static final int TM_INT32 = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
6.95 + public static final int TM_NUM32 = TM_INT32 | TM_FLOAT;
6.96 + public static final int TM_NUM64 = TM_LONG | TM_DOUBLE;
6.97 + public static final int TM_INTEGER = TM_INT32 | TM_LONG;
6.98 + public static final int TM_REAL = TM_FLOAT | TM_DOUBLE;
6.99 + public static final int TM_NUMBER = TM_INTEGER | TM_REAL;
6.100 + public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
6.101 +
6.102 + /*
6.103 + * Class status
6.104 + */
6.105 + public static final int CS_UNDEFINED = 0;
6.106 + public static final int CS_UNDECIDED = 1;
6.107 + public static final int CS_BINARY = 2;
6.108 + public static final int CS_SOURCE = 3;
6.109 + public static final int CS_PARSED = 4;
6.110 + public static final int CS_COMPILED = 5;
6.111 + public static final int CS_NOTFOUND = 6;
6.112 +
6.113 + /*
6.114 + * Attributes
6.115 + */
6.116 + public static final int ATT_ALL = -1;
6.117 + public static final int ATT_CODE = 1;
6.118 +
6.119 + /*
6.120 + * Number of bits used in file offsets
6.121 + */
6.122 + public static final int OFFSETBITS = 19;
6.123 + public static final int MAXFILESIZE = (1 << OFFSETBITS) - 1;
6.124 + public static final int MAXLINENUMBER = (1 << (32 - OFFSETBITS)) - 1;
6.125 +
6.126 + /*
6.127 + * Operators
6.128 + */
6.129 + public final int COMMA = 0;
6.130 + public final int ASSIGN = 1;
6.131 +
6.132 + public final int ASGMUL = 2;
6.133 + public final int ASGDIV = 3;
6.134 + public final int ASGREM = 4;
6.135 + public final int ASGADD = 5;
6.136 + public final int ASGSUB = 6;
6.137 + public final int ASGLSHIFT = 7;
6.138 + public final int ASGRSHIFT = 8;
6.139 + public final int ASGURSHIFT = 9;
6.140 + public final int ASGBITAND = 10;
6.141 + public final int ASGBITOR = 11;
6.142 + public final int ASGBITXOR = 12;
6.143 +
6.144 + public final int COND = 13;
6.145 + public final int OR = 14;
6.146 + public final int AND = 15;
6.147 + public final int BITOR = 16;
6.148 + public final int BITXOR = 17;
6.149 + public final int BITAND = 18;
6.150 + public final int NE = 19;
6.151 + public final int EQ = 20;
6.152 + public final int GE = 21;
6.153 + public final int GT = 22;
6.154 + public final int LE = 23;
6.155 + public final int LT = 24;
6.156 + public final int INSTANCEOF = 25;
6.157 + public final int LSHIFT = 26;
6.158 + public final int RSHIFT = 27;
6.159 + public final int URSHIFT = 28;
6.160 + public final int ADD = 29;
6.161 + public final int SUB = 30;
6.162 + public final int DIV = 31;
6.163 + public final int REM = 32;
6.164 + public final int MUL = 33;
6.165 + public final int CAST = 34; // (x)y
6.166 + public final int POS = 35; // +x
6.167 + public final int NEG = 36; // -x
6.168 + public final int NOT = 37;
6.169 + public final int BITNOT = 38;
6.170 + public final int PREINC = 39; // ++x
6.171 + public final int PREDEC = 40; // --x
6.172 + public final int NEWARRAY = 41;
6.173 + public final int NEWINSTANCE = 42;
6.174 + public final int NEWFROMNAME = 43;
6.175 + public final int POSTINC = 44; // x++
6.176 + public final int POSTDEC = 45; // x--
6.177 + public final int FIELD = 46;
6.178 + public final int METHOD = 47; // x(y)
6.179 + public final int ARRAYACCESS = 48; // x[y]
6.180 + public final int NEW = 49;
6.181 + public final int INC = 50;
6.182 + public final int DEC = 51;
6.183 +
6.184 + public final int CONVERT = 55; // implicit conversion
6.185 + public final int EXPR = 56; // (x)
6.186 + public final int ARRAY = 57; // {x, y, ...}
6.187 + public final int GOTO = 58;
6.188 +
6.189 + /*
6.190 + * Value tokens
6.191 + */
6.192 + public final int IDENT = 60;
6.193 + public final int BOOLEANVAL = 61;
6.194 + public final int BYTEVAL = 62;
6.195 + public final int CHARVAL = 63;
6.196 + public final int SHORTVAL = 64;
6.197 + public final int INTVAL = 65;
6.198 + public final int LONGVAL = 66;
6.199 + public final int FLOATVAL = 67;
6.200 + public final int DOUBLEVAL = 68;
6.201 + public final int STRINGVAL = 69;
6.202 +
6.203 + /*
6.204 + * Type keywords
6.205 + */
6.206 + public final int BYTE = 70;
6.207 + public final int CHAR = 71;
6.208 + public final int SHORT = 72;
6.209 + public final int INT = 73;
6.210 + public final int LONG = 74;
6.211 + public final int FLOAT = 75;
6.212 + public final int DOUBLE = 76;
6.213 + public final int VOID = 77;
6.214 + public final int BOOLEAN = 78;
6.215 +
6.216 + /*
6.217 + * Expression keywords
6.218 + */
6.219 + public final int TRUE = 80;
6.220 + public final int FALSE = 81;
6.221 + public final int THIS = 82;
6.222 + public final int SUPER = 83;
6.223 + public final int NULL = 84;
6.224 +
6.225 + /*
6.226 + * Statement keywords
6.227 + */
6.228 + public final int IF = 90;
6.229 + public final int ELSE = 91;
6.230 + public final int FOR = 92;
6.231 + public final int WHILE = 93;
6.232 + public final int DO = 94;
6.233 + public final int SWITCH = 95;
6.234 + public final int CASE = 96;
6.235 + public final int DEFAULT = 97;
6.236 + public final int BREAK = 98;
6.237 + public final int CONTINUE = 99;
6.238 + public final int RETURN = 100;
6.239 + public final int TRY = 101;
6.240 + public final int CATCH = 102;
6.241 + public final int FINALLY = 103;
6.242 + public final int THROW = 104;
6.243 + public final int STAT = 105;
6.244 + public final int EXPRESSION = 106;
6.245 + public final int DECLARATION = 107;
6.246 + public final int VARDECLARATION = 108;
6.247 +
6.248 + /*
6.249 + * Declaration keywords
6.250 + */
6.251 + public final int IMPORT = 110;
6.252 + public final int CLASS = 111;
6.253 + public final int EXTENDS = 112;
6.254 + public final int IMPLEMENTS = 113;
6.255 + public final int INTERFACE = 114;
6.256 + public final int PACKAGE = 115;
6.257 +
6.258 + /*
6.259 + * Modifier keywords
6.260 + */
6.261 + public final int PRIVATE = 120;
6.262 + public final int PUBLIC = 121;
6.263 + public final int PROTECTED = 122;
6.264 + public final int CONST = 123;
6.265 + public final int STATIC = 124;
6.266 + public final int TRANSIENT = 125;
6.267 + public final int SYNCHRONIZED = 126;
6.268 + public final int NATIVE = 127;
6.269 + public final int FINAL = 128;
6.270 + public final int VOLATILE = 129;
6.271 + public final int ABSTRACT = 130;
6.272 + public final int STRICT = 165;
6.273 +
6.274 + /*
6.275 + * Punctuation
6.276 + */
6.277 + public final int SEMICOLON = 135;
6.278 + public final int COLON = 136;
6.279 + public final int QUESTIONMARK = 137;
6.280 + public final int LBRACE = 138;
6.281 + public final int RBRACE = 139;
6.282 + public final int LPAREN = 140;
6.283 + public final int RPAREN = 141;
6.284 + public final int LSQBRACKET = 142;
6.285 + public final int RSQBRACKET = 143;
6.286 + public final int THROWS = 144;
6.287 +
6.288 + /*
6.289 + * Special tokens
6.290 + */
6.291 + public final int ERROR = 145; // an error
6.292 + public final int COMMENT = 146; // not used anymore.
6.293 + public final int TYPE = 147;
6.294 + public final int LENGTH = 148;
6.295 + public final int INLINERETURN = 149;
6.296 + public final int INLINEMETHOD = 150;
6.297 + public final int INLINENEWINSTANCE = 151;
6.298 +
6.299 + /*
6.300 + * Added for jasm
6.301 + */
6.302 + public final int METHODREF = 152;
6.303 + public final int FIELDREF = 153;
6.304 + public final int STACK = 154;
6.305 + public final int LOCAL = 155;
6.306 + public final int CPINDEX = 156;
6.307 + public final int CPNAME = 157;
6.308 + public final int SIGN = 158;
6.309 + public final int BITS = 159;
6.310 + public final int INF = 160;
6.311 + public final int NAN = 161;
6.312 + public final int INNERCLASS = 162;
6.313 + public final int OF = 163;
6.314 + public final int SYNTHETIC = 164;
6.315 +// last used=165;
6.316 +
6.317 + /*
6.318 + * Operator precedence
6.319 + */
6.320 + public static final int opPrecedence[] = {
6.321 + 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
6.322 + 11, 11, 11, 12, 13, 14, 15, 16, 17, 18,
6.323 + 18, 19, 19, 19, 19, 19, 20, 20, 20, 21,
6.324 + 21, 22, 22, 22, 23, 24, 24, 24, 24, 24,
6.325 + 24, 25, 25, 26, 26, 26, 26, 26, 26
6.326 + };
6.327 +
6.328 + /*
6.329 + * Operator names
6.330 + */
6.331 + public static final String opNames[] = {
6.332 + ",", "=", "*=", "/=", "%=",
6.333 + "+=", "-=", "<<=", ">>=", "<<<=",
6.334 + "&=", "|=", "^=", "?:", "||",
6.335 + "&&", "|", "^", "&", "!=",
6.336 + "==", ">=", ">", "<=", "<",
6.337 + "instanceof", "<<", ">>", "<<<", "+",
6.338 + "-", "/", "%", "*", "cast",
6.339 + "+", "-", "!", "~", "++",
6.340 + "--", "new", "new", "new", "++",
6.341 + "--", "field", "method", "[]", "new",
6.342 + "++", "--", null, null, null,
6.343 +
6.344 + "convert", "expr", "array", "goto", null,
6.345 +
6.346 + "Identifier", "Boolean", "Byte", "Char", "Short",
6.347 + "Integer", "Long", "Float", "Double", "String",
6.348 +
6.349 + "byte", "char", "short", "int", "long",
6.350 + "float", "double", "void", "boolean", null,
6.351 +
6.352 + "true", "false", "this", "super", "null",
6.353 + null, null, null, null, null,
6.354 +
6.355 + "if", "else", "for", "while", "do",
6.356 + "switch", "case", "default", "break", "continue",
6.357 + "return", "try", "catch", "finally", "throw",
6.358 + "stat", "expression", "declaration", "declaration", null,
6.359 +
6.360 + "import", "class", "extends", "implements", "interface",
6.361 + "package", null, null, null, null,
6.362 +
6.363 + "private", "public", "protected", "const", "static",
6.364 + "transient", "synchronized", "native", "final", "volatile",
6.365 + "abstract", null, null, null, null,
6.366 +
6.367 + ";", ":", "?", "{", "}",
6.368 + "(", ")", "[", "]", "throws",
6.369 + "error", "comment", "type", "length", "inline-return",
6.370 + "inline-method", "inline-new",
6.371 + "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
6.372 + "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
6.373 + };
6.374 +
6.375 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/javap/src/main/java/org/apidesign/javap/FieldData.java Fri Nov 16 08:08:36 2012 +0100
7.3 @@ -0,0 +1,167 @@
7.4 +/*
7.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +
7.30 +package org.apidesign.javap;
7.31 +
7.32 +import java.util.*;
7.33 +import java.io.*;
7.34 +
7.35 +/**
7.36 + * Strores field data informastion.
7.37 + *
7.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
7.39 + */
7.40 +
7.41 +public class FieldData implements RuntimeConstants {
7.42 +
7.43 + ClassData cls;
7.44 + int access;
7.45 + int name_index;
7.46 + int descriptor_index;
7.47 + int attributes_count;
7.48 + int value_cpx=0;
7.49 + boolean isSynthetic=false;
7.50 + boolean isDeprecated=false;
7.51 + Vector attrs;
7.52 +
7.53 + public FieldData(ClassData cls){
7.54 + this.cls=cls;
7.55 + }
7.56 +
7.57 + /**
7.58 + * Read and store field info.
7.59 + */
7.60 + public void read(DataInputStream in) throws IOException {
7.61 + access = in.readUnsignedShort();
7.62 + name_index = in.readUnsignedShort();
7.63 + descriptor_index = in.readUnsignedShort();
7.64 + // Read the attributes
7.65 + int attributes_count = in.readUnsignedShort();
7.66 + attrs=new Vector(attributes_count);
7.67 + for (int i = 0; i < attributes_count; i++) {
7.68 + int attr_name_index=in.readUnsignedShort();
7.69 + if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
7.70 + String attr_name=cls.getString(attr_name_index);
7.71 + if (attr_name.equals("ConstantValue")){
7.72 + if (in.readInt()!=2)
7.73 + throw new ClassFormatError("invalid ConstantValue attr length");
7.74 + value_cpx=in.readUnsignedShort();
7.75 + AttrData attr=new AttrData(cls);
7.76 + attr.read(attr_name_index);
7.77 + attrs.addElement(attr);
7.78 + } else if (attr_name.equals("Synthetic")){
7.79 + if (in.readInt()!=0)
7.80 + throw new ClassFormatError("invalid Synthetic attr length");
7.81 + isSynthetic=true;
7.82 + AttrData attr=new AttrData(cls);
7.83 + attr.read(attr_name_index);
7.84 + attrs.addElement(attr);
7.85 + } else if (attr_name.equals("Deprecated")){
7.86 + if (in.readInt()!=0)
7.87 + throw new ClassFormatError("invalid Synthetic attr length");
7.88 + isDeprecated = true;
7.89 + AttrData attr=new AttrData(cls);
7.90 + attr.read(attr_name_index);
7.91 + attrs.addElement(attr);
7.92 + } else {
7.93 + AttrData attr=new AttrData(cls);
7.94 + attr.read(attr_name_index, in);
7.95 + attrs.addElement(attr);
7.96 + }
7.97 + }
7.98 +
7.99 + } // end read
7.100 +
7.101 + public boolean isStatic() {
7.102 + return (access & ACC_STATIC) != 0;
7.103 + }
7.104 +
7.105 + /**
7.106 + * Returns access of a field.
7.107 + */
7.108 + public String[] getAccess(){
7.109 + Vector v = new Vector();
7.110 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
7.111 + if ((access & ACC_PRIVATE) !=0) v.addElement("private");
7.112 + if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
7.113 + if ((access & ACC_STATIC) !=0) v.addElement("static");
7.114 + if ((access & ACC_FINAL) !=0) v.addElement("final");
7.115 + if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
7.116 + if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
7.117 + String[] accflags = new String[v.size()];
7.118 + v.copyInto(accflags);
7.119 + return accflags;
7.120 + }
7.121 +
7.122 + /**
7.123 + * Returns name of a field.
7.124 + */
7.125 + public String getName(){
7.126 + return cls.getStringValue(name_index);
7.127 + }
7.128 +
7.129 + /**
7.130 + * Returns internal signature of a field
7.131 + */
7.132 + public String getInternalSig(){
7.133 + return cls.getStringValue(descriptor_index);
7.134 + }
7.135 +
7.136 + /**
7.137 + * Returns java type signature of a field.
7.138 + */
7.139 + public String getType(){
7.140 + return new TypeSignature(getInternalSig()).getFieldType();
7.141 + }
7.142 +
7.143 + /**
7.144 + * Returns true if field is synthetic.
7.145 + */
7.146 + public boolean isSynthetic(){
7.147 + return isSynthetic;
7.148 + }
7.149 +
7.150 + /**
7.151 + * Returns true if field is deprecated.
7.152 + */
7.153 + public boolean isDeprecated(){
7.154 + return isDeprecated;
7.155 + }
7.156 +
7.157 + /**
7.158 + * Returns index of constant value in cpool.
7.159 + */
7.160 + public int getConstantValueIndex(){
7.161 + return (value_cpx);
7.162 + }
7.163 +
7.164 + /**
7.165 + * Returns list of attributes of field.
7.166 + */
7.167 + public Vector getAttributes(){
7.168 + return attrs;
7.169 + }
7.170 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/javap/src/main/java/org/apidesign/javap/Hashtable.java Fri Nov 16 08:08:36 2012 +0100
8.3 @@ -0,0 +1,81 @@
8.4 +/*
8.5 + * To change this template, choose Tools | Templates
8.6 + * and open the template in the editor.
8.7 + */
8.8 +package org.apidesign.javap;
8.9 +
8.10 +/** A JavaScript optimized replacement for Hashtable.
8.11 + *
8.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
8.13 + */
8.14 +final class Hashtable {
8.15 + private Object[] keys;
8.16 + private Object[] values;
8.17 +
8.18 + Hashtable(int i) {
8.19 + this();
8.20 + }
8.21 +
8.22 + Hashtable(int i, double d) {
8.23 + this();
8.24 + }
8.25 +
8.26 + Hashtable() {
8.27 + }
8.28 +
8.29 + synchronized void put(Object key, Object val) {
8.30 + int[] where = { -1, -1 };
8.31 + Object found = get(key, where);
8.32 + if (where[0] != -1) {
8.33 + // key exists
8.34 + values[where[0]] = val;
8.35 + } else {
8.36 + if (where[1] != -1) {
8.37 + // null found
8.38 + keys[where[1]] = key;
8.39 + values[where[1]] = val;
8.40 + } else {
8.41 + if (keys == null) {
8.42 + keys = new Object[11];
8.43 + values = new Object[11];
8.44 + keys[0] = key;
8.45 + values[0] = val;
8.46 + } else {
8.47 + Object[] newKeys = new Object[keys.length * 2];
8.48 + Object[] newValues = new Object[values.length * 2];
8.49 + for (int i = 0; i < keys.length; i++) {
8.50 + newKeys[i] = keys[i];
8.51 + newValues[i] = values[i];
8.52 + }
8.53 + newKeys[keys.length] = key;
8.54 + newValues[keys.length] = val;
8.55 + keys = newKeys;
8.56 + values = newValues;
8.57 + }
8.58 + }
8.59 + }
8.60 + }
8.61 +
8.62 + Object get(Object key) {
8.63 + return get(key, null);
8.64 + }
8.65 + private synchronized Object get(Object key, int[] foundAndNull) {
8.66 + if (keys == null) {
8.67 + return null;
8.68 + }
8.69 + for (int i = 0; i < keys.length; i++) {
8.70 + if (keys[i] == null) {
8.71 + if (foundAndNull != null) {
8.72 + foundAndNull[1] = i;
8.73 + }
8.74 + } else if (keys[i].equals(key)) {
8.75 + if (foundAndNull != null) {
8.76 + foundAndNull[0] = i;
8.77 + }
8.78 + return values[i];
8.79 + }
8.80 + }
8.81 + return null;
8.82 + }
8.83 +
8.84 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/javap/src/main/java/org/apidesign/javap/InnerClassData.java Fri Nov 16 08:08:36 2012 +0100
9.3 @@ -0,0 +1,75 @@
9.4 +/*
9.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9.7 + *
9.8 + * This code is free software; you can redistribute it and/or modify it
9.9 + * under the terms of the GNU General Public License version 2 only, as
9.10 + * published by the Free Software Foundation. Oracle designates this
9.11 + * particular file as subject to the "Classpath" exception as provided
9.12 + * by Oracle in the LICENSE file that accompanied this code.
9.13 + *
9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.17 + * version 2 for more details (a copy is included in the LICENSE file that
9.18 + * accompanied this code).
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License version
9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.23 + *
9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9.25 + * or visit www.oracle.com if you need additional information or have any
9.26 + * questions.
9.27 + */
9.28 +
9.29 +
9.30 +package org.apidesign.javap;
9.31 +
9.32 +import java.io.*;
9.33 +import java.util.*;
9.34 +
9.35 +/**
9.36 + * Strores InnerClass data informastion.
9.37 + *
9.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
9.39 + */
9.40 +class InnerClassData implements RuntimeConstants {
9.41 + ClassData cls;
9.42 +
9.43 +
9.44 + int inner_class_info_index
9.45 + ,outer_class_info_index
9.46 + ,inner_name_index
9.47 + ,access
9.48 + ;
9.49 +
9.50 + public InnerClassData(ClassData cls) {
9.51 + this.cls=cls;
9.52 +
9.53 + }
9.54 +
9.55 + /**
9.56 + * Read Innerclass attribute data.
9.57 + */
9.58 + public void read(DataInputStream in) throws IOException {
9.59 + inner_class_info_index = in.readUnsignedShort();
9.60 + outer_class_info_index = in.readUnsignedShort();
9.61 + inner_name_index = in.readUnsignedShort();
9.62 + access = in.readUnsignedShort();
9.63 + } // end read
9.64 +
9.65 + /**
9.66 + * Returns the access of this class or interface.
9.67 + */
9.68 + public String[] getAccess(){
9.69 + Vector v = new Vector();
9.70 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
9.71 + if ((access & ACC_FINAL) !=0) v.addElement("final");
9.72 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
9.73 + String[] accflags = new String[v.size()];
9.74 + v.copyInto(accflags);
9.75 + return accflags;
9.76 + }
9.77 +
9.78 +} // end InnerClassData
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/javap/src/main/java/org/apidesign/javap/LineNumData.java Fri Nov 16 08:08:36 2012 +0100
10.3 @@ -0,0 +1,50 @@
10.4 +/*
10.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Oracle designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Oracle in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 + * or visit www.oracle.com if you need additional information or have any
10.26 + * questions.
10.27 + */
10.28 +
10.29 +
10.30 +package org.apidesign.javap;
10.31 +
10.32 +import java.util.*;
10.33 +import java.io.*;
10.34 +
10.35 +/**
10.36 + * Strores LineNumberTable data information.
10.37 + *
10.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
10.39 + */
10.40 +class LineNumData {
10.41 + short start_pc, line_number;
10.42 +
10.43 + public LineNumData() {}
10.44 +
10.45 + /**
10.46 + * Read LineNumberTable attribute.
10.47 + */
10.48 + public LineNumData(DataInputStream in) throws IOException {
10.49 + start_pc = in.readShort();
10.50 + line_number=in.readShort();
10.51 +
10.52 + }
10.53 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/javap/src/main/java/org/apidesign/javap/LocVarData.java Fri Nov 16 08:08:36 2012 +0100
11.3 @@ -0,0 +1,54 @@
11.4 +/*
11.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Oracle designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Oracle in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 + * or visit www.oracle.com if you need additional information or have any
11.26 + * questions.
11.27 + */
11.28 +
11.29 +
11.30 +package org.apidesign.javap;
11.31 +
11.32 +import java.util.*;
11.33 +import java.io.*;
11.34 +
11.35 +/**
11.36 + * Strores LocalVariableTable data information.
11.37 + *
11.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
11.39 + */
11.40 +class LocVarData {
11.41 + short start_pc, length, name_cpx, sig_cpx, slot;
11.42 +
11.43 + public LocVarData() {
11.44 + }
11.45 +
11.46 + /**
11.47 + * Read LocalVariableTable attribute.
11.48 + */
11.49 + public LocVarData(DataInputStream in) throws IOException {
11.50 + start_pc = in.readShort();
11.51 + length=in.readShort();
11.52 + name_cpx=in.readShort();
11.53 + sig_cpx=in.readShort();
11.54 + slot=in.readShort();
11.55 +
11.56 + }
11.57 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/javap/src/main/java/org/apidesign/javap/MethodData.java Fri Nov 16 08:08:36 2012 +0100
12.3 @@ -0,0 +1,425 @@
12.4 +/*
12.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.7 + *
12.8 + * This code is free software; you can redistribute it and/or modify it
12.9 + * under the terms of the GNU General Public License version 2 only, as
12.10 + * published by the Free Software Foundation. Oracle designates this
12.11 + * particular file as subject to the "Classpath" exception as provided
12.12 + * by Oracle in the LICENSE file that accompanied this code.
12.13 + *
12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.17 + * version 2 for more details (a copy is included in the LICENSE file that
12.18 + * accompanied this code).
12.19 + *
12.20 + * You should have received a copy of the GNU General Public License version
12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.23 + *
12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.25 + * or visit www.oracle.com if you need additional information or have any
12.26 + * questions.
12.27 + */
12.28 +
12.29 +package org.apidesign.javap;
12.30 +
12.31 +import java.io.*;
12.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
12.33 +
12.34 +import static org.apidesign.javap.RuntimeConstants.*;
12.35 +
12.36 +/**
12.37 + * Strores method data informastion.
12.38 + *
12.39 + * @author Sucheta Dambalkar (Adopted code from jdis)
12.40 + */
12.41 +public class MethodData {
12.42 +
12.43 + ClassData cls;
12.44 + int access;
12.45 + int name_index;
12.46 + int descriptor_index;
12.47 + int attributes_count;
12.48 + byte[] code;
12.49 + Vector exception_table = new Vector(0);
12.50 + Vector lin_num_tb = new Vector(0);
12.51 + Vector loc_var_tb = new Vector(0);
12.52 + StackMapTableData[] stackMapTable;
12.53 + StackMapData[] stackMap;
12.54 + int[] exc_index_table=null;
12.55 + Vector attrs=new Vector(0);
12.56 + Vector code_attrs=new Vector(0);
12.57 + int max_stack, max_locals;
12.58 + boolean isSynthetic=false;
12.59 + boolean isDeprecated=false;
12.60 +
12.61 + public MethodData(ClassData cls){
12.62 + this.cls=cls;
12.63 + }
12.64 +
12.65 + /**
12.66 + * Read method info.
12.67 + */
12.68 + public void read(DataInputStream in) throws IOException {
12.69 + access = in.readUnsignedShort();
12.70 + name_index=in.readUnsignedShort();
12.71 + descriptor_index =in.readUnsignedShort();
12.72 + int attributes_count = in.readUnsignedShort();
12.73 + for (int i = 0; i < attributes_count; i++) {
12.74 + int attr_name_index=in.readUnsignedShort();
12.75 +
12.76 + readAttr: {
12.77 + if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
12.78 + String attr_name=cls.getString(attr_name_index);
12.79 + if ( attr_name.equals("Code")){
12.80 + readCode (in);
12.81 + AttrData attr=new AttrData(cls);
12.82 + attr.read(attr_name_index);
12.83 + attrs.addElement(attr);
12.84 + break readAttr;
12.85 + } else if ( attr_name.equals("Exceptions")){
12.86 + readExceptions(in);
12.87 + AttrData attr=new AttrData(cls);
12.88 + attr.read(attr_name_index);
12.89 + attrs.addElement(attr);
12.90 + break readAttr;
12.91 + } else if (attr_name.equals("Synthetic")){
12.92 + if (in.readInt()!=0)
12.93 + throw new ClassFormatError("invalid Synthetic attr length");
12.94 + isSynthetic=true;
12.95 + AttrData attr=new AttrData(cls);
12.96 + attr.read(attr_name_index);
12.97 + attrs.addElement(attr);
12.98 + break readAttr;
12.99 + } else if (attr_name.equals("Deprecated")){
12.100 + if (in.readInt()!=0)
12.101 + throw new ClassFormatError("invalid Synthetic attr length");
12.102 + isDeprecated = true;
12.103 + AttrData attr=new AttrData(cls);
12.104 + attr.read(attr_name_index);
12.105 + attrs.addElement(attr);
12.106 + break readAttr;
12.107 + }
12.108 + }
12.109 + AttrData attr=new AttrData(cls);
12.110 + attr.read(attr_name_index, in);
12.111 + attrs.addElement(attr);
12.112 + }
12.113 + }
12.114 + }
12.115 +
12.116 + /**
12.117 + * Read code attribute info.
12.118 + */
12.119 + public void readCode(DataInputStream in) throws IOException {
12.120 +
12.121 + int attr_length = in.readInt();
12.122 + max_stack=in.readUnsignedShort();
12.123 + max_locals=in.readUnsignedShort();
12.124 + int codelen=in.readInt();
12.125 +
12.126 + code=new byte[codelen];
12.127 + int totalread = 0;
12.128 + while(totalread < codelen){
12.129 + totalread += in.read(code, totalread, codelen-totalread);
12.130 + }
12.131 + // in.read(code, 0, codelen);
12.132 + int clen = 0;
12.133 + readExceptionTable(in);
12.134 + int code_attributes_count = in.readUnsignedShort();
12.135 +
12.136 + for (int k = 0 ; k < code_attributes_count ; k++) {
12.137 + int table_name_index=in.readUnsignedShort();
12.138 + int table_name_tag=cls.getTag(table_name_index);
12.139 + AttrData attr=new AttrData(cls);
12.140 + if (table_name_tag==CONSTANT_UTF8) {
12.141 + String table_name_tstr=cls.getString(table_name_index);
12.142 + if (table_name_tstr.equals("LineNumberTable")) {
12.143 + readLineNumTable(in);
12.144 + attr.read(table_name_index);
12.145 + } else if (table_name_tstr.equals("LocalVariableTable")) {
12.146 + readLocVarTable(in);
12.147 + attr.read(table_name_index);
12.148 + } else if (table_name_tstr.equals("StackMapTable")) {
12.149 + readStackMapTable(in);
12.150 + attr.read(table_name_index);
12.151 + } else if (table_name_tstr.equals("StackMap")) {
12.152 + readStackMap(in);
12.153 + attr.read(table_name_index);
12.154 + } else {
12.155 + attr.read(table_name_index, in);
12.156 + }
12.157 + code_attrs.addElement(attr);
12.158 + continue;
12.159 + }
12.160 +
12.161 + attr.read(table_name_index, in);
12.162 + code_attrs.addElement(attr);
12.163 + }
12.164 + }
12.165 +
12.166 + /**
12.167 + * Read exception table info.
12.168 + */
12.169 + void readExceptionTable (DataInputStream in) throws IOException {
12.170 + int exception_table_len=in.readUnsignedShort();
12.171 + exception_table=new Vector(exception_table_len);
12.172 + for (int l = 0; l < exception_table_len; l++) {
12.173 + exception_table.addElement(new TrapData(in, l));
12.174 + }
12.175 + }
12.176 +
12.177 + /**
12.178 + * Read LineNumberTable attribute info.
12.179 + */
12.180 + void readLineNumTable (DataInputStream in) throws IOException {
12.181 + int attr_len = in.readInt(); // attr_length
12.182 + int lin_num_tb_len = in.readUnsignedShort();
12.183 + lin_num_tb=new Vector(lin_num_tb_len);
12.184 + for (int l = 0; l < lin_num_tb_len; l++) {
12.185 + lin_num_tb.addElement(new LineNumData(in));
12.186 + }
12.187 + }
12.188 +
12.189 + /**
12.190 + * Read LocalVariableTable attribute info.
12.191 + */
12.192 + void readLocVarTable (DataInputStream in) throws IOException {
12.193 + int attr_len=in.readInt(); // attr_length
12.194 + int loc_var_tb_len = in.readUnsignedShort();
12.195 + loc_var_tb = new Vector(loc_var_tb_len);
12.196 + for (int l = 0; l < loc_var_tb_len; l++) {
12.197 + loc_var_tb.addElement(new LocVarData(in));
12.198 + }
12.199 + }
12.200 +
12.201 + /**
12.202 + * Read Exception attribute info.
12.203 + */
12.204 + public void readExceptions(DataInputStream in) throws IOException {
12.205 + int attr_len=in.readInt(); // attr_length in prog
12.206 + int num_exceptions = in.readUnsignedShort();
12.207 + exc_index_table=new int[num_exceptions];
12.208 + for (int l = 0; l < num_exceptions; l++) {
12.209 + int exc=in.readShort();
12.210 + exc_index_table[l]=exc;
12.211 + }
12.212 + }
12.213 +
12.214 + /**
12.215 + * Read StackMapTable attribute info.
12.216 + */
12.217 + void readStackMapTable(DataInputStream in) throws IOException {
12.218 + int attr_len = in.readInt(); //attr_length
12.219 + int stack_map_tb_len = in.readUnsignedShort();
12.220 + stackMapTable = new StackMapTableData[stack_map_tb_len];
12.221 + for (int i=0; i<stack_map_tb_len; i++) {
12.222 + stackMapTable[i] = StackMapTableData.getInstance(in, this);
12.223 + }
12.224 + }
12.225 +
12.226 + /**
12.227 + * Read StackMap attribute info.
12.228 + */
12.229 + void readStackMap(DataInputStream in) throws IOException {
12.230 + int attr_len = in.readInt(); //attr_length
12.231 + int stack_map_len = in.readUnsignedShort();
12.232 + stackMap = new StackMapData[stack_map_len];
12.233 + for (int i = 0; i<stack_map_len; i++) {
12.234 + stackMap[i] = new StackMapData(in, this);
12.235 + }
12.236 + }
12.237 +
12.238 + /**
12.239 + * Return access of the method.
12.240 + */
12.241 + public String[] getAccess(){
12.242 +
12.243 + Vector v = new Vector();
12.244 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
12.245 + if ((access & ACC_PRIVATE) !=0) v.addElement("private");
12.246 + if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
12.247 + if ((access & ACC_STATIC) !=0) v.addElement("static");
12.248 + if ((access & ACC_FINAL) !=0) v.addElement("final");
12.249 + if ((access & ACC_SYNCHRONIZED) !=0) v.addElement("synchronized");
12.250 + if ((access & ACC_NATIVE) !=0) v.addElement("native");
12.251 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
12.252 + if ((access & ACC_STRICT) !=0) v.addElement("strictfp");
12.253 +
12.254 + String[] accflags = new String[v.size()];
12.255 + v.copyInto(accflags);
12.256 + return accflags;
12.257 + }
12.258 +
12.259 + /**
12.260 + * Return name of the method.
12.261 + */
12.262 + public String getName(){
12.263 + return cls.getStringValue(name_index);
12.264 + }
12.265 +
12.266 + /**
12.267 + * Return internal siganature of the method.
12.268 + */
12.269 + public String getInternalSig(){
12.270 + return cls.getStringValue(descriptor_index);
12.271 + }
12.272 +
12.273 + /**
12.274 + * Return java return type signature of method.
12.275 + */
12.276 + public String getReturnType(){
12.277 +
12.278 + String rttype = (new TypeSignature(getInternalSig())).getReturnType();
12.279 + return rttype;
12.280 + }
12.281 +
12.282 + /**
12.283 + * Return java type parameter signature.
12.284 + */
12.285 + public String getParameters(){
12.286 + String ptype = (new TypeSignature(getInternalSig())).getParameters();
12.287 +
12.288 + return ptype;
12.289 + }
12.290 +
12.291 + /**
12.292 + * Return code attribute data of a method.
12.293 + */
12.294 + public byte[] getCode(){
12.295 + return code;
12.296 + }
12.297 +
12.298 + /**
12.299 + * Return LineNumberTable size.
12.300 + */
12.301 + public int getnumlines(){
12.302 + return lin_num_tb.size();
12.303 + }
12.304 +
12.305 + /**
12.306 + * Return LineNumberTable
12.307 + */
12.308 + public Vector getlin_num_tb(){
12.309 + return lin_num_tb;
12.310 + }
12.311 +
12.312 + /**
12.313 + * Return LocalVariableTable size.
12.314 + */
12.315 + public int getloc_var_tbsize(){
12.316 + return loc_var_tb.size();
12.317 + }
12.318 +
12.319 +
12.320 + /**
12.321 + * Return LocalVariableTable.
12.322 + */
12.323 + public Vector getloc_var_tb(){
12.324 + return loc_var_tb;
12.325 + }
12.326 +
12.327 + /**
12.328 + * Return StackMap.
12.329 + */
12.330 + public StackMapData[] getStackMap() {
12.331 + return stackMap;
12.332 + }
12.333 +
12.334 + /**
12.335 + * Return StackMapTable.
12.336 + */
12.337 + public StackMapTableData[] getStackMapTable() {
12.338 + return stackMapTable;
12.339 + }
12.340 +
12.341 + /**
12.342 + * Return number of arguments of that method.
12.343 + */
12.344 + public int getArgumentlength(){
12.345 + return new TypeSignature(getInternalSig()).getArgumentlength();
12.346 + }
12.347 +
12.348 + /**
12.349 + * Return true if method is static
12.350 + */
12.351 + public boolean isStatic(){
12.352 + if ((access & ACC_STATIC) !=0) return true;
12.353 + return false;
12.354 + }
12.355 +
12.356 +
12.357 + /**
12.358 + * Return max depth of operand stack.
12.359 + */
12.360 + public int getMaxStack(){
12.361 + return max_stack;
12.362 + }
12.363 +
12.364 +
12.365 + /**
12.366 + * Return number of local variables.
12.367 + */
12.368 + public int getMaxLocals(){
12.369 + return max_locals;
12.370 + }
12.371 +
12.372 +
12.373 + /**
12.374 + * Return exception index table in Exception attribute.
12.375 + */
12.376 + public int []get_exc_index_table(){
12.377 + return exc_index_table;
12.378 + }
12.379 +
12.380 +
12.381 + /**
12.382 + * Return exception table in code attributre.
12.383 + */
12.384 + public Vector getexception_table(){
12.385 + return exception_table;
12.386 + }
12.387 +
12.388 +
12.389 + /**
12.390 + * Return method attributes.
12.391 + */
12.392 + public Vector getAttributes(){
12.393 + return attrs;
12.394 + }
12.395 +
12.396 +
12.397 + /**
12.398 + * Return code attributes.
12.399 + */
12.400 + public Vector getCodeAttributes(){
12.401 + return code_attrs;
12.402 + }
12.403 +
12.404 +
12.405 + /**
12.406 + * Return true if method id synthetic.
12.407 + */
12.408 + public boolean isSynthetic(){
12.409 + return isSynthetic;
12.410 + }
12.411 +
12.412 +
12.413 + /**
12.414 + * Return true if method is deprecated.
12.415 + */
12.416 + public boolean isDeprecated(){
12.417 + return isDeprecated;
12.418 + }
12.419 +
12.420 + public byte[] findAnnotationData(boolean classRetention) {
12.421 + String n = classRetention ?
12.422 + "RuntimeInvisibleAnnotations" : // NOI18N
12.423 + "RuntimeVisibleAnnotations"; // NOI18N
12.424 + AttrData[] arr = new AttrData[attrs.size()];
12.425 + attrs.copyInto(arr);
12.426 + return ClassData.findAttr(n, arr);
12.427 + }
12.428 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/javap/src/main/java/org/apidesign/javap/RuntimeConstants.java Fri Nov 16 08:08:36 2012 +0100
13.3 @@ -0,0 +1,787 @@
13.4 +/*
13.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.7 + *
13.8 + * This code is free software; you can redistribute it and/or modify it
13.9 + * under the terms of the GNU General Public License version 2 only, as
13.10 + * published by the Free Software Foundation. Oracle designates this
13.11 + * particular file as subject to the "Classpath" exception as provided
13.12 + * by Oracle in the LICENSE file that accompanied this code.
13.13 + *
13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.17 + * version 2 for more details (a copy is included in the LICENSE file that
13.18 + * accompanied this code).
13.19 + *
13.20 + * You should have received a copy of the GNU General Public License version
13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13.23 + *
13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13.25 + * or visit www.oracle.com if you need additional information or have any
13.26 + * questions.
13.27 + */
13.28 +
13.29 +
13.30 +package org.apidesign.javap;
13.31 +
13.32 +public interface RuntimeConstants {
13.33 +
13.34 + /* Signature Characters */
13.35 + public static final char SIGC_VOID = 'V';
13.36 + public static final String SIG_VOID = "V";
13.37 + public static final char SIGC_BOOLEAN = 'Z';
13.38 + public static final String SIG_BOOLEAN = "Z";
13.39 + public static final char SIGC_BYTE = 'B';
13.40 + public static final String SIG_BYTE = "B";
13.41 + public static final char SIGC_CHAR = 'C';
13.42 + public static final String SIG_CHAR = "C";
13.43 + public static final char SIGC_SHORT = 'S';
13.44 + public static final String SIG_SHORT = "S";
13.45 + public static final char SIGC_INT = 'I';
13.46 + public static final String SIG_INT = "I";
13.47 + public static final char SIGC_LONG = 'J';
13.48 + public static final String SIG_LONG = "J";
13.49 + public static final char SIGC_FLOAT = 'F';
13.50 + public static final String SIG_FLOAT = "F";
13.51 + public static final char SIGC_DOUBLE = 'D';
13.52 + public static final String SIG_DOUBLE = "D";
13.53 + public static final char SIGC_ARRAY = '[';
13.54 + public static final String SIG_ARRAY = "[";
13.55 + public static final char SIGC_CLASS = 'L';
13.56 + public static final String SIG_CLASS = "L";
13.57 + public static final char SIGC_METHOD = '(';
13.58 + public static final String SIG_METHOD = "(";
13.59 + public static final char SIGC_ENDCLASS = ';';
13.60 + public static final String SIG_ENDCLASS = ";";
13.61 + public static final char SIGC_ENDMETHOD = ')';
13.62 + public static final String SIG_ENDMETHOD = ")";
13.63 + public static final char SIGC_PACKAGE = '/';
13.64 + public static final String SIG_PACKAGE = "/";
13.65 +
13.66 + /* Class File Constants */
13.67 + public static final int JAVA_MAGIC = 0xcafebabe;
13.68 + public static final int JAVA_VERSION = 45;
13.69 + public static final int JAVA_MINOR_VERSION = 3;
13.70 +
13.71 + /* Constant table */
13.72 + public static final int CONSTANT_UTF8 = 1;
13.73 + public static final int CONSTANT_UNICODE = 2;
13.74 + public static final int CONSTANT_INTEGER = 3;
13.75 + public static final int CONSTANT_FLOAT = 4;
13.76 + public static final int CONSTANT_LONG = 5;
13.77 + public static final int CONSTANT_DOUBLE = 6;
13.78 + public static final int CONSTANT_CLASS = 7;
13.79 + public static final int CONSTANT_STRING = 8;
13.80 + public static final int CONSTANT_FIELD = 9;
13.81 + public static final int CONSTANT_METHOD = 10;
13.82 + public static final int CONSTANT_INTERFACEMETHOD = 11;
13.83 + public static final int CONSTANT_NAMEANDTYPE = 12;
13.84 +
13.85 + /* Access Flags */
13.86 + public static final int ACC_PUBLIC = 0x00000001;
13.87 + public static final int ACC_PRIVATE = 0x00000002;
13.88 + public static final int ACC_PROTECTED = 0x00000004;
13.89 + public static final int ACC_STATIC = 0x00000008;
13.90 + public static final int ACC_FINAL = 0x00000010;
13.91 + public static final int ACC_SYNCHRONIZED = 0x00000020;
13.92 + public static final int ACC_SUPER = 0x00000020;
13.93 + public static final int ACC_VOLATILE = 0x00000040;
13.94 + public static final int ACC_TRANSIENT = 0x00000080;
13.95 + public static final int ACC_NATIVE = 0x00000100;
13.96 + public static final int ACC_INTERFACE = 0x00000200;
13.97 + public static final int ACC_ABSTRACT = 0x00000400;
13.98 + public static final int ACC_STRICT = 0x00000800;
13.99 + public static final int ACC_EXPLICIT = 0x00001000;
13.100 + public static final int ACC_SYNTHETIC = 0x00010000; // actually, this is an attribute
13.101 +
13.102 + /* Type codes */
13.103 + public static final int T_CLASS = 0x00000002;
13.104 + public static final int T_BOOLEAN = 0x00000004;
13.105 + public static final int T_CHAR = 0x00000005;
13.106 + public static final int T_FLOAT = 0x00000006;
13.107 + public static final int T_DOUBLE = 0x00000007;
13.108 + public static final int T_BYTE = 0x00000008;
13.109 + public static final int T_SHORT = 0x00000009;
13.110 + public static final int T_INT = 0x0000000a;
13.111 + public static final int T_LONG = 0x0000000b;
13.112 +
13.113 + /* Type codes for StackMap attribute */
13.114 + public static final int ITEM_Bogus =0; // an unknown or uninitialized value
13.115 + public static final int ITEM_Integer =1; // a 32-bit integer
13.116 + public static final int ITEM_Float =2; // not used
13.117 + public static final int ITEM_Double =3; // not used
13.118 + public static final int ITEM_Long =4; // a 64-bit integer
13.119 + public static final int ITEM_Null =5; // the type of null
13.120 + public static final int ITEM_InitObject =6; // "this" in constructor
13.121 + public static final int ITEM_Object =7; // followed by 2-byte index of class name
13.122 + public static final int ITEM_NewObject =8; // followed by 2-byte ref to "new"
13.123 +
13.124 + /* Constants used in StackMapTable attribute */
13.125 + public static final int SAME_FRAME_BOUND = 64;
13.126 + public static final int SAME_LOCALS_1_STACK_ITEM_BOUND = 128;
13.127 + public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
13.128 + public static final int SAME_FRAME_EXTENDED = 251;
13.129 + public static final int FULL_FRAME = 255;
13.130 +
13.131 + /* Opcodes */
13.132 + public static final int opc_dead = -2;
13.133 + public static final int opc_label = -1;
13.134 + public static final int opc_nop = 0;
13.135 + public static final int opc_aconst_null = 1;
13.136 + public static final int opc_iconst_m1 = 2;
13.137 + public static final int opc_iconst_0 = 3;
13.138 + public static final int opc_iconst_1 = 4;
13.139 + public static final int opc_iconst_2 = 5;
13.140 + public static final int opc_iconst_3 = 6;
13.141 + public static final int opc_iconst_4 = 7;
13.142 + public static final int opc_iconst_5 = 8;
13.143 + public static final int opc_lconst_0 = 9;
13.144 + public static final int opc_lconst_1 = 10;
13.145 + public static final int opc_fconst_0 = 11;
13.146 + public static final int opc_fconst_1 = 12;
13.147 + public static final int opc_fconst_2 = 13;
13.148 + public static final int opc_dconst_0 = 14;
13.149 + public static final int opc_dconst_1 = 15;
13.150 + public static final int opc_bipush = 16;
13.151 + public static final int opc_sipush = 17;
13.152 + public static final int opc_ldc = 18;
13.153 + public static final int opc_ldc_w = 19;
13.154 + public static final int opc_ldc2_w = 20;
13.155 + public static final int opc_iload = 21;
13.156 + public static final int opc_lload = 22;
13.157 + public static final int opc_fload = 23;
13.158 + public static final int opc_dload = 24;
13.159 + public static final int opc_aload = 25;
13.160 + public static final int opc_iload_0 = 26;
13.161 + public static final int opc_iload_1 = 27;
13.162 + public static final int opc_iload_2 = 28;
13.163 + public static final int opc_iload_3 = 29;
13.164 + public static final int opc_lload_0 = 30;
13.165 + public static final int opc_lload_1 = 31;
13.166 + public static final int opc_lload_2 = 32;
13.167 + public static final int opc_lload_3 = 33;
13.168 + public static final int opc_fload_0 = 34;
13.169 + public static final int opc_fload_1 = 35;
13.170 + public static final int opc_fload_2 = 36;
13.171 + public static final int opc_fload_3 = 37;
13.172 + public static final int opc_dload_0 = 38;
13.173 + public static final int opc_dload_1 = 39;
13.174 + public static final int opc_dload_2 = 40;
13.175 + public static final int opc_dload_3 = 41;
13.176 + public static final int opc_aload_0 = 42;
13.177 + public static final int opc_aload_1 = 43;
13.178 + public static final int opc_aload_2 = 44;
13.179 + public static final int opc_aload_3 = 45;
13.180 + public static final int opc_iaload = 46;
13.181 + public static final int opc_laload = 47;
13.182 + public static final int opc_faload = 48;
13.183 + public static final int opc_daload = 49;
13.184 + public static final int opc_aaload = 50;
13.185 + public static final int opc_baload = 51;
13.186 + public static final int opc_caload = 52;
13.187 + public static final int opc_saload = 53;
13.188 + public static final int opc_istore = 54;
13.189 + public static final int opc_lstore = 55;
13.190 + public static final int opc_fstore = 56;
13.191 + public static final int opc_dstore = 57;
13.192 + public static final int opc_astore = 58;
13.193 + public static final int opc_istore_0 = 59;
13.194 + public static final int opc_istore_1 = 60;
13.195 + public static final int opc_istore_2 = 61;
13.196 + public static final int opc_istore_3 = 62;
13.197 + public static final int opc_lstore_0 = 63;
13.198 + public static final int opc_lstore_1 = 64;
13.199 + public static final int opc_lstore_2 = 65;
13.200 + public static final int opc_lstore_3 = 66;
13.201 + public static final int opc_fstore_0 = 67;
13.202 + public static final int opc_fstore_1 = 68;
13.203 + public static final int opc_fstore_2 = 69;
13.204 + public static final int opc_fstore_3 = 70;
13.205 + public static final int opc_dstore_0 = 71;
13.206 + public static final int opc_dstore_1 = 72;
13.207 + public static final int opc_dstore_2 = 73;
13.208 + public static final int opc_dstore_3 = 74;
13.209 + public static final int opc_astore_0 = 75;
13.210 + public static final int opc_astore_1 = 76;
13.211 + public static final int opc_astore_2 = 77;
13.212 + public static final int opc_astore_3 = 78;
13.213 + public static final int opc_iastore = 79;
13.214 + public static final int opc_lastore = 80;
13.215 + public static final int opc_fastore = 81;
13.216 + public static final int opc_dastore = 82;
13.217 + public static final int opc_aastore = 83;
13.218 + public static final int opc_bastore = 84;
13.219 + public static final int opc_castore = 85;
13.220 + public static final int opc_sastore = 86;
13.221 + public static final int opc_pop = 87;
13.222 + public static final int opc_pop2 = 88;
13.223 + public static final int opc_dup = 89;
13.224 + public static final int opc_dup_x1 = 90;
13.225 + public static final int opc_dup_x2 = 91;
13.226 + public static final int opc_dup2 = 92;
13.227 + public static final int opc_dup2_x1 = 93;
13.228 + public static final int opc_dup2_x2 = 94;
13.229 + public static final int opc_swap = 95;
13.230 + public static final int opc_iadd = 96;
13.231 + public static final int opc_ladd = 97;
13.232 + public static final int opc_fadd = 98;
13.233 + public static final int opc_dadd = 99;
13.234 + public static final int opc_isub = 100;
13.235 + public static final int opc_lsub = 101;
13.236 + public static final int opc_fsub = 102;
13.237 + public static final int opc_dsub = 103;
13.238 + public static final int opc_imul = 104;
13.239 + public static final int opc_lmul = 105;
13.240 + public static final int opc_fmul = 106;
13.241 + public static final int opc_dmul = 107;
13.242 + public static final int opc_idiv = 108;
13.243 + public static final int opc_ldiv = 109;
13.244 + public static final int opc_fdiv = 110;
13.245 + public static final int opc_ddiv = 111;
13.246 + public static final int opc_irem = 112;
13.247 + public static final int opc_lrem = 113;
13.248 + public static final int opc_frem = 114;
13.249 + public static final int opc_drem = 115;
13.250 + public static final int opc_ineg = 116;
13.251 + public static final int opc_lneg = 117;
13.252 + public static final int opc_fneg = 118;
13.253 + public static final int opc_dneg = 119;
13.254 + public static final int opc_ishl = 120;
13.255 + public static final int opc_lshl = 121;
13.256 + public static final int opc_ishr = 122;
13.257 + public static final int opc_lshr = 123;
13.258 + public static final int opc_iushr = 124;
13.259 + public static final int opc_lushr = 125;
13.260 + public static final int opc_iand = 126;
13.261 + public static final int opc_land = 127;
13.262 + public static final int opc_ior = 128;
13.263 + public static final int opc_lor = 129;
13.264 + public static final int opc_ixor = 130;
13.265 + public static final int opc_lxor = 131;
13.266 + public static final int opc_iinc = 132;
13.267 + public static final int opc_i2l = 133;
13.268 + public static final int opc_i2f = 134;
13.269 + public static final int opc_i2d = 135;
13.270 + public static final int opc_l2i = 136;
13.271 + public static final int opc_l2f = 137;
13.272 + public static final int opc_l2d = 138;
13.273 + public static final int opc_f2i = 139;
13.274 + public static final int opc_f2l = 140;
13.275 + public static final int opc_f2d = 141;
13.276 + public static final int opc_d2i = 142;
13.277 + public static final int opc_d2l = 143;
13.278 + public static final int opc_d2f = 144;
13.279 + public static final int opc_i2b = 145;
13.280 + public static final int opc_int2byte = 145;
13.281 + public static final int opc_i2c = 146;
13.282 + public static final int opc_int2char = 146;
13.283 + public static final int opc_i2s = 147;
13.284 + public static final int opc_int2short = 147;
13.285 + public static final int opc_lcmp = 148;
13.286 + public static final int opc_fcmpl = 149;
13.287 + public static final int opc_fcmpg = 150;
13.288 + public static final int opc_dcmpl = 151;
13.289 + public static final int opc_dcmpg = 152;
13.290 + public static final int opc_ifeq = 153;
13.291 + public static final int opc_ifne = 154;
13.292 + public static final int opc_iflt = 155;
13.293 + public static final int opc_ifge = 156;
13.294 + public static final int opc_ifgt = 157;
13.295 + public static final int opc_ifle = 158;
13.296 + public static final int opc_if_icmpeq = 159;
13.297 + public static final int opc_if_icmpne = 160;
13.298 + public static final int opc_if_icmplt = 161;
13.299 + public static final int opc_if_icmpge = 162;
13.300 + public static final int opc_if_icmpgt = 163;
13.301 + public static final int opc_if_icmple = 164;
13.302 + public static final int opc_if_acmpeq = 165;
13.303 + public static final int opc_if_acmpne = 166;
13.304 + public static final int opc_goto = 167;
13.305 + public static final int opc_jsr = 168;
13.306 + public static final int opc_ret = 169;
13.307 + public static final int opc_tableswitch = 170;
13.308 + public static final int opc_lookupswitch = 171;
13.309 + public static final int opc_ireturn = 172;
13.310 + public static final int opc_lreturn = 173;
13.311 + public static final int opc_freturn = 174;
13.312 + public static final int opc_dreturn = 175;
13.313 + public static final int opc_areturn = 176;
13.314 + public static final int opc_return = 177;
13.315 + public static final int opc_getstatic = 178;
13.316 + public static final int opc_putstatic = 179;
13.317 + public static final int opc_getfield = 180;
13.318 + public static final int opc_putfield = 181;
13.319 + public static final int opc_invokevirtual = 182;
13.320 + public static final int opc_invokenonvirtual = 183;
13.321 + public static final int opc_invokespecial = 183;
13.322 + public static final int opc_invokestatic = 184;
13.323 + public static final int opc_invokeinterface = 185;
13.324 +// public static final int opc_xxxunusedxxx = 186;
13.325 + public static final int opc_new = 187;
13.326 + public static final int opc_newarray = 188;
13.327 + public static final int opc_anewarray = 189;
13.328 + public static final int opc_arraylength = 190;
13.329 + public static final int opc_athrow = 191;
13.330 + public static final int opc_checkcast = 192;
13.331 + public static final int opc_instanceof = 193;
13.332 + public static final int opc_monitorenter = 194;
13.333 + public static final int opc_monitorexit = 195;
13.334 + public static final int opc_wide = 196;
13.335 + public static final int opc_multianewarray = 197;
13.336 + public static final int opc_ifnull = 198;
13.337 + public static final int opc_ifnonnull = 199;
13.338 + public static final int opc_goto_w = 200;
13.339 + public static final int opc_jsr_w = 201;
13.340 + /* Pseudo-instructions */
13.341 + public static final int opc_bytecode = 203;
13.342 + public static final int opc_try = 204;
13.343 + public static final int opc_endtry = 205;
13.344 + public static final int opc_catch = 206;
13.345 + public static final int opc_var = 207;
13.346 + public static final int opc_endvar = 208;
13.347 + public static final int opc_localsmap = 209;
13.348 + public static final int opc_stackmap = 210;
13.349 + /* PicoJava prefixes */
13.350 + public static final int opc_nonpriv = 254;
13.351 + public static final int opc_priv = 255;
13.352 +
13.353 + /* Wide instructions */
13.354 + public static final int opc_iload_w = (opc_wide<<8)|opc_iload;
13.355 + public static final int opc_lload_w = (opc_wide<<8)|opc_lload;
13.356 + public static final int opc_fload_w = (opc_wide<<8)|opc_fload;
13.357 + public static final int opc_dload_w = (opc_wide<<8)|opc_dload;
13.358 + public static final int opc_aload_w = (opc_wide<<8)|opc_aload;
13.359 + public static final int opc_istore_w = (opc_wide<<8)|opc_istore;
13.360 + public static final int opc_lstore_w = (opc_wide<<8)|opc_lstore;
13.361 + public static final int opc_fstore_w = (opc_wide<<8)|opc_fstore;
13.362 + public static final int opc_dstore_w = (opc_wide<<8)|opc_dstore;
13.363 + public static final int opc_astore_w = (opc_wide<<8)|opc_astore;
13.364 + public static final int opc_ret_w = (opc_wide<<8)|opc_ret;
13.365 + public static final int opc_iinc_w = (opc_wide<<8)|opc_iinc;
13.366 +
13.367 + /* Opcode Names */
13.368 + public static final String opcNamesTab[] = {
13.369 + "nop",
13.370 + "aconst_null",
13.371 + "iconst_m1",
13.372 + "iconst_0",
13.373 + "iconst_1",
13.374 + "iconst_2",
13.375 + "iconst_3",
13.376 + "iconst_4",
13.377 + "iconst_5",
13.378 + "lconst_0",
13.379 + "lconst_1",
13.380 + "fconst_0",
13.381 + "fconst_1",
13.382 + "fconst_2",
13.383 + "dconst_0",
13.384 + "dconst_1",
13.385 + "bipush",
13.386 + "sipush",
13.387 + "ldc",
13.388 + "ldc_w",
13.389 + "ldc2_w",
13.390 + "iload",
13.391 + "lload",
13.392 + "fload",
13.393 + "dload",
13.394 + "aload",
13.395 + "iload_0",
13.396 + "iload_1",
13.397 + "iload_2",
13.398 + "iload_3",
13.399 + "lload_0",
13.400 + "lload_1",
13.401 + "lload_2",
13.402 + "lload_3",
13.403 + "fload_0",
13.404 + "fload_1",
13.405 + "fload_2",
13.406 + "fload_3",
13.407 + "dload_0",
13.408 + "dload_1",
13.409 + "dload_2",
13.410 + "dload_3",
13.411 + "aload_0",
13.412 + "aload_1",
13.413 + "aload_2",
13.414 + "aload_3",
13.415 + "iaload",
13.416 + "laload",
13.417 + "faload",
13.418 + "daload",
13.419 + "aaload",
13.420 + "baload",
13.421 + "caload",
13.422 + "saload",
13.423 + "istore",
13.424 + "lstore",
13.425 + "fstore",
13.426 + "dstore",
13.427 + "astore",
13.428 + "istore_0",
13.429 + "istore_1",
13.430 + "istore_2",
13.431 + "istore_3",
13.432 + "lstore_0",
13.433 + "lstore_1",
13.434 + "lstore_2",
13.435 + "lstore_3",
13.436 + "fstore_0",
13.437 + "fstore_1",
13.438 + "fstore_2",
13.439 + "fstore_3",
13.440 + "dstore_0",
13.441 + "dstore_1",
13.442 + "dstore_2",
13.443 + "dstore_3",
13.444 + "astore_0",
13.445 + "astore_1",
13.446 + "astore_2",
13.447 + "astore_3",
13.448 + "iastore",
13.449 + "lastore",
13.450 + "fastore",
13.451 + "dastore",
13.452 + "aastore",
13.453 + "bastore",
13.454 + "castore",
13.455 + "sastore",
13.456 + "pop",
13.457 + "pop2",
13.458 + "dup",
13.459 + "dup_x1",
13.460 + "dup_x2",
13.461 + "dup2",
13.462 + "dup2_x1",
13.463 + "dup2_x2",
13.464 + "swap",
13.465 + "iadd",
13.466 + "ladd",
13.467 + "fadd",
13.468 + "dadd",
13.469 + "isub",
13.470 + "lsub",
13.471 + "fsub",
13.472 + "dsub",
13.473 + "imul",
13.474 + "lmul",
13.475 + "fmul",
13.476 + "dmul",
13.477 + "idiv",
13.478 + "ldiv",
13.479 + "fdiv",
13.480 + "ddiv",
13.481 + "irem",
13.482 + "lrem",
13.483 + "frem",
13.484 + "drem",
13.485 + "ineg",
13.486 + "lneg",
13.487 + "fneg",
13.488 + "dneg",
13.489 + "ishl",
13.490 + "lshl",
13.491 + "ishr",
13.492 + "lshr",
13.493 + "iushr",
13.494 + "lushr",
13.495 + "iand",
13.496 + "land",
13.497 + "ior",
13.498 + "lor",
13.499 + "ixor",
13.500 + "lxor",
13.501 + "iinc",
13.502 + "i2l",
13.503 + "i2f",
13.504 + "i2d",
13.505 + "l2i",
13.506 + "l2f",
13.507 + "l2d",
13.508 + "f2i",
13.509 + "f2l",
13.510 + "f2d",
13.511 + "d2i",
13.512 + "d2l",
13.513 + "d2f",
13.514 + "i2b",
13.515 + "i2c",
13.516 + "i2s",
13.517 + "lcmp",
13.518 + "fcmpl",
13.519 + "fcmpg",
13.520 + "dcmpl",
13.521 + "dcmpg",
13.522 + "ifeq",
13.523 + "ifne",
13.524 + "iflt",
13.525 + "ifge",
13.526 + "ifgt",
13.527 + "ifle",
13.528 + "if_icmpeq",
13.529 + "if_icmpne",
13.530 + "if_icmplt",
13.531 + "if_icmpge",
13.532 + "if_icmpgt",
13.533 + "if_icmple",
13.534 + "if_acmpeq",
13.535 + "if_acmpne",
13.536 + "goto",
13.537 + "jsr",
13.538 + "ret",
13.539 + "tableswitch",
13.540 + "lookupswitch",
13.541 + "ireturn",
13.542 + "lreturn",
13.543 + "freturn",
13.544 + "dreturn",
13.545 + "areturn",
13.546 + "return",
13.547 + "getstatic",
13.548 + "putstatic",
13.549 + "getfield",
13.550 + "putfield",
13.551 + "invokevirtual",
13.552 + "invokespecial", // was "invokenonvirtual",
13.553 + "invokestatic",
13.554 + "invokeinterface",
13.555 + "bytecode 186", //"xxxunusedxxx",
13.556 + "new",
13.557 + "newarray",
13.558 + "anewarray",
13.559 + "arraylength",
13.560 + "athrow",
13.561 + "checkcast",
13.562 + "instanceof",
13.563 + "monitorenter",
13.564 + "monitorexit",
13.565 + null, // "wide",
13.566 + "multianewarray",
13.567 + "ifnull",
13.568 + "ifnonnull",
13.569 + "goto_w",
13.570 + "jsr_w",
13.571 + "bytecode 202", // "breakpoint",
13.572 + "bytecode",
13.573 + "try",
13.574 + "endtry",
13.575 + "catch",
13.576 + "var",
13.577 + "endvar",
13.578 + "locals_map",
13.579 + "stack_map"
13.580 + };
13.581 +
13.582 + /* Opcode Lengths */
13.583 + public static final int opcLengthsTab[] = {
13.584 + 1,
13.585 + 1,
13.586 + 1,
13.587 + 1,
13.588 + 1,
13.589 + 1,
13.590 + 1,
13.591 + 1,
13.592 + 1,
13.593 + 1,
13.594 + 1,
13.595 + 1,
13.596 + 1,
13.597 + 1,
13.598 + 1,
13.599 + 1,
13.600 + 2,
13.601 + 3,
13.602 + 2,
13.603 + 3,
13.604 + 3,
13.605 + 2,
13.606 + 2,
13.607 + 2,
13.608 + 2,
13.609 + 2,
13.610 + 1,
13.611 + 1,
13.612 + 1,
13.613 + 1,
13.614 + 1,
13.615 + 1,
13.616 + 1,
13.617 + 1,
13.618 + 1,
13.619 + 1,
13.620 + 1,
13.621 + 1,
13.622 + 1,
13.623 + 1,
13.624 + 1,
13.625 + 1,
13.626 + 1,
13.627 + 1,
13.628 + 1,
13.629 + 1,
13.630 + 1,
13.631 + 1,
13.632 + 1,
13.633 + 1,
13.634 + 1,
13.635 + 1,
13.636 + 1,
13.637 + 1,
13.638 + 2,
13.639 + 2,
13.640 + 2,
13.641 + 2,
13.642 + 2,
13.643 + 1,
13.644 + 1,
13.645 + 1,
13.646 + 1,
13.647 + 1,
13.648 + 1,
13.649 + 1,
13.650 + 1,
13.651 + 1,
13.652 + 1,
13.653 + 1,
13.654 + 1,
13.655 + 1,
13.656 + 1,
13.657 + 1,
13.658 + 1,
13.659 + 1,
13.660 + 1,
13.661 + 1,
13.662 + 1,
13.663 + 1,
13.664 + 1,
13.665 + 1,
13.666 + 1,
13.667 + 1,
13.668 + 1,
13.669 + 1,
13.670 + 1,
13.671 + 1,
13.672 + 1,
13.673 + 1,
13.674 + 1,
13.675 + 1,
13.676 + 1,
13.677 + 1,
13.678 + 1,
13.679 + 1,
13.680 + 1,
13.681 + 1,
13.682 + 1,
13.683 + 1,
13.684 + 1,
13.685 + 1,
13.686 + 1,
13.687 + 1,
13.688 + 1,
13.689 + 1,
13.690 + 1,
13.691 + 1,
13.692 + 1,
13.693 + 1,
13.694 + 1,
13.695 + 1,
13.696 + 1,
13.697 + 1,
13.698 + 1,
13.699 + 1,
13.700 + 1,
13.701 + 1,
13.702 + 1,
13.703 + 1,
13.704 + 1,
13.705 + 1,
13.706 + 1,
13.707 + 1,
13.708 + 1,
13.709 + 1,
13.710 + 1,
13.711 + 1,
13.712 + 1,
13.713 + 1,
13.714 + 1,
13.715 + 1,
13.716 + 3,
13.717 + 1,
13.718 + 1,
13.719 + 1,
13.720 + 1,
13.721 + 1,
13.722 + 1,
13.723 + 1,
13.724 + 1,
13.725 + 1,
13.726 + 1,
13.727 + 1,
13.728 + 1,
13.729 + 1,
13.730 + 1,
13.731 + 1,
13.732 + 1,
13.733 + 1,
13.734 + 1,
13.735 + 1,
13.736 + 1,
13.737 + 3,
13.738 + 3,
13.739 + 3,
13.740 + 3,
13.741 + 3,
13.742 + 3,
13.743 + 3,
13.744 + 3,
13.745 + 3,
13.746 + 3,
13.747 + 3,
13.748 + 3,
13.749 + 3,
13.750 + 3,
13.751 + 3,
13.752 + 3,
13.753 + 2,
13.754 + 99,
13.755 + 99,
13.756 + 1,
13.757 + 1,
13.758 + 1,
13.759 + 1,
13.760 + 1,
13.761 + 1,
13.762 + 3,
13.763 + 3,
13.764 + 3,
13.765 + 3,
13.766 + 3,
13.767 + 3,
13.768 + 3,
13.769 + 5,
13.770 + 0,
13.771 + 3,
13.772 + 2,
13.773 + 3,
13.774 + 1,
13.775 + 1,
13.776 + 3,
13.777 + 3,
13.778 + 1,
13.779 + 1,
13.780 + 0, // wide
13.781 + 4,
13.782 + 3,
13.783 + 3,
13.784 + 5,
13.785 + 5,
13.786 + 1,
13.787 + 1, 0, 0, 0, 0, 0 // pseudo
13.788 + };
13.789 +
13.790 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapData.java Fri Nov 16 08:08:36 2012 +0100
14.3 @@ -0,0 +1,71 @@
14.4 +/*
14.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14.7 + *
14.8 + * This code is free software; you can redistribute it and/or modify it
14.9 + * under the terms of the GNU General Public License version 2 only, as
14.10 + * published by the Free Software Foundation. Oracle designates this
14.11 + * particular file as subject to the "Classpath" exception as provided
14.12 + * by Oracle in the LICENSE file that accompanied this code.
14.13 + *
14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14.17 + * version 2 for more details (a copy is included in the LICENSE file that
14.18 + * accompanied this code).
14.19 + *
14.20 + * You should have received a copy of the GNU General Public License version
14.21 + * 2 along with this work; if not, write to the Free Software Foundation,
14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14.23 + *
14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14.25 + * or visit www.oracle.com if you need additional information or have any
14.26 + * questions.
14.27 + */
14.28 +
14.29 +
14.30 +package org.apidesign.javap;
14.31 +
14.32 +import java.util.*;
14.33 +import java.io.*;
14.34 +
14.35 +import static org.apidesign.javap.RuntimeConstants.*;
14.36 +
14.37 +/* represents one entry of StackMap attribute
14.38 + */
14.39 +class StackMapData {
14.40 + final int offset;
14.41 + final int[] locals;
14.42 + final int[] stack;
14.43 +
14.44 + StackMapData(int offset, int[] locals, int[] stack) {
14.45 + this.offset = offset;
14.46 + this.locals = locals;
14.47 + this.stack = stack;
14.48 + }
14.49 +
14.50 + StackMapData(DataInputStream in, MethodData method) throws IOException {
14.51 + offset = in.readUnsignedShort();
14.52 + int local_size = in.readUnsignedShort();
14.53 + locals = readTypeArray(in, local_size, method);
14.54 + int stack_size = in.readUnsignedShort();
14.55 + stack = readTypeArray(in, stack_size, method);
14.56 + }
14.57 +
14.58 + static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
14.59 + int[] types = new int[length];
14.60 + for (int i=0; i<length; i++) {
14.61 + types[i] = readType(in, method);
14.62 + }
14.63 + return types;
14.64 + }
14.65 +
14.66 + static final int readType(DataInputStream in, MethodData method) throws IOException {
14.67 + int type = in.readUnsignedByte();
14.68 + if (type == ITEM_Object || type == ITEM_NewObject) {
14.69 + type = type | (in.readUnsignedShort()<<8);
14.70 + }
14.71 + return type;
14.72 + }
14.73 +
14.74 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapTableData.java Fri Nov 16 08:08:36 2012 +0100
15.3 @@ -0,0 +1,126 @@
15.4 +/*
15.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 + *
15.8 + * This code is free software; you can redistribute it and/or modify it
15.9 + * under the terms of the GNU General Public License version 2 only, as
15.10 + * published by the Free Software Foundation. Oracle designates this
15.11 + * particular file as subject to the "Classpath" exception as provided
15.12 + * by Oracle in the LICENSE file that accompanied this code.
15.13 + *
15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 + * version 2 for more details (a copy is included in the LICENSE file that
15.18 + * accompanied this code).
15.19 + *
15.20 + * You should have received a copy of the GNU General Public License version
15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 + *
15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15.25 + * or visit www.oracle.com if you need additional information or have any
15.26 + * questions.
15.27 + */
15.28 +
15.29 +
15.30 +package org.apidesign.javap;
15.31 +
15.32 +import java.io.*;
15.33 +
15.34 +import static org.apidesign.javap.RuntimeConstants.*;
15.35 +
15.36 +/* represents one entry of StackMapTable attribute
15.37 + */
15.38 +class StackMapTableData {
15.39 + final int frameType;
15.40 + int offsetDelta;
15.41 +
15.42 + StackMapTableData(int frameType) {
15.43 + this.frameType = frameType;
15.44 + }
15.45 +
15.46 + static class SameFrame extends StackMapTableData {
15.47 + SameFrame(int frameType, int offsetDelta) {
15.48 + super(frameType);
15.49 + this.offsetDelta = offsetDelta;
15.50 + }
15.51 + }
15.52 +
15.53 + static class SameLocals1StackItem extends StackMapTableData {
15.54 + final int[] stack;
15.55 + SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
15.56 + super(frameType);
15.57 + this.offsetDelta = offsetDelta;
15.58 + this.stack = stack;
15.59 + }
15.60 + }
15.61 +
15.62 + static class ChopFrame extends StackMapTableData {
15.63 + ChopFrame(int frameType, int offsetDelta) {
15.64 + super(frameType);
15.65 + this.offsetDelta = offsetDelta;
15.66 + }
15.67 + }
15.68 +
15.69 + static class AppendFrame extends StackMapTableData {
15.70 + final int[] locals;
15.71 + AppendFrame(int frameType, int offsetDelta, int[] locals) {
15.72 + super(frameType);
15.73 + this.offsetDelta = offsetDelta;
15.74 + this.locals = locals;
15.75 + }
15.76 + }
15.77 +
15.78 + static class FullFrame extends StackMapTableData {
15.79 + final int[] locals;
15.80 + final int[] stack;
15.81 + FullFrame(int offsetDelta, int[] locals, int[] stack) {
15.82 + super(FULL_FRAME);
15.83 + this.offsetDelta = offsetDelta;
15.84 + this.locals = locals;
15.85 + this.stack = stack;
15.86 + }
15.87 + }
15.88 +
15.89 + static StackMapTableData getInstance(DataInputStream in, MethodData method)
15.90 + throws IOException {
15.91 + int frameType = in.readUnsignedByte();
15.92 +
15.93 + if (frameType < SAME_FRAME_BOUND) {
15.94 + // same_frame
15.95 + return new SameFrame(frameType, frameType);
15.96 + } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
15.97 + // same_locals_1_stack_item_frame
15.98 + // read additional single stack element
15.99 + return new SameLocals1StackItem(frameType,
15.100 + (frameType - SAME_FRAME_BOUND),
15.101 + StackMapData.readTypeArray(in, 1, method));
15.102 + } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
15.103 + // same_locals_1_stack_item_extended
15.104 + return new SameLocals1StackItem(frameType,
15.105 + in.readUnsignedShort(),
15.106 + StackMapData.readTypeArray(in, 1, method));
15.107 + } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
15.108 + // chop_frame or same_frame_extended
15.109 + return new ChopFrame(frameType, in.readUnsignedShort());
15.110 + } else if (frameType == SAME_FRAME_EXTENDED) {
15.111 + // chop_frame or same_frame_extended
15.112 + return new SameFrame(frameType, in.readUnsignedShort());
15.113 + } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
15.114 + // append_frame
15.115 + return new AppendFrame(frameType, in.readUnsignedShort(),
15.116 + StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
15.117 + } else if (frameType == FULL_FRAME) {
15.118 + // full_frame
15.119 + int offsetDelta = in.readUnsignedShort();
15.120 + int locals_size = in.readUnsignedShort();
15.121 + int[] locals = StackMapData.readTypeArray(in, locals_size, method);
15.122 + int stack_size = in.readUnsignedShort();
15.123 + int[] stack = StackMapData.readTypeArray(in, stack_size, method);
15.124 + return new FullFrame(offsetDelta, locals, stack);
15.125 + } else {
15.126 + throw new ClassFormatError("unrecognized frame_type in StackMapTable");
15.127 + }
15.128 + }
15.129 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/javap/src/main/java/org/apidesign/javap/Tables.java Fri Nov 16 08:08:36 2012 +0100
16.3 @@ -0,0 +1,373 @@
16.4 +/*
16.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 + *
16.8 + * This code is free software; you can redistribute it and/or modify it
16.9 + * under the terms of the GNU General Public License version 2 only, as
16.10 + * published by the Free Software Foundation. Oracle designates this
16.11 + * particular file as subject to the "Classpath" exception as provided
16.12 + * by Oracle in the LICENSE file that accompanied this code.
16.13 + *
16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 + * version 2 for more details (a copy is included in the LICENSE file that
16.18 + * accompanied this code).
16.19 + *
16.20 + * You should have received a copy of the GNU General Public License version
16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 + *
16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16.25 + * or visit www.oracle.com if you need additional information or have any
16.26 + * questions.
16.27 + */
16.28 +
16.29 +
16.30 +package org.apidesign.javap;
16.31 +
16.32 +
16.33 +
16.34 +public class Tables implements Constants {
16.35 + /**
16.36 + * Define mnemocodes table.
16.37 + */
16.38 + static Hashtable mnemocodes = new Hashtable(301, 0.5f);
16.39 + static String opcExtNamesTab[]=new String[128];
16.40 + static String opcPrivExtNamesTab[]=new String[128];
16.41 + static void defineNonPriv(int opc, String mnem) {
16.42 + mnemocodes.put(opcExtNamesTab[opc]=mnem, new Integer(opc_nonpriv*256+opc));
16.43 + }
16.44 + static void definePriv(int opc, String mnem) {
16.45 + mnemocodes.put(opcPrivExtNamesTab[opc]="priv_"+mnem, new Integer(opc_priv*256+opc));
16.46 + }
16.47 + static void defineExt(int opc, String mnem) {
16.48 + defineNonPriv(opc, mnem);
16.49 + definePriv(opc, mnem);
16.50 + }
16.51 + static { int k;
16.52 + for (k=0; k<opc_wide; k++) {
16.53 + mnemocodes.put(opcNamesTab[k], new Integer(k));
16.54 + }
16.55 + for (k=opc_wide+1; k<opcNamesTab.length; k++) {
16.56 + mnemocodes.put(opcNamesTab[k], new Integer(k));
16.57 + }
16.58 + mnemocodes.put("invokenonvirtual", new Integer(opc_invokespecial));
16.59 +
16.60 + mnemocodes.put("iload_w", new Integer(opc_iload_w));
16.61 + mnemocodes.put("lload_w", new Integer(opc_lload_w));
16.62 + mnemocodes.put("fload_w", new Integer(opc_fload_w));
16.63 + mnemocodes.put("dload_w", new Integer(opc_dload_w));
16.64 + mnemocodes.put("aload_w", new Integer(opc_aload_w));
16.65 + mnemocodes.put("istore_w", new Integer(opc_istore_w));
16.66 + mnemocodes.put("lstore_w", new Integer(opc_lstore_w));
16.67 + mnemocodes.put("fstore_w", new Integer(opc_fstore_w));
16.68 + mnemocodes.put("dstore_w", new Integer(opc_dstore_w));
16.69 + mnemocodes.put("astore_w", new Integer(opc_astore_w));
16.70 + mnemocodes.put("ret_w", new Integer(opc_ret_w));
16.71 + mnemocodes.put("iinc_w", new Integer(opc_iinc_w));
16.72 +
16.73 + mnemocodes.put("nonpriv", new Integer(opc_nonpriv));
16.74 + mnemocodes.put("priv", new Integer(opc_priv));
16.75 +
16.76 + defineExt(0, "load_ubyte");
16.77 + defineExt(1, "load_byte");
16.78 + defineExt(2, "load_char");
16.79 + defineExt(3, "load_short");
16.80 + defineExt(4, "load_word");
16.81 + defineExt(10, "load_char_oe");
16.82 + defineExt(11, "load_short_oe");
16.83 + defineExt(12, "load_word_oe");
16.84 + defineExt(16, "ncload_ubyte");
16.85 + defineExt(17, "ncload_byte");
16.86 + defineExt(18, "ncload_char");
16.87 + defineExt(19, "ncload_short");
16.88 + defineExt(20, "ncload_word");
16.89 + defineExt(26, "ncload_char_oe");
16.90 + defineExt(27, "ncload_short_oe");
16.91 + defineExt(28, "ncload_word_oe");
16.92 + defineExt(30, "cache_flush");
16.93 + defineExt(32, "store_byte");
16.94 + defineExt(34, "store_short");
16.95 + defineExt(36, "store_word");
16.96 + defineExt(42, "store_short_oe");
16.97 + defineExt(44, "store_word_oe");
16.98 + defineExt(48, "ncstore_byte");
16.99 + defineExt(50, "ncstore_short");
16.100 + defineExt(52, "ncstore_word");
16.101 + defineExt(58, "ncstore_short_oe");
16.102 + defineExt(60, "ncstore_word_oe");
16.103 + defineExt(62, "zero_line");
16.104 + defineNonPriv(5, "ret_from_sub");
16.105 + defineNonPriv(63, "enter_sync_method");
16.106 + definePriv(5, "ret_from_trap");
16.107 + definePriv(6, "read_dcache_tag");
16.108 + definePriv(7, "read_dcache_data");
16.109 + definePriv(14, "read_icache_tag");
16.110 + definePriv(15, "read_icache_data");
16.111 + definePriv(22, "powerdown");
16.112 + definePriv(23, "read_scache_data");
16.113 + definePriv(31, "cache_index_flush");
16.114 + definePriv(38, "write_dcache_tag");
16.115 + definePriv(39, "write_dcache_data");
16.116 + definePriv(46, "write_icache_tag");
16.117 + definePriv(47, "write_icache_data");
16.118 + definePriv(54, "reset");
16.119 + definePriv(55, "write_scache_data");
16.120 + for (k=0; k<32; k++) {
16.121 + definePriv(k+64, "read_reg_"+k);
16.122 + }
16.123 + for (k=0; k<32; k++) {
16.124 + definePriv(k+96, "write_reg_"+k);
16.125 + }
16.126 + }
16.127 +
16.128 + public static int opcLength(int opc) throws ArrayIndexOutOfBoundsException {
16.129 + switch (opc>>8) {
16.130 + case 0:
16.131 + return opcLengthsTab[opc];
16.132 + case opc_wide:
16.133 + switch (opc&0xFF) {
16.134 + case opc_aload: case opc_astore:
16.135 + case opc_fload: case opc_fstore:
16.136 + case opc_iload: case opc_istore:
16.137 + case opc_lload: case opc_lstore:
16.138 + case opc_dload: case opc_dstore:
16.139 + case opc_ret:
16.140 + return 4;
16.141 + case opc_iinc:
16.142 + return 6;
16.143 + default:
16.144 + throw new ArrayIndexOutOfBoundsException();
16.145 + }
16.146 + case opc_nonpriv:
16.147 + case opc_priv:
16.148 + return 2;
16.149 + default:
16.150 + throw new ArrayIndexOutOfBoundsException();
16.151 + }
16.152 + }
16.153 +
16.154 + public static String opcName(int opc) {
16.155 + try {
16.156 + switch (opc>>8) {
16.157 + case 0:
16.158 + return opcNamesTab[opc];
16.159 + case opc_wide: {
16.160 + String mnem=opcNamesTab[opc&0xFF]+"_w";
16.161 + if (mnemocodes.get(mnem) == null)
16.162 + return null; // non-existent opcode
16.163 + return mnem;
16.164 + }
16.165 + case opc_nonpriv:
16.166 + return opcExtNamesTab[opc&0xFF];
16.167 + case opc_priv:
16.168 + return opcPrivExtNamesTab[opc&0xFF];
16.169 + default:
16.170 + return null;
16.171 + }
16.172 + } catch (ArrayIndexOutOfBoundsException e) {
16.173 + switch (opc) {
16.174 + case opc_nonpriv:
16.175 + return "nonpriv";
16.176 + case opc_priv:
16.177 + return "priv";
16.178 + default:
16.179 + return null;
16.180 + }
16.181 + }
16.182 + }
16.183 +
16.184 + public static int opcode(String mnem) {
16.185 + Integer Val=(Integer)(mnemocodes.get(mnem));
16.186 + if (Val == null) return -1;
16.187 + return Val.intValue();
16.188 + }
16.189 +
16.190 + /**
16.191 + * Initialized keyword and token Hashtables
16.192 + */
16.193 + static Vector keywordNames = new Vector(40);
16.194 + private static void defineKeywordName(String id, int token) {
16.195 +
16.196 + if (token>=keywordNames.size()) {
16.197 + keywordNames.setSize(token+1);
16.198 + }
16.199 + keywordNames.setElementAt(id, token);
16.200 + }
16.201 + public static String keywordName(int token) {
16.202 + if (token==-1) return "EOF";
16.203 + if (token>=keywordNames.size()) return null;
16.204 + return (String)keywordNames.elementAt(token);
16.205 + }
16.206 + static {
16.207 + defineKeywordName("ident", IDENT);
16.208 + defineKeywordName("STRINGVAL", STRINGVAL);
16.209 + defineKeywordName("intVal", INTVAL);
16.210 + defineKeywordName("longVal", LONGVAL);
16.211 + defineKeywordName("floatVal", FLOATVAL);
16.212 + defineKeywordName("doubleVal", DOUBLEVAL);
16.213 + defineKeywordName("SEMICOLON", SEMICOLON);
16.214 + defineKeywordName("COLON", COLON);
16.215 + defineKeywordName("LBRACE", LBRACE);
16.216 + defineKeywordName("RBRACE", RBRACE);
16.217 + }
16.218 +
16.219 + static Hashtable keywords = new Hashtable(40);
16.220 + public static int keyword(String idValue) {
16.221 + Integer Val=(Integer)(keywords.get(idValue));
16.222 + if (Val == null) return IDENT;
16.223 + return Val.intValue();
16.224 + }
16.225 +
16.226 + private static void defineKeyword(String id, int token) {
16.227 + keywords.put(id, new Integer(token));
16.228 + defineKeywordName(id, token);
16.229 + }
16.230 + static {
16.231 + // Modifier keywords
16.232 + defineKeyword("private", PRIVATE);
16.233 + defineKeyword("public", PUBLIC);
16.234 + defineKeyword("protected", PROTECTED);
16.235 + defineKeyword("static", STATIC);
16.236 + defineKeyword("transient", TRANSIENT);
16.237 + defineKeyword("synchronized", SYNCHRONIZED);
16.238 + defineKeyword("super", SUPER);
16.239 + defineKeyword("native", NATIVE);
16.240 + defineKeyword("abstract", ABSTRACT);
16.241 + defineKeyword("volatile", VOLATILE);
16.242 + defineKeyword("final", FINAL);
16.243 + defineKeyword("interface",INTERFACE);
16.244 + defineKeyword("synthetic",SYNTHETIC);
16.245 + defineKeyword("strict",STRICT);
16.246 +
16.247 + // Declaration keywords
16.248 + defineKeyword("package",PACKAGE);
16.249 + defineKeyword("class",CLASS);
16.250 + defineKeyword("extends",EXTENDS);
16.251 + defineKeyword("implements",IMPLEMENTS);
16.252 + defineKeyword("const", CONST);
16.253 + defineKeyword("throws",THROWS);
16.254 + defineKeyword("interface",INTERFACE);
16.255 + defineKeyword("Method",METHODREF);
16.256 + defineKeyword("Field",FIELDREF);
16.257 + defineKeyword("stack",STACK);
16.258 + defineKeyword("locals",LOCAL);
16.259 +
16.260 + // used in switchtables
16.261 + defineKeyword("default", DEFAULT);
16.262 +
16.263 + // used in inner class declarations
16.264 + defineKeyword("InnerClass", INNERCLASS);
16.265 + defineKeyword("of", OF);
16.266 +
16.267 + // misc
16.268 + defineKeyword("bits",BITS);
16.269 + defineKeyword("Infinity",INF);
16.270 + defineKeyword("Inf",INF);
16.271 + defineKeyword("NaN",NAN);
16.272 + }
16.273 +
16.274 + /**
16.275 + * Define tag table.
16.276 + */
16.277 + private static Vector tagNames = new Vector(10);
16.278 + private static Hashtable Tags = new Hashtable(10);
16.279 + static {
16.280 + defineTag("Asciz",CONSTANT_UTF8);
16.281 + defineTag("int",CONSTANT_INTEGER);
16.282 + defineTag("float",CONSTANT_FLOAT);
16.283 + defineTag("long",CONSTANT_LONG);
16.284 + defineTag("double",CONSTANT_DOUBLE);
16.285 + defineTag("class",CONSTANT_CLASS);
16.286 + defineTag("String",CONSTANT_STRING);
16.287 + defineTag("Field",CONSTANT_FIELD);
16.288 + defineTag("Method",CONSTANT_METHOD);
16.289 + defineTag("InterfaceMethod",CONSTANT_INTERFACEMETHOD);
16.290 + defineTag("NameAndType",CONSTANT_NAMEANDTYPE);
16.291 + }
16.292 + private static void defineTag(String id, int val) {
16.293 + Tags.put(id, new Integer(val));
16.294 + if (val>=tagNames.size()) {
16.295 + tagNames.setSize(val+1);
16.296 + }
16.297 + tagNames.setElementAt(id, val);
16.298 + }
16.299 + public static String tagName(int tag) {
16.300 + if (tag>=tagNames.size()) return null;
16.301 + return (String)tagNames.elementAt(tag);
16.302 + }
16.303 + public static int tagValue(String idValue) {
16.304 + Integer Val=(Integer)(Tags.get(idValue));
16.305 + if (Val == null) return 0;
16.306 + return Val.intValue();
16.307 + }
16.308 +
16.309 + /**
16.310 + * Define type table. These types used in "newarray" instruction only.
16.311 + */
16.312 + private static Vector typeNames = new Vector(10);
16.313 + private static Hashtable Types = new Hashtable(10);
16.314 + static {
16.315 + defineType("int",T_INT);
16.316 + defineType("long",T_LONG);
16.317 + defineType("float",T_FLOAT);
16.318 + defineType("double",T_DOUBLE);
16.319 + defineType("class",T_CLASS);
16.320 + defineType("boolean",T_BOOLEAN);
16.321 + defineType("char",T_CHAR);
16.322 + defineType("byte",T_BYTE);
16.323 + defineType("short",T_SHORT);
16.324 + }
16.325 + private static void defineType(String id, int val) {
16.326 + Types.put(id, new Integer(val));
16.327 + if (val>=typeNames.size()) {
16.328 + typeNames.setSize(val+1);
16.329 + }
16.330 + typeNames.setElementAt(id, val);
16.331 + }
16.332 + public static int typeValue(String idValue) {
16.333 + Integer Val=(Integer)(Types.get(idValue));
16.334 + if (Val == null) return -1;
16.335 + return Val.intValue();
16.336 + }
16.337 + public static String typeName(int type) {
16.338 + if (type>=typeNames.size()) return null;
16.339 + return (String)typeNames.elementAt(type);
16.340 + }
16.341 +
16.342 + /**
16.343 + * Define MapTypes table.
16.344 + * These constants used in stackmap tables only.
16.345 + */
16.346 + private static Vector mapTypeNames = new Vector(10);
16.347 + private static Hashtable MapTypes = new Hashtable(10);
16.348 + static {
16.349 + defineMapType("bogus", ITEM_Bogus);
16.350 + defineMapType("int", ITEM_Integer);
16.351 + defineMapType("float", ITEM_Float);
16.352 + defineMapType("double", ITEM_Double);
16.353 + defineMapType("long", ITEM_Long);
16.354 + defineMapType("null", ITEM_Null);
16.355 + defineMapType("this", ITEM_InitObject);
16.356 + defineMapType("CP", ITEM_Object);
16.357 + defineMapType("uninitialized", ITEM_NewObject);
16.358 + }
16.359 + private static void defineMapType(String id, int val) {
16.360 + MapTypes.put(id, new Integer(val));
16.361 + if (val>=mapTypeNames.size()) {
16.362 + mapTypeNames.setSize(val+1);
16.363 + }
16.364 + mapTypeNames.setElementAt(id, val);
16.365 + }
16.366 + public static int mapTypeValue(String idValue) {
16.367 + Integer Val=(Integer)(MapTypes.get(idValue));
16.368 + if (Val == null) return -1;
16.369 + return Val.intValue();
16.370 + }
16.371 + public static String mapTypeName(int type) {
16.372 + if (type>=mapTypeNames.size()) return null;
16.373 + return (String)mapTypeNames.elementAt(type);
16.374 + }
16.375 +
16.376 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapData.java Fri Nov 16 08:08:36 2012 +0100
17.3 @@ -0,0 +1,60 @@
17.4 +/*
17.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17.7 + *
17.8 + * This code is free software; you can redistribute it and/or modify it
17.9 + * under the terms of the GNU General Public License version 2 only, as
17.10 + * published by the Free Software Foundation. Oracle designates this
17.11 + * particular file as subject to the "Classpath" exception as provided
17.12 + * by Oracle in the LICENSE file that accompanied this code.
17.13 + *
17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17.17 + * version 2 for more details (a copy is included in the LICENSE file that
17.18 + * accompanied this code).
17.19 + *
17.20 + * You should have received a copy of the GNU General Public License version
17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17.23 + *
17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17.25 + * or visit www.oracle.com if you need additional information or have any
17.26 + * questions.
17.27 + */
17.28 +
17.29 +
17.30 +package org.apidesign.javap;
17.31 +
17.32 +import java.util.*;
17.33 +import java.io.*;
17.34 +
17.35 +/**
17.36 + * Stores exception table data in code attribute.
17.37 + *
17.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
17.39 + */
17.40 +class TrapData {
17.41 + short start_pc, end_pc, handler_pc, catch_cpx;
17.42 + int num;
17.43 +
17.44 +
17.45 + /**
17.46 + * Read and store exception table data in code attribute.
17.47 + */
17.48 + public TrapData(DataInputStream in, int num) throws IOException {
17.49 + this.num=num;
17.50 + start_pc = in.readShort();
17.51 + end_pc=in.readShort();
17.52 + handler_pc=in.readShort();
17.53 + catch_cpx=in.readShort();
17.54 + }
17.55 +
17.56 + /**
17.57 + * returns recommended identifier
17.58 + */
17.59 + public String ident() {
17.60 + return "t"+num;
17.61 + }
17.62 +
17.63 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/javap/src/main/java/org/apidesign/javap/TypeSignature.java Fri Nov 16 08:08:36 2012 +0100
18.3 @@ -0,0 +1,295 @@
18.4 +/*
18.5 + * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18.7 + *
18.8 + * This code is free software; you can redistribute it and/or modify it
18.9 + * under the terms of the GNU General Public License version 2 only, as
18.10 + * published by the Free Software Foundation. Oracle designates this
18.11 + * particular file as subject to the "Classpath" exception as provided
18.12 + * by Oracle in the LICENSE file that accompanied this code.
18.13 + *
18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18.17 + * version 2 for more details (a copy is included in the LICENSE file that
18.18 + * accompanied this code).
18.19 + *
18.20 + * You should have received a copy of the GNU General Public License version
18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18.23 + *
18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
18.25 + * or visit www.oracle.com if you need additional information or have any
18.26 + * questions.
18.27 + */
18.28 +
18.29 +
18.30 +package org.apidesign.javap;
18.31 +
18.32 +import java.util.*;
18.33 +import java.io.*;
18.34 +
18.35 +/**
18.36 + * Returns java type signature.
18.37 + *
18.38 + * @author Sucheta Dambalkar
18.39 + */
18.40 +public class TypeSignature {
18.41 +
18.42 + String parameters = null;
18.43 + String returntype = null;
18.44 + String fieldtype = null;
18.45 + int argumentlength = 0;
18.46 +
18.47 + public TypeSignature(String JVMSignature){
18.48 +
18.49 + if(JVMSignature != null){
18.50 + if(JVMSignature.indexOf("(") == -1){
18.51 + //This is a field type.
18.52 + this.fieldtype = getFieldTypeSignature(JVMSignature);
18.53 + }else {
18.54 + String parameterdes = null;
18.55 + if((JVMSignature.indexOf(")")-1) > (JVMSignature.indexOf("("))){
18.56 + //Get parameter signature.
18.57 + parameterdes =
18.58 + JVMSignature.substring(JVMSignature.indexOf("(")+1,
18.59 + JVMSignature.indexOf(")"));
18.60 + this.parameters = getParametersHelper(parameterdes);
18.61 + }else this.parameters = "()";
18.62 + //Get return type signature.
18.63 + String returndes = JVMSignature.substring(JVMSignature.lastIndexOf(")")+1);
18.64 + this.returntype = getReturnTypeHelper(returndes);
18.65 + }
18.66 + }
18.67 + }
18.68 +
18.69 + /**
18.70 + * Returns java type signature of a field.
18.71 + */
18.72 + public String getFieldTypeSignature(String fielddes){
18.73 + if(fielddes.startsWith("L")){
18.74 + return(getObjectType(fielddes));
18.75 + }else if(fielddes.startsWith("[")){
18.76 + return(getArrayType(fielddes));
18.77 + }else
18.78 + return(getBaseType(fielddes));
18.79 + }
18.80 +
18.81 + /**
18.82 + * Returns java type signature of a parameter.
18.83 + */
18.84 + public String getParametersHelper(String parameterdes){
18.85 + Vector parameters = new Vector();
18.86 + int startindex = -1;
18.87 + int endindex = -1;
18.88 + String param = "";
18.89 +
18.90 + while(parameterdes != null){
18.91 +
18.92 + if(parameterdes.startsWith("L")){
18.93 + //parameter is a object.
18.94 + startindex = parameterdes.indexOf("L");
18.95 + endindex = parameterdes.indexOf(";");
18.96 + if(startindex < parameterdes.length()) {
18.97 + if(endindex == parameterdes.length()-1) {
18.98 + //last parameter
18.99 + param = parameterdes.substring(startindex);
18.100 + parameterdes = null;
18.101 + }else if(endindex+1 < parameterdes.length()){
18.102 + //rest parameters
18.103 + param = parameterdes.substring(startindex, endindex+1);
18.104 + parameterdes = parameterdes.substring(endindex+1);
18.105 +
18.106 + }
18.107 + parameters.add(getObjectType(param));
18.108 + }
18.109 + }else if(parameterdes.startsWith("[")){
18.110 + //parameter is an array.
18.111 + String componentType = "";
18.112 + int enddim = -1;
18.113 + int st = 0;
18.114 + while(true){
18.115 + if(st < parameterdes.length()){
18.116 + if(parameterdes.charAt(st) == '['){
18.117 +
18.118 + enddim = st;
18.119 + st++;
18.120 + }
18.121 + else break;
18.122 + }
18.123 + else break;
18.124 + }
18.125 +
18.126 + if(enddim+1 < parameterdes.length()){
18.127 + /* Array dimension.*/
18.128 + param = parameterdes.substring(0,enddim+1);
18.129 +
18.130 + }
18.131 +
18.132 + int stotherparam = param.lastIndexOf("[")+1;
18.133 +
18.134 + if(stotherparam < parameterdes.length()){
18.135 + componentType = parameterdes.substring(stotherparam);
18.136 + }
18.137 +
18.138 + if(componentType.startsWith("L")){
18.139 + //parameter is array of objects.
18.140 + startindex = parameterdes.indexOf("L");
18.141 + endindex = parameterdes.indexOf(";");
18.142 +
18.143 + if(endindex == parameterdes.length()-1){
18.144 + //last parameter
18.145 + param += parameterdes.substring(startindex);
18.146 + parameterdes = null;
18.147 + }else if(endindex+1 < parameterdes.length()){
18.148 + //rest parameters
18.149 + param += parameterdes.substring(startindex, endindex+1);
18.150 + parameterdes = parameterdes.substring(endindex+1);
18.151 + }
18.152 + }else{
18.153 + //parameter is array of base type.
18.154 + if(componentType.length() == 1){
18.155 + //last parameter.
18.156 + param += componentType;
18.157 + parameterdes = null;
18.158 + }
18.159 + else if (componentType.length() > 1) {
18.160 + //rest parameters.
18.161 + param += componentType.substring(0,1);
18.162 + parameterdes = componentType.substring(1);
18.163 + }
18.164 + }
18.165 + parameters.add(getArrayType(param));
18.166 +
18.167 +
18.168 + }else {
18.169 +
18.170 + //parameter is of base type.
18.171 + if(parameterdes.length() == 1){
18.172 + //last parameter
18.173 + param = parameterdes;
18.174 + parameterdes = null;
18.175 + }
18.176 + else if (parameterdes.length() > 1) {
18.177 + //rest parameters.
18.178 + param = parameterdes.substring(0,1);
18.179 + parameterdes = parameterdes.substring(1);
18.180 + }
18.181 + parameters.add(getBaseType(param));
18.182 + }
18.183 + }
18.184 +
18.185 + /* number of arguments of a method.*/
18.186 + argumentlength = parameters.size();
18.187 +
18.188 + /* java type signature.*/
18.189 + String parametersignature = "(";
18.190 + int i;
18.191 +
18.192 + for(i = 0; i < parameters.size(); i++){
18.193 + parametersignature += (String)parameters.elementAt(i);
18.194 + if(i != parameters.size()-1){
18.195 + parametersignature += ", ";
18.196 + }
18.197 + }
18.198 + parametersignature += ")";
18.199 + return parametersignature;
18.200 + }
18.201 +
18.202 + /**
18.203 + * Returns java type signature for a return type.
18.204 + */
18.205 + public String getReturnTypeHelper(String returndes){
18.206 + return getFieldTypeSignature(returndes);
18.207 + }
18.208 +
18.209 + /**
18.210 + * Returns java type signature for a base type.
18.211 + */
18.212 + public String getBaseType(String baseType){
18.213 + if(baseType != null){
18.214 + if(baseType.equals("B")) return "byte";
18.215 + else if(baseType.equals("C")) return "char";
18.216 + else if(baseType.equals("D")) return "double";
18.217 + else if(baseType.equals("F")) return "float";
18.218 + else if(baseType.equals("I")) return "int";
18.219 + else if(baseType.equals("J")) return "long";
18.220 + else if(baseType.equals("S")) return "short";
18.221 + else if(baseType.equals("Z")) return "boolean";
18.222 + else if(baseType.equals("V")) return "void";
18.223 + }
18.224 + return null;
18.225 + }
18.226 +
18.227 + /**
18.228 + * Returns java type signature for a object type.
18.229 + */
18.230 + public String getObjectType(String JVMobjectType) {
18.231 + String objectType = "";
18.232 + int startindex = JVMobjectType.indexOf("L")+1;
18.233 + int endindex = JVMobjectType.indexOf(";");
18.234 + if((startindex != -1) && (endindex != -1)){
18.235 + if((startindex < JVMobjectType.length()) && (endindex < JVMobjectType.length())){
18.236 + objectType = JVMobjectType.substring(startindex, endindex);
18.237 + }
18.238 + objectType = objectType.replace('/','.');
18.239 + return objectType;
18.240 + }
18.241 + return null;
18.242 + }
18.243 +
18.244 + /**
18.245 + * Returns java type signature for array type.
18.246 + */
18.247 + public String getArrayType(String arrayType) {
18.248 + if(arrayType != null){
18.249 + String dimention = "";
18.250 +
18.251 + while(arrayType.indexOf("[") != -1){
18.252 + dimention += "[]";
18.253 +
18.254 + int startindex = arrayType.indexOf("[")+1;
18.255 + if(startindex <= arrayType.length()){
18.256 + arrayType = arrayType.substring(startindex);
18.257 + }
18.258 + }
18.259 +
18.260 + String componentType = "";
18.261 + if(arrayType.startsWith("L")){
18.262 + componentType = getObjectType(arrayType);
18.263 + }else {
18.264 + componentType = getBaseType(arrayType);
18.265 + }
18.266 + return componentType+dimention;
18.267 + }
18.268 + return null;
18.269 + }
18.270 +
18.271 + /**
18.272 + * Returns java type signature for parameters.
18.273 + */
18.274 + public String getParameters(){
18.275 + return parameters;
18.276 + }
18.277 +
18.278 + /**
18.279 + * Returns java type signature for return type.
18.280 + */
18.281 + public String getReturnType(){
18.282 + return returntype;
18.283 + }
18.284 +
18.285 + /**
18.286 + * Returns java type signature for field type.
18.287 + */
18.288 + public String getFieldType(){
18.289 + return fieldtype;
18.290 + }
18.291 +
18.292 + /**
18.293 + * Return number of arguments of a method.
18.294 + */
18.295 + public int getArgumentlength(){
18.296 + return argumentlength;
18.297 + }
18.298 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/javap/src/main/java/org/apidesign/javap/Vector.java Fri Nov 16 08:08:36 2012 +0100
19.3 @@ -0,0 +1,57 @@
19.4 +/*
19.5 + * To change this template, choose Tools | Templates
19.6 + * and open the template in the editor.
19.7 + */
19.8 +package org.apidesign.javap;
19.9 +
19.10 +/** A JavaScript ready replacement for java.util.Vector
19.11 + *
19.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
19.13 + */
19.14 +final class Vector {
19.15 + private Object[] arr;
19.16 +
19.17 + Vector() {
19.18 + }
19.19 +
19.20 + Vector(int i) {
19.21 + this();
19.22 + }
19.23 +
19.24 + void add(Object objectType) {
19.25 + addElement(objectType);
19.26 + }
19.27 + void addElement(Object obj) {
19.28 + final int s = size();
19.29 + setSize(s + 1);
19.30 + setElementAt(obj, s);
19.31 + }
19.32 +
19.33 + int size() {
19.34 + return arr == null ? 0 : arr.length;
19.35 + }
19.36 +
19.37 + void copyInto(Object[] newArr) {
19.38 + if (arr == null) {
19.39 + return;
19.40 + }
19.41 + int min = Math.min(newArr.length, arr.length);
19.42 + for (int i = 0; i < min; i++) {
19.43 + newArr[i] = arr[i];
19.44 + }
19.45 + }
19.46 +
19.47 + Object elementAt(int index) {
19.48 + return arr[index];
19.49 + }
19.50 +
19.51 + void setSize(int len) {
19.52 + Object[] newArr = new Object[len];
19.53 + copyInto(newArr);
19.54 + arr = newArr;
19.55 + }
19.56 +
19.57 + void setElementAt(Object val, int index) {
19.58 + arr[index] = val;
19.59 + }
19.60 +}
20.1 --- a/javap/src/main/java/sun/tools/javap/AnnotationParser.java Fri Nov 16 08:06:48 2012 +0100
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,98 +0,0 @@
20.4 -/*
20.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
20.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 - *
20.8 - * This code is free software; you can redistribute it and/or modify it
20.9 - * under the terms of the GNU General Public License version 2 only, as
20.10 - * published by the Free Software Foundation. Oracle designates this
20.11 - * particular file as subject to the "Classpath" exception as provided
20.12 - * by Oracle in the LICENSE file that accompanied this code.
20.13 - *
20.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 - * version 2 for more details (a copy is included in the LICENSE file that
20.18 - * accompanied this code).
20.19 - *
20.20 - * You should have received a copy of the GNU General Public License version
20.21 - * 2 along with this work; if not, write to the Free Software Foundation,
20.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 - *
20.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20.25 - * or visit www.oracle.com if you need additional information or have any
20.26 - * questions.
20.27 - */
20.28 -package sun.tools.javap;
20.29 -
20.30 -import java.io.ByteArrayInputStream;
20.31 -import java.io.DataInputStream;
20.32 -import java.io.IOException;
20.33 -
20.34 -/** An abstract parser for annotation definitions. Analyses the bytes and
20.35 - * performs some callbacks to the overriden parser methods.
20.36 - *
20.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
20.38 - */
20.39 -public class AnnotationParser {
20.40 - protected AnnotationParser() {
20.41 - }
20.42 -
20.43 - protected void visitAttr(String type, String attr, String value) {
20.44 - }
20.45 -
20.46 - /** Initialize the parsing with constant pool from <code>cd</code>.
20.47 - *
20.48 - * @param attr the attribute defining annotations
20.49 - * @param cd constant pool
20.50 - * @throws IOException in case I/O fails
20.51 - */
20.52 - public final void parse(byte[] attr, ClassData cd) throws IOException {
20.53 - ByteArrayInputStream is = new ByteArrayInputStream(attr);
20.54 - DataInputStream dis = new DataInputStream(is);
20.55 - try {
20.56 - read(dis, cd);
20.57 - } finally {
20.58 - is.close();
20.59 - }
20.60 - }
20.61 -
20.62 - private void read(DataInputStream dis, ClassData cd) throws IOException {
20.63 - int cnt = dis.readUnsignedShort();
20.64 - for (int i = 0; i < cnt; i++) {
20.65 - readAnno(dis, cd);
20.66 - }
20.67 - }
20.68 -
20.69 - private void readAnno(DataInputStream dis, ClassData cd) throws IOException {
20.70 - int type = dis.readUnsignedShort();
20.71 - String typeName = cd.StringValue(type);
20.72 - int cnt = dis.readUnsignedShort();
20.73 - for (int i = 0; i < cnt; i++) {
20.74 - String attrName = cd.StringValue(dis.readUnsignedShort());
20.75 - readValue(dis, cd, typeName, attrName);
20.76 - }
20.77 - }
20.78 -
20.79 - private void readValue(DataInputStream dis, ClassData cd, String typeName, String attrName)
20.80 - throws IOException {
20.81 - char type = (char)dis.readByte();
20.82 - if (type == '@') {
20.83 - readAnno(dis, cd);
20.84 - } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
20.85 - int primitive = dis.readUnsignedShort();
20.86 - visitAttr(typeName, attrName, cd.StringValue(primitive));
20.87 - } else if (type == 'c') {
20.88 - int cls = dis.readUnsignedShort();
20.89 - } else if (type == '[') {
20.90 - int cnt = dis.readUnsignedShort();
20.91 - for (int i = 0; i < cnt; i++) {
20.92 - readValue(dis, cd, typeName, attrName);
20.93 - }
20.94 - } else if (type == 'e') {
20.95 - int enumT = dis.readUnsignedShort();
20.96 - int enumN = dis.readUnsignedShort();
20.97 - } else {
20.98 - throw new IOException("Unknown type " + type);
20.99 - }
20.100 - }
20.101 -}
21.1 --- a/javap/src/main/java/sun/tools/javap/AttrData.java Fri Nov 16 08:06:48 2012 +0100
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,77 +0,0 @@
21.4 -/*
21.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
21.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21.7 - *
21.8 - * This code is free software; you can redistribute it and/or modify it
21.9 - * under the terms of the GNU General Public License version 2 only, as
21.10 - * published by the Free Software Foundation. Oracle designates this
21.11 - * particular file as subject to the "Classpath" exception as provided
21.12 - * by Oracle in the LICENSE file that accompanied this code.
21.13 - *
21.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
21.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21.17 - * version 2 for more details (a copy is included in the LICENSE file that
21.18 - * accompanied this code).
21.19 - *
21.20 - * You should have received a copy of the GNU General Public License version
21.21 - * 2 along with this work; if not, write to the Free Software Foundation,
21.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21.23 - *
21.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.25 - * or visit www.oracle.com if you need additional information or have any
21.26 - * questions.
21.27 - */
21.28 -
21.29 -
21.30 -
21.31 -package sun.tools.javap;
21.32 -
21.33 -import java.io.*;
21.34 -
21.35 -/**
21.36 - * Reads and stores attribute information.
21.37 - *
21.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
21.39 - */
21.40 -class AttrData {
21.41 - ClassData cls;
21.42 - int name_cpx;
21.43 - int datalen;
21.44 - byte data[];
21.45 -
21.46 - public AttrData (ClassData cls) {
21.47 - this.cls=cls;
21.48 - }
21.49 -
21.50 - /**
21.51 - * Reads unknown attribute.
21.52 - */
21.53 - public void read(int name_cpx, DataInputStream in) throws IOException {
21.54 - this.name_cpx=name_cpx;
21.55 - datalen=in.readInt();
21.56 - data=new byte[datalen];
21.57 - in.readFully(data);
21.58 - }
21.59 -
21.60 - /**
21.61 - * Reads just the name of known attribute.
21.62 - */
21.63 - public void read(int name_cpx){
21.64 - this.name_cpx=name_cpx;
21.65 - }
21.66 -
21.67 - /**
21.68 - * Returns attribute name.
21.69 - */
21.70 - public String getAttrName(){
21.71 - return cls.getString(name_cpx);
21.72 - }
21.73 -
21.74 - /**
21.75 - * Returns attribute data.
21.76 - */
21.77 - public byte[] getData(){
21.78 - return data;
21.79 - }
21.80 -}
22.1 --- a/javap/src/main/java/sun/tools/javap/CPX.java Fri Nov 16 08:06:48 2012 +0100
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,40 +0,0 @@
22.4 -/*
22.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
22.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22.7 - *
22.8 - * This code is free software; you can redistribute it and/or modify it
22.9 - * under the terms of the GNU General Public License version 2 only, as
22.10 - * published by the Free Software Foundation. Oracle designates this
22.11 - * particular file as subject to the "Classpath" exception as provided
22.12 - * by Oracle in the LICENSE file that accompanied this code.
22.13 - *
22.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
22.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22.17 - * version 2 for more details (a copy is included in the LICENSE file that
22.18 - * accompanied this code).
22.19 - *
22.20 - * You should have received a copy of the GNU General Public License version
22.21 - * 2 along with this work; if not, write to the Free Software Foundation,
22.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22.23 - *
22.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22.25 - * or visit www.oracle.com if you need additional information or have any
22.26 - * questions.
22.27 - */
22.28 -
22.29 -
22.30 -package sun.tools.javap;
22.31 -
22.32 -/**
22.33 - * Stores constant pool entry information with one field.
22.34 - *
22.35 - * @author Sucheta Dambalkar (Adopted code from jdis)
22.36 - */
22.37 -class CPX {
22.38 - int cpx;
22.39 -
22.40 - CPX (int cpx) {
22.41 - this.cpx=cpx;
22.42 - }
22.43 -}
23.1 --- a/javap/src/main/java/sun/tools/javap/CPX2.java Fri Nov 16 08:06:48 2012 +0100
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,41 +0,0 @@
23.4 -/*
23.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
23.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 - *
23.8 - * This code is free software; you can redistribute it and/or modify it
23.9 - * under the terms of the GNU General Public License version 2 only, as
23.10 - * published by the Free Software Foundation. Oracle designates this
23.11 - * particular file as subject to the "Classpath" exception as provided
23.12 - * by Oracle in the LICENSE file that accompanied this code.
23.13 - *
23.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 - * version 2 for more details (a copy is included in the LICENSE file that
23.18 - * accompanied this code).
23.19 - *
23.20 - * You should have received a copy of the GNU General Public License version
23.21 - * 2 along with this work; if not, write to the Free Software Foundation,
23.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 - *
23.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23.25 - * or visit www.oracle.com if you need additional information or have any
23.26 - * questions.
23.27 - */
23.28 -
23.29 -
23.30 -package sun.tools.javap;
23.31 -
23.32 -/**
23.33 - * Stores constant pool entry information with two fields.
23.34 - *
23.35 - * @author Sucheta Dambalkar (Adopted code from jdis)
23.36 - */
23.37 -class CPX2 {
23.38 - int cpx1,cpx2;
23.39 -
23.40 - CPX2 (int cpx1, int cpx2) {
23.41 - this.cpx1=cpx1;
23.42 - this.cpx2=cpx2;
23.43 - }
23.44 -}
24.1 --- a/javap/src/main/java/sun/tools/javap/ClassData.java Fri Nov 16 08:06:48 2012 +0100
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,718 +0,0 @@
24.4 -/*
24.5 - * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
24.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24.7 - *
24.8 - * This code is free software; you can redistribute it and/or modify it
24.9 - * under the terms of the GNU General Public License version 2 only, as
24.10 - * published by the Free Software Foundation. Oracle designates this
24.11 - * particular file as subject to the "Classpath" exception as provided
24.12 - * by Oracle in the LICENSE file that accompanied this code.
24.13 - *
24.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
24.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24.17 - * version 2 for more details (a copy is included in the LICENSE file that
24.18 - * accompanied this code).
24.19 - *
24.20 - * You should have received a copy of the GNU General Public License version
24.21 - * 2 along with this work; if not, write to the Free Software Foundation,
24.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24.23 - *
24.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24.25 - * or visit www.oracle.com if you need additional information or have any
24.26 - * questions.
24.27 - */
24.28 -
24.29 -
24.30 -package sun.tools.javap;
24.31 -
24.32 -import java.io.*;
24.33 -
24.34 -/**
24.35 - * Central data repository of the Java Disassembler.
24.36 - * Stores all the information in java class file.
24.37 - *
24.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
24.39 - */
24.40 -public final class ClassData implements RuntimeConstants {
24.41 -
24.42 - private int magic;
24.43 - private int minor_version;
24.44 - private int major_version;
24.45 - private int cpool_count;
24.46 - private Object cpool[];
24.47 - private int access;
24.48 - private int this_class = 0;;
24.49 - private int super_class;
24.50 - private int interfaces_count;
24.51 - private int[] interfaces = new int[0];;
24.52 - private int fields_count;
24.53 - private FieldData[] fields;
24.54 - private int methods_count;
24.55 - private MethodData[] methods;
24.56 - private InnerClassData[] innerClasses;
24.57 - private int attributes_count;
24.58 - private AttrData[] attrs;
24.59 - private String classname;
24.60 - private String superclassname;
24.61 - private int source_cpx=0;
24.62 - private byte tags[];
24.63 - private Hashtable indexHashAscii = new Hashtable();
24.64 - private String pkgPrefix="";
24.65 - private int pkgPrefixLen=0;
24.66 -
24.67 - /**
24.68 - * Read classfile to disassemble.
24.69 - */
24.70 - public ClassData(InputStream infile) throws IOException {
24.71 - this.read(new DataInputStream(infile));
24.72 - }
24.73 -
24.74 - /**
24.75 - * Reads and stores class file information.
24.76 - */
24.77 - public void read(DataInputStream in) throws IOException {
24.78 - // Read the header
24.79 - magic = in.readInt();
24.80 - if (magic != JAVA_MAGIC) {
24.81 - throw new ClassFormatError("wrong magic: " +
24.82 - toHex(magic) + ", expected " +
24.83 - toHex(JAVA_MAGIC));
24.84 - }
24.85 - minor_version = in.readShort();
24.86 - major_version = in.readShort();
24.87 - if (major_version != JAVA_VERSION) {
24.88 - }
24.89 -
24.90 - // Read the constant pool
24.91 - readCP(in);
24.92 - access = in.readUnsignedShort();
24.93 - this_class = in.readUnsignedShort();
24.94 - super_class = in.readUnsignedShort();
24.95 -
24.96 - //Read interfaces.
24.97 - interfaces_count = in.readUnsignedShort();
24.98 - if(interfaces_count > 0){
24.99 - interfaces = new int[interfaces_count];
24.100 - }
24.101 - for (int i = 0; i < interfaces_count; i++) {
24.102 - interfaces[i]=in.readShort();
24.103 - }
24.104 -
24.105 - // Read the fields
24.106 - readFields(in);
24.107 -
24.108 - // Read the methods
24.109 - readMethods(in);
24.110 -
24.111 - // Read the attributes
24.112 - attributes_count = in.readUnsignedShort();
24.113 - attrs=new AttrData[attributes_count];
24.114 - for (int k = 0; k < attributes_count; k++) {
24.115 - int name_cpx=in.readUnsignedShort();
24.116 - if (getTag(name_cpx)==CONSTANT_UTF8
24.117 - && getString(name_cpx).equals("SourceFile")
24.118 - ){ if (in.readInt()!=2)
24.119 - throw new ClassFormatError("invalid attr length");
24.120 - source_cpx=in.readUnsignedShort();
24.121 - AttrData attr=new AttrData(this);
24.122 - attr.read(name_cpx);
24.123 - attrs[k]=attr;
24.124 -
24.125 - } else if (getTag(name_cpx)==CONSTANT_UTF8
24.126 - && getString(name_cpx).equals("InnerClasses")
24.127 - ){ int length=in.readInt();
24.128 - int num=in.readUnsignedShort();
24.129 - if (2+num*8 != length)
24.130 - throw new ClassFormatError("invalid attr length");
24.131 - innerClasses=new InnerClassData[num];
24.132 - for (int j = 0; j < num; j++) {
24.133 - InnerClassData innerClass=new InnerClassData(this);
24.134 - innerClass.read(in);
24.135 - innerClasses[j]=innerClass;
24.136 - }
24.137 - AttrData attr=new AttrData(this);
24.138 - attr.read(name_cpx);
24.139 - attrs[k]=attr;
24.140 - } else {
24.141 - AttrData attr=new AttrData(this);
24.142 - attr.read(name_cpx, in);
24.143 - attrs[k]=attr;
24.144 - }
24.145 - }
24.146 - in.close();
24.147 - } // end ClassData.read()
24.148 -
24.149 - /**
24.150 - * Reads and stores constant pool info.
24.151 - */
24.152 - void readCP(DataInputStream in) throws IOException {
24.153 - cpool_count = in.readUnsignedShort();
24.154 - tags = new byte[cpool_count];
24.155 - cpool = new Object[cpool_count];
24.156 - for (int i = 1; i < cpool_count; i++) {
24.157 - byte tag = in.readByte();
24.158 -
24.159 - switch(tags[i] = tag) {
24.160 - case CONSTANT_UTF8:
24.161 - String str=in.readUTF();
24.162 - indexHashAscii.put(cpool[i] = str, new Integer(i));
24.163 - break;
24.164 - case CONSTANT_INTEGER:
24.165 - cpool[i] = new Integer(in.readInt());
24.166 - break;
24.167 - case CONSTANT_FLOAT:
24.168 - cpool[i] = new Float(in.readFloat());
24.169 - break;
24.170 - case CONSTANT_LONG:
24.171 - cpool[i++] = new Long(in.readLong());
24.172 - break;
24.173 - case CONSTANT_DOUBLE:
24.174 - cpool[i++] = new Double(in.readDouble());
24.175 - break;
24.176 - case CONSTANT_CLASS:
24.177 - case CONSTANT_STRING:
24.178 - cpool[i] = new CPX(in.readUnsignedShort());
24.179 - break;
24.180 -
24.181 - case CONSTANT_FIELD:
24.182 - case CONSTANT_METHOD:
24.183 - case CONSTANT_INTERFACEMETHOD:
24.184 - case CONSTANT_NAMEANDTYPE:
24.185 - cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
24.186 - break;
24.187 -
24.188 - case 0:
24.189 - default:
24.190 - throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
24.191 - }
24.192 - }
24.193 - }
24.194 -
24.195 - /**
24.196 - * Reads and strores field info.
24.197 - */
24.198 - protected void readFields(DataInputStream in) throws IOException {
24.199 - int fields_count = in.readUnsignedShort();
24.200 - fields=new FieldData[fields_count];
24.201 - for (int k = 0; k < fields_count; k++) {
24.202 - FieldData field=new FieldData(this);
24.203 - field.read(in);
24.204 - fields[k]=field;
24.205 - }
24.206 - }
24.207 -
24.208 - /**
24.209 - * Reads and strores Method info.
24.210 - */
24.211 - protected void readMethods(DataInputStream in) throws IOException {
24.212 - int methods_count = in.readUnsignedShort();
24.213 - methods=new MethodData[methods_count];
24.214 - for (int k = 0; k < methods_count ; k++) {
24.215 - MethodData method=new MethodData(this);
24.216 - method.read(in);
24.217 - methods[k]=method;
24.218 - }
24.219 - }
24.220 -
24.221 - /**
24.222 - * get a string
24.223 - */
24.224 - public String getString(int n) {
24.225 - if (n == 0) {
24.226 - return null;
24.227 - } else {
24.228 - return (String)cpool[n];
24.229 - }
24.230 - }
24.231 -
24.232 - /**
24.233 - * get the type of constant given an index
24.234 - */
24.235 - public byte getTag(int n) {
24.236 - try{
24.237 - return tags[n];
24.238 - } catch (ArrayIndexOutOfBoundsException e) {
24.239 - return (byte)100;
24.240 - }
24.241 - }
24.242 -
24.243 - static final String hexString="0123456789ABCDEF";
24.244 -
24.245 - public static char hexTable[]=hexString.toCharArray();
24.246 -
24.247 - static String toHex(long val, int width) {
24.248 - StringBuffer s = new StringBuffer();
24.249 - for (int i=width-1; i>=0; i--)
24.250 - s.append(hexTable[((int)(val>>(4*i)))&0xF]);
24.251 - return "0x"+s.toString();
24.252 - }
24.253 -
24.254 - static String toHex(long val) {
24.255 - int width;
24.256 - for (width=16; width>0; width--) {
24.257 - if ((val>>(width-1)*4)!=0) break;
24.258 - }
24.259 - return toHex(val, width);
24.260 - }
24.261 -
24.262 - static String toHex(int val) {
24.263 - int width;
24.264 - for (width=8; width>0; width--) {
24.265 - if ((val>>(width-1)*4)!=0) break;
24.266 - }
24.267 - return toHex(val, width);
24.268 - }
24.269 -
24.270 - /**
24.271 - * Returns the name of this class.
24.272 - */
24.273 - public String getClassName() {
24.274 - String res=null;
24.275 - if (this_class==0) {
24.276 - return res;
24.277 - }
24.278 - int tcpx;
24.279 - try {
24.280 - if (tags[this_class]!=CONSTANT_CLASS) {
24.281 - return res; //"<CP["+cpx+"] is not a Class> ";
24.282 - }
24.283 - tcpx=((CPX)cpool[this_class]).cpx;
24.284 - } catch (ArrayIndexOutOfBoundsException e) {
24.285 - return res; // "#"+cpx+"// invalid constant pool index";
24.286 - } catch (Throwable e) {
24.287 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.288 - }
24.289 -
24.290 - try {
24.291 - return (String)(cpool[tcpx]);
24.292 - } catch (ArrayIndexOutOfBoundsException e) {
24.293 - return res; // "class #"+scpx+"// invalid constant pool index";
24.294 - } catch (ClassCastException e) {
24.295 - return res; // "class #"+scpx+"// invalid constant pool reference";
24.296 - } catch (Throwable e) {
24.297 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.298 - }
24.299 -
24.300 - }
24.301 -
24.302 - /**
24.303 - * Returns the name of class at perticular index.
24.304 - */
24.305 - public String getClassName(int cpx) {
24.306 - String res="#"+cpx;
24.307 - if (cpx==0) {
24.308 - return res;
24.309 - }
24.310 - int scpx;
24.311 - try {
24.312 - if (tags[cpx]!=CONSTANT_CLASS) {
24.313 - return res; //"<CP["+cpx+"] is not a Class> ";
24.314 - }
24.315 - scpx=((CPX)cpool[cpx]).cpx;
24.316 - } catch (ArrayIndexOutOfBoundsException e) {
24.317 - return res; // "#"+cpx+"// invalid constant pool index";
24.318 - } catch (Throwable e) {
24.319 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.320 - }
24.321 - res="#"+scpx;
24.322 - try {
24.323 - return (String)(cpool[scpx]);
24.324 - } catch (ArrayIndexOutOfBoundsException e) {
24.325 - return res; // "class #"+scpx+"// invalid constant pool index";
24.326 - } catch (ClassCastException e) {
24.327 - return res; // "class #"+scpx+"// invalid constant pool reference";
24.328 - } catch (Throwable e) {
24.329 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.330 - }
24.331 - }
24.332 -
24.333 - /**
24.334 - * Returns true if it is a class
24.335 - */
24.336 - public boolean isClass() {
24.337 - if((access & ACC_INTERFACE) == 0) return true;
24.338 - return false;
24.339 - }
24.340 -
24.341 - /**
24.342 - * Returns true if it is a interface.
24.343 - */
24.344 - public boolean isInterface(){
24.345 - if((access & ACC_INTERFACE) != 0) return true;
24.346 - return false;
24.347 - }
24.348 -
24.349 - /**
24.350 - * Returns true if this member is public, false otherwise.
24.351 - */
24.352 - public boolean isPublic(){
24.353 - return (access & ACC_PUBLIC) != 0;
24.354 - }
24.355 -
24.356 - /**
24.357 - * Returns the access of this class or interface.
24.358 - */
24.359 - public String[] getAccess(){
24.360 - Vector v = new Vector();
24.361 - if ((access & ACC_PUBLIC) !=0) v.addElement("public");
24.362 - if ((access & ACC_FINAL) !=0) v.addElement("final");
24.363 - if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
24.364 - String[] accflags = new String[v.size()];
24.365 - v.copyInto(accflags);
24.366 - return accflags;
24.367 - }
24.368 -
24.369 - /**
24.370 - * Returns list of innerclasses.
24.371 - */
24.372 - public InnerClassData[] getInnerClasses(){
24.373 - return innerClasses;
24.374 - }
24.375 -
24.376 - /**
24.377 - * Returns list of attributes.
24.378 - */
24.379 - final AttrData[] getAttributes(){
24.380 - return attrs;
24.381 - }
24.382 -
24.383 - public byte[] findAnnotationData(boolean classRetention) {
24.384 - String n = classRetention ?
24.385 - "RuntimeInvisibleAnnotations" : // NOI18N
24.386 - "RuntimeVisibleAnnotations"; // NOI18N
24.387 - return findAttr(n, attrs);
24.388 - }
24.389 -
24.390 - /**
24.391 - * Returns true if superbit is set.
24.392 - */
24.393 - public boolean isSuperSet(){
24.394 - if ((access & ACC_SUPER) !=0) return true;
24.395 - return false;
24.396 - }
24.397 -
24.398 - /**
24.399 - * Returns super class name.
24.400 - */
24.401 - public String getSuperClassName(){
24.402 - String res=null;
24.403 - if (super_class==0) {
24.404 - return res;
24.405 - }
24.406 - int scpx;
24.407 - try {
24.408 - if (tags[super_class]!=CONSTANT_CLASS) {
24.409 - return res; //"<CP["+cpx+"] is not a Class> ";
24.410 - }
24.411 - scpx=((CPX)cpool[super_class]).cpx;
24.412 - } catch (ArrayIndexOutOfBoundsException e) {
24.413 - return res; // "#"+cpx+"// invalid constant pool index";
24.414 - } catch (Throwable e) {
24.415 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.416 - }
24.417 -
24.418 - try {
24.419 - return (String)(cpool[scpx]);
24.420 - } catch (ArrayIndexOutOfBoundsException e) {
24.421 - return res; // "class #"+scpx+"// invalid constant pool index";
24.422 - } catch (ClassCastException e) {
24.423 - return res; // "class #"+scpx+"// invalid constant pool reference";
24.424 - } catch (Throwable e) {
24.425 - return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
24.426 - }
24.427 - }
24.428 -
24.429 - /**
24.430 - * Returns list of super interfaces.
24.431 - */
24.432 - public String[] getSuperInterfaces(){
24.433 - String interfacenames[] = new String[interfaces.length];
24.434 - int interfacecpx = -1;
24.435 - for(int i = 0; i < interfaces.length; i++){
24.436 - interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
24.437 - interfacenames[i] = (String)(cpool[interfacecpx]);
24.438 - }
24.439 - return interfacenames;
24.440 - }
24.441 -
24.442 - /**
24.443 - * Returns string at prticular constant pool index.
24.444 - */
24.445 - public String getStringValue(int cpoolx) {
24.446 - try {
24.447 - return ((String)cpool[cpoolx]);
24.448 - } catch (ArrayIndexOutOfBoundsException e) {
24.449 - return "//invalid constant pool index:"+cpoolx;
24.450 - } catch (ClassCastException e) {
24.451 - return "//invalid constant pool ref:"+cpoolx;
24.452 - }
24.453 - }
24.454 -
24.455 - /**
24.456 - * Returns list of field info.
24.457 - */
24.458 - public FieldData[] getFields(){
24.459 - return fields;
24.460 - }
24.461 -
24.462 - /**
24.463 - * Returns list of method info.
24.464 - */
24.465 - public MethodData[] getMethods(){
24.466 - return methods;
24.467 - }
24.468 -
24.469 - /**
24.470 - * Returns constant pool entry at that index.
24.471 - */
24.472 - public CPX2 getCpoolEntry(int cpx){
24.473 - return ((CPX2)(cpool[cpx]));
24.474 - }
24.475 -
24.476 - public Object getCpoolEntryobj(int cpx){
24.477 - return (cpool[cpx]);
24.478 - }
24.479 -
24.480 - /**
24.481 - * Returns index of this class.
24.482 - */
24.483 - public int getthis_cpx(){
24.484 - return this_class;
24.485 - }
24.486 -
24.487 - public String TagString (int tag) {
24.488 - String res=Tables.tagName(tag);
24.489 - if (res==null) return "BOGUS_TAG:"+tag;
24.490 - return res;
24.491 - }
24.492 -
24.493 - /**
24.494 - * Returns string at that index.
24.495 - */
24.496 - public String StringValue(int cpx) {
24.497 - return stringValue(cpx, false);
24.498 - }
24.499 - public String stringValue(int cpx, boolean textual) {
24.500 - if (cpx==0) return "#0";
24.501 - int tag;
24.502 - Object x;
24.503 - String suffix="";
24.504 - try {
24.505 - tag=tags[cpx];
24.506 - x=cpool[cpx];
24.507 - } catch (IndexOutOfBoundsException e) {
24.508 - return "<Incorrect CP index:"+cpx+">";
24.509 - }
24.510 -
24.511 - if (x==null) return "<NULL>";
24.512 - switch (tag) {
24.513 - case CONSTANT_UTF8: {
24.514 - if (!textual) {
24.515 - return (String)x;
24.516 - }
24.517 - StringBuilder sb=new StringBuilder();
24.518 - String s=(String)x;
24.519 - for (int k=0; k<s.length(); k++) {
24.520 - char c=s.charAt(k);
24.521 - switch (c) {
24.522 - case '\\': sb.append('\\').append('\\'); break;
24.523 - case '\t': sb.append('\\').append('t'); break;
24.524 - case '\n': sb.append('\\').append('n'); break;
24.525 - case '\r': sb.append('\\').append('r'); break;
24.526 - case '\"': sb.append('\\').append('\"'); break;
24.527 - default: sb.append(c);
24.528 - }
24.529 - }
24.530 - return sb.toString();
24.531 - }
24.532 - case CONSTANT_DOUBLE: {
24.533 - Double d=(Double)x;
24.534 - String sd=d.toString();
24.535 - if (textual) {
24.536 - return sd;
24.537 - }
24.538 - return sd+"d";
24.539 - }
24.540 - case CONSTANT_FLOAT: {
24.541 - Float f=(Float)x;
24.542 - String sf=(f).toString();
24.543 - if (textual) {
24.544 - return sf;
24.545 - }
24.546 - return sf+"f";
24.547 - }
24.548 - case CONSTANT_LONG: {
24.549 - Long ln = (Long)x;
24.550 - if (textual) {
24.551 - return ln.toString();
24.552 - }
24.553 - return ln.toString()+'l';
24.554 - }
24.555 - case CONSTANT_INTEGER: {
24.556 - Integer in = (Integer)x;
24.557 - return in.toString();
24.558 - }
24.559 - case CONSTANT_CLASS:
24.560 - if (textual) {
24.561 - return "new java_lang_Class"; // XXX temporary JS
24.562 - }
24.563 - return javaName(getClassName(cpx));
24.564 - case CONSTANT_STRING:
24.565 - String sv = stringValue(((CPX)x).cpx, textual);
24.566 - if (textual) {
24.567 - return '"' + sv + '"';
24.568 - } else {
24.569 - return sv;
24.570 - }
24.571 - case CONSTANT_FIELD:
24.572 - case CONSTANT_METHOD:
24.573 - case CONSTANT_INTERFACEMETHOD:
24.574 - //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
24.575 - return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
24.576 -
24.577 - case CONSTANT_NAMEANDTYPE:
24.578 - return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
24.579 - default:
24.580 - return "UnknownTag"; //TBD
24.581 - }
24.582 - }
24.583 -
24.584 - /**
24.585 - * Returns resolved java type name.
24.586 - */
24.587 - public String javaName(String name) {
24.588 - if( name==null) return "null";
24.589 - int len=name.length();
24.590 - if (len==0) return "\"\"";
24.591 - int cc='/';
24.592 - fullname: { // xxx/yyy/zzz
24.593 - int cp;
24.594 - for (int k=0; k<len; k += Character.charCount(cp)) {
24.595 - cp=name.codePointAt(k);
24.596 - if (cc=='/') {
24.597 - if (!isJavaIdentifierStart(cp)) break fullname;
24.598 - } else if (cp!='/') {
24.599 - if (!isJavaIdentifierPart(cp)) break fullname;
24.600 - }
24.601 - cc=cp;
24.602 - }
24.603 - return name;
24.604 - }
24.605 - return "\""+name+"\"";
24.606 - }
24.607 -
24.608 - public String getName(int cpx) {
24.609 - String res;
24.610 - try {
24.611 - return javaName((String)cpool[cpx]); //.replace('/','.');
24.612 - } catch (ArrayIndexOutOfBoundsException e) {
24.613 - return "<invalid constant pool index:"+cpx+">";
24.614 - } catch (ClassCastException e) {
24.615 - return "<invalid constant pool ref:"+cpx+">";
24.616 - }
24.617 - }
24.618 -
24.619 - /**
24.620 - * Returns unqualified class name.
24.621 - */
24.622 - public String getShortClassName(int cpx) {
24.623 - String classname=javaName(getClassName(cpx));
24.624 - pkgPrefixLen=classname.lastIndexOf("/")+1;
24.625 - if (pkgPrefixLen!=0) {
24.626 - pkgPrefix=classname.substring(0,pkgPrefixLen);
24.627 - if (classname.startsWith(pkgPrefix)) {
24.628 - return classname.substring(pkgPrefixLen);
24.629 - }
24.630 - }
24.631 - return classname;
24.632 - }
24.633 -
24.634 - /**
24.635 - * Returns source file name.
24.636 - */
24.637 - public String getSourceName(){
24.638 - return getName(source_cpx);
24.639 - }
24.640 -
24.641 - /**
24.642 - * Returns package name.
24.643 - */
24.644 - public String getPkgName(){
24.645 - String classname=getClassName(this_class);
24.646 - pkgPrefixLen=classname.lastIndexOf("/")+1;
24.647 - if (pkgPrefixLen!=0) {
24.648 - pkgPrefix=classname.substring(0,pkgPrefixLen);
24.649 - return("package "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
24.650 - }else return null;
24.651 - }
24.652 -
24.653 - /**
24.654 - * Returns total constant pool entry count.
24.655 - */
24.656 - public int getCpoolCount(){
24.657 - return cpool_count;
24.658 - }
24.659 -
24.660 - public String StringTag(int cpx) {
24.661 - byte tag=0;
24.662 - String str=null;
24.663 - try {
24.664 - if (cpx==0) throw new IndexOutOfBoundsException();
24.665 - tag=tags[cpx];
24.666 - return TagString(tag);
24.667 - } catch (IndexOutOfBoundsException e) {
24.668 - str="Incorrect CP index:"+cpx;
24.669 - }
24.670 - return str;
24.671 - }
24.672 -
24.673 - /**
24.674 - * Returns minor version of class file.
24.675 - */
24.676 - public int getMinor_version(){
24.677 - return minor_version;
24.678 - }
24.679 -
24.680 - /**
24.681 - * Returns major version of class file.
24.682 - */
24.683 - public int getMajor_version(){
24.684 - return major_version;
24.685 - }
24.686 -
24.687 - private boolean isJavaIdentifierStart(int cp) {
24.688 - return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
24.689 - }
24.690 -
24.691 - private boolean isJavaIdentifierPart(int cp) {
24.692 - return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
24.693 - }
24.694 -
24.695 - public String[] getNameAndType(int indx) {
24.696 - return getNameAndType(indx, 0, new String[2]);
24.697 - }
24.698 -
24.699 - private String[] getNameAndType(int indx, int at, String[] arr) {
24.700 - CPX2 c2 = getCpoolEntry(indx);
24.701 - arr[at] = StringValue(c2.cpx1);
24.702 - arr[at + 1] = StringValue(c2.cpx2);
24.703 - return arr;
24.704 - }
24.705 -
24.706 - public String[] getFieldInfoName(int indx) {
24.707 - CPX2 c2 = getCpoolEntry(indx);
24.708 - String[] arr = new String[3];
24.709 - arr[0] = getClassName(c2.cpx1);
24.710 - return getNameAndType(c2.cpx2, 1, arr);
24.711 - }
24.712 -
24.713 - static byte[] findAttr(String n, AttrData[] attrs) {
24.714 - for (AttrData ad : attrs) {
24.715 - if (n.equals(ad.getAttrName())) {
24.716 - return ad.getData();
24.717 - }
24.718 - }
24.719 - return null;
24.720 - }
24.721 -}
25.1 --- a/javap/src/main/java/sun/tools/javap/Constants.java Fri Nov 16 08:06:48 2012 +0100
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,372 +0,0 @@
25.4 -/*
25.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
25.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25.7 - *
25.8 - * This code is free software; you can redistribute it and/or modify it
25.9 - * under the terms of the GNU General Public License version 2 only, as
25.10 - * published by the Free Software Foundation. Oracle designates this
25.11 - * particular file as subject to the "Classpath" exception as provided
25.12 - * by Oracle in the LICENSE file that accompanied this code.
25.13 - *
25.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
25.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25.17 - * version 2 for more details (a copy is included in the LICENSE file that
25.18 - * accompanied this code).
25.19 - *
25.20 - * You should have received a copy of the GNU General Public License version
25.21 - * 2 along with this work; if not, write to the Free Software Foundation,
25.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25.23 - *
25.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25.25 - * or visit www.oracle.com if you need additional information or have any
25.26 - * questions.
25.27 - */
25.28 -
25.29 -
25.30 -
25.31 -package sun.tools.javap;
25.32 -
25.33 -/**
25.34 - * This interface defines constant that are used
25.35 - * throughout the compiler. It inherits from RuntimeConstants,
25.36 - * which is an autogenerated class that contains contstants
25.37 - * defined in the interpreter.
25.38 - */
25.39 -
25.40 -public
25.41 -interface Constants extends RuntimeConstants {
25.42 -
25.43 - /**
25.44 - * End of input
25.45 - */
25.46 - public static final int EOF = -1;
25.47 -
25.48 - /*
25.49 - * Flags
25.50 - */
25.51 - public static final int F_VERBOSE = 1 << 0;
25.52 - public static final int F_DUMP = 1 << 1;
25.53 - public static final int F_WARNINGS = 1 << 2;
25.54 - public static final int F_DEBUG = 1 << 3;
25.55 - public static final int F_OPTIMIZE = 1 << 4;
25.56 - public static final int F_DEPENDENCIES = 1 << 5;
25.57 -
25.58 - /*
25.59 - * Type codes
25.60 - */
25.61 - public static final int TC_BOOLEAN = 0;
25.62 - public static final int TC_BYTE = 1;
25.63 - public static final int TC_CHAR = 2;
25.64 - public static final int TC_SHORT = 3;
25.65 - public static final int TC_INT = 4;
25.66 - public static final int TC_LONG = 5;
25.67 - public static final int TC_FLOAT = 6;
25.68 - public static final int TC_DOUBLE = 7;
25.69 - public static final int TC_NULL = 8;
25.70 - public static final int TC_ARRAY = 9;
25.71 - public static final int TC_CLASS = 10;
25.72 - public static final int TC_VOID = 11;
25.73 - public static final int TC_METHOD = 12;
25.74 - public static final int TC_ERROR = 13;
25.75 -
25.76 - /*
25.77 - * Type Masks
25.78 - */
25.79 - public static final int TM_NULL = 1 << TC_NULL;
25.80 - public static final int TM_VOID = 1 << TC_VOID;
25.81 - public static final int TM_BOOLEAN = 1 << TC_BOOLEAN;
25.82 - public static final int TM_BYTE = 1 << TC_BYTE;
25.83 - public static final int TM_CHAR = 1 << TC_CHAR;
25.84 - public static final int TM_SHORT = 1 << TC_SHORT;
25.85 - public static final int TM_INT = 1 << TC_INT;
25.86 - public static final int TM_LONG = 1 << TC_LONG;
25.87 - public static final int TM_FLOAT = 1 << TC_FLOAT;
25.88 - public static final int TM_DOUBLE = 1 << TC_DOUBLE;
25.89 - public static final int TM_ARRAY = 1 << TC_ARRAY;
25.90 - public static final int TM_CLASS = 1 << TC_CLASS;
25.91 - public static final int TM_METHOD = 1 << TC_METHOD;
25.92 - public static final int TM_ERROR = 1 << TC_ERROR;
25.93 -
25.94 - public static final int TM_INT32 = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
25.95 - public static final int TM_NUM32 = TM_INT32 | TM_FLOAT;
25.96 - public static final int TM_NUM64 = TM_LONG | TM_DOUBLE;
25.97 - public static final int TM_INTEGER = TM_INT32 | TM_LONG;
25.98 - public static final int TM_REAL = TM_FLOAT | TM_DOUBLE;
25.99 - public static final int TM_NUMBER = TM_INTEGER | TM_REAL;
25.100 - public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
25.101 -
25.102 - /*
25.103 - * Class status
25.104 - */
25.105 - public static final int CS_UNDEFINED = 0;
25.106 - public static final int CS_UNDECIDED = 1;
25.107 - public static final int CS_BINARY = 2;
25.108 - public static final int CS_SOURCE = 3;
25.109 - public static final int CS_PARSED = 4;
25.110 - public static final int CS_COMPILED = 5;
25.111 - public static final int CS_NOTFOUND = 6;
25.112 -
25.113 - /*
25.114 - * Attributes
25.115 - */
25.116 - public static final int ATT_ALL = -1;
25.117 - public static final int ATT_CODE = 1;
25.118 -
25.119 - /*
25.120 - * Number of bits used in file offsets
25.121 - */
25.122 - public static final int OFFSETBITS = 19;
25.123 - public static final int MAXFILESIZE = (1 << OFFSETBITS) - 1;
25.124 - public static final int MAXLINENUMBER = (1 << (32 - OFFSETBITS)) - 1;
25.125 -
25.126 - /*
25.127 - * Operators
25.128 - */
25.129 - public final int COMMA = 0;
25.130 - public final int ASSIGN = 1;
25.131 -
25.132 - public final int ASGMUL = 2;
25.133 - public final int ASGDIV = 3;
25.134 - public final int ASGREM = 4;
25.135 - public final int ASGADD = 5;
25.136 - public final int ASGSUB = 6;
25.137 - public final int ASGLSHIFT = 7;
25.138 - public final int ASGRSHIFT = 8;
25.139 - public final int ASGURSHIFT = 9;
25.140 - public final int ASGBITAND = 10;
25.141 - public final int ASGBITOR = 11;
25.142 - public final int ASGBITXOR = 12;
25.143 -
25.144 - public final int COND = 13;
25.145 - public final int OR = 14;
25.146 - public final int AND = 15;
25.147 - public final int BITOR = 16;
25.148 - public final int BITXOR = 17;
25.149 - public final int BITAND = 18;
25.150 - public final int NE = 19;
25.151 - public final int EQ = 20;
25.152 - public final int GE = 21;
25.153 - public final int GT = 22;
25.154 - public final int LE = 23;
25.155 - public final int LT = 24;
25.156 - public final int INSTANCEOF = 25;
25.157 - public final int LSHIFT = 26;
25.158 - public final int RSHIFT = 27;
25.159 - public final int URSHIFT = 28;
25.160 - public final int ADD = 29;
25.161 - public final int SUB = 30;
25.162 - public final int DIV = 31;
25.163 - public final int REM = 32;
25.164 - public final int MUL = 33;
25.165 - public final int CAST = 34; // (x)y
25.166 - public final int POS = 35; // +x
25.167 - public final int NEG = 36; // -x
25.168 - public final int NOT = 37;
25.169 - public final int BITNOT = 38;
25.170 - public final int PREINC = 39; // ++x
25.171 - public final int PREDEC = 40; // --x
25.172 - public final int NEWARRAY = 41;
25.173 - public final int NEWINSTANCE = 42;
25.174 - public final int NEWFROMNAME = 43;
25.175 - public final int POSTINC = 44; // x++
25.176 - public final int POSTDEC = 45; // x--
25.177 - public final int FIELD = 46;
25.178 - public final int METHOD = 47; // x(y)
25.179 - public final int ARRAYACCESS = 48; // x[y]
25.180 - public final int NEW = 49;
25.181 - public final int INC = 50;
25.182 - public final int DEC = 51;
25.183 -
25.184 - public final int CONVERT = 55; // implicit conversion
25.185 - public final int EXPR = 56; // (x)
25.186 - public final int ARRAY = 57; // {x, y, ...}
25.187 - public final int GOTO = 58;
25.188 -
25.189 - /*
25.190 - * Value tokens
25.191 - */
25.192 - public final int IDENT = 60;
25.193 - public final int BOOLEANVAL = 61;
25.194 - public final int BYTEVAL = 62;
25.195 - public final int CHARVAL = 63;
25.196 - public final int SHORTVAL = 64;
25.197 - public final int INTVAL = 65;
25.198 - public final int LONGVAL = 66;
25.199 - public final int FLOATVAL = 67;
25.200 - public final int DOUBLEVAL = 68;
25.201 - public final int STRINGVAL = 69;
25.202 -
25.203 - /*
25.204 - * Type keywords
25.205 - */
25.206 - public final int BYTE = 70;
25.207 - public final int CHAR = 71;
25.208 - public final int SHORT = 72;
25.209 - public final int INT = 73;
25.210 - public final int LONG = 74;
25.211 - public final int FLOAT = 75;
25.212 - public final int DOUBLE = 76;
25.213 - public final int VOID = 77;
25.214 - public final int BOOLEAN = 78;
25.215 -
25.216 - /*
25.217 - * Expression keywords
25.218 - */
25.219 - public final int TRUE = 80;
25.220 - public final int FALSE = 81;
25.221 - public final int THIS = 82;
25.222 - public final int SUPER = 83;
25.223 - public final int NULL = 84;
25.224 -
25.225 - /*
25.226 - * Statement keywords
25.227 - */
25.228 - public final int IF = 90;
25.229 - public final int ELSE = 91;
25.230 - public final int FOR = 92;
25.231 - public final int WHILE = 93;
25.232 - public final int DO = 94;
25.233 - public final int SWITCH = 95;
25.234 - public final int CASE = 96;
25.235 - public final int DEFAULT = 97;
25.236 - public final int BREAK = 98;
25.237 - public final int CONTINUE = 99;
25.238 - public final int RETURN = 100;
25.239 - public final int TRY = 101;
25.240 - public final int CATCH = 102;
25.241 - public final int FINALLY = 103;
25.242 - public final int THROW = 104;
25.243 - public final int STAT = 105;
25.244 - public final int EXPRESSION = 106;
25.245 - public final int DECLARATION = 107;
25.246 - public final int VARDECLARATION = 108;
25.247 -
25.248 - /*
25.249 - * Declaration keywords
25.250 - */
25.251 - public final int IMPORT = 110;
25.252 - public final int CLASS = 111;
25.253 - public final int EXTENDS = 112;
25.254 - public final int IMPLEMENTS = 113;
25.255 - public final int INTERFACE = 114;
25.256 - public final int PACKAGE = 115;
25.257 -
25.258 - /*
25.259 - * Modifier keywords
25.260 - */
25.261 - public final int PRIVATE = 120;
25.262 - public final int PUBLIC = 121;
25.263 - public final int PROTECTED = 122;
25.264 - public final int CONST = 123;
25.265 - public final int STATIC = 124;
25.266 - public final int TRANSIENT = 125;
25.267 - public final int SYNCHRONIZED = 126;
25.268 - public final int NATIVE = 127;
25.269 - public final int FINAL = 128;
25.270 - public final int VOLATILE = 129;
25.271 - public final int ABSTRACT = 130;
25.272 - public final int STRICT = 165;
25.273 -
25.274 - /*
25.275 - * Punctuation
25.276 - */
25.277 - public final int SEMICOLON = 135;
25.278 - public final int COLON = 136;
25.279 - public final int QUESTIONMARK = 137;
25.280 - public final int LBRACE = 138;
25.281 - public final int RBRACE = 139;
25.282 - public final int LPAREN = 140;
25.283 - public final int RPAREN = 141;
25.284 - public final int LSQBRACKET = 142;
25.285 - public final int RSQBRACKET = 143;
25.286 - public final int THROWS = 144;
25.287 -
25.288 - /*
25.289 - * Special tokens
25.290 - */
25.291 - public final int ERROR = 145; // an error
25.292 - public final int COMMENT = 146; // not used anymore.
25.293 - public final int TYPE = 147;
25.294 - public final int LENGTH = 148;
25.295 - public final int INLINERETURN = 149;
25.296 - public final int INLINEMETHOD = 150;
25.297 - public final int INLINENEWINSTANCE = 151;
25.298 -
25.299 - /*
25.300 - * Added for jasm
25.301 - */
25.302 - public final int METHODREF = 152;
25.303 - public final int FIELDREF = 153;
25.304 - public final int STACK = 154;
25.305 - public final int LOCAL = 155;
25.306 - public final int CPINDEX = 156;
25.307 - public final int CPNAME = 157;
25.308 - public final int SIGN = 158;
25.309 - public final int BITS = 159;
25.310 - public final int INF = 160;
25.311 - public final int NAN = 161;
25.312 - public final int INNERCLASS = 162;
25.313 - public final int OF = 163;
25.314 - public final int SYNTHETIC = 164;
25.315 -// last used=165;
25.316 -
25.317 - /*
25.318 - * Operator precedence
25.319 - */
25.320 - public static final int opPrecedence[] = {
25.321 - 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
25.322 - 11, 11, 11, 12, 13, 14, 15, 16, 17, 18,
25.323 - 18, 19, 19, 19, 19, 19, 20, 20, 20, 21,
25.324 - 21, 22, 22, 22, 23, 24, 24, 24, 24, 24,
25.325 - 24, 25, 25, 26, 26, 26, 26, 26, 26
25.326 - };
25.327 -
25.328 - /*
25.329 - * Operator names
25.330 - */
25.331 - public static final String opNames[] = {
25.332 - ",", "=", "*=", "/=", "%=",
25.333 - "+=", "-=", "<<=", ">>=", "<<<=",
25.334 - "&=", "|=", "^=", "?:", "||",
25.335 - "&&", "|", "^", "&", "!=",
25.336 - "==", ">=", ">", "<=", "<",
25.337 - "instanceof", "<<", ">>", "<<<", "+",
25.338 - "-", "/", "%", "*", "cast",
25.339 - "+", "-", "!", "~", "++",
25.340 - "--", "new", "new", "new", "++",
25.341 - "--", "field", "method", "[]", "new",
25.342 - "++", "--", null, null, null,
25.343 -
25.344 - "convert", "expr", "array", "goto", null,
25.345 -
25.346 - "Identifier", "Boolean", "Byte", "Char", "Short",
25.347 - "Integer", "Long", "Float", "Double", "String",
25.348 -
25.349 - "byte", "char", "short", "int", "long",
25.350 - "float", "double", "void", "boolean", null,
25.351 -
25.352 - "true", "false", "this", "super", "null",
25.353 - null, null, null, null, null,
25.354 -
25.355 - "if", "else", "for", "while", "do",
25.356 - "switch", "case", "default", "break", "continue",
25.357 - "return", "try", "catch", "finally", "throw",
25.358 - "stat", "expression", "declaration", "declaration", null,
25.359 -
25.360 - "import", "class", "extends", "implements", "interface",
25.361 - "package", null, null, null, null,
25.362 -
25.363 - "private", "public", "protected", "const", "static",
25.364 - "transient", "synchronized", "native", "final", "volatile",
25.365 - "abstract", null, null, null, null,
25.366 -
25.367 - ";", ":", "?", "{", "}",
25.368 - "(", ")", "[", "]", "throws",
25.369 - "error", "comment", "type", "length", "inline-return",
25.370 - "inline-method", "inline-new",
25.371 - "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
25.372 - "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
25.373 - };
25.374 -
25.375 -}
26.1 --- a/javap/src/main/java/sun/tools/javap/FieldData.java Fri Nov 16 08:06:48 2012 +0100
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,167 +0,0 @@
26.4 -/*
26.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
26.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26.7 - *
26.8 - * This code is free software; you can redistribute it and/or modify it
26.9 - * under the terms of the GNU General Public License version 2 only, as
26.10 - * published by the Free Software Foundation. Oracle designates this
26.11 - * particular file as subject to the "Classpath" exception as provided
26.12 - * by Oracle in the LICENSE file that accompanied this code.
26.13 - *
26.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
26.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26.17 - * version 2 for more details (a copy is included in the LICENSE file that
26.18 - * accompanied this code).
26.19 - *
26.20 - * You should have received a copy of the GNU General Public License version
26.21 - * 2 along with this work; if not, write to the Free Software Foundation,
26.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26.23 - *
26.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26.25 - * or visit www.oracle.com if you need additional information or have any
26.26 - * questions.
26.27 - */
26.28 -
26.29 -
26.30 -package sun.tools.javap;
26.31 -
26.32 -import java.util.*;
26.33 -import java.io.*;
26.34 -
26.35 -/**
26.36 - * Strores field data informastion.
26.37 - *
26.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
26.39 - */
26.40 -
26.41 -public class FieldData implements RuntimeConstants {
26.42 -
26.43 - ClassData cls;
26.44 - int access;
26.45 - int name_index;
26.46 - int descriptor_index;
26.47 - int attributes_count;
26.48 - int value_cpx=0;
26.49 - boolean isSynthetic=false;
26.50 - boolean isDeprecated=false;
26.51 - Vector attrs;
26.52 -
26.53 - public FieldData(ClassData cls){
26.54 - this.cls=cls;
26.55 - }
26.56 -
26.57 - /**
26.58 - * Read and store field info.
26.59 - */
26.60 - public void read(DataInputStream in) throws IOException {
26.61 - access = in.readUnsignedShort();
26.62 - name_index = in.readUnsignedShort();
26.63 - descriptor_index = in.readUnsignedShort();
26.64 - // Read the attributes
26.65 - int attributes_count = in.readUnsignedShort();
26.66 - attrs=new Vector(attributes_count);
26.67 - for (int i = 0; i < attributes_count; i++) {
26.68 - int attr_name_index=in.readUnsignedShort();
26.69 - if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
26.70 - String attr_name=cls.getString(attr_name_index);
26.71 - if (attr_name.equals("ConstantValue")){
26.72 - if (in.readInt()!=2)
26.73 - throw new ClassFormatError("invalid ConstantValue attr length");
26.74 - value_cpx=in.readUnsignedShort();
26.75 - AttrData attr=new AttrData(cls);
26.76 - attr.read(attr_name_index);
26.77 - attrs.addElement(attr);
26.78 - } else if (attr_name.equals("Synthetic")){
26.79 - if (in.readInt()!=0)
26.80 - throw new ClassFormatError("invalid Synthetic attr length");
26.81 - isSynthetic=true;
26.82 - AttrData attr=new AttrData(cls);
26.83 - attr.read(attr_name_index);
26.84 - attrs.addElement(attr);
26.85 - } else if (attr_name.equals("Deprecated")){
26.86 - if (in.readInt()!=0)
26.87 - throw new ClassFormatError("invalid Synthetic attr length");
26.88 - isDeprecated = true;
26.89 - AttrData attr=new AttrData(cls);
26.90 - attr.read(attr_name_index);
26.91 - attrs.addElement(attr);
26.92 - } else {
26.93 - AttrData attr=new AttrData(cls);
26.94 - attr.read(attr_name_index, in);
26.95 - attrs.addElement(attr);
26.96 - }
26.97 - }
26.98 -
26.99 - } // end read
26.100 -
26.101 - public boolean isStatic() {
26.102 - return (access & ACC_STATIC) != 0;
26.103 - }
26.104 -
26.105 - /**
26.106 - * Returns access of a field.
26.107 - */
26.108 - public String[] getAccess(){
26.109 - Vector v = new Vector();
26.110 - if ((access & ACC_PUBLIC) !=0) v.addElement("public");
26.111 - if ((access & ACC_PRIVATE) !=0) v.addElement("private");
26.112 - if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
26.113 - if ((access & ACC_STATIC) !=0) v.addElement("static");
26.114 - if ((access & ACC_FINAL) !=0) v.addElement("final");
26.115 - if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
26.116 - if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
26.117 - String[] accflags = new String[v.size()];
26.118 - v.copyInto(accflags);
26.119 - return accflags;
26.120 - }
26.121 -
26.122 - /**
26.123 - * Returns name of a field.
26.124 - */
26.125 - public String getName(){
26.126 - return cls.getStringValue(name_index);
26.127 - }
26.128 -
26.129 - /**
26.130 - * Returns internal signature of a field
26.131 - */
26.132 - public String getInternalSig(){
26.133 - return cls.getStringValue(descriptor_index);
26.134 - }
26.135 -
26.136 - /**
26.137 - * Returns java type signature of a field.
26.138 - */
26.139 - public String getType(){
26.140 - return new TypeSignature(getInternalSig()).getFieldType();
26.141 - }
26.142 -
26.143 - /**
26.144 - * Returns true if field is synthetic.
26.145 - */
26.146 - public boolean isSynthetic(){
26.147 - return isSynthetic;
26.148 - }
26.149 -
26.150 - /**
26.151 - * Returns true if field is deprecated.
26.152 - */
26.153 - public boolean isDeprecated(){
26.154 - return isDeprecated;
26.155 - }
26.156 -
26.157 - /**
26.158 - * Returns index of constant value in cpool.
26.159 - */
26.160 - public int getConstantValueIndex(){
26.161 - return (value_cpx);
26.162 - }
26.163 -
26.164 - /**
26.165 - * Returns list of attributes of field.
26.166 - */
26.167 - public Vector getAttributes(){
26.168 - return attrs;
26.169 - }
26.170 -}
27.1 --- a/javap/src/main/java/sun/tools/javap/Hashtable.java Fri Nov 16 08:06:48 2012 +0100
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,81 +0,0 @@
27.4 -/*
27.5 - * To change this template, choose Tools | Templates
27.6 - * and open the template in the editor.
27.7 - */
27.8 -package sun.tools.javap;
27.9 -
27.10 -/** A JavaScript optimized replacement for Hashtable.
27.11 - *
27.12 - * @author Jaroslav Tulach <jtulach@netbeans.org>
27.13 - */
27.14 -final class Hashtable {
27.15 - private Object[] keys;
27.16 - private Object[] values;
27.17 -
27.18 - Hashtable(int i) {
27.19 - this();
27.20 - }
27.21 -
27.22 - Hashtable(int i, double d) {
27.23 - this();
27.24 - }
27.25 -
27.26 - Hashtable() {
27.27 - }
27.28 -
27.29 - synchronized void put(Object key, Object val) {
27.30 - int[] where = { -1, -1 };
27.31 - Object found = get(key, where);
27.32 - if (where[0] != -1) {
27.33 - // key exists
27.34 - values[where[0]] = val;
27.35 - } else {
27.36 - if (where[1] != -1) {
27.37 - // null found
27.38 - keys[where[1]] = key;
27.39 - values[where[1]] = val;
27.40 - } else {
27.41 - if (keys == null) {
27.42 - keys = new Object[11];
27.43 - values = new Object[11];
27.44 - keys[0] = key;
27.45 - values[0] = val;
27.46 - } else {
27.47 - Object[] newKeys = new Object[keys.length * 2];
27.48 - Object[] newValues = new Object[values.length * 2];
27.49 - for (int i = 0; i < keys.length; i++) {
27.50 - newKeys[i] = keys[i];
27.51 - newValues[i] = values[i];
27.52 - }
27.53 - newKeys[keys.length] = key;
27.54 - newValues[keys.length] = val;
27.55 - keys = newKeys;
27.56 - values = newValues;
27.57 - }
27.58 - }
27.59 - }
27.60 - }
27.61 -
27.62 - Object get(Object key) {
27.63 - return get(key, null);
27.64 - }
27.65 - private synchronized Object get(Object key, int[] foundAndNull) {
27.66 - if (keys == null) {
27.67 - return null;
27.68 - }
27.69 - for (int i = 0; i < keys.length; i++) {
27.70 - if (keys[i] == null) {
27.71 - if (foundAndNull != null) {
27.72 - foundAndNull[1] = i;
27.73 - }
27.74 - } else if (keys[i].equals(key)) {
27.75 - if (foundAndNull != null) {
27.76 - foundAndNull[0] = i;
27.77 - }
27.78 - return values[i];
27.79 - }
27.80 - }
27.81 - return null;
27.82 - }
27.83 -
27.84 -}
28.1 --- a/javap/src/main/java/sun/tools/javap/InnerClassData.java Fri Nov 16 08:06:48 2012 +0100
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,75 +0,0 @@
28.4 -/*
28.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
28.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28.7 - *
28.8 - * This code is free software; you can redistribute it and/or modify it
28.9 - * under the terms of the GNU General Public License version 2 only, as
28.10 - * published by the Free Software Foundation. Oracle designates this
28.11 - * particular file as subject to the "Classpath" exception as provided
28.12 - * by Oracle in the LICENSE file that accompanied this code.
28.13 - *
28.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
28.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28.17 - * version 2 for more details (a copy is included in the LICENSE file that
28.18 - * accompanied this code).
28.19 - *
28.20 - * You should have received a copy of the GNU General Public License version
28.21 - * 2 along with this work; if not, write to the Free Software Foundation,
28.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28.23 - *
28.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28.25 - * or visit www.oracle.com if you need additional information or have any
28.26 - * questions.
28.27 - */
28.28 -
28.29 -
28.30 -package sun.tools.javap;
28.31 -
28.32 -import java.io.*;
28.33 -import java.util.*;
28.34 -
28.35 -/**
28.36 - * Strores InnerClass data informastion.
28.37 - *
28.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
28.39 - */
28.40 -class InnerClassData implements RuntimeConstants {
28.41 - ClassData cls;
28.42 -
28.43 -
28.44 - int inner_class_info_index
28.45 - ,outer_class_info_index
28.46 - ,inner_name_index
28.47 - ,access
28.48 - ;
28.49 -
28.50 - public InnerClassData(ClassData cls) {
28.51 - this.cls=cls;
28.52 -
28.53 - }
28.54 -
28.55 - /**
28.56 - * Read Innerclass attribute data.
28.57 - */
28.58 - public void read(DataInputStream in) throws IOException {
28.59 - inner_class_info_index = in.readUnsignedShort();
28.60 - outer_class_info_index = in.readUnsignedShort();
28.61 - inner_name_index = in.readUnsignedShort();
28.62 - access = in.readUnsignedShort();
28.63 - } // end read
28.64 -
28.65 - /**
28.66 - * Returns the access of this class or interface.
28.67 - */
28.68 - public String[] getAccess(){
28.69 - Vector v = new Vector();
28.70 - if ((access & ACC_PUBLIC) !=0) v.addElement("public");
28.71 - if ((access & ACC_FINAL) !=0) v.addElement("final");
28.72 - if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
28.73 - String[] accflags = new String[v.size()];
28.74 - v.copyInto(accflags);
28.75 - return accflags;
28.76 - }
28.77 -
28.78 -} // end InnerClassData
29.1 --- a/javap/src/main/java/sun/tools/javap/LineNumData.java Fri Nov 16 08:06:48 2012 +0100
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,50 +0,0 @@
29.4 -/*
29.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
29.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29.7 - *
29.8 - * This code is free software; you can redistribute it and/or modify it
29.9 - * under the terms of the GNU General Public License version 2 only, as
29.10 - * published by the Free Software Foundation. Oracle designates this
29.11 - * particular file as subject to the "Classpath" exception as provided
29.12 - * by Oracle in the LICENSE file that accompanied this code.
29.13 - *
29.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
29.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29.17 - * version 2 for more details (a copy is included in the LICENSE file that
29.18 - * accompanied this code).
29.19 - *
29.20 - * You should have received a copy of the GNU General Public License version
29.21 - * 2 along with this work; if not, write to the Free Software Foundation,
29.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29.23 - *
29.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
29.25 - * or visit www.oracle.com if you need additional information or have any
29.26 - * questions.
29.27 - */
29.28 -
29.29 -
29.30 -package sun.tools.javap;
29.31 -
29.32 -import java.util.*;
29.33 -import java.io.*;
29.34 -
29.35 -/**
29.36 - * Strores LineNumberTable data information.
29.37 - *
29.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
29.39 - */
29.40 -class LineNumData {
29.41 - short start_pc, line_number;
29.42 -
29.43 - public LineNumData() {}
29.44 -
29.45 - /**
29.46 - * Read LineNumberTable attribute.
29.47 - */
29.48 - public LineNumData(DataInputStream in) throws IOException {
29.49 - start_pc = in.readShort();
29.50 - line_number=in.readShort();
29.51 -
29.52 - }
29.53 -}
30.1 --- a/javap/src/main/java/sun/tools/javap/LocVarData.java Fri Nov 16 08:06:48 2012 +0100
30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
30.3 @@ -1,54 +0,0 @@
30.4 -/*
30.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
30.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30.7 - *
30.8 - * This code is free software; you can redistribute it and/or modify it
30.9 - * under the terms of the GNU General Public License version 2 only, as
30.10 - * published by the Free Software Foundation. Oracle designates this
30.11 - * particular file as subject to the "Classpath" exception as provided
30.12 - * by Oracle in the LICENSE file that accompanied this code.
30.13 - *
30.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
30.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30.17 - * version 2 for more details (a copy is included in the LICENSE file that
30.18 - * accompanied this code).
30.19 - *
30.20 - * You should have received a copy of the GNU General Public License version
30.21 - * 2 along with this work; if not, write to the Free Software Foundation,
30.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
30.23 - *
30.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
30.25 - * or visit www.oracle.com if you need additional information or have any
30.26 - * questions.
30.27 - */
30.28 -
30.29 -
30.30 -package sun.tools.javap;
30.31 -
30.32 -import java.util.*;
30.33 -import java.io.*;
30.34 -
30.35 -/**
30.36 - * Strores LocalVariableTable data information.
30.37 - *
30.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
30.39 - */
30.40 -class LocVarData {
30.41 - short start_pc, length, name_cpx, sig_cpx, slot;
30.42 -
30.43 - public LocVarData() {
30.44 - }
30.45 -
30.46 - /**
30.47 - * Read LocalVariableTable attribute.
30.48 - */
30.49 - public LocVarData(DataInputStream in) throws IOException {
30.50 - start_pc = in.readShort();
30.51 - length=in.readShort();
30.52 - name_cpx=in.readShort();
30.53 - sig_cpx=in.readShort();
30.54 - slot=in.readShort();
30.55 -
30.56 - }
30.57 -}
31.1 --- a/javap/src/main/java/sun/tools/javap/MethodData.java Fri Nov 16 08:06:48 2012 +0100
31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
31.3 @@ -1,425 +0,0 @@
31.4 -/*
31.5 - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
31.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31.7 - *
31.8 - * This code is free software; you can redistribute it and/or modify it
31.9 - * under the terms of the GNU General Public License version 2 only, as
31.10 - * published by the Free Software Foundation. Oracle designates this
31.11 - * particular file as subject to the "Classpath" exception as provided
31.12 - * by Oracle in the LICENSE file that accompanied this code.
31.13 - *
31.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
31.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31.17 - * version 2 for more details (a copy is included in the LICENSE file that
31.18 - * accompanied this code).
31.19 - *
31.20 - * You should have received a copy of the GNU General Public License version
31.21 - * 2 along with this work; if not, write to the Free Software Foundation,
31.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31.23 - *
31.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
31.25 - * or visit www.oracle.com if you need additional information or have any
31.26 - * questions.
31.27 - */
31.28 -
31.29 -package sun.tools.javap;
31.30 -
31.31 -import java.io.*;
31.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
31.33 -
31.34 -import static sun.tools.javap.RuntimeConstants.*;
31.35 -
31.36 -/**
31.37 - * Strores method data informastion.
31.38 - *
31.39 - * @author Sucheta Dambalkar (Adopted code from jdis)
31.40 - */
31.41 -public class MethodData {
31.42 -
31.43 - ClassData cls;
31.44 - int access;
31.45 - int name_index;
31.46 - int descriptor_index;
31.47 - int attributes_count;
31.48 - byte[] code;
31.49 - Vector exception_table = new Vector(0);
31.50 - Vector lin_num_tb = new Vector(0);
31.51 - Vector loc_var_tb = new Vector(0);
31.52 - StackMapTableData[] stackMapTable;
31.53 - StackMapData[] stackMap;
31.54 - int[] exc_index_table=null;
31.55 - Vector attrs=new Vector(0);
31.56 - Vector code_attrs=new Vector(0);
31.57 - int max_stack, max_locals;
31.58 - boolean isSynthetic=false;
31.59 - boolean isDeprecated=false;
31.60 -
31.61 - public MethodData(ClassData cls){
31.62 - this.cls=cls;
31.63 - }
31.64 -
31.65 - /**
31.66 - * Read method info.
31.67 - */
31.68 - public void read(DataInputStream in) throws IOException {
31.69 - access = in.readUnsignedShort();
31.70 - name_index=in.readUnsignedShort();
31.71 - descriptor_index =in.readUnsignedShort();
31.72 - int attributes_count = in.readUnsignedShort();
31.73 - for (int i = 0; i < attributes_count; i++) {
31.74 - int attr_name_index=in.readUnsignedShort();
31.75 -
31.76 - readAttr: {
31.77 - if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
31.78 - String attr_name=cls.getString(attr_name_index);
31.79 - if ( attr_name.equals("Code")){
31.80 - readCode (in);
31.81 - AttrData attr=new AttrData(cls);
31.82 - attr.read(attr_name_index);
31.83 - attrs.addElement(attr);
31.84 - break readAttr;
31.85 - } else if ( attr_name.equals("Exceptions")){
31.86 - readExceptions(in);
31.87 - AttrData attr=new AttrData(cls);
31.88 - attr.read(attr_name_index);
31.89 - attrs.addElement(attr);
31.90 - break readAttr;
31.91 - } else if (attr_name.equals("Synthetic")){
31.92 - if (in.readInt()!=0)
31.93 - throw new ClassFormatError("invalid Synthetic attr length");
31.94 - isSynthetic=true;
31.95 - AttrData attr=new AttrData(cls);
31.96 - attr.read(attr_name_index);
31.97 - attrs.addElement(attr);
31.98 - break readAttr;
31.99 - } else if (attr_name.equals("Deprecated")){
31.100 - if (in.readInt()!=0)
31.101 - throw new ClassFormatError("invalid Synthetic attr length");
31.102 - isDeprecated = true;
31.103 - AttrData attr=new AttrData(cls);
31.104 - attr.read(attr_name_index);
31.105 - attrs.addElement(attr);
31.106 - break readAttr;
31.107 - }
31.108 - }
31.109 - AttrData attr=new AttrData(cls);
31.110 - attr.read(attr_name_index, in);
31.111 - attrs.addElement(attr);
31.112 - }
31.113 - }
31.114 - }
31.115 -
31.116 - /**
31.117 - * Read code attribute info.
31.118 - */
31.119 - public void readCode(DataInputStream in) throws IOException {
31.120 -
31.121 - int attr_length = in.readInt();
31.122 - max_stack=in.readUnsignedShort();
31.123 - max_locals=in.readUnsignedShort();
31.124 - int codelen=in.readInt();
31.125 -
31.126 - code=new byte[codelen];
31.127 - int totalread = 0;
31.128 - while(totalread < codelen){
31.129 - totalread += in.read(code, totalread, codelen-totalread);
31.130 - }
31.131 - // in.read(code, 0, codelen);
31.132 - int clen = 0;
31.133 - readExceptionTable(in);
31.134 - int code_attributes_count = in.readUnsignedShort();
31.135 -
31.136 - for (int k = 0 ; k < code_attributes_count ; k++) {
31.137 - int table_name_index=in.readUnsignedShort();
31.138 - int table_name_tag=cls.getTag(table_name_index);
31.139 - AttrData attr=new AttrData(cls);
31.140 - if (table_name_tag==CONSTANT_UTF8) {
31.141 - String table_name_tstr=cls.getString(table_name_index);
31.142 - if (table_name_tstr.equals("LineNumberTable")) {
31.143 - readLineNumTable(in);
31.144 - attr.read(table_name_index);
31.145 - } else if (table_name_tstr.equals("LocalVariableTable")) {
31.146 - readLocVarTable(in);
31.147 - attr.read(table_name_index);
31.148 - } else if (table_name_tstr.equals("StackMapTable")) {
31.149 - readStackMapTable(in);
31.150 - attr.read(table_name_index);
31.151 - } else if (table_name_tstr.equals("StackMap")) {
31.152 - readStackMap(in);
31.153 - attr.read(table_name_index);
31.154 - } else {
31.155 - attr.read(table_name_index, in);
31.156 - }
31.157 - code_attrs.addElement(attr);
31.158 - continue;
31.159 - }
31.160 -
31.161 - attr.read(table_name_index, in);
31.162 - code_attrs.addElement(attr);
31.163 - }
31.164 - }
31.165 -
31.166 - /**
31.167 - * Read exception table info.
31.168 - */
31.169 - void readExceptionTable (DataInputStream in) throws IOException {
31.170 - int exception_table_len=in.readUnsignedShort();
31.171 - exception_table=new Vector(exception_table_len);
31.172 - for (int l = 0; l < exception_table_len; l++) {
31.173 - exception_table.addElement(new TrapData(in, l));
31.174 - }
31.175 - }
31.176 -
31.177 - /**
31.178 - * Read LineNumberTable attribute info.
31.179 - */
31.180 - void readLineNumTable (DataInputStream in) throws IOException {
31.181 - int attr_len = in.readInt(); // attr_length
31.182 - int lin_num_tb_len = in.readUnsignedShort();
31.183 - lin_num_tb=new Vector(lin_num_tb_len);
31.184 - for (int l = 0; l < lin_num_tb_len; l++) {
31.185 - lin_num_tb.addElement(new LineNumData(in));
31.186 - }
31.187 - }
31.188 -
31.189 - /**
31.190 - * Read LocalVariableTable attribute info.
31.191 - */
31.192 - void readLocVarTable (DataInputStream in) throws IOException {
31.193 - int attr_len=in.readInt(); // attr_length
31.194 - int loc_var_tb_len = in.readUnsignedShort();
31.195 - loc_var_tb = new Vector(loc_var_tb_len);
31.196 - for (int l = 0; l < loc_var_tb_len; l++) {
31.197 - loc_var_tb.addElement(new LocVarData(in));
31.198 - }
31.199 - }
31.200 -
31.201 - /**
31.202 - * Read Exception attribute info.
31.203 - */
31.204 - public void readExceptions(DataInputStream in) throws IOException {
31.205 - int attr_len=in.readInt(); // attr_length in prog
31.206 - int num_exceptions = in.readUnsignedShort();
31.207 - exc_index_table=new int[num_exceptions];
31.208 - for (int l = 0; l < num_exceptions; l++) {
31.209 - int exc=in.readShort();
31.210 - exc_index_table[l]=exc;
31.211 - }
31.212 - }
31.213 -
31.214 - /**
31.215 - * Read StackMapTable attribute info.
31.216 - */
31.217 - void readStackMapTable(DataInputStream in) throws IOException {
31.218 - int attr_len = in.readInt(); //attr_length
31.219 - int stack_map_tb_len = in.readUnsignedShort();
31.220 - stackMapTable = new StackMapTableData[stack_map_tb_len];
31.221 - for (int i=0; i<stack_map_tb_len; i++) {
31.222 - stackMapTable[i] = StackMapTableData.getInstance(in, this);
31.223 - }
31.224 - }
31.225 -
31.226 - /**
31.227 - * Read StackMap attribute info.
31.228 - */
31.229 - void readStackMap(DataInputStream in) throws IOException {
31.230 - int attr_len = in.readInt(); //attr_length
31.231 - int stack_map_len = in.readUnsignedShort();
31.232 - stackMap = new StackMapData[stack_map_len];
31.233 - for (int i = 0; i<stack_map_len; i++) {
31.234 - stackMap[i] = new StackMapData(in, this);
31.235 - }
31.236 - }
31.237 -
31.238 - /**
31.239 - * Return access of the method.
31.240 - */
31.241 - public String[] getAccess(){
31.242 -
31.243 - Vector v = new Vector();
31.244 - if ((access & ACC_PUBLIC) !=0) v.addElement("public");
31.245 - if ((access & ACC_PRIVATE) !=0) v.addElement("private");
31.246 - if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
31.247 - if ((access & ACC_STATIC) !=0) v.addElement("static");
31.248 - if ((access & ACC_FINAL) !=0) v.addElement("final");
31.249 - if ((access & ACC_SYNCHRONIZED) !=0) v.addElement("synchronized");
31.250 - if ((access & ACC_NATIVE) !=0) v.addElement("native");
31.251 - if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
31.252 - if ((access & ACC_STRICT) !=0) v.addElement("strictfp");
31.253 -
31.254 - String[] accflags = new String[v.size()];
31.255 - v.copyInto(accflags);
31.256 - return accflags;
31.257 - }
31.258 -
31.259 - /**
31.260 - * Return name of the method.
31.261 - */
31.262 - public String getName(){
31.263 - return cls.getStringValue(name_index);
31.264 - }
31.265 -
31.266 - /**
31.267 - * Return internal siganature of the method.
31.268 - */
31.269 - public String getInternalSig(){
31.270 - return cls.getStringValue(descriptor_index);
31.271 - }
31.272 -
31.273 - /**
31.274 - * Return java return type signature of method.
31.275 - */
31.276 - public String getReturnType(){
31.277 -
31.278 - String rttype = (new TypeSignature(getInternalSig())).getReturnType();
31.279 - return rttype;
31.280 - }
31.281 -
31.282 - /**
31.283 - * Return java type parameter signature.
31.284 - */
31.285 - public String getParameters(){
31.286 - String ptype = (new TypeSignature(getInternalSig())).getParameters();
31.287 -
31.288 - return ptype;
31.289 - }
31.290 -
31.291 - /**
31.292 - * Return code attribute data of a method.
31.293 - */
31.294 - public byte[] getCode(){
31.295 - return code;
31.296 - }
31.297 -
31.298 - /**
31.299 - * Return LineNumberTable size.
31.300 - */
31.301 - public int getnumlines(){
31.302 - return lin_num_tb.size();
31.303 - }
31.304 -
31.305 - /**
31.306 - * Return LineNumberTable
31.307 - */
31.308 - public Vector getlin_num_tb(){
31.309 - return lin_num_tb;
31.310 - }
31.311 -
31.312 - /**
31.313 - * Return LocalVariableTable size.
31.314 - */
31.315 - public int getloc_var_tbsize(){
31.316 - return loc_var_tb.size();
31.317 - }
31.318 -
31.319 -
31.320 - /**
31.321 - * Return LocalVariableTable.
31.322 - */
31.323 - public Vector getloc_var_tb(){
31.324 - return loc_var_tb;
31.325 - }
31.326 -
31.327 - /**
31.328 - * Return StackMap.
31.329 - */
31.330 - public StackMapData[] getStackMap() {
31.331 - return stackMap;
31.332 - }
31.333 -
31.334 - /**
31.335 - * Return StackMapTable.
31.336 - */
31.337 - public StackMapTableData[] getStackMapTable() {
31.338 - return stackMapTable;
31.339 - }
31.340 -
31.341 - /**
31.342 - * Return number of arguments of that method.
31.343 - */
31.344 - public int getArgumentlength(){
31.345 - return new TypeSignature(getInternalSig()).getArgumentlength();
31.346 - }
31.347 -
31.348 - /**
31.349 - * Return true if method is static
31.350 - */
31.351 - public boolean isStatic(){
31.352 - if ((access & ACC_STATIC) !=0) return true;
31.353 - return false;
31.354 - }
31.355 -
31.356 -
31.357 - /**
31.358 - * Return max depth of operand stack.
31.359 - */
31.360 - public int getMaxStack(){
31.361 - return max_stack;
31.362 - }
31.363 -
31.364 -
31.365 - /**
31.366 - * Return number of local variables.
31.367 - */
31.368 - public int getMaxLocals(){
31.369 - return max_locals;
31.370 - }
31.371 -
31.372 -
31.373 - /**
31.374 - * Return exception index table in Exception attribute.
31.375 - */
31.376 - public int []get_exc_index_table(){
31.377 - return exc_index_table;
31.378 - }
31.379 -
31.380 -
31.381 - /**
31.382 - * Return exception table in code attributre.
31.383 - */
31.384 - public Vector getexception_table(){
31.385 - return exception_table;
31.386 - }
31.387 -
31.388 -
31.389 - /**
31.390 - * Return method attributes.
31.391 - */
31.392 - public Vector getAttributes(){
31.393 - return attrs;
31.394 - }
31.395 -
31.396 -
31.397 - /**
31.398 - * Return code attributes.
31.399 - */
31.400 - public Vector getCodeAttributes(){
31.401 - return code_attrs;
31.402 - }
31.403 -
31.404 -
31.405 - /**
31.406 - * Return true if method id synthetic.
31.407 - */
31.408 - public boolean isSynthetic(){
31.409 - return isSynthetic;
31.410 - }
31.411 -
31.412 -
31.413 - /**
31.414 - * Return true if method is deprecated.
31.415 - */
31.416 - public boolean isDeprecated(){
31.417 - return isDeprecated;
31.418 - }
31.419 -
31.420 - public byte[] findAnnotationData(boolean classRetention) {
31.421 - String n = classRetention ?
31.422 - "RuntimeInvisibleAnnotations" : // NOI18N
31.423 - "RuntimeVisibleAnnotations"; // NOI18N
31.424 - AttrData[] arr = new AttrData[attrs.size()];
31.425 - attrs.copyInto(arr);
31.426 - return ClassData.findAttr(n, arr);
31.427 - }
31.428 -}
32.1 --- a/javap/src/main/java/sun/tools/javap/RuntimeConstants.java Fri Nov 16 08:06:48 2012 +0100
32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
32.3 @@ -1,787 +0,0 @@
32.4 -/*
32.5 - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
32.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32.7 - *
32.8 - * This code is free software; you can redistribute it and/or modify it
32.9 - * under the terms of the GNU General Public License version 2 only, as
32.10 - * published by the Free Software Foundation. Oracle designates this
32.11 - * particular file as subject to the "Classpath" exception as provided
32.12 - * by Oracle in the LICENSE file that accompanied this code.
32.13 - *
32.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
32.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32.17 - * version 2 for more details (a copy is included in the LICENSE file that
32.18 - * accompanied this code).
32.19 - *
32.20 - * You should have received a copy of the GNU General Public License version
32.21 - * 2 along with this work; if not, write to the Free Software Foundation,
32.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32.23 - *
32.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32.25 - * or visit www.oracle.com if you need additional information or have any
32.26 - * questions.
32.27 - */
32.28 -
32.29 -
32.30 -package sun.tools.javap;
32.31 -
32.32 -public interface RuntimeConstants {
32.33 -
32.34 - /* Signature Characters */
32.35 - public static final char SIGC_VOID = 'V';
32.36 - public static final String SIG_VOID = "V";
32.37 - public static final char SIGC_BOOLEAN = 'Z';
32.38 - public static final String SIG_BOOLEAN = "Z";
32.39 - public static final char SIGC_BYTE = 'B';
32.40 - public static final String SIG_BYTE = "B";
32.41 - public static final char SIGC_CHAR = 'C';
32.42 - public static final String SIG_CHAR = "C";
32.43 - public static final char SIGC_SHORT = 'S';
32.44 - public static final String SIG_SHORT = "S";
32.45 - public static final char SIGC_INT = 'I';
32.46 - public static final String SIG_INT = "I";
32.47 - public static final char SIGC_LONG = 'J';
32.48 - public static final String SIG_LONG = "J";
32.49 - public static final char SIGC_FLOAT = 'F';
32.50 - public static final String SIG_FLOAT = "F";
32.51 - public static final char SIGC_DOUBLE = 'D';
32.52 - public static final String SIG_DOUBLE = "D";
32.53 - public static final char SIGC_ARRAY = '[';
32.54 - public static final String SIG_ARRAY = "[";
32.55 - public static final char SIGC_CLASS = 'L';
32.56 - public static final String SIG_CLASS = "L";
32.57 - public static final char SIGC_METHOD = '(';
32.58 - public static final String SIG_METHOD = "(";
32.59 - public static final char SIGC_ENDCLASS = ';';
32.60 - public static final String SIG_ENDCLASS = ";";
32.61 - public static final char SIGC_ENDMETHOD = ')';
32.62 - public static final String SIG_ENDMETHOD = ")";
32.63 - public static final char SIGC_PACKAGE = '/';
32.64 - public static final String SIG_PACKAGE = "/";
32.65 -
32.66 - /* Class File Constants */
32.67 - public static final int JAVA_MAGIC = 0xcafebabe;
32.68 - public static final int JAVA_VERSION = 45;
32.69 - public static final int JAVA_MINOR_VERSION = 3;
32.70 -
32.71 - /* Constant table */
32.72 - public static final int CONSTANT_UTF8 = 1;
32.73 - public static final int CONSTANT_UNICODE = 2;
32.74 - public static final int CONSTANT_INTEGER = 3;
32.75 - public static final int CONSTANT_FLOAT = 4;
32.76 - public static final int CONSTANT_LONG = 5;
32.77 - public static final int CONSTANT_DOUBLE = 6;
32.78 - public static final int CONSTANT_CLASS = 7;
32.79 - public static final int CONSTANT_STRING = 8;
32.80 - public static final int CONSTANT_FIELD = 9;
32.81 - public static final int CONSTANT_METHOD = 10;
32.82 - public static final int CONSTANT_INTERFACEMETHOD = 11;
32.83 - public static final int CONSTANT_NAMEANDTYPE = 12;
32.84 -
32.85 - /* Access Flags */
32.86 - public static final int ACC_PUBLIC = 0x00000001;
32.87 - public static final int ACC_PRIVATE = 0x00000002;
32.88 - public static final int ACC_PROTECTED = 0x00000004;
32.89 - public static final int ACC_STATIC = 0x00000008;
32.90 - public static final int ACC_FINAL = 0x00000010;
32.91 - public static final int ACC_SYNCHRONIZED = 0x00000020;
32.92 - public static final int ACC_SUPER = 0x00000020;
32.93 - public static final int ACC_VOLATILE = 0x00000040;
32.94 - public static final int ACC_TRANSIENT = 0x00000080;
32.95 - public static final int ACC_NATIVE = 0x00000100;
32.96 - public static final int ACC_INTERFACE = 0x00000200;
32.97 - public static final int ACC_ABSTRACT = 0x00000400;
32.98 - public static final int ACC_STRICT = 0x00000800;
32.99 - public static final int ACC_EXPLICIT = 0x00001000;
32.100 - public static final int ACC_SYNTHETIC = 0x00010000; // actually, this is an attribute
32.101 -
32.102 - /* Type codes */
32.103 - public static final int T_CLASS = 0x00000002;
32.104 - public static final int T_BOOLEAN = 0x00000004;
32.105 - public static final int T_CHAR = 0x00000005;
32.106 - public static final int T_FLOAT = 0x00000006;
32.107 - public static final int T_DOUBLE = 0x00000007;
32.108 - public static final int T_BYTE = 0x00000008;
32.109 - public static final int T_SHORT = 0x00000009;
32.110 - public static final int T_INT = 0x0000000a;
32.111 - public static final int T_LONG = 0x0000000b;
32.112 -
32.113 - /* Type codes for StackMap attribute */
32.114 - public static final int ITEM_Bogus =0; // an unknown or uninitialized value
32.115 - public static final int ITEM_Integer =1; // a 32-bit integer
32.116 - public static final int ITEM_Float =2; // not used
32.117 - public static final int ITEM_Double =3; // not used
32.118 - public static final int ITEM_Long =4; // a 64-bit integer
32.119 - public static final int ITEM_Null =5; // the type of null
32.120 - public static final int ITEM_InitObject =6; // "this" in constructor
32.121 - public static final int ITEM_Object =7; // followed by 2-byte index of class name
32.122 - public static final int ITEM_NewObject =8; // followed by 2-byte ref to "new"
32.123 -
32.124 - /* Constants used in StackMapTable attribute */
32.125 - public static final int SAME_FRAME_BOUND = 64;
32.126 - public static final int SAME_LOCALS_1_STACK_ITEM_BOUND = 128;
32.127 - public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
32.128 - public static final int SAME_FRAME_EXTENDED = 251;
32.129 - public static final int FULL_FRAME = 255;
32.130 -
32.131 - /* Opcodes */
32.132 - public static final int opc_dead = -2;
32.133 - public static final int opc_label = -1;
32.134 - public static final int opc_nop = 0;
32.135 - public static final int opc_aconst_null = 1;
32.136 - public static final int opc_iconst_m1 = 2;
32.137 - public static final int opc_iconst_0 = 3;
32.138 - public static final int opc_iconst_1 = 4;
32.139 - public static final int opc_iconst_2 = 5;
32.140 - public static final int opc_iconst_3 = 6;
32.141 - public static final int opc_iconst_4 = 7;
32.142 - public static final int opc_iconst_5 = 8;
32.143 - public static final int opc_lconst_0 = 9;
32.144 - public static final int opc_lconst_1 = 10;
32.145 - public static final int opc_fconst_0 = 11;
32.146 - public static final int opc_fconst_1 = 12;
32.147 - public static final int opc_fconst_2 = 13;
32.148 - public static final int opc_dconst_0 = 14;
32.149 - public static final int opc_dconst_1 = 15;
32.150 - public static final int opc_bipush = 16;
32.151 - public static final int opc_sipush = 17;
32.152 - public static final int opc_ldc = 18;
32.153 - public static final int opc_ldc_w = 19;
32.154 - public static final int opc_ldc2_w = 20;
32.155 - public static final int opc_iload = 21;
32.156 - public static final int opc_lload = 22;
32.157 - public static final int opc_fload = 23;
32.158 - public static final int opc_dload = 24;
32.159 - public static final int opc_aload = 25;
32.160 - public static final int opc_iload_0 = 26;
32.161 - public static final int opc_iload_1 = 27;
32.162 - public static final int opc_iload_2 = 28;
32.163 - public static final int opc_iload_3 = 29;
32.164 - public static final int opc_lload_0 = 30;
32.165 - public static final int opc_lload_1 = 31;
32.166 - public static final int opc_lload_2 = 32;
32.167 - public static final int opc_lload_3 = 33;
32.168 - public static final int opc_fload_0 = 34;
32.169 - public static final int opc_fload_1 = 35;
32.170 - public static final int opc_fload_2 = 36;
32.171 - public static final int opc_fload_3 = 37;
32.172 - public static final int opc_dload_0 = 38;
32.173 - public static final int opc_dload_1 = 39;
32.174 - public static final int opc_dload_2 = 40;
32.175 - public static final int opc_dload_3 = 41;
32.176 - public static final int opc_aload_0 = 42;
32.177 - public static final int opc_aload_1 = 43;
32.178 - public static final int opc_aload_2 = 44;
32.179 - public static final int opc_aload_3 = 45;
32.180 - public static final int opc_iaload = 46;
32.181 - public static final int opc_laload = 47;
32.182 - public static final int opc_faload = 48;
32.183 - public static final int opc_daload = 49;
32.184 - public static final int opc_aaload = 50;
32.185 - public static final int opc_baload = 51;
32.186 - public static final int opc_caload = 52;
32.187 - public static final int opc_saload = 53;
32.188 - public static final int opc_istore = 54;
32.189 - public static final int opc_lstore = 55;
32.190 - public static final int opc_fstore = 56;
32.191 - public static final int opc_dstore = 57;
32.192 - public static final int opc_astore = 58;
32.193 - public static final int opc_istore_0 = 59;
32.194 - public static final int opc_istore_1 = 60;
32.195 - public static final int opc_istore_2 = 61;
32.196 - public static final int opc_istore_3 = 62;
32.197 - public static final int opc_lstore_0 = 63;
32.198 - public static final int opc_lstore_1 = 64;
32.199 - public static final int opc_lstore_2 = 65;
32.200 - public static final int opc_lstore_3 = 66;
32.201 - public static final int opc_fstore_0 = 67;
32.202 - public static final int opc_fstore_1 = 68;
32.203 - public static final int opc_fstore_2 = 69;
32.204 - public static final int opc_fstore_3 = 70;
32.205 - public static final int opc_dstore_0 = 71;
32.206 - public static final int opc_dstore_1 = 72;
32.207 - public static final int opc_dstore_2 = 73;
32.208 - public static final int opc_dstore_3 = 74;
32.209 - public static final int opc_astore_0 = 75;
32.210 - public static final int opc_astore_1 = 76;
32.211 - public static final int opc_astore_2 = 77;
32.212 - public static final int opc_astore_3 = 78;
32.213 - public static final int opc_iastore = 79;
32.214 - public static final int opc_lastore = 80;
32.215 - public static final int opc_fastore = 81;
32.216 - public static final int opc_dastore = 82;
32.217 - public static final int opc_aastore = 83;
32.218 - public static final int opc_bastore = 84;
32.219 - public static final int opc_castore = 85;
32.220 - public static final int opc_sastore = 86;
32.221 - public static final int opc_pop = 87;
32.222 - public static final int opc_pop2 = 88;
32.223 - public static final int opc_dup = 89;
32.224 - public static final int opc_dup_x1 = 90;
32.225 - public static final int opc_dup_x2 = 91;
32.226 - public static final int opc_dup2 = 92;
32.227 - public static final int opc_dup2_x1 = 93;
32.228 - public static final int opc_dup2_x2 = 94;
32.229 - public static final int opc_swap = 95;
32.230 - public static final int opc_iadd = 96;
32.231 - public static final int opc_ladd = 97;
32.232 - public static final int opc_fadd = 98;
32.233 - public static final int opc_dadd = 99;
32.234 - public static final int opc_isub = 100;
32.235 - public static final int opc_lsub = 101;
32.236 - public static final int opc_fsub = 102;
32.237 - public static final int opc_dsub = 103;
32.238 - public static final int opc_imul = 104;
32.239 - public static final int opc_lmul = 105;
32.240 - public static final int opc_fmul = 106;
32.241 - public static final int opc_dmul = 107;
32.242 - public static final int opc_idiv = 108;
32.243 - public static final int opc_ldiv = 109;
32.244 - public static final int opc_fdiv = 110;
32.245 - public static final int opc_ddiv = 111;
32.246 - public static final int opc_irem = 112;
32.247 - public static final int opc_lrem = 113;
32.248 - public static final int opc_frem = 114;
32.249 - public static final int opc_drem = 115;
32.250 - public static final int opc_ineg = 116;
32.251 - public static final int opc_lneg = 117;
32.252 - public static final int opc_fneg = 118;
32.253 - public static final int opc_dneg = 119;
32.254 - public static final int opc_ishl = 120;
32.255 - public static final int opc_lshl = 121;
32.256 - public static final int opc_ishr = 122;
32.257 - public static final int opc_lshr = 123;
32.258 - public static final int opc_iushr = 124;
32.259 - public static final int opc_lushr = 125;
32.260 - public static final int opc_iand = 126;
32.261 - public static final int opc_land = 127;
32.262 - public static final int opc_ior = 128;
32.263 - public static final int opc_lor = 129;
32.264 - public static final int opc_ixor = 130;
32.265 - public static final int opc_lxor = 131;
32.266 - public static final int opc_iinc = 132;
32.267 - public static final int opc_i2l = 133;
32.268 - public static final int opc_i2f = 134;
32.269 - public static final int opc_i2d = 135;
32.270 - public static final int opc_l2i = 136;
32.271 - public static final int opc_l2f = 137;
32.272 - public static final int opc_l2d = 138;
32.273 - public static final int opc_f2i = 139;
32.274 - public static final int opc_f2l = 140;
32.275 - public static final int opc_f2d = 141;
32.276 - public static final int opc_d2i = 142;
32.277 - public static final int opc_d2l = 143;
32.278 - public static final int opc_d2f = 144;
32.279 - public static final int opc_i2b = 145;
32.280 - public static final int opc_int2byte = 145;
32.281 - public static final int opc_i2c = 146;
32.282 - public static final int opc_int2char = 146;
32.283 - public static final int opc_i2s = 147;
32.284 - public static final int opc_int2short = 147;
32.285 - public static final int opc_lcmp = 148;
32.286 - public static final int opc_fcmpl = 149;
32.287 - public static final int opc_fcmpg = 150;
32.288 - public static final int opc_dcmpl = 151;
32.289 - public static final int opc_dcmpg = 152;
32.290 - public static final int opc_ifeq = 153;
32.291 - public static final int opc_ifne = 154;
32.292 - public static final int opc_iflt = 155;
32.293 - public static final int opc_ifge = 156;
32.294 - public static final int opc_ifgt = 157;
32.295 - public static final int opc_ifle = 158;
32.296 - public static final int opc_if_icmpeq = 159;
32.297 - public static final int opc_if_icmpne = 160;
32.298 - public static final int opc_if_icmplt = 161;
32.299 - public static final int opc_if_icmpge = 162;
32.300 - public static final int opc_if_icmpgt = 163;
32.301 - public static final int opc_if_icmple = 164;
32.302 - public static final int opc_if_acmpeq = 165;
32.303 - public static final int opc_if_acmpne = 166;
32.304 - public static final int opc_goto = 167;
32.305 - public static final int opc_jsr = 168;
32.306 - public static final int opc_ret = 169;
32.307 - public static final int opc_tableswitch = 170;
32.308 - public static final int opc_lookupswitch = 171;
32.309 - public static final int opc_ireturn = 172;
32.310 - public static final int opc_lreturn = 173;
32.311 - public static final int opc_freturn = 174;
32.312 - public static final int opc_dreturn = 175;
32.313 - public static final int opc_areturn = 176;
32.314 - public static final int opc_return = 177;
32.315 - public static final int opc_getstatic = 178;
32.316 - public static final int opc_putstatic = 179;
32.317 - public static final int opc_getfield = 180;
32.318 - public static final int opc_putfield = 181;
32.319 - public static final int opc_invokevirtual = 182;
32.320 - public static final int opc_invokenonvirtual = 183;
32.321 - public static final int opc_invokespecial = 183;
32.322 - public static final int opc_invokestatic = 184;
32.323 - public static final int opc_invokeinterface = 185;
32.324 -// public static final int opc_xxxunusedxxx = 186;
32.325 - public static final int opc_new = 187;
32.326 - public static final int opc_newarray = 188;
32.327 - public static final int opc_anewarray = 189;
32.328 - public static final int opc_arraylength = 190;
32.329 - public static final int opc_athrow = 191;
32.330 - public static final int opc_checkcast = 192;
32.331 - public static final int opc_instanceof = 193;
32.332 - public static final int opc_monitorenter = 194;
32.333 - public static final int opc_monitorexit = 195;
32.334 - public static final int opc_wide = 196;
32.335 - public static final int opc_multianewarray = 197;
32.336 - public static final int opc_ifnull = 198;
32.337 - public static final int opc_ifnonnull = 199;
32.338 - public static final int opc_goto_w = 200;
32.339 - public static final int opc_jsr_w = 201;
32.340 - /* Pseudo-instructions */
32.341 - public static final int opc_bytecode = 203;
32.342 - public static final int opc_try = 204;
32.343 - public static final int opc_endtry = 205;
32.344 - public static final int opc_catch = 206;
32.345 - public static final int opc_var = 207;
32.346 - public static final int opc_endvar = 208;
32.347 - public static final int opc_localsmap = 209;
32.348 - public static final int opc_stackmap = 210;
32.349 - /* PicoJava prefixes */
32.350 - public static final int opc_nonpriv = 254;
32.351 - public static final int opc_priv = 255;
32.352 -
32.353 - /* Wide instructions */
32.354 - public static final int opc_iload_w = (opc_wide<<8)|opc_iload;
32.355 - public static final int opc_lload_w = (opc_wide<<8)|opc_lload;
32.356 - public static final int opc_fload_w = (opc_wide<<8)|opc_fload;
32.357 - public static final int opc_dload_w = (opc_wide<<8)|opc_dload;
32.358 - public static final int opc_aload_w = (opc_wide<<8)|opc_aload;
32.359 - public static final int opc_istore_w = (opc_wide<<8)|opc_istore;
32.360 - public static final int opc_lstore_w = (opc_wide<<8)|opc_lstore;
32.361 - public static final int opc_fstore_w = (opc_wide<<8)|opc_fstore;
32.362 - public static final int opc_dstore_w = (opc_wide<<8)|opc_dstore;
32.363 - public static final int opc_astore_w = (opc_wide<<8)|opc_astore;
32.364 - public static final int opc_ret_w = (opc_wide<<8)|opc_ret;
32.365 - public static final int opc_iinc_w = (opc_wide<<8)|opc_iinc;
32.366 -
32.367 - /* Opcode Names */
32.368 - public static final String opcNamesTab[] = {
32.369 - "nop",
32.370 - "aconst_null",
32.371 - "iconst_m1",
32.372 - "iconst_0",
32.373 - "iconst_1",
32.374 - "iconst_2",
32.375 - "iconst_3",
32.376 - "iconst_4",
32.377 - "iconst_5",
32.378 - "lconst_0",
32.379 - "lconst_1",
32.380 - "fconst_0",
32.381 - "fconst_1",
32.382 - "fconst_2",
32.383 - "dconst_0",
32.384 - "dconst_1",
32.385 - "bipush",
32.386 - "sipush",
32.387 - "ldc",
32.388 - "ldc_w",
32.389 - "ldc2_w",
32.390 - "iload",
32.391 - "lload",
32.392 - "fload",
32.393 - "dload",
32.394 - "aload",
32.395 - "iload_0",
32.396 - "iload_1",
32.397 - "iload_2",
32.398 - "iload_3",
32.399 - "lload_0",
32.400 - "lload_1",
32.401 - "lload_2",
32.402 - "lload_3",
32.403 - "fload_0",
32.404 - "fload_1",
32.405 - "fload_2",
32.406 - "fload_3",
32.407 - "dload_0",
32.408 - "dload_1",
32.409 - "dload_2",
32.410 - "dload_3",
32.411 - "aload_0",
32.412 - "aload_1",
32.413 - "aload_2",
32.414 - "aload_3",
32.415 - "iaload",
32.416 - "laload",
32.417 - "faload",
32.418 - "daload",
32.419 - "aaload",
32.420 - "baload",
32.421 - "caload",
32.422 - "saload",
32.423 - "istore",
32.424 - "lstore",
32.425 - "fstore",
32.426 - "dstore",
32.427 - "astore",
32.428 - "istore_0",
32.429 - "istore_1",
32.430 - "istore_2",
32.431 - "istore_3",
32.432 - "lstore_0",
32.433 - "lstore_1",
32.434 - "lstore_2",
32.435 - "lstore_3",
32.436 - "fstore_0",
32.437 - "fstore_1",
32.438 - "fstore_2",
32.439 - "fstore_3",
32.440 - "dstore_0",
32.441 - "dstore_1",
32.442 - "dstore_2",
32.443 - "dstore_3",
32.444 - "astore_0",
32.445 - "astore_1",
32.446 - "astore_2",
32.447 - "astore_3",
32.448 - "iastore",
32.449 - "lastore",
32.450 - "fastore",
32.451 - "dastore",
32.452 - "aastore",
32.453 - "bastore",
32.454 - "castore",
32.455 - "sastore",
32.456 - "pop",
32.457 - "pop2",
32.458 - "dup",
32.459 - "dup_x1",
32.460 - "dup_x2",
32.461 - "dup2",
32.462 - "dup2_x1",
32.463 - "dup2_x2",
32.464 - "swap",
32.465 - "iadd",
32.466 - "ladd",
32.467 - "fadd",
32.468 - "dadd",
32.469 - "isub",
32.470 - "lsub",
32.471 - "fsub",
32.472 - "dsub",
32.473 - "imul",
32.474 - "lmul",
32.475 - "fmul",
32.476 - "dmul",
32.477 - "idiv",
32.478 - "ldiv",
32.479 - "fdiv",
32.480 - "ddiv",
32.481 - "irem",
32.482 - "lrem",
32.483 - "frem",
32.484 - "drem",
32.485 - "ineg",
32.486 - "lneg",
32.487 - "fneg",
32.488 - "dneg",
32.489 - "ishl",
32.490 - "lshl",
32.491 - "ishr",
32.492 - "lshr",
32.493 - "iushr",
32.494 - "lushr",
32.495 - "iand",
32.496 - "land",
32.497 - "ior",
32.498 - "lor",
32.499 - "ixor",
32.500 - "lxor",
32.501 - "iinc",
32.502 - "i2l",
32.503 - "i2f",
32.504 - "i2d",
32.505 - "l2i",
32.506 - "l2f",
32.507 - "l2d",
32.508 - "f2i",
32.509 - "f2l",
32.510 - "f2d",
32.511 - "d2i",
32.512 - "d2l",
32.513 - "d2f",
32.514 - "i2b",
32.515 - "i2c",
32.516 - "i2s",
32.517 - "lcmp",
32.518 - "fcmpl",
32.519 - "fcmpg",
32.520 - "dcmpl",
32.521 - "dcmpg",
32.522 - "ifeq",
32.523 - "ifne",
32.524 - "iflt",
32.525 - "ifge",
32.526 - "ifgt",
32.527 - "ifle",
32.528 - "if_icmpeq",
32.529 - "if_icmpne",
32.530 - "if_icmplt",
32.531 - "if_icmpge",
32.532 - "if_icmpgt",
32.533 - "if_icmple",
32.534 - "if_acmpeq",
32.535 - "if_acmpne",
32.536 - "goto",
32.537 - "jsr",
32.538 - "ret",
32.539 - "tableswitch",
32.540 - "lookupswitch",
32.541 - "ireturn",
32.542 - "lreturn",
32.543 - "freturn",
32.544 - "dreturn",
32.545 - "areturn",
32.546 - "return",
32.547 - "getstatic",
32.548 - "putstatic",
32.549 - "getfield",
32.550 - "putfield",
32.551 - "invokevirtual",
32.552 - "invokespecial", // was "invokenonvirtual",
32.553 - "invokestatic",
32.554 - "invokeinterface",
32.555 - "bytecode 186", //"xxxunusedxxx",
32.556 - "new",
32.557 - "newarray",
32.558 - "anewarray",
32.559 - "arraylength",
32.560 - "athrow",
32.561 - "checkcast",
32.562 - "instanceof",
32.563 - "monitorenter",
32.564 - "monitorexit",
32.565 - null, // "wide",
32.566 - "multianewarray",
32.567 - "ifnull",
32.568 - "ifnonnull",
32.569 - "goto_w",
32.570 - "jsr_w",
32.571 - "bytecode 202", // "breakpoint",
32.572 - "bytecode",
32.573 - "try",
32.574 - "endtry",
32.575 - "catch",
32.576 - "var",
32.577 - "endvar",
32.578 - "locals_map",
32.579 - "stack_map"
32.580 - };
32.581 -
32.582 - /* Opcode Lengths */
32.583 - public static final int opcLengthsTab[] = {
32.584 - 1,
32.585 - 1,
32.586 - 1,
32.587 - 1,
32.588 - 1,
32.589 - 1,
32.590 - 1,
32.591 - 1,
32.592 - 1,
32.593 - 1,
32.594 - 1,
32.595 - 1,
32.596 - 1,
32.597 - 1,
32.598 - 1,
32.599 - 1,
32.600 - 2,
32.601 - 3,
32.602 - 2,
32.603 - 3,
32.604 - 3,
32.605 - 2,
32.606 - 2,
32.607 - 2,
32.608 - 2,
32.609 - 2,
32.610 - 1,
32.611 - 1,
32.612 - 1,
32.613 - 1,
32.614 - 1,
32.615 - 1,
32.616 - 1,
32.617 - 1,
32.618 - 1,
32.619 - 1,
32.620 - 1,
32.621 - 1,
32.622 - 1,
32.623 - 1,
32.624 - 1,
32.625 - 1,
32.626 - 1,
32.627 - 1,
32.628 - 1,
32.629 - 1,
32.630 - 1,
32.631 - 1,
32.632 - 1,
32.633 - 1,
32.634 - 1,
32.635 - 1,
32.636 - 1,
32.637 - 1,
32.638 - 2,
32.639 - 2,
32.640 - 2,
32.641 - 2,
32.642 - 2,
32.643 - 1,
32.644 - 1,
32.645 - 1,
32.646 - 1,
32.647 - 1,
32.648 - 1,
32.649 - 1,
32.650 - 1,
32.651 - 1,
32.652 - 1,
32.653 - 1,
32.654 - 1,
32.655 - 1,
32.656 - 1,
32.657 - 1,
32.658 - 1,
32.659 - 1,
32.660 - 1,
32.661 - 1,
32.662 - 1,
32.663 - 1,
32.664 - 1,
32.665 - 1,
32.666 - 1,
32.667 - 1,
32.668 - 1,
32.669 - 1,
32.670 - 1,
32.671 - 1,
32.672 - 1,
32.673 - 1,
32.674 - 1,
32.675 - 1,
32.676 - 1,
32.677 - 1,
32.678 - 1,
32.679 - 1,
32.680 - 1,
32.681 - 1,
32.682 - 1,
32.683 - 1,
32.684 - 1,
32.685 - 1,
32.686 - 1,
32.687 - 1,
32.688 - 1,
32.689 - 1,
32.690 - 1,
32.691 - 1,
32.692 - 1,
32.693 - 1,
32.694 - 1,
32.695 - 1,
32.696 - 1,
32.697 - 1,
32.698 - 1,
32.699 - 1,
32.700 - 1,
32.701 - 1,
32.702 - 1,
32.703 - 1,
32.704 - 1,
32.705 - 1,
32.706 - 1,
32.707 - 1,
32.708 - 1,
32.709 - 1,
32.710 - 1,
32.711 - 1,
32.712 - 1,
32.713 - 1,
32.714 - 1,
32.715 - 1,
32.716 - 3,
32.717 - 1,
32.718 - 1,
32.719 - 1,
32.720 - 1,
32.721 - 1,
32.722 - 1,
32.723 - 1,
32.724 - 1,
32.725 - 1,
32.726 - 1,
32.727 - 1,
32.728 - 1,
32.729 - 1,
32.730 - 1,
32.731 - 1,
32.732 - 1,
32.733 - 1,
32.734 - 1,
32.735 - 1,
32.736 - 1,
32.737 - 3,
32.738 - 3,
32.739 - 3,
32.740 - 3,
32.741 - 3,
32.742 - 3,
32.743 - 3,
32.744 - 3,
32.745 - 3,
32.746 - 3,
32.747 - 3,
32.748 - 3,
32.749 - 3,
32.750 - 3,
32.751 - 3,
32.752 - 3,
32.753 - 2,
32.754 - 99,
32.755 - 99,
32.756 - 1,
32.757 - 1,
32.758 - 1,
32.759 - 1,
32.760 - 1,
32.761 - 1,
32.762 - 3,
32.763 - 3,
32.764 - 3,
32.765 - 3,
32.766 - 3,
32.767 - 3,
32.768 - 3,
32.769 - 5,
32.770 - 0,
32.771 - 3,
32.772 - 2,
32.773 - 3,
32.774 - 1,
32.775 - 1,
32.776 - 3,
32.777 - 3,
32.778 - 1,
32.779 - 1,
32.780 - 0, // wide
32.781 - 4,
32.782 - 3,
32.783 - 3,
32.784 - 5,
32.785 - 5,
32.786 - 1,
32.787 - 1, 0, 0, 0, 0, 0 // pseudo
32.788 - };
32.789 -
32.790 -}
33.1 --- a/javap/src/main/java/sun/tools/javap/StackMapData.java Fri Nov 16 08:06:48 2012 +0100
33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
33.3 @@ -1,71 +0,0 @@
33.4 -/*
33.5 - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
33.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33.7 - *
33.8 - * This code is free software; you can redistribute it and/or modify it
33.9 - * under the terms of the GNU General Public License version 2 only, as
33.10 - * published by the Free Software Foundation. Oracle designates this
33.11 - * particular file as subject to the "Classpath" exception as provided
33.12 - * by Oracle in the LICENSE file that accompanied this code.
33.13 - *
33.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
33.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33.17 - * version 2 for more details (a copy is included in the LICENSE file that
33.18 - * accompanied this code).
33.19 - *
33.20 - * You should have received a copy of the GNU General Public License version
33.21 - * 2 along with this work; if not, write to the Free Software Foundation,
33.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33.23 - *
33.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33.25 - * or visit www.oracle.com if you need additional information or have any
33.26 - * questions.
33.27 - */
33.28 -
33.29 -
33.30 -package sun.tools.javap;
33.31 -
33.32 -import java.util.*;
33.33 -import java.io.*;
33.34 -
33.35 -import static sun.tools.javap.RuntimeConstants.*;
33.36 -
33.37 -/* represents one entry of StackMap attribute
33.38 - */
33.39 -class StackMapData {
33.40 - final int offset;
33.41 - final int[] locals;
33.42 - final int[] stack;
33.43 -
33.44 - StackMapData(int offset, int[] locals, int[] stack) {
33.45 - this.offset = offset;
33.46 - this.locals = locals;
33.47 - this.stack = stack;
33.48 - }
33.49 -
33.50 - StackMapData(DataInputStream in, MethodData method) throws IOException {
33.51 - offset = in.readUnsignedShort();
33.52 - int local_size = in.readUnsignedShort();
33.53 - locals = readTypeArray(in, local_size, method);
33.54 - int stack_size = in.readUnsignedShort();
33.55 - stack = readTypeArray(in, stack_size, method);
33.56 - }
33.57 -
33.58 - static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
33.59 - int[] types = new int[length];
33.60 - for (int i=0; i<length; i++) {
33.61 - types[i] = readType(in, method);
33.62 - }
33.63 - return types;
33.64 - }
33.65 -
33.66 - static final int readType(DataInputStream in, MethodData method) throws IOException {
33.67 - int type = in.readUnsignedByte();
33.68 - if (type == ITEM_Object || type == ITEM_NewObject) {
33.69 - type = type | (in.readUnsignedShort()<<8);
33.70 - }
33.71 - return type;
33.72 - }
33.73 -
33.74 -}
34.1 --- a/javap/src/main/java/sun/tools/javap/StackMapTableData.java Fri Nov 16 08:06:48 2012 +0100
34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
34.3 @@ -1,126 +0,0 @@
34.4 -/*
34.5 - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
34.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34.7 - *
34.8 - * This code is free software; you can redistribute it and/or modify it
34.9 - * under the terms of the GNU General Public License version 2 only, as
34.10 - * published by the Free Software Foundation. Oracle designates this
34.11 - * particular file as subject to the "Classpath" exception as provided
34.12 - * by Oracle in the LICENSE file that accompanied this code.
34.13 - *
34.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
34.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34.17 - * version 2 for more details (a copy is included in the LICENSE file that
34.18 - * accompanied this code).
34.19 - *
34.20 - * You should have received a copy of the GNU General Public License version
34.21 - * 2 along with this work; if not, write to the Free Software Foundation,
34.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34.23 - *
34.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
34.25 - * or visit www.oracle.com if you need additional information or have any
34.26 - * questions.
34.27 - */
34.28 -
34.29 -
34.30 -package sun.tools.javap;
34.31 -
34.32 -import java.io.*;
34.33 -
34.34 -import static sun.tools.javap.RuntimeConstants.*;
34.35 -
34.36 -/* represents one entry of StackMapTable attribute
34.37 - */
34.38 -class StackMapTableData {
34.39 - final int frameType;
34.40 - int offsetDelta;
34.41 -
34.42 - StackMapTableData(int frameType) {
34.43 - this.frameType = frameType;
34.44 - }
34.45 -
34.46 - static class SameFrame extends StackMapTableData {
34.47 - SameFrame(int frameType, int offsetDelta) {
34.48 - super(frameType);
34.49 - this.offsetDelta = offsetDelta;
34.50 - }
34.51 - }
34.52 -
34.53 - static class SameLocals1StackItem extends StackMapTableData {
34.54 - final int[] stack;
34.55 - SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
34.56 - super(frameType);
34.57 - this.offsetDelta = offsetDelta;
34.58 - this.stack = stack;
34.59 - }
34.60 - }
34.61 -
34.62 - static class ChopFrame extends StackMapTableData {
34.63 - ChopFrame(int frameType, int offsetDelta) {
34.64 - super(frameType);
34.65 - this.offsetDelta = offsetDelta;
34.66 - }
34.67 - }
34.68 -
34.69 - static class AppendFrame extends StackMapTableData {
34.70 - final int[] locals;
34.71 - AppendFrame(int frameType, int offsetDelta, int[] locals) {
34.72 - super(frameType);
34.73 - this.offsetDelta = offsetDelta;
34.74 - this.locals = locals;
34.75 - }
34.76 - }
34.77 -
34.78 - static class FullFrame extends StackMapTableData {
34.79 - final int[] locals;
34.80 - final int[] stack;
34.81 - FullFrame(int offsetDelta, int[] locals, int[] stack) {
34.82 - super(FULL_FRAME);
34.83 - this.offsetDelta = offsetDelta;
34.84 - this.locals = locals;
34.85 - this.stack = stack;
34.86 - }
34.87 - }
34.88 -
34.89 - static StackMapTableData getInstance(DataInputStream in, MethodData method)
34.90 - throws IOException {
34.91 - int frameType = in.readUnsignedByte();
34.92 -
34.93 - if (frameType < SAME_FRAME_BOUND) {
34.94 - // same_frame
34.95 - return new SameFrame(frameType, frameType);
34.96 - } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
34.97 - // same_locals_1_stack_item_frame
34.98 - // read additional single stack element
34.99 - return new SameLocals1StackItem(frameType,
34.100 - (frameType - SAME_FRAME_BOUND),
34.101 - StackMapData.readTypeArray(in, 1, method));
34.102 - } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
34.103 - // same_locals_1_stack_item_extended
34.104 - return new SameLocals1StackItem(frameType,
34.105 - in.readUnsignedShort(),
34.106 - StackMapData.readTypeArray(in, 1, method));
34.107 - } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
34.108 - // chop_frame or same_frame_extended
34.109 - return new ChopFrame(frameType, in.readUnsignedShort());
34.110 - } else if (frameType == SAME_FRAME_EXTENDED) {
34.111 - // chop_frame or same_frame_extended
34.112 - return new SameFrame(frameType, in.readUnsignedShort());
34.113 - } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
34.114 - // append_frame
34.115 - return new AppendFrame(frameType, in.readUnsignedShort(),
34.116 - StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
34.117 - } else if (frameType == FULL_FRAME) {
34.118 - // full_frame
34.119 - int offsetDelta = in.readUnsignedShort();
34.120 - int locals_size = in.readUnsignedShort();
34.121 - int[] locals = StackMapData.readTypeArray(in, locals_size, method);
34.122 - int stack_size = in.readUnsignedShort();
34.123 - int[] stack = StackMapData.readTypeArray(in, stack_size, method);
34.124 - return new FullFrame(offsetDelta, locals, stack);
34.125 - } else {
34.126 - throw new ClassFormatError("unrecognized frame_type in StackMapTable");
34.127 - }
34.128 - }
34.129 -}
35.1 --- a/javap/src/main/java/sun/tools/javap/Tables.java Fri Nov 16 08:06:48 2012 +0100
35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
35.3 @@ -1,373 +0,0 @@
35.4 -/*
35.5 - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
35.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35.7 - *
35.8 - * This code is free software; you can redistribute it and/or modify it
35.9 - * under the terms of the GNU General Public License version 2 only, as
35.10 - * published by the Free Software Foundation. Oracle designates this
35.11 - * particular file as subject to the "Classpath" exception as provided
35.12 - * by Oracle in the LICENSE file that accompanied this code.
35.13 - *
35.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
35.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
35.17 - * version 2 for more details (a copy is included in the LICENSE file that
35.18 - * accompanied this code).
35.19 - *
35.20 - * You should have received a copy of the GNU General Public License version
35.21 - * 2 along with this work; if not, write to the Free Software Foundation,
35.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35.23 - *
35.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35.25 - * or visit www.oracle.com if you need additional information or have any
35.26 - * questions.
35.27 - */
35.28 -
35.29 -
35.30 -package sun.tools.javap;
35.31 -
35.32 -
35.33 -
35.34 -public class Tables implements Constants {
35.35 - /**
35.36 - * Define mnemocodes table.
35.37 - */
35.38 - static Hashtable mnemocodes = new Hashtable(301, 0.5f);
35.39 - static String opcExtNamesTab[]=new String[128];
35.40 - static String opcPrivExtNamesTab[]=new String[128];
35.41 - static void defineNonPriv(int opc, String mnem) {
35.42 - mnemocodes.put(opcExtNamesTab[opc]=mnem, new Integer(opc_nonpriv*256+opc));
35.43 - }
35.44 - static void definePriv(int opc, String mnem) {
35.45 - mnemocodes.put(opcPrivExtNamesTab[opc]="priv_"+mnem, new Integer(opc_priv*256+opc));
35.46 - }
35.47 - static void defineExt(int opc, String mnem) {
35.48 - defineNonPriv(opc, mnem);
35.49 - definePriv(opc, mnem);
35.50 - }
35.51 - static { int k;
35.52 - for (k=0; k<opc_wide; k++) {
35.53 - mnemocodes.put(opcNamesTab[k], new Integer(k));
35.54 - }
35.55 - for (k=opc_wide+1; k<opcNamesTab.length; k++) {
35.56 - mnemocodes.put(opcNamesTab[k], new Integer(k));
35.57 - }
35.58 - mnemocodes.put("invokenonvirtual", new Integer(opc_invokespecial));
35.59 -
35.60 - mnemocodes.put("iload_w", new Integer(opc_iload_w));
35.61 - mnemocodes.put("lload_w", new Integer(opc_lload_w));
35.62 - mnemocodes.put("fload_w", new Integer(opc_fload_w));
35.63 - mnemocodes.put("dload_w", new Integer(opc_dload_w));
35.64 - mnemocodes.put("aload_w", new Integer(opc_aload_w));
35.65 - mnemocodes.put("istore_w", new Integer(opc_istore_w));
35.66 - mnemocodes.put("lstore_w", new Integer(opc_lstore_w));
35.67 - mnemocodes.put("fstore_w", new Integer(opc_fstore_w));
35.68 - mnemocodes.put("dstore_w", new Integer(opc_dstore_w));
35.69 - mnemocodes.put("astore_w", new Integer(opc_astore_w));
35.70 - mnemocodes.put("ret_w", new Integer(opc_ret_w));
35.71 - mnemocodes.put("iinc_w", new Integer(opc_iinc_w));
35.72 -
35.73 - mnemocodes.put("nonpriv", new Integer(opc_nonpriv));
35.74 - mnemocodes.put("priv", new Integer(opc_priv));
35.75 -
35.76 - defineExt(0, "load_ubyte");
35.77 - defineExt(1, "load_byte");
35.78 - defineExt(2, "load_char");
35.79 - defineExt(3, "load_short");
35.80 - defineExt(4, "load_word");
35.81 - defineExt(10, "load_char_oe");
35.82 - defineExt(11, "load_short_oe");
35.83 - defineExt(12, "load_word_oe");
35.84 - defineExt(16, "ncload_ubyte");
35.85 - defineExt(17, "ncload_byte");
35.86 - defineExt(18, "ncload_char");
35.87 - defineExt(19, "ncload_short");
35.88 - defineExt(20, "ncload_word");
35.89 - defineExt(26, "ncload_char_oe");
35.90 - defineExt(27, "ncload_short_oe");
35.91 - defineExt(28, "ncload_word_oe");
35.92 - defineExt(30, "cache_flush");
35.93 - defineExt(32, "store_byte");
35.94 - defineExt(34, "store_short");
35.95 - defineExt(36, "store_word");
35.96 - defineExt(42, "store_short_oe");
35.97 - defineExt(44, "store_word_oe");
35.98 - defineExt(48, "ncstore_byte");
35.99 - defineExt(50, "ncstore_short");
35.100 - defineExt(52, "ncstore_word");
35.101 - defineExt(58, "ncstore_short_oe");
35.102 - defineExt(60, "ncstore_word_oe");
35.103 - defineExt(62, "zero_line");
35.104 - defineNonPriv(5, "ret_from_sub");
35.105 - defineNonPriv(63, "enter_sync_method");
35.106 - definePriv(5, "ret_from_trap");
35.107 - definePriv(6, "read_dcache_tag");
35.108 - definePriv(7, "read_dcache_data");
35.109 - definePriv(14, "read_icache_tag");
35.110 - definePriv(15, "read_icache_data");
35.111 - definePriv(22, "powerdown");
35.112 - definePriv(23, "read_scache_data");
35.113 - definePriv(31, "cache_index_flush");
35.114 - definePriv(38, "write_dcache_tag");
35.115 - definePriv(39, "write_dcache_data");
35.116 - definePriv(46, "write_icache_tag");
35.117 - definePriv(47, "write_icache_data");
35.118 - definePriv(54, "reset");
35.119 - definePriv(55, "write_scache_data");
35.120 - for (k=0; k<32; k++) {
35.121 - definePriv(k+64, "read_reg_"+k);
35.122 - }
35.123 - for (k=0; k<32; k++) {
35.124 - definePriv(k+96, "write_reg_"+k);
35.125 - }
35.126 - }
35.127 -
35.128 - public static int opcLength(int opc) throws ArrayIndexOutOfBoundsException {
35.129 - switch (opc>>8) {
35.130 - case 0:
35.131 - return opcLengthsTab[opc];
35.132 - case opc_wide:
35.133 - switch (opc&0xFF) {
35.134 - case opc_aload: case opc_astore:
35.135 - case opc_fload: case opc_fstore:
35.136 - case opc_iload: case opc_istore:
35.137 - case opc_lload: case opc_lstore:
35.138 - case opc_dload: case opc_dstore:
35.139 - case opc_ret:
35.140 - return 4;
35.141 - case opc_iinc:
35.142 - return 6;
35.143 - default:
35.144 - throw new ArrayIndexOutOfBoundsException();
35.145 - }
35.146 - case opc_nonpriv:
35.147 - case opc_priv:
35.148 - return 2;
35.149 - default:
35.150 - throw new ArrayIndexOutOfBoundsException();
35.151 - }
35.152 - }
35.153 -
35.154 - public static String opcName(int opc) {
35.155 - try {
35.156 - switch (opc>>8) {
35.157 - case 0:
35.158 - return opcNamesTab[opc];
35.159 - case opc_wide: {
35.160 - String mnem=opcNamesTab[opc&0xFF]+"_w";
35.161 - if (mnemocodes.get(mnem) == null)
35.162 - return null; // non-existent opcode
35.163 - return mnem;
35.164 - }
35.165 - case opc_nonpriv:
35.166 - return opcExtNamesTab[opc&0xFF];
35.167 - case opc_priv:
35.168 - return opcPrivExtNamesTab[opc&0xFF];
35.169 - default:
35.170 - return null;
35.171 - }
35.172 - } catch (ArrayIndexOutOfBoundsException e) {
35.173 - switch (opc) {
35.174 - case opc_nonpriv:
35.175 - return "nonpriv";
35.176 - case opc_priv:
35.177 - return "priv";
35.178 - default:
35.179 - return null;
35.180 - }
35.181 - }
35.182 - }
35.183 -
35.184 - public static int opcode(String mnem) {
35.185 - Integer Val=(Integer)(mnemocodes.get(mnem));
35.186 - if (Val == null) return -1;
35.187 - return Val.intValue();
35.188 - }
35.189 -
35.190 - /**
35.191 - * Initialized keyword and token Hashtables
35.192 - */
35.193 - static Vector keywordNames = new Vector(40);
35.194 - private static void defineKeywordName(String id, int token) {
35.195 -
35.196 - if (token>=keywordNames.size()) {
35.197 - keywordNames.setSize(token+1);
35.198 - }
35.199 - keywordNames.setElementAt(id, token);
35.200 - }
35.201 - public static String keywordName(int token) {
35.202 - if (token==-1) return "EOF";
35.203 - if (token>=keywordNames.size()) return null;
35.204 - return (String)keywordNames.elementAt(token);
35.205 - }
35.206 - static {
35.207 - defineKeywordName("ident", IDENT);
35.208 - defineKeywordName("STRINGVAL", STRINGVAL);
35.209 - defineKeywordName("intVal", INTVAL);
35.210 - defineKeywordName("longVal", LONGVAL);
35.211 - defineKeywordName("floatVal", FLOATVAL);
35.212 - defineKeywordName("doubleVal", DOUBLEVAL);
35.213 - defineKeywordName("SEMICOLON", SEMICOLON);
35.214 - defineKeywordName("COLON", COLON);
35.215 - defineKeywordName("LBRACE", LBRACE);
35.216 - defineKeywordName("RBRACE", RBRACE);
35.217 - }
35.218 -
35.219 - static Hashtable keywords = new Hashtable(40);
35.220 - public static int keyword(String idValue) {
35.221 - Integer Val=(Integer)(keywords.get(idValue));
35.222 - if (Val == null) return IDENT;
35.223 - return Val.intValue();
35.224 - }
35.225 -
35.226 - private static void defineKeyword(String id, int token) {
35.227 - keywords.put(id, new Integer(token));
35.228 - defineKeywordName(id, token);
35.229 - }
35.230 - static {
35.231 - // Modifier keywords
35.232 - defineKeyword("private", PRIVATE);
35.233 - defineKeyword("public", PUBLIC);
35.234 - defineKeyword("protected", PROTECTED);
35.235 - defineKeyword("static", STATIC);
35.236 - defineKeyword("transient", TRANSIENT);
35.237 - defineKeyword("synchronized", SYNCHRONIZED);
35.238 - defineKeyword("super", SUPER);
35.239 - defineKeyword("native", NATIVE);
35.240 - defineKeyword("abstract", ABSTRACT);
35.241 - defineKeyword("volatile", VOLATILE);
35.242 - defineKeyword("final", FINAL);
35.243 - defineKeyword("interface",INTERFACE);
35.244 - defineKeyword("synthetic",SYNTHETIC);
35.245 - defineKeyword("strict",STRICT);
35.246 -
35.247 - // Declaration keywords
35.248 - defineKeyword("package",PACKAGE);
35.249 - defineKeyword("class",CLASS);
35.250 - defineKeyword("extends",EXTENDS);
35.251 - defineKeyword("implements",IMPLEMENTS);
35.252 - defineKeyword("const", CONST);
35.253 - defineKeyword("throws",THROWS);
35.254 - defineKeyword("interface",INTERFACE);
35.255 - defineKeyword("Method",METHODREF);
35.256 - defineKeyword("Field",FIELDREF);
35.257 - defineKeyword("stack",STACK);
35.258 - defineKeyword("locals",LOCAL);
35.259 -
35.260 - // used in switchtables
35.261 - defineKeyword("default", DEFAULT);
35.262 -
35.263 - // used in inner class declarations
35.264 - defineKeyword("InnerClass", INNERCLASS);
35.265 - defineKeyword("of", OF);
35.266 -
35.267 - // misc
35.268 - defineKeyword("bits",BITS);
35.269 - defineKeyword("Infinity",INF);
35.270 - defineKeyword("Inf",INF);
35.271 - defineKeyword("NaN",NAN);
35.272 - }
35.273 -
35.274 - /**
35.275 - * Define tag table.
35.276 - */
35.277 - private static Vector tagNames = new Vector(10);
35.278 - private static Hashtable Tags = new Hashtable(10);
35.279 - static {
35.280 - defineTag("Asciz",CONSTANT_UTF8);
35.281 - defineTag("int",CONSTANT_INTEGER);
35.282 - defineTag("float",CONSTANT_FLOAT);
35.283 - defineTag("long",CONSTANT_LONG);
35.284 - defineTag("double",CONSTANT_DOUBLE);
35.285 - defineTag("class",CONSTANT_CLASS);
35.286 - defineTag("String",CONSTANT_STRING);
35.287 - defineTag("Field",CONSTANT_FIELD);
35.288 - defineTag("Method",CONSTANT_METHOD);
35.289 - defineTag("InterfaceMethod",CONSTANT_INTERFACEMETHOD);
35.290 - defineTag("NameAndType",CONSTANT_NAMEANDTYPE);
35.291 - }
35.292 - private static void defineTag(String id, int val) {
35.293 - Tags.put(id, new Integer(val));
35.294 - if (val>=tagNames.size()) {
35.295 - tagNames.setSize(val+1);
35.296 - }
35.297 - tagNames.setElementAt(id, val);
35.298 - }
35.299 - public static String tagName(int tag) {
35.300 - if (tag>=tagNames.size()) return null;
35.301 - return (String)tagNames.elementAt(tag);
35.302 - }
35.303 - public static int tagValue(String idValue) {
35.304 - Integer Val=(Integer)(Tags.get(idValue));
35.305 - if (Val == null) return 0;
35.306 - return Val.intValue();
35.307 - }
35.308 -
35.309 - /**
35.310 - * Define type table. These types used in "newarray" instruction only.
35.311 - */
35.312 - private static Vector typeNames = new Vector(10);
35.313 - private static Hashtable Types = new Hashtable(10);
35.314 - static {
35.315 - defineType("int",T_INT);
35.316 - defineType("long",T_LONG);
35.317 - defineType("float",T_FLOAT);
35.318 - defineType("double",T_DOUBLE);
35.319 - defineType("class",T_CLASS);
35.320 - defineType("boolean",T_BOOLEAN);
35.321 - defineType("char",T_CHAR);
35.322 - defineType("byte",T_BYTE);
35.323 - defineType("short",T_SHORT);
35.324 - }
35.325 - private static void defineType(String id, int val) {
35.326 - Types.put(id, new Integer(val));
35.327 - if (val>=typeNames.size()) {
35.328 - typeNames.setSize(val+1);
35.329 - }
35.330 - typeNames.setElementAt(id, val);
35.331 - }
35.332 - public static int typeValue(String idValue) {
35.333 - Integer Val=(Integer)(Types.get(idValue));
35.334 - if (Val == null) return -1;
35.335 - return Val.intValue();
35.336 - }
35.337 - public static String typeName(int type) {
35.338 - if (type>=typeNames.size()) return null;
35.339 - return (String)typeNames.elementAt(type);
35.340 - }
35.341 -
35.342 - /**
35.343 - * Define MapTypes table.
35.344 - * These constants used in stackmap tables only.
35.345 - */
35.346 - private static Vector mapTypeNames = new Vector(10);
35.347 - private static Hashtable MapTypes = new Hashtable(10);
35.348 - static {
35.349 - defineMapType("bogus", ITEM_Bogus);
35.350 - defineMapType("int", ITEM_Integer);
35.351 - defineMapType("float", ITEM_Float);
35.352 - defineMapType("double", ITEM_Double);
35.353 - defineMapType("long", ITEM_Long);
35.354 - defineMapType("null", ITEM_Null);
35.355 - defineMapType("this", ITEM_InitObject);
35.356 - defineMapType("CP", ITEM_Object);
35.357 - defineMapType("uninitialized", ITEM_NewObject);
35.358 - }
35.359 - private static void defineMapType(String id, int val) {
35.360 - MapTypes.put(id, new Integer(val));
35.361 - if (val>=mapTypeNames.size()) {
35.362 - mapTypeNames.setSize(val+1);
35.363 - }
35.364 - mapTypeNames.setElementAt(id, val);
35.365 - }
35.366 - public static int mapTypeValue(String idValue) {
35.367 - Integer Val=(Integer)(MapTypes.get(idValue));
35.368 - if (Val == null) return -1;
35.369 - return Val.intValue();
35.370 - }
35.371 - public static String mapTypeName(int type) {
35.372 - if (type>=mapTypeNames.size()) return null;
35.373 - return (String)mapTypeNames.elementAt(type);
35.374 - }
35.375 -
35.376 -}
36.1 --- a/javap/src/main/java/sun/tools/javap/TrapData.java Fri Nov 16 08:06:48 2012 +0100
36.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
36.3 @@ -1,60 +0,0 @@
36.4 -/*
36.5 - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
36.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36.7 - *
36.8 - * This code is free software; you can redistribute it and/or modify it
36.9 - * under the terms of the GNU General Public License version 2 only, as
36.10 - * published by the Free Software Foundation. Oracle designates this
36.11 - * particular file as subject to the "Classpath" exception as provided
36.12 - * by Oracle in the LICENSE file that accompanied this code.
36.13 - *
36.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
36.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
36.17 - * version 2 for more details (a copy is included in the LICENSE file that
36.18 - * accompanied this code).
36.19 - *
36.20 - * You should have received a copy of the GNU General Public License version
36.21 - * 2 along with this work; if not, write to the Free Software Foundation,
36.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36.23 - *
36.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
36.25 - * or visit www.oracle.com if you need additional information or have any
36.26 - * questions.
36.27 - */
36.28 -
36.29 -
36.30 -package sun.tools.javap;
36.31 -
36.32 -import java.util.*;
36.33 -import java.io.*;
36.34 -
36.35 -/**
36.36 - * Stores exception table data in code attribute.
36.37 - *
36.38 - * @author Sucheta Dambalkar (Adopted code from jdis)
36.39 - */
36.40 -class TrapData {
36.41 - short start_pc, end_pc, handler_pc, catch_cpx;
36.42 - int num;
36.43 -
36.44 -
36.45 - /**
36.46 - * Read and store exception table data in code attribute.
36.47 - */
36.48 - public TrapData(DataInputStream in, int num) throws IOException {
36.49 - this.num=num;
36.50 - start_pc = in.readShort();
36.51 - end_pc=in.readShort();
36.52 - handler_pc=in.readShort();
36.53 - catch_cpx=in.readShort();
36.54 - }
36.55 -
36.56 - /**
36.57 - * returns recommended identifier
36.58 - */
36.59 - public String ident() {
36.60 - return "t"+num;
36.61 - }
36.62 -
36.63 -}
37.1 --- a/javap/src/main/java/sun/tools/javap/TypeSignature.java Fri Nov 16 08:06:48 2012 +0100
37.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
37.3 @@ -1,295 +0,0 @@
37.4 -/*
37.5 - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
37.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37.7 - *
37.8 - * This code is free software; you can redistribute it and/or modify it
37.9 - * under the terms of the GNU General Public License version 2 only, as
37.10 - * published by the Free Software Foundation. Oracle designates this
37.11 - * particular file as subject to the "Classpath" exception as provided
37.12 - * by Oracle in the LICENSE file that accompanied this code.
37.13 - *
37.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
37.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37.17 - * version 2 for more details (a copy is included in the LICENSE file that
37.18 - * accompanied this code).
37.19 - *
37.20 - * You should have received a copy of the GNU General Public License version
37.21 - * 2 along with this work; if not, write to the Free Software Foundation,
37.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37.23 - *
37.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
37.25 - * or visit www.oracle.com if you need additional information or have any
37.26 - * questions.
37.27 - */
37.28 -
37.29 -
37.30 -package sun.tools.javap;
37.31 -
37.32 -import java.util.*;
37.33 -import java.io.*;
37.34 -
37.35 -/**
37.36 - * Returns java type signature.
37.37 - *
37.38 - * @author Sucheta Dambalkar
37.39 - */
37.40 -public class TypeSignature {
37.41 -
37.42 - String parameters = null;
37.43 - String returntype = null;
37.44 - String fieldtype = null;
37.45 - int argumentlength = 0;
37.46 -
37.47 - public TypeSignature(String JVMSignature){
37.48 -
37.49 - if(JVMSignature != null){
37.50 - if(JVMSignature.indexOf("(") == -1){
37.51 - //This is a field type.
37.52 - this.fieldtype = getFieldTypeSignature(JVMSignature);
37.53 - }else {
37.54 - String parameterdes = null;
37.55 - if((JVMSignature.indexOf(")")-1) > (JVMSignature.indexOf("("))){
37.56 - //Get parameter signature.
37.57 - parameterdes =
37.58 - JVMSignature.substring(JVMSignature.indexOf("(")+1,
37.59 - JVMSignature.indexOf(")"));
37.60 - this.parameters = getParametersHelper(parameterdes);
37.61 - }else this.parameters = "()";
37.62 - //Get return type signature.
37.63 - String returndes = JVMSignature.substring(JVMSignature.lastIndexOf(")")+1);
37.64 - this.returntype = getReturnTypeHelper(returndes);
37.65 - }
37.66 - }
37.67 - }
37.68 -
37.69 - /**
37.70 - * Returns java type signature of a field.
37.71 - */
37.72 - public String getFieldTypeSignature(String fielddes){
37.73 - if(fielddes.startsWith("L")){
37.74 - return(getObjectType(fielddes));
37.75 - }else if(fielddes.startsWith("[")){
37.76 - return(getArrayType(fielddes));
37.77 - }else
37.78 - return(getBaseType(fielddes));
37.79 - }
37.80 -
37.81 - /**
37.82 - * Returns java type signature of a parameter.
37.83 - */
37.84 - public String getParametersHelper(String parameterdes){
37.85 - Vector parameters = new Vector();
37.86 - int startindex = -1;
37.87 - int endindex = -1;
37.88 - String param = "";
37.89 -
37.90 - while(parameterdes != null){
37.91 -
37.92 - if(parameterdes.startsWith("L")){
37.93 - //parameter is a object.
37.94 - startindex = parameterdes.indexOf("L");
37.95 - endindex = parameterdes.indexOf(";");
37.96 - if(startindex < parameterdes.length()) {
37.97 - if(endindex == parameterdes.length()-1) {
37.98 - //last parameter
37.99 - param = parameterdes.substring(startindex);
37.100 - parameterdes = null;
37.101 - }else if(endindex+1 < parameterdes.length()){
37.102 - //rest parameters
37.103 - param = parameterdes.substring(startindex, endindex+1);
37.104 - parameterdes = parameterdes.substring(endindex+1);
37.105 -
37.106 - }
37.107 - parameters.add(getObjectType(param));
37.108 - }
37.109 - }else if(parameterdes.startsWith("[")){
37.110 - //parameter is an array.
37.111 - String componentType = "";
37.112 - int enddim = -1;
37.113 - int st = 0;
37.114 - while(true){
37.115 - if(st < parameterdes.length()){
37.116 - if(parameterdes.charAt(st) == '['){
37.117 -
37.118 - enddim = st;
37.119 - st++;
37.120 - }
37.121 - else break;
37.122 - }
37.123 - else break;
37.124 - }
37.125 -
37.126 - if(enddim+1 < parameterdes.length()){
37.127 - /* Array dimension.*/
37.128 - param = parameterdes.substring(0,enddim+1);
37.129 -
37.130 - }
37.131 -
37.132 - int stotherparam = param.lastIndexOf("[")+1;
37.133 -
37.134 - if(stotherparam < parameterdes.length()){
37.135 - componentType = parameterdes.substring(stotherparam);
37.136 - }
37.137 -
37.138 - if(componentType.startsWith("L")){
37.139 - //parameter is array of objects.
37.140 - startindex = parameterdes.indexOf("L");
37.141 - endindex = parameterdes.indexOf(";");
37.142 -
37.143 - if(endindex == parameterdes.length()-1){
37.144 - //last parameter
37.145 - param += parameterdes.substring(startindex);
37.146 - parameterdes = null;
37.147 - }else if(endindex+1 < parameterdes.length()){
37.148 - //rest parameters
37.149 - param += parameterdes.substring(startindex, endindex+1);
37.150 - parameterdes = parameterdes.substring(endindex+1);
37.151 - }
37.152 - }else{
37.153 - //parameter is array of base type.
37.154 - if(componentType.length() == 1){
37.155 - //last parameter.
37.156 - param += componentType;
37.157 - parameterdes = null;
37.158 - }
37.159 - else if (componentType.length() > 1) {
37.160 - //rest parameters.
37.161 - param += componentType.substring(0,1);
37.162 - parameterdes = componentType.substring(1);
37.163 - }
37.164 - }
37.165 - parameters.add(getArrayType(param));
37.166 -
37.167 -
37.168 - }else {
37.169 -
37.170 - //parameter is of base type.
37.171 - if(parameterdes.length() == 1){
37.172 - //last parameter
37.173 - param = parameterdes;
37.174 - parameterdes = null;
37.175 - }
37.176 - else if (parameterdes.length() > 1) {
37.177 - //rest parameters.
37.178 - param = parameterdes.substring(0,1);
37.179 - parameterdes = parameterdes.substring(1);
37.180 - }
37.181 - parameters.add(getBaseType(param));
37.182 - }
37.183 - }
37.184 -
37.185 - /* number of arguments of a method.*/
37.186 - argumentlength = parameters.size();
37.187 -
37.188 - /* java type signature.*/
37.189 - String parametersignature = "(";
37.190 - int i;
37.191 -
37.192 - for(i = 0; i < parameters.size(); i++){
37.193 - parametersignature += (String)parameters.elementAt(i);
37.194 - if(i != parameters.size()-1){
37.195 - parametersignature += ", ";
37.196 - }
37.197 - }
37.198 - parametersignature += ")";
37.199 - return parametersignature;
37.200 - }
37.201 -
37.202 - /**
37.203 - * Returns java type signature for a return type.
37.204 - */
37.205 - public String getReturnTypeHelper(String returndes){
37.206 - return getFieldTypeSignature(returndes);
37.207 - }
37.208 -
37.209 - /**
37.210 - * Returns java type signature for a base type.
37.211 - */
37.212 - public String getBaseType(String baseType){
37.213 - if(baseType != null){
37.214 - if(baseType.equals("B")) return "byte";
37.215 - else if(baseType.equals("C")) return "char";
37.216 - else if(baseType.equals("D")) return "double";
37.217 - else if(baseType.equals("F")) return "float";
37.218 - else if(baseType.equals("I")) return "int";
37.219 - else if(baseType.equals("J")) return "long";
37.220 - else if(baseType.equals("S")) return "short";
37.221 - else if(baseType.equals("Z")) return "boolean";
37.222 - else if(baseType.equals("V")) return "void";
37.223 - }
37.224 - return null;
37.225 - }
37.226 -
37.227 - /**
37.228 - * Returns java type signature for a object type.
37.229 - */
37.230 - public String getObjectType(String JVMobjectType) {
37.231 - String objectType = "";
37.232 - int startindex = JVMobjectType.indexOf("L")+1;
37.233 - int endindex = JVMobjectType.indexOf(";");
37.234 - if((startindex != -1) && (endindex != -1)){
37.235 - if((startindex < JVMobjectType.length()) && (endindex < JVMobjectType.length())){
37.236 - objectType = JVMobjectType.substring(startindex, endindex);
37.237 - }
37.238 - objectType = objectType.replace('/','.');
37.239 - return objectType;
37.240 - }
37.241 - return null;
37.242 - }
37.243 -
37.244 - /**
37.245 - * Returns java type signature for array type.
37.246 - */
37.247 - public String getArrayType(String arrayType) {
37.248 - if(arrayType != null){
37.249 - String dimention = "";
37.250 -
37.251 - while(arrayType.indexOf("[") != -1){
37.252 - dimention += "[]";
37.253 -
37.254 - int startindex = arrayType.indexOf("[")+1;
37.255 - if(startindex <= arrayType.length()){
37.256 - arrayType = arrayType.substring(startindex);
37.257 - }
37.258 - }
37.259 -
37.260 - String componentType = "";
37.261 - if(arrayType.startsWith("L")){
37.262 - componentType = getObjectType(arrayType);
37.263 - }else {
37.264 - componentType = getBaseType(arrayType);
37.265 - }
37.266 - return componentType+dimention;
37.267 - }
37.268 - return null;
37.269 - }
37.270 -
37.271 - /**
37.272 - * Returns java type signature for parameters.
37.273 - */
37.274 - public String getParameters(){
37.275 - return parameters;
37.276 - }
37.277 -
37.278 - /**
37.279 - * Returns java type signature for return type.
37.280 - */
37.281 - public String getReturnType(){
37.282 - return returntype;
37.283 - }
37.284 -
37.285 - /**
37.286 - * Returns java type signature for field type.
37.287 - */
37.288 - public String getFieldType(){
37.289 - return fieldtype;
37.290 - }
37.291 -
37.292 - /**
37.293 - * Return number of arguments of a method.
37.294 - */
37.295 - public int getArgumentlength(){
37.296 - return argumentlength;
37.297 - }
37.298 -}
38.1 --- a/javap/src/main/java/sun/tools/javap/Vector.java Fri Nov 16 08:06:48 2012 +0100
38.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
38.3 @@ -1,57 +0,0 @@
38.4 -/*
38.5 - * To change this template, choose Tools | Templates
38.6 - * and open the template in the editor.
38.7 - */
38.8 -package sun.tools.javap;
38.9 -
38.10 -/** A JavaScript ready replacement for java.util.Vector
38.11 - *
38.12 - * @author Jaroslav Tulach <jtulach@netbeans.org>
38.13 - */
38.14 -final class Vector {
38.15 - private Object[] arr;
38.16 -
38.17 - Vector() {
38.18 - }
38.19 -
38.20 - Vector(int i) {
38.21 - this();
38.22 - }
38.23 -
38.24 - void add(Object objectType) {
38.25 - addElement(objectType);
38.26 - }
38.27 - void addElement(Object obj) {
38.28 - final int s = size();
38.29 - setSize(s + 1);
38.30 - setElementAt(obj, s);
38.31 - }
38.32 -
38.33 - int size() {
38.34 - return arr == null ? 0 : arr.length;
38.35 - }
38.36 -
38.37 - void copyInto(Object[] newArr) {
38.38 - if (arr == null) {
38.39 - return;
38.40 - }
38.41 - int min = Math.min(newArr.length, arr.length);
38.42 - for (int i = 0; i < min; i++) {
38.43 - newArr[i] = arr[i];
38.44 - }
38.45 - }
38.46 -
38.47 - Object elementAt(int index) {
38.48 - return arr[index];
38.49 - }
38.50 -
38.51 - void setSize(int len) {
38.52 - Object[] newArr = new Object[len];
38.53 - copyInto(newArr);
38.54 - arr = newArr;
38.55 - }
38.56 -
38.57 - void setElementAt(Object val, int index) {
38.58 - arr[index] = val;
38.59 - }
38.60 -}
39.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Nov 16 08:06:48 2012 +0100
39.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Nov 16 08:08:36 2012 +0100
39.3 @@ -21,11 +21,11 @@
39.4 import java.io.InputStream;
39.5 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
39.6 import org.apidesign.bck2brwsr.core.JavaScriptBody;
39.7 -import sun.tools.javap.AnnotationParser;
39.8 -import sun.tools.javap.ClassData;
39.9 -import sun.tools.javap.FieldData;
39.10 -import sun.tools.javap.MethodData;
39.11 -import static sun.tools.javap.RuntimeConstants.*;
39.12 +import org.apidesign.javap.AnnotationParser;
39.13 +import org.apidesign.javap.ClassData;
39.14 +import org.apidesign.javap.FieldData;
39.15 +import org.apidesign.javap.MethodData;
39.16 +import static org.apidesign.javap.RuntimeConstants.*;
39.17
39.18 /** Translator of the code inside class files to JavaScript.
39.19 *