hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java
changeset 10251 71b8938a2821
parent 9124 f60dee480d49
child 11882 cb4e9c768c67
equal deleted inserted replaced
10250:0794cd144834 10251:71b8938a2821
   210     }
   210     }
   211     return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) };
   211     return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) };
   212   }
   212   }
   213 
   213 
   214   public Symbol getNameRefAt(int which) {
   214   public Symbol getNameRefAt(int which) {
   215     int nameIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[0];
   215     return implGetNameRefAt(which, false);
   216     return getSymbolAt(nameIndex);
   216   }
       
   217 
       
   218   private Symbol implGetNameRefAt(int which, boolean uncached) {
       
   219     int signatureIndex = getNameRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
       
   220     return getSymbolAt(signatureIndex);
   217   }
   221   }
   218 
   222 
   219   public Symbol getSignatureRefAt(int which) {
   223   public Symbol getSignatureRefAt(int which) {
   220     int sigIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[1];
   224     return implGetSignatureRefAt(which, false);
   221     return getSymbolAt(sigIndex);
   225   }
       
   226 
       
   227   private Symbol implGetSignatureRefAt(int which, boolean uncached) {
       
   228     int signatureIndex = getSignatureRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
       
   229     return getSymbolAt(signatureIndex);
       
   230   }
       
   231 
       
   232 
       
   233   private int implNameAndTypeRefIndexAt(int which, boolean uncached) {
       
   234     int i = which;
       
   235     if (!uncached && getCache() != null) {
       
   236       if (ConstantPoolCache.isSecondaryIndex(which)) {
       
   237         // Invokedynamic index.
       
   238         int pool_index = getCache().getMainEntryAt(which).getConstantPoolIndex();
       
   239         pool_index = invokeDynamicNameAndTypeRefIndexAt(pool_index);
       
   240         // assert(tagAt(pool_index).isNameAndType(), "");
       
   241         return pool_index;
       
   242       }
       
   243       // change byte-ordering and go via cache
       
   244       i = remapInstructionOperandFromCache(which);
       
   245     } else {
       
   246       if (getTagAt(which).isInvokeDynamic()) {
       
   247         int pool_index = invokeDynamicNameAndTypeRefIndexAt(which);
       
   248         // assert(tag_at(pool_index).is_name_and_type(), "");
       
   249         return pool_index;
       
   250       }
       
   251     }
       
   252     // assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
       
   253     // assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
       
   254     int ref_index = getIntAt(i);
       
   255     return extractHighShortFromInt(ref_index);
       
   256   }
       
   257 
       
   258   private int remapInstructionOperandFromCache(int operand) {
       
   259     int cpc_index = operand;
       
   260     // DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
       
   261     // assert((int)(u2)cpc_index == cpc_index, "clean u2");
       
   262     int member_index = getCache().getEntryAt(cpc_index).getConstantPoolIndex();
       
   263     return member_index;
       
   264   }
       
   265 
       
   266   int invokeDynamicNameAndTypeRefIndexAt(int which) {
       
   267     // assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool");
       
   268     return extractHighShortFromInt(getIntAt(which));
   222   }
   269   }
   223 
   270 
   224   // returns null, if not resolved.
   271   // returns null, if not resolved.
   225   public Klass getKlassRefAt(int which) {
   272   public Klass getKlassRefAt(int which) {
   226     if( ! getTagAt(which).isKlass()) return null;
   273     if( ! getTagAt(which).isKlass()) return null;
   251     Symbol sig  = getSignatureRefAt(which);
   298     Symbol sig  = getSignatureRefAt(which);
   252     return klass.findField(name, sig);
   299     return klass.findField(name, sig);
   253   }
   300   }
   254 
   301 
   255   public int getNameAndTypeRefIndexAt(int index) {
   302   public int getNameAndTypeRefIndexAt(int index) {
   256     int refIndex = getFieldOrMethodAt(index);
   303     return implNameAndTypeRefIndexAt(index, false);
   257     if (DEBUG) {
       
   258       System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): refIndex = " + refIndex);
       
   259     }
       
   260     int i = extractHighShortFromInt(refIndex);
       
   261     if (DEBUG) {
       
   262       System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): result = " + i);
       
   263     }
       
   264     return i;
       
   265   }
   304   }
   266 
   305 
   267   /** Lookup for entries consisting of (name_index, signature_index) */
   306   /** Lookup for entries consisting of (name_index, signature_index) */
   268   public int getNameRefIndexAt(int index) {
   307   public int getNameRefIndexAt(int index) {
   269     int[] refIndex = getNameAndTypeAt(index);
   308     int[] refIndex = getNameAndTypeAt(index);