langtools/src/share/classes/com/sun/tools/javac/jvm/Pool.java
changeset 14547 86d8d242b0c4
parent 14053 99e71e40b111
child 14949 45f43822bbde
equal deleted inserted replaced
14546:7e2a1569de76 14547:86d8d242b0c4
    93     /** Place an object in the pool, unless it is already there.
    93     /** Place an object in the pool, unless it is already there.
    94      *  If object is a symbol also enter its owner unless the owner is a
    94      *  If object is a symbol also enter its owner unless the owner is a
    95      *  package.  Return the object's index in the pool.
    95      *  package.  Return the object's index in the pool.
    96      */
    96      */
    97     public int put(Object value) {
    97     public int put(Object value) {
    98         if (value instanceof MethodSymbol)
    98         value = makePoolValue(value);
    99             value = new Method((MethodSymbol)value);
       
   100         else if (value instanceof VarSymbol)
       
   101             value = new Variable((VarSymbol)value);
       
   102 //      assert !(value instanceof Type.TypeVar);
    99 //      assert !(value instanceof Type.TypeVar);
   103         Integer index = indices.get(value);
   100         Integer index = indices.get(value);
   104         if (index == null) {
   101         if (index == null) {
   105 //          System.err.println("put " + value + " " + value.getClass());//DEBUG
   102 //          System.err.println("put " + value + " " + value.getClass());//DEBUG
   106             index = pp;
   103             index = pp;
   113             }
   110             }
   114         }
   111         }
   115         return index.intValue();
   112         return index.intValue();
   116     }
   113     }
   117 
   114 
       
   115     Object makePoolValue(Object o) {
       
   116         if (o instanceof DynamicMethodSymbol) {
       
   117             return new DynamicMethod((DynamicMethodSymbol)o);
       
   118         } else if (o instanceof MethodSymbol) {
       
   119             return new Method((MethodSymbol)o);
       
   120         } else if (o instanceof VarSymbol) {
       
   121             return new Variable((VarSymbol)o);
       
   122         } else {
       
   123             return o;
       
   124         }
       
   125     }
       
   126 
   118     /** Return the given object's index in the pool,
   127     /** Return the given object's index in the pool,
   119      *  or -1 if object is not in there.
   128      *  or -1 if object is not in there.
   120      */
   129      */
   121     public int get(Object o) {
   130     public int get(Object o) {
   122         Integer n = indices.get(o);
   131         Integer n = indices.get(o);
   140         public int hashCode() {
   149         public int hashCode() {
   141             return
   150             return
   142                 m.name.hashCode() * 33 +
   151                 m.name.hashCode() * 33 +
   143                 m.owner.hashCode() * 9 +
   152                 m.owner.hashCode() * 9 +
   144                 m.type.hashCode();
   153                 m.type.hashCode();
       
   154         }
       
   155     }
       
   156 
       
   157     static class DynamicMethod extends Method {
       
   158 
       
   159         DynamicMethod(DynamicMethodSymbol m) {
       
   160             super(m);
       
   161         }
       
   162 
       
   163         @Override
       
   164         public boolean equals(Object other) {
       
   165             if (!super.equals(other)) return false;
       
   166             if (!(other instanceof DynamicMethod)) return false;
       
   167             DynamicMethodSymbol dm1 = (DynamicMethodSymbol)m;
       
   168             DynamicMethodSymbol dm2 = (DynamicMethodSymbol)((DynamicMethod)other).m;
       
   169             return dm1.bsm == dm2.bsm &&
       
   170                         dm1.bsmKind == dm2.bsmKind &&
       
   171                         Arrays.equals(dm1.staticArgs, dm2.staticArgs);
       
   172         }
       
   173 
       
   174         @Override
       
   175         public int hashCode() {
       
   176             int hash = super.hashCode();
       
   177             DynamicMethodSymbol dm = (DynamicMethodSymbol)m;
       
   178             hash += dm.bsmKind * 7 +
       
   179                     dm.bsm.hashCode() * 11;
       
   180             for (int i = 0; i < dm.staticArgs.length; i++) {
       
   181                 hash += (dm.staticArgs[i].hashCode() * 23);
       
   182             }
       
   183             return hash;
   145         }
   184         }
   146     }
   185     }
   147 
   186 
   148     static class Variable extends DelegatedSymbol {
   187     static class Variable extends DelegatedSymbol {
   149         VarSymbol v;
   188         VarSymbol v;