8032869: remove support for legacy options in javap

Reviewed-by: ksrini
This commit is contained in:
Jonathan Gibbons 2014-01-29 14:32:27 -08:00
parent 77feb9302c
commit 214de0eb69
7 changed files with 29 additions and 105 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -71,10 +71,6 @@ public abstract class Attribute {
// defer init of standardAttributeClasses until after options set up // 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) public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
throws IOException { throws IOException {
if (standardAttributes == null) { if (standardAttributes == null) {
@ -112,6 +108,7 @@ public abstract class Attribute {
standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class); standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class);
standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class); standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
standardAttributes.put(Code, Code_attribute.class); standardAttributes.put(Code, Code_attribute.class);
standardAttributes.put(CompilationID, CompilationID_attribute.class);
standardAttributes.put(ConstantValue, ConstantValue_attribute.class); standardAttributes.put(ConstantValue, ConstantValue_attribute.class);
standardAttributes.put(Deprecated, Deprecated_attribute.class); standardAttributes.put(Deprecated, Deprecated_attribute.class);
standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class); standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class);
@ -120,10 +117,7 @@ public abstract class Attribute {
standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class); standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class);
standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class); standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class);
standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_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(MethodParameters, MethodParameters_attribute.class);
standardAttributes.put(CompilationID, CompilationID_attribute.class);
standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class); standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class); standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class); standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
@ -131,18 +125,15 @@ public abstract class Attribute {
standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class); standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class); standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
standardAttributes.put(Signature, Signature_attribute.class); standardAttributes.put(Signature, Signature_attribute.class);
standardAttributes.put(SourceID, SourceID_attribute.class);
}
standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class); standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class);
standardAttributes.put(SourceFile, SourceFile_attribute.class); standardAttributes.put(SourceFile, SourceFile_attribute.class);
standardAttributes.put(SourceID, SourceID_attribute.class);
standardAttributes.put(StackMap, StackMap_attribute.class); standardAttributes.put(StackMap, StackMap_attribute.class);
standardAttributes.put(StackMapTable, StackMapTable_attribute.class); standardAttributes.put(StackMapTable, StackMapTable_attribute.class);
standardAttributes.put(Synthetic, Synthetic_attribute.class); standardAttributes.put(Synthetic, Synthetic_attribute.class);
} }
private Map<String,Class<? extends Attribute>> standardAttributes; 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 { public static Attribute read(ClassReader cr) throws IOException {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -227,9 +227,6 @@ public class AttributeWriter extends BasicWriter
} }
public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) { 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); constantWriter.write(attr.constantvalue_index);
println(); println();
@ -291,20 +288,10 @@ public class AttributeWriter extends BasicWriter
public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) {
boolean first = true; boolean first = true;
if (options.compat) {
writeInnerClassHeader();
first = false;
}
for (int i = 0 ; i < attr.classes.length; i++) { for (int i = 0 ; i < attr.classes.length; i++) {
InnerClasses_attribute.Info info = attr.classes[i]; InnerClasses_attribute.Info info = attr.classes[i];
//access //access
AccessFlags access_flags = info.inner_class_access_flags; 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 (options.checkAccess(access_flags)) {
if (first) { if (first) {
writeInnerClassHeader(); writeInnerClassHeader();
@ -346,11 +333,7 @@ public class AttributeWriter extends BasicWriter
} }
private void writeInnerClassHeader() { private void writeInnerClassHeader() {
if (options.compat) // BUG 6622216: javap names some attributes incorrectly println("InnerClasses:");
print("InnerClass");
else
print("InnerClasses");
println(":");
indent(+1); indent(+1);
} }
@ -711,9 +694,6 @@ public class AttributeWriter extends BasicWriter
} }
String toHex(byte b, int w) { 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);
} }

View file

