changeset 2345:3fbda1dca565

8032869: remove support for legacy options in javap Reviewed-by: ksrini
author kizune
date Mon, 03 Mar 2014 16:08:06 +0400
parents 4267f38a1706
children 21685ef33d2b 27c08b9195d1
files src/share/classes/com/sun/tools/classfile/Attribute.java src/share/classes/com/sun/tools/javap/AttributeWriter.java src/share/classes/com/sun/tools/javap/ClassWriter.java src/share/classes/com/sun/tools/javap/JavapTask.java src/share/classes/com/sun/tools/javap/Options.java src/share/classes/com/sun/tools/javap/resources/javap.properties test/tools/javap/InvalidOptions.java
diffstat 7 files changed, 23 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/classfile/Attribute.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/classfile/Attribute.java	Mon Mar 03 16:08:06 2014 +0400
@@ -71,10 +71,6 @@
             // defer init of standardAttributeClasses until after options set up
         }
 
-        public void setCompat(boolean compat) {
-            this.compat = compat;
-        }
-
         public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
                 throws IOException {
             if (standardAttributes == null) {
@@ -109,9 +105,10 @@
         protected void init() {
             standardAttributes = new HashMap<String,Class<? extends Attribute>>();
             standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
-            standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class);
+            standardAttributes.put(BootstrapMethods,  BootstrapMethods_attribute.class);
             standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
             standardAttributes.put(Code,              Code_attribute.class);
+            standardAttributes.put(CompilationID,     CompilationID_attribute.class);
             standardAttributes.put(ConstantValue,     ConstantValue_attribute.class);
             standardAttributes.put(Deprecated,        Deprecated_attribute.class);
             standardAttributes.put(EnclosingMethod,   EnclosingMethod_attribute.class);
@@ -120,29 +117,23 @@
             standardAttributes.put(LineNumberTable,   LineNumberTable_attribute.class);
             standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class);
             standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class);
-
-            if (!compat) { // old javap does not recognize recent attributes
-                standardAttributes.put(MethodParameters, MethodParameters_attribute.class);
-                standardAttributes.put(CompilationID, CompilationID_attribute.class);
-                standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
-                standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
-                standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
-                standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
-                standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
-                standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
-                standardAttributes.put(Signature,     Signature_attribute.class);
-                standardAttributes.put(SourceID, SourceID_attribute.class);
-            }
-
+            standardAttributes.put(MethodParameters,  MethodParameters_attribute.class);
+            standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
+            standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
+            standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
+            standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
+            standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
+            standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
+            standardAttributes.put(Signature,         Signature_attribute.class);
             standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class);
             standardAttributes.put(SourceFile,        SourceFile_attribute.class);
+            standardAttributes.put(SourceID,          SourceID_attribute.class);
             standardAttributes.put(StackMap,          StackMap_attribute.class);
             standardAttributes.put(StackMapTable,     StackMapTable_attribute.class);
             standardAttributes.put(Synthetic,         Synthetic_attribute.class);
         }
 
         private Map<String,Class<? extends Attribute>> standardAttributes;
