Merge

Tue, 18 Jun 2013 20:08:49 +0100

author
chegar
date
Tue, 18 Jun 2013 20:08:49 +0100
changeset 1840
64f511787fd9
parent 1839
db6bf740a578
parent 1826
9851071b551a
child 1841
792c40d5185a

Merge

     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Jun 18 09:36:46 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Jun 18 20:08:49 2013 +0100
     1.3 @@ -110,49 +110,27 @@
     1.4      }
     1.5  
     1.6      public boolean isNumeric() {
     1.7 -        switch (tag) {
     1.8 -            case BYTE: case CHAR:
     1.9 -            case SHORT:
    1.10 -            case INT: case LONG:
    1.11 -            case FLOAT: case DOUBLE:
    1.12 -                return true;
    1.13 -            default:
    1.14 -                return false;
    1.15 -        }
    1.16 +        return tag.isNumeric;
    1.17      }
    1.18  
    1.19      public boolean isPrimitive() {
    1.20 -        return (isNumeric() || tag == BOOLEAN);
    1.21 +        return tag.isPrimitive;
    1.22      }
    1.23  
    1.24      public boolean isPrimitiveOrVoid() {
    1.25 -        return (isPrimitive() || tag == VOID);
    1.26 +        return tag.isPrimitiveOrVoid;
    1.27      }
    1.28  
    1.29      public boolean isReference() {
    1.30 -        switch (tag) {
    1.31 -        case CLASS:
    1.32 -        case ARRAY:
    1.33 -        case TYPEVAR:
    1.34 -        case WILDCARD:
    1.35 -        case ERROR:
    1.36 -            return true;
    1.37 -        default:
    1.38 -            return false;
    1.39 -        }
    1.40 +        return tag.isReference;
    1.41      }
    1.42  
    1.43      public boolean isNullOrReference() {
    1.44 -        return (tag == BOT || isReference());
    1.45 +        return (tag.isReference || tag == BOT);
    1.46      }
    1.47  
    1.48      public boolean isPartial() {
    1.49 -        switch(tag) {
    1.50 -            case ERROR: case UNKNOWN: case UNDETVAR:
    1.51 -                return true;
    1.52 -            default:
    1.53 -                return false;
    1.54 -        }
    1.55 +        return tag.isPartial;
    1.56      }
    1.57  
    1.58      /**
     2.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeTag.java	Tue Jun 18 09:36:46 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeTag.java	Tue Jun 18 20:08:49 2013 +0100
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -29,6 +29,8 @@
    2.11  
    2.12  import javax.lang.model.type.TypeKind;
    2.13  
    2.14 +import static com.sun.tools.javac.code.TypeTag.NumericClasses.*;
    2.15 +
    2.16  /** An interface for type tag values, which distinguish between different
    2.17   *  sorts of types.
    2.18   *
    2.19 @@ -40,113 +42,170 @@
    2.20  public enum TypeTag {
    2.21      /** The tag of the basic type `byte'.
    2.22       */
    2.23 -    BYTE(1),
    2.24 +    BYTE(BYTE_CLASS, BYTE_SUPERCLASSES,
    2.25 +            TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.26  
    2.27      /** The tag of the basic type `char'.
    2.28       */
    2.29 -    CHAR(2),
    2.30 +    CHAR(CHAR_CLASS, CHAR_SUPERCLASSES,
    2.31 +            TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.32  
    2.33      /** The tag of the basic type `short'.
    2.34       */
    2.35 -    SHORT(3),
    2.36 +    SHORT(SHORT_CLASS, SHORT_SUPERCLASSES,
    2.37 +            TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.38  
    2.39      /** The tag of the basic type `int'.
    2.40       */
    2.41 -    INT(4),
    2.42 +    INT(INT_CLASS, INT_SUPERCLASSES,
    2.43 +            TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.44  
    2.45      /** The tag of the basic type `long'.
    2.46       */
    2.47 -    LONG(5),
    2.48 +    LONG(LONG_CLASS, LONG_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.49  
    2.50      /** The tag of the basic type `float'.
    2.51       */
    2.52 -    FLOAT(6),
    2.53 +    FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.54  
    2.55      /** The tag of the basic type `double'.
    2.56       */
    2.57 -    DOUBLE(7),
    2.58 +    DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
    2.59  
    2.60      /** The tag of the basic type `boolean'.
    2.61       */
    2.62 -    BOOLEAN,
    2.63 +    BOOLEAN(TypeTagKind.PRIMITIVE),
    2.64  
    2.65      /** The tag of the type `void'.
    2.66       */
    2.67 -    VOID,
    2.68 +    VOID(TypeTagKind.VOID),
    2.69  
    2.70      /** The tag of all class and interface types.
    2.71       */
    2.72 -    CLASS,
    2.73 +    CLASS(TypeTagKind.REFERENCE),
    2.74  
    2.75      /** The tag of all array types.
    2.76       */
    2.77 -    ARRAY,
    2.78 +    ARRAY(TypeTagKind.REFERENCE),
    2.79  
    2.80      /** The tag of all (monomorphic) method types.
    2.81       */
    2.82 -    METHOD,
    2.83 +    METHOD(TypeTagKind.OTHER),
    2.84  
    2.85      /** The tag of all package "types".
    2.86       */
    2.87 -    PACKAGE,
    2.88 +    PACKAGE(TypeTagKind.OTHER),
    2.89  
    2.90      /** The tag of all (source-level) type variables.
    2.91       */
    2.92 -    TYPEVAR,
    2.93 +    TYPEVAR(TypeTagKind.REFERENCE),
    2.94  
    2.95      /** The tag of all type arguments.
    2.96       */
    2.97 -    WILDCARD,
    2.98 +    WILDCARD(TypeTagKind.REFERENCE),
    2.99  
   2.100      /** The tag of all polymorphic (method-) types.
   2.101       */
   2.102 -    FORALL,
   2.103 +    FORALL(TypeTagKind.OTHER),
   2.104  
   2.105      /** The tag of deferred expression types in method context
   2.106       */
   2.107 -    DEFERRED,
   2.108 +    DEFERRED(TypeTagKind.OTHER),
   2.109  
   2.110      /** The tag of the bottom type {@code <null>}.
   2.111       */
   2.112 -    BOT,
   2.113 +    BOT(TypeTagKind.OTHER),
   2.114  
   2.115      /** The tag of a missing type.
   2.116       */
   2.117 -    NONE,
   2.118 +    NONE(TypeTagKind.OTHER),
   2.119  
   2.120      /** The tag of the error type.
   2.121       */
   2.122 -    ERROR,
   2.123 +    ERROR(TypeTagKind.REFERENCE | TypeTagKind.PARTIAL),
   2.124  
   2.125      /** The tag of an unknown type
   2.126       */
   2.127 -    UNKNOWN,
   2.128 +    UNKNOWN(TypeTagKind.PARTIAL),
   2.129  
   2.130      /** The tag of all instantiatable type variables.
   2.131       */
   2.132 -    UNDETVAR,
   2.133 +    UNDETVAR(TypeTagKind.PARTIAL),
   2.134  
   2.135      /** Pseudo-types, these are special tags
   2.136       */
   2.137 -    UNINITIALIZED_THIS,
   2.138 +    UNINITIALIZED_THIS(TypeTagKind.OTHER),
   2.139  
   2.140 -    UNINITIALIZED_OBJECT;
   2.141 +    UNINITIALIZED_OBJECT(TypeTagKind.OTHER);
   2.142  
   2.143 -    /** This field will only be used for tags related with numeric types for
   2.144 -     *  optimization reasons.
   2.145 -     */
   2.146 -    private final int order;
   2.147 +    final boolean isPrimitive;
   2.148 +    final boolean isNumeric;
   2.149 +    final boolean isPartial;
   2.150 +    final boolean isReference;
   2.151 +    final boolean isPrimitiveOrVoid;
   2.152 +    final int superClasses;
   2.153 +    final int numericClass;
   2.154  
   2.155 -    private TypeTag() {
   2.156 -        this(0);
   2.157 +    private TypeTag(int kind) {
   2.158 +        this(0, 0, kind);
   2.159      }
   2.160  
   2.161 -    private TypeTag(int order) {
   2.162 -        this.order = order;
   2.163 +    private TypeTag(int numericClass, int superClasses, int kind) {
   2.164 +         isPrimitive = (kind & TypeTagKind.PRIMITIVE) != 0;
   2.165 +         isNumeric = (kind & TypeTagKind.NUMERIC) != 0;
   2.166 +         isPartial = (kind & TypeTagKind.PARTIAL) != 0;
   2.167 +         isReference = (kind & TypeTagKind.REFERENCE) != 0;
   2.168 +         isPrimitiveOrVoid = ((kind & TypeTagKind.PRIMITIVE) != 0) ||
   2.169 +                 ((kind & TypeTagKind.VOID) != 0);
   2.170 +         this.superClasses = superClasses;
   2.171 +         this.numericClass = numericClass;
   2.172 +     }
   2.173 +
   2.174 +    static class TypeTagKind {
   2.175 +        static final int PRIMITIVE = 1;
   2.176 +        static final int NUMERIC = 2;
   2.177 +        static final int REFERENCE = 4;
   2.178 +        static final int PARTIAL = 8;
   2.179 +        static final int OTHER = 16;
   2.180 +        static final int VOID = 32;
   2.181      }
   2.182  
   2.183 -    private static final int MIN_NUMERIC_TAG_ORDER = 1;
   2.184 -    private static final int MAX_NUMERIC_TAG_ORDER = 7;
   2.185 +    public static class NumericClasses {
   2.186 +        public static final int BYTE_CLASS = 1;
   2.187 +        public static final int CHAR_CLASS = 2;
   2.188 +        public static final int SHORT_CLASS = 4;
   2.189 +        public static final int INT_CLASS = 8;
   2.190 +        public static final int LONG_CLASS = 16;
   2.191 +        public static final int FLOAT_CLASS = 32;
   2.192 +        public static final int DOUBLE_CLASS = 64;
   2.193 +
   2.194 +        static final int BYTE_SUPERCLASSES = BYTE_CLASS | SHORT_CLASS | INT_CLASS |
   2.195 +                LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS;
   2.196 +
   2.197 +        static final int CHAR_SUPERCLASSES = CHAR_CLASS | INT_CLASS |
   2.198 +                LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS;
   2.199 +
   2.200 +        static final int SHORT_SUPERCLASSES = SHORT_CLASS | INT_CLASS |
   2.201 +                LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS;
   2.202 +
   2.203 +        static final int INT_SUPERCLASSES = INT_CLASS | LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS;
   2.204 +
   2.205 +        static final int LONG_SUPERCLASSES = LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS;
   2.206 +
   2.207 +        static final int FLOAT_SUPERCLASSES = FLOAT_CLASS | DOUBLE_CLASS;
   2.208 +    }
   2.209 +
   2.210 +    public boolean isStrictSubRangeOf(TypeTag tag) {
   2.211 +        /*  Please don't change the implementation of this method to call method
   2.212 +         *  isSubRangeOf. Both methods are called from hotspot code, the current
   2.213 +         *  implementation is better performance-wise than the commented modification.
   2.214 +         */
   2.215 +        return (this.superClasses & tag.numericClass) != 0 && this != tag;
   2.216 +    }
   2.217 +
   2.218 +    public boolean isSubRangeOf(TypeTag tag) {
   2.219 +        return (this.superClasses & tag.numericClass) != 0;
   2.220 +    }
   2.221  
   2.222      /** Returns the number of type tags.
   2.223       */
   2.224 @@ -155,29 +214,6 @@
   2.225          return (UNDETVAR.ordinal() + 1);
   2.226      }
   2.227  
   2.228 -    public boolean isSubRangeOf(TypeTag range) {
   2.229 -        return (this == range) || isStrictSubRangeOf(range);
   2.230 -    }
   2.231 -
   2.232 -    public boolean isStrictSubRangeOf(TypeTag range) {
   2.233 -        if (this.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER &&
   2.234 -            range.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER) {
   2.235 -            if (this == range)
   2.236 -                return false;
   2.237 -            switch (this) {
   2.238 -                case BYTE:
   2.239 -                    return true;
   2.240 -                case CHAR: case SHORT: case INT:
   2.241 -                case LONG: case FLOAT:
   2.242 -                    return this.order < range.order && range.order <= MAX_NUMERIC_TAG_ORDER;
   2.243 -                default:
   2.244 -                    return false;
   2.245 -            }
   2.246 -        }
   2.247 -        else
   2.248 -            return false;
   2.249 -    }
   2.250 -
   2.251      public Kind getKindLiteral() {
   2.252          switch (this) {
   2.253          case INT:
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 18 09:36:46 2013 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 18 20:08:49 2013 +0100
     3.3 @@ -1532,21 +1532,23 @@
     3.4                  // If one arm has an integer subrange type (i.e., byte,
     3.5                  // short, or char), and the other is an integer constant
     3.6                  // that fits into the subrange, return the subrange type.
     3.7 -                if (thenUnboxed.getTag().isStrictSubRangeOf(INT) && elseUnboxed.hasTag(INT) &&
     3.8 -                    types.isAssignable(elseUnboxed, thenUnboxed))
     3.9 +                if (thenUnboxed.getTag().isStrictSubRangeOf(INT) &&
    3.10 +                    elseUnboxed.hasTag(INT) &&
    3.11 +                    types.isAssignable(elseUnboxed, thenUnboxed)) {
    3.12                      return thenUnboxed.baseType();
    3.13 -                if (elseUnboxed.getTag().isStrictSubRangeOf(INT) && thenUnboxed.hasTag(INT) &&
    3.14 -                    types.isAssignable(thenUnboxed, elseUnboxed))
    3.15 +                }
    3.16 +                if (elseUnboxed.getTag().isStrictSubRangeOf(INT) &&
    3.17 +                    thenUnboxed.hasTag(INT) &&
    3.18 +                    types.isAssignable(thenUnboxed, elseUnboxed)) {
    3.19                      return elseUnboxed.baseType();
    3.20 -
    3.21 -                for (TypeTag tag : TypeTag.values()) {
    3.22 -                    if (tag.ordinal() >= TypeTag.getTypeTagCount()) break;
    3.23 +                }
    3.24 +
    3.25 +                for (TypeTag tag : primitiveTags) {
    3.26                      Type candidate = syms.typeOfTag[tag.ordinal()];
    3.27 -                    if (candidate != null &&
    3.28 -                        candidate.isPrimitive() &&
    3.29 -                        types.isSubtype(thenUnboxed, candidate) &&
    3.30 -                        types.isSubtype(elseUnboxed, candidate))
    3.31 +                    if (types.isSubtype(thenUnboxed, candidate) &&
    3.32 +                        types.isSubtype(elseUnboxed, candidate)) {
    3.33                          return candidate;
    3.34 +                    }
    3.35                  }
    3.36              }
    3.37  
    3.38 @@ -1575,6 +1577,17 @@
    3.39              return types.lub(thentype.baseType(), elsetype.baseType());
    3.40          }
    3.41  
    3.42 +    final static TypeTag[] primitiveTags = new TypeTag[]{
    3.43 +        BYTE,
    3.44 +        CHAR,
    3.45 +        SHORT,
    3.46 +        INT,
    3.47 +        LONG,
    3.48 +        FLOAT,
    3.49 +        DOUBLE,
    3.50 +        BOOLEAN,
    3.51 +    };
    3.52 +
    3.53      public void visitIf(JCIf tree) {
    3.54          attribExpr(tree.cond, env, syms.booleanType);
    3.55          attribStat(tree.thenpart, env);
     4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Jun 18 09:36:46 2013 +0100
     4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Jun 18 20:08:49 2013 +0100
     4.3 @@ -544,7 +544,7 @@
     4.4          if (checkContext.compatible(found, req, checkContext.checkWarner(pos, found, req))) {
     4.5              return found;
     4.6          } else {
     4.7 -            if (found.getTag().isSubRangeOf(DOUBLE) && req.getTag().isSubRangeOf(DOUBLE)) {
     4.8 +            if (found.isNumeric() && req.isNumeric()) {
     4.9                  checkContext.report(pos, diags.fragment("possible.loss.of.precision", found, req));
    4.10                  return types.createErrorType(found);
    4.11              }
    4.12 @@ -754,7 +754,7 @@
    4.13       *  @param t             The type to be checked.
    4.14       */
    4.15      Type checkNullOrRefType(DiagnosticPosition pos, Type t) {
    4.16 -        if (t.isNullOrReference())
    4.17 +        if (t.isReference() || t.hasTag(BOT))
    4.18              return t;
    4.19          else
    4.20              return typeTagError(pos,
    4.21 @@ -3228,7 +3228,7 @@
    4.22      void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
    4.23          if (operand.constValue() != null
    4.24              && lint.isEnabled(LintCategory.DIVZERO)
    4.25 -            && (operand.getTag().isSubRangeOf(LONG))
    4.26 +            && operand.getTag().isSubRangeOf(LONG)
    4.27              && ((Number) (operand.constValue())).longValue() == 0) {
    4.28              int opc = ((OperatorSymbol)operator).opcode;
    4.29              if (opc == ByteCodes.idiv || opc == ByteCodes.imod
     5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Jun 18 09:36:46 2013 +0100
     5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Jun 18 20:08:49 2013 +0100
     5.3 @@ -952,8 +952,9 @@
     5.4              Type solve(UndetVar uv, InferenceContext inferenceContext) {
     5.5                  Infer infer = inferenceContext.infer();
     5.6                  List<Type> lobounds = filterBounds(uv, inferenceContext);
     5.7 -                Type owntype = infer.types.lub(lobounds);
     5.8 -                if (owntype.hasTag(ERROR)) {
     5.9 +                //note: lobounds should have at least one element
    5.10 +                Type owntype = lobounds.tail.tail == null  ? lobounds.head : infer.types.lub(lobounds);
    5.11 +                if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
    5.12                      throw infer.inferenceException
    5.13                          .setMessage("no.unique.minimal.instance.exists",
    5.14                                      uv.qtype, lobounds);
    5.15 @@ -971,8 +972,9 @@
    5.16              Type solve(UndetVar uv, InferenceContext inferenceContext) {
    5.17                  Infer infer = inferenceContext.infer();
    5.18                  List<Type> hibounds = filterBounds(uv, inferenceContext);
    5.19 -                Type owntype = infer.types.glb(hibounds);
    5.20 -                if (owntype.isErroneous()) {
    5.21 +                //note: lobounds should have at least one element
    5.22 +                Type owntype = hibounds.tail.tail == null  ? hibounds.head : infer.types.glb(hibounds);
    5.23 +                if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
    5.24                      throw infer.inferenceException
    5.25                          .setMessage("no.unique.maximal.instance.exists",
    5.26                                      uv.qtype, hibounds);
    5.27 @@ -1100,10 +1102,11 @@
    5.28                              }
    5.29                          }
    5.30                          //no progress
    5.31 -                        throw inferenceException;
    5.32 +                        throw inferenceException.setMessage();
    5.33                      }
    5.34                  }
    5.35                  catch (InferenceException ex) {
    5.36 +                    //did we fail because of interdependent ivars?
    5.37                      inferenceContext.rollback();
    5.38                      instantiateAsUninferredVars(varsToSolve, inferenceContext);
    5.39                      checkWithinBounds(inferenceContext, warn);
     6.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Jun 18 09:36:46 2013 +0100
     6.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Jun 18 20:08:49 2013 +0100
     6.3 @@ -1435,11 +1435,13 @@
     6.4              env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
     6.5              compileStates.put(env, CompileState.TRANSTYPES);
     6.6  
     6.7 -            if (shouldStop(CompileState.UNLAMBDA))
     6.8 -                return;
     6.9 +            if (source.allowLambda()) {
    6.10 +                if (shouldStop(CompileState.UNLAMBDA))
    6.11 +                    return;
    6.12  
    6.13 -            env.tree = lambdaToMethod.translateTopLevelClass(env, env.tree, localMake);
    6.14 -            compileStates.put(env, CompileState.UNLAMBDA);
    6.15 +                env.tree = lambdaToMethod.translateTopLevelClass(env, env.tree, localMake);
    6.16 +                compileStates.put(env, CompileState.UNLAMBDA);
    6.17 +            }
    6.18  
    6.19              if (shouldStop(CompileState.LOWER))
    6.20                  return;

mercurial