Wed, 19 Feb 2014 21:01:41 -0800
Merge
.hgtags | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Wed Feb 19 13:14:43 2014 -0800 1.2 +++ b/.hgtags Wed Feb 19 21:01:41 2014 -0800 1.3 @@ -248,4 +248,9 @@ 1.4 d5aab8300d3b51e8043ab5fe5832ef6c6cbb5552 jdk8u20-b00 1.5 436176151e85455e74cd1441a2ba96e791c56785 jdk8-b124 1.6 79dc4b992c0a385c1364592801781b747b85c6ca jdk8u20-b01 1.7 +436176151e85455e74cd1441a2ba96e791c56785 jdk8-b125 1.8 +ba24b63043626003929927f091e8b84190f39261 jdk8-b126 1.9 +bb69217ed81202b1a490dc7150dc7cd073689341 jdk8-b127 1.10 +09cdd3b493c0d13dc32206e5f12bb1a2f7465687 jdk8-b128 1.11 +8fe7202d3c38784f3f14368e3954fc4e0394afa4 jdk8-b129 1.12 26b33a6ea08810853af37e81c9b435465b289c98 jdk8u20-b02
2.1 --- a/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Wed Feb 19 13:14:43 2014 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Wed Feb 19 21:01:41 2014 -0800 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -1172,8 +1172,10 @@ 2.11 DCText string = quotedString(); 2.12 if (string != null) { 2.13 skipWhitespace(); 2.14 - if (ch == '@') 2.15 + if (ch == '@' 2.16 + || ch == EOI && bp == buf.length - 1) { 2.17 return m.at(pos).See(List.<DCTree>of(string)); 2.18 + } 2.19 } 2.20 break; 2.21
3.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Feb 19 13:14:43 2014 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Feb 19 21:01:41 2014 -0800 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -30,6 +30,7 @@ 3.11 import java.util.Collection; 3.12 import java.util.EnumSet; 3.13 import java.util.HashMap; 3.14 +import java.util.HashSet; 3.15 import java.util.Map; 3.16 import java.util.Set; 3.17 import javax.tools.JavaFileManager.Location; 3.18 @@ -238,10 +239,13 @@ 3.19 files = lb.toList(); 3.20 } 3.21 3.22 + Set<JavaFileObject> ufiles = new HashSet<>(); 3.23 for (JavaFileObject fo : files) { 3.24 - // messager.notice("main.Loading_source_file", fn); 3.25 - trees.append(parse(fo)); 3.26 - hasFiles = true; 3.27 + if (ufiles.add(fo)) { // ignore duplicates 3.28 + // messager.notice("main.Loading_source_file", fn); 3.29 + trees.append(parse(fo)); 3.30 + hasFiles = true; 3.31 + } 3.32 } 3.33 3.34 if (!hasFiles) {
4.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Wed Feb 19 13:14:43 2014 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Wed Feb 19 21:01:41 2014 -0800 4.3 @@ -547,7 +547,6 @@ 4.4 for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 4.5 w.write(entry); 4.6 } 4.7 - println(); 4.8 indent(-1); 4.9 return null; 4.10 } 4.11 @@ -559,7 +558,6 @@ 4.12 for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 4.13 w.write(entry); 4.14 } 4.15 - println(); 4.16 indent(-1); 4.17 return null; 4.18 } 4.19 @@ -571,14 +569,12 @@ 4.20 } 4.21 4.22 public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) { 4.23 - printHeader(frame); 4.24 - println(" /* same */"); 4.25 + printHeader(frame, "/* same */"); 4.26 return null; 4.27 } 4.28 4.29 public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) { 4.30 - printHeader(frame); 4.31 - println(" /* same_locals_1_stack_item */"); 4.32 + printHeader(frame, "/* same_locals_1_stack_item */"); 4.33 indent(+1); 4.34 printMap("stack", frame.stack); 4.35 indent(-1); 4.36 @@ -586,8 +582,7 @@ 4.37 } 4.38 4.39 public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) { 4.40 - printHeader(frame); 4.41 - println(" /* same_locals_1_stack_item_frame_extended */"); 4.42 + printHeader(frame, "/* same_locals_1_stack_item_frame_extended */"); 4.43 indent(+1); 4.44 println("offset_delta = " + frame.offset_delta); 4.45 printMap("stack", frame.stack); 4.46 @@ -596,8 +591,7 @@ 4.47 } 4.48 4.49 public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) { 4.50 - printHeader(frame); 4.51 - println(" /* chop */"); 4.52 + printHeader(frame, "/* chop */"); 4.53 indent(+1); 4.54 println("offset_delta = " + frame.offset_delta); 4.55 indent(-1); 4.56 @@ -605,8 +599,7 @@ 4.57 } 4.58 4.59 public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) { 4.60 - printHeader(frame); 4.61 - println(" /* same_frame_extended */"); 4.62 + printHeader(frame, "/* same_frame_extended */"); 4.63 indent(+1); 4.64 println("offset_delta = " + frame.offset_delta); 4.65 indent(-1); 4.66 @@ -614,21 +607,20 @@ 4.67 } 4.68 4.69 public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) { 4.70 - printHeader(frame); 4.71 - println(" /* append */"); 4.72 + printHeader(frame, "/* append */"); 4.73 indent(+1); 4.74 println("offset_delta = " + frame.offset_delta); 4.75 printMap("locals", frame.locals); 4.76 + indent(-1); 4.77 return null; 4.78 } 4.79 4.80 public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) { 4.81 - printHeader(frame); 4.82 if (frame instanceof StackMap_attribute.stack_map_frame) { 4.83 + printHeader(frame, "offset = " + frame.offset_delta); 4.84 indent(+1); 4.85 - println(" offset = " + frame.offset_delta); 4.86 } else { 4.87 - println(" /* full_frame */"); 4.88 + printHeader(frame, "/* full_frame */"); 4.89 indent(+1); 4.90 println("offset_delta = " + frame.offset_delta); 4.91 } 4.92 @@ -638,8 +630,9 @@ 4.93 return null; 4.94 } 4.95 4.96 - void printHeader(StackMapTable_attribute.stack_map_frame frame) { 4.97 - print(" frame_type = " + frame.frame_type); 4.98 + void printHeader(StackMapTable_attribute.stack_map_frame frame, String extra) { 4.99 + print("frame_type = " + frame.frame_type + " "); 4.100 + println(extra); 4.101 } 4.102 4.103 void printMap(String name, StackMapTable_attribute.verification_type_info[] map) {
5.1 --- a/src/share/classes/com/sun/tools/javap/BasicWriter.java Wed Feb 19 13:14:43 2014 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javap/BasicWriter.java Wed Feb 19 21:01:41 2014 -0800 5.3 @@ -151,12 +151,22 @@ 5.4 for (int i = 0; i < s.length(); i++) { 5.5 char c = s.charAt(i); 5.6 switch (c) { 5.7 + case ' ': 5.8 + pendingSpaces++; 5.9 + break; 5.10 + 5.11 case '\n': 5.12 println(); 5.13 break; 5.14 + 5.15 default: 5.16 if (buffer.length() == 0) 5.17 indent(); 5.18 + if (pendingSpaces > 0) { 5.19 + for (int sp = 0; sp < pendingSpaces; sp++) 5.20 + buffer.append(' '); 5.21 + pendingSpaces = 0; 5.22 + } 5.23 buffer.append(c); 5.24 } 5.25 } 5.26 @@ -164,6 +174,8 @@ 5.27 } 5.28 5.29 protected void println() { 5.30 + // ignore/discard pending spaces 5.31 + pendingSpaces = 0; 5.32 out.println(buffer); 5.33 buffer.setLength(0); 5.34 } 5.35 @@ -173,26 +185,21 @@ 5.36 } 5.37 5.38 protected void tab() { 5.39 - if (buffer.length() == 0) 5.40 - indent(); 5.41 - space(indentCount * indentWidth + tabColumn - buffer.length()); 5.42 + int col = indentCount * indentWidth + tabColumn; 5.43 + pendingSpaces += (col <= buffer.length() ? 1 : col - buffer.length()); 5.44 } 5.45 5.46 private void indent() { 5.47 - space(indentCount * indentWidth); 5.48 + pendingSpaces += (indentCount * indentWidth); 5.49 } 5.50 5.51 - private void space(int n) { 5.52 - for (int i = 0; i < n; i++) 5.53 - buffer.append(' '); 5.54 - } 5.55 - 5.56 - private PrintWriter out; 5.57 - private StringBuilder buffer; 5.58 + private final PrintWriter out; 5.59 + private final StringBuilder buffer; 5.60 private int indentCount; 5.61 - private int indentWidth; 5.62 - private int tabColumn; 5.63 + private final int indentWidth; 5.64 + private final int tabColumn; 5.65 private boolean pendingNewline; 5.66 + private int pendingSpaces; 5.67 } 5.68 } 5.69
6.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Wed Feb 19 13:14:43 2014 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Wed Feb 19 21:01:41 2014 -0800 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -385,6 +385,8 @@ 6.11 6.12 indent(+1); 6.13 6.14 + boolean showBlank = false; 6.15 + 6.16 if (options.showDescriptors) 6.17 println("descriptor: " + getValue(f.descriptor)); 6.18 6.19 @@ -394,12 +396,12 @@ 6.20 if (options.showAllAttrs) { 6.21 for (Attribute attr: f.attributes) 6.22 attrWriter.write(f, attr, constant_pool); 6.23 - println(); 6.24 + showBlank = true; 6.25 } 6.26 6.27 indent(-1); 6.28 6.29 - if (options.showDisassembled || options.showLineAndLocalVariableTables) 6.30 + if (showBlank || options.showDisassembled || options.showLineAndLocalVariableTables) 6.31 println(); 6.32 } 6.33 6.34 @@ -498,27 +500,23 @@ 6.35 report("Unexpected or invalid value for Code attribute"); 6.36 } 6.37 6.38 - if (options.showDisassembled && !options.showAllAttrs) { 6.39 - if (code != null) { 6.40 + if (options.showAllAttrs) { 6.41 + Attribute[] attrs = m.attributes.attrs; 6.42 + for (Attribute attr: attrs) 6.43 + attrWriter.write(m, attr, constant_pool); 6.44 + } else if (code != null) { 6.45 + if (options.showDisassembled) { 6.46 println("Code:"); 6.47 codeWriter.writeInstrs(code); 6.48 codeWriter.writeExceptionTable(code); 6.49 } 6.50 - } 6.51 6.52 - if (options.showLineAndLocalVariableTables) { 6.53 - if (code != null) { 6.54 + if (options.showLineAndLocalVariableTables) { 6.55 attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool); 6.56 attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool); 6.57 } 6.58 } 6.59 6.60 - if (options.showAllAttrs) { 6.61 - Attribute[] attrs = m.attributes.attrs; 6.62 - for (Attribute attr: attrs) 6.63 - attrWriter.write(m, attr, constant_pool); 6.64 - } 6.65 - 6.66 indent(-1); 6.67 6.68 // set pendingNewline to write a newline before the next method (if any)
7.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Wed Feb 19 13:14:43 2014 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Wed Feb 19 21:01:41 2014 -0800 7.3 @@ -309,7 +309,9 @@ 7.4 void process(JavapTask task, String opt, String arg) throws BadArgs { 7.5 int sep = opt.indexOf(":"); 7.6 try { 7.7 - task.options.indentWidth = Integer.valueOf(opt.substring(sep + 1)); 7.8 + int i = Integer.valueOf(opt.substring(sep + 1)); 7.9 + if (i > 0) // silently ignore invalid values 7.10 + task.options.indentWidth = i; 7.11 } catch (NumberFormatException e) { 7.12 } 7.13 } 7.14 @@ -325,7 +327,9 @@ 7.15 void process(JavapTask task, String opt, String arg) throws BadArgs { 7.16 int sep = opt.indexOf(":"); 7.17 try { 7.18 - task.options.tabColumn = Integer.valueOf(opt.substring(sep + 1)); 7.19 + int i = Integer.valueOf(opt.substring(sep + 1)); 7.20 + if (i > 0) // silently ignore invalid values 7.21 + task.options.tabColumn = i; 7.22 } catch (NumberFormatException e) { 7.23 } 7.24 } 7.25 @@ -466,7 +470,7 @@ 7.26 } catch (BadArgs e) { 7.27 reportError(e.key, e.args); 7.28 if (e.showUsage) { 7.29 - log.println(getMessage("main.usage.summary", progname)); 7.30 + printLines(getMessage("main.usage.summary", progname)); 7.31 } 7.32 return EXIT_CMDERR; 7.33 } catch (InternalError e) { 7.34 @@ -561,8 +565,12 @@ 7.35 } 7.36 } 7.37 7.38 - if (fileManager.handleOption(name, rest)) 7.39 - return; 7.40 + try { 7.41 + if (fileManager.handleOption(name, rest)) 7.42 + return; 7.43 + } catch (IllegalArgumentException e) { 7.44 + throw new BadArgs("err.invalid.use.of.option", name).showUsage(true); 7.45 + } 7.46 7.47 throw new BadArgs("err.unknown.option", name).showUsage(true); 7.48 } 7.49 @@ -878,27 +886,33 @@ 7.50 } 7.51 7.52 private void showHelp() { 7.53 - log.println(getMessage("main.usage", progname)); 7.54 + printLines(getMessage("main.usage", progname)); 7.55 for (Option o: recognizedOptions) { 7.56 String name = o.aliases[0].substring(1); // there must always be at least one name 7.57 if (name.startsWith("X") || name.equals("fullversion") || name.equals("h") || name.equals("verify")) 7.58 continue; 7.59 - log.println(getMessage("main.opt." + name)); 7.60 + printLines(getMessage("main.opt." + name)); 7.61 } 7.62 String[] fmOptions = { "-classpath", "-cp", "-bootclasspath" }; 7.63 for (String o: fmOptions) { 7.64 if (fileManager.isSupportedOption(o) == -1) 7.65 continue; 7.66 String name = o.substring(1); 7.67 - log.println(getMessage("main.opt." + name)); 7.68 + printLines(getMessage("main.opt." + name)); 7.69 } 7.70 7.71 } 7.72 7.73 private void showVersion(boolean full) { 7.74 - log.println(version(full ? "full" : "release")); 7.75 + printLines(version(full ? "full" : "release")); 7.76 } 7.77 7.78 + private void printLines(String msg) { 7.79 + log.println(msg.replace("\n", nl)); 7.80 + } 7.81 + 7.82 + private static final String nl = System.getProperty("line.separator"); 7.83 + 7.84 private static final String versionRBName = "com.sun.tools.javap.resources.version"; 7.85 private static ResourceBundle versionRB; 7.86
8.1 --- a/src/share/classes/com/sun/tools/javap/Options.java Wed Feb 19 13:14:43 2014 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javap/Options.java Wed Feb 19 21:01:41 2014 -0800 8.3 @@ -86,8 +86,8 @@ 8.4 public boolean showConstants; 8.5 public boolean sysInfo; 8.6 public boolean showInnerClasses; 8.7 - public int indentWidth = 2; // #spaces per indentWidth level 8.8 - public int tabColumn = 40; // column number for comments 8.9 + public int indentWidth = 2; // #spaces per indentWidth level; must be > 0 8.10 + public int tabColumn = 40; // column number for comments; must be > 0 8.11 8.12 public boolean compat; // bug-for-bug compatibility mode with old javap 8.13 }
9.1 --- a/src/share/classes/com/sun/tools/javap/resources/javap.properties Wed Feb 19 13:14:43 2014 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties Wed Feb 19 21:01:41 2014 -0800 9.3 @@ -14,6 +14,7 @@ 9.4 err.missing.arg=no value given for {0} 9.5 err.no.classes.specified=no classes specified 9.6 err.not.standard.file.manager=can only specify class files when using a standard file manager 9.7 +err.invalid.use.of.option=invalid use of option: {0} 9.8 err.unknown.option=unknown option: {0} 9.9 err.verify.not.supported=-verify not supported 9.10 err.no.SourceFile.attribute=no SourceFile attribute 9.11 @@ -80,7 +81,7 @@ 9.12 \ -bootclasspath <path> Override location of bootstrap class files 9.13 9.14 main.opt.constants=\ 9.15 -\ -constants Show static final constants 9.16 +\ -constants Show final constants 9.17 9.18 9.19 main.opt.sysinfo=\
10.1 --- a/test/tools/javac/doctree/SeeTest.java Wed Feb 19 13:14:43 2014 -0800 10.2 +++ b/test/tools/javac/doctree/SeeTest.java Wed Feb 19 21:01:41 2014 -0800 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -23,7 +23,7 @@ 10.11 10.12 /* 10.13 * @test 10.14 - * @bug 7021614 10.15 + * @bug 7021614 8031212 10.16 * @summary extend com.sun.source API to support parsing javadoc comments 10.17 * @build DocCommentTester 10.18 * @run main DocCommentTester SeeTest.java 10.19 @@ -41,9 +41,9 @@ 10.20 Text[TEXT, pos:1, abc.] 10.21 body: empty 10.22 block tags: 1 10.23 - Erroneous[ERRONEOUS, pos:7 10.24 - code: compiler.err.dc.unexpected.content 10.25 - body: @see_"String" 10.26 + See[SEE, pos:7 10.27 + reference: 1 10.28 + Text[TEXT, pos:12, "String"] 10.29 ] 10.30 ] 10.31 */
11.1 --- a/test/tools/javadoc/parser/7091528/T7091528.java Wed Feb 19 13:14:43 2014 -0800 11.2 +++ b/test/tools/javadoc/parser/7091528/T7091528.java Wed Feb 19 21:01:41 2014 -0800 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. 11.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.8 * 11.9 * This code is free software; you can redistribute it and/or modify it 11.10 @@ -23,8 +23,8 @@ 11.11 11.12 /** 11.13 * @test 11.14 - * @bug 7091528 11.15 - * @summary javadoc attempts to parse .class files 11.16 + * @bug 7091528 8029145 11.17 + * @summary ensures javadoc parses unique source files and ignores all class files 11.18 * @compile p/C1.java p/q/C2.java 11.19 * @run main T7091528 11.20 */ 11.21 @@ -37,17 +37,22 @@ 11.22 public static void main(String... args) { 11.23 new T7091528().run(); 11.24 } 11.25 - 11.26 void run() { 11.27 File testSrc = new File(System.getProperty("test.src")); 11.28 File testClasses = new File(System.getProperty("test.classes")); 11.29 - String[] args = { 11.30 - "-d", ".", 11.31 + // 7091528, tests if class files are being ignored 11.32 + runTest("-d", ".", 11.33 "-sourcepath", testClasses + File.pathSeparator + testSrc, 11.34 "-subpackages", 11.35 - "p" 11.36 - }; 11.37 + "p"); 11.38 + // 8029145, tests if unique source files are parsed 11.39 + runTest("-d", ".", 11.40 + "-sourcepath", testSrc.getAbsolutePath(), 11.41 + "-subpackages", 11.42 + "p:p.q"); 11.43 11.44 + } 11.45 + void runTest(String... args) { 11.46 StringWriter sw = new StringWriter(); 11.47 PrintWriter pw = new PrintWriter(sw); 11.48 String doclet = com.sun.tools.doclets.standard.Standard.class.getName();
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javap/StackMapTableTest.java Wed Feb 19 21:01:41 2014 -0800 12.3 @@ -0,0 +1,92 @@ 12.4 +/* 12.5 + * Copyright (c) 2014, 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. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/* 12.28 + * @test 12.29 + * @bug 8033930 8033913 12.30 + * @summary bad formatting of StackMapTable entries 12.31 + */ 12.32 + 12.33 +import java.io.*; 12.34 +import java.util.*; 12.35 + 12.36 +public class StackMapTableTest { 12.37 + public static void main(String... args) throws Exception { 12.38 + new StackMapTableTest().run(); 12.39 + } 12.40 + 12.41 + void run() throws Exception { 12.42 + String testClasses = System.getProperty("test.classes"); 12.43 + String out = javap("-v", "-classpath", testClasses, A.class.getName()); 12.44 + 12.45 + String nl = System.getProperty("line.separator"); 12.46 + out = out.replaceAll(nl, "\n"); 12.47 + 12.48 + if (out.contains("\n\n\n")) 12.49 + error("double blank line found"); 12.50 + 12.51 + String expect = 12.52 + " StackMapTable: number_of_entries = 2\n" + 12.53 + " frame_type = 252 /* append */\n" + 12.54 + " offset_delta = 2\n" + 12.55 + " locals = [ int ]\n" + 12.56 + " frame_type = 250 /* chop */\n" + 12.57 + " offset_delta = 18\n"; 12.58 + if (!out.contains(expect)) 12.59 + error("expected text not found"); 12.60 + 12.61 + if (errors > 0) 12.62 + throw new Exception(errors + " errors found"); 12.63 + } 12.64 + 12.65 + String javap(String... args) throws Exception { 12.66 + StringWriter sw = new StringWriter(); 12.67 + PrintWriter out = new PrintWriter(sw); 12.68 + int rc = com.sun.tools.javap.Main.run(args, out); 12.69 + out.close(); 12.70 + System.out.println(sw.toString()); 12.71 + if (rc < 0) 12.72 + throw new Exception("javap exited, rc=" + rc); 12.73 + return sw.toString(); 12.74 + } 12.75 + 12.76 + void error(String msg) { 12.77 + System.out.println("Error: " + msg); 12.78 + errors++; 12.79 + } 12.80 + 12.81 + int errors; 12.82 + 12.83 + /** Simple test class to run through javap. */ 12.84 + public class A { 12.85 + public void a() { 12.86 + for (int i = 0; i < 10; i++) { 12.87 + System.out.println(i); 12.88 + } 12.89 + } 12.90 + public void b() { 12.91 + } 12.92 + public void c() { 12.93 + } 12.94 + } 12.95 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javap/T8032814.java Wed Feb 19 21:01:41 2014 -0800 13.3 @@ -0,0 +1,93 @@ 13.4 +/* 13.5 + * Copyright (c) 2014, 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. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/* 13.28 + * @test 13.29 + * @bug 8032814 13.30 + * @summary LineNumberTable/LocalVariableTable tables duplication for the 13.31 + * "-v -l" combination of options 13.32 + * @compile -g T8032814.java 13.33 + * @run main T8032814 13.34 + */ 13.35 + 13.36 +import java.io.*; 13.37 +import java.util.*; 13.38 + 13.39 +public class T8032814 { 13.40 + public static void main(String... args) throws Exception { 13.41 + new T8032814().run(); 13.42 + } 13.43 + 13.44 + void run() throws Exception { 13.45 + Class<?> clazz = T8032814.class; 13.46 + int count = clazz.getDeclaredConstructors().length 13.47 + + clazz.getDeclaredMethods().length; 13.48 + test(clazz, 0); 13.49 + test(clazz, count, "-v"); 13.50 + test(clazz, count, "-l"); 13.51 + test(clazz, count, "-v", "-l"); 13.52 + 13.53 + if (errors > 0) 13.54 + throw new Exception(errors + " errors occurred"); 13.55 + } 13.56 + 13.57 + void test(Class<?> clazz, int expectedCount, String... opts) throws Exception { 13.58 + System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount); 13.59 + List<String> args = new ArrayList<String>(); 13.60 + args.addAll(Arrays.asList(opts)); 13.61 + args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes"))); 13.62 + args.add(clazz.getName()); 13.63 + StringWriter sw = new StringWriter(); 13.64 + PrintWriter pw = new PrintWriter(sw); 13.65 + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); 13.66 + pw.close(); 13.67 + String out = sw.toString(); 13.68 + if (rc != 0) 13.69 + throw new Exception("javap failed unexpectedly: rc=" + rc); 13.70 + 13.71 + int lntCount = 0, lvtCount = 0; 13.72 + for (String line: out.split("[\r\n]+")) { 13.73 + if (line.matches("^ *LineNumberTable:$")) 13.74 + lntCount++; 13.75 + if (line.matches("^ *LocalVariableTable:$")) 13.76 + lvtCount++; 13.77 + } 13.78 + checkEqual("LineNumberTable", lntCount, expectedCount); 13.79 + checkEqual("LocalVariableTable", lvtCount, expectedCount); 13.80 + } 13.81 + 13.82 + void checkEqual(String attr, int found, int expect) { 13.83 + if (found != expect) { 13.84 + error("Unexpected number of occurrences of " + attr + "\n" + 13.85 + "found: " + found + ", expected: " + expect); 13.86 + } 13.87 + } 13.88 + 13.89 + void error(String msg) { 13.90 + System.err.println("Error: " + msg); 13.91 + errors++; 13.92 + } 13.93 + 13.94 + int errors = 0; 13.95 +} 13.96 +
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javap/T8032819.java Wed Feb 19 21:01:41 2014 -0800 14.3 @@ -0,0 +1,95 @@ 14.4 +/* 14.5 + * Copyright (c) 2014, 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. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 8032819 14.30 + * @summary Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options 14.31 + * @compile -g T8032819.java 14.32 + * @run main T8032819 14.33 + */ 14.34 + 14.35 +import java.io.*; 14.36 +import java.util.*; 14.37 + 14.38 +public class T8032819 { 14.39 + static class Fields { 14.40 + int f1; 14.41 + int f2; 14.42 + } 14.43 + 14.44 + public static void main(String... args) throws Exception { 14.45 + new T8032819().run(); 14.46 + } 14.47 + 14.48 + void run() throws Exception { 14.49 + Class<?> clazz = Fields.class; 14.50 + test(clazz); 14.51 + test(clazz, "-c"); 14.52 + test(clazz, "-l"); 14.53 + test(clazz, "-l", "-c"); 14.54 + test(clazz, "-v"); 14.55 + test(clazz, "-v", "-c"); 14.56 + test(clazz, "-v", "-l"); 14.57 + test(clazz, "-v", "-l", "-c"); 14.58 + 14.59 + if (errors > 0) 14.60 + throw new Exception(errors + " errors occurred"); 14.61 + } 14.62 + 14.63 + static final String sep = System.getProperty("line.separator"); 14.64 + static final String doubleBlankLine = sep + sep + sep; 14.65 + 14.66 + void test(Class<?> clazz, String... opts) throws Exception { 14.67 + System.err.println("test " + Arrays.asList(opts)); 14.68 + List<String> args = new ArrayList<String>(); 14.69 + args.addAll(Arrays.asList(opts)); 14.70 + args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes"))); 14.71 + args.add(clazz.getName()); 14.72 + StringWriter sw = new StringWriter(); 14.73 + PrintWriter pw = new PrintWriter(sw); 14.74 + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); 14.75 + pw.close(); 14.76 + String out = sw.toString(); 14.77 + if (rc != 0) 14.78 + throw new Exception("javap failed unexpectedly: rc=" + rc); 14.79 + 14.80 + int count = 0; 14.81 + int i = out.indexOf(doubleBlankLine, 0); 14.82 + while (i != -1) { 14.83 + count++; 14.84 + i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length()); 14.85 + } 14.86 + 14.87 + if (count > 0) 14.88 + error(count + " double blank lines found"); 14.89 + } 14.90 + 14.91 + void error(String msg) { 14.92 + System.err.println("Error: " + msg); 14.93 + errors++; 14.94 + } 14.95 + 14.96 + int errors = 0; 14.97 +} 14.98 +
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javap/T8033180.java Wed Feb 19 21:01:41 2014 -0800 15.3 @@ -0,0 +1,88 @@ 15.4 +/* 15.5 + * Copyright (c) 2014, 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. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @bug 8033180 15.30 + * @summary Bad newline characters 15.31 + */ 15.32 + 15.33 +import java.io.*; 15.34 +import java.util.*; 15.35 + 15.36 +public class T8033180 { 15.37 + 15.38 + public static void main(String... args) throws Exception { 15.39 + new T8033180().run(); 15.40 + } 15.41 + 15.42 + void run() throws Exception { 15.43 + // fast-track this case, because test cannot fail in this case 15.44 + if (lineSep.equals(nl)) 15.45 + return; 15.46 + 15.47 + test("-help"); 15.48 + test("-version"); 15.49 + 15.50 + if (errors > 0) 15.51 + throw new Exception(errors + " errors occurred"); 15.52 + } 15.53 + 15.54 + static final String lineSep = System.getProperty("line.separator"); 15.55 + static final String nl = "\n"; 15.56 + 15.57 + void test(String... opts) throws Exception { 15.58 + System.err.println("test " + Arrays.asList(opts)); 15.59 + List<String> args = new ArrayList<String>(); 15.60 + args.addAll(Arrays.asList(opts)); 15.61 + StringWriter sw = new StringWriter(); 15.62 + PrintWriter pw = new PrintWriter(sw); 15.63 + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); 15.64 + pw.close(); 15.65 + String out = sw.toString(); 15.66 + if (rc != 0) 15.67 + throw new Exception("javap failed unexpectedly: rc=" + rc); 15.68 + 15.69 + // remove all valid platform newline sequences 15.70 + String out2 = out.replace(lineSep, ""); 15.71 + 15.72 + // count the remaining simple newline characters 15.73 + int count = 0; 15.74 + int i = out2.indexOf(nl, 0); 15.75 + while (i != -1) { 15.76 + count++; 15.77 + i = out2.indexOf(nl, i + nl.length()); 15.78 + } 15.79 + 15.80 + if (count > 0) 15.81 + error(count + " newline characters found"); 15.82 + } 15.83 + 15.84 + void error(String msg) { 15.85 + System.err.println("Error: " + msg); 15.86 + errors++; 15.87 + } 15.88 + 15.89 + int errors = 0; 15.90 +} 15.91 +
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javap/T8033711.java Wed Feb 19 21:01:41 2014 -0800 16.3 @@ -0,0 +1,55 @@ 16.4 +/* 16.5 + * Copyright (c) 2014, 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. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * @test 16.29 + * @bug 8033711 16.30 + * @summary An exception is thrown if using the "-classpath" option with no arguments 16.31 + */ 16.32 + 16.33 + 16.34 +import java.io.*; 16.35 + 16.36 +public class T8033711 { 16.37 + public static void main(String[] args) throws Exception { 16.38 + new T8033711().run(); 16.39 + } 16.40 + 16.41 + public void run() throws Exception { 16.42 + String out = javap("-classpath"); 16.43 + if (out.contains("IllegalArgumentException")) 16.44 + throw new Exception("exception found in javap output"); 16.45 + if (!out.contains("Error: invalid use of option")) 16.46 + throw new Exception("expected error message not found in javap output"); 16.47 + } 16.48 + 16.49 + String javap(String... args) { 16.50 + StringWriter sw = new StringWriter(); 16.51 + PrintWriter out = new PrintWriter(sw); 16.52 + int rc = com.sun.tools.javap.Main.run(args, out); 16.53 + out.close(); 16.54 + System.out.println(sw.toString()); 16.55 + System.out.println("javap exited, rc=" + rc); 16.56 + return sw.toString(); 16.57 + } 16.58 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javap/WhitespaceTest.java Wed Feb 19 21:01:41 2014 -0800 17.3 @@ -0,0 +1,91 @@ 17.4 +/* 17.5 + * Copyright (c) 2014, 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. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/* 17.28 + * @test 17.29 + * @bug 8033581 8033798 8033726 17.30 + * @summary Check whitespace in generated output 17.31 + */ 17.32 + 17.33 +import java.io.*; 17.34 +import java.util.*; 17.35 + 17.36 +public class WhitespaceTest { 17.37 + public static void main(String... args) throws Exception { 17.38 + new WhitespaceTest().run(); 17.39 + } 17.40 + 17.41 + void run() throws Exception { 17.42 + test("-v", "java.lang.String"); 17.43 + test("-XDtab:1", "-v", "java.lang.String"); 17.44 + 17.45 + String testClasses = System.getProperty("test.classes"); 17.46 + for (int i = 10; i < 40; i++) 17.47 + test("-XDtab:" + i, "-v", "-classpath", testClasses, "WhitespaceTest$HelloWorld"); 17.48 + 17.49 + if (errors > 0) 17.50 + throw new Exception(errors + " errors found"); 17.51 + } 17.52 + 17.53 + void test(String... args) throws Exception { 17.54 + // need to avoid "//" appearing as a constant in the constant pool 17.55 + String slash = "/"; 17.56 + String doubleSlash = slash + slash; 17.57 + System.out.println("test: " + Arrays.asList(args)); 17.58 + String out = javap(args); 17.59 + for (String line: out.split("[\r\n]+")) { 17.60 + if (line.endsWith(" ")) 17.61 + error("line has trailing whitespace: " + line); 17.62 + int comment = line.indexOf(doubleSlash); 17.63 + if (comment > 0 && line.charAt(comment - 1) != ' ') 17.64 + error("no space before comment: " + line); 17.65 + if (line.matches(" +}")) 17.66 + error("bad indentation: " + line); 17.67 + } 17.68 + } 17.69 + 17.70 + String javap(String... args) throws Exception { 17.71 + StringWriter sw = new StringWriter(); 17.72 + PrintWriter out = new PrintWriter(sw); 17.73 + int rc = com.sun.tools.javap.Main.run(args, out); 17.74 + out.close(); 17.75 + System.out.println(sw.toString()); 17.76 + if (rc < 0) 17.77 + throw new Exception("javap exited, rc=" + rc); 17.78 + return sw.toString(); 17.79 + } 17.80 + 17.81 + void error(String msg) { 17.82 + System.out.println("Error: " + msg); 17.83 + errors++; 17.84 + } 17.85 + 17.86 + int errors; 17.87 + 17.88 + // small class to test repeatedly with different tab values 17.89 + static class HelloWorld { 17.90 + public static void main(String... args) { 17.91 + System.out.println("Hello World!"); 17.92 + } 17.93 + } 17.94 +}