changeset 3509:6949c3d06e8f

Add support for species static access. * add parser support for new '__species' modifier * add resolution and type-checking support for species access members * add code generation support for species static * optimize translation of generic specializable methods (static and species static) to use species static * cleanup accessor bridge generation using species static * cleanup BootstrapMethodSymbol * remove dead code in ClassWriter * add javap support for species statics * add tests
author mcimadamore
date Fri, 27 May 2016 14:18:42 +0100
parents 162ea1f3dfd9
children 515df83430aa
files src/java.compiler/share/classes/javax/lang/model/element/Modifier.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/SymbolMetadata.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/IndifierTranslator.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java src/jdk.jshell/share/classes/jdk/jshell/ReplResolve.java src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java test/tools/javac/annotations/typeAnnotations/classfile/TypeInitializer.java test/tools/javac/diags/examples/TypeStaticCantBeRef.java test/tools/javac/diags/examples/UncheckedGenericSpeciesAccess.java test/tools/javac/lambda/TestBootstrapMethodsCount.java test/tools/javac/lambda/TestInvokeDynamic.java test/tools/javac/valhalla/speciesstatic/SpeciesAccessParserTest.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic01.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic01.out test/tools/javac/valhalla/speciesstatic/SpeciesStatic02.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic03.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic03.out test/tools/javac/valhalla/speciesstatic/SpeciesStatic04.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic04.out test/tools/javac/valhalla/speciesstatic/SpeciesStatic05.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic05.out test/tools/javac/valhalla/speciesstatic/SpeciesStatic06.java test/tools/javac/valhalla/speciesstatic/SpeciesStatic06.out test/tools/javac/valhalla/speciesstatic/separate/Foo.java test/tools/javac/valhalla/speciesstatic/separate/Separate01.java test/tools/javac/valhalla/typespec/items/m3/Opcodes.java test/tools/javac/valhalla/typespec/items/m3/tests/TestArrayLoadAndStore.java test/tools/javac/valhalla/typespec/items/m3/tests/TestDup.java test/tools/javac/valhalla/typespec/items/m3/tests/TestGeneric2GenericCall.java test/tools/javac/valhalla/typespec/items/m3/tests/TestLoadAndStore.java test/tools/javac/valhalla/typespec/items/m3/tests/TestNonSpecializedGenericCall.java test/tools/javac/valhalla/typespec/items/m3/tests/TestSpeciesStatic.java
diffstat 56 files changed, 1294 insertions(+), 310 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.compiler/share/classes/javax/lang/model/element/Modifier.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/java.compiler/share/classes/javax/lang/model/element/Modifier.java	Fri May 27 14:18:42 2016 +0100
@@ -63,6 +63,11 @@
      * @since 1.9
      */
      VALUE,
+    /**
+     * The modifier {@code species static}
+     * @since 1.9
+     */
+     SPECIES,
     /** The modifier {@code static} */          STATIC,
     /** The modifier {@code final} */           FINAL,
     /** The modifier {@code transient} */       TRANSIENT,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Fri May 27 14:18:42 2016 +0100
@@ -114,6 +114,7 @@
     public static final int ACC_BRIDGE   = 0x0040;
     public static final int ACC_VARARGS  = 0x0080;
     public static final int ACC_VALUE    = 0x0100;
+    public static final int ACC_SPECIES  = 0x8000;
 
     /*****************************************
      * Internal compiler flags (no bits in the lower 16).
@@ -296,9 +297,9 @@
     public static final long PEELED = 1L<<53;
 
     /**
-     * Flag to mark specializable (synthetic) symbols
+     * Flag to mark type species static decls (this flag augments ACC_STATIC)
      */
-    public static final long SPECIALIZABLE = 1L<<54;
+    public static final long SPECIES = 1L << 54;
 
     /**
      * Flag to mark virtualized members and types in SpecializeTypes
@@ -324,26 +325,26 @@
      */
     public static final int
         AccessFlags           = PUBLIC | PROTECTED | PRIVATE,
+        TypeVarFlags          = ANY,
+        AnnotationTypeElementMask   = ABSTRACT | PUBLIC,
         LocalClassFlags       = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | VALUE,
+        ClassFlags            = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
+        InterfaceMethodImplicitFlags     = ABSTRACT | PUBLIC,
+        InterfaceVarImplicitFlags     = FINAL | STATIC | PUBLIC;
+
+    public static final long
+        ExtendedStandardFlags       = (long)StandardFlags | DEFAULT | VALUE | SPECIES,
         MemberClassFlags      = LocalClassFlags | INTERFACE | AccessFlags,
-        ClassFlags            = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
-        InterfaceVarFlags     = FINAL | STATIC | PUBLIC,
         VarFlags              = AccessFlags | FINAL | STATIC |
-                                VOLATILE | TRANSIENT | ENUM,
+                                VOLATILE | TRANSIENT | ENUM | SPECIES,
         ConstructorFlags      = AccessFlags,
-        InterfaceMethodFlags  = ABSTRACT | PUBLIC,
+        InterfaceMethodFlags  = ABSTRACT | PUBLIC | PRIVATE | STATIC | STRICTFP | DEFAULT | SPECIES,
         MethodFlags           = AccessFlags | ABSTRACT | STATIC | NATIVE |
-                                SYNCHRONIZED | FINAL | STRICTFP | VALUEFACTORY,
-        TypeVarFlags          = ANY;
-    public static final long
-        ExtendedStandardFlags       = (long)StandardFlags | DEFAULT | VALUE,
-        ModifierFlags               = ((long)StandardFlags & ~INTERFACE) | DEFAULT | VALUE,
-        InterfaceMethodMask         = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
-        AnnotationTypeElementMask   = ABSTRACT | PUBLIC,
+                                SYNCHRONIZED | FINAL | STRICTFP | VALUEFACTORY | SPECIES,
+        ModifierFlags               = ((long)StandardFlags & ~INTERFACE) | DEFAULT | VALUE | SPECIES,
         LocalVarFlags               = FINAL | PARAMETER,
         ReceiverParamFlags          = PARAMETER;
 
-
     public static Set<Modifier> asModifierSet(long flags) {
         Set<Modifier> modifiers = modifierSets.get(flags);
         if (modifiers == null) {
@@ -358,6 +359,8 @@
             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
             if (0 != (flags & SYNCHRONIZED))
                                           modifiers.add(Modifier.SYNCHRONIZED);
+            if (0 != (flags & SPECIES))
+                                          modifiers.add(Modifier.SPECIES);
             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
@@ -407,6 +410,7 @@
         ENUM(Flags.ENUM),
         MANDATED(Flags.MANDATED),
         VALUE(Flags.VALUE),
+        SPECIES(Flags.SPECIES),
         NOOUTERTHIS(Flags.NOOUTERTHIS),
         EXISTS(Flags.EXISTS),
         COMPOUND(Flags.COMPOUND),
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Fri May 27 14:18:42 2016 +0100
@@ -37,10 +37,6 @@
 import javax.tools.JavaFileObject;
 
 import com.sun.tools.javac.code.Types.AsSuperKind;
-import com.sun.tools.javac.code.Attribute.Compound;
-import com.sun.tools.javac.code.TypeAnnotations.AnnotationType;
-import com.sun.tools.javac.code.TypeMetadata.Entry;
-import com.sun.tools.javac.comp.Annotate.AnnotationTypeCompleter;
 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
 import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.code.Type.*;
@@ -163,6 +159,12 @@
         }
     }
 
+    public void appendSpeciesInitTypeAttributes(List<Attribute.TypeCompound> l) {
+        if (l.nonEmpty()) {
+            initedMetadata().appendSpeciesInitTypeAttributes(l);
+        }
+    }
+
     public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
         if (l.nonEmpty()) {
             initedMetadata().appendInitTypeAttributes(l);
@@ -187,6 +189,12 @@
                 : metadata.getInitTypeAttributes();
     }
 
+    public List<Attribute.TypeCompound> getSpeciesInitTypeAttributes() {
+        return (metadata == null)
+                ? List.<Attribute.TypeCompound>nil()
+                : metadata.getSpeciesInitTypeAttributes();
+    }
+
     public void setInitTypeAttributes(List<Attribute.TypeCompound> l) {
         initedMetadata().setInitTypeAttributes(l);
     }
@@ -195,6 +203,10 @@
         initedMetadata().setClassInitTypeAttributes(l);
     }
 
+    public void setSpeciesInitTypeAttributes(List<Attribute.TypeCompound> l) {
+        initedMetadata().setSpeciesInitTypeAttributes(l);
+    }
+
     public List<Attribute.Compound> getDeclarationAttributes() {
         return (metadata == null)
                 ? List.<Attribute.Compound>nil()
@@ -353,6 +365,10 @@
              name != name.table.names._this;
     }
 
+    public boolean isTypeStatic() {
+        return isStatic() && (flags() & SPECIES) != 0;
+    }
+
     public boolean isInterface() {
         return (flags() & INTERFACE) != 0;
     }
@@ -1975,10 +1991,9 @@
         public Symbol bsm;
         public int bsmKind;
 
-        public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, BootstrapArgument<?>[] staticArgs) {
+        public DynamicMethodSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, BootstrapArgument<?>[] staticArgs) {
             super(0, name, type, owner);
             this.bsm = bsm;
-            this.bsmKind = bsmKind;
             this.staticArgs = staticArgs;
         }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/SymbolMetadata.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/SymbolMetadata.java	Fri May 27 14:18:42 2016 +0100
@@ -84,6 +84,12 @@
     private List<Attribute.TypeCompound> clinit_type_attributes = List.<Attribute.TypeCompound>nil();
 
     /*
+     * Type attributes of species initializers in this class.
+     * Unused if the current symbol is not a ClassSymbol.
+     */
+    private List<Attribute.TypeCompound> sclinit_type_attributes = List.<Attribute.TypeCompound>nil();
+
+    /*
      * The Symbol this SymbolMetadata instance belongs to
      */
     private final Symbol sym;
@@ -108,6 +114,10 @@
         return clinit_type_attributes;
     }
 