-        private boolean compat; // don't support recent attrs in compatibility mode
     }
 
     public static Attribute read(ClassReader cr) throws IOException {
--- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Mon Mar 03 16:08:06 2014 +0400
@@ -226,10 +226,7 @@
     }
 
     public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) {
-        if (options.compat) // BUG 6622216 javap names some attributes incorrectly
-            print("Constant value: ");
-        else
-            print("ConstantValue: ");
+        print("ConstantValue: ");
         constantWriter.write(attr.constantvalue_index);
         println();
         return null;
@@ -290,20 +287,10 @@
 
     public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) {
         boolean first = true;
-        if (options.compat) {
-            writeInnerClassHeader();
-            first = false;
-        }
         for (int i = 0 ; i < attr.classes.length; i++) {
             InnerClasses_attribute.Info info = attr.classes[i];
             //access
             AccessFlags access_flags = info.inner_class_access_flags;
-            if (options.compat) {
-                // BUG 6622215: javap ignores certain relevant access flags
-                access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM);
-                // BUG 6622232: javap gets whitespace confused
-                print("   ");
-            }
             if (options.checkAccess(access_flags)) {
                 if (first) {
                     writeInnerClassHeader();
@@ -345,11 +332,7 @@
     }
 
     private void writeInnerClassHeader() {
-        if (options.compat) // BUG 6622216: javap names some attributes incorrectly
-            print("InnerClass");
-        else
-            print("InnerClasses");
-        println(":");
+        println("InnerClasses:");
         indent(+1);
     }
 
@@ -703,10 +686,7 @@
     }
 
     String toHex(byte b, int w) {
-        if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex
-            return toHex((int) b, w);
-        else
-            return toHex(b & 0xff, w);
+        return toHex(b & 0xff, w);
     }
 
     static String toHex(int i) {
--- a/src/share/classes/com/sun/tools/javap/ClassWriter.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java	Mon Mar 03 16:08:06 2014 +0400
@@ -120,7 +120,7 @@
     public void write(ClassFile cf) {
         setClassFile(cf);
 
-        if ((options.sysInfo || options.verbose) && !options.compat) {
+        if (options.sysInfo || options.verbose) {
             if (uri != null) {
                 if (uri.getScheme().equals("file"))
                     println("Classfile " + uri.getPath());
@@ -152,7 +152,7 @@
             println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\"");
         }
 
-        if ((options.sysInfo || options.verbose) && !options.compat) {
+        if (options.sysInfo || options.verbose) {
             indent(-1);
         }
 
@@ -205,8 +205,7 @@
             attrWriter.write(cf, cf.attributes, constant_pool);
             println("minor version: " + cf.minor_version);
             println("major version: " + cf.major_version);
-            if (!options.compat)
-              writeList("flags: ", flags.getClassFlags(), "\n");
+            writeList("flags: ", flags.getClassFlags(), "\n");
             indent(-1);
             constantWriter.writeConstantPool();
         } else {
@@ -372,7 +371,7 @@
         }
         print(" ");
         print(getFieldName(f));
-        if (options.showConstants && !options.compat) { // BUG 4111861 print static final field contents
+        if (options.showConstants) {
             Attribute a = f.attributes.get(Attribute.ConstantValue);
             if (a instanceof ConstantValue_attribute) {
                 print(" = ");
@@ -390,7 +389,7 @@
         if (options.showDescriptors)
             println("descriptor: " + getValue(f.descriptor));
 
-        if (options.verbose && !options.compat)
+        if (options.verbose)
             writeList("flags: ", flags.getFieldFlags(), "\n");
 
         if (options.showAllAttrs) {
@@ -487,7 +486,7 @@
             println("descriptor: " + getValue(m.descriptor));
         }
 
-        if (options.verbose && !options.compat) {
+        if (options.verbose) {
             writeList("flags: ", flags.getMethodFlags(), "\n");
         }
 
@@ -553,13 +552,11 @@
     }
 
     Signature_attribute getSignature(Attributes attributes) {
-        if (options.compat) // javap does not recognize recent attributes
-            return null;
         return (Signature_attribute) attributes.get(Attribute.Signature);
     }
 
     String adjustVarargs(AccessFlags flags, String params) {
-        if (flags.is(ACC_VARARGS) && !options.compat) {
+        if (flags.is(ACC_VARARGS)) {
             int i = params.lastIndexOf("[]");
             if (i > 0)
                 return params.substring(0, i) + "..." + params.substring(i+2);
--- a/src/share/classes/com/sun/tools/javap/JavapTask.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/javap/JavapTask.java	Mon Mar 03 16:08:06 2014 +0400
@@ -195,48 +195,12 @@
             }
         },
 
-//        new Option(false, "-all") {
-//            void process(JavapTask task, String opt, String arg) {
-//                task.options.showAllAttrs = true;
-//            }
-//        },
-
-        new Option(false, "-h") {
-            void process(JavapTask task, String opt, String arg) throws BadArgs {
-                throw task.new BadArgs("err.h.not.supported");
-            }
-        },
-
-        new Option(false, "-verify", "-verify-verbose") {
-            void process(JavapTask task, String opt, String arg) throws BadArgs {
-                throw task.new BadArgs("err.verify.not.supported");
-            }
-        },
-
         new Option(false, "-sysinfo") {
             void process(JavapTask task, String opt, String arg) {
                 task.options.sysInfo = true;
             }
         },
 
-        new Option(false, "-Xold") {
-            void process(JavapTask task, String opt, String arg) throws BadArgs {
-                task.log.println(task.getMessage("warn.Xold.not.supported"));
-            }
-        },
-
-        new Option(false, "-Xnew") {
-            void process(JavapTask task, String opt, String arg) throws BadArgs {
-                // ignore: this _is_ the new version
-            }
-        },
-
-        new Option(false, "-XDcompat") {
-            void process(JavapTask task, String opt, String arg) {
-                task.options.compat = true;
-            }
-        },
-
         new Option(false, "-XDdetails") {
             void process(JavapTask task, String opt, String arg) {
                 task.options.details = EnumSet.allOf(InstructionDetailWriter.Kind.class);
@@ -524,7 +488,7 @@
                 throw new BadArgs("err.unknown.option", arg).showUsage(true);
         }
 
-        if (!options.compat && options.accessOptions.size() > 1) {
+        if (options.accessOptions.size() > 1) {
             StringBuilder sb = new StringBuilder();
             for (String opt: options.accessOptions) {
                 if (sb.length() > 0)
@@ -589,8 +553,6 @@
         SourceWriter sourceWriter = SourceWriter.instance(context);
         sourceWriter.setFileManager(fileManager);
 
-        attributeFactory.setCompat(options.compat);
-
         int result = EXIT_OK;
 
         for (String className: classes) {
--- a/src/share/classes/com/sun/tools/javap/Options.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/javap/Options.java	Mon Mar 03 16:08:06 2014 +0400
@@ -88,6 +88,4 @@
     public boolean showInnerClasses;
     public int indentWidth = 2;   // #spaces per indentWidth level; must be > 0
     public int tabColumn = 40;    // column number for comments; must be > 0
-
-    public boolean compat;             // bug-for-bug compatibility mode with old javap
 }
--- a/src/share/classes/com/sun/tools/javap/resources/javap.properties	Thu Feb 20 18:28:46 2014 +0400
+++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties	Mon Mar 03 16:08:06 2014 +0400
@@ -6,7 +6,6 @@
 err.crash=A serious internal error has occurred: {0}\nPlease file a bug report, and include the following information:\n{1}
 err.end.of.file=unexpected end of file while reading {0}
 err.file.not.found=file not found: {0}
-err.h.not.supported=-h is no longer available - use the 'javah' program
 err.incompatible.options=bad combination of options: {0}
 err.internal.error=internal error: {0} {1} {2}
 err.invalid.arg.for.option=invalid argument for option: {0}
@@ -16,11 +15,9 @@
 err.not.standard.file.manager=can only specify class files when using a standard file manager
 err.invalid.use.of.option=invalid use of option: {0}
 err.unknown.option=unknown option: {0}
-err.verify.not.supported=-verify not supported
 err.no.SourceFile.attribute=no SourceFile attribute
 err.source.file.not.found=source file not found
 err.bad.innerclasses.attribute=bad InnerClasses attribute for {0}
-warn.Xold.not.supported=-Xold is no longer available
 
 main.usage.summary=\
 Usage: {0} <options> <classes>\n\
--- a/test/tools/javap/InvalidOptions.java	Thu Feb 20 18:28:46 2014 +0400
+++ b/test/tools/javap/InvalidOptions.java	Mon Mar 03 16:08:06 2014 +0400
@@ -24,7 +24,7 @@
 /*
  * @test
  * @bug 8027411
- * @summary test invalid options -h and -b
+ * @summary test an invalid option
  */
 
 import java.io.*;
@@ -39,7 +39,6 @@
     }
 
     void run() throws Exception {
-        test(2, "-h", "Error: -h is no longer available - use the javah program");
         test(2, "-b", "Error: unknown option: -b",
                       "Usage: javap <options> <classes>",
                       "use -help for a list of possible options");