1.1 --- a/javap/src/main/java/sun/tools/javap/JavapEnvironment.java Fri Nov 09 21:33:22 2012 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,355 +0,0 @@
1.4 -/*
1.5 - * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 - *
1.8 - * This code is free software; you can redistribute it and/or modify it
1.9 - * under the terms of the GNU General Public License version 2 only, as
1.10 - * published by the Free Software Foundation. Oracle designates this
1.11 - * particular file as subject to the "Classpath" exception as provided
1.12 - * by Oracle in the LICENSE file that accompanied this code.
1.13 - *
1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 - * version 2 for more details (a copy is included in the LICENSE file that
1.18 - * accompanied this code).
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License version
1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 - *
1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 - * or visit www.oracle.com if you need additional information or have any
1.26 - * questions.
1.27 - */
1.28 -
1.29 -
1.30 -package sun.tools.javap;
1.31 -
1.32 -import java.util.*;
1.33 -import java.io.*;
1.34 -import java.util.jar.*;
1.35 -
1.36 -
1.37 -/**
1.38 - * Strores flag values according to command line options
1.39 - * and sets path where to find classes.
1.40 - *
1.41 - * @author Sucheta Dambalkar
1.42 - */
1.43 -public class JavapEnvironment {
1.44 -
1.45 - //Access flags
1.46 - public static final int PRIVATE = 0;
1.47 - public static final int PROTECTED = 1;
1.48 - public static final int PACKAGE = 2;
1.49 - public static final int PUBLIC = 3;
1.50 -
1.51 - //search path flags.
1.52 - private static final int start = 0;
1.53 - private static final int cmdboot= 1;
1.54 - private static final int sunboot = 2;
1.55 - private static final int javaclass= 3;
1.56 - private static final int cmdextdir= 4;
1.57 - private static final int javaext= 5;
1.58 - private static final int cmdclasspath= 6;
1.59 - private static final int envclasspath= 7;
1.60 - private static final int javaclasspath= 8;
1.61 - private static final int currentdir = 9;
1.62 -
1.63 -
1.64 - // JavapEnvironment flag settings
1.65 - boolean showLineAndLocal = false;
1.66 - int showAccess = PACKAGE;
1.67 - boolean showDisassembled = false;
1.68 - boolean showVerbose = false;
1.69 - boolean showInternalSigs = false;
1.70 - String classPathString = null;
1.71 - String bootClassPathString = null;
1.72 - String extDirsString = null;
1.73 - boolean extDirflag = false;
1.74 - boolean nothingToDo = true;
1.75 - boolean showallAttr = false;
1.76 - String classpath = null;
1.77 - int searchpath = start;
1.78 -
1.79 - /**
1.80 - * According to which flags are set,
1.81 - * returns file input stream for classfile to disassemble.
1.82 - */
1.83 -
1.84 - public InputStream getFileInputStream(String Name){
1.85 - InputStream fileInStream = null;
1.86 - searchpath = cmdboot;
1.87 - try{
1.88 - if(searchpath == cmdboot){
1.89 - if(bootClassPathString != null){
1.90 - //search in specified bootclasspath.
1.91 - classpath = bootClassPathString;
1.92 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.93 - //no classes found in search path.
1.94 - else searchpath = cmdextdir;
1.95 - }
1.96 - else searchpath = sunboot;
1.97 - }
1.98 -
1.99 - if(searchpath == sunboot){
1.100 - if(System.getProperty("sun.boot.class.path") != null){
1.101 - //search in sun.boot.class.path
1.102 - classpath = System.getProperty("sun.boot.class.path");
1.103 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.104 - //no classes found in search path
1.105 - else searchpath = cmdextdir;
1.106 - }
1.107 - else searchpath = javaclass;
1.108 - }
1.109 -
1.110 - if(searchpath == javaclass){
1.111 - if(System.getProperty("java.class.path") != null){
1.112 - //search in java.class.path
1.113 - classpath =System.getProperty("java.class.path");
1.114 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.115 - //no classes found in search path
1.116 - else searchpath = cmdextdir;
1.117 - }
1.118 - else searchpath = cmdextdir;
1.119 - }
1.120 -
1.121 - if(searchpath == cmdextdir){
1.122 - if(extDirsString != null){
1.123 - //search in specified extdir.
1.124 - classpath = extDirsString;
1.125 - extDirflag = true;
1.126 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.127 - //no classes found in search path
1.128 - else {
1.129 - searchpath = cmdclasspath;
1.130 - extDirflag = false;
1.131 - }
1.132 - }
1.133 - else searchpath = javaext;
1.134 - }
1.135 -
1.136 - if(searchpath == javaext){
1.137 - if(System.getProperty("java.ext.dirs") != null){
1.138 - //search in java.ext.dirs
1.139 - classpath = System.getProperty("java.ext.dirs");
1.140 - extDirflag = true;
1.141 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.142 - //no classes found in search path
1.143 - else {
1.144 - searchpath = cmdclasspath;
1.145 - extDirflag = false;
1.146 - }
1.147 - }
1.148 - else searchpath = cmdclasspath;
1.149 - }
1.150 - if(searchpath == cmdclasspath){
1.151 - if(classPathString != null){
1.152 - //search in specified classpath.
1.153 - classpath = classPathString;
1.154 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.155 - //no classes found in search path
1.156 - else searchpath = 8;
1.157 - }
1.158 - else searchpath = envclasspath;
1.159 - }
1.160 -
1.161 - if(searchpath == envclasspath){
1.162 - if(System.getProperty("env.class.path")!= null){
1.163 - //search in env.class.path
1.164 - classpath = System.getProperty("env.class.path");
1.165 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.166 - //no classes found in search path.
1.167 - else searchpath = javaclasspath;
1.168 - }
1.169 - else searchpath = javaclasspath;
1.170 - }
1.171 -
1.172 - if(searchpath == javaclasspath){
1.173 - if(("application.home") == null){
1.174 - //search in java.class.path
1.175 - classpath = System.getProperty("java.class.path");
1.176 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.177 - //no classes found in search path.
1.178 - else searchpath = currentdir;
1.179 - }
1.180 - else searchpath = currentdir;
1.181 - }
1.182 -
1.183 - if(searchpath == currentdir){
1.184 - classpath = ".";
1.185 - //search in current dir.
1.186 - if((fileInStream = resolvefilename(Name)) != null) return fileInStream;
1.187 - else {
1.188 - //no classes found in search path.
1.189 - error("Could not find "+ Name);
1.190 - System.exit(1);
1.191 - }
1.192 - }
1.193 - }catch(SecurityException excsec){
1.194 - excsec.printStackTrace();
1.195 - error("fatal exception");
1.196 - }catch(NullPointerException excnull){
1.197 - excnull.printStackTrace();
1.198 - error("fatal exception");
1.199 - }catch(IllegalArgumentException excill){
1.200 - excill.printStackTrace();
1.201 - error("fatal exception");
1.202 - }
1.203 -
1.204 - return null;
1.205 - }
1.206 -
1.207 -
1.208 - public void error(String msg) {
1.209 - System.err.println("ERROR:" +msg);
1.210 - }
1.211 -
1.212 - /**
1.213 - * Resolves file name for classfile to disassemble.
1.214 - */
1.215 - public InputStream resolvefilename(String name){
1.216 - String classname = name.replace('.', '/') + ".class";
1.217 - while (true) {
1.218 - InputStream instream = extDirflag
1.219 - ? resolveExdirFilename(classname)
1.220 - : resolveclasspath(classname);
1.221 - if (instream != null)
1.222 - return instream;
1.223 - int lastindex = classname.lastIndexOf('/');
1.224 - if (lastindex == -1) return null;
1.225 - classname = classname.substring(0, lastindex) + "$" +
1.226 - classname.substring(lastindex + 1);
1.227 - }
1.228 - }
1.229 -
1.230 - /**
1.231 - * Resolves file name for classfile to disassemble if flag exdir is set.
1.232 - */
1.233 - public InputStream resolveExdirFilename(String classname){
1.234 - if(classpath.indexOf(File.pathSeparator) != -1){
1.235 - //separates path
1.236 - StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator);
1.237 - while(st.hasMoreTokens()){
1.238 - String path = st.nextToken();
1.239 - InputStream in = resolveExdirFilenamehelper(path, classname);
1.240 - if (in != null)
1.241 - return in;
1.242 - }
1.243 - }else return (resolveExdirFilenamehelper(classpath, classname));
1.244 -
1.245 - return null;
1.246 - }
1.247 -
1.248 - /**
1.249 - * Resolves file name for classfile to disassemble.
1.250 - */
1.251 - public InputStream resolveclasspath(String classname){
1.252 - if(classpath.indexOf(File.pathSeparator) != -1){
1.253 - StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator);
1.254 - //separates path.
1.255 - while(st.hasMoreTokens()){
1.256 - String path = (st.nextToken()).trim();
1.257 - InputStream in = resolveclasspathhelper(path, classname);
1.258 - if(in != null) return in;
1.259 -
1.260 - }
1.261 - return null;
1.262 - }
1.263 - else return (resolveclasspathhelper(classpath, classname));
1.264 - }
1.265 -
1.266 -
1.267 - /**
1.268 - * Returns file input stream for classfile to disassemble if exdir is set.
1.269 - */
1.270 - public InputStream resolveExdirFilenamehelper(String path, String classname){
1.271 - File fileobj = new File(path);
1.272 - if(fileobj.isDirectory()){
1.273 - // gets list of files in that directory.
1.274 - File[] filelist = fileobj.listFiles();
1.275 - for(int i = 0; i < filelist.length; i++){
1.276 - try{
1.277 - //file is a jar file.
1.278 - if(filelist[i].toString().endsWith(".jar")){
1.279 - JarFile jfile = new JarFile(filelist[i]);
1.280 - if((jfile.getEntry(classname)) != null){
1.281 -
1.282 - InputStream filein = jfile.getInputStream(jfile.getEntry(classname));
1.283 - int bytearraysize = filein.available();
1.284 - byte []b = new byte[bytearraysize];
1.285 - int totalread = 0;
1.286 - while(totalread < bytearraysize){
1.287 - totalread += filein.read(b, totalread, bytearraysize-totalread);
1.288 - }
1.289 - InputStream inbyte = new ByteArrayInputStream(b);
1.290 - filein.close();
1.291 - return inbyte;
1.292 - }
1.293 - } else {
1.294 - //not a jar file.
1.295 - String filename = path+"/"+ classname;
1.296 - File file = new File(filename);
1.297 - if(file.isFile()){
1.298 - return (new FileInputStream(file));
1.299 - }
1.300 - }
1.301 - }catch(FileNotFoundException fnexce){
1.302 - fnexce.printStackTrace();
1.303 - error("cant read file");
1.304 - error("fatal exception");
1.305 - }catch(IOException ioexc){
1.306 - ioexc.printStackTrace();
1.307 - error("fatal exception");
1.308 - }
1.309 - }
1.310 - }
1.311 -
1.312 - return null;
1.313 - }
1.314 -
1.315 -
1.316 - /**
1.317 - * Returns file input stream for classfile to disassemble.
1.318 - */
1.319 - public InputStream resolveclasspathhelper(String path, String classname){
1.320 - File fileobj = new File(path);
1.321 - try{
1.322 - if(fileobj.isDirectory()){
1.323 - //is a directory.
1.324 - String filename = path+"/"+ classname;
1.325 - File file = new File(filename);
1.326 - if(file.isFile()){
1.327 - return (new FileInputStream(file));
1.328 - }
1.329 -
1.330 - }else if(fileobj.isFile()){
1.331 - if(fileobj.toString().endsWith(".jar")){
1.332 - //is a jar file.
1.333 - JarFile jfile = new JarFile(fileobj);
1.334 - if((jfile.getEntry(classname)) != null){
1.335 - InputStream filein = jfile.getInputStream(jfile.getEntry(classname));
1.336 - int bytearraysize = filein.available();
1.337 - byte []b = new byte[bytearraysize];
1.338 - int totalread = 0;
1.339 - while(totalread < bytearraysize){
1.340 - totalread += filein.read(b, totalread, bytearraysize-totalread);
1.341 - }
1.342 - InputStream inbyte = new ByteArrayInputStream(b);
1.343 - filein.close();
1.344 - return inbyte;
1.345 - }
1.346 - }
1.347 - }
1.348 - }catch(FileNotFoundException fnexce){
1.349 - fnexce.printStackTrace();
1.350 - error("cant read file");
1.351 - error("fatal exception");
1.352 - }catch(IOException ioexce){
1.353 - ioexce.printStackTrace();
1.354 - error("fatal exception");
1.355 - }
1.356 - return null;
1.357 - }
1.358 -}
2.1 --- a/javap/src/main/java/sun/tools/javap/JavapPrinter.java Fri Nov 09 21:33:22 2012 +0100
2.2 +++ b/javap/src/main/java/sun/tools/javap/JavapPrinter.java Sat Nov 10 07:27:09 2012 +0100
2.3 @@ -37,874 +37,4 @@
2.4 * @author Sucheta Dambalkar
2.5 */
2.6 public class JavapPrinter {
2.7 - JavapEnvironment env;
2.8 - ClassData cls;
2.9 - byte[] code;
2.10 - String lP= "";
2.11 - PrintWriter out;
2.12 -
2.13 - public JavapPrinter(InputStream cname, PrintWriter out, JavapEnvironment env){
2.14 - this.out = out;
2.15 - this.cls = new ClassData(cname);
2.16 - this.env = env;
2.17 - }
2.18 -
2.19 - /**
2.20 - * Entry point to print class file information.
2.21 - */
2.22 - public void print(){
2.23 - printclassHeader();
2.24 - printfields();
2.25 - printMethods();
2.26 - printend();
2.27 - }
2.28 -
2.29 - /**
2.30 - * Print a description of the class (not members).
2.31 - */
2.32 - public void printclassHeader(){
2.33 - String srcName="";
2.34 - if ((srcName = cls.getSourceName()) != "null") // requires debug info
2.35 - out.println("Compiled from " + javaclassname(srcName));
2.36 -
2.37 - if(cls.isInterface()) {
2.38 - // The only useful access modifier of an interface is
2.39 - // public; interfaces are always marked as abstract and
2.40 - // cannot be final.
2.41 - out.print((cls.isPublic()?"public ":"") +
2.42 - "interface "+ javaclassname(cls.getClassName()));
2.43 - }
2.44 - else if(cls.isClass()) {
2.45 - String []accflags = cls.getAccess();
2.46 - printAccess(accflags);
2.47 - out.print("class "+ javaclassname(cls.getClassName()));
2.48 -
2.49 - if(cls.getSuperClassName() != null){
2.50 - out.print(" extends " + javaclassname(cls.getSuperClassName()));
2.51 - }
2.52 - }
2.53 -
2.54 - String []interfacelist = cls.getSuperInterfaces();
2.55 - if(interfacelist.length > 0){
2.56 - if(cls.isClass()) {
2.57 - out.print(" implements ");
2.58 - }
2.59 - else if(cls.isInterface()){
2.60 - out.print(" extends ");
2.61 - }
2.62 -
2.63 - for(int j = 0; j < interfacelist.length; j++){
2.64 - out.print(javaclassname(interfacelist[j]));
2.65 -
2.66 - if((j+1) < interfacelist.length) {
2.67 - out.print(",");
2.68 - }
2.69 - }
2.70 - }
2.71 -
2.72 - // Print class attribute information.
2.73 - if((env.showallAttr) || (env.showVerbose)){
2.74 - printClassAttributes();
2.75 - }
2.76 - // Print verbose output.
2.77 - if(env.showVerbose){
2.78 - printverbosecls();
2.79 - }
2.80 - out.println("{");
2.81 - }
2.82 -
2.83 - /**
2.84 - * Print verbose output.
2.85 - */
2.86 - public void printverbosecls(){
2.87 - out.println(" minor version: "+cls.getMinor_version());
2.88 - out.println(" major version: "+cls.getMajor_version());
2.89 - out.println(" Constant pool:");
2.90 - printcp();
2.91 - env.showallAttr = true;
2.92 - }
2.93 -
2.94 - /**
2.95 - * Print class attribute information.
2.96 - */
2.97 - public void printClassAttributes(){
2.98 - out.println();
2.99 - AttrData[] clsattrs = cls.getAttributes();
2.100 - for(int i = 0; i < clsattrs.length; i++){
2.101 - String clsattrname = clsattrs[i].getAttrName();
2.102 - if(clsattrname.equals("SourceFile")){
2.103 - out.println(" SourceFile: "+ cls.getSourceName());
2.104 - }else if(clsattrname.equals("InnerClasses")){
2.105 - printInnerClasses();
2.106 - }else {
2.107 - printAttrData(clsattrs[i]);
2.108 - }
2.109 - }
2.110 - }
2.111 -
2.112 - /**
2.113 - * Print the fields
2.114 - */
2.115 - public void printfields(){
2.116 - FieldData[] fields = cls.getFields();
2.117 - for(int f = 0; f < fields.length; f++){
2.118 - String[] accflags = fields[f].getAccess();
2.119 - if(checkAccess(accflags)){
2.120 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
2.121 - || env.showInternalSigs || env.showallAttr)){
2.122 - out.print(" ");
2.123 - }
2.124 - printAccess(accflags);
2.125 - out.println(fields[f].getType()+" " +fields[f].getName()+";");
2.126 - if (env.showInternalSigs) {
2.127 - out.println(" Signature: " + (fields[f].getInternalSig()));
2.128 - }
2.129 -
2.130 - // print field attribute information.
2.131 - if (env.showallAttr){
2.132 - printFieldAttributes(fields[f]);
2.133 -
2.134 - }
2.135 - if((env.showDisassembled) || (env.showLineAndLocal)){
2.136 - out.println();
2.137 - }
2.138 - }
2.139 - }
2.140 - }
2.141 -
2.142 -
2.143 - /* print field attribute information. */
2.144 - public void printFieldAttributes(FieldData field){
2.145 - Vector fieldattrs = field.getAttributes();
2.146 - for(int j = 0; j < fieldattrs.size(); j++){
2.147 - String fieldattrname = ((AttrData)fieldattrs.elementAt(j)).getAttrName();
2.148 - if(fieldattrname.equals("ConstantValue")){
2.149 - printConstantValue(field);
2.150 - }else if (fieldattrname.equals("Deprecated")){
2.151 - out.println("Deprecated: "+ field.isDeprecated());
2.152 - }else if (fieldattrname.equals("Synthetic")){
2.153 - out.println(" Synthetic: "+ field.isSynthetic());
2.154 - }else {
2.155 - printAttrData((AttrData)fieldattrs.elementAt(j));
2.156 - }
2.157 - }
2.158 - out.println();
2.159 - }
2.160 -
2.161 - /**
2.162 - * Print the methods
2.163 - */
2.164 - public void printMethods(){
2.165 - MethodData[] methods = cls.getMethods();
2.166 - for(int m = 0; m < methods.length; m++){
2.167 - String[] accflags = methods[m].getAccess();
2.168 - if(checkAccess(accflags)){
2.169 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
2.170 - || env.showInternalSigs || env.showallAttr)){
2.171 - out.print(" ");
2.172 - }
2.173 - printMethodSignature(methods[m], accflags);
2.174 - printExceptions(methods[m]);
2.175 - out.println(";");
2.176 -
2.177 - // Print internal signature of method.
2.178 - if (env.showInternalSigs){
2.179 - out.println(" Signature: " + (methods[m].getInternalSig()));
2.180 - }
2.181 -
2.182 - //Print disassembled code.
2.183 - if(env.showDisassembled && ! env.showallAttr) {
2.184 - printcodeSequence(methods[m]);
2.185 - printExceptionTable(methods[m]);
2.186 - out.println();
2.187 - }
2.188 -
2.189 - // Print line and local variable attribute information.
2.190 - if (env.showLineAndLocal) {
2.191 - printLineNumTable(methods[m]);
2.192 - printLocVarTable(methods[m]);
2.193 - out.println();
2.194 - }
2.195 -
2.196 - // Print method attribute information.
2.197 - if (env.showallAttr){
2.198 - printMethodAttributes(methods[m]);
2.199 - }
2.200 - }
2.201 - }
2.202 - }
2.203 -
2.204 - /**
2.205 - * Print method signature.
2.206 - */
2.207 - public void printMethodSignature(MethodData method, String[] accflags){
2.208 - printAccess(accflags);
2.209 -
2.210 - if((method.getName()).equals("<init>")){
2.211 - out.print(javaclassname(cls.getClassName()));
2.212 - out.print(method.getParameters());
2.213 - }else if((method.getName()).equals("<clinit>")){
2.214 - out.print("{}");
2.215 - }else{
2.216 - out.print(method.getReturnType()+" ");
2.217 - out.print(method.getName());
2.218 - out.print(method.getParameters());
2.219 - }
2.220 - }
2.221 -
2.222 - /**
2.223 - * print method attribute information.
2.224 - */
2.225 - public void printMethodAttributes(MethodData method){
2.226 - Vector methodattrs = method.getAttributes();
2.227 - Vector codeattrs = method.getCodeAttributes();
2.228 - for(int k = 0; k < methodattrs.size(); k++){
2.229 - String methodattrname = ((AttrData)methodattrs.elementAt(k)).getAttrName();
2.230 - if(methodattrname.equals("Code")){
2.231 - printcodeSequence(method);
2.232 - printExceptionTable(method);
2.233 - for(int c = 0; c < codeattrs.size(); c++){
2.234 - String codeattrname = ((AttrData)codeattrs.elementAt(c)).getAttrName();
2.235 - if(codeattrname.equals("LineNumberTable")){
2.236 - printLineNumTable(method);
2.237 - }else if(codeattrname.equals("LocalVariableTable")){
2.238 - printLocVarTable(method);
2.239 - }else if(codeattrname.equals("StackMapTable")) {
2.240 - // Java SE JSR 202 stack map tables
2.241 - printStackMapTable(method);
2.242 - }else if(codeattrname.equals("StackMap")) {
2.243 - // Java ME CLDC stack maps
2.244 - printStackMap(method);
2.245 - } else {
2.246 - printAttrData((AttrData)codeattrs.elementAt(c));
2.247 - }
2.248 - }
2.249 - }else if(methodattrname.equals("Exceptions")){
2.250 - out.println(" Exceptions: ");
2.251 - printExceptions(method);
2.252 - }else if (methodattrname.equals("Deprecated")){
2.253 - out.println(" Deprecated: "+ method.isDeprecated());
2.254 - }else if (methodattrname.equals("Synthetic")){
2.255 - out.println(" Synthetic: "+ method.isSynthetic());
2.256 - }else {
2.257 - printAttrData((AttrData)methodattrs.elementAt(k));
2.258 - }
2.259 - }
2.260 - out.println();
2.261 - }
2.262 -
2.263 - /**
2.264 - * Print exceptions.
2.265 - */
2.266 - public void printExceptions(MethodData method){
2.267 - int []exc_index_table = method.get_exc_index_table();
2.268 - if (exc_index_table != null) {
2.269 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
2.270 - || env.showInternalSigs || env.showallAttr)){
2.271 - out.print(" ");
2.272 - }
2.273 - out.print(" throws ");
2.274 - int k;
2.275 - int l = exc_index_table.length;
2.276 -
2.277 - for (k=0; k<l; k++) {
2.278 - out.print(javaclassname(cls.getClassName(exc_index_table[k])));
2.279 - if (k<l-1) out.print(", ");
2.280 - }
2.281 - }
2.282 - }
2.283 -
2.284 - /**
2.285 - * Print code sequence.
2.286 - */
2.287 - public void printcodeSequence(MethodData method){
2.288 - code = method.getCode();
2.289 - if(code != null){
2.290 - out.println(" Code:");
2.291 - if(env.showVerbose){
2.292 - printVerboseHeader(method);
2.293 - }
2.294 -
2.295 - for (int pc=0; pc < code.length; ) {
2.296 - out.print(" "+pc+":\t");
2.297 - pc=pc+printInstr(pc);
2.298 - out.println();
2.299 - }
2.300 - }
2.301 - }
2.302 -
2.303 - /**
2.304 - * Print instructions.
2.305 - */
2.306 - public int printInstr(int pc){
2.307 - int opcode = getUbyte(pc);
2.308 - int opcode2;
2.309 - String mnem;
2.310 - switch (opcode) {
2.311 - case opc_nonpriv:
2.312 - case opc_priv:
2.313 - opcode2 = getUbyte(pc+1);
2.314 - mnem=Tables.opcName((opcode<<8)+opcode2);
2.315 - if (mnem==null)
2.316 - // assume all (even nonexistent) priv and nonpriv instructions
2.317 - // are 2 bytes long
2.318 - mnem=Tables.opcName(opcode)+" "+opcode2;
2.319 - out.print(mnem);
2.320 - return 2;
2.321 - case opc_wide: {
2.322 - opcode2 = getUbyte(pc+1);
2.323 - mnem=Tables.opcName((opcode<<8)+opcode2);
2.324 - if (mnem==null) {
2.325 - // nonexistent opcode - but we have to print something
2.326 - out.print("bytecode "+opcode);
2.327 - return 1;
2.328 - }
2.329 - out.print(mnem+" "+getUShort(pc+2));
2.330 - if (opcode2==opc_iinc) {
2.331 - out.print(", "+getShort(pc+4));
2.332 - return 6;
2.333 - }
2.334 - return 4;
2.335 - }
2.336 - }
2.337 - mnem=Tables.opcName(opcode);
2.338 - if (mnem==null) {
2.339 - // nonexistent opcode - but we have to print something
2.340 - out.print("bytecode "+opcode);
2.341 - return 1;
2.342 - }
2.343 - if (opcode>opc_jsr_w) {
2.344 - // pseudo opcodes should be printed as bytecodes
2.345 - out.print("bytecode "+opcode);
2.346 - return 1;
2.347 - }
2.348 - out.print(Tables.opcName(opcode));
2.349 - switch (opcode) {
2.350 - case opc_aload: case opc_astore:
2.351 - case opc_fload: case opc_fstore:
2.352 - case opc_iload: case opc_istore:
2.353 - case opc_lload: case opc_lstore:
2.354 - case opc_dload: case opc_dstore:
2.355 - case opc_ret:
2.356 - out.print("\t"+getUbyte(pc+1));
2.357 - return 2;
2.358 - case opc_iinc:
2.359 - out.print("\t"+getUbyte(pc+1)+", "+getbyte(pc+2));
2.360 - return 3;
2.361 - case opc_tableswitch:{
2.362 - int tb=align(pc+1);
2.363 - int default_skip = getInt(tb); /* default skip pamount */
2.364 - int low = getInt(tb+4);
2.365 - int high = getInt(tb+8);
2.366 - int count = high - low;
2.367 - out.print("{ //"+low+" to "+high);
2.368 - for (int i = 0; i <= count; i++)
2.369 - out.print( "\n\t\t" + (i+low) + ": "+lP+(pc+getInt(tb+12+4*i))+";");
2.370 - out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
2.371 - return tb-pc+16+count*4;
2.372 - }
2.373 -
2.374 - case opc_lookupswitch:{
2.375 - int tb=align(pc+1);
2.376 - int default_skip = getInt(tb);
2.377 - int npairs = getInt(tb+4);
2.378 - out.print("{ //"+npairs);
2.379 - for (int i = 1; i <= npairs; i++)
2.380 - out.print("\n\t\t"+getInt(tb+i*8)
2.381 - +": "+lP+(pc+getInt(tb+4+i*8))+";"
2.382 - );
2.383 - out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
2.384 - return tb-pc+(npairs+1)*8;
2.385 - }
2.386 - case opc_newarray:
2.387 - int type=getUbyte(pc+1);
2.388 - switch (type) {
2.389 - case T_BOOLEAN:out.print(" boolean");break;
2.390 - case T_BYTE: out.print(" byte"); break;
2.391 - case T_CHAR: out.print(" char"); break;
2.392 - case T_SHORT: out.print(" short"); break;
2.393 - case T_INT: out.print(" int"); break;
2.394 - case T_LONG: out.print(" long"); break;
2.395 - case T_FLOAT: out.print(" float"); break;
2.396 - case T_DOUBLE: out.print(" double"); break;
2.397 - case T_CLASS: out.print(" class"); break;
2.398 - default: out.print(" BOGUS TYPE:"+type);
2.399 - }
2.400 - return 2;
2.401 -
2.402 - case opc_anewarray: {
2.403 - int index = getUShort(pc+1);
2.404 - out.print("\t#"+index+"; //");
2.405 - PrintConstant(index);
2.406 - return 3;
2.407 - }
2.408 -
2.409 - case opc_sipush:
2.410 - out.print("\t"+getShort(pc+1));
2.411 - return 3;
2.412 -
2.413 - case opc_bipush:
2.414 - out.print("\t"+getbyte(pc+1));
2.415 - return 2;
2.416 -
2.417 - case opc_ldc: {
2.418 - int index = getUbyte(pc+1);
2.419 - out.print("\t#"+index+"; //");
2.420 - PrintConstant(index);
2.421 - return 2;
2.422 - }
2.423 -
2.424 - case opc_ldc_w: case opc_ldc2_w:
2.425 - case opc_instanceof: case opc_checkcast:
2.426 - case opc_new:
2.427 - case opc_putstatic: case opc_getstatic:
2.428 - case opc_putfield: case opc_getfield:
2.429 - case opc_invokevirtual:
2.430 - case opc_invokespecial:
2.431 - case opc_invokestatic: {
2.432 - int index = getUShort(pc+1);
2.433 - out.print("\t#"+index+"; //");
2.434 - PrintConstant(index);
2.435 - return 3;
2.436 - }
2.437 -
2.438 - case opc_invokeinterface: {
2.439 - int index = getUShort(pc+1), nargs=getUbyte(pc+3);
2.440 - out.print("\t#"+index+", "+nargs+"; //");
2.441 - PrintConstant(index);
2.442 - return 5;
2.443 - }
2.444 -
2.445 - case opc_multianewarray: {
2.446 - int index = getUShort(pc+1), dimensions=getUbyte(pc+3);
2.447 - out.print("\t#"+index+", "+dimensions+"; //");
2.448 - PrintConstant(index);
2.449 - return 4;
2.450 - }
2.451 - case opc_jsr: case opc_goto:
2.452 - case opc_ifeq: case opc_ifge: case opc_ifgt:
2.453 - case opc_ifle: case opc_iflt: case opc_ifne:
2.454 - case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpge:
2.455 - case opc_if_icmpgt: case opc_if_icmple: case opc_if_icmplt:
2.456 - case opc_if_acmpeq: case opc_if_acmpne:
2.457 - case opc_ifnull: case opc_ifnonnull:
2.458 - out.print("\t"+lP+(pc + getShort(pc+1)) );
2.459 - return 3;
2.460 -
2.461 - case opc_jsr_w:
2.462 - case opc_goto_w:
2.463 - out.print("\t"+lP+(pc + getInt(pc+1)));
2.464 - return 5;
2.465 -
2.466 - default:
2.467 - return 1;
2.468 - }
2.469 - }
2.470 - /**
2.471 - * Print code attribute details.
2.472 - */
2.473 - public void printVerboseHeader(MethodData method) {
2.474 - int argCount = method.getArgumentlength();
2.475 - if (!method.isStatic())
2.476 - ++argCount; // for 'this'
2.477 -
2.478 - out.println(" Stack=" + method.getMaxStack()
2.479 - + ", Locals=" + method.getMaxLocals()
2.480 - + ", Args_size=" + argCount);
2.481 -
2.482 - }
2.483 -
2.484 -
2.485 - /**
2.486 - * Print the exception table for this method code
2.487 - */
2.488 - void printExceptionTable(MethodData method){//throws IOException
2.489 - Vector exception_table = method.getexception_table();
2.490 - if (exception_table.size() > 0) {
2.491 - out.println(" Exception table:");
2.492 - out.println(" from to target type");
2.493 - for (int idx = 0; idx < exception_table.size(); ++idx) {
2.494 - TrapData handler = (TrapData)exception_table.elementAt(idx);
2.495 - printFixedWidthInt(handler.start_pc, 6);
2.496 - printFixedWidthInt(handler.end_pc, 6);
2.497 - printFixedWidthInt(handler.handler_pc, 6);
2.498 - out.print(" ");
2.499 - int catch_cpx = handler.catch_cpx;
2.500 - if (catch_cpx == 0) {
2.501 - out.println("any");
2.502 - }else {
2.503 - out.print("Class ");
2.504 - out.println(cls.getClassName(catch_cpx));
2.505 - out.println("");
2.506 - }
2.507 - }
2.508 - }
2.509 - }
2.510 -
2.511 - /**
2.512 - * Print LineNumberTable attribute information.
2.513 - */
2.514 - public void printLineNumTable(MethodData method) {
2.515 - int numlines = method.getnumlines();
2.516 - Vector lin_num_tb = method.getlin_num_tb();
2.517 - if( lin_num_tb.size() > 0){
2.518 - out.println(" LineNumberTable: ");
2.519 - for (int i=0; i<numlines; i++) {
2.520 - LineNumData linnumtb_entry=(LineNumData)lin_num_tb.elementAt(i);
2.521 - out.println(" line " + linnumtb_entry.line_number + ": "
2.522 - + linnumtb_entry.start_pc);
2.523 - }
2.524 - }
2.525 - out.println();
2.526 - }
2.527 -
2.528 - /**
2.529 - * Print LocalVariableTable attribute information.
2.530 - */
2.531 - public void printLocVarTable(MethodData method){
2.532 - int siz = method.getloc_var_tbsize();
2.533 - if(siz > 0){
2.534 - out.println(" LocalVariableTable: ");
2.535 - out.print(" ");
2.536 - out.println("Start Length Slot Name Signature");
2.537 - }
2.538 - Vector loc_var_tb = method.getloc_var_tb();
2.539 -
2.540 - for (int i=0; i<siz; i++) {
2.541 - LocVarData entry=(LocVarData)loc_var_tb.elementAt(i);
2.542 -
2.543 - out.println(" "+entry.start_pc+" "+entry.length+" "+
2.544 - entry.slot+" "+cls.StringValue(entry.name_cpx) +
2.545 - " "+cls.StringValue(entry.sig_cpx));
2.546 - }
2.547 - out.println();
2.548 - }
2.549 -
2.550 - /**
2.551 - * Print StackMap attribute information.
2.552 - */
2.553 - public void printStackMap(MethodData method) {
2.554 - StackMapData[] stack_map_tb = method.getStackMap();
2.555 - int number_of_entries = stack_map_tb.length;
2.556 - if (number_of_entries > 0) {
2.557 - out.println(" StackMap: number_of_entries = " + number_of_entries);
2.558 -
2.559 - for (StackMapData frame : stack_map_tb) {
2.560 - frame.print(this);
2.561 - }
2.562 - }
2.563 - out.println();
2.564 - }
2.565 -
2.566 - /**
2.567 - * Print StackMapTable attribute information.
2.568 - */
2.569 - public void printStackMapTable(MethodData method) {
2.570 - StackMapTableData[] stack_map_tb = method.getStackMapTable();
2.571 - int number_of_entries = stack_map_tb.length;
2.572 - if (number_of_entries > 0) {
2.573 - out.println(" StackMapTable: number_of_entries = " + number_of_entries);
2.574 -
2.575 - for (StackMapTableData frame : stack_map_tb) {
2.576 - frame.print(this);
2.577 - }
2.578 - }
2.579 - out.println();
2.580 - }
2.581 -
2.582 - void printMap(String name, int[] map) {
2.583 - out.print(name);
2.584 - for (int i=0; i<map.length; i++) {
2.585 - int fulltype = map[i];
2.586 - int type = fulltype & 0xFF;
2.587 - int argument = fulltype >> 8;
2.588 - switch (type) {
2.589 - case ITEM_Object:
2.590 - out.print(" ");
2.591 - PrintConstant(argument);
2.592 - break;
2.593 - case ITEM_NewObject:
2.594 - out.print(" " + Tables.mapTypeName(type));
2.595 - out.print(" " + argument);
2.596 - break;
2.597 - default:
2.598 - out.print(" " + Tables.mapTypeName(type));
2.599 - }
2.600 - out.print( (i==(map.length-1)? ' ' : ','));
2.601 - }
2.602 - out.println("]");
2.603 - }
2.604 -
2.605 - /**
2.606 - * Print ConstantValue attribute information.
2.607 - */
2.608 - public void printConstantValue(FieldData field){
2.609 - out.print(" Constant value: ");
2.610 - int cpx = (field.getConstantValueIndex());
2.611 - byte tag=0;
2.612 - try {
2.613 - tag=cls.getTag(cpx);
2.614 -
2.615 - } catch (IndexOutOfBoundsException e) {
2.616 - out.print("Error:");
2.617 - return;
2.618 - }
2.619 - switch (tag) {
2.620 - case CONSTANT_METHOD:
2.621 - case CONSTANT_INTERFACEMETHOD:
2.622 - case CONSTANT_FIELD: {
2.623 - CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
2.624 - if (x.cpx1 == cls.getthis_cpx()) {
2.625 - // don't print class part for local references
2.626 - cpx=x.cpx2;
2.627 - }
2.628 - }
2.629 - }
2.630 - out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
2.631 - }
2.632 -
2.633 - /**
2.634 - * Print InnerClass attribute information.
2.635 - */
2.636 - public void printInnerClasses(){//throws ioexception
2.637 -
2.638 - InnerClassData[] innerClasses = cls.getInnerClasses();
2.639 - if(innerClasses != null){
2.640 - if(innerClasses.length > 0){
2.641 - out.print(" ");
2.642 - out.println("InnerClass: ");
2.643 - for(int i = 0 ; i < innerClasses.length; i++){
2.644 - out.print(" ");
2.645 - //access
2.646 - String[] accflags = innerClasses[i].getAccess();
2.647 - if(checkAccess(accflags)){
2.648 - printAccess(accflags);
2.649 - if (innerClasses[i].inner_name_index!=0) {
2.650 - out.print("#"+innerClasses[i].inner_name_index+"= ");
2.651 - }
2.652 - out.print("#"+innerClasses[i].inner_class_info_index);
2.653 - if (innerClasses[i].outer_class_info_index!=0) {
2.654 - out.print(" of #"+innerClasses[i].outer_class_info_index);
2.655 - }
2.656 - out.print("; //");
2.657 - if (innerClasses[i].inner_name_index!=0) {
2.658 - out.print(cls.getName(innerClasses[i].inner_name_index)+"=");
2.659 - }
2.660 - PrintConstant(innerClasses[i].inner_class_info_index);
2.661 - if (innerClasses[i].outer_class_info_index!=0) {
2.662 - out.print(" of ");
2.663 - PrintConstant(innerClasses[i].outer_class_info_index);
2.664 - }
2.665 - out.println();
2.666 - }
2.667 - }
2.668 -
2.669 - }
2.670 - }
2.671 - }
2.672 -
2.673 - /**
2.674 - * Print constant pool information.
2.675 - */
2.676 - public void printcp(){
2.677 - int cpx = 1 ;
2.678 -
2.679 - while (cpx < cls.getCpoolCount()) {
2.680 - out.print("const #"+cpx+" = ");
2.681 - cpx+=PrintlnConstantEntry(cpx);
2.682 - }
2.683 - out.println();
2.684 - }
2.685 -
2.686 - /**
2.687 - * Print constant pool entry information.
2.688 - */
2.689 - public int PrintlnConstantEntry(int cpx) {
2.690 - int size=1;
2.691 - byte tag=0;
2.692 - try {
2.693 - tag=cls.getTag(cpx);
2.694 - } catch (IndexOutOfBoundsException e) {
2.695 - out.println(" <Incorrect CP index>");
2.696 - return 1;
2.697 - }
2.698 - out.print(cls.StringTag(cpx)+"\t");
2.699 - Object x=cls.getCpoolEntryobj(cpx);
2.700 - if (x==null) {
2.701 - switch (tag) {
2.702 - case CONSTANT_LONG:
2.703 - case CONSTANT_DOUBLE:
2.704 - size=2;
2.705 - }
2.706 - out.println("null;");
2.707 - return size;
2.708 - }
2.709 - String str=cls.StringValue(cpx);
2.710 -
2.711 - switch (tag) {
2.712 - case CONSTANT_CLASS:
2.713 - case CONSTANT_STRING:
2.714 - out.println("#"+(((CPX)x).cpx)+";\t// "+str);
2.715 - break;
2.716 - case CONSTANT_FIELD:
2.717 - case CONSTANT_METHOD:
2.718 - case CONSTANT_INTERFACEMETHOD:
2.719 - out.println("#"+((CPX2)x).cpx1+".#"+((CPX2)x).cpx2+";\t// "+str);
2.720 - break;
2.721 - case CONSTANT_NAMEANDTYPE:
2.722 - out.println("#"+((CPX2)x).cpx1+":#"+((CPX2)x).cpx2+";// "+str);
2.723 - break;
2.724 - case CONSTANT_LONG:
2.725 - case CONSTANT_DOUBLE:
2.726 - size=2;
2.727 - default:
2.728 - out.println(str+";");
2.729 - }
2.730 - return size;
2.731 - }
2.732 -
2.733 - /**
2.734 - * Checks access of class, field or method.
2.735 - */
2.736 - public boolean checkAccess(String accflags[]){
2.737 -
2.738 - boolean ispublic = false;
2.739 - boolean isprotected = false;
2.740 - boolean isprivate = false;
2.741 - boolean ispackage = false;
2.742 -
2.743 - for(int i= 0; i < accflags.length; i++){
2.744 - if(accflags[i].equals("public")) ispublic = true;
2.745 - else if (accflags[i].equals("protected")) isprotected = true;
2.746 - else if (accflags[i].equals("private")) isprivate = true;
2.747 - }
2.748 -
2.749 - if(!(ispublic || isprotected || isprivate)) ispackage = true;
2.750 -
2.751 - if((env.showAccess == env.PUBLIC) && (isprotected || isprivate || ispackage)) return false;
2.752 - else if((env.showAccess == env.PROTECTED) && (isprivate || ispackage)) return false;
2.753 - else if((env.showAccess == env.PACKAGE) && (isprivate)) return false;
2.754 - else return true;
2.755 - }
2.756 -
2.757 - /**
2.758 - * Prints access of class, field or method.
2.759 - */
2.760 - public void printAccess(String []accflags){
2.761 - for(int j = 0; j < accflags.length; j++){
2.762 - out.print(accflags[j]+" ");
2.763 - }
2.764 - }
2.765 -
2.766 - /**
2.767 - * Print an integer so that it takes 'length' characters in
2.768 - * the output. Temporary until formatting code is stable.
2.769 - */
2.770 - public void printFixedWidthInt(long x, int length) {
2.771 - CharArrayWriter baStream = new CharArrayWriter();
2.772 - PrintWriter pStream = new PrintWriter(baStream);
2.773 - pStream.print(x);
2.774 - String str = baStream.toString();
2.775 - for (int cnt = length - str.length(); cnt > 0; --cnt)
2.776 - out.print(' ');
2.777 - out.print(str);
2.778 - }
2.779 -
2.780 - protected int getbyte (int pc) {
2.781 - return code[pc];
2.782 - }
2.783 -
2.784 - protected int getUbyte (int pc) {
2.785 - return code[pc]&0xFF;
2.786 - }
2.787 -
2.788 - int getShort (int pc) {
2.789 - return (code[pc]<<8) | (code[pc+1]&0xFF);
2.790 - }
2.791 -
2.792 - int getUShort (int pc) {
2.793 - return ((code[pc]<<8) | (code[pc+1]&0xFF))&0xFFFF;
2.794 - }
2.795 -
2.796 - protected int getInt (int pc) {
2.797 - return (getShort(pc)<<16) | (getShort(pc+2)&0xFFFF);
2.798 - }
2.799 -
2.800 - /**
2.801 - * Print constant value at that index.
2.802 - */
2.803 - void PrintConstant(int cpx) {
2.804 - if (cpx==0) {
2.805 - out.print("#0");
2.806 - return;
2.807 - }
2.808 - byte tag=0;
2.809 - try {
2.810 - tag=cls.getTag(cpx);
2.811 -
2.812 - } catch (IndexOutOfBoundsException e) {
2.813 - out.print("#"+cpx);
2.814 - return;
2.815 - }
2.816 - switch (tag) {
2.817 - case CONSTANT_METHOD:
2.818 - case CONSTANT_INTERFACEMETHOD:
2.819 - case CONSTANT_FIELD: {
2.820 - // CPX2 x=(CPX2)(cpool[cpx]);
2.821 - CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
2.822 - if (x.cpx1 == cls.getthis_cpx()) {
2.823 - // don't print class part for local references
2.824 - cpx=x.cpx2;
2.825 - }
2.826 - }
2.827 - }
2.828 - out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
2.829 - }
2.830 -
2.831 - protected static int align (int n) {
2.832 - return (n+3) & ~3 ;
2.833 - }
2.834 -
2.835 - public void printend(){
2.836 - out.println("}");
2.837 - out.println();
2.838 - }
2.839 -
2.840 - public String javaclassname(String name){
2.841 - return name.replace('/','.');
2.842 - }
2.843 -
2.844 - /**
2.845 - * Print attribute data in hex.
2.846 - */
2.847 - public void printAttrData(AttrData attr){
2.848 - byte []data = attr.getData();
2.849 - int i = 0;
2.850 - int j = 0;
2.851 - out.print(" "+attr.getAttrName()+": ");
2.852 - out.println("length = " + cls.toHex(attr.datalen));
2.853 -
2.854 - out.print(" ");
2.855 -
2.856 -
2.857 - while (i < data.length){
2.858 - String databytestring = cls.toHex(data[i]);
2.859 - if(databytestring.equals("0x")) out.print("00");
2.860 - else if(databytestring.substring(2).length() == 1){
2.861 - out.print("0"+databytestring.substring(2));
2.862 - } else{
2.863 - out.print(databytestring.substring(2));
2.864 - }
2.865 -
2.866 - j++;
2.867 - if(j == 16) {
2.868 - out.println();
2.869 - out.print(" ");
2.870 - j = 0;
2.871 - }
2.872 - else out.print(" ");
2.873 - i++;
2.874 - }
2.875 - out.println();
2.876 - }
2.877 }
3.1 --- a/javap/src/main/java/sun/tools/javap/Main.java Fri Nov 09 21:33:22 2012 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,216 +0,0 @@
3.4 -/*
3.5 - * Copyright (c) 2002, 2003, 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 -
3.31 -package sun.tools.javap;
3.32 -
3.33 -import java.util.*;
3.34 -import java.io.*;
3.35 -
3.36 -/**
3.37 - * Entry point for javap, class file disassembler.
3.38 - *
3.39 - * @author Sucheta Dambalkar (Adopted code from old javap)
3.40 - */
3.41 -public class Main{
3.42 -
3.43 - private Vector classList = new Vector();
3.44 - private PrintWriter out;
3.45 - JavapEnvironment env = new JavapEnvironment();
3.46 - private static boolean errorOccurred = false;
3.47 - private static final String progname = "javap";
3.48 -
3.49 -
3.50 - public Main(PrintWriter out){
3.51 - this.out = out;
3.52 - }
3.53 -
3.54 - public static void main(String argv[]) {
3.55 - entry(argv);
3.56 - if (errorOccurred) {
3.57 - System.exit(1);
3.58 - }
3.59 - }
3.60 -
3.61 -
3.62 - /**
3.63 - * Entry point for tool if you don't want System.exit() called.
3.64 - */
3.65 - public static void entry(String argv[]) {
3.66 - PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
3.67 - try {
3.68 -
3.69 - Main jpmain = new Main(out);
3.70 - jpmain.perform(argv);
3.71 -
3.72 - } finally {
3.73 - out.close();
3.74 - }
3.75 - }
3.76 -
3.77 - /**
3.78 - * Process the arguments and perform the desired action
3.79 - */
3.80 - private void perform(String argv[]) {
3.81 - if (parseArguments(argv)) {
3.82 - displayResults();
3.83 -
3.84 - }
3.85 - }
3.86 -
3.87 - private void error(String msg) {
3.88 - errorOccurred = true;
3.89 - System.err.println(msg);
3.90 - System.err.flush();
3.91 - }
3.92 -
3.93 - /**
3.94 - * Print usage information
3.95 - */
3.96 - private void usage() {
3.97 - java.io.PrintStream out = System.out;
3.98 - out.println("Usage: " + progname + " <options> <classes>...");
3.99 - out.println();
3.100 - out.println("where options include:");
3.101 - out.println(" -c Disassemble the code");
3.102 - out.println(" -classpath <pathlist> Specify where to find user class files");
3.103 - out.println(" -extdirs <dirs> Override location of installed extensions");
3.104 - out.println(" -help Print this usage message");
3.105 - out.println(" -J<flag> Pass <flag> directly to the runtime system");
3.106 - out.println(" -l Print line number and local variable tables");
3.107 - out.println(" -public Show only public classes and members");
3.108 - out.println(" -protected Show protected/public classes and members");
3.109 - out.println(" -package Show package/protected/public classes");
3.110 - out.println(" and members (default)");
3.111 - out.println(" -private Show all classes and members");
3.112 - out.println(" -s Print internal type signatures");
3.113 - out.println(" -bootclasspath <pathlist> Override location of class files loaded");
3.114 - out.println(" by the bootstrap class loader");
3.115 - out.println(" -verbose Print stack size, number of locals and args for methods");
3.116 - out.println(" If verifying, print reasons for failure");
3.117 - out.println();
3.118 - }
3.119 -
3.120 - /**
3.121 - * Parse the command line arguments.
3.122 - * Set flags, construct the class list and create environment.
3.123 - */
3.124 - private boolean parseArguments(String argv[]) {
3.125 - for (int i = 0 ; i < argv.length ; i++) {
3.126 - String arg = argv[i];
3.127 - if (arg.startsWith("-")) {
3.128 - if (arg.equals("-l")) {
3.129 - env.showLineAndLocal = true;
3.130 - } else if (arg.equals("-private") || arg.equals("-p")) {
3.131 - env.showAccess = env.PRIVATE;
3.132 - } else if (arg.equals("-package")) {
3.133 - env.showAccess = env.PACKAGE;
3.134 - } else if (arg.equals("-protected")) {
3.135 - env.showAccess = env.PROTECTED;
3.136 - } else if (arg.equals("-public")) {
3.137 - env.showAccess = env.PUBLIC;
3.138 - } else if (arg.equals("-c")) {
3.139 - env.showDisassembled = true;
3.140 - } else if (arg.equals("-s")) {
3.141 - env.showInternalSigs = true;
3.142 - } else if (arg.equals("-verbose")) {
3.143 - env.showVerbose = true;
3.144 - } else if (arg.equals("-v")) {
3.145 - env.showVerbose = true;
3.146 - } else if (arg.equals("-h")) {
3.147 - error("-h is no longer available - use the 'javah' program");
3.148 - return false;
3.149 - } else if (arg.equals("-verify")) {
3.150 - error("-verify is no longer available - use 'java -verify'");
3.151 - return false;
3.152 - } else if (arg.equals("-verify-verbose")) {
3.153 - error("-verify is no longer available - use 'java -verify'");
3.154 - return false;
3.155 - } else if (arg.equals("-help")) {
3.156 - usage();
3.157 - return false;
3.158 - } else if (arg.equals("-classpath")) {
3.159 - if ((i + 1) < argv.length) {
3.160 - env.classPathString = argv[++i];
3.161 - } else {
3.162 - error("-classpath requires argument");
3.163 - usage();
3.164 - return false;
3.165 - }
3.166 - } else if (arg.equals("-bootclasspath")) {
3.167 - if ((i + 1) < argv.length) {
3.168 - env.bootClassPathString = argv[++i];
3.169 - } else {
3.170 - error("-bootclasspath requires argument");
3.171 - usage();
3.172 - return false;
3.173 - }
3.174 - } else if (arg.equals("-extdirs")) {
3.175 - if ((i + 1) < argv.length) {
3.176 - env.extDirsString = argv[++i];
3.177 - } else {
3.178 - error("-extdirs requires argument");
3.179 - usage();
3.180 - return false;
3.181 - }
3.182 - } else if (arg.equals("-all")) {
3.183 - env.showallAttr = true;
3.184 - } else {
3.185 - error("invalid flag: " + arg);
3.186 - usage();
3.187 - return false;
3.188 - }
3.189 - } else {
3.190 - classList.addElement(arg);
3.191 - env.nothingToDo = false;
3.192 - }
3.193 - }
3.194 - if (env.nothingToDo) {
3.195 - System.out.println("No classes were specified on the command line. Try -help.");
3.196 - errorOccurred = true;
3.197 - return false;
3.198 - }
3.199 - return true;
3.200 - }
3.201 -
3.202 - /**
3.203 - * Display results
3.204 - */
3.205 - private void displayResults() {
3.206 - for (int i = 0; i < classList.size() ; i++ ) {
3.207 - String Name = (String)classList.elementAt(i);
3.208 - InputStream classin = env.getFileInputStream(Name);
3.209 -
3.210 - try {
3.211 - JavapPrinter printer = new JavapPrinter(classin, out, env);
3.212 - printer.print(); // actual do display
3.213 -
3.214 - } catch (IllegalArgumentException exc) {
3.215 - error(exc.getMessage());
3.216 - }
3.217 - }
3.218 - }
3.219 -}