8010179: Remove transitional target values from javac

Reviewed-by: jjg, mcimadamore
This commit is contained in:
Joe Darcy 2013-03-19 13:10:40 -07:00
parent 49d55f9300
commit 479d5c83b0
6 changed files with 13 additions and 280 deletions

View file

@ -4009,8 +4009,7 @@ public class Attr extends JCTree.Visitor {
// Enums may not be extended by source-level classes // Enums may not be extended by source-level classes
if (st.tsym != null && if (st.tsym != null &&
((st.tsym.flags_field & Flags.ENUM) != 0) && ((st.tsym.flags_field & Flags.ENUM) != 0) &&
((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0) && ((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0)) {
!target.compilerBootstrap(c)) {
log.error(env.tree.pos(), "enum.types.not.extensible"); log.error(env.tree.pos(), "enum.types.not.extensible");
} }
attribClassBody(env, c); attribClassBody(env, c);

View file

@ -2604,11 +2604,6 @@ public class Lower extends TreeTranslator {
enumDefs.appendList(otherDefs.toList()); enumDefs.appendList(otherDefs.toList());
tree.defs = enumDefs.toList(); tree.defs = enumDefs.toList();
// Add the necessary members for the EnumCompatibleMode
if (target.compilerBootstrap(tree.sym)) {
addEnumCompatibleMembers(tree);
}
} }
// where // where
private MethodSymbol systemArraycopyMethod; private MethodSymbol systemArraycopyMethod;
@ -2657,30 +2652,6 @@ public class Lower extends TreeTranslator {
olderasure.getReturnType(), olderasure.getReturnType(),
olderasure.getThrownTypes(), olderasure.getThrownTypes(),
syms.methodClass); syms.methodClass);
if (target.compilerBootstrap(m.owner)) {
// Initialize synthetic name field
Symbol nameVarSym = lookupSynthetic(names.fromString("$name"),
tree.sym.owner.members());
JCIdent nameIdent = make.Ident(nameParam.sym);
JCIdent id1 = make.Ident(nameVarSym);
JCAssign newAssign = make.Assign(id1, nameIdent);
newAssign.type = id1.type;
JCExpressionStatement nameAssign = make.Exec(newAssign);
nameAssign.type = id1.type;
tree.body.stats = tree.body.stats.prepend(nameAssign);
// Initialize synthetic ordinal field
Symbol ordinalVarSym = lookupSynthetic(names.fromString("$ordinal"),
tree.sym.owner.members());
JCIdent ordIdent = make.Ident(ordParam.sym);
id1 = make.Ident(ordinalVarSym);
newAssign = make.Assign(id1, ordIdent);
newAssign.type = id1.type;
JCExpressionStatement ordinalAssign = make.Exec(newAssign);
ordinalAssign.type = id1.type;
tree.body.stats = tree.body.stats.prepend(ordinalAssign);
}
} }
JCMethodDecl prevMethodDef = currentMethodDef; JCMethodDecl prevMethodDef = currentMethodDef;
@ -3888,168 +3859,4 @@ public class Lower extends TreeTranslator {
} }
return translated.toList(); return translated.toList();
} }
//////////////////////////////////////////////////////////////
// The following contributed by Borland for bootstrapping purposes
//////////////////////////////////////////////////////////////
private void addEnumCompatibleMembers(JCClassDecl cdef) {
make_at(null);
// Add the special enum fields
VarSymbol ordinalFieldSym = addEnumOrdinalField(cdef);
VarSymbol nameFieldSym = addEnumNameField(cdef);
// Add the accessor methods for name and ordinal
MethodSymbol ordinalMethodSym = addEnumFieldOrdinalMethod(cdef, ordinalFieldSym);
MethodSymbol nameMethodSym = addEnumFieldNameMethod(cdef, nameFieldSym);
// Add the toString method
addEnumToString(cdef, nameFieldSym);
// Add the compareTo method
addEnumCompareTo(cdef, ordinalFieldSym);
}
private VarSymbol addEnumOrdinalField(JCClassDecl cdef) {
VarSymbol ordinal = new VarSymbol(PRIVATE|FINAL|SYNTHETIC,
names.fromString("$ordinal"),
syms.intType,
cdef.sym);
cdef.sym.members().enter(ordinal);
cdef.defs = cdef.defs.prepend(make.VarDef(ordinal, null));
return ordinal;
}
private VarSymbol addEnumNameField(JCClassDecl cdef) {
VarSymbol name = new VarSymbol(PRIVATE|FINAL|SYNTHETIC,
names.fromString("$name"),
syms.stringType,
cdef.sym);
cdef.sym.members().enter(name);
cdef.defs = cdef.defs.prepend(make.VarDef(name, null));
return name;
}
private MethodSymbol addEnumFieldOrdinalMethod(JCClassDecl cdef, VarSymbol ordinalSymbol) {
// Add the accessor methods for ordinal
Symbol ordinalSym = lookupMethod(cdef.pos(),
names.ordinal,
cdef.type,
List.<Type>nil());
Assert.check(ordinalSym instanceof MethodSymbol);
JCStatement ret = make.Return(make.Ident(ordinalSymbol));
cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)ordinalSym,
make.Block(0L, List.of(ret))));
return (MethodSymbol)ordinalSym;
}
private MethodSymbol addEnumFieldNameMethod(JCClassDecl cdef, VarSymbol nameSymbol) {
// Add the accessor methods for name
Symbol nameSym = lookupMethod(cdef.pos(),
names._name,
cdef.type,
List.<Type>nil());
Assert.check(nameSym instanceof MethodSymbol);
JCStatement ret = make.Return(make.Ident(nameSymbol));
cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)nameSym,
make.Block(0L, List.of(ret))));
return (MethodSymbol)nameSym;
}
private MethodSymbol addEnumToString(JCClassDecl cdef,
VarSymbol nameSymbol) {
Symbol toStringSym = lookupMethod(cdef.pos(),
names.toString,
cdef.type,
List.<Type>nil());
JCTree toStringDecl = null;
if (toStringSym != null)
toStringDecl = TreeInfo.declarationFor(toStringSym, cdef);
if (toStringDecl != null)
return (MethodSymbol)toStringSym;
JCStatement ret = make.Return(make.Ident(nameSymbol));
JCTree resTypeTree = make.Type(syms.stringType);
MethodType toStringType = new MethodType(List.<Type>nil(),
syms.stringType,
List.<Type>nil(),
cdef.sym);
toStringSym = new MethodSymbol(PUBLIC,
names.toString,
toStringType,
cdef.type.tsym);
toStringDecl = make.MethodDef((MethodSymbol)toStringSym,
make.Block(0L, List.of(ret)));
cdef.defs = cdef.defs.prepend(toStringDecl);
cdef.sym.members().enter(toStringSym);
return (MethodSymbol)toStringSym;
}
private MethodSymbol addEnumCompareTo(JCClassDecl cdef, VarSymbol ordinalSymbol) {
Symbol compareToSym = lookupMethod(cdef.pos(),
names.compareTo,
cdef.type,
List.of(cdef.sym.type));
Assert.check(compareToSym instanceof MethodSymbol);
JCMethodDecl compareToDecl = (JCMethodDecl) TreeInfo.declarationFor(compareToSym, cdef);
ListBuffer<JCStatement> blockStatements = new ListBuffer<JCStatement>();
JCModifiers mod1 = make.Modifiers(0L);
Name oName = names.fromString("o");
JCVariableDecl par1 = make.Param(oName, cdef.type, compareToSym);
JCIdent paramId1 = make.Ident(names.java_lang_Object);
paramId1.type = cdef.type;
paramId1.sym = par1.sym;
((MethodSymbol)compareToSym).params = List.of(par1.sym);
JCIdent par1UsageId = make.Ident(par1.sym);
JCIdent castTargetIdent = make.Ident(cdef.sym);
JCTypeCast cast = make.TypeCast(castTargetIdent, par1UsageId);
cast.setType(castTargetIdent.type);
Name otherName = names.fromString("other");
VarSymbol otherVarSym = new VarSymbol(mod1.flags,
otherName,
cdef.type,
compareToSym);
JCVariableDecl otherVar = make.VarDef(otherVarSym, cast);
blockStatements.append(otherVar);
JCIdent id1 = make.Ident(ordinalSymbol);
JCIdent fLocUsageId = make.Ident(otherVarSym);
JCExpression sel = make.Select(fLocUsageId, ordinalSymbol);
JCBinary bin = makeBinary(MINUS, id1, sel);
JCReturn ret = make.Return(bin);
blockStatements.append(ret);
JCMethodDecl compareToMethod = make.MethodDef((MethodSymbol)compareToSym,
make.Block(0L,
blockStatements.toList()));
compareToMethod.params = List.of(par1);
cdef.defs = cdef.defs.append(compareToMethod);
return (MethodSymbol)compareToSym;
}
//////////////////////////////////////////////////////////////
// The above contributed by Borland for bootstrapping purposes
//////////////////////////////////////////////////////////////
} }

