< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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

@@ -46,43 +46,40 @@
 import javax.lang.model.element.TypeParameterElement;
 import javax.lang.model.element.VariableElement;
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileObject;
 
+import com.sun.tools.javac.code.ClassFinder.BadEnclosingMethodAttr;
+import com.sun.tools.javac.code.Directive.RequiresFlag;
 import com.sun.tools.javac.code.Kinds.Kind;
 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
+import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.code.Type.*;
 import com.sun.tools.javac.comp.Attr;
 import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Env;
 import com.sun.tools.javac.jvm.*;
-import com.sun.tools.javac.jvm.PoolConstant;
 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
 import com.sun.tools.javac.tree.JCTree.Tag;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.DefinedBy.Api;
 import com.sun.tools.javac.util.Name;
 
 import static com.sun.tools.javac.code.Flags.*;
 import static com.sun.tools.javac.code.Kinds.*;
 import static com.sun.tools.javac.code.Kinds.Kind.*;
-import com.sun.tools.javac.code.MissingInfoHandler;
 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
-import com.sun.tools.javac.code.Scope.WriteableScope;
-import com.sun.tools.javac.code.Symbol;
 import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
-import com.sun.tools.javac.code.Type;
 import static com.sun.tools.javac.code.TypeTag.CLASS;
 import static com.sun.tools.javac.code.TypeTag.FORALL;
 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
 import static com.sun.tools.javac.jvm.ByteCodes.iadd;
 import static com.sun.tools.javac.jvm.ByteCodes.ishll;
 import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
 import static com.sun.tools.javac.jvm.ByteCodes.lxor;
 import static com.sun.tools.javac.jvm.ByteCodes.string_add;
-import com.sun.tools.javac.util.Name;
 
 /** Root class for Java symbols. It contains subclasses
  *  for specific sorts of symbols, such as variables, methods and operators,
  *  types, packages. Each subclass is represented as a static inner class
  *  inside Symbol.

@@ -90,11 +87,11 @@
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.
  *  This code and its internal interfaces are subject to change or
  *  deletion without notice.</b>
  */
-public abstract class Symbol extends AnnoConstruct implements PoolConstant, Element {
+public abstract class Symbol extends AnnoConstruct implements Element {
 
     /** The kind of this symbol.
      *  @see Kinds
      */
     public Kind kind;

@@ -285,15 +282,10 @@
         this.completer = Completer.NULL_COMPLETER;
         this.erasure_field = null;
         this.name = name;
     }
 
-    @Override
-    public int poolTag() {
-        throw new AssertionError("Invalid pool entry");
-    }
-
     /** Clone this symbol with new owner.
      *  Legal only for fields and methods.
      */
     public Symbol clone(Symbol newOwner) {
         throw new AssertionError();

@@ -408,10 +400,18 @@
 
     public boolean isEnum() {
         return (flags() & ENUM) != 0;
     }
 
+    public boolean isFinal() {
+        return (flags() & FINAL) != 0;
+    }
+
+    public boolean isEffectivelyFinal() {
+        return (flags() & EFFECTIVELY_FINAL) != 0;
+    }
+
     /** Is this symbol declared (directly or indirectly) local
      *  to a method or variable initializer?
      *  Also includes fields of inner classes which are in
      *  turn local to a method or variable initializer.
      */

@@ -432,14 +432,10 @@
      */
     public boolean isConstructor() {
         return name == name.table.names.init;
     }
 
-    public boolean isDynamic() {
-        return false;
-    }
-
     /** The fully qualified name of this symbol.
      *  This is the same as the symbol's name except for class symbols,
      *  which are handled separately.
      */
     public Name getQualifiedName() {

@@ -831,11 +827,11 @@
             }
             apiComplete();
             for (Symbol sym : members().getSymbols(NON_RECURSIVE)) {
                 sym.apiComplete();
                 if ((sym.flags() & SYNTHETIC) == 0 && sym.owner == this && sym.kind != ERR) {
-                    list = list.prepend(sym);
+                        list = list.prepend(sym);
                 }
             }
             return list;
         }
 

@@ -979,15 +975,10 @@
             super(MDL, 0, name, null, owner);
             Assert.checkNonNull(name);
             this.type = new ModuleType(this);
         }
 
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_Module;
-        }
-
         @Override @DefinedBy(Api.LANGUAGE_MODEL)
         public Name getSimpleName() {
             return Convert.shortName(name);
         }
 

@@ -1150,15 +1141,10 @@
         public WriteableScope members() {
             complete();
             return members_field;
         }
 
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_Package;
-        }
-
         public long flags() {
             complete();
             return flags_field;
         }
 

@@ -1211,20 +1197,10 @@
             metadata = null;
         }
 
     }
 