+    public List<Attribute.TypeCompound> getSpeciesInitTypeAttributes() {
+        return sclinit_type_attributes;
+    }
+
     public void setDeclarationAttributes(List<Attribute.Compound> a) {
         Assert.check(pendingCompletion() || !isStarted());
         if (a == null) {
@@ -137,6 +147,13 @@
         clinit_type_attributes = a;
     }
 
+    public void setSpeciesInitTypeAttributes(List<Attribute.TypeCompound> a) {
+        if (a == null) {
+            throw new NullPointerException();
+        }
+        sclinit_type_attributes = a;
+    }
+
     public void setAttributes(SymbolMetadata other) {
         if (other == null) {
             throw new NullPointerException();
@@ -217,6 +234,17 @@
         return this;
     }
 
+    public SymbolMetadata appendSpeciesInitTypeAttributes(List<Attribute.TypeCompound> l) {
+        if (l.isEmpty()) {
+            // no-op
+        } else if (sclinit_type_attributes.isEmpty()) {
+            sclinit_type_attributes = l;
+        } else {
+            sclinit_type_attributes = sclinit_type_attributes.appendList(l);
+        }
+        return this;
+    }
+
     public SymbolMetadata prepend(List<Attribute.Compound> l) {
         attributes = filterDeclSentinels(attributes);
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Fri May 27 14:18:42 2016 +0100
@@ -2438,7 +2438,7 @@
     public Type memberType(Type t, Symbol sym, AsSuperKind superKind) {
         MemberType visitor = superKind == AsSuperKind.NORMAL ?
                 memberType : memberTypePartialErasure;
-        return (sym.flags() & STATIC) != 0
+        return (sym.isStatic() && !sym.isTypeStatic())
             ? sym.type
             : visitor.visit(t, sym);
     }
@@ -2463,8 +2463,7 @@
             @Override
             public Type visitClassType(ClassType t, Symbol sym) {
                 Symbol owner = sym.owner;
-                long flags = sym.flags();
-                if (((flags & STATIC) == 0) && owner.type.isParameterized()) {
+                if ((!sym.isStatic() || sym.isTypeStatic()) && owner.type.isParameterized()) {
                     Type base = asOuterSuper(t, owner, superKind);
                     //if t is an intersection type T = CT & I1 & I2 ... & In
                     //its supertypes CT, I1, ... In might contain wildcards
@@ -3035,7 +3034,7 @@
                 case VAR:
                 case MTH:
                 case TYP:
-                    return ((sym.flags() & (STATIC | SPECIALIZABLE)) == STATIC) ?
+                    return (sym.isStatic() && !sym.isTypeStatic()) ?
                             closure :
                             ownersClosure(sym.owner, closure);
                 default:
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 27 14:18:42 2016 +0100
@@ -47,6 +47,7 @@
 import com.sun.tools.javac.comp.Check.CheckContext;
 import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
 import com.sun.tools.javac.comp.Infer.FreeTypeListener;
+import com.sun.tools.javac.comp.Resolve.StaticLevel;
 import com.sun.tools.javac.jvm.*;
 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond;
 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg;
@@ -272,7 +273,7 @@
              &&
              v.owner == owner.owner
              &&
-             ((v.flags() & STATIC) != 0) == Resolve.isStatic(env));
+             (StaticLevel.from(v) == StaticLevel.from(env)));
     }
 
     /** Check that variable can be assigned to.
@@ -938,9 +939,10 @@
                 // no explicit outer instance is given,
                 // disable implicit outer instance from being passed.
                 // (This would be an illegal access to "this before super").
-                if (env.info.isSelfCall &&
+                if ((c.flags_field & SPECIES) != 0 ||
+                        (env.info.isSelfCall &&
                         env.tree.hasTag(NEWCLASS) &&
-                        ((JCNewClass)env.tree).encl == null) {
+                        ((JCNewClass)env.tree).encl == null)) {
                     c.flags_field |= NOOUTERTHIS;
                 }
                 attribClass(tree.pos(), c);
@@ -1184,7 +1186,12 @@
             final Env<AttrContext> localEnv =
                 env.dup(tree, env.info.dup(env.info.scope.dupUnshared(fakeOwner)));
 
-            if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++;
+            if ((tree.flags & SPECIES) != 0) {
+                localEnv.info.typeStaticLevel++;
+            } else if ((tree.flags & STATIC) != 0) {
+                localEnv.info.staticLevel++;
+            }
+
             // Attribute all type annotations in the block
             annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, localEnv.info.scope.owner, null);
             annotate.flush();
@@ -1195,7 +1202,9 @@
                 // to allow output in Gen.normalizeDefs.
                 ClassSymbol cs = (ClassSymbol)env.info.scope.owner;
                 List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes();
-                if ((tree.flags & STATIC) != 0) {
+                if ((tree.flags & SPECIES) != 0) {
+                    cs.appendSpeciesInitTypeAttributes(tas);
+                } else if ((tree.flags & STATIC) != 0) {
                     cs.appendClassInitTypeAttributes(tas);
                 } else {
                     cs.appendInitTypeAttributes(tas);
@@ -1860,7 +1869,7 @@
                     Type encl = site.getEnclosingType();
                     while (encl != null && encl.hasTag(TYPEVAR))
                         encl = encl.getUpperBound();
-                    if (encl.hasTag(CLASS)) {
+                    if (encl.hasTag(CLASS) && !site.tsym.isStatic()) {
                         // we are calling a nested class
 
                         if (tree.meth.hasTag(SELECT)) {
@@ -2099,6 +2108,7 @@
                 }
             }
         } else if (!clazztype.tsym.isInterface() &&
+                   !clazztype.tsym.isTypeStatic() &&
                    clazztype.getEnclosingType().hasTag(CLASS)) {
             // Check for the existence of an apropos outer instance
             rs.resolveImplicitThis(tree.pos(), env, clazztype);
@@ -2784,11 +2794,8 @@
          * Also as LTM is a phase subsequent to attribution, the methods from
          * clinits can be safely removed by LTM to save memory.
          */
-        private Map<ClassSymbol, MethodSymbol> clinits = new HashMap<>();
-
-        public MethodSymbol removeClinit(ClassSymbol sym) {
-            return clinits.remove(sym);
-        }
+        Map<ClassSymbol, MethodSymbol> clinits = new HashMap<>();
+        Map<ClassSymbol, MethodSymbol> sclinits = new HashMap<>();
 
         /* This method returns an environment to be used to attribute a lambda
          * expression.
@@ -2820,14 +2827,17 @@
                     /* if the field is static then we need to create a fake clinit
                      * method, this method can later be reused by LTM.
                      */
-                    MethodSymbol clinit = clinits.get(enclClass);
+                    Map<ClassSymbol, MethodSymbol> inits = owner.isTypeStatic() ?
+                            sclinits : clinits;
+                    MethodSymbol clinit = inits.get(enclClass);
                     if (clinit == null) {
                         Type clinitType = new MethodType(List.<Type>nil(),
                                 syms.voidType, List.<Type>nil(), syms.methodClass);
-                        clinit = new MethodSymbol(STATIC | SYNTHETIC | PRIVATE,
+                        clinit = new MethodSymbol(STATIC | SYNTHETIC | PRIVATE |
+                                (owner.isTypeStatic() ? SPECIES : 0),
                                 names.clinit, clinitType, enclClass);
                         clinit.params = List.<VarSymbol>nil();
-                        clinits.put(enclClass, clinit);
+                        inits.put(enclClass, clinit);
                     }
                     newScopeOwner = clinit;
                 }
@@ -2981,6 +2991,11 @@
                     chk.checkRaw(that.expr, localEnv);
                 }
 
+                // Disallow selecting a species static member from a non-reifiable type
+                if (refSym.isTypeStatic() && TreeInfo.isStaticSelector(that.expr, names)) {
+                    chk.checkSpeciesAccessQualifier(that, that.expr.type, refSym);
+                }
+
                 if (that.sym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) &&
                         exprType.getTypeArguments().nonEmpty()) {
                     //static ref with class type-args
@@ -3367,6 +3382,14 @@
             }
         }
 
+        // Disallow selecting a species static member from a non-reifiable type
+        if (sym.owner != null && sym.isTypeStatic()) {
+            Type outer = types.asOuterSuper(env.enclClass.type, sym.owner.enclClass());
+            if (outer != null) {
+                chk.checkSpeciesAccessQualifier(tree, outer, sym);
+            }
+        }
+
         // If symbol is a variable, ...
         if (sym.kind == VAR) {
             VarSymbol v = (VarSymbol)sym;
@@ -3501,6 +3524,11 @@
                               new ResultInfo(KindSelector.TYP_PCK, pt()));
         }
 
+        // Disallow selecting a species static member from a non-reifiable type
+        if (isType(sitesym) && sym.isTypeStatic()) {
+            chk.checkSpeciesAccessQualifier(tree, site, sym);
+        }
+
         // Disallow selecting a non-virtual field from an expression whose type is anyfied raw/wildcard
         if ((sym.kind == VAR || sym.kind == MTH) &&
                 (sitesym == null || !sitesym.kind.matches(KindSelector.TYP_PCK)) &&
@@ -3520,7 +3548,7 @@
                 }
             } else {
                 // Check if type-qualified fields or methods are static (JLS)
-                if ((sym.flags() & STATIC) == 0 &&
+                if (!sym.isStatic() &&
                     !env.next.tree.hasTag(REFERENCE) &&
                     sym.name != names._super &&
                     (sym.kind == VAR || sym.kind == MTH)) {
@@ -3533,7 +3561,7 @@
                 log.error(tree.pos(), "static.intf.method.invoke.not.supported.in.source", sourceName);
             }
         } else if (sym.kind != ERR &&
-                   (sym.flags() & STATIC) != 0 &&
+                   sym.isStatic() &&
                    sym.name != names._class) {
             // If the qualified item is not a type and the selected item is static, report
             // a warning. Make allowance for the class of an array type e.g. Object[].class)
@@ -3871,7 +3899,7 @@
                 (initEnv.info.enclVar == v || v.pos > tree.pos) &&
                 v.owner.kind == TYP &&
                 v.owner == env.info.scope.owner.enclClass() &&
-                ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) &&
+                (StaticLevel.from(v) == StaticLevel.from(env)) &&
                 (!env.tree.hasTag(ASSIGN) ||
                  TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
                 String suffix = (initEnv.info.enclVar == v) ?
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java	Fri May 27 14:18:42 2016 +0100
@@ -48,6 +48,10 @@
      */
     int staticLevel = 0;
 
+    /** The number of enclosing `species static' modifiers.
+     */
+    int typeStaticLevel = 0;
+
     /** Is this an environment for a this(...) or super(...) call?
      */
     boolean isSelfCall = false;
@@ -109,6 +113,7 @@
         AttrContext info = new AttrContext();
         info.scope = scope;
         info.staticLevel = staticLevel;
+        info.typeStaticLevel = typeStaticLevel;
         info.isSelfCall = isSelfCall;
         info.selectSuper = selectSuper;
         info.pendingResolutionPhase = pendingResolutionPhase;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Fri May 27 14:18:42 2016 +0100
@@ -871,6 +871,13 @@
             }
         };
 
+    void checkSpeciesAccessQualifier(DiagnosticPosition pos, Type site, Symbol sym) {
+        if (!types.isReifiable(site) &&
+                sym.type.containsAny(site.tsym.type.allparams())) {
+            warnUnchecked(pos, "unchecked.generic.species.access", site);
+        }
+    }
+
     void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) {
         MethodSymbol m = tree.sym;
         if (!allowSimplifiedVarargs) return;
@@ -1213,7 +1220,7 @@
             else if (sym.owner.kind != TYP)
                 mask = LocalVarFlags;
             else if ((sym.owner.flags_field & INTERFACE) != 0)
-                mask = implicit = InterfaceVarFlags;
+                mask = implicit = InterfaceVarImplicitFlags;
             else
                 mask = VarFlags;
             break;
@@ -1232,13 +1239,13 @@
                     mask = AnnotationTypeElementMask;
                     implicit = PUBLIC | ABSTRACT;
                 } else if ((flags & (DEFAULT | STATIC | PRIVATE)) != 0) {
-                    mask = InterfaceMethodMask;
+                    mask = InterfaceMethodFlags;
                     implicit = (flags & PRIVATE) != 0 ? 0 : PUBLIC;
                     if ((flags & DEFAULT) != 0) {
                         implicit |= ABSTRACT;
                     }
                 } else {
-                    mask = implicit = InterfaceMethodFlags;
+                    mask = implicit = InterfaceMethodImplicitFlags;
                 }
             } else {
                 // instance methods of value types do not have a monitor associated with their `this'
@@ -1264,11 +1271,16 @@
                 mask = MemberClassFlags;
                 if (sym.owner.owner.kind == PCK ||
                     (sym.owner.flags_field & STATIC) != 0)
-                    mask |= STATIC;
+                    mask |= STATIC | SPECIES;
                 else if ((flags & ENUM) != 0)
                     log.error(pos, "enums.must.be.static");
                 // Nested interfaces and enums are always STATIC (Spec ???)
                 if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC;
+                if ((sym.owner.flags_field & SPECIES) != 0 &&
+                        (flags & (STATIC | SPECIES)) == STATIC) {
+                    log.error(pos,
+                          "mod.not.allowed.here", asFlagSet(STATIC));
+                }
             } else {
                 mask = ClassFlags;
             }
@@ -1286,6 +1298,9 @@
         default:
             throw new AssertionError();
         }
