Thu, 07 Aug 2008 18:03:32 -0700
Merge
test/tools/javac/5045412/out | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Aug 07 09:45:08 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Aug 07 18:03:32 2008 -0700 1.3 @@ -75,6 +75,7 @@ 1.4 1.5 private final Name.Table names; 1.6 private final ClassReader reader; 1.7 + private final Target target; 1.8 1.9 /** A symbol for the root package. 1.10 */ 1.11 @@ -144,6 +145,7 @@ 1.12 public final Type suppressWarningsType; 1.13 public final Type inheritedType; 1.14 public final Type proprietaryType; 1.15 + public final Type systemType; 1.16 1.17 /** The symbol representing the length field of an array. 1.18 */ 1.19 @@ -272,6 +274,55 @@ 1.20 return reader.enterClass(names.fromString(s)).type; 1.21 } 1.22 1.23 + public void synthesizeEmptyInterfaceIfMissing(final Type type) { 1.24 + final Completer completer = type.tsym.completer; 1.25 + if (completer != null) { 1.26 + type.tsym.completer = new Completer() { 1.27 + public void complete(Symbol sym) throws CompletionFailure { 1.28 + try { 1.29 + completer.complete(sym); 1.30 + } catch (CompletionFailure e) { 1.31 + sym.flags_field |= (PUBLIC | INTERFACE); 1.32 + ((ClassType) sym.type).supertype_field = objectType; 1.33 + } 1.34 + } 1.35 + }; 1.36 + } 1.37 + } 1.38 + 1.39 + public void synthesizeBoxTypeIfMissing(final Type type) { 1.40 + ClassSymbol sym = reader.enterClass(boxedName[type.tag]); 1.41 + final Completer completer = sym.completer; 1.42 + if (completer != null) { 1.43 + sym.completer = new Completer() { 1.44 + public void complete(Symbol sym) throws CompletionFailure { 1.45 + try { 1.46 + completer.complete(sym); 1.47 + } catch (CompletionFailure e) { 1.48 + sym.flags_field |= PUBLIC; 1.49 + ((ClassType) sym.type).supertype_field = objectType; 1.50 + Name n = target.boxWithConstructors() ? names.init : names.valueOf; 1.51 + MethodSymbol boxMethod = 1.52 + new MethodSymbol(PUBLIC | STATIC, 1.53 + n, 1.54 + new MethodType(List.of(type), sym.type, 1.55 + List.<Type>nil(), methodClass), 1.56 + sym); 1.57 + sym.members().enter(boxMethod); 1.58 + MethodSymbol unboxMethod = 1.59 + new MethodSymbol(PUBLIC, 1.60 + type.tsym.name.append(names.Value), // x.intValue() 1.61 + new MethodType(List.<Type>nil(), type, 1.62 + List.<Type>nil(), methodClass), 1.63 + sym); 1.64 + sym.members().enter(unboxMethod); 1.65 + } 1.66 + } 1.67 + }; 1.68 + } 1.69 + 1.70 + } 1.71 + 1.72 /** Constructor; enters all predefined identifiers and operators 1.73 * into symbol table. 1.74 */ 1.75 @@ -279,6 +330,7 @@ 1.76 context.put(symtabKey, this); 1.77 1.78 names = Name.Table.instance(context); 1.79 + target = Target.instance(context); 1.80 1.81 // Create the unknown type 1.82 unknownType = new Type(TypeTags.UNKNOWN, null); 1.83 @@ -373,7 +425,7 @@ 1.84 collectionsType = enterClass("java.util.Collections"); 1.85 comparableType = enterClass("java.lang.Comparable"); 1.86 arraysType = enterClass("java.util.Arrays"); 1.87 - iterableType = Target.instance(context).hasIterable() 1.88 + iterableType = target.hasIterable() 1.89 ? enterClass("java.lang.Iterable") 1.90 : enterClass("java.util.Collection"); 1.91 iteratorType = enterClass("java.util.Iterator"); 1.92 @@ -383,6 +435,12 @@ 1.93 deprecatedType = enterClass("java.lang.Deprecated"); 1.94 suppressWarningsType = enterClass("java.lang.SuppressWarnings"); 1.95 inheritedType = enterClass("java.lang.annotation.Inherited"); 1.96 + systemType = enterClass("java.lang.System"); 1.97 + 1.98 + synthesizeEmptyInterfaceIfMissing(cloneableType); 1.99 + synthesizeEmptyInterfaceIfMissing(serializableType); 1.100 + synthesizeBoxTypeIfMissing(doubleType); 1.101 + synthesizeBoxTypeIfMissing(floatType); 1.102 1.103 // Enter a synthetic class that is used to mark Sun 1.104 // proprietary classes in ct.sym. This class does not have a
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Aug 07 09:45:08 2008 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Aug 07 18:03:32 2008 -0700 2.3 @@ -79,6 +79,7 @@ 2.4 final Enter enter; 2.5 final Target target; 2.6 final Types types; 2.7 + final JCDiagnostic.Factory diags; 2.8 final Annotate annotate; 2.9 2.10 public static Attr instance(Context context) { 2.11 @@ -102,6 +103,7 @@ 2.12 cfolder = ConstFold.instance(context); 2.13 target = Target.instance(context); 2.14 types = Types.instance(context); 2.15 + diags = JCDiagnostic.Factory.instance(context); 2.16 annotate = Annotate.instance(context); 2.17 2.18 Options options = Options.instance(context); 2.19 @@ -2419,7 +2421,7 @@ 2.20 2.21 if (false) { 2.22 // TODO: make assertConvertible work 2.23 - chk.typeError(tree.pos(), JCDiagnostic.fragment("incompatible.types"), actual, formal); 2.24 + chk.typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal); 2.25 throw new AssertionError("Tree: " + tree 2.26 + " actual:" + actual 2.27 + " formal: " + formal);
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 07 09:45:08 2008 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 07 18:03:32 2008 -0700 3.3 @@ -63,6 +63,7 @@ 3.4 private final Target target; 3.5 private final Source source; 3.6 private final Types types; 3.7 + private final JCDiagnostic.Factory diags; 3.8 private final boolean skipAnnotations; 3.9 private final TreeInfo treeinfo; 3.10 3.11 @@ -86,6 +87,7 @@ 3.12 syms = Symtab.instance(context); 3.13 infer = Infer.instance(context); 3.14 this.types = Types.instance(context); 3.15 + diags = JCDiagnostic.Factory.instance(context); 3.16 Options options = Options.instance(context); 3.17 target = Target.instance(context); 3.18 source = Source.instance(context); 3.19 @@ -343,7 +345,7 @@ 3.20 if (types.isAssignable(found, req, convertWarner(pos, found, req))) 3.21 return found; 3.22 if (found.tag <= DOUBLE && req.tag <= DOUBLE) 3.23 - return typeError(pos, JCDiagnostic.fragment("possible.loss.of.precision"), found, req); 3.24 + return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req); 3.25 if (found.isSuperBound()) { 3.26 log.error(pos, "assignment.from.super-bound", found); 3.27 return syms.errType; 3.28 @@ -352,7 +354,7 @@ 3.29 log.error(pos, "assignment.to.extends-bound", req); 3.30 return syms.errType; 3.31 } 3.32 - return typeError(pos, JCDiagnostic.fragment("incompatible.types"), found, req); 3.33 + return typeError(pos, diags.fragment("incompatible.types"), found, req); 3.34 } 3.35 3.36 /** Instantiate polymorphic type to some prototype, unless 3.37 @@ -380,7 +382,7 @@ 3.38 } else { 3.39 JCDiagnostic d = ex.getDiagnostic(); 3.40 return typeError(pos, 3.41 - JCDiagnostic.fragment("incompatible.types" + (d!=null ? ".1" : ""), d), 3.42 + diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d), 3.43 t, pt); 3.44 } 3.45 } 3.46 @@ -401,7 +403,7 @@ 3.47 return req; 3.48 } else { 3.49 return typeError(pos, 3.50 - JCDiagnostic.fragment("inconvertible.types"), 3.51 + diags.fragment("inconvertible.types"), 3.52 found, req); 3.53 } 3.54 } 3.55 @@ -480,9 +482,9 @@ 3.56 Type checkClassType(DiagnosticPosition pos, Type t) { 3.57 if (t.tag != CLASS && t.tag != ERROR) 3.58 return typeTagError(pos, 3.59 - JCDiagnostic.fragment("type.req.class"), 3.60 + diags.fragment("type.req.class"), 3.61 (t.tag == TYPEVAR) 3.62 - ? JCDiagnostic.fragment("type.parameter", t) 3.63 + ? diags.fragment("type.parameter", t) 3.64 : t); 3.65 else 3.66 return t; 3.67 @@ -515,7 +517,7 @@ 3.68 Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) { 3.69 if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) { 3.70 return typeTagError(pos, 3.71 - JCDiagnostic.fragment("type.req.class.array"), 3.72 + diags.fragment("type.req.class.array"), 3.73 t); 3.74 } else if (!types.isReifiable(t)) { 3.75 log.error(pos, "illegal.generic.type.for.instof"); 3.76 @@ -540,7 +542,7 @@ 3.77 return t; 3.78 default: 3.79 return typeTagError(pos, 3.80 - JCDiagnostic.fragment("type.req.ref"), 3.81 + diags.fragment("type.req.ref"), 3.82 t); 3.83 } 3.84 } 3.85 @@ -560,7 +562,7 @@ 3.86 return t; 3.87 default: 3.88 return typeTagError(pos, 3.89 - JCDiagnostic.fragment("type.req.ref"), 3.90 + diags.fragment("type.req.ref"), 3.91 t); 3.92 } 3.93 } 3.94 @@ -1028,7 +1030,7 @@ 3.95 * @param other The overridden method. 3.96 * @return An internationalized string. 3.97 */ 3.98 - static Object cannotOverride(MethodSymbol m, MethodSymbol other) { 3.99 + Object cannotOverride(MethodSymbol m, MethodSymbol other) { 3.100 String key; 3.101 if ((other.owner.flags() & INTERFACE) == 0) 3.102 key = "cant.override"; 3.103 @@ -1036,7 +1038,7 @@ 3.104 key = "cant.implement"; 3.105 else 3.106 key = "clashes.with"; 3.107 - return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); 3.108 + return diags.fragment(key, m, m.location(), other, other.location()); 3.109 } 3.110 3.111 /** A customized "override" warning message. 3.112 @@ -1044,7 +1046,7 @@ 3.113 * @param other The overridden method. 3.114 * @return An internationalized string. 3.115 */ 3.116 - static Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) { 3.117 + Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) { 3.118 String key; 3.119 if ((other.owner.flags() & INTERFACE) == 0) 3.120 key = "unchecked.override"; 3.121 @@ -1052,7 +1054,7 @@ 3.122 key = "unchecked.implement"; 3.123 else 3.124 key = "unchecked.clash.with"; 3.125 - return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); 3.126 + return diags.fragment(key, m, m.location(), other, other.location()); 3.127 } 3.128 3.129 /** A customized "override" warning message. 3.130 @@ -1060,7 +1062,7 @@ 3.131 * @param other The overridden method. 3.132 * @return An internationalized string. 3.133 */ 3.134 - static Object varargsOverrides(MethodSymbol m, MethodSymbol other) { 3.135 + Object varargsOverrides(MethodSymbol m, MethodSymbol other) { 3.136 String key; 3.137 if ((other.owner.flags() & INTERFACE) == 0) 3.138 key = "varargs.override"; 3.139 @@ -1068,7 +1070,7 @@ 3.140 key = "varargs.implement"; 3.141 else 3.142 key = "varargs.clash.with"; 3.143 - return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); 3.144 + return diags.fragment(key, m, m.location(), other, other.location()); 3.145 } 3.146 3.147 /** Check that this method conforms with overridden method 'other'. 3.148 @@ -1157,7 +1159,7 @@ 3.149 // allow limited interoperability with covariant returns 3.150 } else { 3.151 typeError(TreeInfo.diagnosticPositionFor(m, tree), 3.152 - JCDiagnostic.fragment("override.incompatible.ret", 3.153 + diags.fragment("override.incompatible.ret", 3.154 cannotOverride(m, other)), 3.155 mtres, otres); 3.156 return; 3.157 @@ -1165,7 +1167,7 @@ 3.158 } else if (overrideWarner.warned) { 3.159 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), 3.160 "prob.found.req", 3.161 - JCDiagnostic.fragment("override.unchecked.ret", 3.162 + diags.fragment("override.unchecked.ret", 3.163 uncheckedOverrides(m, other)), 3.164 mtres, otres); 3.165 } 3.166 @@ -2170,7 +2172,7 @@ 3.167 boolean warned = this.warned; 3.168 super.warnUnchecked(); 3.169 if (warned) return; // suppress redundant diagnostics 3.170 - Object problem = JCDiagnostic.fragment(key); 3.171 + Object problem = diags.fragment(key); 3.172 Check.this.warnUnchecked(pos(), "prob.found.req", problem, found, expected); 3.173 } 3.174 }
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Aug 07 09:45:08 2008 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Aug 07 18:03:32 2008 -0700 4.3 @@ -29,6 +29,7 @@ 4.4 import com.sun.tools.javac.util.List; 4.5 import com.sun.tools.javac.code.*; 4.6 import com.sun.tools.javac.code.Type.*; 4.7 +import com.sun.tools.javac.util.JCDiagnostic; 4.8 4.9 import static com.sun.tools.javac.code.Flags.*; 4.10 import static com.sun.tools.javac.code.Kinds.*; 4.11 @@ -50,6 +51,7 @@ 4.12 4.13 Symtab syms; 4.14 Types types; 4.15 + JCDiagnostic.Factory diags; 4.16 4.17 public static Infer instance(Context context) { 4.18 Infer instance = context.get(inferKey); 4.19 @@ -62,6 +64,11 @@ 4.20 context.put(inferKey, this); 4.21 syms = Symtab.instance(context); 4.22 types = Types.instance(context); 4.23 + diags = JCDiagnostic.Factory.instance(context); 4.24 + ambiguousNoInstanceException = 4.25 + new NoInstanceException(true, diags); 4.26 + unambiguousNoInstanceException = 4.27 + new NoInstanceException(false, diags); 4.28 } 4.29 4.30 public static class NoInstanceException extends RuntimeException { 4.31 @@ -70,35 +77,35 @@ 4.32 boolean isAmbiguous; // exist several incomparable best instances? 4.33 4.34 JCDiagnostic diagnostic; 4.35 + JCDiagnostic.Factory diags; 4.36 4.37 - NoInstanceException(boolean isAmbiguous) { 4.38 + NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) { 4.39 this.diagnostic = null; 4.40 this.isAmbiguous = isAmbiguous; 4.41 + this.diags = diags; 4.42 } 4.43 NoInstanceException setMessage(String key) { 4.44 - this.diagnostic = JCDiagnostic.fragment(key); 4.45 + this.diagnostic = diags.fragment(key); 4.46 return this; 4.47 } 4.48 NoInstanceException setMessage(String key, Object arg1) { 4.49 - this.diagnostic = JCDiagnostic.fragment(key, arg1); 4.50 + this.diagnostic = diags.fragment(key, arg1); 4.51 return this; 4.52 } 4.53 NoInstanceException setMessage(String key, Object arg1, Object arg2) { 4.54 - this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2); 4.55 + this.diagnostic = diags.fragment(key, arg1, arg2); 4.56 return this; 4.57 } 4.58 NoInstanceException setMessage(String key, Object arg1, Object arg2, Object arg3) { 4.59 - this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2, arg3); 4.60 + this.diagnostic = diags.fragment(key, arg1, arg2, arg3); 4.61 return this; 4.62 } 4.63 public JCDiagnostic getDiagnostic() { 4.64 return diagnostic; 4.65 } 4.66 } 4.67 - private final NoInstanceException ambiguousNoInstanceException = 4.68 - new NoInstanceException(true); 4.69 - private final NoInstanceException unambiguousNoInstanceException = 4.70 - new NoInstanceException(false); 4.71 + private final NoInstanceException ambiguousNoInstanceException; 4.72 + private final NoInstanceException unambiguousNoInstanceException; 4.73 4.74 /*************************************************************************** 4.75 * Auxiliary type values and classes
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Aug 07 09:45:08 2008 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Aug 07 18:03:32 2008 -0700 5.3 @@ -2110,16 +2110,64 @@ 5.4 5.5 Symbol valuesSym = lookupMethod(tree.pos(), names.values, 5.6 tree.type, List.<Type>nil()); 5.7 - JCTypeCast valuesResult = 5.8 - make.TypeCast(valuesSym.type.getReturnType(), 5.9 - make.App(make.Select(make.Ident(valuesVar), 5.10 - syms.arrayCloneMethod))); 5.11 + List<JCStatement> valuesBody; 5.12 + if (useClone()) { 5.13 + // return (T[]) $VALUES.clone(); 5.14 + JCTypeCast valuesResult = 5.15 + make.TypeCast(valuesSym.type.getReturnType(), 5.16 + make.App(make.Select(make.Ident(valuesVar), 5.17 + syms.arrayCloneMethod))); 5.18 + valuesBody = List.<JCStatement>of(make.Return(valuesResult)); 5.19 + } else { 5.20 + // template: T[] $result = new T[$values.length]; 5.21 + Name resultName = names.fromString(target.syntheticNameChar() + "result"); 5.22 + while (tree.sym.members().lookup(resultName).scope != null) // avoid name clash 5.23 + resultName = names.fromString(resultName + "" + target.syntheticNameChar()); 5.24 + VarSymbol resultVar = new VarSymbol(FINAL|SYNTHETIC, 5.25 + resultName, 5.26 + arrayType, 5.27 + valuesSym); 5.28 + JCNewArray resultArray = make.NewArray(make.Type(types.erasure(tree.type)), 5.29 + List.of(make.Select(make.Ident(valuesVar), syms.lengthVar)), 5.30 + null); 5.31 + resultArray.type = arrayType; 5.32 + JCVariableDecl decl = make.VarDef(resultVar, resultArray); 5.33 + 5.34 + // template: System.arraycopy($VALUES, 0, $result, 0, $VALUES.length); 5.35 + if (systemArraycopyMethod == null) { 5.36 + systemArraycopyMethod = 5.37 + new MethodSymbol(PUBLIC | STATIC, 5.38 + names.fromString("arraycopy"), 5.39 + new MethodType(List.<Type>of(syms.objectType, 5.40 + syms.intType, 5.41 + syms.objectType, 5.42 + syms.intType, 5.43 + syms.intType), 5.44 + syms.voidType, 5.45 + List.<Type>nil(), 5.46 + syms.methodClass), 5.47 + syms.systemType.tsym); 5.48 + } 5.49 + JCStatement copy = 5.50 + make.Exec(make.App(make.Select(make.Ident(syms.systemType.tsym), 5.51 + systemArraycopyMethod), 5.52 + List.of(make.Ident(valuesVar), make.Literal(0), 5.53 + make.Ident(resultVar), make.Literal(0), 5.54 + make.Select(make.Ident(valuesVar), syms.lengthVar)))); 5.55 + 5.56 + // template: return $result; 5.57 + JCStatement ret = make.Return(make.Ident(resultVar)); 5.58 + valuesBody = List.<JCStatement>of(decl, copy, ret); 5.59 + } 5.60 + 5.61 JCMethodDecl valuesDef = 5.62 - make.MethodDef((MethodSymbol)valuesSym, 5.63 - make.Block(0, List.<JCStatement>nil() 5.64 - .prepend(make.Return(valuesResult)))); 5.65 + make.MethodDef((MethodSymbol)valuesSym, make.Block(0, valuesBody)); 5.66 + 5.67 enumDefs.append(valuesDef); 5.68 5.69 + if (debugLower) 5.70 + System.err.println(tree.sym + ".valuesDef = " + valuesDef); 5.71 + 5.72 /** The template for the following code is: 5.73 * 5.74 * public static E valueOf(String name) { 5.75 @@ -2155,6 +2203,17 @@ 5.76 addEnumCompatibleMembers(tree); 5.77 } 5.78 } 5.79 + // where 5.80 + private MethodSymbol systemArraycopyMethod; 5.81 + private boolean useClone() { 5.82 + try { 5.83 + Scope.Entry e = syms.objectType.tsym.members().lookup(names.clone); 5.84 + return (e.sym != null); 5.85 + } 5.86 + catch (CompletionFailure e) { 5.87 + return false; 5.88 + } 5.89 + } 5.90 5.91 /** Translate an enumeration constant and its initializer. */ 5.92 private void visitEnumConstantDef(JCVariableDecl var, int ordinal) {
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 07 09:45:08 2008 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 07 18:03:32 2008 -0700 6.3 @@ -72,6 +72,7 @@ 6.4 private final Todo todo; 6.5 private final Annotate annotate; 6.6 private final Types types; 6.7 + private final JCDiagnostic.Factory diags; 6.8 private final Target target; 6.9 6.10 private final boolean skipAnnotations; 6.11 @@ -96,6 +97,7 @@ 6.12 todo = Todo.instance(context); 6.13 annotate = Annotate.instance(context); 6.14 types = Types.instance(context); 6.15 + diags = JCDiagnostic.Factory.instance(context); 6.16 target = Target.instance(context); 6.17 skipAnnotations = 6.18 Options.instance(context).get("skipAnnotations") != null; 6.19 @@ -133,7 +135,7 @@ 6.20 if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) { 6.21 // If we can't find java.lang, exit immediately. 6.22 if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) { 6.23 - JCDiagnostic msg = JCDiagnostic.fragment("fatal.err.no.java.lang"); 6.24 + JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang"); 6.25 throw new FatalError(msg); 6.26 } else { 6.27 log.error(pos, "doesnt.exist", tsym); 6.28 @@ -319,7 +321,7 @@ 6.29 log.error(pos, "cant.resolve.location", 6.30 KindName.STATIC, 6.31 name, List.<Type>nil(), List.<Type>nil(), 6.32 - typeKindName(tsym.type), 6.33 + Kinds.typeKindName(tsym.type), 6.34 tsym.type); 6.35 } 6.36 } finally {
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Aug 07 09:45:08 2008 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Aug 07 18:03:32 2008 -0700 7.3 @@ -59,6 +59,7 @@ 7.4 ClassReader reader; 7.5 TreeInfo treeinfo; 7.6 Types types; 7.7 + JCDiagnostic.Factory diags; 7.8 public final boolean boxingEnabled; // = source.allowBoxing(); 7.9 public final boolean varargsEnabled; // = source.allowVarargs(); 7.10 private final boolean debugResolve; 7.11 @@ -92,6 +93,7 @@ 7.12 reader = ClassReader.instance(context); 7.13 treeinfo = TreeInfo.instance(context); 7.14 types = Types.instance(context); 7.15 + diags = JCDiagnostic.Factory.instance(context); 7.16 Source source = Source.instance(context); 7.17 boxingEnabled = source.allowBoxing(); 7.18 varargsEnabled = source.allowVarargs(); 7.19 @@ -449,7 +451,7 @@ 7.20 Symbol sym = findField(env, site, name, site.tsym); 7.21 if (sym.kind == VAR) return (VarSymbol)sym; 7.22 else throw new FatalError( 7.23 - JCDiagnostic.fragment("fatal.err.cant.locate.field", 7.24 + diags.fragment("fatal.err.cant.locate.field", 7.25 name)); 7.26 } 7.27 7.28 @@ -1248,7 +1250,7 @@ 7.29 pos, env, site, name, argtypes, typeargtypes); 7.30 if (sym.kind == MTH) return (MethodSymbol)sym; 7.31 else throw new FatalError( 7.32 - JCDiagnostic.fragment("fatal.err.cant.locate.meth", 7.33 + diags.fragment("fatal.err.cant.locate.meth", 7.34 name)); 7.35 } 7.36 7.37 @@ -1320,7 +1322,7 @@ 7.38 pos, env, site, argtypes, typeargtypes); 7.39 if (sym.kind == MTH) return (MethodSymbol)sym; 7.40 else throw new FatalError( 7.41 - JCDiagnostic.fragment("fatal.err.cant.locate.ctor", site)); 7.42 + diags.fragment("fatal.err.cant.locate.ctor", site)); 7.43 } 7.44 7.45 /** Resolve operator.
8.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Aug 07 09:45:08 2008 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Aug 07 18:03:32 2008 -0700 8.3 @@ -59,20 +59,19 @@ 8.4 return instance; 8.5 } 8.6 8.7 - final Messages messages; 8.8 + DiagnosticFormatter<JCDiagnostic> formatter; 8.9 final String prefix; 8.10 8.11 /** Create a new diagnostic factory. */ 8.12 protected Factory(Context context) { 8.13 + this(Messages.instance(context), "compiler"); 8.14 context.put(diagnosticFactoryKey, this); 8.15 - messages = Messages.instance(context); 8.16 - prefix = "compiler"; 8.17 } 8.18 8.19 /** Create a new diagnostic factory. */ 8.20 public Factory(Messages messages, String prefix) { 8.21 - this.messages = messages; 8.22 this.prefix = prefix; 8.23 + this.formatter = new BasicDiagnosticFormatter(messages); 8.24 } 8.25 8.26 /** 8.27 @@ -84,7 +83,7 @@ 8.28 */ 8.29 public JCDiagnostic error( 8.30 DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { 8.31 - return new JCDiagnostic(messages, ERROR, true, source, pos, qualify(ERROR, key), args); 8.32 + return new JCDiagnostic(formatter, ERROR, true, source, pos, qualify(ERROR, key), args); 8.33 } 8.34 8.35 /** 8.36 @@ -97,7 +96,7 @@ 8.37 */ 8.38 public JCDiagnostic mandatoryWarning( 8.39 DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { 8.40 - return new JCDiagnostic(messages, WARNING, true, source, pos, qualify(WARNING, key), args); 8.41 + return new JCDiagnostic(formatter, WARNING, true, source, pos, qualify(WARNING, key), args); 8.42 } 8.43 8.44 /** 8.45 @@ -109,7 +108,7 @@ 8.46 */ 8.47 public JCDiagnostic warning( 8.48 DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { 8.49 - return new JCDiagnostic(messages, WARNING, false, source, pos, qualify(WARNING, key), args); 8.50 + return new JCDiagnostic(formatter, WARNING, false, source, pos, qualify(WARNING, key), args); 8.51 } 8.52 8.53 /** 8.54 @@ -119,7 +118,7 @@ 8.55 * @see MandatoryWarningHandler 8.56 */ 8.57 public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) { 8.58 - return new JCDiagnostic(messages, NOTE, true, source, null, qualify(NOTE, key), args); 8.59 + return new JCDiagnostic(formatter, NOTE, true, source, null, qualify(NOTE, key), args); 8.60 } 8.61 8.62 /** 8.63 @@ -140,7 +139,7 @@ 8.64 */ 8.65 public JCDiagnostic note( 8.66 DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { 8.67 - return new JCDiagnostic(messages, NOTE, false, source, pos, qualify(NOTE, key), args); 8.68 + return new JCDiagnostic(formatter, NOTE, false, source, pos, qualify(NOTE, key), args); 8.69 } 8.70 8.71 /** 8.72 @@ -149,7 +148,7 @@ 8.73 * @param args Fields of the error message. 8.74 */ 8.75 public JCDiagnostic fragment(String key, Object... args) { 8.76 - return new JCDiagnostic(messages, FRAGMENT, false, null, null, qualify(FRAGMENT, key), args); 8.77 + return new JCDiagnostic(formatter, FRAGMENT, false, null, null, qualify(FRAGMENT, key), args); 8.78 } 8.79 8.80 protected String qualify(DiagnosticType t, String key) { 8.81 @@ -163,10 +162,11 @@ 8.82 * Create a fragment diagnostic, for use as an argument in other diagnostics 8.83 * @param key The key for the localized error message. 8.84 * @param args Fields of the error message. 8.85 + * 8.86 */ 8.87 - // should be deprecated 8.88 + @Deprecated 8.89 public static JCDiagnostic fragment(String key, Object... args) { 8.90 - return new JCDiagnostic(Messages.getDefaultMessages(), 8.91 + return new JCDiagnostic(getFragmentFormatter(), 8.92 FRAGMENT, 8.93 false, 8.94 null, 8.95 @@ -174,6 +174,14 @@ 8.96 "compiler." + FRAGMENT.key + "." + key, 8.97 args); 8.98 } 8.99 + //where 8.100 + @Deprecated 8.101 + public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() { 8.102 + if (fragmentFormatter == null) { 8.103 + fragmentFormatter = new BasicDiagnosticFormatter(Messages.getDefaultMessages()); 8.104 + } 8.105 + return fragmentFormatter; 8.106 + } 8.107 8.108 /** 8.109 * A DiagnosticType defines the type of the diagnostic. 8.110 @@ -247,7 +255,6 @@ 8.111 private final int pos; 8.112 } 8.113 8.114 - private final Messages messages; 8.115 private final DiagnosticType type; 8.116 private final DiagnosticSource source; 8.117 private final DiagnosticPosition position; 8.118 @@ -266,7 +273,7 @@ 8.119 * @param key a resource key to identify the text of the diagnostic 8.120 * @param args arguments to be included in the text of the diagnostic 8.121 */ 8.122 - protected JCDiagnostic(Messages messages, 8.123 + protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter, 8.124 DiagnosticType dt, 8.125 boolean mandatory, 8.126 DiagnosticSource source, 8.127 @@ -276,7 +283,7 @@ 8.128 if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) 8.129 throw new IllegalArgumentException(); 8.130 8.131 - this.messages = messages; 8.132 + this.defaultFormatter = formatter; 8.133 this.type = dt; 8.134 this.mandatory = mandatory; 8.135 this.source = source; 8.136 @@ -398,25 +405,19 @@ 8.137 * @return the prefix string associated with a particular type of diagnostic 8.138 */ 8.139 public String getPrefix(DiagnosticType dt) { 8.140 - return getFormatter().formatKind(this, Locale.getDefault()); 8.141 + return defaultFormatter.formatKind(this, Locale.getDefault()); 8.142 } 8.143 8.144 - private DiagnosticFormatter<JCDiagnostic> getFormatter() { 8.145 - if (defaultFormatter == null) { 8.146 - defaultFormatter = new BasicDiagnosticFormatter(messages); 8.147 - } 8.148 - return defaultFormatter; 8.149 - } 8.150 - 8.151 - 8.152 /** 8.153 * Return the standard presentation of this diagnostic. 8.154 */ 8.155 public String toString() { 8.156 - return getFormatter().format(this,Locale.getDefault()); 8.157 + return defaultFormatter.format(this,Locale.getDefault()); 8.158 } 8.159 8.160 - private static DiagnosticFormatter<JCDiagnostic> defaultFormatter; 8.161 + private DiagnosticFormatter<JCDiagnostic> defaultFormatter; 8.162 + @Deprecated 8.163 + private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter; 8.164 8.165 // Methods for javax.tools.Diagnostic 8.166 8.167 @@ -440,6 +441,6 @@ 8.168 8.169 public String getMessage(Locale locale) { 8.170 // RFE 6406133: JCDiagnostic.getMessage ignores locale argument 8.171 - return getFormatter().formatMessage(this, locale); 8.172 + return defaultFormatter.formatMessage(this, locale); 8.173 } 8.174 }
9.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Thu Aug 07 09:45:08 2008 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Thu Aug 07 18:03:32 2008 -0700 9.3 @@ -25,6 +25,7 @@ 9.4 9.5 package com.sun.tools.javap; 9.6 9.7 +import java.net.URI; 9.8 import java.util.Collection; 9.9 import java.util.List; 9.10 9.11 @@ -35,6 +36,7 @@ 9.12 import com.sun.tools.classfile.Code_attribute; 9.13 import com.sun.tools.classfile.ConstantPool; 9.14 import com.sun.tools.classfile.ConstantPoolException; 9.15 +import com.sun.tools.classfile.ConstantValue_attribute; 9.16 import com.sun.tools.classfile.Descriptor; 9.17 import com.sun.tools.classfile.DescriptorException; 9.18 import com.sun.tools.classfile.Exceptions_attribute; 9.19 @@ -45,6 +47,8 @@ 9.20 import com.sun.tools.classfile.SourceFile_attribute; 9.21 import com.sun.tools.classfile.Type; 9.22 9.23 +import java.text.DateFormat; 9.24 +import java.util.Date; 9.25 import static com.sun.tools.classfile.AccessFlags.*; 9.26 9.27 /* 9.28 @@ -72,6 +76,23 @@ 9.29 constantWriter = ConstantWriter.instance(context); 9.30 } 9.31 9.32 + void setDigest(String name, byte[] digest) { 9.33 + this.digestName = name; 9.34 + this.digest = digest; 9.35 + } 9.36 + 9.37 + void setFile(URI uri) { 9.38 + this.uri = uri; 9.39 + } 9.40 + 9.41 + void setFileSize(int size) { 9.42 + this.size = size; 9.43 + } 9.44 + 9.45 + void setLastModified(long lastModified) { 9.46 + this.lastModified = lastModified; 9.47 + } 9.48 + 9.49 ClassFile getClassFile() { 9.50 return classFile; 9.51 } 9.52 @@ -84,6 +105,32 @@ 9.53 classFile = cf; 9.54 constant_pool = classFile.constant_pool; 9.55 9.56 + if ((options.sysInfo || options.verbose) && !options.compat) { 9.57 + if (uri != null) { 9.58 + if (uri.getScheme().equals("file")) 9.59 + println("Classfile " + uri.getPath()); 9.60 + else 9.61 + println("Classfile " + uri); 9.62 + } 9.63 + if (lastModified != -1) { 9.64 + Date lm = new Date(lastModified); 9.65 + DateFormat df = DateFormat.getDateInstance(); 9.66 + if (size > 0) { 9.67 + println("Last modified " + df.format(lm) + "; size " + size + " bytes"); 9.68 + } else { 9.69 + println("Last modified " + df.format(lm)); 9.70 + } 9.71 + } else if (size > 0) { 9.72 + println("Size " + size + " bytes"); 9.73 + } 9.74 + if (digestName != null && digest != null) { 9.75 + StringBuilder sb = new StringBuilder(); 9.76 + for (byte b: digest) 9.77 + sb.append(String.format("%02x", b)); 9.78 + println(digestName + " checksum " + sb); 9.79 + } 9.80 + } 9.81 + 9.82 Attribute sfa = cf.getAttribute(Attribute.SourceFile); 9.83 if (sfa instanceof SourceFile_attribute) { 9.84 println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\""); 9.85 @@ -185,6 +232,14 @@ 9.86 } 9.87 print(" "); 9.88 print(getFieldName(f)); 9.89 + if (options.showConstants && !options.compat) { // BUG 4111861 print static final field contents 9.90 + Attribute a = f.attributes.get(Attribute.ConstantValue); 9.91 + if (a instanceof ConstantValue_attribute) { 9.92 + print(" = "); 9.93 + ConstantValue_attribute cv = (ConstantValue_attribute) a; 9.94 + print(getConstantValue(f.descriptor, cv.constantvalue_index)); 9.95 + } 9.96 + } 9.97 print(";"); 9.98 println(); 9.99 9.100 @@ -481,11 +536,91 @@ 9.101 } 9.102 } 9.103 9.104 + /** 9.105 + * Get the value of an entry in the constant pool as a Java constant. 9.106 + * Characters and booleans are represented by CONSTANT_Intgere entries. 9.107 + * Character and string values are processed to escape characters outside 9.108 + * the basic printable ASCII set. 9.109 + * @param d the descriptor, giving the expected type of the constant 9.110 + * @param index the index of the value in the constant pool 9.111 + * @return a printable string containing the value of the constant. 9.112 + */ 9.113 + String getConstantValue(Descriptor d, int index) { 9.114 + try { 9.115 + ConstantPool.CPInfo cpInfo = constant_pool.get(index); 9.116 + 9.117 + switch (cpInfo.getTag()) { 9.118 + case ConstantPool.CONSTANT_Integer: { 9.119 + ConstantPool.CONSTANT_Integer_info info = 9.120 + (ConstantPool.CONSTANT_Integer_info) cpInfo; 9.121 + String t = d.getValue(constant_pool); 9.122 + if (t.equals("C")) { // character 9.123 + return getConstantCharValue((char) info.value); 9.124 + } else if (t.equals("Z")) { // boolean 9.125 + return String.valueOf(info.value == 1); 9.126 + } else { // other: assume integer 9.127 + return String.valueOf(info.value); 9.128 + } 9.129 + } 9.130 + 9.131 + case ConstantPool.CONSTANT_String: { 9.132 + ConstantPool.CONSTANT_String_info info = 9.133 + (ConstantPool.CONSTANT_String_info) cpInfo; 9.134 + return getConstantStringValue(info.getString()); 9.135 + } 9.136 + 9.137 + default: 9.138 + return constantWriter.stringValue(cpInfo); 9.139 + } 9.140 + } catch (ConstantPoolException e) { 9.141 + return "#" + index; 9.142 + } 9.143 + } 9.144 + 9.145 + private String getConstantCharValue(char c) { 9.146 + StringBuilder sb = new StringBuilder(); 9.147 + sb.append('\''); 9.148 + sb.append(esc(c, '\'')); 9.149 + sb.append('\''); 9.150 + return sb.toString(); 9.151 + } 9.152 + 9.153 + private String getConstantStringValue(String s) { 9.154 + StringBuilder sb = new StringBuilder(); 9.155 + sb.append("\""); 9.156 + for (int i = 0; i < s.length(); i++) { 9.157 + sb.append(esc(s.charAt(i), '"')); 9.158 + } 9.159 + sb.append("\""); 9.160 + return sb.toString(); 9.161 + } 9.162 + 9.163 + private String esc(char c, char quote) { 9.164 + if (32 <= c && c <= 126 && c != quote) 9.165 + return String.valueOf(c); 9.166 + else switch (c) { 9.167 + case '\b': return "\\b"; 9.168 + case '\n': return "\\n"; 9.169 + case '\t': return "\\t"; 9.170 + case '\f': return "\\f"; 9.171 + case '\r': return "\\r"; 9.172 + case '\\': return "\\\\"; 9.173 + case '\'': return "\\'"; 9.174 + case '\"': return "\\\""; 9.175 + default: return String.format("\\u%04x", (int) c); 9.176 + } 9.177 + } 9.178 + 9.179 private Options options; 9.180 private AttributeWriter attrWriter; 9.181 private CodeWriter codeWriter; 9.182 private ConstantWriter constantWriter; 9.183 private ClassFile classFile; 9.184 + private URI uri; 9.185 + private long lastModified; 9.186 + private String digestName; 9.187 + private byte[] digest; 9.188 + private int size; 9.189 private ConstantPool constant_pool; 9.190 private Method method; 9.191 private static final String NEWLINE = System.getProperty("line.separator", "\n");
10.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Thu Aug 07 09:45:08 2008 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Thu Aug 07 18:03:32 2008 -0700 10.3 @@ -16,7 +16,7 @@ 10.4 * 10.5 * You should have received a copy of the GNU General Public License version 10.6 * 2 along with this work; if not, write to the Free Software Foundation, 10.7 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-15301 USA. 10.8 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.9 * 10.10 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 10.11 * CA 95054 USA or visit www.sun.com if you need additional information or 10.12 @@ -27,11 +27,15 @@ 10.13 10.14 import java.io.EOFException; 10.15 import java.io.FileNotFoundException; 10.16 +import java.io.FilterInputStream; 10.17 +import java.io.InputStream; 10.18 import java.io.IOException; 10.19 import java.io.OutputStream; 10.20 import java.io.PrintWriter; 10.21 import java.io.StringWriter; 10.22 import java.io.Writer; 10.23 +import java.security.DigestInputStream; 10.24 +import java.security.MessageDigest; 10.25 import java.text.MessageFormat; 10.26 import java.util.ArrayList; 10.27 import java.util.Arrays; 10.28 @@ -199,6 +203,12 @@ 10.29 } 10.30 }, 10.31 10.32 + new Option(false, "-sysinfo") { 10.33 + void process(JavapTask task, String opt, String arg) { 10.34 + task.options.sysInfo = true; 10.35 + } 10.36 + }, 10.37 + 10.38 new Option(false, "-Xold") { 10.39 void process(JavapTask task, String opt, String arg) throws BadArgs { 10.40 // -Xold is only supported as first arg when invoked from 10.41 @@ -229,6 +239,12 @@ 10.42 void process(JavapTask task, String opt, String arg) { 10.43 task.options.ignoreSymbolFile = true; 10.44 } 10.45 + }, 10.46 + 10.47 + new Option(false, "-constants") { 10.48 + void process(JavapTask task, String opt, String arg) { 10.49 + task.options.showConstants = true; 10.50 + } 10.51 } 10.52 10.53 }; 10.54 @@ -488,8 +504,27 @@ 10.55 Attribute.Factory attributeFactory = new Attribute.Factory(); 10.56 attributeFactory.setCompat(options.compat); 10.57 attributeFactory.setJSR277(options.jsr277); 10.58 - ClassFile cf = ClassFile.read(fo.openInputStream(), attributeFactory); 10.59 + 10.60 + InputStream in = fo.openInputStream(); 10.61 + SizeInputStream sizeIn = null; 10.62 + MessageDigest md = null; 10.63 + if (options.sysInfo || options.verbose) { 10.64 + md = MessageDigest.getInstance("MD5"); 10.65 + in = new DigestInputStream(in, md); 10.66 + in = sizeIn = new SizeInputStream(in); 10.67 + } 10.68 + 10.69 + ClassFile cf = ClassFile.read(in, attributeFactory); 10.70 + 10.71 + if (options.sysInfo || options.verbose) { 10.72 + classWriter.setFile(fo.toUri()); 10.73 + classWriter.setLastModified(fo.getLastModified()); 10.74 + classWriter.setDigest("MD5", md.digest()); 10.75 + classWriter.setFileSize(sizeIn.size()); 10.76 + } 10.77 + 10.78 classWriter.write(cf); 10.79 + 10.80 } catch (ConstantPoolException e) { 10.81 diagnosticListener.report(createDiagnostic("err.bad.constant.pool", className, e.getLocalizedMessage())); 10.82 ok = false; 10.83 @@ -659,4 +694,31 @@ 10.84 Map<Locale, ResourceBundle> bundles; 10.85 10.86 private static final String progname = "javap"; 10.87 + 10.88 + private static class SizeInputStream extends FilterInputStream { 10.89 + SizeInputStream(InputStream in) { 10.90 + super(in); 10.91 + } 10.92 + 10.93 + int size() { 10.94 + return size; 10.95 + } 10.96 + 10.97 + @Override 10.98 + public int read(byte[] buf, int offset, int length) throws IOException { 10.99 + int n = super.read(buf, offset, length); 10.100 + if (n > 0) 10.101 + size += n; 10.102 + return n; 10.103 + } 10.104 + 10.105 + @Override 10.106 + public int read() throws IOException { 10.107 + int b = super.read(); 10.108 + size += 1; 10.109 + return b; 10.110 + } 10.111 + 10.112 + private int size; 10.113 + } 10.114 }
11.1 --- a/src/share/classes/com/sun/tools/javap/Options.java Thu Aug 07 09:45:08 2008 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javap/Options.java Thu Aug 07 18:03:32 2008 -0700 11.3 @@ -80,6 +80,8 @@ 11.4 public boolean showDisassembled; 11.5 public boolean showInternalSignatures; 11.6 public boolean showAllAttrs; 11.7 + public boolean showConstants; 11.8 + public boolean sysInfo; 11.9 11.10 public boolean compat; // bug-for-bug compatibility mode with old javap 11.11 public boolean jsr277;
12.1 --- a/src/share/classes/com/sun/tools/javap/resources/javap.properties Thu Aug 07 09:45:08 2008 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties Thu Aug 07 18:03:32 2008 -0700 12.3 @@ -63,5 +63,10 @@ 12.4 main.opt.bootclasspath=\ 12.5 \ -bootclasspath <path> Override location of bootstrap class files 12.6 12.7 +main.opt.constants=\ 12.8 +\ -constants Show static final constants 12.9 12.10 12.11 +main.opt.sysinfo=\ 12.12 +\ -sysinfo Show system info (path, size, date, MD5 hash)\n\ 12.13 +\ of class being processed
13.1 --- a/test/tools/javac/5045412/Bar.java Thu Aug 07 09:45:08 2008 -0700 13.2 +++ b/test/tools/javac/5045412/Bar.java Thu Aug 07 18:03:32 2008 -0700 13.3 @@ -1,13 +1,36 @@ 13.4 -/** 13.5 - * @test /nodynamiccopyright/ 13.6 - * @bug 5045412 13.7 - * @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java 13.8 +/* 13.9 + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 13.10 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.11 + * 13.12 + * This code is free software; you can redistribute it and/or modify it 13.13 + * under the terms of the GNU General Public License version 2 only, as 13.14 + * published by the Free Software Foundation. 13.15 + * 13.16 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.18 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.19 + * version 2 for more details (a copy is included in the LICENSE file that 13.20 + * accompanied this code). 13.21 + * 13.22 + * You should have received a copy of the GNU General Public License version 13.23 + * 2 along with this work; if not, write to the Free Software Foundation, 13.24 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.25 + * 13.26 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 13.27 + * CA 95054 USA or visit www.sun.com if you need additional information or 13.28 + * have any questions. 13.29 */ 13.30 13.31 /** 13.32 - * @test /nodynamiccopyright/ 13.33 - * @bug 5045412 13.34 - * @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java 13.35 + * @test 13.36 + * @bug 5045412 6627366 13.37 + * @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java 13.38 + */ 13.39 + 13.40 +/** 13.41 + * @test 13.42 + * @bug 5045412 6627366 13.43 + * @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java 13.44 */ 13.45 13.46 class Bar implements java.io.Serializable { }
14.1 --- a/test/tools/javac/5045412/Foo.java Thu Aug 07 09:45:08 2008 -0700 14.2 +++ b/test/tools/javac/5045412/Foo.java Thu Aug 07 18:03:32 2008 -0700 14.3 @@ -23,14 +23,14 @@ 14.4 14.5 /** 14.6 * @test 14.7 - * @bug 5045412 14.8 + * @bug 5045412 6627366 14.9 * @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java 14.10 */ 14.11 14.12 /** 14.13 * @test 14.14 - * @bug 5045412 14.15 - * @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java 14.16 + * @bug 5045412 6627366 14.17 + * @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java 14.18 */ 14.19 14.20 class Foo { }
15.1 --- a/test/tools/javac/5045412/out Thu Aug 07 09:45:08 2008 -0700 15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 15.3 @@ -1,2 +0,0 @@ 15.4 -Bar.java:13:29: compiler.err.cant.resolve.location: kindname.class, Serializable, , , kindname.package, java.io 15.5 -1 error
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/6627362/T6627362.java Thu Aug 07 18:03:32 2008 -0700 16.3 @@ -0,0 +1,133 @@ 16.4 +/* 16.5 + * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 16.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 16.24 + * have any questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * @test 16.29 + * @bug 6627362 16.30 + * @summary javac generates code that uses array.clone, 16.31 + * which is not available on JavaCard 16.32 + */ 16.33 + 16.34 +import java.io.*; 16.35 +import java.lang.reflect.*; 16.36 +import java.net.*; 16.37 +import java.util.*; 16.38 + 16.39 +public class T6627362 { 16.40 + static String testSrc = System.getProperty("test.src", "."); 16.41 + 16.42 + public static void main(String... args) throws Exception { 16.43 + new T6627362().run(); 16.44 + } 16.45 + 16.46 + public void run() throws Exception { 16.47 + testStandard(); 16.48 + testNoClone(); 16.49 + if (errors > 0) 16.50 + throw new Error(errors + " test cases failed"); 16.51 + } 16.52 + 16.53 + void testStandard() throws Exception { 16.54 + // compile and disassemble E.java, check for reference to Object.clone() 16.55 + File x = new File(testSrc, "x"); 16.56 + String[] jcArgs = { "-d", ".", 16.57 + new File(x, "E.java").getPath() }; 16.58 + compile(jcArgs); 16.59 + 16.60 + String[] jpArgs = { "-classpath", ".", "-c", "E" }; 16.61 + 16.62 + StringWriter sw = new StringWriter(); 16.63 + javap(new PrintWriter(sw, true), jpArgs); 16.64 + check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;"); 16.65 + callValues(); 16.66 + } 16.67 + 16.68 + void testNoClone() throws Exception { 16.69 + // compile and disassemble E.java, using modified Object.java, 16.70 + // check for reference to System.arraycopy 16.71 + File x = new File(testSrc, "x"); 16.72 + String[] jcArgs = { "-d", ".", 16.73 + new File(x, "E.java").getPath(), 16.74 + new File(x, "Object.java").getPath()}; 16.75 + compile(jcArgs); 16.76 + 16.77 + String[] jpArgs = { "-classpath", ".", "-c", "E" }; 16.78 + 16.79 + StringWriter sw = new StringWriter(); 16.80 + javap(new PrintWriter(sw, true), jpArgs); 16.81 + check(sw.toString(), "//Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); 16.82 + callValues(); 16.83 + } 16.84 + 16.85 + void compile(String... args) { 16.86 + int rc = com.sun.tools.javac.Main.compile(args); 16.87 + if (rc != 0) 16.88 + throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); 16.89 + } 16.90 + 16.91 + void javap(PrintWriter out, String... args) throws Exception { 16.92 + // for now, we have to exec javap 16.93 + File javaHome = new File(System.getProperty("java.home")); 16.94 + if (javaHome.getName().equals("jre")) 16.95 + javaHome = javaHome.getParentFile(); 16.96 + File javap = new File(new File(javaHome, "bin"), "javap"); 16.97 + String[] cmd = new String[args.length + 1]; 16.98 + cmd[0] = javap.getPath(); 16.99 + System.arraycopy(args, 0, cmd, 1, args.length); 16.100 + Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start(); 16.101 + p.getOutputStream().close(); 16.102 + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 16.103 + String line; 16.104 + while ((line = in.readLine()) != null) 16.105 + out.println(line); 16.106 + int rc = p.waitFor(); 16.107 + if (rc != 0) 16.108 + throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); 16.109 + } 16.110 + 16.111 + void check(String s, String require) { 16.112 + if (s.indexOf(require) == -1) { 16.113 + System.err.println("Can't find " + require); 16.114 + errors++; 16.115 + } 16.116 + } 16.117 + 16.118 + void callValues() { 16.119 + try { 16.120 + File dot = new File(System.getProperty("user.dir")); 16.121 + ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() }); 16.122 + Class<?> e_class = cl.loadClass("E"); 16.123 + Method m = e_class.getMethod("values", new Class[] { }); 16.124 + //System.err.println(m); 16.125 + Object o = m.invoke(null, (Object[]) null); 16.126 + List<Object> v = Arrays.asList((Object[]) o); 16.127 + if (!v.toString().equals("[a, b, c]")) 16.128 + throw new Error("unexpected result for E.values(): " + v); 16.129 + } catch (Exception e) { 16.130 + throw new Error(e); 16.131 + } 16.132 + } 16.133 + 16.134 + int errors; 16.135 +} 16.136 +
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/6627362/x/E.java Thu Aug 07 18:03:32 2008 -0700 17.3 @@ -0,0 +1,26 @@ 17.4 +/* 17.5 + * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 17.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 17.24 + * have any questions. 17.25 + */ 17.26 + 17.27 +public enum E { 17.28 + a, b, c 17.29 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/6627362/x/Object.java Thu Aug 07 18:03:32 2008 -0700 18.3 @@ -0,0 +1,30 @@ 18.4 +/* 18.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. 18.11 + * 18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 + * version 2 for more details (a copy is included in the LICENSE file that 18.16 + * accompanied this code). 18.17 + * 18.18 + * You should have received a copy of the GNU General Public License version 18.19 + * 2 along with this work; if not, write to the Free Software Foundation, 18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 + * 18.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 18.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 18.24 + * have any questions. 18.25 + */ 18.26 + 18.27 +package java.lang; 18.28 + 18.29 +/* 18.30 + * Object, without clone() 18.31 + */ 18.32 +public class Object { 18.33 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/synthesize/Boolean.java Thu Aug 07 18:03:32 2008 -0700 19.3 @@ -0,0 +1,41 @@ 19.4 +/* 19.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 19.24 + * have any questions. 19.25 + */ 19.26 + 19.27 +package java.lang; 19.28 + 19.29 +public class Boolean 19.30 +{ 19.31 + public static Boolean valueOf(boolean v) { 19.32 + return new Boolean(v); 19.33 + } 19.34 + 19.35 + public Boolean(boolean v) { 19.36 + value = v; 19.37 + } 19.38 + 19.39 + public boolean booleanValue() { 19.40 + return value; 19.41 + } 19.42 + 19.43 + private boolean value; 19.44 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/synthesize/Byte.java Thu Aug 07 18:03:32 2008 -0700 20.3 @@ -0,0 +1,41 @@ 20.4 +/* 20.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 20.24 + * have any questions. 20.25 + */ 20.26 + 20.27 +package java.lang; 20.28 + 20.29 +public class Byte 20.30 +{ 20.31 + public static Byte valueOf(byte v) { 20.32 + return new Byte(v); 20.33 + } 20.34 + 20.35 + public Byte(byte v) { 20.36 + value = v; 20.37 + } 20.38 + 20.39 + public byte byteValue() { 20.40 + return value; 20.41 + } 20.42 + 20.43 + private byte value; 20.44 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/synthesize/Character.java Thu Aug 07 18:03:32 2008 -0700 21.3 @@ -0,0 +1,41 @@ 21.4 +/* 21.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 21.24 + * have any questions. 21.25 + */ 21.26 + 21.27 +package java.lang; 21.28 + 21.29 +public class Character 21.30 +{ 21.31 + public static Character valueOf(char v) { 21.32 + return new Character(v); 21.33 + } 21.34 + 21.35 + public Character(char v) { 21.36 + value = v; 21.37 + } 21.38 + 21.39 + public char characterValue() { 21.40 + return value; 21.41 + } 21.42 + 21.43 + private char value; 21.44 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/synthesize/Cloneable.java Thu Aug 07 18:03:32 2008 -0700 22.3 @@ -0,0 +1,27 @@ 22.4 +/* 22.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 22.24 + * have any questions. 22.25 + */ 22.26 + 22.27 +package java.lang; 22.28 + 22.29 +public interface Cloneable { 22.30 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/synthesize/Double.java Thu Aug 07 18:03:32 2008 -0700 23.3 @@ -0,0 +1,18 @@ 23.4 +package java.lang; 23.5 + 23.6 +public class Double extends Number 23.7 +{ 23.8 + public static Double valueOf(double v) { 23.9 + return new Double(v); 23.10 + } 23.11 + 23.12 + public Double(double v) { 23.13 + value = v; 23.14 + } 23.15 + 23.16 + public double doubleValue() { 23.17 + return value; 23.18 + } 23.19 + 23.20 + private double value; 23.21 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/synthesize/Float.java Thu Aug 07 18:03:32 2008 -0700 24.3 @@ -0,0 +1,18 @@ 24.4 +package java.lang; 24.5 + 24.6 +public class Float extends Number 24.7 +{ 24.8 + public static Float valueOf(float v) { 24.9 + return new Float(v); 24.10 + } 24.11 + 24.12 + public Float(float v) { 24.13 + value = v; 24.14 + } 24.15 + 24.16 + public float floatValue() { 24.17 + return value; 24.18 + } 24.19 + 24.20 + private float value; 24.21 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/tools/javac/synthesize/Integer.java Thu Aug 07 18:03:32 2008 -0700 25.3 @@ -0,0 +1,41 @@ 25.4 +/* 25.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 + * 25.8 + * This code is free software; you can redistribute it and/or modify it 25.9 + * under the terms of the GNU General Public License version 2 only, as 25.10 + * published by the Free Software Foundation. 25.11 + * 25.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.15 + * version 2 for more details (a copy is included in the LICENSE file that 25.16 + * accompanied this code). 25.17 + * 25.18 + * You should have received a copy of the GNU General Public License version 25.19 + * 2 along with this work; if not, write to the Free Software Foundation, 25.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.21 + * 25.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 25.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 25.24 + * have any questions. 25.25 + */ 25.26 + 25.27 +package java.lang; 25.28 + 25.29 +public class Integer extends Number 25.30 +{ 25.31 + public static Integer valueOf(int v) { 25.32 + return new Integer(v); 25.33 + } 25.34 + 25.35 + public Integer(int v) { 25.36 + value = v; 25.37 + } 25.38 + 25.39 + public int integerValue() { 25.40 + return value; 25.41 + } 25.42 + 25.43 + private int value; 25.44 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javac/synthesize/Long.java Thu Aug 07 18:03:32 2008 -0700 26.3 @@ -0,0 +1,41 @@ 26.4 +/* 26.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 26.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 26.24 + * have any questions. 26.25 + */ 26.26 + 26.27 +package java.lang; 26.28 + 26.29 +public class Long extends Number 26.30 +{ 26.31 + public static Long valueOf(long v) { 26.32 + return new Long(v); 26.33 + } 26.34 + 26.35 + public Long(long v) { 26.36 + value = v; 26.37 + } 26.38 + 26.39 + public long longValue() { 26.40 + return value; 26.41 + } 26.42 + 26.43 + private long value; 26.44 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/synthesize/Main.java Thu Aug 07 18:03:32 2008 -0700 27.3 @@ -0,0 +1,122 @@ 27.4 +/* 27.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 27.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 27.24 + * have any questions. 27.25 + */ 27.26 + 27.27 +/* 27.28 + * @test 27.29 + * @bug 6627364 6627366 27.30 + * @summary Synthesize important classes if they are missing from the (boot)classpath 27.31 + */ 27.32 + 27.33 +import java.io.*; 27.34 +import java.util.*; 27.35 + 27.36 +public class Main 27.37 +{ 27.38 + File testSrc = new File(System.getProperty("test.src")); 27.39 + 27.40 + public static void main(String[] args) throws Exception { 27.41 + new Main().run(); 27.42 + } 27.43 + 27.44 + public void run() throws Exception { 27.45 + 27.46 + // compile with standard bootclasspath 27.47 + compile(true, "Test.java"); 27.48 + 27.49 + // compile with various missing system classes 27.50 + 27.51 + List<String> base_files = Arrays.asList( 27.52 + "Boolean.java", 27.53 + "Byte.java", 27.54 + "Character.java", 27.55 + "Integer.java", 27.56 + "Long.java", 27.57 + "Number.java", 27.58 + "Object.java", 27.59 + "Short.java", 27.60 + "Void.java" 27.61 + ); 27.62 + 27.63 + List<String> extra_files = Arrays.asList( 27.64 + "Double.java", 27.65 + "Float.java", 27.66 + "Cloneable.java", 27.67 + "Serializable.java" 27.68 + ); 27.69 + 27.70 + List<String> files = new ArrayList<String>(); 27.71 + files.addAll(base_files); 27.72 + files.add("Test.java"); 27.73 + 27.74 + compile(false, files); 27.75 + 27.76 + for (String f: extra_files) { 27.77 + files = new ArrayList<String>(); 27.78 + files.addAll(base_files); 27.79 + files.addAll(extra_files); 27.80 + files.remove(f); 27.81 + files.add("Test.java"); 27.82 + compile(false, files); 27.83 + } 27.84 + 27.85 + if (errors > 0) 27.86 + throw new Exception(errors + " errors occurred"); 27.87 + } 27.88 + 27.89 + void compile(boolean stdBootClassPath, String... files) { 27.90 + compile(stdBootClassPath, Arrays.asList(files)); 27.91 + } 27.92 + 27.93 + void compile(boolean stdBootClassPath, List<String> files) { 27.94 + File empty = new File("empty"); 27.95 + empty.mkdirs(); 27.96 + 27.97 + List<String> args = new ArrayList<String>(); 27.98 + args.add("-classpath"); 27.99 + args.add("empty"); 27.100 + 27.101 + if (!stdBootClassPath) { 27.102 + args.add("-bootclasspath"); 27.103 + args.add("empty"); 27.104 + } 27.105 + args.add("-d"); 27.106 + args.add("."); 27.107 + for (String f: files) 27.108 + args.add(new File(testSrc, f).getPath()); 27.109 + 27.110 + System.out.println("Compile: " + args); 27.111 + StringWriter out = new StringWriter(); 27.112 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), 27.113 + new PrintWriter(out)); 27.114 + System.out.println(out.toString()); 27.115 + System.out.println("result: " + rc); 27.116 + System.out.println(); 27.117 + 27.118 + if (rc != 0) 27.119 + errors++; 27.120 + } 27.121 + 27.122 + private int errors; 27.123 +} 27.124 + 27.125 +
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/synthesize/Number.java Thu Aug 07 18:03:32 2008 -0700 28.3 @@ -0,0 +1,29 @@ 28.4 +/* 28.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 28.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 28.24 + * have any questions. 28.25 + */ 28.26 + 28.27 +package java.lang; 28.28 + 28.29 +public class Number 28.30 +{ 28.31 + 28.32 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/tools/javac/synthesize/Object.java Thu Aug 07 18:03:32 2008 -0700 29.3 @@ -0,0 +1,28 @@ 29.4 +/* 29.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. 29.11 + * 29.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.15 + * version 2 for more details (a copy is included in the LICENSE file that 29.16 + * accompanied this code). 29.17 + * 29.18 + * You should have received a copy of the GNU General Public License version 29.19 + * 2 along with this work; if not, write to the Free Software Foundation, 29.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.21 + * 29.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 29.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 29.24 + * have any questions. 29.25 + */ 29.26 + 29.27 +package java.lang; 29.28 + 29.29 +public class Object 29.30 +{ 29.31 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/tools/javac/synthesize/Serializable.java Thu Aug 07 18:03:32 2008 -0700 30.3 @@ -0,0 +1,27 @@ 30.4 +/* 30.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. 30.11 + * 30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.15 + * version 2 for more details (a copy is included in the LICENSE file that 30.16 + * accompanied this code). 30.17 + * 30.18 + * You should have received a copy of the GNU General Public License version 30.19 + * 2 along with this work; if not, write to the Free Software Foundation, 30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.21 + * 30.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 30.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 30.24 + * have any questions. 30.25 + */ 30.26 + 30.27 +package java.io; 30.28 + 30.29 +public interface Serializable { 30.30 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/tools/javac/synthesize/Short.java Thu Aug 07 18:03:32 2008 -0700 31.3 @@ -0,0 +1,41 @@ 31.4 +/* 31.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. 31.11 + * 31.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.15 + * version 2 for more details (a copy is included in the LICENSE file that 31.16 + * accompanied this code). 31.17 + * 31.18 + * You should have received a copy of the GNU General Public License version 31.19 + * 2 along with this work; if not, write to the Free Software Foundation, 31.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.21 + * 31.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 31.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 31.24 + * have any questions. 31.25 + */ 31.26 + 31.27 +package java.lang; 31.28 + 31.29 +public class Short extends Number 31.30 +{ 31.31 + public static Short valueOf(short v) { 31.32 + return new Short(v); 31.33 + } 31.34 + 31.35 + public Short(short v) { 31.36 + value = v; 31.37 + } 31.38 + 31.39 + public short shortValue() { 31.40 + return value; 31.41 + } 31.42 + 31.43 + private short value; 31.44 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/synthesize/Test.java Thu Aug 07 18:03:32 2008 -0700 32.3 @@ -0,0 +1,32 @@ 32.4 +/* 32.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. 32.11 + * 32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 + * version 2 for more details (a copy is included in the LICENSE file that 32.16 + * accompanied this code). 32.17 + * 32.18 + * You should have received a copy of the GNU General Public License version 32.19 + * 2 along with this work; if not, write to the Free Software Foundation, 32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 + * 32.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 32.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 32.24 + * have any questions. 32.25 + */ 32.26 + 32.27 +// This code (indirectly) requires the presence of 32.28 +// Cloneable and Serializable (supertypes for Java arrays) 32.29 +// Double and Float (for boxing/unboxing) 32.30 +public class Test 32.31 +{ 32.32 + Object f(boolean b, int[] array) { 32.33 + return b ? array : 2; 32.34 + } 32.35 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/synthesize/Void.java Thu Aug 07 18:03:32 2008 -0700 33.3 @@ -0,0 +1,29 @@ 33.4 +/* 33.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 33.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 33.24 + * have any questions. 33.25 + */ 33.26 + 33.27 +package java.lang; 33.28 + 33.29 +public class Void 33.30 +{ 33.31 + 33.32 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javap/4111861/A.java Thu Aug 07 18:03:32 2008 -0700 34.3 @@ -0,0 +1,14 @@ 34.4 +class A { 34.5 + public static final int i = 42; 34.6 + public static final boolean b = true; 34.7 + public static final float f = 1.0f; 34.8 + public static final double d = 1.0d; 34.9 + public static final short s = 1; 34.10 + public static final long l = 1l; 34.11 + public static final char cA = 'A'; 34.12 + public static final char c0 = '\u0000'; 34.13 + public static final char cn = '\n'; 34.14 + public static final char cq1 = '\''; 34.15 + public static final char cq2 = '"'; 34.16 + public static final java.lang.String t1 = "abc \u0000 \f\n\r\t'\""; 34.17 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javap/4111861/T4111861.java Thu Aug 07 18:03:32 2008 -0700 35.3 @@ -0,0 +1,101 @@ 35.4 +/* 35.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 35.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 35.24 + * have any questions. 35.25 + */ 35.26 + 35.27 +import java.io.*; 35.28 + 35.29 +/* 35.30 + * @test 35.31 + * @bug 4111861 35.32 + * @summary static final field contents are not displayed 35.33 + */ 35.34 +public class T4111861 { 35.35 + public static void main(String... args) throws Exception { 35.36 + new T4111861().run(); 35.37 + } 35.38 + 35.39 + void run() throws Exception { 35.40 + File testSrc = new File(System.getProperty("test.src", ".")); 35.41 + File a_java = new File(testSrc, "A.java"); 35.42 + javac("-d", ".", a_java.getPath()); 35.43 + 35.44 + String out = javap("-classpath", ".", "-constants", "A"); 35.45 + 35.46 + String a = read(a_java); 35.47 + 35.48 + if (!filter(out).equals(filter(read(a_java)))) { 35.49 + System.out.println(out); 35.50 + throw new Exception("unexpected output"); 35.51 + } 35.52 + } 35.53 + 35.54 + String javac(String... args) throws Exception { 35.55 + StringWriter sw = new StringWriter(); 35.56 + PrintWriter pw = new PrintWriter(sw); 35.57 + int rc = com.sun.tools.javac.Main.compile(args, pw); 35.58 + if (rc != 0) 35.59 + throw new Exception("javac failed, rc=" + rc); 35.60 + return sw.toString(); 35.61 + } 35.62 + 35.63 + String javap(String... args) throws Exception { 35.64 + StringWriter sw = new StringWriter(); 35.65 + PrintWriter pw = new PrintWriter(sw); 35.66 + int rc = com.sun.tools.javap.Main.run(args, pw); 35.67 + if (rc != 0) 35.68 + throw new Exception("javap failed, rc=" + rc); 35.69 + return sw.toString(); 35.70 + } 35.71 + 35.72 + String read(File f) throws IOException { 35.73 + StringBuilder sb = new StringBuilder(); 35.74 + BufferedReader in = new BufferedReader(new FileReader(f)); 35.75 + try { 35.76 + String line; 35.77 + while ((line = in.readLine()) != null) { 35.78 + sb.append(line); 35.79 + sb.append('\n'); 35.80 + } 35.81 + } finally { 35.82 + in.close(); 35.83 + } 35.84 + return sb.toString(); 35.85 + } 35.86 + 35.87 + // return those lines beginning "public static final" 35.88 + String filter(String s) throws IOException { 35.89 + StringBuilder sb = new StringBuilder(); 35.90 + BufferedReader in = new BufferedReader(new StringReader(s)); 35.91 + try { 35.92 + String line; 35.93 + while ((line = in.readLine()) != null) { 35.94 + if (line.indexOf("public static final") > 0) { 35.95 + sb.append(line); 35.96 + sb.append('\n'); 35.97 + } 35.98 + } 35.99 + } finally { 35.100 + in.close(); 35.101 + } 35.102 + return sb.toString(); 35.103 + } 35.104 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javap/T4884240.java Thu Aug 07 18:03:32 2008 -0700 36.3 @@ -0,0 +1,56 @@ 36.4 +/* 36.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. Sun designates this 36.11 + * particular file as subject to the "Classpath" exception as provided 36.12 + * by Sun in the LICENSE file that accompanied this code. 36.13 + * 36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.17 + * version 2 for more details (a copy is included in the LICENSE file that 36.18 + * accompanied this code). 36.19 + * 36.20 + * You should have received a copy of the GNU General Public License version 36.21 + * 2 along with this work; if not, write to the Free Software Foundation, 36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-15301 USA. 36.23 + * 36.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 36.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 36.26 + * have any questions. 36.27 + */ 36.28 + 36.29 +/* 36.30 + * @test 36.31 + * @bug 4884240 36.32 + * @summary additional option required for javap 36.33 + */ 36.34 + 36.35 +import java.io.*; 36.36 + 36.37 +public class T4884240 { 36.38 + public static void main(String... args) throws Exception { 36.39 + new T4884240().run(); 36.40 + } 36.41 + 36.42 + public void run() throws Exception { 36.43 + StringWriter sw = new StringWriter(); 36.44 + PrintWriter pw = new PrintWriter(sw); 36.45 + String[] args = { "-sysinfo", "java.lang.Object" }; 36.46 + int rc = com.sun.tools.javap.Main.run(args, pw); 36.47 + if (rc != 0) 36.48 + throw new Exception("unexpected return code: " + rc); 36.49 + pw.close(); 36.50 + String[] lines = sw.toString().split("\n"); 36.51 + if (lines.length < 3 36.52 + || !lines[0].startsWith("Classfile") 36.53 + || !lines[1].startsWith("Last modified") 36.54 + || !lines[2].startsWith("MD5")) { 36.55 + System.out.println(sw); 36.56 + throw new Exception("unexpected output"); 36.57 + } 36.58 + } 36.59 +}
37.1 --- a/test/tools/javap/T6622260.java Thu Aug 07 09:45:08 2008 -0700 37.2 +++ b/test/tools/javap/T6622260.java Thu Aug 07 18:03:32 2008 -0700 37.3 @@ -189,6 +189,10 @@ 37.4 37.5 void verify(String output) { 37.6 System.out.println(output); 37.7 + if (output.startsWith("Classfile")) { 37.8 + // make sure to ignore filename 37.9 + output = output.substring(output.indexOf('\n')); 37.10 + } 37.11 if (output.indexOf("-") >= 0) 37.12 throw new Error("- found in output"); 37.13 if (output.indexOf("FFFFFF") >= 0)