8004643: Reduce javac space overhead introduced with compiler support for repeating annotations

Reviewed-by: mcimadamore, jfranck
This commit is contained in:
Jonathan Gibbons 2013-06-04 14:17:50 -07:00
parent aeb1c4b67e
commit bdfb93ee25
17 changed files with 218 additions and 108 deletions

View file

@ -68,19 +68,11 @@ public class Lint
/** /**
* Returns the result of combining the values in this object with * Returns the result of combining the values in this object with
* the given annotations. * the metadata on the given symbol.
*/ */
public Lint augment(Annotations annots) { public Lint augment(Symbol sym) {
return augmentor.augment(this, annots.getDeclarationAttributes()); Lint l = augmentor.augment(this, sym.getDeclarationAttributes());
} if (sym.isDeprecated()) {
/**
* Returns the result of combining the values in this object with
* the given annotations and flags.
*/
public Lint augment(Annotations annots, long flags) {
Lint l = augmentor.augment(this, annots.getDeclarationAttributes());
if ((flags & DEPRECATED) != 0) {
if (l == this) if (l == this)
l = new Lint(this); l = new Lint(this);
l.values.remove(LintCategory.DEPRECATION); l.values.remove(LintCategory.DEPRECATION);

View file

@ -32,6 +32,7 @@ import javax.lang.model.element.*;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.comp.Annotate;
import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.comp.Env;
@ -74,35 +75,6 @@ public abstract class Symbol implements Element {
*/ */
public long flags() { return flags_field; } public long flags() { return flags_field; }
/** The attributes of this symbol are contained in this
* Annotations. The Annotations instance is NOT immutable.
*/
public final Annotations annotations = new Annotations(this);
/** An accessor method for the attributes of this symbol.
* Attributes of class symbols should be accessed through the accessor
* method to make sure that the class symbol is loaded.
*/
public List<Attribute.Compound> getRawAttributes() {
return annotations.getDeclarationAttributes();
}
/** An accessor method for the type attributes of this symbol.
* Attributes of class symbols should be accessed through the accessor
* method to make sure that the class symbol is loaded.
*/
public List<Attribute.TypeCompound> getRawTypeAttributes() {
return annotations.getTypeAttributes();
}
/** Fetch a particular annotation from a symbol. */
public Attribute.Compound attribute(Symbol anno) {
for (Attribute.Compound a : getRawAttributes()) {
if (a.type.tsym == anno) return a;
}
return null;
}
/** The name of this symbol in Utf8 representation. /** The name of this symbol in Utf8 representation.
*/ */
public Name name; public Name name;
@ -123,6 +95,146 @@ public abstract class Symbol implements Element {
*/ */
public Type erasure_field; public Type erasure_field;
// <editor-fold defaultstate="collapsed" desc="annotations">
/** The attributes of this symbol are contained in this
* Annotations. The Annotations instance is NOT immutable.
*/
protected Annotations annotations;
/** An accessor method for the attributes of this symbol.
* Attributes of class symbols should be accessed through the accessor
* method to make sure that the class symbol is loaded.
*/
public List<Attribute.Compound> getRawAttributes() {
return (annotations == null)
? List.<Attribute.Compound>nil()
: annotations.getDeclarationAttributes();
}
/** An accessor method for the type attributes of this symbol.
* Attributes of class symbols should be accessed through the accessor
* method to make sure that the class symbol is loaded.
*/
public List<Attribute.TypeCompound> getRawTypeAttributes() {
return (annotations == null)
? List.<Attribute.TypeCompound>nil()
: annotations.getTypeAttributes();
}
/** Fetch a particular annotation from a symbol. */
public Attribute.Compound attribute(Symbol anno) {
for (Attribute.Compound a : getRawAttributes()) {
if (a.type.tsym == anno) return a;
}
return null;
}
public boolean annotationsPendingCompletion() {
return annotations == null ? false : annotations.pendingCompletion();
}
public void appendAttributes(List<Attribute.Compound> l) {
if (l.nonEmpty()) {
initedAnnos().append(l);
}
}
public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
if (l.nonEmpty()) {
initedAnnos().appendClassInitTypeAttributes(l);
}
}
public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
if (l.nonEmpty()) {
initedAnnos().appendInitTypeAttributes(l);
}
}
public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
initedAnnos().appendTypeAttributesWithCompletion(ctx);
}
public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) {
if (l.nonEmpty()) {
initedAnnos().appendUniqueTypes(l);
}
}
public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
return (annotations == null)
? List.<Attribute.TypeCompound>nil()
: annotations.getClassInitTypeAttributes();
}
public List<Attribute.TypeCompound> getInitTypeAttributes() {
return (annotations == null)
? List.<Attribute.TypeCompound>nil()
: annotations.getInitTypeAttributes();
}
public List<Attribute.Compound> getDeclarationAttributes() {
return (annotations == null)
? List.<Attribute.Compound>nil()
: annotations.getDeclarationAttributes();
}
public boolean hasAnnotations() {
return (annotations != null && !annotations.isEmpty());
}
public boolean hasTypeAnnotations() {
return (annotations != null && !annotations.isTypesEmpty());
}
public void prependAttributes(List<Attribute.Compound> l) {
if (l.nonEmpty()) {
initedAnnos().prepend(l);
}
}
public void resetAnnotations() {
initedAnnos().reset();
}
public void setAttributes(Symbol other) {
if (annotations != null || other.annotations != null) {
initedAnnos().setAttributes(other.annotations);
}
}
public void setDeclarationAttributes(List<Attribute.Compound> a) {
if (annotations != null || a.nonEmpty()) {
initedAnnos().setDeclarationAttributes(a);
}
}
public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
initedAnnos().setDeclarationAttributesWithCompletion(ctx);
}
public void setTypeAttributes(List<Attribute.TypeCompound> a) {
if (annotations != null || a.nonEmpty()) {
if (annotations == null)
annotations = new Annotations(this);
annotations.setTypeAttributes(a);
}
}
private Annotations initedAnnos() {
if (annotations == null)
annotations = new Annotations(this);
return annotations;
}
/** This method is intended for debugging only. */
public Annotations getAnnotations() {
return annotations;
}
// </editor-fold>
/** Construct a symbol with given kind, flags, name, type and owner. /** Construct a symbol with given kind, flags, name, type and owner.
*/ */
public Symbol(int kind, long flags, Name name, Type type, Symbol owner) { public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
@ -207,6 +319,10 @@ public abstract class Symbol implements Element {
} }
} }
public boolean isDeprecated() {
return (flags_field & DEPRECATED) != 0;
}
public boolean isStatic() { public boolean isStatic() {
return return
(flags() & STATIC) != 0 || (flags() & STATIC) != 0 ||
@ -726,8 +842,9 @@ public abstract class Symbol implements Element {
} }
private void mergeAttributes() { private void mergeAttributes() {
if (annotations.isEmpty() && if (annotations == null &&
!package_info.annotations.isEmpty()) { package_info.annotations != null) {
annotations = new Annotations(this);
annotations.setAttributes(package_info.annotations); annotations.setAttributes(package_info.annotations);
} }
} }

View file

@ -271,8 +271,8 @@ public class TypeAnnotations {
} }
} }
sym.annotations.reset(); sym.resetAnnotations();
sym.annotations.setDeclarationAttributes(declAnnos.toList()); sym.setDeclarationAttributes(declAnnos.toList());
if (typeAnnos.isEmpty()) { if (typeAnnos.isEmpty()) {
return; return;
@ -284,7 +284,7 @@ public class TypeAnnotations {
// When type is null, put the type annotations to the symbol. // When type is null, put the type annotations to the symbol.
// This is used for constructor return annotations, for which // This is used for constructor return annotations, for which
// no appropriate type exists. // no appropriate type exists.
sym.annotations.appendUniqueTypes(typeAnnotations); sym.appendUniqueTypeAttributes(typeAnnotations);
return; return;
} }
@ -318,7 +318,7 @@ public class TypeAnnotations {
sym.type = type; sym.type = type;
} }
sym.annotations.appendUniqueTypes(typeAnnotations); sym.appendUniqueTypeAttributes(typeAnnotations);
if (sym.getKind() == ElementKind.PARAMETER || if (sym.getKind() == ElementKind.PARAMETER ||
sym.getKind() == ElementKind.LOCAL_VARIABLE || sym.getKind() == ElementKind.LOCAL_VARIABLE ||
@ -326,7 +326,7 @@ public class TypeAnnotations {
sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
// Make sure all type annotations from the symbol are also // Make sure all type annotations from the symbol are also
// on the owner. // on the owner.
sym.owner.annotations.appendUniqueTypes(sym.getRawTypeAttributes()); sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes());
} }
} }
@ -855,7 +855,7 @@ public class TypeAnnotations {
Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind()); Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
} }
if (v.getKind() != ElementKind.FIELD) { if (v.getKind() != ElementKind.FIELD) {
v.owner.annotations.appendUniqueTypes(v.getRawTypeAttributes()); v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
} }
return; return;