-    public static class RootPackageSymbol extends PackageSymbol {
-        public final MissingInfoHandler missingInfoHandler;
-
-        public RootPackageSymbol(Name name, Symbol owner, MissingInfoHandler missingInfoHandler) {
-            super(name, owner);
-            this.missingInfoHandler = missingInfoHandler;
-        }
-
-    }
-
     /** A class for class symbols
      */
     public static class ClassSymbol extends TypeSymbol implements TypeElement {
 
         /** a scope for all class members; variables, methods and inner classes

@@ -1255,20 +1231,25 @@
         /** the list of translated local classes (used for generating
          * InnerClasses attribute)
          */
         public List<ClassSymbol> trans_local;
 
+        /** the constant pool of the class
+         */
+        public Pool pool;
+
         /** the annotation metadata attached to this class */
         private AnnotationTypeMetadata annotationTypeMetadata;
 
         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
             super(TYP, flags, name, type, owner);
             this.members_field = null;
             this.fullname = formFullName(name, owner);
             this.flatname = formFlatName(name, owner);
             this.sourcefile = null;
             this.classfile = null;
+            this.pool = null;
             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
         }
 
         public ClassSymbol(long flags, Name name, Symbol owner) {
             this(

@@ -1556,32 +1537,18 @@
          */
         public VarSymbol(long flags, Name name, Type type, Symbol owner) {
             super(VAR, flags, name, type, owner);
         }
 
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_Fieldref;
-        }
-
-        public MethodHandleSymbol asMethodHandle(boolean getter) {
-            return new MethodHandleSymbol(this, getter);
-        }
-
         /** Clone this symbol with new owner.
          */
         public VarSymbol clone(Symbol newOwner) {
             VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
                 @Override
                 public Symbol baseSymbol() {
                     return VarSymbol.this;
                 }
-
-                @Override
-                public Object poolKey(Types types) {
-                    return new Pair<>(newOwner, baseSymbol());
-                }
             };
             v.pos = pos;
             v.adr = adr;
             v.data = data;
 //          System.out.println("clone " + v + " in " + newOwner);//DEBUG

@@ -1590,10 +1557,14 @@
 
         public String toString() {
             return name.toString();
         }
 
+        public boolean isDynamic() {
+            return false;
+        }
+
         public Symbol asMemberOf(Type site, Types types) {
             return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
         }
 
         @DefinedBy(Api.LANGUAGE_MODEL)

@@ -1675,36 +1646,10 @@
         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
             return v.visitVarSymbol(this, p);
         }
     }
 
-    public static class ParamSymbol extends VarSymbol {
-        public ParamSymbol(long flags, Name name, Type type, Symbol owner) {
-            super(flags, name, type, owner);
-        }
-
-        @Override
-        public Name getSimpleName() {
-            if ((flags_field & NAME_FILLED) == 0) {
-                flags_field |= NAME_FILLED;
-                Symbol rootPack = this;
-                while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
-                    rootPack = rootPack.owner;
-                }
-                if (rootPack != null) {
-                    Name inferredName =
-                            ((RootPackageSymbol) rootPack).missingInfoHandler.getParameterName(this);
-                    if (inferredName != null) {
-                        this.name = inferredName;
-                    }
-                }
-            }
-            return super.getSimpleName();
-        }
-
-    }
-
     /** A class for method symbols.
      */
     public static class MethodSymbol extends Symbol implements ExecutableElement {
 
         /** The code of the method. */

@@ -1738,15 +1683,10 @@
             MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
                 @Override
                 public Symbol baseSymbol() {
                     return MethodSymbol.this;
                 }
-
-                @Override
-                public Object poolKey(Types types) {
-                    return new Pair<>(newOwner, baseSymbol());
-                }
             };
             m.code = code;
             return m;
         }
 

@@ -1772,23 +1712,16 @@
                 }
                 return s;
             }
         }
 
