1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/javap/pom.xml Fri Nov 09 21:33:22 2012 +0100
1.3 @@ -0,0 +1,41 @@
1.4 +<?xml version="1.0"?>
1.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
1.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1.7 + <modelVersion>4.0.0</modelVersion>
1.8 + <parent>
1.9 + <groupId>org.apidesign</groupId>
1.10 + <artifactId>bck2brwsr</artifactId>
1.11 + <version>1.0-SNAPSHOT</version>
1.12 + </parent>
1.13 + <groupId>org.apidesign.bck2brwsr</groupId>
1.14 + <artifactId>javap</artifactId>
1.15 + <version>1.0-SNAPSHOT</version>
1.16 + <name>javap</name>
1.17 + <url>http://maven.apache.org</url>
1.18 + <properties>
1.19 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1.20 + </properties>
1.21 + <build>
1.22 + <plugins>
1.23 + <plugin>
1.24 + <groupId>org.apache.maven.plugins</groupId>
1.25 + <artifactId>maven-compiler-plugin</artifactId>
1.26 + <version>2.5.1</version>
1.27 + <configuration>
1.28 + <compilerArguments>
1.29 + <bootclasspath>non-existing</bootclasspath>
1.30 + </compilerArguments>
1.31 + <source>1.7</source>
1.32 + <target>1.7</target>
1.33 + </configuration>
1.34 + </plugin>
1.35 + </plugins>
1.36 + </build>
1.37 + <dependencies>
1.38 + <dependency>
1.39 + <groupId>org.apidesign.bck2brwsr</groupId>
1.40 + <artifactId>emul</artifactId>
1.41 + <version>1.0-SNAPSHOT</version>
1.42 + </dependency>
1.43 + </dependencies>
1.44 +</project>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/javap/src/main/java/sun/tools/javap/AttrData.java Fri Nov 09 21:33:22 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 sun.tools.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/sun/tools/javap/CPX.java Fri Nov 09 21:33:22 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 sun.tools.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/sun/tools/javap/CPX2.java Fri Nov 09 21:33:22 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 sun.tools.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/sun/tools/javap/ClassData.java Fri Nov 09 21:33:22 2012 +0100
5.3 @@ -0,0 +1,663 @@
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 sun.tools.javap;
5.31 +
5.32 +import java.util.*;
5.33 +import java.io.*;
5.34 +
5.35 +/**
5.36 + * Central data repository of the Java Disassembler.
5.37 + * Stores all the information in java class file.
5.38 + *
5.39 + * @author Sucheta Dambalkar (Adopted code from jdis)
5.40 + */
5.41 +public class ClassData implements RuntimeConstants {
5.42 +
5.43 + private int magic;
5.44 + private int minor_version;
5.45 + private int major_version;
5.46 + private int cpool_count;
5.47 + private Object cpool[];
5.48 + private int access;
5.49 + private int this_class = 0;;
5.50 + private int super_class;
5.51 + private int interfaces_count;
5.52 + private int[] interfaces = new int[0];;
5.53 + private int fields_count;
5.54 + private FieldData[] fields;
5.55 + private int methods_count;
5.56 + private MethodData[] methods;
5.57 + private InnerClassData[] innerClasses;
5.58 + private int attributes_count;
5.59 + private AttrData[] attrs;
5.60 + private String classname;
5.61 + private String superclassname;
5.62 + private int source_cpx=0;
5.63 + private byte tags[];
5.64 + private Hashtable indexHashAscii = new Hashtable();
5.65 + private String pkgPrefix="";
5.66 + private int pkgPrefixLen=0;
5.67 +
5.68 + /**
5.69 + * Read classfile to disassemble.
5.70 + */
5.71 + public ClassData(InputStream infile){
5.72 + try{
5.73 + this.read(new DataInputStream(infile));
5.74 + }catch (FileNotFoundException ee) {
5.75 + error("cant read file");
5.76 + }catch (Error ee) {
5.77 + ee.printStackTrace();
5.78 + error("fatal error");
5.79 + } catch (Exception ee) {
5.80 + ee.printStackTrace();
5.81 + error("fatal exception");
5.82 + }
5.83 + }
5.84 +
5.85 + /**
5.86 + * Reads and stores class file information.
5.87 + */
5.88 + public void read(DataInputStream in) throws IOException {
5.89 + // Read the header
5.90 + magic = in.readInt();
5.91 + if (magic != JAVA_MAGIC) {
5.92 + throw new ClassFormatError("wrong magic: " +
5.93 + toHex(magic) + ", expected " +
5.94 + toHex(JAVA_MAGIC));
5.95 + }
5.96 + minor_version = in.readShort();
5.97 + major_version = in.readShort();
5.98 + if (major_version != JAVA_VERSION) {
5.99 + }
5.100 +
5.101 + // Read the constant pool
5.102 + readCP(in);
5.103 + access = in.readUnsignedShort();
5.104 + this_class = in.readUnsignedShort();
5.105 + super_class = in.readUnsignedShort();
5.106 +
5.107 + //Read interfaces.
5.108 + interfaces_count = in.readUnsignedShort();
5.109 + if(interfaces_count > 0){
5.110 + interfaces = new int[interfaces_count];
5.111 + }
5.112 + for (int i = 0; i < interfaces_count; i++) {
5.113 + interfaces[i]=in.readShort();
5.114 + }
5.115 +
5.116 + // Read the fields
5.117 + readFields(in);
5.118 +
5.119 + // Read the methods
5.120 + readMethods(in);
5.121 +
5.122 + // Read the attributes
5.123 + attributes_count = in.readUnsignedShort();
5.124 + attrs=new AttrData[attributes_count];
5.125 + for (int k = 0; k < attributes_count; k++) {
5.126 + int name_cpx=in.readUnsignedShort();
5.127 + if (getTag(name_cpx)==CONSTANT_UTF8
5.128 + && getString(name_cpx).equals("SourceFile")
5.129 + ){ if (in.readInt()!=2)
5.130 + throw new ClassFormatError("invalid attr length");
5.131 + source_cpx=in.readUnsignedShort();
5.132 + AttrData attr=new AttrData(this);
5.133 + attr.read(name_cpx);
5.134 + attrs[k]=attr;
5.135 +
5.136 + } else if (getTag(name_cpx)==CONSTANT_UTF8
5.137 + && getString(name_cpx).equals("InnerClasses")
5.138 + ){ int length=in.readInt();
5.139 + int num=in.readUnsignedShort();
5.140 + if (2+num*8 != length)
5.141 + throw new ClassFormatError("invalid attr length");
5.142 + innerClasses=new InnerClassData[num];
5.143 + for (int j = 0; j < num; j++) {
5.144 + InnerClassData innerClass=new InnerClassData(this);
5.145 + innerClass.read(in);
5.146 + innerClasses[j]=innerClass;
5.147 + }
5.148 + AttrData attr=new AttrData(this);
5.149 + attr.read(name_cpx);
5.150 + attrs[k]=attr;
5.151 + } else {
5.152 + AttrData attr=new AttrData(this);
5.153 + attr.read(name_cpx, in);
5.154 + attrs[k]=attr;
5.155 + }
5.156 + }
5.157 + in.close();
5.158 + } // end ClassData.read()
5.159 +
5.160 + /**
5.161 + * Reads and stores constant pool info.
5.162 + */
5.163 + void readCP(DataInputStream in) throws IOException {
5.164 + cpool_count = in.readUnsignedShort();
5.165 + tags = new byte[cpool_count];
5.166 + cpool = new Object[cpool_count];
5.167 + for (int i = 1; i < cpool_count; i++) {
5.168 + byte tag = in.readByte();
5.169 +
5.170 + switch(tags[i] = tag) {
5.171 + case CONSTANT_UTF8:
5.172 + String str=in.readUTF();
5.173 + indexHashAscii.put(cpool[i] = str, new Integer(i));
5.174 + break;
5.175 + case CONSTANT_INTEGER:
5.176 + cpool[i] = new Integer(in.readInt());
5.177 + break;
5.178 + case CONSTANT_FLOAT:
5.179 + cpool[i] = new Float(in.readFloat());
5.180 + break;
5.181 + case CONSTANT_LONG:
5.182 + cpool[i++] = new Long(in.readLong());
5.183 + break;
5.184 + case CONSTANT_DOUBLE:
5.185 + cpool[i++] = new Double(in.readDouble());
5.186 + break;
5.187 + case CONSTANT_CLASS:
5.188 + case CONSTANT_STRING:
5.189 + cpool[i] = new CPX(in.readUnsignedShort());
5.190 + break;
5.191 +
5.192 + case CONSTANT_FIELD:
5.193 + case CONSTANT_METHOD:
5.194 + case CONSTANT_INTERFACEMETHOD:
5.195 + case CONSTANT_NAMEANDTYPE:
5.196 + cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
5.197 + break;
5.198 +
5.199 + case 0:
5.200 + default:
5.201 + throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
5.202 + }
5.203 + }
5.204 + }
5.205 +
5.206 + /**
5.207 + * Reads and strores field info.
5.208 + */
5.209 + protected void readFields(DataInputStream in) throws IOException {
5.210 + int fields_count = in.readUnsignedShort();
5.211 + fields=new FieldData[fields_count];
5.212 + for (int k = 0; k < fields_count; k++) {
5.213 + FieldData field=new FieldData(this);
5.214 + field.read(in);
5.215 + fields[k]=field;
5.216 + }
5.217 + }
5.218 +
5.219 + /**
5.220 + * Reads and strores Method info.
5.221 + */
5.222 + protected void readMethods(DataInputStream in) throws IOException {
5.223 + int methods_count = in.readUnsignedShort();
5.224 + methods=new MethodData[methods_count];
5.225 + for (int k = 0; k < methods_count ; k++) {
5.226 + MethodData method=new MethodData(this);
5.227 + method.read(in);
5.228 + methods[k]=method;
5.229 + }
5.230 + }
5.231 +
5.232 + /**
5.233 + * get a string
5.234 + */
5.235 + public String getString(int n) {
5.236 + return (n == 0) ? null : (String)cpool[n];
5.237 + }
5.238 +
5.239 + /**
5.240 + * get the type of constant given an index
5.241 + */
5.242 + public byte getTag(int n) {
5.243 + try{
5.244 + return tags[n];
5.245 + } catch (ArrayIndexOutOfBoundsException e) {
5.246 + return (byte)100;
5.247 + }
5.248 + }
5.249 +
5.250 + static final String hexString="0123456789ABCDEF";
5.251 +
5.252 + public static char hexTable[]=hexString.toCharArray();
5.253 +
5.254 + static String toHex(long val, int width) {
5.255 + StringBuffer s = new StringBuffer();
5.256 + for (int i=width-1; i>=0; i--)
5.257 + s.append(hexTable[((int)(val>>(4*i)))&0xF]);
5.258 + return "0x"+s.toString();
5.259 + }
5.260 +
5.261 + static String toHex(long val) {
5.262 + int width;
5.263 + for (width=16; width>0; width--) {
5.264 + if ((val>>(width-1)*4)!=0) break;
5.265 + }
5.266 + return toHex(val, width);
5.267 + }
5.268 +
5.269 + static String toHex(int val) {
5.270 + int width;
5.271 + for (width=8; width>0; width--) {
5.272 + if ((val>>(width-1)*4)!=0) break;
5.273 + }
5.274 + return toHex(val, width);
5.275 + }
5.276 +
5.277 + public void error(String msg) {
5.278 + System.err.println("ERROR:" +msg);
5.279 + }
5.280 +
5.281 + /**
5.282 + * Returns the name of this class.
5.283 + */
5.284 + public String getClassName() {
5.285 + String res=null;
5.286 + if (this_class==0) {
5.287 + return res;
5.288 + }
5.289 + int tcpx;
5.290 + try {
5.291 + if (tags[this_class]!=CONSTANT_CLASS) {
5.292 + return res; //"<CP["+cpx+"] is not a Class> ";
5.293 + }
5.294 + tcpx=((CPX)cpool[this_class]).cpx;
5.295 + } catch (ArrayIndexOutOfBoundsException e) {
5.296 + return res; // "#"+cpx+"// invalid constant pool index";
5.297 + } catch (Throwable e) {
5.298 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.299 + }
5.300 +
5.301 + try {
5.302 + return (String)(cpool[tcpx]);
5.303 + } catch (ArrayIndexOutOfBoundsException e) {
5.304 + return res; // "class #"+scpx+"// invalid constant pool index";
5.305 + } catch (ClassCastException e) {
5.306 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.307 + } catch (Throwable e) {
5.308 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.309 + }
5.310 +
5.311 + }
5.312 +
5.313 + /**
5.314 + * Returns the name of class at perticular index.
5.315 + */
5.316 + public String getClassName(int cpx) {
5.317 + String res="#"+cpx;
5.318 + if (cpx==0) {
5.319 + return res;
5.320 + }
5.321 + int scpx;
5.322 + try {
5.323 + if (tags[cpx]!=CONSTANT_CLASS) {
5.324 + return res; //"<CP["+cpx+"] is not a Class> ";
5.325 + }
5.326 + scpx=((CPX)cpool[cpx]).cpx;
5.327 + } catch (ArrayIndexOutOfBoundsException e) {
5.328 + return res; // "#"+cpx+"// invalid constant pool index";
5.329 + } catch (Throwable e) {
5.330 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.331 + }
5.332 + res="#"+scpx;
5.333 + try {
5.334 + return (String)(cpool[scpx]);
5.335 + } catch (ArrayIndexOutOfBoundsException e) {
5.336 + return res; // "class #"+scpx+"// invalid constant pool index";
5.337 + } catch (ClassCastException e) {
5.338 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.339 + } catch (Throwable e) {
5.340 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.341 + }
5.342 + }
5.343 +
5.344 + /**
5.345 + * Returns true if it is a class
5.346 + */
5.347 + public boolean isClass() {
5.348 + if((access & ACC_INTERFACE) == 0) return true;
5.349 + return false;
5.350 + }
5.351 +
5.352 + /**
5.353 + * Returns true if it is a interface.
5.354 + */
5.355 + public boolean isInterface(){
5.356 + if((access & ACC_INTERFACE) != 0) return true;
5.357 + return false;
5.358 + }
5.359 +
5.360 + /**
5.361 + * Returns true if this member is public, false otherwise.
5.362 + */
5.363 + public boolean isPublic(){
5.364 + return (access & ACC_PUBLIC) != 0;
5.365 + }
5.366 +
5.367 + /**
5.368 + * Returns the access of this class or interface.
5.369 + */
5.370 + public String[] getAccess(){
5.371 + Vector v = new Vector();
5.372 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
5.373 + if ((access & ACC_FINAL) !=0) v.addElement("final");
5.374 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
5.375 + String[] accflags = new String[v.size()];
5.376 + v.copyInto(accflags);
5.377 + return accflags;
5.378 + }
5.379 +
5.380 + /**
5.381 + * Returns list of innerclasses.
5.382 + */
5.383 + public InnerClassData[] getInnerClasses(){
5.384 + return innerClasses;
5.385 + }
5.386 +
5.387 + /**
5.388 + * Returns list of attributes.
5.389 + */
5.390 + public AttrData[] getAttributes(){
5.391 + return attrs;
5.392 + }
5.393 +
5.394 + /**
5.395 + * Returns true if superbit is set.
5.396 + */
5.397 + public boolean isSuperSet(){
5.398 + if ((access & ACC_SUPER) !=0) return true;
5.399 + return false;
5.400 + }
5.401 +
5.402 + /**
5.403 + * Returns super class name.
5.404 + */
5.405 + public String getSuperClassName(){
5.406 + String res=null;
5.407 + if (super_class==0) {
5.408 + return res;
5.409 + }
5.410 + int scpx;
5.411 + try {
5.412 + if (tags[super_class]!=CONSTANT_CLASS) {
5.413 + return res; //"<CP["+cpx+"] is not a Class> ";
5.414 + }
5.415 + scpx=((CPX)cpool[super_class]).cpx;
5.416 + } catch (ArrayIndexOutOfBoundsException e) {
5.417 + return res; // "#"+cpx+"// invalid constant pool index";
5.418 + } catch (Throwable e) {
5.419 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.420 + }
5.421 +
5.422 + try {
5.423 + return (String)(cpool[scpx]);
5.424 + } catch (ArrayIndexOutOfBoundsException e) {
5.425 + return res; // "class #"+scpx+"// invalid constant pool index";
5.426 + } catch (ClassCastException e) {
5.427 + return res; // "class #"+scpx+"// invalid constant pool reference";
5.428 + } catch (Throwable e) {
5.429 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
5.430 + }
5.431 + }
5.432 +
5.433 + /**
5.434 + * Returns list of super interfaces.
5.435 + */
5.436 + public String[] getSuperInterfaces(){
5.437 + String interfacenames[] = new String[interfaces.length];
5.438 + int interfacecpx = -1;
5.439 + for(int i = 0; i < interfaces.length; i++){
5.440 + interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
5.441 + interfacenames[i] = (String)(cpool[interfacecpx]);
5.442 + }
5.443 + return interfacenames;
5.444 + }
5.445 +
5.446 + /**
5.447 + * Returns string at prticular constant pool index.
5.448 + */
5.449 + public String getStringValue(int cpoolx) {
5.450 + try {
5.451 + return ((String)cpool[cpoolx]);
5.452 + } catch (ArrayIndexOutOfBoundsException e) {
5.453 + return "//invalid constant pool index:"+cpoolx;
5.454 + } catch (ClassCastException e) {
5.455 + return "//invalid constant pool ref:"+cpoolx;
5.456 + }
5.457 + }
5.458 +
5.459 + /**
5.460 + * Returns list of field info.
5.461 + */
5.462 + public FieldData[] getFields(){
5.463 + return fields;
5.464 + }
5.465 +
5.466 + /**
5.467 + * Returns list of method info.
5.468 + */
5.469 + public MethodData[] getMethods(){
5.470 + return methods;
5.471 + }
5.472 +
5.473 + /**
5.474 + * Returns constant pool entry at that index.
5.475 + */
5.476 + public CPX2 getCpoolEntry(int cpx){
5.477 + return ((CPX2)(cpool[cpx]));
5.478 + }
5.479 +
5.480 + public Object getCpoolEntryobj(int cpx){
5.481 + return (cpool[cpx]);
5.482 + }
5.483 +
5.484 + /**
5.485 + * Returns index of this class.
5.486 + */
5.487 + public int getthis_cpx(){
5.488 + return this_class;
5.489 + }
5.490 +
5.491 + public String TagString (int tag) {
5.492 + String res=Tables.tagName(tag);
5.493 + if (res==null) return "BOGUS_TAG:"+tag;
5.494 + return res;
5.495 + }
5.496 +
5.497 + /**
5.498 + * Returns string at that index.
5.499 + */
5.500 + public String StringValue(int cpx) {
5.501 + if (cpx==0) return "#0";
5.502 + int tag;
5.503 + Object x;
5.504 + String suffix="";
5.505 + try {
5.506 + tag=tags[cpx];
5.507 + x=cpool[cpx];
5.508 + } catch (IndexOutOfBoundsException e) {
5.509 + return "<Incorrect CP index:"+cpx+">";
5.510 + }
5.511 +
5.512 + if (x==null) return "<NULL>";
5.513 + switch (tag) {
5.514 + case CONSTANT_UTF8: {
5.515 + StringBuffer sb=new StringBuffer();
5.516 + String s=(String)x;
5.517 + for (int k=0; k<s.length(); k++) {
5.518 + char c=s.charAt(k);
5.519 + switch (c) {
5.520 + case '\t': sb.append('\\').append('t'); break;
5.521 + case '\n': sb.append('\\').append('n'); break;
5.522 + case '\r': sb.append('\\').append('r'); break;
5.523 + case '\"': sb.append('\\').append('\"'); break;
5.524 + default: sb.append(c);
5.525 + }
5.526 + }
5.527 + return sb.toString();
5.528 + }
5.529 + case CONSTANT_DOUBLE: {
5.530 + Double d=(Double)x;
5.531 + String sd=d.toString();
5.532 + return sd+"d";
5.533 + }
5.534 + case CONSTANT_FLOAT: {
5.535 + Float f=(Float)x;
5.536 + String sf=(f).toString();
5.537 + return sf+"f";
5.538 + }
5.539 + case CONSTANT_LONG: {
5.540 + Long ln = (Long)x;
5.541 + return ln.toString()+'l';
5.542 + }
5.543 + case CONSTANT_INTEGER: {
5.544 + Integer in = (Integer)x;
5.545 + return in.toString();
5.546 + }
5.547 + case CONSTANT_CLASS:
5.548 + return javaName(getClassName(cpx));
5.549 + case CONSTANT_STRING:
5.550 + return StringValue(((CPX)x).cpx);
5.551 + case CONSTANT_FIELD:
5.552 + case CONSTANT_METHOD:
5.553 + case CONSTANT_INTERFACEMETHOD:
5.554 + //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
5.555 + return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
5.556 +
5.557 + case CONSTANT_NAMEANDTYPE:
5.558 + return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
5.559 + default:
5.560 + return "UnknownTag"; //TBD
5.561 + }
5.562 + }
5.563 +
5.564 + /**
5.565 + * Returns resolved java type name.
5.566 + */
5.567 + public String javaName(String name) {
5.568 + if( name==null) return "null";
5.569 + int len=name.length();
5.570 + if (len==0) return "\"\"";
5.571 + int cc='/';
5.572 + fullname: { // xxx/yyy/zzz
5.573 + int cp;
5.574 + for (int k=0; k<len; k += Character.charCount(cp)) {
5.575 + cp=name.codePointAt(k);
5.576 + if (cc=='/') {
5.577 + if (!Character.isJavaIdentifierStart(cp)) break fullname;
5.578 + } else if (cp!='/') {
5.579 + if (!Character.isJavaIdentifierPart(cp)) break fullname;
5.580 + }
5.581 + cc=cp;
5.582 + }
5.583 + return name;
5.584 + }
5.585 + return "\""+name+"\"";
5.586 + }
5.587 +
5.588 + public String getName(int cpx) {
5.589 + String res;
5.590 + try {
5.591 + return javaName((String)cpool[cpx]); //.replace('/','.');
5.592 + } catch (ArrayIndexOutOfBoundsException e) {
5.593 + return "<invalid constant pool index:"+cpx+">";
5.594 + } catch (ClassCastException e) {
5.595 + return "<invalid constant pool ref:"+cpx+">";
5.596 + }
5.597 + }
5.598 +
5.599 + /**
5.600 + * Returns unqualified class name.
5.601 + */
5.602 + public String getShortClassName(int cpx) {
5.603 + String classname=javaName(getClassName(cpx));
5.604 + pkgPrefixLen=classname.lastIndexOf("/")+1;
5.605 + if (pkgPrefixLen!=0) {
5.606 + pkgPrefix=classname.substring(0,pkgPrefixLen);
5.607 + if (classname.startsWith(pkgPrefix)) {
5.608 + return classname.substring(pkgPrefixLen);
5.609 + }
5.610 + }
5.611 + return classname;
5.612 + }
5.613 +
5.614 + /**
5.615 + * Returns source file name.
5.616 + */
5.617 + public String getSourceName(){
5.618 + return getName(source_cpx);
5.619 + }
5.620 +
5.621 + /**
5.622 + * Returns package name.
5.623 + */
5.624 + public String getPkgName(){
5.625 + String classname=getClassName(this_class);
5.626 + pkgPrefixLen=classname.lastIndexOf("/")+1;
5.627 + if (pkgPrefixLen!=0) {
5.628 + pkgPrefix=classname.substring(0,pkgPrefixLen);
5.629 + return("package "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
5.630 + }else return null;
5.631 + }
5.632 +
5.633 + /**
5.634 + * Returns total constant pool entry count.
5.635 + */
5.636 + public int getCpoolCount(){
5.637 + return cpool_count;
5.638 + }
5.639 +
5.640 + public String StringTag(int cpx) {
5.641 + byte tag=0;
5.642 + String str=null;
5.643 + try {
5.644 + if (cpx==0) throw new IndexOutOfBoundsException();
5.645 + tag=tags[cpx];
5.646 + return TagString(tag);
5.647 + } catch (IndexOutOfBoundsException e) {
5.648 + str="Incorrect CP index:"+cpx;
5.649 + }
5.650 + return str;
5.651 + }
5.652 +
5.653 + /**
5.654 + * Returns minor version of class file.
5.655 + */
5.656 + public int getMinor_version(){
5.657 + return minor_version;
5.658 + }
5.659 +
5.660 + /**
5.661 + * Returns major version of class file.
5.662 + */
5.663 + public int getMajor_version(){
5.664 + return major_version;
5.665 + }
5.666 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/javap/src/main/java/sun/tools/javap/Constants.java Fri Nov 09 21:33:22 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 sun.tools.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/sun/tools/javap/FieldData.java Fri Nov 09 21:33:22 2012 +0100
7.3 @@ -0,0 +1,163 @@
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 sun.tools.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 + /**
7.102 + * Returns access of a field.
7.103 + */
7.104 + public String[] getAccess(){
7.105 + Vector v = new Vector();
7.106 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
7.107 + if ((access & ACC_PRIVATE) !=0) v.addElement("private");
7.108 + if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
7.109 + if ((access & ACC_STATIC) !=0) v.addElement("static");
7.110 + if ((access & ACC_FINAL) !=0) v.addElement("final");
7.111 + if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
7.112 + if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
7.113 + String[] accflags = new String[v.size()];
7.114 + v.copyInto(accflags);
7.115 + return accflags;
7.116 + }
7.117 +
7.118 + /**
7.119 + * Returns name of a field.
7.120 + */
7.121 + public String getName(){
7.122 + return cls.getStringValue(name_index);
7.123 + }
7.124 +
7.125 + /**
7.126 + * Returns internal signature of a field
7.127 + */
7.128 + public String getInternalSig(){
7.129 + return cls.getStringValue(descriptor_index);
7.130 + }
7.131 +
7.132 + /**
7.133 + * Returns java type signature of a field.
7.134 + */
7.135 + public String getType(){
7.136 + return new TypeSignature(getInternalSig()).getFieldType();
7.137 + }
7.138 +
7.139 + /**
7.140 + * Returns true if field is synthetic.
7.141 + */
7.142 + public boolean isSynthetic(){
7.143 + return isSynthetic;
7.144 + }
7.145 +
7.146 + /**
7.147 + * Returns true if field is deprecated.
7.148 + */
7.149 + public boolean isDeprecated(){
7.150 + return isDeprecated;
7.151 + }
7.152 +
7.153 + /**
7.154 + * Returns index of constant value in cpool.
7.155 + */
7.156 + public int getConstantValueIndex(){
7.157 + return (value_cpx);
7.158 + }
7.159 +
7.160 + /**
7.161 + * Returns list of attributes of field.
7.162 + */
7.163 + public Vector getAttributes(){
7.164 + return attrs;
7.165 + }
7.166 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/javap/src/main/java/sun/tools/javap/InnerClassData.java Fri Nov 09 21:33:22 2012 +0100
8.3 @@ -0,0 +1,75 @@
8.4 +/*
8.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Oracle designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Oracle in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8.25 + * or visit www.oracle.com if you need additional information or have any
8.26 + * questions.
8.27 + */
8.28 +
8.29 +
8.30 +package sun.tools.javap;
8.31 +
8.32 +import java.io.*;
8.33 +import java.util.*;
8.34 +
8.35 +/**
8.36 + * Strores InnerClass data informastion.
8.37 + *
8.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
8.39 + */
8.40 +class InnerClassData implements RuntimeConstants {
8.41 + ClassData cls;
8.42 +
8.43 +
8.44 + int inner_class_info_index
8.45 + ,outer_class_info_index
8.46 + ,inner_name_index
8.47 + ,access
8.48 + ;
8.49 +
8.50 + public InnerClassData(ClassData cls) {
8.51 + this.cls=cls;
8.52 +
8.53 + }
8.54 +
8.55 + /**
8.56 + * Read Innerclass attribute data.
8.57 + */
8.58 + public void read(DataInputStream in) throws IOException {
8.59 + inner_class_info_index = in.readUnsignedShort();
8.60 + outer_class_info_index = in.readUnsignedShort();
8.61 + inner_name_index = in.readUnsignedShort();
8.62 + access = in.readUnsignedShort();
8.63 + } // end read
8.64 +
8.65 + /**
8.66 + * Returns the access of this class or interface.
8.67 + */
8.68 + public String[] getAccess(){
8.69 + Vector v = new Vector();
8.70 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
8.71 + if ((access & ACC_FINAL) !=0) v.addElement("final");
8.72 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
8.73 + String[] accflags = new String[v.size()];
8.74 + v.copyInto(accflags);
8.75 + return accflags;
8.76 + }
8.77 +
8.78 +} // end InnerClassData
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/javap/src/main/java/sun/tools/javap/JavapEnvironment.java Fri Nov 09 21:33:22 2012 +0100
9.3 @@ -0,0 +1,355 @@
9.4 +/*
9.5 + * Copyright (c) 2002, 2006, 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 sun.tools.javap;
9.31 +
9.32 +import java.util.*;
9.33 +import java.io.*;
9.34 +import java.util.jar.*;
9.35 +
9.36 +
9.37 +/**
9.38 + * Strores flag values according to command line options
9.39 + * and sets path where to find classes.
9.40 + *
9.41 + * @author Sucheta Dambalkar
9.42 + */
9.43 +public class JavapEnvironment {
9.44 +
9.45 + //Access flags
9.46 + public static final int PRIVATE = 0;
9.47 + public static final int PROTECTED = 1;
9.48 + public static final int PACKAGE = 2;
9.49 + public static final int PUBLIC = 3;
9.50 +
9.51 + //search path flags.
9.52 + private static final int start = 0;
9.53 + private static final int cmdboot= 1;
9.54 + private static final int sunboot = 2;
9.55 + private static final int javaclass= 3;
9.56 + private static final int cmdextdir= 4;
9.57 + private static final int javaext= 5;
9.58 + private static final int cmdclasspath= 6;
9.59 + private static final int envclasspath= 7;
9.60 + private static final int javaclasspath= 8;
9.61 + private static final int currentdir = 9;
9.62 +
9.63 +
9.64 + // JavapEnvironment flag settings
9.65 + boolean showLineAndLocal = false;
9.66 + int showAccess = PACKAGE;
9.67 + boolean showDisassembled = false;
9.68 + boolean showVerbose = false;
9.69 + boolean showInternalSigs = false;
9.70 + String classPathString = null;
9.71 + String bootClassPathString = null;
9.72 + String extDirsString = null;
9.73 + boolean extDirflag = false;
9.74 + boolean nothingToDo = true;
9.75 + boolean showallAttr = false;
9.76 + String classpath = null;
9.77 + int searchpath = start;
9.78 +
9.79 + /**
9.80 + * According to which flags are set,
9.81 + * returns file input stream for classfile to disassemble.
9.82 + */
9.83 +
9.84 + public InputStream getFileInputStream(String Name){
9.85 + InputStream fileInStream = null;
9.86 + searchpath = cmdboot;
9.87 + try{
9.88 + if(searchpath == cmdboot){
9.89 + if(bootClassPathString != null){
9.90 + //search in specified bootclasspath.
9.91 + classpath = bootClassPathString;
9.92 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.93 + //no classes found in search path.
9.94 + else searchpath = cmdextdir;
9.95 + }
9.96 + else searchpath = sunboot;
9.97 + }
9.98 +
9.99 + if(searchpath == sunboot){
9.100 + if(System.getProperty("sun.boot.class.path") != null){
9.101 + //search in sun.boot.class.path
9.102 + classpath = System.getProperty("sun.boot.class.path");
9.103 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.104 + //no classes found in search path
9.105 + else searchpath = cmdextdir;
9.106 + }
9.107 + else searchpath = javaclass;
9.108 + }
9.109 +
9.110 + if(searchpath == javaclass){
9.111 + if(System.getProperty("java.class.path") != null){
9.112 + //search in java.class.path
9.113 + classpath =System.getProperty("java.class.path");
9.114 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.115 + //no classes found in search path
9.116 + else searchpath = cmdextdir;
9.117 + }
9.118 + else searchpath = cmdextdir;
9.119 + }
9.120 +
9.121 + if(searchpath == cmdextdir){
9.122 + if(extDirsString != null){
9.123 + //search in specified extdir.
9.124 + classpath = extDirsString;
9.125 + extDirflag = true;
9.126 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.127 + //no classes found in search path
9.128 + else {
9.129 + searchpath = cmdclasspath;
9.130 + extDirflag = false;
9.131 + }
9.132 + }
9.133 + else searchpath = javaext;
9.134 + }
9.135 +
9.136 + if(searchpath == javaext){
9.137 + if(System.getProperty("java.ext.dirs") != null){
9.138 + //search in java.ext.dirs
9.139 + classpath = System.getProperty("java.ext.dirs");
9.140 + extDirflag = true;
9.141 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.142 + //no classes found in search path
9.143 + else {
9.144 + searchpath = cmdclasspath;
9.145 + extDirflag = false;
9.146 + }
9.147 + }
9.148 + else searchpath = cmdclasspath;
9.149 + }
9.150 + if(searchpath == cmdclasspath){
9.151 + if(classPathString != null){
9.152 + //search in specified classpath.
9.153 + classpath = classPathString;
9.154 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.155 + //no classes found in search path
9.156 + else searchpath = 8;
9.157 + }
9.158 + else searchpath = envclasspath;
9.159 + }
9.160 +
9.161 + if(searchpath == envclasspath){
9.162 + if(System.getProperty("env.class.path")!= null){
9.163 + //search in env.class.path
9.164 + classpath = System.getProperty("env.class.path");
9.165 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.166 + //no classes found in search path.
9.167 + else searchpath = javaclasspath;
9.168 + }
9.169 + else searchpath = javaclasspath;
9.170 + }
9.171 +
9.172 + if(searchpath == javaclasspath){
9.173 + if(("application.home") == null){
9.174 + //search in java.class.path
9.175 + classpath = System.getProperty("java.class.path");
9.176 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.177 + //no classes found in search path.
9.178 + else searchpath = currentdir;
9.179 + }
9.180 + else searchpath = currentdir;
9.181 + }
9.182 +
9.183 + if(searchpath == currentdir){
9.184 + classpath = ".";
9.185 + //search in current dir.
9.186 + if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
9.187 + else {
9.188 + //no classes found in search path.
9.189 + error("Could not find "+ Name);
9.190 + System.exit(1);
9.191 + }
9.192 + }
9.193 + }catch(SecurityException excsec){
9.194 + excsec.printStackTrace();
9.195 + error("fatal exception");
9.196 + }catch(NullPointerException excnull){
9.197 + excnull.printStackTrace();
9.198 + error("fatal exception");
9.199 + }catch(IllegalArgumentException excill){
9.200 + excill.printStackTrace();
9.201 + error("fatal exception");
9.202 + }
9.203 +
9.204 + return null;
9.205 + }
9.206 +
9.207 +
9.208 + public void error(String msg) {
9.209 + System.err.println("ERROR:" +msg);
9.210 + }
9.211 +
9.212 + /**
9.213 + * Resolves file name for classfile to disassemble.
9.214 + */
9.215 + public InputStream resolvefilename(String name){
9.216 + String classname = name.replace('.', '/') + ".class";
9.217 + while (true) {
9.218 + InputStream instream = extDirflag
9.219 + ? resolveExdirFilename(classname)
9.220 + : resolveclasspath(classname);
9.221 + if (instream != null)
9.222 + return instream;
9.223 + int lastindex = classname.lastIndexOf('/');
9.224 + if (lastindex == -1) return null;
9.225 + classname = classname.substring(0, lastindex) + "$" +
9.226 + classname.substring(lastindex + 1);
9.227 + }
9.228 + }
9.229 +
9.230 + /**
9.231 + * Resolves file name for classfile to disassemble if flag exdir is set.
9.232 + */
9.233 + public InputStream resolveExdirFilename(String classname){
9.234 + if(classpath.indexOf(File.pathSeparator) != -1){
9.235 + //separates path
9.236 + StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator);
9.237 + while(st.hasMoreTokens()){
9.238 + String path = st.nextToken();
9.239 + InputStream in = resolveExdirFilenamehelper(path, classname);
9.240 + if (in != null)
9.241 + return in;
9.242 + }
9.243 + }else return (resolveExdirFilenamehelper(classpath, classname));
9.244 +
9.245 + return null;
9.246 + }
9.247 +
9.248 + /**
9.249 + * Resolves file name for classfile to disassemble.
9.250 + */
9.251 + public InputStream resolveclasspath(String classname){
9.252 + if(classpath.indexOf(File.pathSeparator) != -1){
9.253 + StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator);
9.254 + //separates path.
9.255 + while(st.hasMoreTokens()){
9.256 + String path = (st.nextToken()).trim();
9.257 + InputStream in = resolveclasspathhelper(path, classname);
9.258 + if(in != null) return in;
9.259 +
9.260 + }
9.261 + return null;
9.262 + }
9.263 + else return (resolveclasspathhelper(classpath, classname));
9.264 + }
9.265 +
9.266 +
9.267 + /**
9.268 + * Returns file input stream for classfile to disassemble if exdir is set.
9.269 + */
9.270 + public InputStream resolveExdirFilenamehelper(String path, String classname){
9.271 + File fileobj = new File(path);
9.272 + if(fileobj.isDirectory()){
9.273 + // gets list of files in that directory.
9.274 + File[] filelist = fileobj.listFiles();
9.275 + for(int i = 0; i < filelist.length; i++){
9.276 + try{
9.277 + //file is a jar file.
9.278 + if(filelist[i].toString().endsWith(".jar")){
9.279 + JarFile jfile = new JarFile(filelist[i]);
9.280 + if((jfile.getEntry(classname)) != null){
9.281 +
9.282 + InputStream filein = jfile.getInputStream(jfile.getEntry(classname));
9.283 + int bytearraysize = filein.available();
9.284 + byte []b = new byte[bytearraysize];
9.285 + int totalread = 0;
9.286 + while(totalread < bytearraysize){
9.287 + totalread += filein.read(b, totalread, bytearraysize-totalread);
9.288 + }
9.289 + InputStream inbyte = new ByteArrayInputStream(b);
9.290 + filein.close();
9.291 + return inbyte;
9.292 + }
9.293 + } else {
9.294 + //not a jar file.
9.295 + String filename = path+"/"+ classname;
9.296 + File file = new File(filename);
9.297 + if(file.isFile()){
9.298 + return (new FileInputStream(file));
9.299 + }
9.300 + }
9.301 + }catch(FileNotFoundException fnexce){
9.302 + fnexce.printStackTrace();
9.303 + error("cant read file");
9.304 + error("fatal exception");
9.305 + }catch(IOException ioexc){
9.306 + ioexc.printStackTrace();
9.307 + error("fatal exception");
9.308 + }
9.309 + }
9.310 + }
9.311 +
9.312 + return null;
9.313 + }
9.314 +
9.315 +
9.316 + /**
9.317 + * Returns file input stream for classfile to disassemble.
9.318 + */
9.319 + public InputStream resolveclasspathhelper(String path, String classname){
9.320 + File fileobj = new File(path);
9.321 + try{
9.322 + if(fileobj.isDirectory()){
9.323 + //is a directory.
9.324 + String filename = path+"/"+ classname;
9.325 + File file = new File(filename);
9.326 + if(file.isFile()){
9.327 + return (new FileInputStream(file));
9.328 + }
9.329 +
9.330 + }else if(fileobj.isFile()){
9.331 + if(fileobj.toString().endsWith(".jar")){
9.332 + //is a jar file.
9.333 + JarFile jfile = new JarFile(fileobj);
9.334 + if((jfile.getEntry(classname)) != null){
9.335 + InputStream filein = jfile.getInputStream(jfile.getEntry(classname));
9.336 + int bytearraysize = filein.available();
9.337 + byte []b = new byte[bytearraysize];
9.338 + int totalread = 0;
9.339 + while(totalread < bytearraysize){
9.340 + totalread += filein.read(b, totalread, bytearraysize-totalread);
9.341 + }
9.342 + InputStream inbyte = new ByteArrayInputStream(b);
9.343 + filein.close();
9.344 + return inbyte;
9.345 + }
9.346 + }
9.347 + }
9.348 + }catch(FileNotFoundException fnexce){
9.349 + fnexce.printStackTrace();
9.350 + error("cant read file");
9.351 + error("fatal exception");
9.352 + }catch(IOException ioexce){
9.353 + ioexce.printStackTrace();
9.354 + error("fatal exception");
9.355 + }
9.356 + return null;
9.357 + }
9.358 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/javap/src/main/java/sun/tools/javap/JavapPrinter.java Fri Nov 09 21:33:22 2012 +0100
10.3 @@ -0,0 +1,910 @@
10.4 +/*
10.5 + * Copyright (c) 2002, 2005, 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 sun.tools.javap;
10.31 +
10.32 +import java.util.*;
10.33 +import java.io.*;
10.34 +
10.35 +import static sun.tools.javap.RuntimeConstants.*;
10.36 +
10.37 +/**
10.38 + * Program to print information about class files
10.39 + *
10.40 + * @author Sucheta Dambalkar
10.41 + */
10.42 +public class JavapPrinter {
10.43 + JavapEnvironment env;
10.44 + ClassData cls;
10.45 + byte[] code;
10.46 + String lP= "";
10.47 + PrintWriter out;
10.48 +
10.49 + public JavapPrinter(InputStream cname, PrintWriter out, JavapEnvironment env){
10.50 + this.out = out;
10.51 + this.cls = new ClassData(cname);
10.52 + this.env = env;
10.53 + }
10.54 +
10.55 + /**
10.56 + * Entry point to print class file information.
10.57 + */
10.58 + public void print(){
10.59 + printclassHeader();
10.60 + printfields();
10.61 + printMethods();
10.62 + printend();
10.63 + }
10.64 +
10.65 + /**
10.66 + * Print a description of the class (not members).
10.67 + */
10.68 + public void printclassHeader(){
10.69 + String srcName="";
10.70 + if ((srcName = cls.getSourceName()) != "null") // requires debug info
10.71 + out.println("Compiled from " + javaclassname(srcName));
10.72 +
10.73 + if(cls.isInterface()) {
10.74 + // The only useful access modifier of an interface is
10.75 + // public; interfaces are always marked as abstract and
10.76 + // cannot be final.
10.77 + out.print((cls.isPublic()?"public ":"") +
10.78 + "interface "+ javaclassname(cls.getClassName()));
10.79 + }
10.80 + else if(cls.isClass()) {
10.81 + String []accflags = cls.getAccess();
10.82 + printAccess(accflags);
10.83 + out.print("class "+ javaclassname(cls.getClassName()));
10.84 +
10.85 + if(cls.getSuperClassName() != null){
10.86 + out.print(" extends " + javaclassname(cls.getSuperClassName()));
10.87 + }
10.88 + }
10.89 +
10.90 + String []interfacelist = cls.getSuperInterfaces();
10.91 + if(interfacelist.length > 0){
10.92 + if(cls.isClass()) {
10.93 + out.print(" implements ");
10.94 + }
10.95 + else if(cls.isInterface()){
10.96 + out.print(" extends ");
10.97 + }
10.98 +
10.99 + for(int j = 0; j < interfacelist.length; j++){
10.100 + out.print(javaclassname(interfacelist[j]));
10.101 +
10.102 + if((j+1) < interfacelist.length) {
10.103 + out.print(",");
10.104 + }
10.105 + }
10.106 + }
10.107 +
10.108 + // Print class attribute information.
10.109 + if((env.showallAttr) || (env.showVerbose)){
10.110 + printClassAttributes();
10.111 + }
10.112 + // Print verbose output.
10.113 + if(env.showVerbose){
10.114 + printverbosecls();
10.115 + }
10.116 + out.println("{");
10.117 + }
10.118 +
10.119 + /**
10.120 + * Print verbose output.
10.121 + */
10.122 + public void printverbosecls(){
10.123 + out.println(" minor version: "+cls.getMinor_version());
10.124 + out.println(" major version: "+cls.getMajor_version());
10.125 + out.println(" Constant pool:");
10.126 + printcp();
10.127 + env.showallAttr = true;
10.128 + }
10.129 +
10.130 + /**
10.131 + * Print class attribute information.
10.132 + */
10.133 + public void printClassAttributes(){
10.134 + out.println();
10.135 + AttrData[] clsattrs = cls.getAttributes();
10.136 + for(int i = 0; i < clsattrs.length; i++){
10.137 + String clsattrname = clsattrs[i].getAttrName();
10.138 + if(clsattrname.equals("SourceFile")){
10.139 + out.println(" SourceFile: "+ cls.getSourceName());
10.140 + }else if(clsattrname.equals("InnerClasses")){
10.141 + printInnerClasses();
10.142 + }else {
10.143 + printAttrData(clsattrs[i]);
10.144 + }
10.145 + }
10.146 + }
10.147 +
10.148 + /**
10.149 + * Print the fields
10.150 + */
10.151 + public void printfields(){
10.152 + FieldData[] fields = cls.getFields();
10.153 + for(int f = 0; f < fields.length; f++){
10.154 + String[] accflags = fields[f].getAccess();
10.155 + if(checkAccess(accflags)){
10.156 + if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
10.157 + || env.showInternalSigs || env.showallAttr)){
10.158 + out.print(" ");
10.159 + }
10.160 + printAccess(accflags);
10.161 + out.println(fields[f].getType()+" " +fields[f].getName()+";");
10.162 + if (env.showInternalSigs) {
10.163 + out.println(" Signature: " + (fields[f].getInternalSig()));
10.164 + }
10.165 +
10.166 + // print field attribute information.
10.167 + if (env.showallAttr){
10.168 + printFieldAttributes(fields[f]);
10.169 +
10.170 + }
10.171 + if((env.showDisassembled) || (env.showLineAndLocal)){
10.172 + out.println();
10.173 + }
10.174 + }
10.175 + }
10.176 + }
10.177 +
10.178 +
10.179 + /* print field attribute information. */
10.180 + public void printFieldAttributes(FieldData field){
10.181 + Vector fieldattrs = field.getAttributes();
10.182 + for(int j = 0; j < fieldattrs.size(); j++){
10.183 + String fieldattrname = ((AttrData)fieldattrs.elementAt(j)).getAttrName();
10.184 + if(fieldattrname.equals("ConstantValue")){
10.185 + printConstantValue(field);
10.186 + }else if (fieldattrname.equals("Deprecated")){
10.187 + out.println("Deprecated: "+ field.isDeprecated());
10.188 + }else if (fieldattrname.equals("Synthetic")){
10.189 + out.println(" Synthetic: "+ field.isSynthetic());
10.190 + }else {
10.191 + printAttrData((AttrData)fieldattrs.elementAt(j));
10.192 + }
10.193 + }
10.194 + out.println();
10.195 + }
10.196 +
10.197 + /**
10.198 + * Print the methods
10.199 + */
10.200 + public void printMethods(){
10.201 + MethodData[] methods = cls.getMethods();
10.202 + for(int m = 0; m < methods.length; m++){
10.203 + String[] accflags = methods[m].getAccess();
10.204 + if(checkAccess(accflags)){
10.205 + if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
10.206 + || env.showInternalSigs || env.showallAttr)){
10.207 + out.print(" ");
10.208 + }
10.209 + printMethodSignature(methods[m], accflags);
10.210 + printExceptions(methods[m]);
10.211 + out.println(";");
10.212 +
10.213 + // Print internal signature of method.
10.214 + if (env.showInternalSigs){
10.215 + out.println(" Signature: " + (methods[m].getInternalSig()));
10.216 + }
10.217 +
10.218 + //Print disassembled code.
10.219 + if(env.showDisassembled && ! env.showallAttr) {
10.220 + printcodeSequence(methods[m]);
10.221 + printExceptionTable(methods[m]);
10.222 + out.println();
10.223 + }
10.224 +
10.225 + // Print line and local variable attribute information.
10.226 + if (env.showLineAndLocal) {
10.227 + printLineNumTable(methods[m]);
10.228 + printLocVarTable(methods[m]);
10.229 + out.println();
10.230 + }
10.231 +
10.232 + // Print method attribute information.
10.233 + if (env.showallAttr){
10.234 + printMethodAttributes(methods[m]);
10.235 + }
10.236 + }
10.237 + }
10.238 + }
10.239 +
10.240 + /**
10.241 + * Print method signature.
10.242 + */
10.243 + public void printMethodSignature(MethodData method, String[] accflags){
10.244 + printAccess(accflags);
10.245 +
10.246 + if((method.getName()).equals("<init>")){
10.247 + out.print(javaclassname(cls.getClassName()));
10.248 + out.print(method.getParameters());
10.249 + }else if((method.getName()).equals("<clinit>")){
10.250 + out.print("{}");
10.251 + }else{
10.252 + out.print(method.getReturnType()+" ");
10.253 + out.print(method.getName());
10.254 + out.print(method.getParameters());
10.255 + }
10.256 + }
10.257 +
10.258 + /**
10.259 + * print method attribute information.
10.260 + */
10.261 + public void printMethodAttributes(MethodData method){
10.262 + Vector methodattrs = method.getAttributes();
10.263 + Vector codeattrs = method.getCodeAttributes();
10.264 + for(int k = 0; k < methodattrs.size(); k++){
10.265 + String methodattrname = ((AttrData)methodattrs.elementAt(k)).getAttrName();
10.266 + if(methodattrname.equals("Code")){
10.267 + printcodeSequence(method);
10.268 + printExceptionTable(method);
10.269 + for(int c = 0; c < codeattrs.size(); c++){
10.270 + String codeattrname = ((AttrData)codeattrs.elementAt(c)).getAttrName();
10.271 + if(codeattrname.equals("LineNumberTable")){
10.272 + printLineNumTable(method);
10.273 + }else if(codeattrname.equals("LocalVariableTable")){
10.274 + printLocVarTable(method);
10.275 + }else if(codeattrname.equals("StackMapTable")) {
10.276 + // Java SE JSR 202 stack map tables
10.277 + printStackMapTable(method);
10.278 + }else if(codeattrname.equals("StackMap")) {
10.279 + // Java ME CLDC stack maps
10.280 + printStackMap(method);
10.281 + } else {
10.282 + printAttrData((AttrData)codeattrs.elementAt(c));
10.283 + }
10.284 + }
10.285 + }else if(methodattrname.equals("Exceptions")){
10.286 + out.println(" Exceptions: ");
10.287 + printExceptions(method);
10.288 + }else if (methodattrname.equals("Deprecated")){
10.289 + out.println(" Deprecated: "+ method.isDeprecated());
10.290 + }else if (methodattrname.equals("Synthetic")){
10.291 + out.println(" Synthetic: "+ method.isSynthetic());
10.292 + }else {
10.293 + printAttrData((AttrData)methodattrs.elementAt(k));
10.294 + }
10.295 + }
10.296 + out.println();
10.297 + }
10.298 +
10.299 + /**
10.300 + * Print exceptions.
10.301 + */
10.302 + public void printExceptions(MethodData method){
10.303 + int []exc_index_table = method.get_exc_index_table();
10.304 + if (exc_index_table != null) {
10.305 + if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
10.306 + || env.showInternalSigs || env.showallAttr)){
10.307 + out.print(" ");
10.308 + }
10.309 + out.print(" throws ");
10.310 + int k;
10.311 + int l = exc_index_table.length;
10.312 +
10.313 + for (k=0; k<l; k++) {
10.314 + out.print(javaclassname(cls.getClassName(exc_index_table[k])));
10.315 + if (k<l-1) out.print(", ");
10.316 + }
10.317 + }
10.318 + }
10.319 +
10.320 + /**
10.321 + * Print code sequence.
10.322 + */
10.323 + public void printcodeSequence(MethodData method){
10.324 + code = method.getCode();
10.325 + if(code != null){
10.326 + out.println(" Code:");
10.327 + if(env.showVerbose){
10.328 + printVerboseHeader(method);
10.329 + }
10.330 +
10.331 + for (int pc=0; pc < code.length; ) {
10.332 + out.print(" "+pc+":\t");
10.333 + pc=pc+printInstr(pc);
10.334 + out.println();
10.335 + }
10.336 + }
10.337 + }
10.338 +
10.339 + /**
10.340 + * Print instructions.
10.341 + */
10.342 + public int printInstr(int pc){
10.343 + int opcode = getUbyte(pc);
10.344 + int opcode2;
10.345 + String mnem;
10.346 + switch (opcode) {
10.347 + case opc_nonpriv:
10.348 + case opc_priv:
10.349 + opcode2 = getUbyte(pc+1);
10.350 + mnem=Tables.opcName((opcode<<8)+opcode2);
10.351 + if (mnem==null)
10.352 + // assume all (even nonexistent) priv and nonpriv instructions
10.353 + // are 2 bytes long
10.354 + mnem=Tables.opcName(opcode)+" "+opcode2;
10.355 + out.print(mnem);
10.356 + return 2;
10.357 + case opc_wide: {
10.358 + opcode2 = getUbyte(pc+1);
10.359 + mnem=Tables.opcName((opcode<<8)+opcode2);
10.360 + if (mnem==null) {
10.361 + // nonexistent opcode - but we have to print something
10.362 + out.print("bytecode "+opcode);
10.363 + return 1;
10.364 + }
10.365 + out.print(mnem+" "+getUShort(pc+2));
10.366 + if (opcode2==opc_iinc) {
10.367 + out.print(", "+getShort(pc+4));
10.368 + return 6;
10.369 + }
10.370 + return 4;
10.371 + }
10.372 + }
10.373 + mnem=Tables.opcName(opcode);
10.374 + if (mnem==null) {
10.375 + // nonexistent opcode - but we have to print something
10.376 + out.print("bytecode "+opcode);
10.377 + return 1;
10.378 + }
10.379 + if (opcode>opc_jsr_w) {
10.380 + // pseudo opcodes should be printed as bytecodes
10.381 + out.print("bytecode "+opcode);
10.382 + return 1;
10.383 + }
10.384 + out.print(Tables.opcName(opcode));
10.385 + switch (opcode) {
10.386 + case opc_aload: case opc_astore:
10.387 + case opc_fload: case opc_fstore:
10.388 + case opc_iload: case opc_istore:
10.389 + case opc_lload: case opc_lstore:
10.390 + case opc_dload: case opc_dstore:
10.391 + case opc_ret:
10.392 + out.print("\t"+getUbyte(pc+1));
10.393 + return 2;
10.394 + case opc_iinc:
10.395 + out.print("\t"+getUbyte(pc+1)+", "+getbyte(pc+2));
10.396 + return 3;
10.397 + case opc_tableswitch:{
10.398 + int tb=align(pc+1);
10.399 + int default_skip = getInt(tb); /* default skip pamount */
10.400 + int low = getInt(tb+4);
10.401 + int high = getInt(tb+8);
10.402 + int count = high - low;
10.403 + out.print("{ //"+low+" to "+high);
10.404 + for (int i = 0; i <= count; i++)
10.405 + out.print( "\n\t\t" + (i+low) + ": "+lP+(pc+getInt(tb+12+4*i))+";");
10.406 + out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
10.407 + return tb-pc+16+count*4;
10.408 + }
10.409 +
10.410 + case opc_lookupswitch:{
10.411 + int tb=align(pc+1);
10.412 + int default_skip = getInt(tb);
10.413 + int npairs = getInt(tb+4);
10.414 + out.print("{ //"+npairs);
10.415 + for (int i = 1; i <= npairs; i++)
10.416 + out.print("\n\t\t"+getInt(tb+i*8)
10.417 + +": "+lP+(pc+getInt(tb+4+i*8))+";"
10.418 + );
10.419 + out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
10.420 + return tb-pc+(npairs+1)*8;
10.421 + }
10.422 + case opc_newarray:
10.423 + int type=getUbyte(pc+1);
10.424 + switch (type) {
10.425 + case T_BOOLEAN:out.print(" boolean");break;
10.426 + case T_BYTE: out.print(" byte"); break;
10.427 + case T_CHAR: out.print(" char"); break;
10.428 + case T_SHORT: out.print(" short"); break;
10.429 + case T_INT: out.print(" int"); break;
10.430 + case T_LONG: out.print(" long"); break;
10.431 + case T_FLOAT: out.print(" float"); break;
10.432 + case T_DOUBLE: out.print(" double"); break;
10.433 + case T_CLASS: out.print(" class"); break;
10.434 + default: out.print(" BOGUS TYPE:"+type);
10.435 + }
10.436 + return 2;
10.437 +
10.438 + case opc_anewarray: {
10.439 + int index = getUShort(pc+1);
10.440 + out.print("\t#"+index+"; //");
10.441 + PrintConstant(index);
10.442 + return 3;
10.443 + }
10.444 +
10.445 + case opc_sipush:
10.446 + out.print("\t"+getShort(pc+1));
10.447 + return 3;
10.448 +
10.449 + case opc_bipush:
10.450 + out.print("\t"+getbyte(pc+1));
10.451 + return 2;
10.452 +
10.453 + case opc_ldc: {
10.454 + int index = getUbyte(pc+1);
10.455 + out.print("\t#"+index+"; //");
10.456 + PrintConstant(index);
10.457 + return 2;
10.458 + }
10.459 +
10.460 + case opc_ldc_w: case opc_ldc2_w:
10.461 + case opc_instanceof: case opc_checkcast:
10.462 + case opc_new:
10.463 + case opc_putstatic: case opc_getstatic:
10.464 + case opc_putfield: case opc_getfield:
10.465 + case opc_invokevirtual:
10.466 + case opc_invokespecial:
10.467 + case opc_invokestatic: {
10.468 + int index = getUShort(pc+1);
10.469 + out.print("\t#"+index+"; //");
10.470 + PrintConstant(index);
10.471 + return 3;
10.472 + }
10.473 +
10.474 + case opc_invokeinterface: {
10.475 + int index = getUShort(pc+1), nargs=getUbyte(pc+3);
10.476 + out.print("\t#"+index+", "+nargs+"; //");
10.477 + PrintConstant(index);
10.478 + return 5;
10.479 + }
10.480 +
10.481 + case opc_multianewarray: {
10.482 + int index = getUShort(pc+1), dimensions=getUbyte(pc+3);
10.483 + out.print("\t#"+index+", "+dimensions+"; //");
10.484 + PrintConstant(index);
10.485 + return 4;
10.486 + }
10.487 + case opc_jsr: case opc_goto:
10.488 + case opc_ifeq: case opc_ifge: case opc_ifgt:
10.489 + case opc_ifle: case opc_iflt: case opc_ifne:
10.490 + case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpge:
10.491 + case opc_if_icmpgt: case opc_if_icmple: case opc_if_icmplt:
10.492 + case opc_if_acmpeq: case opc_if_acmpne:
10.493 + case opc_ifnull: case opc_ifnonnull:
10.494 + out.print("\t"+lP+(pc + getShort(pc+1)) );
10.495 + return 3;
10.496 +
10.497 + case opc_jsr_w:
10.498 + case opc_goto_w:
10.499 + out.print("\t"+lP+(pc + getInt(pc+1)));
10.500 + return 5;
10.501 +
10.502 + default:
10.503 + return 1;
10.504 + }
10.505 + }
10.506 + /**
10.507 + * Print code attribute details.
10.508 + */
10.509 + public void printVerboseHeader(MethodData method) {
10.510 + int argCount = method.getArgumentlength();
10.511 + if (!method.isStatic())
10.512 + ++argCount; // for 'this'
10.513 +
10.514 + out.println(" Stack=" + method.getMaxStack()
10.515 + + ", Locals=" + method.getMaxLocals()
10.516 + + ", Args_size=" + argCount);
10.517 +
10.518 + }
10.519 +
10.520 +
10.521 + /**
10.522 + * Print the exception table for this method code
10.523 + */
10.524 + void printExceptionTable(MethodData method){//throws IOException
10.525 + Vector exception_table = method.getexception_table();
10.526 + if (exception_table.size() > 0) {
10.527 + out.println(" Exception table:");
10.528 + out.println(" from to target type");
10.529 + for (int idx = 0; idx < exception_table.size(); ++idx) {
10.530 + TrapData handler = (TrapData)exception_table.elementAt(idx);
10.531 + printFixedWidthInt(handler.start_pc, 6);
10.532 + printFixedWidthInt(handler.end_pc, 6);
10.533 + printFixedWidthInt(handler.handler_pc, 6);
10.534 + out.print(" ");
10.535 + int catch_cpx = handler.catch_cpx;
10.536 + if (catch_cpx == 0) {
10.537 + out.println("any");
10.538 + }else {
10.539 + out.print("Class ");
10.540 + out.println(cls.getClassName(catch_cpx));
10.541 + out.println("");
10.542 + }
10.543 + }
10.544 + }
10.545 + }
10.546 +
10.547 + /**
10.548 + * Print LineNumberTable attribute information.
10.549 + */
10.550 + public void printLineNumTable(MethodData method) {
10.551 + int numlines = method.getnumlines();
10.552 + Vector lin_num_tb = method.getlin_num_tb();
10.553 + if( lin_num_tb.size() > 0){
10.554 + out.println(" LineNumberTable: ");
10.555 + for (int i=0; i<numlines; i++) {
10.556 + LineNumData linnumtb_entry=(LineNumData)lin_num_tb.elementAt(i);
10.557 + out.println(" line " + linnumtb_entry.line_number + ": "
10.558 + + linnumtb_entry.start_pc);
10.559 + }
10.560 + }
10.561 + out.println();
10.562 + }
10.563 +
10.564 + /**
10.565 + * Print LocalVariableTable attribute information.
10.566 + */
10.567 + public void printLocVarTable(MethodData method){
10.568 + int siz = method.getloc_var_tbsize();
10.569 + if(siz > 0){
10.570 + out.println(" LocalVariableTable: ");
10.571 + out.print(" ");
10.572 + out.println("Start Length Slot Name Signature");
10.573 + }
10.574 + Vector loc_var_tb = method.getloc_var_tb();
10.575 +
10.576 + for (int i=0; i<siz; i++) {
10.577 + LocVarData entry=(LocVarData)loc_var_tb.elementAt(i);
10.578 +
10.579 + out.println(" "+entry.start_pc+" "+entry.length+" "+
10.580 + entry.slot+" "+cls.StringValue(entry.name_cpx) +
10.581 + " "+cls.StringValue(entry.sig_cpx));
10.582 + }
10.583 + out.println();
10.584 + }
10.585 +
10.586 + /**
10.587 + * Print StackMap attribute information.
10.588 + */
10.589 + public void printStackMap(MethodData method) {
10.590 + StackMapData[] stack_map_tb = method.getStackMap();
10.591 + int number_of_entries = stack_map_tb.length;
10.592 + if (number_of_entries > 0) {
10.593 + out.println(" StackMap: number_of_entries = " + number_of_entries);
10.594 +
10.595 + for (StackMapData frame : stack_map_tb) {
10.596 + frame.print(this);
10.597 + }
10.598 + }
10.599 + out.println();
10.600 + }
10.601 +
10.602 + /**
10.603 + * Print StackMapTable attribute information.
10.604 + */
10.605 + public void printStackMapTable(MethodData method) {
10.606 + StackMapTableData[] stack_map_tb = method.getStackMapTable();
10.607 + int number_of_entries = stack_map_tb.length;
10.608 + if (number_of_entries > 0) {
10.609 + out.println(" StackMapTable: number_of_entries = " + number_of_entries);
10.610 +
10.611 + for (StackMapTableData frame : stack_map_tb) {
10.612 + frame.print(this);
10.613 + }
10.614 + }
10.615 + out.println();
10.616 + }
10.617 +
10.618 + void printMap(String name, int[] map) {
10.619 + out.print(name);
10.620 + for (int i=0; i<map.length; i++) {
10.621 + int fulltype = map[i];
10.622 + int type = fulltype & 0xFF;
10.623 + int argument = fulltype >> 8;
10.624 + switch (type) {
10.625 + case ITEM_Object:
10.626 + out.print(" ");
10.627 + PrintConstant(argument);
10.628 + break;
10.629 + case ITEM_NewObject:
10.630 + out.print(" " + Tables.mapTypeName(type));
10.631 + out.print(" " + argument);
10.632 + break;
10.633 + default:
10.634 + out.print(" " + Tables.mapTypeName(type));
10.635 + }
10.636 + out.print( (i==(map.length-1)? ' ' : ','));
10.637 + }
10.638 + out.println("]");
10.639 + }
10.640 +
10.641 + /**
10.642 + * Print ConstantValue attribute information.
10.643 + */
10.644 + public void printConstantValue(FieldData field){
10.645 + out.print(" Constant value: ");
10.646 + int cpx = (field.getConstantValueIndex());
10.647 + byte tag=0;
10.648 + try {
10.649 + tag=cls.getTag(cpx);
10.650 +
10.651 + } catch (IndexOutOfBoundsException e) {
10.652 + out.print("Error:");
10.653 + return;
10.654 + }
10.655 + switch (tag) {
10.656 + case CONSTANT_METHOD:
10.657 + case CONSTANT_INTERFACEMETHOD:
10.658 + case CONSTANT_FIELD: {
10.659 + CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
10.660 + if (x.cpx1 == cls.getthis_cpx()) {
10.661 + // don't print class part for local references
10.662 + cpx=x.cpx2;
10.663 + }
10.664 + }
10.665 + }
10.666 + out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
10.667 + }
10.668 +
10.669 + /**
10.670 + * Print InnerClass attribute information.
10.671 + */
10.672 + public void printInnerClasses(){//throws ioexception
10.673 +
10.674 + InnerClassData[] innerClasses = cls.getInnerClasses();
10.675 + if(innerClasses != null){
10.676 + if(innerClasses.length > 0){
10.677 + out.print(" ");
10.678 + out.println("InnerClass: ");
10.679 + for(int i = 0 ; i < innerClasses.length; i++){
10.680 + out.print(" ");
10.681 + //access
10.682 + String[] accflags = innerClasses[i].getAccess();
10.683 + if(checkAccess(accflags)){
10.684 + printAccess(accflags);
10.685 + if (innerClasses[i].inner_name_index!=0) {
10.686 + out.print("#"+innerClasses[i].inner_name_index+"= ");
10.687 + }
10.688 + out.print("#"+innerClasses[i].inner_class_info_index);
10.689 + if (innerClasses[i].outer_class_info_index!=0) {
10.690 + out.print(" of #"+innerClasses[i].outer_class_info_index);
10.691 + }
10.692 + out.print("; //");
10.693 + if (innerClasses[i].inner_name_index!=0) {
10.694 + out.print(cls.getName(innerClasses[i].inner_name_index)+"=");
10.695 + }
10.696 + PrintConstant(innerClasses[i].inner_class_info_index);
10.697 + if (innerClasses[i].outer_class_info_index!=0) {
10.698 + out.print(" of ");
10.699 + PrintConstant(innerClasses[i].outer_class_info_index);
10.700 + }
10.701 + out.println();
10.702 + }
10.703 + }
10.704 +
10.705 + }
10.706 + }
10.707 + }
10.708 +
10.709 + /**
10.710 + * Print constant pool information.
10.711 + */
10.712 + public void printcp(){
10.713 + int cpx = 1 ;
10.714 +
10.715 + while (cpx < cls.getCpoolCount()) {
10.716 + out.print("const #"+cpx+" = ");
10.717 + cpx+=PrintlnConstantEntry(cpx);
10.718 + }
10.719 + out.println();
10.720 + }
10.721 +
10.722 + /**
10.723 + * Print constant pool entry information.
10.724 + */
10.725 + public int PrintlnConstantEntry(int cpx) {
10.726 + int size=1;
10.727 + byte tag=0;
10.728 + try {
10.729 + tag=cls.getTag(cpx);
10.730 + } catch (IndexOutOfBoundsException e) {
10.731 + out.println(" <Incorrect CP index>");
10.732 + return 1;
10.733 + }
10.734 + out.print(cls.StringTag(cpx)+"\t");
10.735 + Object x=cls.getCpoolEntryobj(cpx);
10.736 + if (x==null) {
10.737 + switch (tag) {
10.738 + case CONSTANT_LONG:
10.739 + case CONSTANT_DOUBLE:
10.740 + size=2;
10.741 + }
10.742 + out.println("null;");
10.743 + return size;
10.744 + }
10.745 + String str=cls.StringValue(cpx);
10.746 +
10.747 + switch (tag) {
10.748 + case CONSTANT_CLASS:
10.749 + case CONSTANT_STRING:
10.750 + out.println("#"+(((CPX)x).cpx)+";\t// "+str);
10.751 + break;
10.752 + case CONSTANT_FIELD:
10.753 + case CONSTANT_METHOD:
10.754 + case CONSTANT_INTERFACEMETHOD:
10.755 + out.println("#"+((CPX2)x).cpx1+".#"+((CPX2)x).cpx2+";\t// "+str);
10.756 + break;
10.757 + case CONSTANT_NAMEANDTYPE:
10.758 + out.println("#"+((CPX2)x).cpx1+":#"+((CPX2)x).cpx2+";// "+str);
10.759 + break;
10.760 + case CONSTANT_LONG:
10.761 + case CONSTANT_DOUBLE:
10.762 + size=2;
10.763 + default:
10.764 + out.println(str+";");
10.765 + }
10.766 + return size;
10.767 + }
10.768 +
10.769 + /**
10.770 + * Checks access of class, field or method.
10.771 + */
10.772 + public boolean checkAccess(String accflags[]){
10.773 +
10.774 + boolean ispublic = false;
10.775 + boolean isprotected = false;
10.776 + boolean isprivate = false;
10.777 + boolean ispackage = false;
10.778 +
10.779 + for(int i= 0; i < accflags.length; i++){
10.780 + if(accflags[i].equals("public")) ispublic = true;
10.781 + else if (accflags[i].equals("protected")) isprotected = true;
10.782 + else if (accflags[i].equals("private")) isprivate = true;
10.783 + }
10.784 +
10.785 + if(!(ispublic || isprotected || isprivate)) ispackage = true;
10.786 +
10.787 + if((env.showAccess == env.PUBLIC) && (isprotected || isprivate || ispackage)) return false;
10.788 + else if((env.showAccess == env.PROTECTED) && (isprivate || ispackage)) return false;
10.789 + else if((env.showAccess == env.PACKAGE) && (isprivate)) return false;
10.790 + else return true;
10.791 + }
10.792 +
10.793 + /**
10.794 + * Prints access of class, field or method.
10.795 + */
10.796 + public void printAccess(String []accflags){
10.797 + for(int j = 0; j < accflags.length; j++){
10.798 + out.print(accflags[j]+" ");
10.799 + }
10.800 + }
10.801 +
10.802 + /**
10.803 + * Print an integer so that it takes 'length' characters in
10.804 + * the output. Temporary until formatting code is stable.
10.805 + */
10.806 + public void printFixedWidthInt(long x, int length) {
10.807 + CharArrayWriter baStream = new CharArrayWriter();
10.808 + PrintWriter pStream = new PrintWriter(baStream);
10.809 + pStream.print(x);
10.810 + String str = baStream.toString();
10.811 + for (int cnt = length - str.length(); cnt > 0; --cnt)
10.812 + out.print(' ');
10.813 + out.print(str);
10.814 + }
10.815 +
10.816 + protected int getbyte (int pc) {
10.817 + return code[pc];
10.818 + }
10.819 +
10.820 + protected int getUbyte (int pc) {
10.821 + return code[pc]&0xFF;
10.822 + }
10.823 +
10.824 + int getShort (int pc) {
10.825 + return (code[pc]<<8) | (code[pc+1]&0xFF);
10.826 + }
10.827 +
10.828 + int getUShort (int pc) {
10.829 + return ((code[pc]<<8) | (code[pc+1]&0xFF))&0xFFFF;
10.830 + }
10.831 +
10.832 + protected int getInt (int pc) {
10.833 + return (getShort(pc)<<16) | (getShort(pc+2)&0xFFFF);
10.834 + }
10.835 +
10.836 + /**
10.837 + * Print constant value at that index.
10.838 + */
10.839 + void PrintConstant(int cpx) {
10.840 + if (cpx==0) {
10.841 + out.print("#0");
10.842 + return;
10.843 + }
10.844 + byte tag=0;
10.845 + try {
10.846 + tag=cls.getTag(cpx);
10.847 +
10.848 + } catch (IndexOutOfBoundsException e) {
10.849 + out.print("#"+cpx);
10.850 + return;
10.851 + }
10.852 + switch (tag) {
10.853 + case CONSTANT_METHOD:
10.854 + case CONSTANT_INTERFACEMETHOD:
10.855 + case CONSTANT_FIELD: {
10.856 + // CPX2 x=(CPX2)(cpool[cpx]);
10.857 + CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
10.858 + if (x.cpx1 == cls.getthis_cpx()) {
10.859 + // don't print class part for local references
10.860 + cpx=x.cpx2;
10.861 + }
10.862 + }
10.863 + }
10.864 + out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
10.865 + }
10.866 +
10.867 + protected static int align (int n) {
10.868 + return (n+3) & ~3 ;
10.869 + }
10.870 +
10.871 + public void printend(){
10.872 + out.println("}");
10.873 + out.println();
10.874 + }
10.875 +
10.876 + public String javaclassname(String name){
10.877 + return name.replace('/','.');
10.878 + }
10.879 +
10.880 + /**
10.881 + * Print attribute data in hex.
10.882 + */
10.883 + public void printAttrData(AttrData attr){
10.884 + byte []data = attr.getData();
10.885 + int i = 0;
10.886 + int j = 0;
10.887 + out.print(" "+attr.getAttrName()+": ");
10.888 + out.println("length = " + cls.toHex(attr.datalen));
10.889 +
10.890 + out.print(" ");
10.891 +
10.892 +
10.893 + while (i < data.length){
10.894 + String databytestring = cls.toHex(data[i]);
10.895 + if(databytestring.equals("0x")) out.print("00");
10.896 + else if(databytestring.substring(2).length() == 1){
10.897 + out.print("0"+databytestring.substring(2));
10.898 + } else{
10.899 + out.print(databytestring.substring(2));
10.900 + }
10.901 +
10.902 + j++;
10.903 + if(j == 16) {
10.904 + out.println();
10.905 + out.print(" ");
10.906 + j = 0;
10.907 + }
10.908 + else out.print(" ");
10.909 + i++;
10.910 + }
10.911 + out.println();
10.912 + }
10.913 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/javap/src/main/java/sun/tools/javap/LineNumData.java Fri Nov 09 21:33:22 2012 +0100
11.3 @@ -0,0 +1,50 @@
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 sun.tools.javap;
11.31 +
11.32 +import java.util.*;
11.33 +import java.io.*;
11.34 +
11.35 +/**
11.36 + * Strores LineNumberTable data information.
11.37 + *
11.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
11.39 + */
11.40 +class LineNumData {
11.41 + short start_pc, line_number;
11.42 +
11.43 + public LineNumData() {}
11.44 +
11.45 + /**
11.46 + * Read LineNumberTable attribute.
11.47 + */
11.48 + public LineNumData(DataInputStream in) throws IOException {
11.49 + start_pc = in.readShort();
11.50 + line_number=in.readShort();
11.51 +
11.52 + }
11.53 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/javap/src/main/java/sun/tools/javap/LocVarData.java Fri Nov 09 21:33:22 2012 +0100
12.3 @@ -0,0 +1,54 @@
12.4 +/*
12.5 + * Copyright (c) 2002, 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 +
12.30 +package sun.tools.javap;
12.31 +
12.32 +import java.util.*;
12.33 +import java.io.*;
12.34 +
12.35 +/**
12.36 + * Strores LocalVariableTable data information.
12.37 + *
12.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
12.39 + */
12.40 +class LocVarData {
12.41 + short start_pc, length, name_cpx, sig_cpx, slot;
12.42 +
12.43 + public LocVarData() {
12.44 + }
12.45 +
12.46 + /**
12.47 + * Read LocalVariableTable attribute.
12.48 + */
12.49 + public LocVarData(DataInputStream in) throws IOException {
12.50 + start_pc = in.readShort();
12.51 + length=in.readShort();
12.52 + name_cpx=in.readShort();
12.53 + sig_cpx=in.readShort();
12.54 + slot=in.readShort();
12.55 +
12.56 + }
12.57 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/javap/src/main/java/sun/tools/javap/Main.java Fri Nov 09 21:33:22 2012 +0100
13.3 @@ -0,0 +1,216 @@
13.4 +/*
13.5 + * Copyright (c) 2002, 2003, 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 +
13.31 +package sun.tools.javap;
13.32 +
13.33 +import java.util.*;
13.34 +import java.io.*;
13.35 +
13.36 +/**
13.37 + * Entry point for javap, class file disassembler.
13.38 + *
13.39 + * @author Sucheta Dambalkar (Adopted code from old javap)
13.40 + */
13.41 +public class Main{
13.42 +
13.43 + private Vector classList = new Vector();
13.44 + private PrintWriter out;
13.45 + JavapEnvironment env = new JavapEnvironment();
13.46 + private static boolean errorOccurred = false;
13.47 + private static final String progname = "javap";
13.48 +
13.49 +
13.50 + public Main(PrintWriter out){
13.51 + this.out = out;
13.52 + }
13.53 +
13.54 + public static void main(String argv[]) {
13.55 + entry(argv);
13.56 + if (errorOccurred) {
13.57 + System.exit(1);
13.58 + }
13.59 + }
13.60 +
13.61 +
13.62 + /**
13.63 + * Entry point for tool if you don't want System.exit() called.
13.64 + */
13.65 + public static void entry(String argv[]) {
13.66 + PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
13.67 + try {
13.68 +
13.69 + Main jpmain = new Main(out);
13.70 + jpmain.perform(argv);
13.71 +
13.72 + } finally {
13.73 + out.close();
13.74 + }
13.75 + }
13.76 +
13.77 + /**
13.78 + * Process the arguments and perform the desired action
13.79 + */
13.80 + private void perform(String argv[]) {
13.81 + if (parseArguments(argv)) {
13.82 + displayResults();
13.83 +
13.84 + }
13.85 + }
13.86 +
13.87 + private void error(String msg) {
13.88 + errorOccurred = true;
13.89 + System.err.println(msg);
13.90 + System.err.flush();
13.91 + }
13.92 +
13.93 + /**
13.94 + * Print usage information
13.95 + */
13.96 + private void usage() {
13.97 + java.io.PrintStream out = System.out;
13.98 + out.println("Usage: " + progname + " <options> <classes>...");
13.99 + out.println();
13.100 + out.println("where options include:");
13.101 + out.println(" -c Disassemble the code");
13.102 + out.println(" -classpath <pathlist> Specify where to find user class files");
13.103 + out.println(" -extdirs <dirs> Override location of installed extensions");
13.104 + out.println(" -help Print this usage message");
13.105 + out.println(" -J<flag> Pass <flag> directly to the runtime system");
13.106 + out.println(" -l Print line number and local variable tables");
13.107 + out.println(" -public Show only public classes and members");
13.108 + out.println(" -protected Show protected/public classes and members");
13.109 + out.println(" -package Show package/protected/public classes");
13.110 + out.println(" and members (default)");
13.111 + out.println(" -private Show all classes and members");
13.112 + out.println(" -s Print internal type signatures");
13.113 + out.println(" -bootclasspath <pathlist> Override location of class files loaded");
13.114 + out.println(" by the bootstrap class loader");
13.115 + out.println(" -verbose Print stack size, number of locals and args for methods");
13.116 + out.println(" If verifying, print reasons for failure");
13.117 + out.println();
13.118 + }
13.119 +
13.120 + /**
13.121 + * Parse the command line arguments.
13.122 + * Set flags, construct the class list and create environment.
13.123 + */
13.124 + private boolean parseArguments(String argv[]) {
13.125 + for (int i = 0 ; i < argv.length ; i++) {
13.126 + String arg = argv[i];
13.127 + if (arg.startsWith("-")) {
13.128 + if (arg.equals("-l")) {
13.129 + env.showLineAndLocal = true;
13.130 + } else if (arg.equals("-private") || arg.equals("-p")) {
13.131 + env.showAccess = env.PRIVATE;
13.132 + } else if (arg.equals("-package")) {
13.133 + env.showAccess = env.PACKAGE;
13.134 + } else if (arg.equals("-protected")) {
13.135 + env.showAccess = env.PROTECTED;
13.136 + } else if (arg.equals("-public")) {
13.137 + env.showAccess = env.PUBLIC;
13.138 + } else if (arg.equals("-c")) {
13.139 + env.showDisassembled = true;
13.140 + } else if (arg.equals("-s")) {
13.141 + env.showInternalSigs = true;
13.142 + } else if (arg.equals("-verbose")) {
13.143 + env.showVerbose = true;
13.144 + } else if (arg.equals("-v")) {
13.145 + env.showVerbose = true;
13.146 + } else if (arg.equals("-h")) {
13.147 + error("-h is no longer available - use the 'javah' program");
13.148 + return false;
13.149 + } else if (arg.equals("-verify")) {
13.150 + error("-verify is no longer available - use 'java -verify'");
13.151 + return false;
13.152 + } else if (arg.equals("-verify-verbose")) {
13.153 + error("-verify is no longer available - use 'java -verify'");
13.154 + return false;
13.155 + } else if (arg.equals("-help")) {
13.156 + usage();
13.157 + return false;
13.158 + } else if (arg.equals("-classpath")) {
13.159 + if ((i + 1) < argv.length) {
13.160 + env.classPathString = argv[++i];
13.161 + } else {
13.162 + error("-classpath requires argument");
13.163 + usage();
13.164 + return false;
13.165 + }
13.166 + } else if (arg.equals("-bootclasspath")) {
13.167 + if ((i + 1) < argv.length) {
13.168 + env.bootClassPathString = argv[++i];
13.169 + } else {
13.170 + error("-bootclasspath requires argument");
13.171 + usage();
13.172 + return false;
13.173 + }
13.174 + } else if (arg.equals("-extdirs")) {
13.175 + if ((i + 1) < argv.length) {
13.176 + env.extDirsString = argv[++i];
13.177 + } else {
13.178 + error("-extdirs requires argument");
13.179 + usage();
13.180 + return false;
13.181 + }
13.182 + } else if (arg.equals("-all")) {
13.183 + env.showallAttr = true;
13.184 + } else {
13.185 + error("invalid flag: " + arg);
13.186 + usage();
13.187 + return false;
13.188 + }
13.189 + } else {
13.190 + classList.addElement(arg);
13.191 + env.nothingToDo = false;
13.192 + }
13.193 + }
13.194 + if (env.nothingToDo) {
13.195 + System.out.println("No classes were specified on the command line. Try -help.");
13.196 + errorOccurred = true;
13.197 + return false;
13.198 + }
13.199 + return true;
13.200 + }
13.201 +
13.202 + /**
13.203 + * Display results
13.204 + */
13.205 + private void displayResults() {
13.206 + for (int i = 0; i < classList.size() ; i++ ) {
13.207 + String Name = (String)classList.elementAt(i);
13.208 + InputStream classin = env.getFileInputStream(Name);
13.209 +
13.210 + try {
13.211 + JavapPrinter printer = new JavapPrinter(classin, out, env);
13.212 + printer.print(); // actual do display
13.213 +
13.214 + } catch (IllegalArgumentException exc) {
13.215 + error(exc.getMessage());
13.216 + }
13.217 + }
13.218 + }
13.219 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/javap/src/main/java/sun/tools/javap/MethodData.java Fri Nov 09 21:33:22 2012 +0100
14.3 @@ -0,0 +1,416 @@
14.4 +/*
14.5 + * Copyright (c) 2002, 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 +package sun.tools.javap;
14.30 +
14.31 +import java.util.*;
14.32 +import java.io.*;
14.33 +
14.34 +import static sun.tools.javap.RuntimeConstants.*;
14.35 +
14.36 +/**
14.37 + * Strores method data informastion.
14.38 + *
14.39 + * @author Sucheta Dambalkar (Adopted code from jdis)
14.40 + */
14.41 +public class MethodData {
14.42 +
14.43 + ClassData cls;
14.44 + int access;
14.45 + int name_index;
14.46 + int descriptor_index;
14.47 + int attributes_count;
14.48 + byte[] code;
14.49 + Vector exception_table = new Vector(0);
14.50 + Vector lin_num_tb = new Vector(0);
14.51 + Vector loc_var_tb = new Vector(0);
14.52 + StackMapTableData[] stackMapTable;
14.53 + StackMapData[] stackMap;
14.54 + int[] exc_index_table=null;
14.55 + Vector attrs=new Vector(0);
14.56 + Vector code_attrs=new Vector(0);
14.57 + int max_stack, max_locals;
14.58 + boolean isSynthetic=false;
14.59 + boolean isDeprecated=false;
14.60 +
14.61 + public MethodData(ClassData cls){
14.62 + this.cls=cls;
14.63 + }
14.64 +
14.65 + /**
14.66 + * Read method info.
14.67 + */
14.68 + public void read(DataInputStream in) throws IOException {
14.69 + access = in.readUnsignedShort();
14.70 + name_index=in.readUnsignedShort();
14.71 + descriptor_index =in.readUnsignedShort();
14.72 + int attributes_count = in.readUnsignedShort();
14.73 + for (int i = 0; i < attributes_count; i++) {
14.74 + int attr_name_index=in.readUnsignedShort();
14.75 +
14.76 + readAttr: {
14.77 + if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
14.78 + String attr_name=cls.getString(attr_name_index);
14.79 + if ( attr_name.equals("Code")){
14.80 + readCode (in);
14.81 + AttrData attr=new AttrData(cls);
14.82 + attr.read(attr_name_index);
14.83 + attrs.addElement(attr);
14.84 + break readAttr;
14.85 + } else if ( attr_name.equals("Exceptions")){
14.86 + readExceptions(in);
14.87 + AttrData attr=new AttrData(cls);
14.88 + attr.read(attr_name_index);
14.89 + attrs.addElement(attr);
14.90 + break readAttr;
14.91 + } else if (attr_name.equals("Synthetic")){
14.92 + if (in.readInt()!=0)
14.93 + throw new ClassFormatError("invalid Synthetic attr length");
14.94 + isSynthetic=true;
14.95 + AttrData attr=new AttrData(cls);
14.96 + attr.read(attr_name_index);
14.97 + attrs.addElement(attr);
14.98 + break readAttr;
14.99 + } else if (attr_name.equals("Deprecated")){
14.100 + if (in.readInt()!=0)
14.101 + throw new ClassFormatError("invalid Synthetic attr length");
14.102 + isDeprecated = true;
14.103 + AttrData attr=new AttrData(cls);
14.104 + attr.read(attr_name_index);
14.105 + attrs.addElement(attr);
14.106 + break readAttr;
14.107 + }
14.108 + }
14.109 + AttrData attr=new AttrData(cls);
14.110 + attr.read(attr_name_index, in);
14.111 + attrs.addElement(attr);
14.112 + }
14.113 + }
14.114 + }
14.115 +
14.116 + /**
14.117 + * Read code attribute info.
14.118 + */
14.119 + public void readCode(DataInputStream in) throws IOException {
14.120 +
14.121 + int attr_length = in.readInt();
14.122 + max_stack=in.readUnsignedShort();
14.123 + max_locals=in.readUnsignedShort();
14.124 + int codelen=in.readInt();
14.125 +
14.126 + code=new byte[codelen];
14.127 + int totalread = 0;
14.128 + while(totalread < codelen){
14.129 + totalread += in.read(code, totalread, codelen-totalread);
14.130 + }
14.131 + // in.read(code, 0, codelen);
14.132 + int clen = 0;
14.133 + readExceptionTable(in);
14.134 + int code_attributes_count = in.readUnsignedShort();
14.135 +
14.136 + for (int k = 0 ; k < code_attributes_count ; k++) {
14.137 + int table_name_index=in.readUnsignedShort();
14.138 + int table_name_tag=cls.getTag(table_name_index);
14.139 + AttrData attr=new AttrData(cls);
14.140 + if (table_name_tag==CONSTANT_UTF8) {
14.141 + String table_name_tstr=cls.getString(table_name_index);
14.142 + if (table_name_tstr.equals("LineNumberTable")) {
14.143 + readLineNumTable(in);
14.144 + attr.read(table_name_index);
14.145 + } else if (table_name_tstr.equals("LocalVariableTable")) {
14.146 + readLocVarTable(in);
14.147 + attr.read(table_name_index);
14.148 + } else if (table_name_tstr.equals("StackMapTable")) {
14.149 + readStackMapTable(in);
14.150 + attr.read(table_name_index);
14.151 + } else if (table_name_tstr.equals("StackMap")) {
14.152 + readStackMap(in);
14.153 + attr.read(table_name_index);
14.154 + } else {
14.155 + attr.read(table_name_index, in);
14.156 + }
14.157 + code_attrs.addElement(attr);
14.158 + continue;
14.159 + }
14.160 +
14.161 + attr.read(table_name_index, in);
14.162 + code_attrs.addElement(attr);
14.163 + }
14.164 + }
14.165 +
14.166 + /**
14.167 + * Read exception table info.
14.168 + */
14.169 + void readExceptionTable (DataInputStream in) throws IOException {
14.170 + int exception_table_len=in.readUnsignedShort();
14.171 + exception_table=new Vector(exception_table_len);
14.172 + for (int l = 0; l < exception_table_len; l++) {
14.173 + exception_table.addElement(new TrapData(in, l));
14.174 + }
14.175 + }
14.176 +
14.177 + /**
14.178 + * Read LineNumberTable attribute info.
14.179 + */
14.180 + void readLineNumTable (DataInputStream in) throws IOException {
14.181 + int attr_len = in.readInt(); // attr_length
14.182 + int lin_num_tb_len = in.readUnsignedShort();
14.183 + lin_num_tb=new Vector(lin_num_tb_len);
14.184 + for (int l = 0; l < lin_num_tb_len; l++) {
14.185 + lin_num_tb.addElement(new LineNumData(in));
14.186 + }
14.187 + }
14.188 +
14.189 + /**
14.190 + * Read LocalVariableTable attribute info.
14.191 + */
14.192 + void readLocVarTable (DataInputStream in) throws IOException {
14.193 + int attr_len=in.readInt(); // attr_length
14.194 + int loc_var_tb_len = in.readUnsignedShort();
14.195 + loc_var_tb = new Vector(loc_var_tb_len);
14.196 + for (int l = 0; l < loc_var_tb_len; l++) {
14.197 + loc_var_tb.addElement(new LocVarData(in));
14.198 + }
14.199 + }
14.200 +
14.201 + /**
14.202 + * Read Exception attribute info.
14.203 + */
14.204 + public void readExceptions(DataInputStream in) throws IOException {
14.205 + int attr_len=in.readInt(); // attr_length in prog
14.206 + int num_exceptions = in.readUnsignedShort();
14.207 + exc_index_table=new int[num_exceptions];
14.208 + for (int l = 0; l < num_exceptions; l++) {
14.209 + int exc=in.readShort();
14.210 + exc_index_table[l]=exc;
14.211 + }
14.212 + }
14.213 +
14.214 + /**
14.215 + * Read StackMapTable attribute info.
14.216 + */
14.217 + void readStackMapTable(DataInputStream in) throws IOException {
14.218 + int attr_len = in.readInt(); //attr_length
14.219 + int stack_map_tb_len = in.readUnsignedShort();
14.220 + stackMapTable = new StackMapTableData[stack_map_tb_len];
14.221 + for (int i=0; i<stack_map_tb_len; i++) {
14.222 + stackMapTable[i] = StackMapTableData.getInstance(in, this);
14.223 + }
14.224 + }
14.225 +
14.226 + /**
14.227 + * Read StackMap attribute info.
14.228 + */
14.229 + void readStackMap(DataInputStream in) throws IOException {
14.230 + int attr_len = in.readInt(); //attr_length
14.231 + int stack_map_len = in.readUnsignedShort();
14.232 + stackMap = new StackMapData[stack_map_len];
14.233 + for (int i = 0; i<stack_map_len; i++) {
14.234 + stackMap[i] = new StackMapData(in, this);
14.235 + }
14.236 + }
14.237 +
14.238 + /**
14.239 + * Return access of the method.
14.240 + */
14.241 + public String[] getAccess(){
14.242 +
14.243 + Vector v = new Vector();
14.244 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
14.245 + if ((access & ACC_PRIVATE) !=0) v.addElement("private");
14.246 + if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
14.247 + if ((access & ACC_STATIC) !=0) v.addElement("static");
14.248 + if ((access & ACC_FINAL) !=0) v.addElement("final");
14.249 + if ((access & ACC_SYNCHRONIZED) !=0) v.addElement("synchronized");
14.250 + if ((access & ACC_NATIVE) !=0) v.addElement("native");
14.251 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
14.252 + if ((access & ACC_STRICT) !=0) v.addElement("strictfp");
14.253 +
14.254 + String[] accflags = new String[v.size()];
14.255 + v.copyInto(accflags);
14.256 + return accflags;
14.257 + }
14.258 +
14.259 + /**
14.260 + * Return name of the method.
14.261 + */
14.262 + public String getName(){
14.263 + return cls.getStringValue(name_index);
14.264 + }
14.265 +
14.266 + /**
14.267 + * Return internal siganature of the method.
14.268 + */
14.269 + public String getInternalSig(){
14.270 + return cls.getStringValue(descriptor_index);
14.271 + }
14.272 +
14.273 + /**
14.274 + * Return java return type signature of method.
14.275 + */
14.276 + public String getReturnType(){
14.277 +
14.278 + String rttype = (new TypeSignature(getInternalSig())).getReturnType();
14.279 + return rttype;
14.280 + }
14.281 +
14.282 + /**
14.283 + * Return java type parameter signature.
14.284 + */
14.285 + public String getParameters(){
14.286 + String ptype = (new TypeSignature(getInternalSig())).getParameters();
14.287 +
14.288 + return ptype;
14.289 + }
14.290 +
14.291 + /**
14.292 + * Return code attribute data of a method.
14.293 + */
14.294 + public byte[] getCode(){
14.295 + return code;
14.296 + }
14.297 +
14.298 + /**
14.299 + * Return LineNumberTable size.
14.300 + */
14.301 + public int getnumlines(){
14.302 + return lin_num_tb.size();
14.303 + }
14.304 +
14.305 + /**
14.306 + * Return LineNumberTable
14.307 + */
14.308 + public Vector getlin_num_tb(){
14.309 + return lin_num_tb;
14.310 + }
14.311 +
14.312 + /**
14.313 + * Return LocalVariableTable size.
14.314 + */
14.315 + public int getloc_var_tbsize(){
14.316 + return loc_var_tb.size();
14.317 + }
14.318 +
14.319 +
14.320 + /**
14.321 + * Return LocalVariableTable.
14.322 + */
14.323 + public Vector getloc_var_tb(){
14.324 + return loc_var_tb;
14.325 + }
14.326 +
14.327 + /**
14.328 + * Return StackMap.
14.329 + */
14.330 + public StackMapData[] getStackMap() {
14.331 + return stackMap;
14.332 + }
14.333 +
14.334 + /**
14.335 + * Return StackMapTable.
14.336 + */
14.337 + public StackMapTableData[] getStackMapTable() {
14.338 + return stackMapTable;
14.339 + }
14.340 +
14.341 + /**
14.342 + * Return number of arguments of that method.
14.343 + */
14.344 + public int getArgumentlength(){
14.345 + return new TypeSignature(getInternalSig()).getArgumentlength();
14.346 + }
14.347 +
14.348 + /**
14.349 + * Return true if method is static
14.350 + */
14.351 + public boolean isStatic(){
14.352 + if ((access & ACC_STATIC) !=0) return true;
14.353 + return false;
14.354 + }
14.355 +
14.356 +
14.357 + /**
14.358 + * Return max depth of operand stack.
14.359 + */
14.360 + public int getMaxStack(){
14.361 + return max_stack;
14.362 + }
14.363 +
14.364 +
14.365 + /**
14.366 + * Return number of local variables.
14.367 + */
14.368 + public int getMaxLocals(){
14.369 + return max_locals;
14.370 + }
14.371 +
14.372 +
14.373 + /**
14.374 + * Return exception index table in Exception attribute.
14.375 + */
14.376 + public int []get_exc_index_table(){
14.377 + return exc_index_table;
14.378 + }
14.379 +
14.380 +
14.381 + /**
14.382 + * Return exception table in code attributre.
14.383 + */
14.384 + public Vector getexception_table(){
14.385 + return exception_table;
14.386 + }
14.387 +
14.388 +
14.389 + /**
14.390 + * Return method attributes.
14.391 + */
14.392 + public Vector getAttributes(){
14.393 + return attrs;
14.394 + }
14.395 +
14.396 +
14.397 + /**
14.398 + * Return code attributes.
14.399 + */
14.400 + public Vector getCodeAttributes(){
14.401 + return code_attrs;
14.402 + }
14.403 +
14.404 +
14.405 + /**
14.406 + * Return true if method id synthetic.
14.407 + */
14.408 + public boolean isSynthetic(){
14.409 + return isSynthetic;
14.410 + }
14.411 +
14.412 +
14.413 + /**
14.414 + * Return true if method is deprecated.
14.415 + */
14.416 + public boolean isDeprecated(){
14.417 + return isDeprecated;
14.418 + }
14.419 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/javap/src/main/java/sun/tools/javap/RuntimeConstants.java Fri Nov 09 21:33:22 2012 +0100
15.3 @@ -0,0 +1,787 @@
15.4 +/*
15.5 + * Copyright (c) 2002, 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 sun.tools.javap;
15.31 +
15.32 +public interface RuntimeConstants {
15.33 +
15.34 + /* Signature Characters */
15.35 + public static final char SIGC_VOID = 'V';
15.36 + public static final String SIG_VOID = "V";
15.37 + public static final char SIGC_BOOLEAN = 'Z';
15.38 + public static final String SIG_BOOLEAN = "Z";
15.39 + public static final char SIGC_BYTE = 'B';
15.40 + public static final String SIG_BYTE = "B";
15.41 + public static final char SIGC_CHAR = 'C';
15.42 + public static final String SIG_CHAR = "C";
15.43 + public static final char SIGC_SHORT = 'S';
15.44 + public static final String SIG_SHORT = "S";
15.45 + public static final char SIGC_INT = 'I';
15.46 + public static final String SIG_INT = "I";
15.47 + public static final char SIGC_LONG = 'J';
15.48 + public static final String SIG_LONG = "J";
15.49 + public static final char SIGC_FLOAT = 'F';
15.50 + public static final String SIG_FLOAT = "F";
15.51 + public static final char SIGC_DOUBLE = 'D';
15.52 + public static final String SIG_DOUBLE = "D";
15.53 + public static final char SIGC_ARRAY = '[';
15.54 + public static final String SIG_ARRAY = "[";
15.55 + public static final char SIGC_CLASS = 'L';
15.56 + public static final String SIG_CLASS = "L";
15.57 + public static final char SIGC_METHOD = '(';
15.58 + public static final String SIG_METHOD = "(";
15.59 + public static final char SIGC_ENDCLASS = ';';
15.60 + public static final String SIG_ENDCLASS = ";";
15.61 + public static final char SIGC_ENDMETHOD = ')';
15.62 + public static final String SIG_ENDMETHOD = ")";
15.63 + public static final char SIGC_PACKAGE = '/';
15.64 + public static final String SIG_PACKAGE = "/";
15.65 +
15.66 + /* Class File Constants */
15.67 + public static final int JAVA_MAGIC = 0xcafebabe;
15.68 + public static final int JAVA_VERSION = 45;
15.69 + public static final int JAVA_MINOR_VERSION = 3;
15.70 +
15.71 + /* Constant table */
15.72 + public static final int CONSTANT_UTF8 = 1;
15.73 + public static final int CONSTANT_UNICODE = 2;
15.74 + public static final int CONSTANT_INTEGER = 3;
15.75 + public static final int CONSTANT_FLOAT = 4;
15.76 + public static final int CONSTANT_LONG = 5;
15.77 + public static final int CONSTANT_DOUBLE = 6;
15.78 + public static final int CONSTANT_CLASS = 7;
15.79 + public static final int CONSTANT_STRING = 8;
15.80 + public static final int CONSTANT_FIELD = 9;
15.81 + public static final int CONSTANT_METHOD = 10;
15.82 + public static final int CONSTANT_INTERFACEMETHOD = 11;
15.83 + public static final int CONSTANT_NAMEANDTYPE = 12;
15.84 +
15.85 + /* Access Flags */
15.86 + public static final int ACC_PUBLIC = 0x00000001;
15.87 + public static final int ACC_PRIVATE = 0x00000002;
15.88 + public static final int ACC_PROTECTED = 0x00000004;
15.89 + public static final int ACC_STATIC = 0x00000008;
15.90 + public static final int ACC_FINAL = 0x00000010;
15.91 + public static final int ACC_SYNCHRONIZED = 0x00000020;
15.92 + public static final int ACC_SUPER = 0x00000020;
15.93 + public static final int ACC_VOLATILE = 0x00000040;
15.94 + public static final int ACC_TRANSIENT = 0x00000080;
15.95 + public static final int ACC_NATIVE = 0x00000100;
15.96 + public static final int ACC_INTERFACE = 0x00000200;
15.97 + public static final int ACC_ABSTRACT = 0x00000400;
15.98 + public static final int ACC_STRICT = 0x00000800;
15.99 + public static final int ACC_EXPLICIT = 0x00001000;
15.100 + public static final int ACC_SYNTHETIC = 0x00010000; // actually, this is an attribute
15.101 +
15.102 + /* Type codes */
15.103 + public static final int T_CLASS = 0x00000002;
15.104 + public static final int T_BOOLEAN = 0x00000004;
15.105 + public static final int T_CHAR = 0x00000005;
15.106 + public static final int T_FLOAT = 0x00000006;
15.107 + public static final int T_DOUBLE = 0x00000007;
15.108 + public static final int T_BYTE = 0x00000008;
15.109 + public static final int T_SHORT = 0x00000009;
15.110 + public static final int T_INT = 0x0000000a;
15.111 + public static final int T_LONG = 0x0000000b;
15.112 +
15.113 + /* Type codes for StackMap attribute */
15.114 + public static final int ITEM_Bogus =0; // an unknown or uninitialized value
15.115 + public static final int ITEM_Integer =1; // a 32-bit integer
15.116 + public static final int ITEM_Float =2; // not used
15.117 + public static final int ITEM_Double =3; // not used
15.118 + public static final int ITEM_Long =4; // a 64-bit integer
15.119 + public static final int ITEM_Null =5; // the type of null
15.120 + public static final int ITEM_InitObject =6; // "this" in constructor
15.121 + public static final int ITEM_Object =7; // followed by 2-byte index of class name
15.122 + public static final int ITEM_NewObject =8; // followed by 2-byte ref to "new"
15.123 +
15.124 + /* Constants used in StackMapTable attribute */
15.125 + public static final int SAME_FRAME_BOUND = 64;
15.126 + public static final int SAME_LOCALS_1_STACK_ITEM_BOUND = 128;
15.127 + public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
15.128 + public static final int SAME_FRAME_EXTENDED = 251;
15.129 + public static final int FULL_FRAME = 255;
15.130 +
15.131 + /* Opcodes */
15.132 + public static final int opc_dead = -2;
15.133 + public static final int opc_label = -1;
15.134 + public static final int opc_nop = 0;
15.135 + public static final int opc_aconst_null = 1;
15.136 + public static final int opc_iconst_m1 = 2;
15.137 + public static final int opc_iconst_0 = 3;
15.138 + public static final int opc_iconst_1 = 4;
15.139 + public static final int opc_iconst_2 = 5;
15.140 + public static final int opc_iconst_3 = 6;
15.141 + public static final int opc_iconst_4 = 7;
15.142 + public static final int opc_iconst_5 = 8;
15.143 + public static final int opc_lconst_0 = 9;
15.144 + public static final int opc_lconst_1 = 10;
15.145 + public static final int opc_fconst_0 = 11;
15.146 + public static final int opc_fconst_1 = 12;
15.147 + public static final int opc_fconst_2 = 13;
15.148 + public static final int opc_dconst_0 = 14;
15.149 + public static final int opc_dconst_1 = 15;
15.150 + public static final int opc_bipush = 16;
15.151 + public static final int opc_sipush = 17;
15.152 + public static final int opc_ldc = 18;
15.153 + public static final int opc_ldc_w = 19;
15.154 + public static final int opc_ldc2_w = 20;
15.155 + public static final int opc_iload = 21;
15.156 + public static final int opc_lload = 22;
15.157 + public static final int opc_fload = 23;
15.158 + public static final int opc_dload = 24;
15.159 + public static final int opc_aload = 25;
15.160 + public static final int opc_iload_0 = 26;
15.161 + public static final int opc_iload_1 = 27;
15.162 + public static final int opc_iload_2 = 28;
15.163 + public static final int opc_iload_3 = 29;
15.164 + public static final int opc_lload_0 = 30;
15.165 + public static final int opc_lload_1 = 31;
15.166 + public static final int opc_lload_2 = 32;
15.167 + public static final int opc_lload_3 = 33;
15.168 + public static final int opc_fload_0 = 34;
15.169 + public static final int opc_fload_1 = 35;
15.170 + public static final int opc_fload_2 = 36;
15.171 + public static final int opc_fload_3 = 37;
15.172 + public static final int opc_dload_0 = 38;
15.173 + public static final int opc_dload_1 = 39;
15.174 + public static final int opc_dload_2 = 40;
15.175 + public static final int opc_dload_3 = 41;
15.176 + public static final int opc_aload_0 = 42;
15.177 + public static final int opc_aload_1 = 43;
15.178 + public static final int opc_aload_2 = 44;
15.179 + public static final int opc_aload_3 = 45;
15.180 + public static final int opc_iaload = 46;
15.181 + public static final int opc_laload = 47;
15.182 + public static final int opc_faload = 48;
15.183 + public static final int opc_daload = 49;
15.184 + public static final int opc_aaload = 50;
15.185 + public static final int opc_baload = 51;
15.186 + public static final int opc_caload = 52;
15.187 + public static final int opc_saload = 53;
15.188 + public static final int opc_istore = 54;
15.189 + public static final int opc_lstore = 55;
15.190 + public static final int opc_fstore = 56;
15.191 + public static final int opc_dstore = 57;
15.192 + public static final int opc_astore = 58;
15.193 + public static final int opc_istore_0 = 59;
15.194 + public static final int opc_istore_1 = 60;
15.195 + public static final int opc_istore_2 = 61;
15.196 + public static final int opc_istore_3 = 62;
15.197 + public static final int opc_lstore_0 = 63;
15.198 + public static final int opc_lstore_1 = 64;
15.199 + public static final int opc_lstore_2 = 65;
15.200 + public static final int opc_lstore_3 = 66;
15.201 + public static final int opc_fstore_0 = 67;
15.202 + public static final int opc_fstore_1 = 68;
15.203 + public static final int opc_fstore_2 = 69;
15.204 + public static final int opc_fstore_3 = 70;
15.205 + public static final int opc_dstore_0 = 71;
15.206 + public static final int opc_dstore_1 = 72;
15.207 + public static final int opc_dstore_2 = 73;
15.208 + public static final int opc_dstore_3 = 74;
15.209 + public static final int opc_astore_0 = 75;
15.210 + public static final int opc_astore_1 = 76;
15.211 + public static final int opc_astore_2 = 77;
15.212 + public static final int opc_astore_3 = 78;
15.213 + public static final int opc_iastore = 79;
15.214 + public static final int opc_lastore = 80;
15.215 + public static final int opc_fastore = 81;
15.216 + public static final int opc_dastore = 82;
15.217 + public static final int opc_aastore = 83;
15.218 + public static final int opc_bastore = 84;
15.219 + public static final int opc_castore = 85;
15.220 + public static final int opc_sastore = 86;
15.221 + public static final int opc_pop = 87;
15.222 + public static final int opc_pop2 = 88;
15.223 + public static final int opc_dup = 89;
15.224 + public static final int opc_dup_x1 = 90;
15.225 + public static final int opc_dup_x2 = 91;
15.226 + public static final int opc_dup2 = 92;
15.227 + public static final int opc_dup2_x1 = 93;
15.228 + public static final int opc_dup2_x2 = 94;
15.229 + public static final int opc_swap = 95;
15.230 + public static final int opc_iadd = 96;
15.231 + public static final int opc_ladd = 97;
15.232 + public static final int opc_fadd = 98;
15.233 + public static final int opc_dadd = 99;
15.234 + public static final int opc_isub = 100;
15.235 + public static final int opc_lsub = 101;
15.236 + public static final int opc_fsub = 102;
15.237 + public static final int opc_dsub = 103;
15.238 + public static final int opc_imul = 104;
15.239 + public static final int opc_lmul = 105;
15.240 + public static final int opc_fmul = 106;
15.241 + public static final int opc_dmul = 107;
15.242 + public static final int opc_idiv = 108;
15.243 + public static final int opc_ldiv = 109;
15.244 + public static final int opc_fdiv = 110;
15.245 + public static final int opc_ddiv = 111;
15.246 + public static final int opc_irem = 112;
15.247 + public static final int opc_lrem = 113;
15.248 + public static final int opc_frem = 114;
15.249 + public static final int opc_drem = 115;
15.250 + public static final int opc_ineg = 116;
15.251 + public static final int opc_lneg = 117;
15.252 + public static final int opc_fneg = 118;
15.253 + public static final int opc_dneg = 119;
15.254 + public static final int opc_ishl = 120;
15.255 + public static final int opc_lshl = 121;
15.256 + public static final int opc_ishr = 122;
15.257 + public static final int opc_lshr = 123;
15.258 + public static final int opc_iushr = 124;
15.259 + public static final int opc_lushr = 125;
15.260 + public static final int opc_iand = 126;
15.261 + public static final int opc_land = 127;
15.262 + public static final int opc_ior = 128;
15.263 + public static final int opc_lor = 129;
15.264 + public static final int opc_ixor = 130;
15.265 + public static final int opc_lxor = 131;
15.266 + public static final int opc_iinc = 132;
15.267 + public static final int opc_i2l = 133;
15.268 + public static final int opc_i2f = 134;
15.269 + public static final int opc_i2d = 135;
15.270 + public static final int opc_l2i = 136;
15.271 + public static final int opc_l2f = 137;
15.272 + public static final int opc_l2d = 138;
15.273 + public static final int opc_f2i = 139;
15.274 + public static final int opc_f2l = 140;
15.275 + public static final int opc_f2d = 141;
15.276 + public static final int opc_d2i = 142;
15.277 + public static final int opc_d2l = 143;
15.278 + public static final int opc_d2f = 144;
15.279 + public static final int opc_i2b = 145;
15.280 + public static final int opc_int2byte = 145;
15.281 + public static final int opc_i2c = 146;
15.282 + public static final int opc_int2char = 146;
15.283 + public static final int opc_i2s = 147;
15.284 + public static final int opc_int2short = 147;
15.285 + public static final int opc_lcmp = 148;
15.286 + public static final int opc_fcmpl = 149;
15.287 + public static final int opc_fcmpg = 150;
15.288 + public static final int opc_dcmpl = 151;
15.289 + public static final int opc_dcmpg = 152;
15.290 + public static final int opc_ifeq = 153;
15.291 + public static final int opc_ifne = 154;
15.292 + public static final int opc_iflt = 155;
15.293 + public static final int opc_ifge = 156;
15.294 + public static final int opc_ifgt = 157;
15.295 + public static final int opc_ifle = 158;
15.296 + public static final int opc_if_icmpeq = 159;
15.297 + public static final int opc_if_icmpne = 160;
15.298 + public static final int opc_if_icmplt = 161;
15.299 + public static final int opc_if_icmpge = 162;
15.300 + public static final int opc_if_icmpgt = 163;
15.301 + public static final int opc_if_icmple = 164;
15.302 + public static final int opc_if_acmpeq = 165;
15.303 + public static final int opc_if_acmpne = 166;
15.304 + public static final int opc_goto = 167;
15.305 + public static final int opc_jsr = 168;
15.306 + public static final int opc_ret = 169;
15.307 + public static final int opc_tableswitch = 170;
15.308 + public static final int opc_lookupswitch = 171;
15.309 + public static final int opc_ireturn = 172;
15.310 + public static final int opc_lreturn = 173;
15.311 + public static final int opc_freturn = 174;
15.312 + public static final int opc_dreturn = 175;
15.313 + public static final int opc_areturn = 176;
15.314 + public static final int opc_return = 177;
15.315 + public static final int opc_getstatic = 178;
15.316 + public static final int opc_putstatic = 179;
15.317 + public static final int opc_getfield = 180;
15.318 + public static final int opc_putfield = 181;
15.319 + public static final int opc_invokevirtual = 182;
15.320 + public static final int opc_invokenonvirtual = 183;
15.321 + public static final int opc_invokespecial = 183;
15.322 + public static final int opc_invokestatic = 184;
15.323 + public static final int opc_invokeinterface = 185;
15.324 +// public static final int opc_xxxunusedxxx = 186;
15.325 + public static final int opc_new = 187;
15.326 + public static final int opc_newarray = 188;
15.327 + public static final int opc_anewarray = 189;
15.328 + public static final int opc_arraylength = 190;
15.329 + public static final int opc_athrow = 191;
15.330 + public static final int opc_checkcast = 192;
15.331 + public static final int opc_instanceof = 193;
15.332 + public static final int opc_monitorenter = 194;
15.333 + public static final int opc_monitorexit = 195;
15.334 + public static final int opc_wide = 196;
15.335 + public static final int opc_multianewarray = 197;
15.336 + public static final int opc_ifnull = 198;
15.337 + public static final int opc_ifnonnull = 199;
15.338 + public static final int opc_goto_w = 200;
15.339 + public static final int opc_jsr_w = 201;
15.340 + /* Pseudo-instructions */
15.341 + public static final int opc_bytecode = 203;
15.342 + public static final int opc_try = 204;
15.343 + public static final int opc_endtry = 205;
15.344 + public static final int opc_catch = 206;
15.345 + public static final int opc_var = 207;
15.346 + public static final int opc_endvar = 208;
15.347 + public static final int opc_localsmap = 209;
15.348 + public static final int opc_stackmap = 210;
15.349 + /* PicoJava prefixes */
15.350 + public static final int opc_nonpriv = 254;
15.351 + public static final int opc_priv = 255;
15.352 +
15.353 + /* Wide instructions */
15.354 + public static final int opc_iload_w = (opc_wide<<8)|opc_iload;
15.355 + public static final int opc_lload_w = (opc_wide<<8)|opc_lload;
15.356 + public static final int opc_fload_w = (opc_wide<<8)|opc_fload;
15.357 + public static final int opc_dload_w = (opc_wide<<8)|opc_dload;
15.358 + public static final int opc_aload_w = (opc_wide<<8)|opc_aload;
15.359 + public static final int opc_istore_w = (opc_wide<<8)|opc_istore;
15.360 + public static final int opc_lstore_w = (opc_wide<<8)|opc_lstore;
15.361 + public static final int opc_fstore_w = (opc_wide<<8)|opc_fstore;
15.362 + public static final int opc_dstore_w = (opc_wide<<8)|opc_dstore;
15.363 + public static final int opc_astore_w = (opc_wide<<8)|opc_astore;
15.364 + public static final int opc_ret_w = (opc_wide<<8)|opc_ret;
15.365 + public static final int opc_iinc_w = (opc_wide<<8)|opc_iinc;
15.366 +
15.367 + /* Opcode Names */
15.368 + public static final String opcNamesTab[] = {
15.369 + "nop",
15.370 + "aconst_null",
15.371 + "iconst_m1",
15.372 + "iconst_0",
15.373 + "iconst_1",
15.374 + "iconst_2",
15.375 + "iconst_3",
15.376 + "iconst_4",
15.377 + "iconst_5",
15.378 + "lconst_0",
15.379 + "lconst_1",
15.380 + "fconst_0",
15.381 + "fconst_1",
15.382 + "fconst_2",
15.383 + "dconst_0",
15.384 + "dconst_1",
15.385 + "bipush",
15.386 + "sipush",
15.387 + "ldc",
15.388 + "ldc_w",
15.389 + "ldc2_w",
15.390 + "iload",
15.391 + "lload",
15.392 + "fload",
15.393 + "dload",
15.394 + "aload",
15.395 + "iload_0",
15.396 + "iload_1",
15.397 + "iload_2",
15.398 + "iload_3",
15.399 + "lload_0",
15.400 + "lload_1",
15.401 + "lload_2",
15.402 + "lload_3",
15.403 + "fload_0",
15.404 + "fload_1",
15.405 + "fload_2",
15.406 + "fload_3",
15.407 + "dload_0",
15.408 + "dload_1",
15.409 + "dload_2",
15.410 + "dload_3",
15.411 + "aload_0",
15.412 + "aload_1",
15.413 + "aload_2",
15.414 + "aload_3",
15.415 + "iaload",
15.416 + "laload",
15.417 + "faload",
15.418 + "daload",
15.419 + "aaload",
15.420 + "baload",
15.421 + "caload",
15.422 + "saload",
15.423 + "istore",
15.424 + "lstore",
15.425 + "fstore",
15.426 + "dstore",
15.427 + "astore",
15.428 + "istore_0",
15.429 + "istore_1",
15.430 + "istore_2",
15.431 + "istore_3",
15.432 + "lstore_0",
15.433 + "lstore_1",
15.434 + "lstore_2",
15.435 + "lstore_3",
15.436 + "fstore_0",
15.437 + "fstore_1",
15.438 + "fstore_2",
15.439 + "fstore_3",
15.440 + "dstore_0",
15.441 + "dstore_1",
15.442 + "dstore_2",
15.443 + "dstore_3",
15.444 + "astore_0",
15.445 + "astore_1",
15.446 + "astore_2",
15.447 + "astore_3",
15.448 + "iastore",
15.449 + "lastore",
15.450 + "fastore",
15.451 + "dastore",
15.452 + "aastore",
15.453 + "bastore",
15.454 + "castore",
15.455 + "sastore",
15.456 + "pop",
15.457 + "pop2",
15.458 + "dup",
15.459 + "dup_x1",
15.460 + "dup_x2",
15.461 + "dup2",
15.462 + "dup2_x1",
15.463 + "dup2_x2",
15.464 + "swap",
15.465 + "iadd",
15.466 + "ladd",
15.467 + "fadd",
15.468 + "dadd",
15.469 + "isub",
15.470 + "lsub",
15.471 + "fsub",
15.472 + "dsub",
15.473 + "imul",
15.474 + "lmul",
15.475 + "fmul",
15.476 + "dmul",
15.477 + "idiv",
15.478 + "ldiv",
15.479 + "fdiv",
15.480 + "ddiv",
15.481 + "irem",
15.482 + "lrem",
15.483 + "frem",
15.484 + "drem",
15.485 + "ineg",
15.486 + "lneg",
15.487 + "fneg",
15.488 + "dneg",
15.489 + "ishl",
15.490 + "lshl",
15.491 + "ishr",
15.492 + "lshr",
15.493 + "iushr",
15.494 + "lushr",
15.495 + "iand",
15.496 + "land",
15.497 + "ior",
15.498 + "lor",
15.499 + "ixor",
15.500 + "lxor",
15.501 + "iinc",
15.502 + "i2l",
15.503 + "i2f",
15.504 + "i2d",
15.505 + "l2i",
15.506 + "l2f",
15.507 + "l2d",
15.508 + "f2i",
15.509 + "f2l",
15.510 + "f2d",
15.511 + "d2i",
15.512 + "d2l",
15.513 + "d2f",
15.514 + "i2b",
15.515 + "i2c",
15.516 + "i2s",
15.517 + "lcmp",
15.518 + "fcmpl",
15.519 + "fcmpg",
15.520 + "dcmpl",
15.521 + "dcmpg",
15.522 + "ifeq",
15.523 + "ifne",
15.524 + "iflt",
15.525 + "ifge",
15.526 + "ifgt",
15.527 + "ifle",
15.528 + "if_icmpeq",
15.529 + "if_icmpne",
15.530 + "if_icmplt",
15.531 + "if_icmpge",
15.532 + "if_icmpgt",
15.533 + "if_icmple",
15.534 + "if_acmpeq",
15.535 + "if_acmpne",
15.536 + "goto",
15.537 + "jsr",
15.538 + "ret",
15.539 + "tableswitch",
15.540 + "lookupswitch",
15.541 + "ireturn",
15.542 + "lreturn",
15.543 + "freturn",
15.544 + "dreturn",
15.545 + "areturn",
15.546 + "return",
15.547 + "getstatic",
15.548 + "putstatic",
15.549 + "getfield",
15.550 + "putfield",
15.551 + "invokevirtual",
15.552 + "invokespecial", // was "invokenonvirtual",
15.553 + "invokestatic",
15.554 + "invokeinterface",
15.555 + "bytecode 186", //"xxxunusedxxx",
15.556 + "new",
15.557 + "newarray",
15.558 + "anewarray",
15.559 + "arraylength",
15.560 + "athrow",
15.561 + "checkcast",
15.562 + "instanceof",
15.563 + "monitorenter",
15.564 + "monitorexit",
15.565 + null, // "wide",
15.566 + "multianewarray",
15.567 + "ifnull",
15.568 + "ifnonnull",
15.569 + "goto_w",
15.570 + "jsr_w",
15.571 + "bytecode 202", // "breakpoint",
15.572 + "bytecode",
15.573 + "try",
15.574 + "endtry",
15.575 + "catch",
15.576 + "var",
15.577 + "endvar",
15.578 + "locals_map",
15.579 + "stack_map"
15.580 + };
15.581 +
15.582 + /* Opcode Lengths */
15.583 + public static final int opcLengthsTab[] = {
15.584 + 1,
15.585 + 1,
15.586 + 1,
15.587 + 1,
15.588 + 1,
15.589 + 1,
15.590 + 1,
15.591 + 1,
15.592 + 1,
15.593 + 1,
15.594 + 1,
15.595 + 1,
15.596 + 1,
15.597 + 1,
15.598 + 1,
15.599 + 1,
15.600 + 2,
15.601 + 3,
15.602 + 2,
15.603 + 3,
15.604 + 3,
15.605 + 2,
15.606 + 2,
15.607 + 2,
15.608 + 2,
15.609 + 2,
15.610 + 1,
15.611 + 1,
15.612 + 1,
15.613 + 1,
15.614 + 1,
15.615 + 1,
15.616 + 1,
15.617 + 1,
15.618 + 1,
15.619 + 1,
15.620 + 1,
15.621 + 1,
15.622 + 1,
15.623 + 1,
15.624 + 1,
15.625 + 1,
15.626 + 1,
15.627 + 1,
15.628 + 1,
15.629 + 1,
15.630 + 1,
15.631 + 1,
15.632 + 1,
15.633 + 1,
15.634 + 1,
15.635 + 1,
15.636 + 1,
15.637 + 1,
15.638 + 2,
15.639 + 2,
15.640 + 2,
15.641 + 2,
15.642 + 2,
15.643 + 1,
15.644 + 1,
15.645 + 1,
15.646 + 1,
15.647 + 1,
15.648 + 1,
15.649 + 1,
15.650 + 1,
15.651 + 1,
15.652 + 1,
15.653 + 1,
15.654 + 1,
15.655 + 1,
15.656 + 1,
15.657 + 1,
15.658 + 1,
15.659 + 1,
15.660 + 1,
15.661 + 1,
15.662 + 1,
15.663 + 1,
15.664 + 1,
15.665 + 1,
15.666 + 1,
15.667 + 1,
15.668 + 1,
15.669 + 1,
15.670 + 1,
15.671 + 1,
15.672 + 1,
15.673 + 1,
15.674 + 1,
15.675 + 1,
15.676 + 1,
15.677 + 1,
15.678 + 1,
15.679 + 1,
15.680 + 1,
15.681 + 1,
15.682 + 1,
15.683 + 1,
15.684 + 1,
15.685 + 1,
15.686 + 1,
15.687 + 1,
15.688 + 1,
15.689 + 1,
15.690 + 1,
15.691 + 1,
15.692 + 1,
15.693 + 1,
15.694 + 1,
15.695 + 1,
15.696 + 1,
15.697 + 1,
15.698 + 1,
15.699 + 1,
15.700 + 1,
15.701 + 1,
15.702 + 1,
15.703 + 1,
15.704 + 1,
15.705 + 1,
15.706 + 1,
15.707 + 1,
15.708 + 1,
15.709 + 1,
15.710 + 1,
15.711 + 1,
15.712 + 1,
15.713 + 1,
15.714 + 1,
15.715 + 1,
15.716 + 3,
15.717 + 1,
15.718 + 1,
15.719 + 1,
15.720 + 1,
15.721 + 1,
15.722 + 1,
15.723 + 1,
15.724 + 1,
15.725 + 1,
15.726 + 1,
15.727 + 1,
15.728 + 1,
15.729 + 1,
15.730 + 1,
15.731 + 1,
15.732 + 1,
15.733 + 1,
15.734 + 1,
15.735 + 1,
15.736 + 1,
15.737 + 3,
15.738 + 3,
15.739 + 3,
15.740 + 3,
15.741 + 3,
15.742 + 3,
15.743 + 3,
15.744 + 3,
15.745 + 3,
15.746 + 3,
15.747 + 3,
15.748 + 3,
15.749 + 3,
15.750 + 3,
15.751 + 3,
15.752 + 3,
15.753 + 2,
15.754 + 99,
15.755 + 99,
15.756 + 1,
15.757 + 1,
15.758 + 1,
15.759 + 1,
15.760 + 1,
15.761 + 1,
15.762 + 3,
15.763 + 3,
15.764 + 3,
15.765 + 3,
15.766 + 3,
15.767 + 3,
15.768 + 3,
15.769 + 5,
15.770 + 0,
15.771 + 3,
15.772 + 2,
15.773 + 3,
15.774 + 1,
15.775 + 1,
15.776 + 3,
15.777 + 3,
15.778 + 1,
15.779 + 1,
15.780 + 0, // wide
15.781 + 4,
15.782 + 3,
15.783 + 3,
15.784 + 5,
15.785 + 5,
15.786 + 1,
15.787 + 1, 0, 0, 0, 0, 0 // pseudo
15.788 + };
15.789 +
15.790 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/javap/src/main/java/sun/tools/javap/StackMapData.java Fri Nov 09 21:33:22 2012 +0100
16.3 @@ -0,0 +1,76 @@
16.4 +/*
16.5 + * Copyright (c) 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 sun.tools.javap;
16.31 +
16.32 +import java.util.*;
16.33 +import java.io.*;
16.34 +
16.35 +import static sun.tools.javap.RuntimeConstants.*;
16.36 +
16.37 +/* represents one entry of StackMap attribute
16.38 + */
16.39 +class StackMapData {
16.40 + final int offset;
16.41 + final int[] locals;
16.42 + final int[] stack;
16.43 +
16.44 + StackMapData(int offset, int[] locals, int[] stack) {
16.45 + this.offset = offset;
16.46 + this.locals = locals;
16.47 + this.stack = stack;
16.48 + }
16.49 +
16.50 + StackMapData(DataInputStream in, MethodData method) throws IOException {
16.51 + offset = in.readUnsignedShort();
16.52 + int local_size = in.readUnsignedShort();
16.53 + locals = readTypeArray(in, local_size, method);
16.54 + int stack_size = in.readUnsignedShort();
16.55 + stack = readTypeArray(in, stack_size, method);
16.56 + }
16.57 +
16.58 + static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
16.59 + int[] types = new int[length];
16.60 + for (int i=0; i<length; i++) {
16.61 + types[i] = readType(in, method);
16.62 + }
16.63 + return types;
16.64 + }
16.65 +
16.66 + static final int readType(DataInputStream in, MethodData method) throws IOException {
16.67 + int type = in.readUnsignedByte();
16.68 + if (type == ITEM_Object || type == ITEM_NewObject) {
16.69 + type = type | (in.readUnsignedShort()<<8);
16.70 + }
16.71 + return type;
16.72 + }
16.73 +
16.74 + void print(JavapPrinter p) {
16.75 + p.out.println(" " + offset + ":");
16.76 + p.printMap(" locals = [", locals);
16.77 + p.printMap(" stack = [", stack);
16.78 + }
16.79 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/javap/src/main/java/sun/tools/javap/StackMapTableData.java Fri Nov 09 21:33:22 2012 +0100
17.3 @@ -0,0 +1,168 @@
17.4 +/*
17.5 + * Copyright (c) 2005, 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 sun.tools.javap;
17.31 +
17.32 +import java.util.*;
17.33 +import java.io.*;
17.34 +
17.35 +import static sun.tools.javap.RuntimeConstants.*;
17.36 +
17.37 +/* represents one entry of StackMapTable attribute
17.38 + */
17.39 +class StackMapTableData {
17.40 + final int frameType;
17.41 + int offsetDelta;
17.42 +
17.43 + StackMapTableData(int frameType) {
17.44 + this.frameType = frameType;
17.45 + }
17.46 +
17.47 + void print(JavapPrinter p) {
17.48 + p.out.print(" frame_type = " + frameType);
17.49 + }
17.50 +
17.51 + static class SameFrame extends StackMapTableData {
17.52 + SameFrame(int frameType, int offsetDelta) {
17.53 + super(frameType);
17.54 + this.offsetDelta = offsetDelta;
17.55 + }
17.56 + void print(JavapPrinter p) {
17.57 + super.print(p);
17.58 + if (frameType < SAME_FRAME_BOUND) {
17.59 + p.out.println(" /* same */");
17.60 + } else {
17.61 + p.out.println(" /* same_frame_extended */");
17.62 + p.out.println(" offset_delta = " + offsetDelta);
17.63 + }
17.64 + }
17.65 + }
17.66 +
17.67 + static class SameLocals1StackItem extends StackMapTableData {
17.68 + final int[] stack;
17.69 + SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
17.70 + super(frameType);
17.71 + this.offsetDelta = offsetDelta;
17.72 + this.stack = stack;
17.73 + }
17.74 + void print(JavapPrinter p) {
17.75 + super.print(p);
17.76 + if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
17.77 + p.out.println(" /* same_locals_1_stack_item_frame_extended */");
17.78 + p.out.println(" offset_delta = " + offsetDelta);
17.79 + } else {
17.80 + p.out.println(" /* same_locals_1_stack_item */");
17.81 + }
17.82 + p.printMap(" stack = [", stack);
17.83 + }
17.84 + }
17.85 +
17.86 + static class ChopFrame extends StackMapTableData {
17.87 + ChopFrame(int frameType, int offsetDelta) {
17.88 + super(frameType);
17.89 + this.offsetDelta = offsetDelta;
17.90 + }
17.91 + void print(JavapPrinter p) {
17.92 + super.print(p);
17.93 + p.out.println(" /* chop */");
17.94 + p.out.println(" offset_delta = " + offsetDelta);
17.95 + }
17.96 + }
17.97 +
17.98 + static class AppendFrame extends StackMapTableData {
17.99 + final int[] locals;
17.100 + AppendFrame(int frameType, int offsetDelta, int[] locals) {
17.101 + super(frameType);
17.102 + this.offsetDelta = offsetDelta;
17.103 + this.locals = locals;
17.104 + }
17.105 + void print(JavapPrinter p) {
17.106 + super.print(p);
17.107 + p.out.println(" /* append */");
17.108 + p.out.println(" offset_delta = " + offsetDelta);
17.109 + p.printMap(" locals = [", locals);
17.110 + }
17.111 + }
17.112 +
17.113 + static class FullFrame extends StackMapTableData {
17.114 + final int[] locals;
17.115 + final int[] stack;
17.116 + FullFrame(int offsetDelta, int[] locals, int[] stack) {
17.117 + super(FULL_FRAME);
17.118 + this.offsetDelta = offsetDelta;
17.119 + this.locals = locals;
17.120 + this.stack = stack;
17.121 + }
17.122 + void print(JavapPrinter p) {
17.123 + super.print(p);
17.124 + p.out.println(" /* full_frame */");
17.125 + p.out.println(" offset_delta = " + offsetDelta);
17.126 + p.printMap(" locals = [", locals);
17.127 + p.printMap(" stack = [", stack);
17.128 + }
17.129 + }
17.130 +
17.131 + static StackMapTableData getInstance(DataInputStream in, MethodData method)
17.132 + throws IOException {
17.133 + int frameType = in.readUnsignedByte();
17.134 +
17.135 + if (frameType < SAME_FRAME_BOUND) {
17.136 + // same_frame
17.137 + return new SameFrame(frameType, frameType);
17.138 + } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
17.139 + // same_locals_1_stack_item_frame
17.140 + // read additional single stack element
17.141 + return new SameLocals1StackItem(frameType,
17.142 + (frameType - SAME_FRAME_BOUND),
17.143 + StackMapData.readTypeArray(in, 1, method));
17.144 + } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
17.145 + // same_locals_1_stack_item_extended
17.146 + return new SameLocals1StackItem(frameType,
17.147 + in.readUnsignedShort(),
17.148 + StackMapData.readTypeArray(in, 1, method));
17.149 + } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
17.150 + // chop_frame or same_frame_extended
17.151 + return new ChopFrame(frameType, in.readUnsignedShort());
17.152 + } else if (frameType == SAME_FRAME_EXTENDED) {
17.153 + // chop_frame or same_frame_extended
17.154 + return new SameFrame(frameType, in.readUnsignedShort());
17.155 + } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
17.156 + // append_frame
17.157 + return new AppendFrame(frameType, in.readUnsignedShort(),
17.158 + StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
17.159 + } else if (frameType == FULL_FRAME) {
17.160 + // full_frame
17.161 + int offsetDelta = in.readUnsignedShort();
17.162 + int locals_size = in.readUnsignedShort();
17.163 + int[] locals = StackMapData.readTypeArray(in, locals_size, method);
17.164 + int stack_size = in.readUnsignedShort();
17.165 + int[] stack = StackMapData.readTypeArray(in, stack_size, method);
17.166 + return new FullFrame(offsetDelta, locals, stack);
17.167 + } else {
17.168 + throw new ClassFormatError("unrecognized frame_type in StackMapTable");
17.169 + }
17.170 + }
17.171 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/javap/src/main/java/sun/tools/javap/Tables.java Fri Nov 09 21:33:22 2012 +0100
18.3 @@ -0,0 +1,377 @@
18.4 +/*
18.5 + * Copyright (c) 2002, 2005, 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 sun.tools.javap;
18.31 +
18.32 +import java.io.IOException;
18.33 +import java.io.InputStream;
18.34 +import java.util.Hashtable;
18.35 +import java.util.Vector;
18.36 +
18.37 +
18.38 +public class Tables implements Constants {
18.39 + /**
18.40 + * Define mnemocodes table.
18.41 + */
18.42 + static Hashtable mnemocodes = new Hashtable(301, 0.5f);
18.43 + static String opcExtNamesTab[]=new String[128];
18.44 + static String opcPrivExtNamesTab[]=new String[128];
18.45 + static void defineNonPriv(int opc, String mnem) {
18.46 + mnemocodes.put(opcExtNamesTab[opc]=mnem, new Integer(opc_nonpriv*256+opc));
18.47 + }
18.48 + static void definePriv(int opc, String mnem) {
18.49 + mnemocodes.put(opcPrivExtNamesTab[opc]="priv_"+mnem, new Integer(opc_priv*256+opc));
18.50 + }
18.51 + static void defineExt(int opc, String mnem) {
18.52 + defineNonPriv(opc, mnem);
18.53 + definePriv(opc, mnem);
18.54 + }
18.55 + static { int k;
18.56 + for (k=0; k<opc_wide; k++) {
18.57 + mnemocodes.put(opcNamesTab[k], new Integer(k));
18.58 + }
18.59 + for (k=opc_wide+1; k<opcNamesTab.length; k++) {
18.60 + mnemocodes.put(opcNamesTab[k], new Integer(k));
18.61 + }
18.62 + mnemocodes.put("invokenonvirtual", new Integer(opc_invokespecial));
18.63 +
18.64 + mnemocodes.put("iload_w", new Integer(opc_iload_w));
18.65 + mnemocodes.put("lload_w", new Integer(opc_lload_w));
18.66 + mnemocodes.put("fload_w", new Integer(opc_fload_w));
18.67 + mnemocodes.put("dload_w", new Integer(opc_dload_w));
18.68 + mnemocodes.put("aload_w", new Integer(opc_aload_w));
18.69 + mnemocodes.put("istore_w", new Integer(opc_istore_w));
18.70 + mnemocodes.put("lstore_w", new Integer(opc_lstore_w));
18.71 + mnemocodes.put("fstore_w", new Integer(opc_fstore_w));
18.72 + mnemocodes.put("dstore_w", new Integer(opc_dstore_w));
18.73 + mnemocodes.put("astore_w", new Integer(opc_astore_w));
18.74 + mnemocodes.put("ret_w", new Integer(opc_ret_w));
18.75 + mnemocodes.put("iinc_w", new Integer(opc_iinc_w));
18.76 +
18.77 + mnemocodes.put("nonpriv", new Integer(opc_nonpriv));
18.78 + mnemocodes.put("priv", new Integer(opc_priv));
18.79 +
18.80 + defineExt(0, "load_ubyte");
18.81 + defineExt(1, "load_byte");
18.82 + defineExt(2, "load_char");
18.83 + defineExt(3, "load_short");
18.84 + defineExt(4, "load_word");
18.85 + defineExt(10, "load_char_oe");
18.86 + defineExt(11, "load_short_oe");
18.87 + defineExt(12, "load_word_oe");
18.88 + defineExt(16, "ncload_ubyte");
18.89 + defineExt(17, "ncload_byte");
18.90 + defineExt(18, "ncload_char");
18.91 + defineExt(19, "ncload_short");
18.92 + defineExt(20, "ncload_word");
18.93 + defineExt(26, "ncload_char_oe");
18.94 + defineExt(27, "ncload_short_oe");
18.95 + defineExt(28, "ncload_word_oe");
18.96 + defineExt(30, "cache_flush");
18.97 + defineExt(32, "store_byte");
18.98 + defineExt(34, "store_short");
18.99 + defineExt(36, "store_word");
18.100 + defineExt(42, "store_short_oe");
18.101 + defineExt(44, "store_word_oe");
18.102 + defineExt(48, "ncstore_byte");
18.103 + defineExt(50, "ncstore_short");
18.104 + defineExt(52, "ncstore_word");
18.105 + defineExt(58, "ncstore_short_oe");
18.106 + defineExt(60, "ncstore_word_oe");
18.107 + defineExt(62, "zero_line");
18.108 + defineNonPriv(5, "ret_from_sub");
18.109 + defineNonPriv(63, "enter_sync_method");
18.110 + definePriv(5, "ret_from_trap");
18.111 + definePriv(6, "read_dcache_tag");
18.112 + definePriv(7, "read_dcache_data");
18.113 + definePriv(14, "read_icache_tag");
18.114 + definePriv(15, "read_icache_data");
18.115 + definePriv(22, "powerdown");
18.116 + definePriv(23, "read_scache_data");
18.117 + definePriv(31, "cache_index_flush");
18.118 + definePriv(38, "write_dcache_tag");
18.119 + definePriv(39, "write_dcache_data");
18.120 + definePriv(46, "write_icache_tag");
18.121 + definePriv(47, "write_icache_data");
18.122 + definePriv(54, "reset");
18.123 + definePriv(55, "write_scache_data");
18.124 + for (k=0; k<32; k++) {
18.125 + definePriv(k+64, "read_reg_"+k);
18.126 + }
18.127 + for (k=0; k<32; k++) {
18.128 + definePriv(k+96, "write_reg_"+k);
18.129 + }
18.130 + }
18.131 +
18.132 + public static int opcLength(int opc) throws ArrayIndexOutOfBoundsException {
18.133 + switch (opc>>8) {
18.134 + case 0:
18.135 + return opcLengthsTab[opc];
18.136 + case opc_wide:
18.137 + switch (opc&0xFF) {
18.138 + case opc_aload: case opc_astore:
18.139 + case opc_fload: case opc_fstore:
18.140 + case opc_iload: case opc_istore:
18.141 + case opc_lload: case opc_lstore:
18.142 + case opc_dload: case opc_dstore:
18.143 + case opc_ret:
18.144 + return 4;
18.145 + case opc_iinc:
18.146 + return 6;
18.147 + default:
18.148 + throw new ArrayIndexOutOfBoundsException();
18.149 + }
18.150 + case opc_nonpriv:
18.151 + case opc_priv:
18.152 + return 2;
18.153 + default:
18.154 + throw new ArrayIndexOutOfBoundsException();
18.155 + }
18.156 + }
18.157 +
18.158 + public static String opcName(int opc) {
18.159 + try {
18.160 + switch (opc>>8) {
18.161 + case 0:
18.162 + return opcNamesTab[opc];
18.163 + case opc_wide: {
18.164 + String mnem=opcNamesTab[opc&0xFF]+"_w";
18.165 + if (mnemocodes.get(mnem) == null)
18.166 + return null; // non-existent opcode
18.167 + return mnem;
18.168 + }
18.169 + case opc_nonpriv:
18.170 + return opcExtNamesTab[opc&0xFF];
18.171 + case opc_priv:
18.172 + return opcPrivExtNamesTab[opc&0xFF];
18.173 + default:
18.174 + return null;
18.175 + }
18.176 + } catch (ArrayIndexOutOfBoundsException e) {
18.177 + switch (opc) {
18.178 + case opc_nonpriv:
18.179 + return "nonpriv";
18.180 + case opc_priv:
18.181 + return "priv";
18.182 + default:
18.183 + return null;
18.184 + }
18.185 + }
18.186 + }
18.187 +
18.188 + public static int opcode(String mnem) {
18.189 + Integer Val=(Integer)(mnemocodes.get(mnem));
18.190 + if (Val == null) return -1;
18.191 + return Val.intValue();
18.192 + }
18.193 +
18.194 + /**
18.195 + * Initialized keyword and token Hashtables
18.196 + */
18.197 + static Vector keywordNames = new Vector(40);
18.198 + private static void defineKeywordName(String id, int token) {
18.199 +
18.200 + if (token>=keywordNames.size()) {
18.201 + keywordNames.setSize(token+1);
18.202 + }
18.203 + keywordNames.setElementAt(id, token);
18.204 + }
18.205 + public static String keywordName(int token) {
18.206 + if (token==-1) return "EOF";
18.207 + if (token>=keywordNames.size()) return null;
18.208 + return (String)keywordNames.elementAt(token);
18.209 + }
18.210 + static {
18.211 + defineKeywordName("ident", IDENT);
18.212 + defineKeywordName("STRINGVAL", STRINGVAL);
18.213 + defineKeywordName("intVal", INTVAL);
18.214 + defineKeywordName("longVal", LONGVAL);
18.215 + defineKeywordName("floatVal", FLOATVAL);
18.216 + defineKeywordName("doubleVal", DOUBLEVAL);
18.217 + defineKeywordName("SEMICOLON", SEMICOLON);
18.218 + defineKeywordName("COLON", COLON);
18.219 + defineKeywordName("LBRACE", LBRACE);
18.220 + defineKeywordName("RBRACE", RBRACE);
18.221 + }
18.222 +
18.223 + static Hashtable keywords = new Hashtable(40);
18.224 + public static int keyword(String idValue) {
18.225 + Integer Val=(Integer)(keywords.get(idValue));
18.226 + if (Val == null) return IDENT;
18.227 + return Val.intValue();
18.228 + }
18.229 +
18.230 + private static void defineKeyword(String id, int token) {
18.231 + keywords.put(id, new Integer(token));
18.232 + defineKeywordName(id, token);
18.233 + }
18.234 + static {
18.235 + // Modifier keywords
18.236 + defineKeyword("private", PRIVATE);
18.237 + defineKeyword("public", PUBLIC);
18.238 + defineKeyword("protected", PROTECTED);
18.239 + defineKeyword("static", STATIC);
18.240 + defineKeyword("transient", TRANSIENT);
18.241 + defineKeyword("synchronized", SYNCHRONIZED);
18.242 + defineKeyword("super", SUPER);
18.243 + defineKeyword("native", NATIVE);
18.244 + defineKeyword("abstract", ABSTRACT);
18.245 + defineKeyword("volatile", VOLATILE);
18.246 + defineKeyword("final", FINAL);
18.247 + defineKeyword("interface",INTERFACE);
18.248 + defineKeyword("synthetic",SYNTHETIC);
18.249 + defineKeyword("strict",STRICT);
18.250 +
18.251 + // Declaration keywords
18.252 + defineKeyword("package",PACKAGE);
18.253 + defineKeyword("class",CLASS);
18.254 + defineKeyword("extends",EXTENDS);
18.255 + defineKeyword("implements",IMPLEMENTS);
18.256 + defineKeyword("const", CONST);
18.257 + defineKeyword("throws",THROWS);
18.258 + defineKeyword("interface",INTERFACE);
18.259 + defineKeyword("Method",METHODREF);
18.260 + defineKeyword("Field",FIELDREF);
18.261 + defineKeyword("stack",STACK);
18.262 + defineKeyword("locals",LOCAL);
18.263 +
18.264 + // used in switchtables
18.265 + defineKeyword("default", DEFAULT);
18.266 +
18.267 + // used in inner class declarations
18.268 + defineKeyword("InnerClass", INNERCLASS);
18.269 + defineKeyword("of", OF);
18.270 +
18.271 + // misc
18.272 + defineKeyword("bits",BITS);
18.273 + defineKeyword("Infinity",INF);
18.274 + defineKeyword("Inf",INF);
18.275 + defineKeyword("NaN",NAN);
18.276 + }
18.277 +
18.278 + /**
18.279 + * Define tag table.
18.280 + */
18.281 + private static Vector tagNames = new Vector(10);
18.282 + private static Hashtable Tags = new Hashtable(10);
18.283 + static {
18.284 + defineTag("Asciz",CONSTANT_UTF8);
18.285 + defineTag("int",CONSTANT_INTEGER);
18.286 + defineTag("float",CONSTANT_FLOAT);
18.287 + defineTag("long",CONSTANT_LONG);
18.288 + defineTag("double",CONSTANT_DOUBLE);
18.289 + defineTag("class",CONSTANT_CLASS);
18.290 + defineTag("String",CONSTANT_STRING);
18.291 + defineTag("Field",CONSTANT_FIELD);
18.292 + defineTag("Method",CONSTANT_METHOD);
18.293 + defineTag("InterfaceMethod",CONSTANT_INTERFACEMETHOD);
18.294 + defineTag("NameAndType",CONSTANT_NAMEANDTYPE);
18.295 + }
18.296 + private static void defineTag(String id, int val) {
18.297 + Tags.put(id, new Integer(val));
18.298 + if (val>=tagNames.size()) {
18.299 + tagNames.setSize(val+1);
18.300 + }
18.301 + tagNames.setElementAt(id, val);
18.302 + }
18.303 + public static String tagName(int tag) {
18.304 + if (tag>=tagNames.size()) return null;
18.305 + return (String)tagNames.elementAt(tag);
18.306 + }
18.307 + public static int tagValue(String idValue) {
18.308 + Integer Val=(Integer)(Tags.get(idValue));
18.309 + if (Val == null) return 0;
18.310 + return Val.intValue();
18.311 + }
18.312 +
18.313 + /**
18.314 + * Define type table. These types used in "newarray" instruction only.
18.315 + */
18.316 + private static Vector typeNames = new Vector(10);
18.317 + private static Hashtable Types = new Hashtable(10);
18.318 + static {
18.319 + defineType("int",T_INT);
18.320 + defineType("long",T_LONG);
18.321 + defineType("float",T_FLOAT);
18.322 + defineType("double",T_DOUBLE);
18.323 + defineType("class",T_CLASS);
18.324 + defineType("boolean",T_BOOLEAN);
18.325 + defineType("char",T_CHAR);
18.326 + defineType("byte",T_BYTE);
18.327 + defineType("short",T_SHORT);
18.328 + }
18.329 + private static void defineType(String id, int val) {
18.330 + Types.put(id, new Integer(val));
18.331 + if (val>=typeNames.size()) {
18.332 + typeNames.setSize(val+1);
18.333 + }
18.334 + typeNames.setElementAt(id, val);
18.335 + }
18.336 + public static int typeValue(String idValue) {
18.337 + Integer Val=(Integer)(Types.get(idValue));
18.338 + if (Val == null) return -1;
18.339 + return Val.intValue();
18.340 + }
18.341 + public static String typeName(int type) {
18.342 + if (type>=typeNames.size()) return null;
18.343 + return (String)typeNames.elementAt(type);
18.344 + }
18.345 +
18.346 + /**
18.347 + * Define MapTypes table.
18.348 + * These constants used in stackmap tables only.
18.349 + */
18.350 + private static Vector mapTypeNames = new Vector(10);
18.351 + private static Hashtable MapTypes = new Hashtable(10);
18.352 + static {
18.353 + defineMapType("bogus", ITEM_Bogus);
18.354 + defineMapType("int", ITEM_Integer);
18.355 + defineMapType("float", ITEM_Float);
18.356 + defineMapType("double", ITEM_Double);
18.357 + defineMapType("long", ITEM_Long);
18.358 + defineMapType("null", ITEM_Null);
18.359 + defineMapType("this", ITEM_InitObject);
18.360 + defineMapType("CP", ITEM_Object);
18.361 + defineMapType("uninitialized", ITEM_NewObject);
18.362 + }
18.363 + private static void defineMapType(String id, int val) {
18.364 + MapTypes.put(id, new Integer(val));
18.365 + if (val>=mapTypeNames.size()) {
18.366 + mapTypeNames.setSize(val+1);
18.367 + }
18.368 + mapTypeNames.setElementAt(id, val);
18.369 + }
18.370 + public static int mapTypeValue(String idValue) {
18.371 + Integer Val=(Integer)(MapTypes.get(idValue));
18.372 + if (Val == null) return -1;
18.373 + return Val.intValue();
18.374 + }
18.375 + public static String mapTypeName(int type) {
18.376 + if (type>=mapTypeNames.size()) return null;
18.377 + return (String)mapTypeNames.elementAt(type);
18.378 + }
18.379 +
18.380 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/javap/src/main/java/sun/tools/javap/TrapData.java Fri Nov 09 21:33:22 2012 +0100
19.3 @@ -0,0 +1,60 @@
19.4 +/*
19.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19.7 + *
19.8 + * This code is free software; you can redistribute it and/or modify it
19.9 + * under the terms of the GNU General Public License version 2 only, as
19.10 + * published by the Free Software Foundation. Oracle designates this
19.11 + * particular file as subject to the "Classpath" exception as provided
19.12 + * by Oracle in the LICENSE file that accompanied this code.
19.13 + *
19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19.17 + * version 2 for more details (a copy is included in the LICENSE file that
19.18 + * accompanied this code).
19.19 + *
19.20 + * You should have received a copy of the GNU General Public License version
19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.23 + *
19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19.25 + * or visit www.oracle.com if you need additional information or have any
19.26 + * questions.
19.27 + */
19.28 +
19.29 +
19.30 +package sun.tools.javap;
19.31 +
19.32 +import java.util.*;
19.33 +import java.io.*;
19.34 +
19.35 +/**
19.36 + * Stores exception table data in code attribute.
19.37 + *
19.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
19.39 + */
19.40 +class TrapData {
19.41 + short start_pc, end_pc, handler_pc, catch_cpx;
19.42 + int num;
19.43 +
19.44 +
19.45 + /**
19.46 + * Read and store exception table data in code attribute.
19.47 + */
19.48 + public TrapData(DataInputStream in, int num) throws IOException {
19.49 + this.num=num;
19.50 + start_pc = in.readShort();
19.51 + end_pc=in.readShort();
19.52 + handler_pc=in.readShort();
19.53 + catch_cpx=in.readShort();
19.54 + }
19.55 +
19.56 + /**
19.57 + * returns recommended identifier
19.58 + */
19.59 + public String ident() {
19.60 + return "t"+num;
19.61 + }
19.62 +
19.63 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/javap/src/main/java/sun/tools/javap/TypeSignature.java Fri Nov 09 21:33:22 2012 +0100
20.3 @@ -0,0 +1,295 @@
20.4 +/*
20.5 + * Copyright (c) 2002, 2003, 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 +
20.29 +
20.30 +package sun.tools.javap;
20.31 +
20.32 +import java.util.*;
20.33 +import java.io.*;
20.34 +
20.35 +/**
20.36 + * Returns java type signature.
20.37 + *
20.38 + * @author Sucheta Dambalkar
20.39 + */
20.40 +public class TypeSignature {
20.41 +
20.42 + String parameters = null;
20.43 + String returntype = null;
20.44 + String fieldtype = null;
20.45 + int argumentlength = 0;
20.46 +
20.47 + public TypeSignature(String JVMSignature){
20.48 +
20.49 + if(JVMSignature != null){
20.50 + if(JVMSignature.indexOf("(") == -1){
20.51 + //This is a field type.
20.52 + this.fieldtype = getFieldTypeSignature(JVMSignature);
20.53 + }else {
20.54 + String parameterdes = null;
20.55 + if((JVMSignature.indexOf(")")-1) > (JVMSignature.indexOf("("))){
20.56 + //Get parameter signature.
20.57 + parameterdes =
20.58 + JVMSignature.substring(JVMSignature.indexOf("(")+1,
20.59 + JVMSignature.indexOf(")"));
20.60 + this.parameters = getParametersHelper(parameterdes);
20.61 + }else this.parameters = "()";
20.62 + //Get return type signature.
20.63 + String returndes = JVMSignature.substring(JVMSignature.lastIndexOf(")")+1);
20.64 + this.returntype = getReturnTypeHelper(returndes);
20.65 + }
20.66 + }
20.67 + }
20.68 +
20.69 + /**
20.70 + * Returns java type signature of a field.
20.71 + */
20.72 + public String getFieldTypeSignature(String fielddes){
20.73 + if(fielddes.startsWith("L")){
20.74 + return(getObjectType(fielddes));
20.75 + }else if(fielddes.startsWith("[")){
20.76 + return(getArrayType(fielddes));
20.77 + }else
20.78 + return(getBaseType(fielddes));
20.79 + }
20.80 +
20.81 + /**
20.82 + * Returns java type signature of a parameter.
20.83 + */
20.84 + public String getParametersHelper(String parameterdes){
20.85 + Vector parameters = new Vector();
20.86 + int startindex = -1;
20.87 + int endindex = -1;
20.88 + String param = "";
20.89 +
20.90 + while(parameterdes != null){
20.91 +
20.92 + if(parameterdes.startsWith("L")){
20.93 + //parameter is a object.
20.94 + startindex = parameterdes.indexOf("L");
20.95 + endindex = parameterdes.indexOf(";");
20.96 + if(startindex < parameterdes.length()) {
20.97 + if(endindex == parameterdes.length()-1) {
20.98 + //last parameter
20.99 + param = parameterdes.substring(startindex);
20.100 + parameterdes = null;
20.101 + }else if(endindex+1 < parameterdes.length()){
20.102 + //rest parameters
20.103 + param = parameterdes.substring(startindex, endindex+1);
20.104 + parameterdes = parameterdes.substring(endindex+1);
20.105 +
20.106 + }
20.107 + parameters.add(getObjectType(param));
20.108 + }
20.109 + }else if(parameterdes.startsWith("[")){
20.110 + //parameter is an array.
20.111 + String componentType = "";
20.112 + int enddim = -1;
20.113 + int st = 0;
20.114 + while(true){
20.115 + if(st < parameterdes.length()){
20.116 + if(parameterdes.charAt(st) == '['){
20.117 +
20.118 + enddim = st;
20.119 + st++;
20.120 + }
20.121 + else break;
20.122 + }
20.123 + else break;
20.124 + }
20.125 +
20.126 + if(enddim+1 < parameterdes.length()){
20.127 + /* Array dimension.*/
20.128 + param = parameterdes.substring(0,enddim+1);
20.129 +
20.130 + }
20.131 +
20.132 + int stotherparam = param.lastIndexOf("[")+1;
20.133 +
20.134 + if(stotherparam < parameterdes.length()){
20.135 + componentType = parameterdes.substring(stotherparam);
20.136 + }
20.137 +
20.138 + if(componentType.startsWith("L")){
20.139 + //parameter is array of objects.
20.140 + startindex = parameterdes.indexOf("L");
20.141 + endindex = parameterdes.indexOf(";");
20.142 +
20.143 + if(endindex == parameterdes.length()-1){
20.144 + //last parameter
20.145 + param += parameterdes.substring(startindex);
20.146 + parameterdes = null;
20.147 + }else if(endindex+1 < parameterdes.length()){
20.148 + //rest parameters
20.149 + param += parameterdes.substring(startindex, endindex+1);
20.150 + parameterdes = parameterdes.substring(endindex+1);
20.151 + }
20.152 + }else{
20.153 + //parameter is array of base type.
20.154 + if(componentType.length() == 1){
20.155 + //last parameter.
20.156 + param += componentType;
20.157 + parameterdes = null;
20.158 + }
20.159 + else if (componentType.length() > 1) {
20.160 + //rest parameters.
20.161 + param += componentType.substring(0,1);
20.162 + parameterdes = componentType.substring(1);
20.163 + }
20.164 + }
20.165 + parameters.add(getArrayType(param));
20.166 +
20.167 +
20.168 + }else {
20.169 +
20.170 + //parameter is of base type.
20.171 + if(parameterdes.length() == 1){
20.172 + //last parameter
20.173 + param = parameterdes;
20.174 + parameterdes = null;
20.175 + }
20.176 + else if (parameterdes.length() > 1) {
20.177 + //rest parameters.
20.178 + param = parameterdes.substring(0,1);
20.179 + parameterdes = parameterdes.substring(1);
20.180 + }
20.181 + parameters.add(getBaseType(param));
20.182 + }
20.183 + }
20.184 +
20.185 + /* number of arguments of a method.*/
20.186 + argumentlength = parameters.size();
20.187 +
20.188 + /* java type signature.*/
20.189 + String parametersignature = "(";
20.190 + int i;
20.191 +
20.192 + for(i = 0; i < parameters.size(); i++){
20.193 + parametersignature += (String)parameters.elementAt(i);
20.194 + if(i != parameters.size()-1){
20.195 + parametersignature += ", ";
20.196 + }
20.197 + }
20.198 + parametersignature += ")";
20.199 + return parametersignature;
20.200 + }
20.201 +
20.202 + /**
20.203 + * Returns java type signature for a return type.
20.204 + */
20.205 + public String getReturnTypeHelper(String returndes){
20.206 + return getFieldTypeSignature(returndes);
20.207 + }
20.208 +
20.209 + /**
20.210 + * Returns java type signature for a base type.
20.211 + */
20.212 + public String getBaseType(String baseType){
20.213 + if(baseType != null){
20.214 + if(baseType.equals("B")) return "byte";
20.215 + else if(baseType.equals("C")) return "char";
20.216 + else if(baseType.equals("D")) return "double";
20.217 + else if(baseType.equals("F")) return "float";
20.218 + else if(baseType.equals("I")) return "int";
20.219 + else if(baseType.equals("J")) return "long";
20.220 + else if(baseType.equals("S")) return "short";
20.221 + else if(baseType.equals("Z")) return "boolean";
20.222 + else if(baseType.equals("V")) return "void";
20.223 + }
20.224 + return null;
20.225 + }
20.226 +
20.227 + /**
20.228 + * Returns java type signature for a object type.
20.229 + */
20.230 + public String getObjectType(String JVMobjectType) {
20.231 + String objectType = "";
20.232 + int startindex = JVMobjectType.indexOf("L")+1;
20.233 + int endindex = JVMobjectType.indexOf(";");
20.234 + if((startindex != -1) && (endindex != -1)){
20.235 + if((startindex < JVMobjectType.length()) && (endindex < JVMobjectType.length())){
20.236 + objectType = JVMobjectType.substring(startindex, endindex);
20.237 + }
20.238 + objectType = objectType.replace('/','.');
20.239 + return objectType;
20.240 + }
20.241 + return null;
20.242 + }
20.243 +
20.244 + /**
20.245 + * Returns java type signature for array type.
20.246 + */
20.247 + public String getArrayType(String arrayType) {
20.248 + if(arrayType != null){
20.249 + String dimention = "";
20.250 +
20.251 + while(arrayType.indexOf("[") != -1){
20.252 + dimention += "[]";
20.253 +
20.254 + int startindex = arrayType.indexOf("[")+1;
20.255 + if(startindex <= arrayType.length()){
20.256 + arrayType = arrayType.substring(startindex);
20.257 + }
20.258 + }
20.259 +
20.260 + String componentType = "";
20.261 + if(arrayType.startsWith("L")){
20.262 + componentType = getObjectType(arrayType);
20.263 + }else {
20.264 + componentType = getBaseType(arrayType);
20.265 + }
20.266 + return componentType+dimention;
20.267 + }
20.268 + return null;
20.269 + }
20.270 +
20.271 + /**
20.272 + * Returns java type signature for parameters.
20.273 + */
20.274 + public String getParameters(){
20.275 + return parameters;
20.276 + }
20.277 +
20.278 + /**
20.279 + * Returns java type signature for return type.
20.280 + */
20.281 + public String getReturnType(){
20.282 + return returntype;
20.283 + }
20.284 +
20.285 + /**
20.286 + * Returns java type signature for field type.
20.287 + */
20.288 + public String getFieldType(){
20.289 + return fieldtype;
20.290 + }
20.291 +
20.292 + /**
20.293 + * Return number of arguments of a method.
20.294 + */
20.295 + public int getArgumentlength(){
20.296 + return argumentlength;
20.297 + }
20.298 +}
21.1 --- a/pom.xml Fri Nov 09 12:15:25 2012 +0100
21.2 +++ b/pom.xml Fri Nov 09 21:33:22 2012 +0100
21.3 @@ -12,6 +12,7 @@
21.4 <module>core</module>
21.5 <module>mojo</module>
21.6 <module>javaquery</module>
21.7 + <module>javap</module>
21.8 </modules>
21.9 <licenses>
21.10 <license>