View file

@ -757,11 +757,10 @@ public class Attr extends JCTree.Visitor {
// env.info.enclVar.attributes_field might not yet have been evaluated, and so might be // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be
// null. In that case, calling augment will throw an NPE. To avoid this, for now we // null. In that case, calling augment will throw an NPE. To avoid this, for now we
// revert to the jdk 6 behavior and ignore the (unevaluated) attributes. // revert to the jdk 6 behavior and ignore the (unevaluated) attributes.
if (env.info.enclVar.annotations.pendingCompletion()) { if (env.info.enclVar.annotationsPendingCompletion()) {
env.info.lint = lintEnv.info.lint; env.info.lint = lintEnv.info.lint;
} else { } else {
env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.annotations, env.info.lint = lintEnv.info.lint.augment(env.info.enclVar);
env.info.enclVar.flags());
} }
Lint prevLint = chk.setLint(env.info.lint); Lint prevLint = chk.setLint(env.info.lint);
@ -881,7 +880,7 @@ public class Attr extends JCTree.Visitor {
MethodSymbol m = tree.sym; MethodSymbol m = tree.sym;
boolean isDefaultMethod = (m.flags() & DEFAULT) != 0; boolean isDefaultMethod = (m.flags() & DEFAULT) != 0;
Lint lint = env.info.lint.augment(m.annotations, m.flags()); Lint lint = env.info.lint.augment(m);
Lint prevLint = chk.setLint(lint); Lint prevLint = chk.setLint(lint);
MethodSymbol prevMethod = chk.setMethod(m); MethodSymbol prevMethod = chk.setMethod(m);
try { try {
@ -1052,7 +1051,7 @@ public class Attr extends JCTree.Visitor {
} }
VarSymbol v = tree.sym; VarSymbol v = tree.sym;
Lint lint = env.info.lint.augment(v.annotations, v.flags()); Lint lint = env.info.lint.augment(v);
Lint prevLint = chk.setLint(lint); Lint prevLint = chk.setLint(lint);
// Check that the variable's declared type is well-formed. // Check that the variable's declared type is well-formed.
@ -1121,9 +1120,9 @@ public class Attr extends JCTree.Visitor {
ClassSymbol cs = (ClassSymbol)env.info.scope.owner; ClassSymbol cs = (ClassSymbol)env.info.scope.owner;
List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes(); List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes();
if ((tree.flags & STATIC) != 0) { if ((tree.flags & STATIC) != 0) {
cs.annotations.appendClassInitTypeAttributes(tas); cs.appendClassInitTypeAttributes(tas);
} else { } else {
cs.annotations.appendInitTypeAttributes(tas); cs.appendInitTypeAttributes(tas);
} }
} }
@ -4118,7 +4117,7 @@ public class Attr extends JCTree.Visitor {
lintEnv = lintEnv.next; lintEnv = lintEnv.next;
// Having found the enclosing lint value, we can initialize the lint value for this class // Having found the enclosing lint value, we can initialize the lint value for this class
env.info.lint = lintEnv.info.lint.augment(c.annotations, c.flags()); env.info.lint = lintEnv.info.lint.augment(c);
Lint prevLint = chk.setLint(env.info.lint); Lint prevLint = chk.setLint(env.info.lint);
JavaFileObject prev = log.useSource(c.sourcefile); JavaFileObject prev = log.useSource(c.sourcefile);

View file

@ -161,7 +161,7 @@ public class Enter extends JCTree.Visitor {
Env<AttrContext> lintEnv = localEnv; Env<AttrContext> lintEnv = localEnv;
while (lintEnv.info.lint == null) while (lintEnv.info.lint == null)
lintEnv = lintEnv.next; lintEnv = lintEnv.next;
localEnv.info.lint = lintEnv.info.lint.augment(sym.annotations, sym.flags()); localEnv.info.lint = lintEnv.info.lint.augment(sym);
return localEnv; return localEnv;
} }

View file

@ -434,7 +434,7 @@ public class Flow {
Lint lintPrev = lint; Lint lintPrev = lint;
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try { try {
// process all the static initializers // process all the static initializers
@ -470,7 +470,7 @@ public class Flow {
if (tree.body == null) return; if (tree.body == null) return;
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
Assert.check(pendingExits.isEmpty()); Assert.check(pendingExits.isEmpty());
@ -496,7 +496,7 @@ public class Flow {
public void visitVarDef(JCVariableDecl tree) { public void visitVarDef(JCVariableDecl tree) {
if (tree.init != null) { if (tree.init != null) {
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try{ try{
scan(tree.init); scan(tree.init);
} finally { } finally {
@ -836,7 +836,7 @@ public class Flow {
} }
classDef = tree; classDef = tree;
thrown = List.nil(); thrown = List.nil();
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try { try {
// process all the static initializers // process all the static initializers
@ -916,7 +916,7 @@ public class Flow {
List<Type> mthrown = tree.sym.type.getThrownTypes(); List<Type> mthrown = tree.sym.type.getThrownTypes();
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
Assert.check(pendingExits.isEmpty()); Assert.check(pendingExits.isEmpty());
@ -955,7 +955,7 @@ public class Flow {
public void visitVarDef(JCVariableDecl tree) { public void visitVarDef(JCVariableDecl tree) {
if (tree.init != null) { if (tree.init != null) {
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try{ try{
scan(tree.init); scan(tree.init);
} finally { } finally {
@ -1580,7 +1580,7 @@ public class Flow {
firstadr = nextadr; firstadr = nextadr;
} }
classDef = tree; classDef = tree;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try { try {
// define all the static fields // define all the static fields
@ -1648,7 +1648,7 @@ public class Flow {
int returnadrPrev = returnadr; int returnadrPrev = returnadr;
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
Assert.check(pendingExits.isEmpty()); Assert.check(pendingExits.isEmpty());
@ -1700,7 +1700,7 @@ public class Flow {
if (track && tree.sym.owner.kind == MTH) newVar(tree.sym); if (track && tree.sym.owner.kind == MTH) newVar(tree.sym);
if (tree.init != null) { if (tree.init != null) {
Lint lintPrev = lint; Lint lintPrev = lint;
lint = lint.augment(tree.sym.annotations); lint = lint.augment(tree.sym);
try{ try{
scanExpr(tree.init); scanExpr(tree.init);
if (track) letInit(tree.pos(), tree.sym); if (track) letInit(tree.pos(), tree.sym);

View file

@ -249,8 +249,8 @@ public class LambdaToMethod extends TreeTranslator {
} }
} }
if (lambdaTypeAnnos.nonEmpty()) { if (lambdaTypeAnnos.nonEmpty()) {
owner.annotations.setTypeAttributes(ownerTypeAnnos.toList()); owner.setTypeAttributes(ownerTypeAnnos.toList());
sym.annotations.setTypeAttributes(lambdaTypeAnnos.toList()); sym.setTypeAttributes(lambdaTypeAnnos.toList());
} }
} }
@ -389,15 +389,15 @@ public class LambdaToMethod extends TreeTranslator {
if (lambdaContext.getSymbolMap(PARAM).containsKey(tree.sym)) { if (lambdaContext.getSymbolMap(PARAM).containsKey(tree.sym)) {
Symbol translatedSym = lambdaContext.getSymbolMap(PARAM).get(tree.sym); Symbol translatedSym = lambdaContext.getSymbolMap(PARAM).get(tree.sym);
result = make.Ident(translatedSym).setType(tree.type); result = make.Ident(translatedSym).setType(tree.type);
translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes()); translatedSym.setTypeAttributes(tree.sym.getRawTypeAttributes());
} else if (lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) { } else if (lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) {
Symbol translatedSym = lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym); Symbol translatedSym = lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym);
result = make.Ident(translatedSym).setType(tree.type); result = make.Ident(translatedSym).setType(tree.type);
translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes()); translatedSym.setTypeAttributes(tree.sym.getRawTypeAttributes());
} else if (lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) { } else if (lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) {
Symbol translatedSym = lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym); Symbol translatedSym = lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym);
result = make.Ident(translatedSym).setType(translatedSym.type); result = make.Ident(translatedSym).setType(translatedSym.type);
translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes()); translatedSym.setTypeAttributes(tree.sym.getRawTypeAttributes());
} else if (lambdaContext.getSymbolMap(CAPTURED_VAR).containsKey(tree.sym)) { } else if (lambdaContext.getSymbolMap(CAPTURED_VAR).containsKey(tree.sym)) {
Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym); Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym);
result = make.Ident(translatedSym).setType(tree.type); result = make.Ident(translatedSym).setType(tree.type);
@ -1715,8 +1715,8 @@ public class LambdaToMethod extends TreeTranslator {
ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym); ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym);
} }
if (ret != sym) { if (ret != sym) {
ret.annotations.setDeclarationAttributes(sym.getRawAttributes()); ret.setDeclarationAttributes(sym.getRawAttributes());
ret.annotations.setTypeAttributes(sym.getRawTypeAttributes()); ret.setTypeAttributes(sym.getRawTypeAttributes());
} }
return ret; return ret;
} }

View file

@ -2360,7 +2360,7 @@ public class Lower extends TreeTranslator {
null, List.<JCExpression>nil(), List.<JCTree>nil()); null, List.<JCExpression>nil(), List.<JCTree>nil());
ClassSymbol c = tree.packge.package_info; ClassSymbol c = tree.packge.package_info;
c.flags_field |= flags; c.flags_field |= flags;
c.annotations.setAttributes(tree.packge.annotations); c.setAttributes(tree.packge);
ClassType ctype = (ClassType) c.type; ClassType ctype = (ClassType) c.type;
ctype.supertype_field = syms.objectType; ctype.supertype_field = syms.objectType;
ctype.interfaces_field = List.nil(); ctype.interfaces_field = List.nil();
@ -2378,7 +2378,7 @@ public class Lower extends TreeTranslator {
return tree.packageAnnotations.nonEmpty(); return tree.packageAnnotations.nonEmpty();
case NONEMPTY: case NONEMPTY:
for (Attribute.Compound a : for (Attribute.Compound a :
tree.packge.annotations.getDeclarationAttributes()) { tree.packge.getDeclarationAttributes()) {
Attribute.RetentionPolicy p = types.getRetention(a); Attribute.RetentionPolicy p = types.getRetention(a);
if (p != Attribute.RetentionPolicy.SOURCE) if (p != Attribute.RetentionPolicy.SOURCE)
return true; return true;

View file

@ -712,7 +712,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) { public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
Env<AttrContext> mEnv = methodEnv(tree, env); Env<AttrContext> mEnv = methodEnv(tree, env);
mEnv.info.lint = mEnv.info.lint.augment(tree.sym.annotations, tree.sym.flags()); mEnv.info.lint = mEnv.info.lint.augment(tree.sym);
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
mEnv.info.scope.enterIfAbsent(l.head.type.tsym); mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
@ -753,7 +753,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
return; return;
} }
if (s.kind != PCK) { if (s.kind != PCK) {
s.annotations.reset(); // mark Annotations as incomplete for now s.resetAnnotations(); // mark Annotations as incomplete for now
} }
annotate.normal(new Annotate.Annotator() { annotate.normal(new Annotate.Annotator() {
@Override @Override
@ -763,10 +763,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
@Override @Override
public void enterAnnotation() { public void enterAnnotation() {
Assert.check(s.kind == PCK || s.annotations.pendingCompletion()); Assert.check(s.kind == PCK || s.annotationsPendingCompletion());
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
try { try {
if (!s.annotations.isEmpty() && if (s.hasAnnotations() &&
annotations.nonEmpty()) annotations.nonEmpty())
log.error(annotations.head.pos, log.error(annotations.head.pos,
"already.annotated", "already.annotated",
@ -832,7 +832,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
} }
} }
s.annotations.setDeclarationAttributesWithCompletion( s.setDeclarationAttributesWithCompletion(
annotate.new AnnotateRepeatedContext<Attribute.Compound>(env, annotated, pos, log, false)); annotate.new AnnotateRepeatedContext<Attribute.Compound>(env, annotated, pos, log, false));
} }
@ -1107,7 +1107,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
} }
if (s != null) { if (s != null) {
s.annotations.appendTypeAttributesWithCompletion( s.appendTypeAttributesWithCompletion(
annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true)); annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
} }
} }

View file

@ -262,9 +262,7 @@ public class TransTypes extends TreeTranslator {
* be applied to method addOverrideBridgesIfNeeded * be applied to method addOverrideBridgesIfNeeded
*/ */
bridge.params = createBridgeParams(impl, bridge, bridgeType); bridge.params = createBridgeParams(impl, bridge, bridgeType);
if (impl.annotations != null) { bridge.setAttributes(impl);
bridge.annotations.setAttributes(impl.annotations);
}
if (!hypothetical) { if (!hypothetical) {
JCMethodDecl md = make.MethodDef(bridge, null); JCMethodDecl md = make.MethodDef(bridge, null);
@ -311,9 +309,7 @@ public class TransTypes extends TreeTranslator {
while (implParams.nonEmpty() && argTypes.nonEmpty()) { while (implParams.nonEmpty() && argTypes.nonEmpty()) {
VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC, VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC,
implParams.head.name, argTypes.head, bridge); implParams.head.name, argTypes.head, bridge);
if (implParams.head.annotations != null) { param.setAttributes(implParams.head);
param.annotations.setAttributes(implParams.head.annotations);
}
bridgeParams = bridgeParams.append(param); bridgeParams = bridgeParams.append(param);
implParams = implParams.tail; implParams = implParams.tail;
argTypes = argTypes.tail; argTypes = argTypes.tail;

View file

@ -1896,12 +1896,11 @@ public class ClassReader implements Completer {
JavaFileObject previousClassFile = currentClassFile; JavaFileObject previousClassFile = currentClassFile;
try { try {
currentClassFile = classFile; currentClassFile = classFile;
Annotations annotations = sym.annotations;
List<Attribute.Compound> newList = deproxyCompoundList(l); List<Attribute.Compound> newList = deproxyCompoundList(l);
if (annotations.pendingCompletion()) { if (sym.annotationsPendingCompletion()) {
annotations.setDeclarationAttributes(newList); sym.setDeclarationAttributes(newList);
} else { } else {
annotations.append(newList); sym.appendAttributes(newList);
} }
} finally { } finally {
currentClassFile = previousClassFile; currentClassFile = previousClassFile;
@ -1935,7 +1934,7 @@ public class ClassReader implements Completer {
try { try {
currentClassFile = classFile; currentClassFile = classFile;
List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies); List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies);
sym.annotations.setTypeAttributes(newList.prependList(sym.getRawTypeAttributes())); sym.setTypeAttributes(newList.prependList(sym.getRawTypeAttributes()));
} finally { } finally {
currentClassFile = previousClassFile; currentClassFile = previousClassFile;
} }

View file

@ -1960,8 +1960,7 @@ public class Code {
} }
private void fillLocalVarPosition(LocalVar lv) { private void fillLocalVarPosition(LocalVar lv) {
if (lv == null || lv.sym == null if (lv == null || lv.sym == null || !lv.sym.hasTypeAnnotations())
|| lv.sym.annotations.isTypesEmpty())
return; return;
for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) { for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
TypeAnnotationPosition p = ta.position; TypeAnnotationPosition p = ta.position;
@ -1979,7 +1978,7 @@ public class Code {
for (int i = 0; i < varBufferSize; ++i) { for (int i = 0; i < varBufferSize; ++i) {
LocalVar lv = varBuffer[i]; LocalVar lv = varBuffer[i];
if (lv == null || lv.sym == null if (lv == null || lv.sym == null
|| lv.sym.annotations.isTypesEmpty() || !lv.sym.hasTypeAnnotations()
|| !lv.sym.isExceptionParameter()) || !lv.sym.isExceptionParameter())
continue; continue;
@ -2028,7 +2027,7 @@ public class Code {
// 2) it is an exception type and it contains type annotations // 2) it is an exception type and it contains type annotations
if (!varDebugInfo && if (!varDebugInfo &&
(!var.sym.isExceptionParameter() || (!var.sym.isExceptionParameter() ||
var.sym.annotations.isTypesEmpty())) return; var.sym.hasTypeAnnotations())) return;
if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
if (varBuffer == null) if (varBuffer == null)
varBuffer = new LocalVar[20]; varBuffer = new LocalVar[20];

View file

@ -518,7 +518,7 @@ public class Gen extends JCTree.Visitor {
// Insert any instance initializers into all constructors. // Insert any instance initializers into all constructors.
if (initCode.length() != 0) { if (initCode.length() != 0) {
List<JCStatement> inits = initCode.toList(); List<JCStatement> inits = initCode.toList();
initTAs.addAll(c.annotations.getInitTypeAttributes()); initTAs.addAll(c.getInitTypeAttributes());
List<Attribute.TypeCompound> initTAlist = initTAs.toList(); List<Attribute.TypeCompound> initTAlist = initTAs.toList();
for (JCTree t : methodDefs) { for (JCTree t : methodDefs) {
normalizeMethod((JCMethodDecl)t, inits, initTAlist); normalizeMethod((JCMethodDecl)t, inits, initTAlist);
@ -541,9 +541,9 @@ public class Gen extends JCTree.Visitor {
methodDefs.append(make.MethodDef(clinit, block)); methodDefs.append(make.MethodDef(clinit, block));
if (!clinitTAs.isEmpty()) if (!clinitTAs.isEmpty())
clinit.annotations.appendUniqueTypes(clinitTAs.toList()); clinit.appendUniqueTypeAttributes(clinitTAs.toList());
if (!c.annotations.getClassInitTypeAttributes().isEmpty()) if (!c.getClassInitTypeAttributes().isEmpty())
clinit.annotations.appendUniqueTypes(c.annotations.getClassInitTypeAttributes()); clinit.appendUniqueTypeAttributes(c.getClassInitTypeAttributes());
} }
// Return all method definitions. // Return all method definitions.
return methodDefs.toList(); return methodDefs.toList();
@ -560,7 +560,7 @@ public class Gen extends JCTree.Visitor {
nonfieldTAs.add(ta); nonfieldTAs.add(ta);
} }
} }
sym.annotations.setTypeAttributes(fieldTAs.toList()); sym.setTypeAttributes(fieldTAs.toList());
return nonfieldTAs.toList(); return nonfieldTAs.toList();
} }
@ -618,7 +618,7 @@ public class Gen extends JCTree.Visitor {
if (md.body.endpos == Position.NOPOS) if (md.body.endpos == Position.NOPOS)
md.body.endpos = TreeInfo.endPos(md.body.stats.last()); md.body.endpos = TreeInfo.endPos(md.body.stats.last());
md.sym.annotations.appendUniqueTypes(initTAs); md.sym.appendUniqueTypeAttributes(initTAs);
} }
} }

View file

@ -160,7 +160,7 @@ public class JNIWriter {
for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) { for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0) if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
return true; return true;
for (Attribute.Compound a: i.sym.annotations.getDeclarationAttributes()) { for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
if (a.type.tsym == syms.nativeHeaderType.tsym) if (a.type.tsym == syms.nativeHeaderType.tsym)
return true; return true;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -225,11 +225,11 @@ public class CreateSymbols extends AbstractProcessor {
} }
ClassSymbol cs = (ClassSymbol) sym; ClassSymbol cs = (ClassSymbol) sym;
if (addLegacyAnnotation) { if (addLegacyAnnotation) {
cs.annotations.prepend(List.of(proprietaryAnno)); cs.prependAttributes(List.of(proprietaryAnno));
} }
int p = profiles.getProfile(cs.fullname.toString().replace(".", "/")); int p = profiles.getProfile(cs.fullname.toString().replace(".", "/"));
if (0 < p && p < profileAnnos.length) if (0 < p && p < profileAnnos.length)
cs.annotations.prepend(List.of(profileAnnos[p])); cs.prependAttributes(List.of(profileAnnos[p]));
writeClass(pool, cs, writer); writeClass(pool, cs, writer);
} }

View file

@ -1131,6 +1131,14 @@ public class TreeInfo {
private static class TypeAnnotationFinder extends TreeScanner { private static class TypeAnnotationFinder extends TreeScanner {
public boolean foundTypeAnno = false; public boolean foundTypeAnno = false;
@Override
public void scan(JCTree tree) {
if (foundTypeAnno || tree == null)
return;
super.scan(tree);
}
public void visitAnnotation(JCAnnotation tree) { public void visitAnnotation(JCAnnotation tree) {
foundTypeAnno = foundTypeAnno || tree.hasTag(TYPE_ANNOTATION); foundTypeAnno = foundTypeAnno || tree.hasTag(TYPE_ANNOTATION);
} }

View file

@ -403,7 +403,7 @@ public class DPrinter {
printType("type", sym.type, Details.SUMMARY); printType("type", sym.type, Details.SUMMARY);
printType("erasure", sym.erasure_field, Details.SUMMARY); printType("erasure", sym.erasure_field, Details.SUMMARY);
sym.accept(symVisitor, null); sym.accept(symVisitor, null);
printAnnotations("annotations", sym.annotations, Details.SUMMARY); printAnnotations("annotations", sym.getAnnotations(), Details.SUMMARY);
indent(-1); indent(-1);
} }
} }