-        @Override
-        public int poolTag() {
-            return owner.isInterface() ?
-                    ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref;
-        }
-
-        public boolean isHandle() {
+        public boolean isDynamic() {
             return false;
         }
 
-
-        public MethodHandleSymbol asHandle() {
-            return new MethodHandleSymbol(this);
+        public boolean isOwnerAnInterface() {
+            return (owner.flags_field & INTERFACE) != 0;
         }
 
         /** find a symbol that this (proxy method) symbol implements.
          *  @param    c       The class whose members are searched for
          *                    implementations

@@ -1961,17 +1894,10 @@
 
         public boolean isLambdaMethod() {
             return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD;
         }
 
-        /** override this method to point to the original enclosing method if this method symbol represents a synthetic
-         *  lambda method
-         */
-        public MethodSymbol originalEnclosingMethod() {
-            return this;
-        }
-
         /** The implementation of this (abstract) symbol in class origin;
          *  null if none exists. Synthetic methods are not considered
          *  as possible implementations.
          */
         public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {

@@ -2073,154 +1999,65 @@
 
         @DefinedBy(Api.LANGUAGE_MODEL)
         public List<Type> getThrownTypes() {
             return asType().getThrownTypes();
         }
-    }
-
-    /** A class for invokedynamic method calls.
-     */
-    public static class DynamicMethodSymbol extends MethodSymbol implements Dynamic {
-
-        public LoadableConstant[] staticArgs;
-        public MethodHandleSymbol bsm;
-
-        public DynamicMethodSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, LoadableConstant[] staticArgs) {
-            super(0, name, type, owner);
-            this.bsm = bsm;
-            this.staticArgs = staticArgs;
-        }
 
-        @Override
-        public boolean isDynamic() {
-            return true;
-        }
+        public boolean isIntrinsicsLDC() { return false; }
+    }
 
-        @Override
-        public LoadableConstant[] staticArgs() {
-            return staticArgs;
-        }
+    public static class IntrinsicsLDCMethodSymbol extends MethodSymbol {
+        private Object constant;
 
-        @Override
-        public MethodHandleSymbol bootstrapMethod() {
-            return bsm;
+        public IntrinsicsLDCMethodSymbol(long flags, Name name, Type type, Symbol owner, Object constant) {
+            super(flags, name, type, owner);
+            this.constant = constant;
         }
 
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_InvokeDynamic;
-        }
+        public Object getConstant() { return constant; }
 
         @Override
-        public Type dynamicType() {
-            return type;
-        }
+        public boolean isIntrinsicsLDC() { return true; }
     }
 
-    /** A class for condy.
+    /** A class for invokedynamic method calls.
      */
-    public static class DynamicVarSymbol extends VarSymbol implements Dynamic, LoadableConstant {
-        public LoadableConstant[] staticArgs;
-        public MethodHandleSymbol bsm;
+    public static class DynamicMethodSymbol extends MethodSymbol {
+
+        public Object[] staticArgs;
+        public MethodSymbol bsm;
+        public int bsmKind;
 
-        public DynamicVarSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, LoadableConstant[] staticArgs) {
+        public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
             super(0, name, type, owner);
             this.bsm = bsm;
+            this.bsmKind = bsmKind;
             this.staticArgs = staticArgs;
         }
 
         @Override
         public boolean isDynamic() {
             return true;
         }
-
-        @Override
-        public PoolConstant dynamicType() {
-            return type;
-        }
-
-        @Override
-        public LoadableConstant[] staticArgs() {
-            return staticArgs;
-        }
-
-        @Override
-        public LoadableConstant bootstrapMethod() {
-            return bsm;
-        }
-
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_Dynamic;
-        }
     }
 
-    /** A class for method handles.
+    /** A class for condy.
      */
-    public static class MethodHandleSymbol extends MethodSymbol implements LoadableConstant {
-
-        private Symbol refSym;
-        private boolean getter;
+    public static class DynamicVarSymbol extends VarSymbol {
+        public Object[] staticArgs;
+        public MethodSymbol bsm;
+        public int bsmKind;
 
-        public MethodHandleSymbol(Symbol msym) {
-            this(msym, false);
-        }
-
-        public MethodHandleSymbol(Symbol msym, boolean getter) {
-            super(msym.flags_field, msym.name, msym.type, msym.owner);
-            this.refSym = msym;
-            this.getter = getter;
-        }
-
-        /**
-         * Returns the kind associated with this method handle.
-         */
-        public int referenceKind() {
-            if (refSym.kind == VAR) {
-                return getter ?
-                        refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
-                        refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
-            } else {
-                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;
-                    }
-                }
-            }
-        }
-
-        @Override
-        public int poolTag() {
-            return ClassFile.CONSTANT_MethodHandle;
-        }
-
-        @Override
-        public Object poolKey(Types types) {
-            return new Pair<>(baseSymbol(), referenceKind());
-        }
-
-        @Override
-        public MethodHandleSymbol asHandle() {
-            return this;
-        }
-
-        @Override
-        public Symbol baseSymbol() {
-            return refSym;
+        public DynamicVarSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
+            super(0, name, type, owner);
+            this.bsm = bsm;
+            this.bsmKind = bsmKind;
+            this.staticArgs = staticArgs;
         }
 
-
         @Override
-        public boolean isHandle() {
+        public boolean isDynamic() {
             return true;
         }
     }
 
     /** A class for predefined operators.

@@ -2246,10 +2083,22 @@
             }
             accessCode = AccessCode.from(tag, opcode);
             return accessCode;
         }
 
+        public OperatorSymbol pre(Types types) {
+            Assert.check(opcode > ByteCodes.preMask);
+            return new OperatorSymbol(types.names.empty, type, opcode >> ByteCodes.preShift, owner);
+        }
+
+        public OperatorSymbol post(Types types) {
+            Assert.check(opcode > ByteCodes.preMask);
+            return new OperatorSymbol(types.names.empty,
+                    types.createMethodTypeWithParameters(type, List.of(type.getParameterTypes().head)),
+                    opcode & ByteCodes.preMask, owner);
+        }
+
         /** Access codes for dereferencing, assignment,
          *  and pre/post increment/decrement.
 
          *  All access codes for accesses to the current class are even.
          *  If a member of the superclass should be accessed instead (because
< prev index next >