@ -120,7 +120,7 @@ public class ClassWriter extends BasicWriter {
public void write(ClassFile cf) { public void write(ClassFile cf) {
setClassFile(cf); setClassFile(cf);
if ((options.sysInfo || options.verbose) && !options.compat) { if (options.sysInfo || options.verbose) {
if (uri != null) { if (uri != null) {
if (uri.getScheme().equals("file")) if (uri.getScheme().equals("file"))
println("Classfile " + uri.getPath()); println("Classfile " + uri.getPath());
@ -152,7 +152,7 @@ public class ClassWriter extends BasicWriter {
println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\""); println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\"");
} }
if ((options.sysInfo || options.verbose) && !options.compat) { if (options.sysInfo || options.verbose) {
indent(-1); indent(-1);
} }
@ -205,7 +205,6 @@ public class ClassWriter extends BasicWriter {
attrWriter.write(cf, cf.attributes, constant_pool); attrWriter.write(cf, cf.attributes, constant_pool);
println("minor version: " + cf.minor_version); println("minor version: " + cf.minor_version);
println("major version: " + cf.major_version); println("major version: " + cf.major_version);
if (!options.compat)
writeList("flags: ", flags.getClassFlags(), "\n"); writeList("flags: ", flags.getClassFlags(), "\n");
indent(-1); indent(-1);
constantWriter.writeConstantPool(); constantWriter.writeConstantPool();
@ -372,7 +371,7 @@ public class ClassWriter extends BasicWriter {
} }
print(" "); print(" ");
print(getFieldName(f)); 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); Attribute a = f.attributes.get(Attribute.ConstantValue);
if (a instanceof ConstantValue_attribute) { if (a instanceof ConstantValue_attribute) {
print(" = "); print(" = ");
@ -390,7 +389,7 @@ public class ClassWriter extends BasicWriter {
if (options.showDescriptors) if (options.showDescriptors)
println("descriptor: " + getValue(f.descriptor)); println("descriptor: " + getValue(f.descriptor));
if (options.verbose && !options.compat) if (options.verbose)
writeList("flags: ", flags.getFieldFlags(), "\n"); writeList("flags: ", flags.getFieldFlags(), "\n");
if (options.showAllAttrs) { if (options.showAllAttrs) {
@ -487,7 +486,7 @@ public class ClassWriter extends BasicWriter {
println("descriptor: " + getValue(m.descriptor)); println("descriptor: " + getValue(m.descriptor));
} }
if (options.verbose && !options.compat) { if (options.verbose) {
writeList("flags: ", flags.getMethodFlags(), "\n"); writeList("flags: ", flags.getMethodFlags(), "\n");
} }
@ -553,13 +552,11 @@ public class ClassWriter extends BasicWriter {
} }
Signature_attribute getSignature(Attributes attributes) { Signature_attribute getSignature(Attributes attributes) {
if (options.compat) // javap does not recognize recent attributes
return null;
return (Signature_attribute) attributes.get(Attribute.Signature); return (Signature_attribute) attributes.get(Attribute.Signature);
} }
String adjustVarargs(AccessFlags flags, String params) { String adjustVarargs(AccessFlags flags, String params) {
if (flags.is(ACC_VARARGS) && !options.compat) { if (flags.is(ACC_VARARGS)) {
int i = params.lastIndexOf("[]"); int i = params.lastIndexOf("[]");
if (i > 0) if (i > 0)
return params.substring(0, i) + "..." + params.substring(i+2); return params.substring(0, i) + "..." + params.substring(i+2);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -195,48 +195,12 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
} }
}, },
// 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") { new Option(false, "-sysinfo") {
void process(JavapTask task, String opt, String arg) { void process(JavapTask task, String opt, String arg) {
task.options.sysInfo = true; 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") { new Option(false, "-XDdetails") {
void process(JavapTask task, String opt, String arg) { void process(JavapTask task, String opt, String arg) {
task.options.details = EnumSet.allOf(InstructionDetailWriter.Kind.class); task.options.details = EnumSet.allOf(InstructionDetailWriter.Kind.class);
@ -520,7 +484,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
throw new BadArgs("err.unknown.option", arg).showUsage(true); 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(); StringBuilder sb = new StringBuilder();
for (String opt: options.accessOptions) { for (String opt: options.accessOptions) {
if (sb.length() > 0) if (sb.length() > 0)
@ -581,8 +545,6 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
SourceWriter sourceWriter = SourceWriter.instance(context); SourceWriter sourceWriter = SourceWriter.instance(context);
sourceWriter.setFileManager(fileManager); sourceWriter.setFileManager(fileManager);
attributeFactory.setCompat(options.compat);
int result = EXIT_OK; int result = EXIT_OK;
for (String className: classes) { for (String className: classes) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -88,6 +88,4 @@ public class Options {
public boolean showInnerClasses; public boolean showInnerClasses;
public int indentWidth = 2; // #spaces per indentWidth level public int indentWidth = 2; // #spaces per indentWidth level
public int tabColumn = 40; // column number for comments public int tabColumn = 40; // column number for comments
public boolean compat; // bug-for-bug compatibility mode with old javap
} }

View file

@ -6,7 +6,6 @@ err.class.not.found=class not found: {0}
err.crash=A serious internal error has occurred: {0}\nPlease file a bug report, and include the following information:\n{1} 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.end.of.file=unexpected end of file while reading {0}
err.file.not.found=file not found: {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.incompatible.options=bad combination of options: {0}
err.internal.error=internal error: {0} {1} {2} err.internal.error=internal error: {0} {1} {2}
err.invalid.arg.for.option=invalid argument for option: {0} err.invalid.arg.for.option=invalid argument for option: {0}
@ -15,11 +14,9 @@ err.missing.arg=no value given for {0}
err.no.classes.specified=no classes specified err.no.classes.specified=no classes specified
err.not.standard.file.manager=can only specify class files when using a standard file manager err.not.standard.file.manager=can only specify class files when using a standard file manager
err.unknown.option=unknown option: {0} err.unknown.option=unknown option: {0}
err.verify.not.supported=-verify not supported
err.no.SourceFile.attribute=no SourceFile attribute err.no.SourceFile.attribute=no SourceFile attribute
err.source.file.not.found=source file not found err.source.file.not.found=source file not found
err.bad.innerclasses.attribute=bad InnerClasses attribute for {0} err.bad.innerclasses.attribute=bad InnerClasses attribute for {0}
warn.Xold.not.supported=-Xold is no longer available
main.usage.summary=\ main.usage.summary=\
Usage: {0} <options> <classes>\n\ Usage: {0} <options> <classes>\n\

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
/* /*
* @test * @test
* @bug 8027411 * @bug 8027411 8032869
* @summary test invalid options -h and -b * @summary test an invalid option
*/ */
import java.io.*; import java.io.*;
@ -39,7 +39,6 @@ public class InvalidOptions {
} }
void run() throws Exception { void run() throws Exception {
test(2, "-h", "Error: -h is no longer available - use the javah program");
test(2, "-b", "Error: unknown option: -b", test(2, "-b", "Error: unknown option: -b",
"Usage: javap <options> <classes>", "Usage: javap <options> <classes>",
"use -help for a list of possible options"); "use -help for a list of possible options");