View file

@ -473,44 +473,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
null); null);
memberEnter(valueOf, env); memberEnter(valueOf, env);
// the remaining members are for bootstrapping only
if (!target.compilerBootstrap(tree.sym)) return;
// public final int ordinal() { return ???; }
JCMethodDecl ordinal = make.at(tree.pos).
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
names.ordinal,
make.Type(syms.intType),
List.<JCTypeParameter>nil(),
List.<JCVariableDecl>nil(),
List.<JCExpression>nil(),
null,
null);
memberEnter(ordinal, env);
// public final String name() { return ???; }
JCMethodDecl name = make.
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
names._name,
make.Type(syms.stringType),
List.<JCTypeParameter>nil(),
List.<JCVariableDecl>nil(),
List.<JCExpression>nil(),
null,
null);
memberEnter(name, env);
// public int compareTo(E other) { return ???; }
MethodSymbol compareTo = new
MethodSymbol(Flags.PUBLIC,
names.compareTo,
new MethodType(List.of(tree.sym.type),
syms.intType,
List.<Type>nil(),
syms.methodClass),
tree.sym);
memberEnter(make.MethodDef(compareTo, null), env);
} }
public void visitTopLevel(JCCompilationUnit tree) { public void visitTopLevel(JCCompilationUnit tree) {
@ -936,7 +898,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
Type supertype = Type supertype =
(tree.extending != null) (tree.extending != null)
? attr.attribBase(tree.extending, baseEnv, true, false, true) ? attr.attribBase(tree.extending, baseEnv, true, false, true)
: ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c)) : ((tree.mods.flags & Flags.ENUM) != 0)
? attr.attribBase(enumBase(tree.pos, c), baseEnv, ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
true, false, false) true, false, false)
: (c.fullname == names.java_lang_Object) : (c.fullname == names.java_lang_Object)
@ -949,16 +911,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
ListBuffer<Type> all_interfaces = null; // lazy init ListBuffer<Type> all_interfaces = null; // lazy init
Set<Type> interfaceSet = new HashSet<Type>(); Set<Type> interfaceSet = new HashSet<Type>();
List<JCExpression> interfaceTrees = tree.implementing; List<JCExpression> interfaceTrees = tree.implementing;
if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) {
// add interface Comparable<T>
interfaceTrees =
interfaceTrees.prepend(make.Type(new ClassType(syms.comparableType.getEnclosingType(),
List.of(c.type),
syms.comparableType.tsym)));
// add interface Serializable
interfaceTrees =
interfaceTrees.prepend(make.Type(syms.serializableType));
}
for (JCExpression iface : interfaceTrees) { for (JCExpression iface : interfaceTrees) {
Type i = attr.attribBase(iface, baseEnv, false, true, true); Type i = attr.attribBase(iface, baseEnv, false, true, true);
if (i.hasTag(CLASS)) { if (i.hasTag(CLASS)) {
@ -1401,8 +1353,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
if (c.type != syms.objectType) if (c.type != syms.objectType)
stats = stats.prepend(SuperCall(make, typarams, params, based)); stats = stats.prepend(SuperCall(make, typarams, params, based));
if ((c.flags() & ENUM) != 0 && if ((c.flags() & ENUM) != 0 &&
(types.supertype(c.type).tsym == syms.enumSym || (types.supertype(c.type).tsym == syms.enumSym)) {
target.compilerBootstrap(c))) {
// constructors of true enums are private // constructors of true enums are private
flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR; flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
} else } else

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 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
@ -48,17 +48,6 @@ public enum Target {
/** J2SE1.4 = Merlin. */ /** J2SE1.4 = Merlin. */
JDK1_4("1.4", 48, 0), JDK1_4("1.4", 48, 0),
/** Support for the JSR14 prototype compiler (targeting 1.4 VMs
* augmented with a few support classes). This is a transitional
* option that will not be supported in the product. */
JSR14("jsr14", 48, 0),
/** The following are undocumented transitional targets that we
* had used to test VM fixes in update releases. We do not
* promise to retain support for them. */
JDK1_4_1("1.4.1", 48, 0),
JDK1_4_2("1.4.2", 48, 0),
/** Tiger. */ /** Tiger. */
JDK1_5("1.5", 49, 0), JDK1_5("1.5", 49, 0),
@ -175,23 +164,23 @@ public enum Target {
return compareTo(JDK1_5) >= 0; return compareTo(JDK1_5) >= 0;
} }
/** Beginning in -target 1.4.2, we make synthetic variables /** Beginning in -target 1.5, we make synthetic variables
* package-private instead of private. This is to prevent the * package-private instead of private. This is to prevent the
* necessity of access methods, which effectively relax the * necessity of access methods, which effectively relax the
* protection of the field but bloat the class files and affect * protection of the field but bloat the class files and affect
* execution. * execution.
*/ */
public boolean usePrivateSyntheticFields() { public boolean usePrivateSyntheticFields() {
return compareTo(JDK1_4_2) < 0; return compareTo(JDK1_5) < 0;
} }
/** Sometimes we need to create a field to cache a value like a /** Sometimes we need to create a field to cache a value like a
* class literal of the assertions flag. In -target 1.4.2 and * class literal of the assertions flag. In -target 1.5 and
* later we create a new synthetic class for this instead of * later we create a new synthetic class for this instead of
* using the outermost class. See 4401576. * using the outermost class. See 4401576.
*/ */
public boolean useInnerCacheClass() { public boolean useInnerCacheClass() {
return compareTo(JDK1_4_2) >= 0; return compareTo(JDK1_5) >= 0;
} }
/** Return true if cldc-style stack maps need to be generated. */ /** Return true if cldc-style stack maps need to be generated. */
@ -276,7 +265,7 @@ public enum Target {
* See 4468823 * See 4468823
*/ */
public boolean classLiteralsNoInit() { public boolean classLiteralsNoInit() {
return compareTo(JDK1_4_2) >= 0; return compareTo(JDK1_5) >= 0;
} }
/** Although we may not have support for class literals, when we /** Although we may not have support for class literals, when we
@ -300,22 +289,10 @@ public enum Target {
return compareTo(JDK1_5) >= 0; return compareTo(JDK1_5) >= 0;
} }
/** For bootstrapping javac only, we do without java.lang.Enum if
* necessary.
*/
public boolean compilerBootstrap(Symbol c) {
return
this == JSR14 &&
(c.flags() & Flags.ENUM) != 0 &&
c.flatName().toString().startsWith("com.sun.tools.")
// && !Target.class.getSuperclass().getName().equals("java.lang.Enum")
;
}
/** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
* for improved reflection support. * for improved reflection support.
*/ */
public boolean hasEnclosingMethodAttribute() { public boolean hasEnclosingMethodAttribute() {
return compareTo(JDK1_5) >= 0 || this == JSR14; return compareTo(JDK1_5) >= 0;
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 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
@ -26,7 +26,7 @@
* @bug 4249112 4785453 * @bug 4249112 4785453
* @summary Verify that implicit member modifiers are set correctly. * @summary Verify that implicit member modifiers are set correctly.
* *
* @compile/ref=MemberModifiers.out -source 1.4 -target 1.4.2 -Xlint:-options -XDdumpmodifiers=cfm MemberModifiers.java * @compile/ref=MemberModifiers.out -source 1.4 -target 1.5 -Xlint:-options -XDdumpmodifiers=cfm MemberModifiers.java
*/ */
// Currently, we check only that members of final classes are not final. // Currently, we check only that members of final classes are not final.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 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
@ -106,7 +106,6 @@ public class ProfileOptionTest {
for (Target t: Target.values()) { for (Target t: Target.values()) {
switch (t) { switch (t) {
case JDK1_1: case JDK1_2: // no equivalent -source case JDK1_1: case JDK1_2: // no equivalent -source
case JDK1_4_1: case JDK1_4_2: case JSR14: // transitional values
continue; continue;
} }