+        if ((flags & SPECIES) != 0) {
+            implicit |= STATIC;
+        }
         long illegal = flags & ExtendedStandardFlags & ~mask;
         if (illegal != 0) {
             if ((illegal & INTERFACE) != 0) {
@@ -1308,6 +1323,10 @@
                                 DEFAULT)
                  &&
                  checkDisjoint(pos, flags,
+                                STATIC,
+                                SPECIES)
+                 &&
+                 checkDisjoint(pos, flags,
                                ABSTRACT | INTERFACE,
                                FINAL | NATIVE | SYNCHRONIZED | VALUE)
                  &&
@@ -1484,6 +1503,7 @@
 
         public void visitSelectInternal(JCFieldAccess tree) {
             if (tree.type.tsym.isStatic() &&
+                !tree.type.tsym.isTypeStatic() &&
                 tree.selected.type.isParameterized()) {
                 // The enclosing type is not a class, so we are
                 // looking at a static member type.  However, the
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java	Fri May 27 14:18:42 2016 +0100
@@ -392,7 +392,7 @@
         c.members_field = WriteableScope.create(c);
 
         ClassType ct = (ClassType)c.type;
-        if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
+        if (owner.kind != PCK && (c.flags_field & (STATIC | SPECIES)) != STATIC) {
             // We are seeing a local or inner class.
             // Set outer_field of this class to closest enclosing class
             // which contains this class in a non-static context
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/IndifierTranslator.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/IndifierTranslator.java	Fri May 27 14:18:42 2016 +0100
@@ -95,13 +95,12 @@
                 syms.stringType,
                 syms.methodTypeType).appendList(staticArgs.map(a -> a.kind.asType(syms)));
 
-        Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
+        MethodSymbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
                 bsmName, bsm_staticArgs, List.<Type>nil());
 
         DynamicMethodSymbol dynSym = new DynamicMethodSymbol(methName,
                 owner,
-                referenceKind(bsm),
-                (MethodSymbol)bsm,
+                bsm.asHandle(),
                 indyType,
                 staticArgs.toArray(new BootstrapArgument<?>[staticArgs.length()])) {
             @Override
@@ -124,25 +123,6 @@
         }
     }
 
-    /**
-     * Get the opcode associated with this method reference
-     */
-    protected int referenceKind(Symbol refSym) {
-        if (refSym.isConstructor()) {
-            return ClassFile.REF_newInvokeSpecial;
-        } else {
-            if (refSym.isStatic()) {
-                return ClassFile.REF_invokeStatic;
-            } else if ((refSym.flags() & PRIVATE) != 0) {
-                return ClassFile.REF_invokeSpecial;
-            } else if (refSym.enclClass().isInterface()) {
-                return ClassFile.REF_invokeInterface;
-            } else {
-                return ClassFile.REF_invokeVirtual;
-            }
-        }
-    }
-
     protected JCIdent makeThis(Type type, Symbol owner) {
         VarSymbol _this = new VarSymbol(PARAMETER | FINAL | SYNTHETIC,
                 names._this,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Fri May 27 14:18:42 2016 +0100
@@ -25,9 +25,11 @@
 
 package com.sun.tools.javac.comp;
 
+import com.sun.tools.javac.code.Attribute.TypeCompound;
 import com.sun.tools.javac.code.Kinds.KindSelector;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument;
+import com.sun.tools.javac.code.Symbol.MethodHandleSymbol;
 import com.sun.tools.javac.code.Symbol.TypeVariableSymbol;
 import com.sun.tools.javac.code.Type.ForAll;
 import com.sun.tools.javac.code.Types.AsSuperKind;
@@ -61,6 +63,7 @@
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
 
+import java.lang.invoke.MethodHandle;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -298,12 +301,24 @@
                     sym::setTypeAttributes);
 
 
-            boolean init;
-            if ((init = (owner.name == names.init)) || owner.name == names.clinit) {
-                owner = owner.owner;
+            if (owner.name == names.init || owner.name == names.clinit || owner.name == names.sclinit) {
+                Symbol destOwner = owner.owner;
+                Supplier<List<TypeCompound>> getter;
+                Consumer<List<TypeCompound>> setter;
+
+                if (owner.name == names.init) {
+                    getter = destOwner::getInitTypeAttributes;
+                    setter = destOwner::setInitTypeAttributes;
+                } else if (owner.name == names.sclinit) {
+                    getter = destOwner::getSpeciesInitTypeAttributes;
+                    setter = destOwner::setSpeciesInitTypeAttributes;
+                } else {
+                    getter = destOwner::getClassInitTypeAttributes;
+                    setter = destOwner::setClassInitTypeAttributes;
+                }
+
                 apportionTypeAnnotations(tree,
-                        init ? owner::getInitTypeAttributes : owner::getClassInitTypeAttributes,
-                        init ? owner::setInitTypeAttributes : owner::setClassInitTypeAttributes,
+                        getter, setter,
                         sym::appendUniqueTypeAttributes);
             }
             if (localContext.self != null && localContext.self.getKind() == ElementKind.FIELD) {
@@ -376,11 +391,8 @@
         //then, determine the arguments to the indy call
         List<JCExpression> indy_args = translate(syntheticInits.toList(), localContext.prev);
 
-        //build a sam instance using an indy call to the meta-factory
-        int refKind = referenceKind(sym);
-
         //convert to an invokedynamic call
-        result = makeMetafactoryIndyCall(context, refKind, sym, indy_args);
+        result = makeMetafactoryIndyCall(context, sym, indy_args);
     }
 
     // where
@@ -452,7 +464,7 @@
 
 
         //build a sam instance using an indy call to the meta-factory
-        result = makeMetafactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args);
+        result = makeMetafactoryIndyCall(localContext, refSym, indy_args);
     }
 
     /**
@@ -1051,7 +1063,7 @@
      * Generate an indy method call to the meta factory
      */
     private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context,
-            int refKind, Symbol refSym, List<JCExpression> indy_args) {
+            Symbol refSym, List<JCExpression> indy_args) {
         JCFunctionalExpression tree = context.tree;
         //determine the static bsm args
         MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
@@ -1124,6 +1136,8 @@
                 int prevPos = make.pos;
                 try {
                     make.at(kInfo.clazz);
+                    @SuppressWarnings("unchecked")
+                    int refKind = ((BootstrapArgument<MethodHandleSymbol>)staticArgs.tail.head).data.referenceKind();
                     addDeserializationCase(refKind, refSym, tree.type, samSym,
                             tree, staticArgs, indyType);
                 } finally {
@@ -1233,6 +1247,7 @@
          * a static var init context
          */
         private Map<ClassSymbol, Symbol> clinits = new HashMap<>();
+        private Map<ClassSymbol, Symbol> sclinits = new HashMap<>();
 
         private JCClassDecl analyzeAndPreprocessClass(JCClassDecl tree) {
             frameStack = List.nil();
@@ -1286,6 +1301,7 @@
             SyntheticMethodNameCounter prevSyntheticMethodNameCounts =
                     syntheticMethodNameCounts;
             Map<ClassSymbol, Symbol> prevClinits = clinits;
+            Map<ClassSymbol, Symbol> prevSclinits = sclinits;
             DiagnosticSource prevSource = log.currentSource();
             try {
                 log.useSource(tree.sym.sourcefile);
@@ -1322,6 +1338,7 @@
                 lambdaCount = prevLambdaCount;
                 syntheticMethodNameCounts = prevSyntheticMethodNameCounts;
                 clinits = prevClinits;
+                sclinits = prevSclinits;
             }
         }
 
@@ -1604,31 +1621,42 @@
         }
 
         private Symbol initSym(ClassSymbol csym, long flags) {
-            boolean isStatic = (flags & STATIC) != 0;
-            if (isStatic) {
+            if ((flags & STATIC) != 0) {
                 /* static clinits are generated in Gen, so we need to use a fake
                  * one. Attr creates a fake clinit method while attributing
                  * lambda expressions used as initializers of static fields, so
                  * let's use that one.
                  */
-                MethodSymbol clinit = attr.removeClinit(csym);
+                boolean isSpeciesStatic = (flags & SPECIES) != 0;
+
+                Map<ClassSymbol, MethodSymbol> attr_inits;
+                Map<ClassSymbol, Symbol> inits;
+                if (isSpeciesStatic) {
+                    attr_inits = attr.sclinits;
+                    inits = sclinits;
+                } else {
+                    attr_inits = attr.clinits;
+                    inits = clinits;
+                }
+
+                MethodSymbol clinit = attr_inits.remove(csym);
                 if (clinit != null) {
-                    clinits.put(csym, clinit);
+                    inits.put(csym, clinit);
                     return clinit;
                 }
 
                 /* if no clinit is found at Attr, then let's try at clinits.
                  */
-                clinit = (MethodSymbol)clinits.get(csym);
+                clinit = (MethodSymbol)inits.get(csym);
                 if (clinit == null) {
                     /* no luck, let's create a new one
                      */
-                    clinit = makePrivateSyntheticMethod(STATIC,
+                    clinit = makePrivateSyntheticMethod(STATIC | (isSpeciesStatic ? SPECIES : 0),
                             names.clinit,
                             new MethodType(List.<Type>nil(), syms.voidType,
-                                List.<Type>nil(), syms.methodClass),
+                                    List.<Type>nil(), syms.methodClass),
                             csym);
-                    clinits.put(csym, clinit);
+                    inits.put(csym, clinit);
                 }
                 return clinit;
             } else {
@@ -2156,11 +2184,19 @@
                 // Lambda methods are private synthetic.
                 // Inherit ACC_STRICT from the enclosing method, or, for clinit,
                 // from the class.
-                translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD | SPECIALIZABLE |
+                long staticLevel;
+                if (thisReferenced) {
+                    staticLevel = inInterface? DEFAULT : 0;
+                } else {
+                    staticLevel = STATIC;
+                    if (types.isAnyfied(translatedSym.owner.enclClass())) {
+                        staticLevel |= SPECIES;
+                    }
+                }
+                translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD |
                         owner.flags_field & STRICTFP |
                         owner.owner.flags_field & STRICTFP |
-                        PRIVATE |
-                        (thisReferenced? (inInterface? DEFAULT : 0) : STATIC);
+                        PRIVATE | staticLevel;
 
                 //compute synthetic params
                 ListBuffer<JCVariableDecl> params = new ListBuffer<>();
@@ -2234,13 +2270,6 @@
                         : null;
             }
 
-            /**
-             * Get the opcode associated with this method reference
-             */
-            int referenceKind() {
-                return LambdaToMethod.this.referenceKind(tree.sym);
-            }
-
             boolean needsVarArgsConversion() {
                 return tree.varargsElement != null;
             }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri May 27 14:18:42 2016 +0100
@@ -32,6 +32,7 @@
 import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument.Kind;
+import com.sun.tools.javac.comp.Resolve.StaticLevel;
 import com.sun.tools.javac.jvm.*;
 import com.sun.tools.javac.main.Option.PkgInfo;
 import com.sun.tools.javac.tree.*;
@@ -1039,7 +1040,7 @@
         // For protected symbols this needs to be the instance as a member
         // of the type containing the accessed symbol, not the class
         // containing the access method.
-        if ((vsym.flags() & STATIC) == 0) {
+        if (!vsym.isStatic()) {
             argtypes = argtypes.prepend(vsym.owner.type);
         }
         MethodSymbol[] accessors = accessSyms.get(vsym);
@@ -1047,7 +1048,7 @@
         Symbol baseSymbol = sym;
         if (accessor == null) {
             accessor = new MethodSymbol(
-                STATIC | SYNTHETIC | (accOwner.isInterface() ? PUBLIC : 0),
+                SYNTHETIC | (accOwner.isInterface() ? PUBLIC : 0),
                 baseAcc != null ? baseAcc.name : accessName(anum.intValue(), acode),
                 new MethodType(argtypes, restype, thrown, syms.methodClass),
                 accOwner) {
@@ -1056,9 +1057,11 @@
                     return baseSymbol;
                 }
             };
+            long staticLevel = STATIC;
             if (types.needsMangling(accessor.type)) {
-                accessor.flags_field |= SPECIALIZABLE;
+                staticLevel |= SPECIES;
             }
+            accessor.flags_field |= staticLevel;
             if (sym.type.hasTag(FORALL)) {
                 ForAll fa = (ForAll)sym.type;
                 final Symbol accSym = accessor;
@@ -1079,7 +1082,7 @@
      *  @param sym   The accessed symbol.
      */
     JCExpression accessBase(DiagnosticPosition pos, Symbol sym) {
-        return (sym.flags() & STATIC) != 0
+        return sym.isStatic()
             ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner))
             : makeOwnerThis(pos, sym, true);
     }
@@ -1119,7 +1122,7 @@
 
     boolean crossSpecializationBoundaries(Symbol sym, JCTree base) {
         Type rec = specializedReceiver(sym, base);
-        if (sym.isStatic()) {
+        if (StaticLevel.from(sym) != StaticLevel.INSTANCE) {
             //static non-specializable call, needs accessor if we are in a specializable class
             return types.needsMangling(currentClass.type);
         } else if (rec != null) {
@@ -1274,7 +1277,7 @@
                         Type unerasedSite = base != null ?
                                 base.unerasedType :
                                 types.asOuterSuper(currentClass.type, accessor.owner);
-                        if ((sym.flags() & STATIC) == 0) {
+                        if (!sym.isStatic()) {
                             // Instance access methods get instance
                             // as first parameter.
                             if (base == null)
@@ -1352,7 +1355,7 @@
                         .prepend(syms.intType)
                         .prepend(syms.stringType);
                 aconstr = new MethodSymbol(
-                    SYNTHETIC | SPECIALIZABLE,
+                    SYNTHETIC,
                     names.init,
                     new MethodType(
                         argtypes.append(
@@ -1465,7 +1468,7 @@
 
         JCExpression ref;           // The tree referencing the private symbol.
         List<JCExpression> args;    // Any additional arguments to be passed along.
-        if ((sym.flags() & STATIC) != 0) {
+        if (sym.isStatic()) {
             ref = make.Ident(sym);
             args = make.Idents(md.params);
         } else {
@@ -1630,7 +1633,7 @@
         Type unerasedType = owner.enclClass().type.getEnclosingType();
         Type target = types.erasure(unerasedType);
         VarSymbol outerThis =
-            new VarSymbol(flags | SPECIALIZABLE, outerThisName(target, owner), unerasedType, owner);
+            new VarSymbol(flags, outerThisName(target, owner), unerasedType, owner);
         outerThisStack = outerThisStack.prepend(outerThis);
         return outerThis;
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri May 27 14:18:42 2016 +0100
@@ -282,13 +282,20 @@
             localEnv.info.returnResult = attr.new ResultInfo(KindSelector.VAL,
                                                              tree.sym.type.getReturnType());
         }
-        if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++;
+        if ((tree.mods.flags & SPECIES) != 0) {
+            localEnv.info.typeStaticLevel++;
+        } else if ((tree.mods.flags & STATIC) != 0) {
+            localEnv.info.staticLevel++;
+        }
         return localEnv;
     }
 
     public void visitVarDef(JCVariableDecl tree) {
         Env<AttrContext> localEnv = env;
-        if ((tree.mods.flags & STATIC) != 0 ||
+        if ((tree.mods.flags & SPECIES) != 0) {
+            localEnv = env.dup(tree, env.info.dup());
+            localEnv.info.typeStaticLevel++;
+        } else if ((tree.mods.flags & STATIC) != 0 ||
             (env.info.scope.owner.flags() & INTERFACE) != 0) {
             localEnv = env.dup(tree, env.info.dup());
             localEnv.info.staticLevel++;
@@ -453,9 +460,12 @@
         if (tree.sym.owner.kind == TYP) {
             localEnv.info.scope = env.info.scope.dupUnshared(tree.sym);
         }
-        if ((tree.mods.flags & STATIC) != 0 ||
-                ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null))
+        if ((tree.mods.flags & SPECIES) != 0) {
+            localEnv.info.typeStaticLevel++;
+        } else if ((tree.mods.flags & STATIC) != 0 ||
+                ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null)) {
             localEnv.info.staticLevel++;
+        }
         return localEnv;
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri May 27 14:18:42 2016 +0100
@@ -57,9 +57,9 @@
 import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.function.BiPredicate;
-import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import javax.lang.model.element.ElementVisitor;
@@ -262,11 +262,39 @@
  * Identifier resolution
  *************************************************************************/
 
-    /** An environment is "static" if its static level is greater than
-     *  the one of its outer environment
-     */
-    protected static boolean isStatic(Env<AttrContext> env) {
-        return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel;
+    public enum StaticLevel {
+        INSTANCE,
+        TYPE_STATIC,
+        STATIC;
+
+        public static StaticLevel from(Env<AttrContext> env) {
+            if (env.info.staticLevel > env.outer.info.staticLevel) {
+                return STATIC;
+            } else if (env.info.typeStaticLevel > env.outer.info.typeStaticLevel) {
+                return TYPE_STATIC;
+            } else {
+                return INSTANCE;
+            }
+        }
+
+        public static StaticLevel from(Symbol sym) {
+            if (sym.isTypeStatic()) {
+                return TYPE_STATIC;
+            } else if (sym.isStatic()) {
+                return STATIC;
+            } else {
+                return INSTANCE;
+            }
+        }
+
+        public StaticLevel intersect(StaticLevel newLevel) {
+            return (ordinal() >= newLevel.ordinal()) ?
+                    this : newLevel;
+        }
+
+        public boolean check(Symbol sym) {
+            return from(sym).ordinal() >= ordinal();
+        }
     }
 
     /** An environment is an "initializer" if it is a constructor or
@@ -1406,10 +1434,10 @@
     Symbol findVar(Env<AttrContext> env, Name name) {
         Symbol bestSoFar = varNotFound;
         Env<AttrContext> env1 = env;
-        boolean staticOnly = false;
+        StaticLevel staticLevel = StaticLevel.INSTANCE;
         while (env1.outer != null) {
             Symbol sym = null;
-            if (isStatic(env1)) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1));
             for (Symbol s : env1.info.scope.getSymbolsByName(name)) {
                 if (s.kind == VAR && (s.flags_field & SYNTHETIC) == 0) {
                     sym = s;
@@ -1420,10 +1448,9 @@
                 sym = findField(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
             }
             if (sym.exists()) {
-                if (staticOnly &&
-                    sym.kind == VAR &&
+                if (sym.kind == VAR &&
                     sym.owner.kind == TYP &&
-                    (sym.flags() & STATIC) == 0)
+                    !staticLevel.check(sym))
                     return new StaticError(sym);
                 else
                     return sym;
@@ -1431,7 +1458,7 @@
                 bestSoFar = bestOf(bestSoFar, sym);
             }
 
-            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1.enclClass.sym));
             env1 = env1.outer;
         }
 
@@ -1876,9 +1903,9 @@
                    boolean allowBoxing, boolean useVarargs) {
         Symbol bestSoFar = methodNotFound;
         Env<AttrContext> env1 = env;
-        boolean staticOnly = false;
+        StaticLevel staticLevel = StaticLevel.INSTANCE;
         while (env1.outer != null) {
-            if (isStatic(env1)) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1));
             Assert.check(env1.info.preferredTreeForDiagnostics == null);
             env1.info.preferredTreeForDiagnostics = env.tree;
             try {
@@ -1886,10 +1913,9 @@
                     env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
                     allowBoxing, useVarargs);
                 if (sym.exists()) {
-                    if (staticOnly &&
-                        sym.kind == MTH &&
+                    if (sym.kind == MTH &&
                         sym.owner.kind == TYP &&
-                        (sym.flags() & STATIC) == 0) return new StaticError(sym);
+                        !staticLevel.check(sym)) return new StaticError(sym);
                     else return sym;
                 } else {
                     bestSoFar = bestOf(bestSoFar, sym);
@@ -1897,7 +1923,7 @@
             } finally {
                 env1.info.preferredTreeForDiagnostics = null;
             }
-            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1.enclClass.sym));
             env1 = env1.outer;
         }
 
@@ -2054,10 +2080,10 @@
         return bestSoFar;
     }
 
-    Symbol findTypeVar(Env<AttrContext> env, Name name, boolean staticOnly) {
+    Symbol findTypeVar(Env<AttrContext> env, Name name, StaticLevel staticLevel) {
         for (Symbol sym : env.info.scope.getSymbolsByName(name)) {
             if (sym.kind == TYP) {
-                if (staticOnly &&
+                if (staticLevel == StaticLevel.STATIC &&
                     sym.type.hasTag(TYPEVAR) &&
                     sym.owner.kind == TYP)
                     return new StaticError(sym);
@@ -2076,11 +2102,11 @@
             return typeNotFound; // do not allow inadvertent "lookup" of anonymous types
         Symbol bestSoFar = typeNotFound;
         Symbol sym;
-        boolean staticOnly = false;
+        StaticLevel staticLevel = StaticLevel.INSTANCE;
         for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
-            if (isStatic(env1)) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1));
             // First, look for a type variable and the first member type
-            final Symbol tyvar = findTypeVar(env1, name, staticOnly);
+            final Symbol tyvar = findTypeVar(env1, name, staticLevel);
             sym = findImmediateMemberType(env1, env1.enclClass.sym.type,
                                           name, env1.enclClass.sym);
 
@@ -2100,7 +2126,7 @@
                 sym = findInheritedMemberType(env1, env1.enclClass.sym.type,
                                               name, env1.enclClass.sym);
 
-            if (staticOnly && sym.kind == TYP &&
+            if (staticLevel == StaticLevel.STATIC && sym.kind == TYP && //Todo: type static inner classes have an enclosing type?
                 sym.type.hasTag(CLASS) &&
                 sym.type.getEnclosingType().hasTag(CLASS) &&
                 env1.enclClass.sym.type.isParameterized() &&
@@ -2110,8 +2136,7 @@
             else bestSoFar = bestOf(bestSoFar, sym);
 
             JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass;
-            if ((encl.sym.flags() & STATIC) != 0)
-                staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(encl.sym));
         }
 
         if (!env.tree.hasTag(IMPORT)) {
@@ -3315,22 +3340,22 @@
                        TypeSymbol c,
                        Name name) {
         Env<AttrContext> env1 = env;
-        boolean staticOnly = false;
+        StaticLevel staticLevel = StaticLevel.INSTANCE;
         while (env1.outer != null) {
-            if (isStatic(env1)) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1));
             if (env1.enclClass.sym == c) {
                 Symbol sym = env1.info.scope.findFirst(name);
                 if (sym != null) {
-                    if (staticOnly) sym = new StaticError(sym);
+                    if (staticLevel != StaticLevel.INSTANCE) sym = new StaticError(sym);
                     return accessBase(sym, pos, env.enclClass.sym.type,
                                   name, true);
                 }
             }
-            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
+            staticLevel = staticLevel.intersect(StaticLevel.from(env1.enclClass.sym));
             env1 = env1.outer;
         }
         if (c.isInterface() &&
-            name == names._super && !isStatic(env) &&
+            name == names._super && StaticLevel.from(env) == StaticLevel.INSTANCE &&
             types.isDirectSuperInterface(c, env.enclClass.sym)) {
             //this might be a default super call if one of the superinterfaces is 'c'
             for (Type t : pruneInterfaces(env.enclClass.type)) {
@@ -3404,19 +3429,18 @@
                                  boolean isSuperCall) {
         Name name = names._this;
         Env<AttrContext> env1 = isSuperCall ? env.outer : env;
-        boolean staticOnly = false;
+        StaticLevel staticLevel = StaticLevel.INSTANCE;
         if (env1 != null) {
             while (env1 != null && env1.outer != null) {
-                if (isStatic(env1)) staticOnly = true;
+                staticLevel = staticLevel.intersect(StaticLevel.from(env1));
                 if (env1.enclClass.sym.isSubClass(member.owner.enclClass(), types)) {
                     Symbol sym = env1.info.scope.findFirst(name);
                     if (sym != null) {
-                        if (staticOnly) sym = new StaticError(sym);
+                        if (staticLevel != StaticLevel.INSTANCE) sym = new StaticError(sym);
                         return sym;
                     }
                 }
-                if ((env1.enclClass.sym.flags() & STATIC) != 0)
-                    staticOnly = true;
+                staticLevel = staticLevel.intersect(StaticLevel.from(env1.enclClass.sym));
                 env1 = env1.outer;
             }
         }
@@ -3996,8 +4020,9 @@
             Symbol errSym = ((sym.kind == TYP && sym.type.hasTag(CLASS))
                 ? types.erasure(sym.type).tsym
                 : sym);
+            String key = sym.isTypeStatic() ? "type-static.cant.be.ref" : "non-static.cant.be.ref";
             return diags.create(dkind, log.currentSource(), pos,
-                    "non-static.cant.be.ref", kindName(sym), errSym);
+                    key, kindName(sym), errSym);
         }
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Fri May 27 14:18:42 2016 +0100
@@ -33,6 +33,7 @@
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument.Kind;
+import com.sun.tools.javac.code.Symbol.MethodHandleSymbol;
 import com.sun.tools.javac.code.Symbol.MethodSymbol;
 import com.sun.tools.javac.code.Symbol.TypeVariableSymbol;
 import com.sun.tools.javac.code.Symbol.VarSymbol;
@@ -93,6 +94,7 @@
 import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.function.ToIntBiFunction;
+import java.util.function.ToIntFunction;
 import java.util.stream.Collectors;
 
 import static com.sun.tools.javac.code.Kinds.Kind.*;
@@ -189,7 +191,7 @@
     }
 
     JCMethodInvocation specializeGenericMethodCallIfNeeded(Symbol msym, JCMethodInvocation tree, List<Type> inferredTypeargs) {
-        JCExpression receiverExpr = null;
+        JCExpression receiverExpr;
         Type receiverType;
         if (!msym.isStatic()) {
             receiverExpr = tree.meth.hasTag(Tag.SELECT) ?
@@ -198,6 +200,9 @@
             receiverType = tree.meth.hasTag(Tag.SELECT) ?
                     ((JCFieldAccess)tree.meth).selected.unerasedType : currentClass.type;
         } else {
+            receiverExpr = tree.meth.hasTag(Tag.SELECT) ?
+                    ((JCFieldAccess)tree.meth).selected :
+                    null;
             receiverType = msym.owner.type;
         }
         return specializeGenericCallIfNeeded(
@@ -302,7 +307,7 @@
 
                 Type mt = uninstantiatedMethodType;
                 Type indyType = types.subst(mt.asMethodType(), formals, instTypes);
-                if (receiverExpr != null) {
+                if (!msym.isStatic() && !msym.isConstructor()) {
                     indyType = types.createMethodTypeWithParameters(indyType,
                             indyType.getParameterTypes().prepend(receiverType));
                     args = args.prepend(receiverExpr);
@@ -320,6 +325,9 @@
                         syms.genericInstanceDispatch;
                 JCMethodInvocation methInv = makeIndyCall(tree, msym.owner, bsmType,
                         names.metafactory, staticArgs, (MethodType)indyType, args, msym.name, msym);
+                if (msym.isStatic() && receiverExpr != null) {
+                    methInv.meth = make.Select(receiverExpr, TreeInfo.symbol(methInv.meth));
+                }
                 methInv.varargsElement = varargsElement;
                 methInv.unerasedType = tree.type;
 
@@ -787,7 +795,9 @@
         //desugar generic method as instance method of the fresh inner class
         MethodSymbol desugaredMethod = msym.clone(genMethodClassSym);
         desugaredMethod.flags_field &= ~Flags.AccessFlags;
-        desugaredMethod.flags_field &= ~Flags.STATIC;
+        if (msym.isStatic()) {
+            desugaredMethod.flags_field |= Flags.SPECIES;
+        }
         desugaredMethod.flags_field |= Flags.PUBLIC; //for now
         desugaredMethod.type = types.subst(msym.type.asMethodType(), oldTypeParams, newTypeParams);
         genMethodClassSym.members_field = WriteableScope.create(genMethodClassSym);
@@ -837,14 +847,21 @@
                         oldTypeParams,
                         oldTypeParams.stream().map(types::erasure).collect(List.collector())).asMethodType();
         JCMethodDecl bridgeDecl = make.MethodDef(bridgeSym, null);
-        JCNewClass newClazz = make.NewClass(null, List.nil(), make.Ident(genMethodClassSym), List.nil(), null);
-        newClazz.constructor = defaultConstr;
-        newClazz.constructorType = defaultConstr.type;
-        newClazz.type = newClazz.clazz.type = types.subst(genMethodClassSym.type,
+        Type recvrType = types.subst(genMethodClassSym.type,
                 newTypeParams,
                 newTypeParams.stream().map(ta -> types.decorateDescriptor(ta, ta)).collect(List.collector()));
-        JCFieldAccess bridgedCall = make.Select(newClazz, bridgeSym.name);
-        bridgedCall.type = types.memberType(newClazz.type, desugaredMethod);
+        JCExpression sel;
+        if (msym.isStatic()) {
+            sel = make.Type(recvrType);
+        } else {
+            JCNewClass newClazz = make.NewClass(null, List.nil(), make.Ident(genMethodClassSym), List.nil(), null);
+            newClazz.constructor = defaultConstr;
+            newClazz.constructorType = defaultConstr.type;
+            newClazz.type = newClazz.clazz.type = recvrType;
+            sel = newClazz;
+        }
+        JCFieldAccess bridgedCall = make.Select(sel, bridgeSym.name);
+        bridgedCall.type = types.memberType(sel.type, desugaredMethod);
         bridgedCall.sym = desugaredMethod;
         List<JCExpression> args = bridgeDecl.params.stream()
                 .map(p -> make.Ident(p.sym)).collect(List.collector());
@@ -1015,7 +1032,7 @@
             Symbol bridgeSym = genericMethodBridgeMap.get(msym);
             if (bridgeSym == null) {
                 bridgeSym = msym.clone(msym.owner);
-                bridgeSym.flags_field |= Flags.SYNTHETIC | Flags.SPECIALIZABLE |
+                bridgeSym.flags_field |= Flags.SYNTHETIC |
                         Flags.GENERIC_METHOD_BRIDGE; //this is a trick to fixup method name when writing the class
                 msym.enclClass().members().enter(bridgeSym);
                 genericMethodBridgeMap.put(msym, bridgeSym);
@@ -1140,21 +1157,21 @@
         GETTER(s -> s.name.toString().contains("$get"),
                 (t, syms) -> new MethodType(List.nil(), t, List.nil(), syms.methodClass),
                 t -> t,
-                (st, s) -> ClassFile.REF_getField),
+                (s) -> ClassFile.REF_getField),
         /** a setter member */
         SETTER(s -> s.name.toString().contains("$set"),
                 (t,syms) -> new MethodType(List.of(t), t, List.nil(), syms.methodClass),
                 t -> t,
-                (st, s) -> ClassFile.REF_putField),
+                (s) -> ClassFile.REF_putField),
         /** a boxing bridge */
-        METHOD(s -> true, (t, syms) -> t, Type::getReturnType, SpecializeTypes::referenceKind);
+        METHOD(s -> true, (t, syms) -> t, Type::getReturnType, s -> ((MethodSymbol)s).asHandle().referenceKind());
 
         final Filter<Symbol> asFilter;
         final BiFunction<Type, Symtab, Type> asType;
         final Function<Type, Type> asInvType;
-        final ToIntBiFunction<SpecializeTypes, Symbol> bsmKind;
+        final ToIntFunction<Symbol> bsmKind;
 
-        VirtualKind(Filter<Symbol> asFilter, BiFunction<Type, Symtab, Type> asType, Function<Type, Type> asInvType, ToIntBiFunction<SpecializeTypes, Symbol> bsmKind) {
+        VirtualKind(Filter<Symbol> asFilter, BiFunction<Type, Symtab, Type> asType, Function<Type, Type> asInvType, ToIntFunction<Symbol> bsmKind) {
             this.asFilter = asFilter;
             this.asType = asType;
             this.asInvType = asInvType;
@@ -1176,7 +1193,7 @@
         List<BootstrapArgument<?>> static_args =
                 List.of(BootstrapArgument.Class((ClassSymbol)sel.selected.type.tsym),
                         BootstrapArgument.String(virtualDesc(site, sel.sym.type)),
-                        BootstrapArgument.Int(vk.bsmKind.applyAsInt(this, sel.sym)));
+                        BootstrapArgument.Int(vk.bsmKind.applyAsInt(sel.sym)));
         for (Type t : site.allparams()) {
             static_args = static_args.append(BootstrapArgument.String(virtualDesc(site, types.skipTypeVars(t, false))));
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java	Fri May 27 14:18:42 2016 +0100
@@ -267,7 +267,7 @@
 
         // Create a bridge method symbol and a bridge definition without a body.
         Type bridgeType = types.decorateDescriptor(origType, meth.type);
-        long flags = impl.flags() & AccessFlags | SPECIALIZABLE | SYNTHETIC | BRIDGE |
+        long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE |
                 (origin.isInterface() ? DEFAULT : 0);
         if (hypothetical) flags |= HYPOTHETICAL;
         MethodSymbol bridge = new MethodSymbol(flags,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri May 27 14:18:42 2016 +0100
@@ -2254,6 +2254,9 @@
  ***********************************************************************/
 
     long adjustFieldFlags(long flags) {
+        if ((flags & ACC_SPECIES) != 0) {
+            flags |= (flags ^ ACC_SPECIES) | STATIC | SPECIES;
+        }
         return flags;
     }
 
@@ -2266,12 +2269,18 @@
             flags &= ~ACC_VARARGS;
             flags |= VARARGS;
         }
+        if ((flags & ACC_SPECIES) != 0) {
+            flags |= (flags ^ ACC_SPECIES) | STATIC | SPECIES;
+        }
         return flags;
     }
 
     long adjustClassFlags(long flags) {
         if ((flags & ACC_VALUE) != 0)
             flags = (flags ^ ACC_VALUE) | VALUE;
+        if ((flags & ACC_SPECIES) != 0) {
+            flags |= (flags ^ ACC_SPECIES) | STATIC | SPECIES;
+        }
         return flags & ~ACC_SUPER; // SUPER and SYNCHRONIZED bits overloaded
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri May 27 14:18:42 2016 +0100
@@ -428,8 +428,8 @@
      */
     int writeBridgeAttr(Symbol s) {
         int alenIdx = writeAttr(names.Bridge);
-        Symbol impl = s.baseSymbol();
-        databuf.appendChar(poolwriter.putSymbol(new MethodHandleSymbol((MethodSymbol)impl)));
+        MethodSymbol impl = (MethodSymbol)s.baseSymbol();
+        databuf.appendChar(poolwriter.putSymbol(impl.asHandle()));
         endAttr(alenIdx);
         return 1;
     }
@@ -467,15 +467,13 @@
                     names.Signature :
                     names.SpecializerSignature;
 
-            if (regularSig || (sym.flags() & SPECIALIZABLE) != 0) {
-                // note that a local class with captured variables
-                // will get a signature attribute
-                int alenIdx = writeAttr(sigName);
+            // note that a local class with captured variables
+            // will get a signature attribute
+            int alenIdx = writeAttr(sigName);
 
-                databuf.appendChar(poolwriter.putConstant(typeSig(sym.type)));
-                endAttr(alenIdx);
-                acount++;
-            }
+            databuf.appendChar(poolwriter.putConstant(typeSig(sym.type)));
+            endAttr(alenIdx);
+            acount++;
         }
 
         if (sym.isConstructor() && sym.enclClass().isInner()) {
@@ -1023,30 +1021,6 @@
             }
         }
 
-    /**
-     * Map bytecodes associated with 'any' type-variables back to their original type signature.
-     * The attribute is structured as a sequence of enttry of the kind (PC,CP_IDX), where PC
-     * denotes a code offset and CP_IDX is a constant pool index pointing to an (String) entry
-     * containing the unerased type-signature associated with PC.
-     */
-    int writeBytecodeMapping(MethodSymbol msym) {
-        if (msym.code == null ||
-                (msym.flags() & (SYNTHETIC | SPECIALIZABLE)) == SYNTHETIC) {
-            return 0;
-        } else {
-            Map<Integer, Name> opcodeMap = msym.code.anyOpcodeMap;
-            if (opcodeMap.isEmpty()) return 0;
-            int alenIdx = writeAttr(names.BytecodeMapping);
-            databuf.appendChar((short)opcodeMap.size());
-            for (Map.Entry<Integer, Name> opcodeEntry : opcodeMap.entrySet()) {
-                databuf.appendChar(opcodeEntry.getKey().shortValue());
-                databuf.appendChar((short)poolwriter.putConstant(opcodeEntry.getValue()));
-            }
-            endAttr(alenIdx);
-            return 1;
-        }
-    }
-
     /** Write field symbol, entering all references into constant poolwriter.
      */
     void writeField(VarSymbol v) {
@@ -1093,7 +1067,6 @@
             writeCode(m.code);
             endAttr(alenIdx);
             acount++;
-            acount += writeBytecodeMapping(m);
             m.code = null; // to conserve space
         }
         if (!foldValueAsReference && m.name == names.vminit) {
@@ -1674,6 +1647,11 @@
         if ((flags & PROTECTED) != 0) flags |= PUBLIC;
         flags = flags & ClassFlags & ~STRICTFP;
 
+        if ((c.flags() & SPECIES) != 0) {
+            //the above line got rid of this...
+            flags |= ACC_SPECIES;
+        }
+
         if ((flags & VALUE) != 0) flags |= ACC_VALUE;
         flags = flags & ~VALUE;
 
@@ -1827,6 +1805,10 @@
             result &= ~ABSTRACT;
         if ((flags & GENERIC_METHOD_BRIDGE) != 0)
             result &= ~SYNTHETIC;
+        if ((flags & SPECIES) != 0) {
+            result &= ~STATIC;
+            result |= ACC_SPECIES;
+        }
         return result;
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri May 27 14:18:42 2016 +0100
@@ -31,6 +31,7 @@
 import java.util.function.Predicate;
 
 import com.sun.tools.javac.code.Types.TypeVarContext;
+import com.sun.tools.javac.comp.Resolve.StaticLevel;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.util.List;
@@ -257,7 +258,7 @@
                     Type mt2 = asExternalType(other.type, types);
                     return dropTypeParameters(types.decorateDescriptor(mt1, mt2), types);
                 case VAR:
-                    return types.decorateDescriptor(types.memberType(types.capture(site), other), other.type);
+                    return types.decorateDescriptor(instType(types), other.type);
                 default:
                     throw new AssertionError("Cant get here!");
             }
@@ -276,13 +277,8 @@
              * Return the instantiated view of this descriptor.
              */
             private Type instType(Types types) {
-                if (!other.isStatic()) {
+                if (!other.isStatic() || other.isTypeStatic()) {
                     return types.memberType(types.capture(site), other);
-                } else if (other.name.toString().startsWith("access$")) {
-                    //patch up accessor symbol
-                    List<Type> from = other.enclClass().type.allparams();
-                    List<Type> to = types.capture(site).allparams();
-                    return types.subst(other.type, from, to);
                 } else {
                     return other.type;
                 }
@@ -325,7 +321,7 @@
                 // JLS 13.1.
                 descSite = sym.enclClass().type;
             } else if (needsInstantiatedSite(site, types) &&
-                    (!sym.isStatic() || (sym.flags() & SPECIALIZABLE) != 0)) {
+                    (!sym.isStatic() || sym.isTypeStatic())) {
                 //keep specialized info
                 descSite = site;
             } else if ((sym.flags() & (STATIC | SYNTHETIC)) == (STATIC | SYNTHETIC)) {
@@ -523,6 +519,8 @@
         ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<>();
         ListBuffer<JCStatement> clinitCode = new ListBuffer<>();
         ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<>();
+        ListBuffer<JCStatement> sclinitCode = new ListBuffer<>();
+        ListBuffer<Attribute.TypeCompound> sclinitTAs = new ListBuffer<>();
         ListBuffer<JCTree> methodDefs = new ListBuffer<>();
         // Sort definitions into three listbuffers:
         //  - initCode for instance initializers
@@ -533,9 +531,11 @@
             switch (def.getTag()) {
             case BLOCK:
                 JCBlock block = (JCBlock)def;
-                if ((block.flags & STATIC) != 0)
+                if ((block.flags & SPECIES) != 0) {
+                    sclinitCode.append(block);
+                } else if ((block.flags & STATIC) != 0) {
                     clinitCode.append(block);
-                else if ((block.flags & SYNTHETIC) == 0)
+                } else if ((block.flags & SYNTHETIC) == 0)
                     initCode.append(block);
                 break;
             case METHODDEF:
@@ -546,7 +546,8 @@
                 VarSymbol sym = vdef.sym;
                 checkDimension(vdef.pos(), sym.type);
                 if (vdef.init != null) {
-                    if ((sym.flags() & STATIC) == 0) {
+                    StaticLevel staticLevel = StaticLevel.from(vdef.sym);
+                    if (staticLevel == StaticLevel.INSTANCE) {
                         // Always initialize instance variables.
                         JCStatement init = make.at(vdef.pos()).
                             Assignment(sym, vdef.init);
@@ -559,8 +560,14 @@
                         JCStatement init = make.at(vdef.pos).
                             Assignment(sym, vdef.init);
                         clinitCode.append(init);
+                        if (staticLevel == StaticLevel.TYPE_STATIC) {
+                            sclinitCode.append(init);
+                        }
                         endPosTable.replaceTree(vdef, init);
                         clinitTAs.addAll(getAndRemoveNonFieldTAs(sym));
+                        if (staticLevel == StaticLevel.TYPE_STATIC) {
+                            sclinitTAs.addAll(getAndRemoveNonFieldTAs(sym));
+                        }
                     } else {
                         checkStringConstant(vdef.init.pos(), sym.getConstValue());
                         /* if the init contains a reference to an external class, add it to the
@@ -604,6 +611,28 @@
             if (!c.getClassInitTypeAttributes().isEmpty())
                 clinit.appendUniqueTypeAttributes(c.getClassInitTypeAttributes());
         }
+
+        // If there are type initializers, create a <sclinit> method
+        // that contains them as its body.
+        if (sclinitCode.length() != 0) {
+            MethodSymbol sclinit = new MethodSymbol(
+                SPECIES | (c.flags() & STRICTFP),
+                names.sclinit,
+                new MethodType(
+                    List.<Type>nil(), syms.voidType,
+                    List.<Type>nil(), syms.methodClass),
+                c);
+            c.members().enter(sclinit);
+            List<JCStatement> sclinitStats = sclinitCode.toList();
+            JCBlock block = make.at(sclinitStats.head.pos()).Block(0, sclinitStats);
+            block.endpos = TreeInfo.endPos(sclinitStats.last());
+            methodDefs.append(make.MethodDef(sclinit, block));
+
+            if (!sclinitTAs.isEmpty())
+                sclinit.appendUniqueTypeAttributes(sclinitTAs.toList());
+            if (!c.getClassInitTypeAttributes().isEmpty())
+                sclinit.appendUniqueTypeAttributes(c.getSpeciesInitTypeAttributes());
+        }
         // Return all method definitions.
         return methodDefs.toList();
     }
@@ -1077,7 +1106,7 @@
                     !meth.enclClass().isStatic()) {
                     extras++;
                 }
-            } else if ((tree.mods.flags & STATIC) == 0) {
+            } else if (!tree.sym.isStatic()) {
                 extras++;
             }
             //      System.err.println("Generating " + meth + " in " + meth.owner); //DEBUG
@@ -1174,7 +1203,7 @@
 
             // If method is not static, create a new local variable address
             // for `this'.
-            if ((tree.mods.flags & STATIC) == 0) {
+            if (!tree.sym.isStatic()) {
                 Type selfType = meth.owner.type;
                 if (meth.isConstructor() && selfType != syms.objectType)
                     selfType = UninitializedType.uninitializedThis(selfType);
@@ -2391,7 +2420,7 @@
             result = items.makeDynamicItem(sym);
         } else if ((sym.flags() & STATIC) != 0) {
             if (!isAccessSuper(env.enclMethod))
-                sym = Descriptor.of(sym, env.enclClass.type, types);
+                sym = Descriptor.of(sym, env.enclClass.sym.type, types);
             result = sym.kind == MTH ?
                     items.makeStaticMethodItem(sym) :
                     items.makeStaticFieldItem(sym);
@@ -2452,6 +2481,9 @@
                 makeImmediateItem(sym.type, ((VarSymbol) sym).getConstValue());
         } else {
             if (isInvokeDynamic(sym)) {
+                if (!selectSuper && (ssym == null || ssym.kind != TYP))
+                    base = base.load();
+                base.drop();
                 result = items.makeDynamicItem(sym);
                 return;
             } else {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Fri May 27 14:18:42 2016 +0100
@@ -926,7 +926,7 @@
         @Override
         boolean isAny() {
             return types.containsSpecializableTvars(ownerType()) &&
-                    (!member.isStatic() || (member.flags() & Flags.SPECIALIZABLE) != 0);
+                    (!member.isStatic() || member.isTypeStatic());
         }
 
         @Override
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Fri May 27 14:18:42 2016 +0100
@@ -287,7 +287,7 @@
         }
         
         private Entry visitDescriptor(Descriptor d) {
-            boolean simpleSite = (d.isStatic() && (d.flags() & Flags.SPECIALIZABLE) == 0);
+            boolean simpleSite = d.isStatic() && !d.isTypeStatic();
             ClassRef cref = simpleSite ?
                     (ClassRef)visit(d.site.tsym, null) :
                     makeClass(d.site);
@@ -297,7 +297,7 @@
         }
         
         private Entry visitDynamicMethod(DynamicMethodSymbol dynSym) {
-            MethodHandle handle = (MethodHandle)makeSymbol(((MethodSymbol)dynSym.bsm).asHandle()); //bsm
+            MethodHandle handle = (MethodHandle)makeSymbol(dynSym.bsm); //bsm
 
             Entry[] staticArgs = Stream.of(dynSym.staticArgs)
                     .map(this::visitStaticIndyArg)
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java	Fri May 27 14:18:42 2016 +0100
@@ -27,6 +27,8 @@
 
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol.BootstrapArgument;
+import com.sun.tools.javac.code.Symbol.MethodHandleSymbol;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
 import com.sun.tools.javac.code.Type.MethodType;
 import com.sun.tools.javac.comp.Resolve;
 import com.sun.tools.javac.jvm.Gen.Descriptor;
@@ -161,7 +163,7 @@
                     syms.methodTypeType)
                     .appendList(constTypes);
 
-            Symbol bsm = rs.resolveInternalMethod(pos,
+            MethodSymbol bsm = rs.resolveInternalMethod(pos,
                     gen.getAttrEnv(),
                     bsmClass,
                     bsmName,
@@ -170,8 +172,7 @@
 
             Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(bsmName,
                     syms.noSymbol,
-                    ClassFile.REF_invokeStatic,
-                    (Symbol.MethodSymbol)bsm,
+                    bsm.asHandle(),
                     indyType,
                     staticArgs.stream().toArray(BootstrapArgument<?>[]::new));
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri May 27 14:18:42 2016 +0100
@@ -31,6 +31,7 @@
 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
 
 import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.code.Flags.Flag;
 import com.sun.tools.javac.parser.Tokens.*;
 import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
 import com.sun.tools.javac.resources.CompilerProperties;
@@ -1353,7 +1354,7 @@
                         }
                         break loop;
                     case LT:
-                        if ((mode & TYPE) == 0 && isUnboundMemberRef()) {
+                        if (isGenericTypeSelector()) {
                             //this is an unbound method reference whose qualifier
                             //is a generic type i.e. A<S>::m
                             int pos1 = token.pos;
@@ -1366,19 +1367,33 @@
                             }
                             accept(GT);
                             t = toP(F.at(pos1).TypeApply(t, args.toList()));
-                            while (token.kind == DOT && !peekToken(CLASS)) {
+                            while (token.kind == DOT &&
+                                    !peekToken(CLASS) &&
+                                    !peekToken(LT) &&
+                                    !peekToken(NEW) &&
+                                    !peekToken(VNEW) &&
+                                    !peekToken(SUPER)) {
+                                int selPos = token.pos;
                                 nextToken();
-                                t = toP(F.at(token.pos).Select(t, ident()));
+                                List<JCAnnotation> tyannos1 = typeAnnotationsOpt();
+                                t = toP(F.at(selPos).Select(t, ident()));
+                                if (tyannos1 != null && tyannos1.nonEmpty()) {
+                                    t = toP(F.at(tyannos1.head.pos).AnnotatedType(tyannos1, t));
+                                }
                                 t = typeArgumentsOpt(t);
                             }
                             t = bracketsOpt(t);
-                            if (token.kind != COLCOL &&
-                                    (token.kind != DOT || !peekToken(CLASS))) {
-                                //method reference or class literal expected here
-                                t = illegal();
+                            if (token.kind == COLCOL || token.kind == DOT) {
+                                mode = EXPR;
+                                return term3Rest(TYPE, t, typeArgs);
+                            } else if (token.kind == LPAREN || token.kind == LT) {
+                                mode = EXPR;
+                                List<JCExpression> typargs1 = null;
+                                if (token.kind == LT) {
+                                    typargs1 = typeArguments(false);
+                                }
+                                t = arguments(typargs1, t);
                             }
-                            mode = EXPR;
-                            return term3Rest(TYPE, t, typeArgs);
                         }
                         break loop;
                     default:
@@ -1518,17 +1533,26 @@
      * matching '&gt;' and see if the subsequent terminal is either '.' or '::'.
      */
     @SuppressWarnings("fallthrough")
-    boolean isUnboundMemberRef() {
+    boolean isGenericTypeSelector() {
         int pos = 0, depth = 0;
         outer: for (Token t = S.token(pos) ; ; t = S.token(++pos)) {
             switch (t.kind) {
                 case IDENTIFIER: case UNDERSCORE: case ANY: case QUES: case EXTENDS: case SUPER:
-                case DOT: case RBRACKET: case LBRACKET: case COMMA:
+                case DOT: case LBRACKET: case COMMA:
                 case BYTE: case SHORT: case INT: case LONG: case FLOAT:
                 case DOUBLE: case BOOLEAN: case CHAR:
                 case MONKEYS_AT:
                     break;
 
+                case RBRACKET:
+                    if (depth == 0) {
+                        TokenKind nextKind = S.token(pos + 1).kind;
+                        if (nextKind == COLCOL || nextKind == DOT) {
+                            return true;
+                        }
+                    }
+                    break;
+
                 case LPAREN:
                     // skip annotation values
                     int nesting = 0;
@@ -1559,10 +1583,10 @@
                     depth--;
                     if (depth == 0) {
                         TokenKind nextKind = S.token(pos + 1).kind;
-                        return
-                            nextKind == TokenKind.DOT ||
-                            nextKind == TokenKind.LBRACKET ||
-                            nextKind == TokenKind.COLCOL;
+                        if (nextKind == TokenKind.DOT ||
+                            nextKind == TokenKind.COLCOL) {
+                            return true;
+                        }
                     }
                     break;
                 default:
@@ -2853,6 +2877,7 @@
             case MONKEYS_AT  : flag = Flags.ANNOTATION; break;
             case DEFAULT     : checkDefaultMethods(); flag = Flags.DEFAULT; break;
             case VALUE       : flag = Flags.VALUE; break;
+            case SPECIES     : flag = Flags.SPECIES; break;
             case ERROR       : flag = 0; nextToken(); break;
             default: break loop;
             }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java	Fri May 27 14:18:42 2016 +0100
@@ -165,6 +165,7 @@
         TRANSIENT("transient"),
         TRY("try"),
         VALUE("__ByValue"),
+        SPECIES("__species"),
         WHEREREF("__WhereRef"),
         WHEREVAL("__WhereVal"),
         VNEW("__Make"),
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri May 27 14:18:42 2016 +0100
@@ -1651,6 +1651,10 @@
     unchecked generic class literal of type {0}
 
 # 0: type
+compiler.warn.unchecked.generic.species.access=\
+    unchecked generic species access of type {0}
+
+# 0: type
 compiler.warn.unchecked.varargs.non.reifiable.type=\
     Possible heap pollution from parameterized vararg type {0}
 
@@ -2109,6 +2113,10 @@
     non-static {0} {1} cannot be referenced from a static context
 
 # 0: symbol kind, 1: symbol
+compiler.err.type-static.cant.be.ref=\
+    type-static {0} {1} cannot be referenced from a static context
+
+# 0: symbol kind, 1: symbol
 compiler.misc.bad.static.method.in.unbound.lookup=\
     unexpected static {0} {1} found in unbound lookup
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Fri May 27 14:18:42 2016 +0100
@@ -70,6 +70,7 @@
     public final Name any;
     public final Name append;
     public final Name clinit;
+    public final Name sclinit;
     public final Name clone;
     public final Name close;
     public final Name compareTo;
@@ -223,6 +224,7 @@
         any = fromString("<any>");
         append = fromString("append");
         clinit = fromString("<clinit>");
+        sclinit = fromString("<sclinit>");
         clone = fromString("clone");
         close = fromString("close");
         compareTo = fromString("compareTo");
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java	Fri May 27 14:18:42 2016 +0100
@@ -58,7 +58,8 @@
     public static final int ACC_ANNOTATION    = 0x2000; // class, inner
     public static final int ACC_VALUEFACTORY  = 0x2000; //                      method
     public static final int ACC_ENUM          = 0x4000; // class, inner, field
-    public static final int ACC_MANDATED      = 0x8000; // class, inner, field, method
+    public static final int ACC_MANDATED      = 0x8000; // method parameters
+    public static final int ACC_SPECIES       = 0x8000; // class, inner, field, method
 
     public static enum Kind { Class, InnerClass, Field, Method}
 
@@ -102,12 +103,12 @@
 
     private static final int[] innerClassModifiers = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
-        ACC_ABSTRACT, ACC_VALUE
+        ACC_ABSTRACT, ACC_VALUE, ACC_SPECIES
     };
 
     private static final int[] innerClassFlags = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER,
-        ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_VALUE
+        ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_VALUE, ACC_SPECIES
     };
 
     public Set<String> getInnerClassModifiers() {
@@ -121,12 +122,12 @@
 
     private static final int[] fieldModifiers = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
-        ACC_VOLATILE, ACC_TRANSIENT
+        ACC_VOLATILE, ACC_TRANSIENT, ACC_SPECIES
     };
 
     private static final int[] fieldFlags = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
-        ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM
+        ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM, ACC_SPECIES
     };
 
     public Set<String> getFieldModifiers() {
@@ -139,13 +140,13 @@
 
     private static final int[] methodModifiers = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
-        ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT
+        ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT, ACC_SPECIES
     };
 
     private static final int[] methodFlags = {
         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
         ACC_SYNCHRONIZED, ACC_BRIDGE, ACC_VARARGS, ACC_NATIVE, ACC_ABSTRACT,
-        ACC_STRICT, ACC_SYNTHETIC, ACC_VALUEFACTORY
+        ACC_STRICT, ACC_SYNTHETIC, ACC_VALUEFACTORY, ACC_SPECIES
     };
 
     public Set<String> getMethodModifiers() {
@@ -210,8 +211,8 @@
                 return "abstract";
             case ACC_STRICT:
                 return "strictfp";
-            case ACC_MANDATED:
-                return "mandated";
+            case ACC_SPECIES:
+                return "species";
             default:
                 return null;
         }
@@ -249,8 +250,8 @@
             return (t == Kind.Method ? "ACC_VALUEFACTORY" : "ACC_ANNOTATION");
         case ACC_ENUM:
             return "ACC_ENUM";
-        case ACC_MANDATED:
-            return "ACC_MANDATED";
+        case ACC_SPECIES:
+            return "ACC_SPECIES";
         default:
             return null;
         }
--- a/src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java	Fri May 27 14:18:42 2016 +0100
@@ -191,6 +191,7 @@
         UNDERSCORE(TokenKind.UNDERSCORE, XERRO),  //  _
         ANY(TokenKind.ANY, XEXPR1|XDECL1|XTERM),  //  "any"
         VALUE(TokenKind.VALUE, XEXPR1|XDECL1|XTERM),  //  "__ByValue"
+        SPECIES_STATIC(TokenKind.SPECIES, XEXPR1|XDECL1|XTERM),  //  "__SpeciesStatic"
         WHEREREF(TokenKind.WHEREREF, XEXPR1|XDECL1|XTERM),  //  "__WhereRef"
         WHEREVAL(TokenKind.WHEREVAL, XEXPR1|XDECL1|XTERM),  //  "__WhereVal"
         VNEW(TokenKind.VNEW, XEXPR1|XDECL1|XTERM),  //  "__Make"
--- a/src/jdk.jshell/share/classes/jdk/jshell/ReplResolve.java	Tue Apr 26 15:48:22 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.jshell;
-
-import com.sun.tools.javac.comp.AttrContext;
-import com.sun.tools.javac.comp.Env;
-import com.sun.tools.javac.comp.Resolve;
-import com.sun.tools.javac.util.Context;
-
-/**
- * Just need access to isStatic
- */
-class ReplResolve extends Resolve {
-
-    ReplResolve(Context context) {
-        super(context);
-    }
-
-    public static boolean isStatic(Env<AttrContext> env) {
-        return Resolve.isStatic(env);
-    }
-}
--- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Fri May 27 14:18:42 2016 +0100
@@ -25,6 +25,9 @@
 
 package jdk.jshell;
 
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.comp.Resolve;
+import com.sun.tools.javac.comp.Resolve.StaticLevel;
 import jdk.jshell.SourceCodeAnalysis.Completeness;
 import com.sun.source.tree.AssignmentTree;
 import com.sun.source.tree.CompilationUnitTree;
@@ -375,8 +378,8 @@
                     break;
                 case ERRONEOUS:
                 case EMPTY_STATEMENT: {
-                    boolean staticOnly = ReplResolve.isStatic(((JavacScope)scope).getEnv());
-                    Predicate<Element> accept = accessibility.and(staticOnly ? STATIC_ONLY : TRUE);
+                    StaticLevel staticLevel = StaticLevel.from(((JavacScope)scope).getEnv());
+                    Predicate<Element> accept = accessibility.and(staticLevel != StaticLevel.INSTANCE ? STATIC_ONLY : TRUE); //todo: fixup type static
                     addScopeElements(at, scope, IDENTITY, accept, smartFilter, result);
 
                     Tree parent = tp.getParentPath().getLeaf();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/TypeInitializer.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.Field;
+import com.sun.tools.classfile.Method;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+
+/*
+ * @test
+ * @bug 8136419
+ * @summary test that type annotations on entities in initializers are emitted to classfile
+ * @modules jdk.jdeps/com.sun.tools.classfile
+ */
+
+public class TypeInitializer extends ClassfileTestHelper {
+    public static void main(String[] args) throws Exception {
+        new InstanceInitializer().run();
+    }
+
+    public void run() throws Exception {
+        expected_tinvisibles = 4;
+        expected_tvisibles = 0;
+
+        ClassFile cf = getClassFile("InstanceInitializer$Test.class");
+        test(cf);
+        for (Field f : cf.fields) {
+            test(cf, f);
+        }
+        for (Method m: cf.methods) {
+            test(cf, m, true);
+        }
+
+        countAnnotations();
+
+        if (errors > 0)
+            throw new Exception(errors + " errors found");
+        System.out.println("PASSED");
+    }
+
+    /*********************** Test class *************************/
+    static class Test {
+        @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
+        @interface T {}
+
+        __species {
+            @T String s = null;
+            Runnable r = () -> new ArrayList<@T String>();
+        }
+        __species @T String s = null;
+        __species Runnable r = () -> new ArrayList<@T String>();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/diags/examples/TypeStaticCantBeRef.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.type-static.cant.be.ref
+public class TypeStaticCantBeRef {
+    __species void m() { }
+
+    static void g() {
+        m();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/diags/examples/UncheckedGenericSpeciesAccess.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.warn.unchecked.generic.species.access
+// options: -Xlint:unchecked
+class UncheckedGenericSpeciesAccess<X> {
+
+    __species X s() { return null; }
+
+    static class Test {
+        void m() {
+            UncheckedGenericSpeciesAccess<String>.s();
+        }
+    }
+}
--- a/test/tools/javac/lambda/TestBootstrapMethodsCount.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/lambda/TestBootstrapMethodsCount.java	Fri May 27 14:18:42 2016 +0100
@@ -190,7 +190,7 @@
             Symbol oldSym = ident.sym;
             if (!oldSym.isConstructor()) {
                 ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
-                        oldSym.owner, REF_invokeStatic, bsm, oldSym.type, new BootstrapArgument[0]);
+                        oldSym.owner, bsm.asHandle(), oldSym.type, new BootstrapArgument[0]);
             }
             return null;
         }
--- a/test/tools/javac/lambda/TestInvokeDynamic.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/lambda/TestInvokeDynamic.java	Fri May 27 14:18:42 2016 +0100
@@ -42,6 +42,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Iterator;
 
 import javax.tools.JavaFileObject;
 
@@ -239,20 +240,21 @@
 
     final String source_template =
                 "import java.lang.invoke.*;\n" +
+                "class Bootstrap {\n" +
+                "   public static CallSite bsm(MethodHandles.Lookup lookup, " +
+                "String name, MethodType methodType #{SARGS}) {\n" +
+                "       return null;\n" +
+                "   }\n" +
+                "}\n" +
                 "class Test {\n" +
                 "   void m() { }\n" +
                 "   void test() {\n" +
                 "      Object o = this; // marker statement \n" +
                 "      m();\n" +
                 "   }\n" +
-                "}\n" +
-                "class Bootstrap {\n" +
-                "   public static CallSite bsm(MethodHandles.Lookup lookup, " +
-                "String name, MethodType methodType #{SARGS}) {\n" +
-                "       return null;\n" +
-                "   }\n" +
                 "}";
 
+
     @Override
     public void doWork() throws IOException {
         ComboTask comboTask = newCompilationTask()
@@ -273,7 +275,9 @@
             fail("Diags found when compiling instance: " + res.compilationInfo());
             return;
         }
-        try (InputStream is = res.get().iterator().next().openInputStream()){
+        Iterator<? extends JavaFileObject> jfoIt = res.get().iterator();
+        jfoIt.next();
+        try (InputStream is = jfoIt.next().openInputStream()){
             ClassFile cf = ClassFile.read(is);
             Method testMethod = null;
             for (Method m : cf.methods) {
@@ -433,7 +437,7 @@
                     staticArgs[i] = new BootstrapArgument<>(saks[i].kind, saks[i].getValue(syms, names, types));
                 }
                 ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
-                        oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
+                        oldSym.owner, bsm.asHandle(), oldSym.type, staticArgs);
             }
             return null;
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesAccessParserTest.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Smoke test for singleton access
+ * @library /tools/javac/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.code
+ *          jdk.compiler/com.sun.tools.javac.comp
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.compiler/com.sun.tools.javac.tree
+ *          jdk.compiler/com.sun.tools.javac.util
+ * @build combo.ComboTestHelper
+ * @run main SpeciesAccessParserTest
+ */
+
+import java.io.IOException;
+
+import combo.ComboInstance;
+import combo.ComboParameter;
+import combo.ComboTask.Result;
+import combo.ComboTestHelper;
+
+public class SpeciesAccessParserTest extends ComboInstance<SpeciesAccessParserTest> {
+
+    enum AccessKind implements ComboParameter {
+        METHOD_ACCESS("#{QUAL}.#{TARGS}m()"),
+        FIELD_ACCESS("#{QUAL}.#{TARGS}f"),
+        SUPER("#{QUAL}.#{TARGS}super"),
+        ERR_CONSTR0("#{QUAL}.#{TARGS}new()"),
+        ERR_CONSTR1("#{QUAL}.#{TARGS}new(X)");
+
+        String referenceTemplate;
+
+        AccessKind(String referenceTemplate) {
+            this.referenceTemplate = referenceTemplate;
+        }
+
+        boolean erroneous(QualifierKind qk, GenericKind gk, SubExprKind sk) {
+            switch (this) {
+                case FIELD_ACCESS:
+                    return gk != GenericKind.NONE &&
+                            (sk == SubExprKind.NONE ||
+                            sk == SubExprKind.POSTINC ||
+                            sk == SubExprKind.POSTDEC ||
+                            qk != QualifierKind.SIMPLE);
+                case SUPER:
+                    return qk != QualifierKind.SIMPLE ||
+                            gk != GenericKind.NONE ||
+                            (sk != SubExprKind.SELECT_FIELD && sk != SubExprKind.SELECT_METHOD);
+                case ERR_CONSTR0:
+                case ERR_CONSTR1:
+                    return true;
+                default: return false;
+            }
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return referenceTemplate;
+        }
+    }
+
+    enum ContextKind implements ComboParameter {
+        ASSIGN("Object s = #{EXPR};"),
+        METHOD("m(#{EXPR}, i);");
+
+        String contextTemplate;
+
+        ContextKind(String contextTemplate) {
+            this.contextTemplate = contextTemplate;
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return contextTemplate;
+        }
+    }
+
+    enum GenericKind implements ComboParameter {
+        NONE(""),
+        ONE("<X>"),
+        TWO("<X,Y>");
+
+        String typeParameters;
+
+        GenericKind(String typeParameters) {
+            this.typeParameters = typeParameters;
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return typeParameters;
+        }
+    }
+
+    enum QualifierKind implements ComboParameter {
+        SIMPLE("A"),
+        ARRAY1("int[]"),
+        ARRAY2("A<G>[][]"),
+        GENERIC1("A<X>"),
+        GENERIC2("A<X, Y>"),
+        GENERIC3("A<? extends X, ? super Y>"),
+        GENERIC4("A<int[], short[][]>"),
+        NESTED_GENERIC1("A<A<X,Y>, A<X,Y>>"),
+        NESTED_GENERIC2("A<A<A<X,Y>,A<X,Y>>, A<A<X,Y>,A<X,Y>>>");
+
+        String qualifier;
+
+        QualifierKind(String qualifier) {
+            this.qualifier = qualifier;
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return qualifier;
+        }
+    }
+
+    enum ExprKind implements ComboParameter {
+        NONE("#{ACC}"),
+        SINGLE_PAREN1("(#{ACC}#{SUBEXPR})"),
+        DOUBLE_PAREN1("((#{ACC}#{SUBEXPR}))");
+
+        String expressionTemplate;
+
+        ExprKind(String expressionTemplate) {
+            this.expressionTemplate = expressionTemplate;
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return expressionTemplate;
+        }
+    }
+
+    enum SubExprKind implements ComboParameter {
+        NONE(""),
+        SELECT_FIELD(".f"),
+        SELECT_METHOD(".f()"),
+        SELECT_NEW(".new Foo()"),
+        POSTINC("++"),
+        POSTDEC("--");
+
+        String subExpression;
+
+        SubExprKind(String subExpression) {
+            this.subExpression = subExpression;
+        }
+
+        @Override
+        public String expand(String optParameter) {
+            return subExpression;
+        }
+    }
+
+    public static void main(String... args) throws Exception {
+        new ComboTestHelper<SpeciesAccessParserTest>()
+                .withDimension("ACC", (x, ref) -> x.ak = ref, AccessKind.values())
+                .withDimension("QUAL", (x, qk) -> x.qk = qk, QualifierKind.values())
+                .withDimension("TARGS", (x, gk) -> x.gk = gk, GenericKind.values())
+                .withDimension("EXPR", (x, ek) -> x.ek = ek, ExprKind.values())
+                .withDimension("SUBEXPR", (x, sk) -> x.sk = sk, SubExprKind.values())
+                .withDimension("CTX", ContextKind.values())
+                .withFilter(SpeciesAccessParserTest::filter)
+                .run(SpeciesAccessParserTest::new);
+    }
+
+    AccessKind ak;
+    QualifierKind qk;
+    GenericKind gk;
+    ExprKind ek;
+    SubExprKind sk;
+
+    String template = "class Test {\n" +
+                      "   void test() {\n" +
+                      "      #{CTX}\n" +
+                      "   }" +
+                      "}";
+
+    @Override
+    public void doWork() throws IOException {
+        check(newCompilationTask()
+                .withSourceFromTemplate(template)
+                .parse());
+    }
+
+    boolean filter() {
+        return sk == SubExprKind.NONE ||
+                ek != ExprKind.NONE;
+    }
+
+    void check(Result<?> res) {
+        boolean expectedError = ak.erroneous(qk, gk, sk) ||
+                qk == QualifierKind.ARRAY1;
+
+        if (res.hasErrors() != expectedError) {
+            fail("invalid diagnostics for source:\n" +
+                res.compilationInfo() +
+                "\nFound error: " + res.hasErrors() +
+                "\nExpected error: " + expectedError);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic01.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,70 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for species static nesting
+ * @compile/fail/ref=SpeciesStatic01.out -XDrawDiagnostics SpeciesStatic01.java
+ */
+class SpeciesStatic01 {
+
+    void m() { }
+    String s;
+
+    static void m_S() { }
+    static String f_S;
+
+    __species void m_SS() { }
+    __species String f_SS;
+
+    class Inner {
+       class InnerInner {
+           void test() {
+               m();
+               m_S();
+               m_SS();
+           }
+       }
+       static class InnerInnerS { }//error
+       __species class InnerInnerSS { } //error
+    }
+
+    static class InnerS {
+       class InnerInner {
+           void test() {
+               m(); //error
+               m_S();
+               m_SS(); //error
+           }
+       }
+       static class InnerInnerS {
+           void test() {
+               m(); //error
+               m_S();
+               m_SS(); //error
+           }
+       }
+       __species class InnerInnerSS {
+            void test() {
+               m(); //error
+               m_S();
+               m_SS(); //error
+           }
+        }
+    }
+
+    __species class InnerSS {
+        class InnerInner {
+            void test() {
+               m(); //error
+               m_S();
+               m_SS();
+            }
+        }
+        static class InnerInnerS { } //error
+        __species class InnerInnerSS {
+            void test() {
+               m(); //error
+               m_S();
+               m_SS();
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic01.out	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,12 @@
+SpeciesStatic01.java:25:15: compiler.err.mod.not.allowed.here: static
+SpeciesStatic01.java:26:18: compiler.err.mod.not.allowed.here: species
+SpeciesStatic01.java:61:16: compiler.err.mod.not.allowed.here: static
+SpeciesStatic01.java:32:16: compiler.err.non-static.cant.be.ref: kindname.method, m()
+SpeciesStatic01.java:34:16: compiler.err.type-static.cant.be.ref: kindname.method, m_SS()
+SpeciesStatic01.java:39:16: compiler.err.non-static.cant.be.ref: kindname.method, m()
+SpeciesStatic01.java:41:16: compiler.err.type-static.cant.be.ref: kindname.method, m_SS()
+SpeciesStatic01.java:46:16: compiler.err.non-static.cant.be.ref: kindname.method, m()
+SpeciesStatic01.java:48:16: compiler.err.type-static.cant.be.ref: kindname.method, m_SS()
+SpeciesStatic01.java:56:16: compiler.err.non-static.cant.be.ref: kindname.method, m()
+SpeciesStatic01.java:64:16: compiler.err.non-static.cant.be.ref: kindname.method, m()
+11 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic02.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @clean .*
+ * @compile SpeciesStatic02.java
+ * @run main SpeciesStatic02
+ */
+public class SpeciesStatic02<any T> {
+
+    static void assertTrue(boolean cond) {
+        if (!cond) {
+            throw new AssertionError();
+        }
+    }
+
+    __species int m() {
+        return SpeciesStatic02<T>.class.hashCode();
+    }
+
+    __species class Bar {
+		int m2() { return m(); }
+    }
+
+	int test() {
+       return new Bar().m2();
+    }
+
+	public static void main(String[] args) {
+       assertTrue(new SpeciesStatic02<int>().test() != new SpeciesStatic02<float>().test());
+       assertTrue(new SpeciesStatic02<String>().test() == new SpeciesStatic02<Integer>().test());
+
+	   assertTrue(new SpeciesStatic02<int>.Bar().m2() != new SpeciesStatic02<float>.Bar().m2());
+       assertTrue(new SpeciesStatic02<String>.Bar().m2() == new SpeciesStatic02<Integer>.Bar().m2());
+
+       assertTrue(new SpeciesStatic02<int>.Bar() { }.m2() != new SpeciesStatic02<float>.Bar() { }.m2());
+       assertTrue(new SpeciesStatic02<String>.Bar() { }.m2() == new SpeciesStatic02<Integer>.Bar() { }.m2());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic03.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,44 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for species static unchecked access
+ * @compile/fail/ref=SpeciesStatic03.out -Werror -Xlint:unchecked -XDrawDiagnostics SpeciesStatic03.java
+ */
+
+public class SpeciesStatic03 {
+    static class S<any X> {
+        __species X m_x(X x) { return x; }
+
+        __species String m_S(String s) { return s; }
+
+        void testAny(X x) {
+            m_x(x); //unchecked
+            m_S(""); //ok
+        }
+
+        __WhereRef(X) void testRef(X x) {
+            m_x(x); //unchecked
+            m_S(""); //ok
+        }
+
+        __WhereVal(X) void testVal(X x) {
+            m_x(x); //ok
+            m_S(""); //ok
+        }
+    }
+
+    <any A, R> void test_mx(A a, R r) {
+        S<Integer>.m_x(1); //unchecked
+        S<String>.m_x(""); //unchecked
+        S<A>.m_x(a); //unchecked
+        S<R>.m_x(r); //unchecked
+        S<int>.m_x(1); //ok
+    }
+
+    <any A, R> void test_mS(A a, R r) {
+        S<Integer>.m_S(""); //ok
+        S<String>.m_S(""); //ok
+        S<A>.m_S(""); //ok
+        S<R>.m_S(""); //ok
+        S<int>.m_S(""); //ok
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic03.out	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,9 @@
+SpeciesStatic03.java:14:13: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<X>
+SpeciesStatic03.java:19:13: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<X>
+SpeciesStatic03.java:30:19: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<java.lang.Integer>
+SpeciesStatic03.java:31:18: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<java.lang.String>
+SpeciesStatic03.java:32:13: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<A>
+SpeciesStatic03.java:33:13: compiler.warn.unchecked.generic.species.access: SpeciesStatic03.S<R>
+- compiler.err.warnings.and.werror
+1 error
+6 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic04.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for species static and forward references
+ * @compile/fail/ref=SpeciesStatic04.out -XDrawDiagnostics SpeciesStatic04.java
+ */
+
+class SpeciesStatic04 {
+    static String s1_S = s_S; //error - forward ref
+    static String s2_S = s_SS; //error - bad static access
+    static String s3_S = s_I; //error - bad static access
+
+    __species String s1_SS = s_S; //ok
+    __species String s2_SS = s_SS; //error - forward ref
+    __species String s3_SS = s_I; //error - bad static access
+
+    String s1_I = s_S; //ok
+    String s2_I = s_SS; //ok
+    String s3_I = s_I; //error - forward ref
+
+	static String s_S;
+    __species String s_SS;
+    String s_I;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic04.out	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,7 @@
+SpeciesStatic04.java:8:26: compiler.err.illegal.forward.ref
+SpeciesStatic04.java:9:26: compiler.err.type-static.cant.be.ref: kindname.variable, s_SS
+SpeciesStatic04.java:10:26: compiler.err.non-static.cant.be.ref: kindname.variable, s_I
+SpeciesStatic04.java:13:30: compiler.err.illegal.forward.ref
+SpeciesStatic04.java:14:30: compiler.err.non-static.cant.be.ref: kindname.variable, s_I
+SpeciesStatic04.java:18:19: compiler.err.illegal.forward.ref
+6 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic05.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary check that species static behave like static w.r.t. 'this', 'super' and overriding
+ * @compile/fail/ref=SpeciesStatic05.out -XDrawDiagnostics SpeciesStatic05.java
+ */
+
+class SpeciesStatic05 {
+    static class Sup {
+        __species void m1() {
+            this.m2();
+        }
+
+        void m2() { }
+    }
+
+    static class Sub extends Sup {
+        void m1() { }
+
+        __species void m2() {
+            super.m2();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic05.out	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,5 @@
+SpeciesStatic05.java:10:13: compiler.err.non-static.cant.be.ref: kindname.variable, this
+SpeciesStatic05.java:17:14: compiler.err.override.meth: (compiler.misc.cant.override: m1(), SpeciesStatic05.Sub, m1(), SpeciesStatic05.Sup), static
+SpeciesStatic05.java:19:24: compiler.err.override.static: (compiler.misc.cant.override: m2(), SpeciesStatic05.Sub, m2(), SpeciesStatic05.Sup)
+SpeciesStatic05.java:20:13: compiler.err.non-static.cant.be.ref: kindname.variable, super
+4 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic06.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,28 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for species static hiding
+ * @compile/fail/ref=SpeciesStatic06.out -XDrawDiagnostics SpeciesStatic06.java
+ */
+
+class SpeciesStatic06 {
+
+    static class Box<any X> { }
+
+    static class Sup<any X> {
+        __species void m(Box<X> foo) { }
+    }
+
+    static class Sub1<any X> extends Sup<X> {
+        __species void m(Box<X> foo) { }
+    }
+
+    static class Sub2<any X> extends Sup<X> {
+        __species
+
+        void m(Box<String> foo) { }
+    }
+
+    static class Sub3<any X> extends Sup<X> {
+        __species void m(Box<int> foo) { }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/SpeciesStatic06.out	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,3 @@
+SpeciesStatic06.java:22:14: compiler.err.name.clash.same.erasure.no.hide: m(SpeciesStatic06.Box<java.lang.String>), SpeciesStatic06.Sub2, m(SpeciesStatic06.Box<X>), SpeciesStatic06.Sup
+SpeciesStatic06.java:26:24: compiler.err.name.clash.same.erasure.no.hide: m(SpeciesStatic06.Box<int>), SpeciesStatic06.Sub3, m(SpeciesStatic06.Box<X>), SpeciesStatic06.Sup
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/separate/Foo.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+class Foo<any X> {
+    __species String s;
+    __species void m() { }
+    __species class Inner { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/speciesstatic/separate/Separate01.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for separate compilation involving species statics
+ *
+ * @compile Foo.java
+ * @compile Separate01.java
+ */
+class Separate01 {
+    void test() {
+        Foo<int>.m();
+        String s = Foo<int>.s;
+        new Foo<int>.Inner();
+    }
+}
--- a/test/tools/javac/valhalla/typespec/items/m3/Opcodes.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/Opcodes.java	Fri May 27 14:18:42 2016 +0100
@@ -51,9 +51,12 @@
     NEW("new"),
     GETFIELD("getfield"),
     PUTFIELD("putfield"),
+    GETSTATIC("getstatic"),
+    PUTSTATIC("putstatic"),
     INVOKEVIRTUAL("invokevirtual"),
     INVOKEINTERFACE("invokeinterface"),
     INVOKESPECIAL("invokespecial"),
+    INVOKESTATIC("invokestatic"),
     INVOKEDYNAMIC("invokedynamic");
 
     String mnemonic;
--- a/test/tools/javac/valhalla/typespec/items/m3/tests/TestArrayLoadAndStore.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestArrayLoadAndStore.java	Fri May 27 14:18:42 2016 +0100
@@ -33,10 +33,10 @@
 
 class TestArrayLoadAndStore {
 
-    @PoolMapping(opcode= Opcodes.ALOAD_2)
+    @PoolMapping(opcode= Opcodes.ALOAD_1)
     @PoolMapping(opcode= Opcodes.AASTORE)
     @PoolMapping(opcode= Opcodes.AALOAD)
-    @PoolMapping(opcode= Opcodes.ASTORE_2)
+    @PoolMapping(opcode= Opcodes.ASTORE_1)
     static <any T> void test(T[] tarr, T t) {
         tarr[0] = t;
         t = tarr[0];
--- a/test/tools/javac/valhalla/typespec/items/m3/tests/TestDup.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestDup.java	Fri May 27 14:18:42 2016 +0100
@@ -37,10 +37,10 @@
 
         T t;
 
-        @PoolMapping(opcode= Opcodes.ALOAD_3)
+        @PoolMapping(opcode= Opcodes.ALOAD_2)
         @PoolMapping(opcode= Opcodes.DUP)
-        @PoolMapping(opcode= Opcodes.ASTORE_2)
         @PoolMapping(opcode= Opcodes.ASTORE_1)
+        @PoolMapping(opcode= Opcodes.ASTORE_0)
         static <any T> void test_dup(T t1, T t2, T t3) {
             t1 = (t2 = t3);
         }
--- a/test/tools/javac/valhalla/typespec/items/m3/tests/TestGeneric2GenericCall.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestGeneric2GenericCall.java	Fri May 27 14:18:42 2016 +0100
@@ -40,11 +40,11 @@
     @PoolMapping(opcode= Opcodes.CHECKCAST, entry = "LTestGeneric2GenericCall$List<Z/_>;")
     static <any Z> List<Z> list(Z z) { return id(new List<Z>()); }
 
-    @PoolMapping(opcode= Opcodes.ALOAD_1)
+    @PoolMapping(opcode= Opcodes.ALOAD_0)
     @PoolMapping(opcode= Opcodes.ARETURN)
     static <any Z> Z id(Z z) { return z; }
 
-    @PoolMapping(opcode= Opcodes.ALOAD_1)
+    @PoolMapping(opcode= Opcodes.ALOAD_0)
     @PoolMapping(opcode= Opcodes.INVOKEDYNAMIC,
                  entry = "id:(Z/Ljava/lang/Object;)Z/Ljava/lang/Object;::{TestGeneric2GenericCall,(Ljava/lang/Object;)Ljava/lang/Object;,Z/_,Z/_}")
     @PoolMapping(opcode= Opcodes.INVOKEDYNAMIC,
--- a/test/tools/javac/valhalla/typespec/items/m3/tests/TestLoadAndStore.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestLoadAndStore.java	Fri May 27 14:18:42 2016 +0100
@@ -33,6 +33,8 @@
 
 class TestLoadAndStore {
 
+    @PoolMapping(opcode= Opcodes.ALOAD_0)
+    @PoolMapping(opcode= Opcodes.ASTORE_0)
     @PoolMapping(opcode= Opcodes.ALOAD_1)
     @PoolMapping(opcode= Opcodes.ASTORE_1)
     @PoolMapping(opcode= Opcodes.ALOAD_2)
@@ -41,8 +43,6 @@
     @PoolMapping(opcode= Opcodes.ASTORE_3)
     @PoolMapping(opcode= Opcodes.ALOAD)
     @PoolMapping(opcode= Opcodes.ASTORE)
-    @PoolMapping(opcode= Opcodes.ALOAD)
-    @PoolMapping(opcode= Opcodes.ASTORE)
     static <any T> void test(T t0, T t1, T t2, T t3, T t4) {
         t0 = t0;
         t1 = t1;
--- a/test/tools/javac/valhalla/typespec/items/m3/tests/TestNonSpecializedGenericCall.java	Tue Apr 26 15:48:22 2016 +0100
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestNonSpecializedGenericCall.java	Fri May 27 14:18:42 2016 +0100
@@ -36,7 +36,7 @@
     static class Box<any T> {
         T t;
 
-        @PoolMapping(opcode = Opcodes.ALOAD_1)
+        @PoolMapping(opcode = Opcodes.ALOAD_0)
         @PoolMapping(opcode = Opcodes.ARETURN)
         static <any Z> Z id(Z z) { return z; }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/typespec/items/m3/tests/TestSpeciesStatic.java	Fri May 27 14:18:42 2016 +0100
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Check that generic pool entries are emitted for certain type-dependent opcodes
+ * @library ../
+ * @build PoolMappingHarness
+ * @run main PoolMappingHarness TestSpeciesStatic.java
+ */
+class TestSpeciesStatic {
+    class Foo<any X> {
+        __species X x;
+
+        @PoolMapping(opcode = Opcodes.PUTFIELD)
+        Foo() { }
+
+        @PoolMapping(opcode = Opcodes.ALOAD_0)
+        @PoolMapping(opcode = Opcodes.ARETURN)
+        __species X m(X x) { return x; }
+    }
+
+    @PoolMapping(opcode = Opcodes.GETSTATIC, entry = "LTestSpeciesStatic$Foo<Z/_>;.x:Z/Ljava/lang/Object;")
+    @PoolMapping(opcode = Opcodes.ASTORE_2)
+    @PoolMapping(opcode = Opcodes.ALOAD_1)
+    @PoolMapping(opcode = Opcodes.INVOKESTATIC, entry = "LTestSpeciesStatic$Foo<Z/_>;.m:(Z/Ljava/lang/Object;)Z/Ljava/lang/Object;")
+    @PoolMapping(opcode = Opcodes.ASTORE_3)
+    <any Z> void testAny(Z z) {
+        Z z1 = Foo<Z>.x;
+        Z z2 = Foo<Z>.m(z);
+    }
+
+    <Z> void testRef(Z z) {
+        Z z1 = Foo<Z>.x;
+        Z z2 = Foo<Z>.m(z);
+    }
+}