< prev index next >

src/share/vm/oops/constantPool.cpp

Print this page




 175 void ConstantPool::remove_unshareable_info() {
 176   // Resolved references are not in the shared archive.
 177   // Save the length for restoration.  It is not necessarily the same length
 178   // as reference_map.length() if invokedynamic is saved.
 179   set_resolved_reference_length(
 180     resolved_references() != NULL ? resolved_references()->length() : 0);
 181   set_resolved_references(NULL);
 182 }
 183 
 184 int ConstantPool::cp_to_object_index(int cp_index) {
 185   // this is harder don't do this so much.
 186   int i = reference_map()->find(cp_index);
 187   // We might not find the index for jsr292 call.
 188   return (i < 0) ? _no_index_sentinel : i;
 189 }
 190 
 191 void ConstantPool::string_at_put(int which, int obj_index, oop str) {
 192   resolved_references()->obj_at_put(obj_index, str);
 193 }
 194 
 195 void ConstantPool::trace_class_resolution(const constantPoolHandle& this_cp, KlassHandle k) {
 196   ResourceMark rm;
 197   int line_number = -1;
 198   const char * source_file = NULL;
 199   if (JavaThread::current()->has_last_Java_frame()) {
 200     // try to identify the method which called this function.
 201     vframeStream vfst(JavaThread::current());
 202     if (!vfst.at_end()) {
 203       line_number = vfst.method()->line_number_from_bci(vfst.bci());
 204       Symbol* s = vfst.method()->method_holder()->source_file_name();
 205       if (s != NULL) {
 206         source_file = s->as_C_string();
 207       }
 208     }
 209   }
 210   if (k() != this_cp->pool_holder()) {
 211     // only print something if the classes are different
 212     if (source_file != NULL) {
 213       log_debug(class, resolve)("%s %s %s:%d",
 214                  this_cp->pool_holder()->external_name(),
 215                  k->external_name(), source_file, line_number);
 216     } else {
 217       log_debug(class, resolve)("%s %s",
 218                  this_cp->pool_holder()->external_name(),
 219                  k->external_name());
 220     }
 221   }
 222 }
 223 
 224 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int which,
 225                                    bool save_resolution_error, TRAPS) {
 226   assert(THREAD->is_Java_thread(), "must be a Java thread");
 227 
 228   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 229   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 230   // the entry and tag is not updated atomicly.


 236   }
 237 
 238   // This tag doesn't change back to unresolved class unless at a safepoint.
 239   if (this_cp->tag_at(which).is_unresolved_klass_in_error()) {
 240     // The original attempt to resolve this constant pool entry failed so find the
 241     // class of the original error and throw another error of the same class
 242     // (JVMS 5.4.3).
 243     // If there is a detail message, pass that detail message to the error.
 244     // The JVMS does not strictly require us to duplicate the same detail message,
 245     // or any internal exception fields such as cause or stacktrace.  But since the
 246     // detail message is often a class name or other literal string, we will repeat it
 247     // if we can find it in the symbol table.
 248     throw_resolution_error(this_cp, which, CHECK_0);
 249     ShouldNotReachHere();
 250   }
 251 
 252   Handle mirror_handle;
 253   Symbol* name = entry.get_symbol();
 254   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 255   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 256   Klass* kk = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
 257   KlassHandle k (THREAD, kk);
 258   if (!HAS_PENDING_EXCEPTION) {
 259     // preserve the resolved klass from unloading
 260     mirror_handle = Handle(THREAD, kk->java_mirror());
 261     // Do access check for klasses
 262     verify_constant_pool_resolve(this_cp, k, THREAD);
 263   }
 264 
 265   // Failed to resolve class. We must record the errors so that subsequent attempts
 266   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 267   if (HAS_PENDING_EXCEPTION) {
 268     if (save_resolution_error) {
 269       save_and_throw_exception(this_cp, which, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 270       // If CHECK_NULL above doesn't return the exception, that means that
 271       // some other thread has beaten us and has resolved the class.
 272       // To preserve old behavior, we return the resolved class.
 273       entry = this_cp->resolved_klass_at(which);
 274       assert(entry.is_resolved(), "must be resolved if exception was cleared");
 275       assert(entry.get_klass()->is_klass(), "must be resolved to a klass");
 276       return entry.get_klass();
 277     } else {
 278       return NULL;  // return the pending exception
 279     }
 280   }
 281 
 282   // Make this class loader depend upon the class loader owning the class reference
 283   ClassLoaderData* this_key = this_cp->pool_holder()->class_loader_data();
 284   this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM
 285 
 286   // logging for class+resolve.
 287   if (log_is_enabled(Debug, class, resolve)){
 288     trace_class_resolution(this_cp, k);
 289   }
 290   this_cp->klass_at_put(which, k());
 291   entry = this_cp->resolved_klass_at(which);
 292   assert(entry.is_resolved() && entry.get_klass()->is_klass(), "must be resolved at this point");
 293   return entry.get_klass();
 294 }
 295 
 296 
 297 // Does not update ConstantPool* - to avoid any exception throwing. Used
 298 // by compiler and exception handling.  Also used to avoid classloads for
 299 // instanceof operations. Returns NULL if the class has not been loaded or
 300 // if the verification of constant pool failed
 301 Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 302   CPSlot entry = this_cp->slot_at(which);
 303   if (entry.is_resolved()) {
 304     assert(entry.get_klass()->is_klass(), "must be");
 305     return entry.get_klass();
 306   } else {
 307     assert(entry.is_unresolved(), "must be either symbol or klass");
 308     Thread *thread = Thread::current();
 309     Symbol* name = entry.get_symbol();
 310     oop loader = this_cp->pool_holder()->class_loader();
 311     oop protection_domain = this_cp->pool_holder()->protection_domain();
 312     Handle h_prot (thread, protection_domain);
 313     Handle h_loader (thread, loader);
 314     Klass* k = SystemDictionary::find(name, h_loader, h_prot, thread);
 315 
 316     if (k != NULL) {
 317       // Make sure that resolving is legal
 318       EXCEPTION_MARK;
 319       KlassHandle klass(THREAD, k);
 320       // return NULL if verification fails
 321       verify_constant_pool_resolve(this_cp, klass, THREAD);
 322       if (HAS_PENDING_EXCEPTION) {
 323         CLEAR_PENDING_EXCEPTION;
 324         return NULL;
 325       }
 326       return klass();
 327     } else {
 328       return k;
 329     }
 330   }
 331 }
 332 
 333 
 334 Klass* ConstantPool::klass_ref_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 335   return klass_at_if_loaded(this_cp, this_cp->klass_ref_index_at(which));
 336 }
 337 
 338 
 339 Method* ConstantPool::method_at_if_loaded(const constantPoolHandle& cpool,
 340                                                    int which) {
 341   if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
 342   int cache_index = decode_cpcache_index(which, true);
 343   if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
 344     // FIXME: should be an assert
 345     log_debug(class, resolve)("bad operand %d in:", which); cpool->print();
 346     return NULL;


 438   if (!uncached && cache() != NULL) {
 439     // change byte-ordering and go via cache
 440     i = remap_instruction_operand_from_cache(which);
 441   }
 442   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 443   jint ref_index = *int_at_addr(i);
 444   return extract_low_short_from_int(ref_index);
 445 }
 446 
 447 
 448 
 449 int ConstantPool::remap_instruction_operand_from_cache(int operand) {
 450   int cpc_index = operand;
 451   DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
 452   assert((int)(u2)cpc_index == cpc_index, "clean u2");
 453   int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
 454   return member_index;
 455 }
 456 
 457 
 458 void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, KlassHandle k, TRAPS) {
 459  if (k->is_instance_klass() || k->is_objArray_klass()) {
 460     instanceKlassHandle holder (THREAD, this_cp->pool_holder());
 461     Klass* elem = k->is_instance_klass() ? k() : ObjArrayKlass::cast(k())->bottom_klass();
 462     KlassHandle element (THREAD, elem);
 463 
 464     // The element type could be a typeArray - we only need the access check if it is
 465     // an reference to another class
 466     if (element->is_instance_klass()) {
 467       LinkResolver::check_klass_accessability(holder, element, CHECK);
 468     }
 469   }
 470 }
 471 
 472 
 473 int ConstantPool::name_ref_index_at(int which_nt) {
 474   jint ref_index = name_and_type_at(which_nt);
 475   return extract_low_short_from_int(ref_index);
 476 }
 477 
 478 
 479 int ConstantPool::signature_ref_index_at(int which_nt) {
 480   jint ref_index = name_and_type_at(which_nt);
 481   return extract_high_short_from_int(ref_index);
 482 }
 483 
 484 
 485 Klass* ConstantPool::klass_ref_at(int which, TRAPS) {
 486   return klass_at(klass_ref_index_at(which), THREAD);
 487 }


 675   case JVM_CONSTANT_MethodHandleInError:
 676   case JVM_CONSTANT_MethodTypeInError:
 677     {
 678       throw_resolution_error(this_cp, index, CHECK_NULL);
 679       break;
 680     }
 681 
 682   case JVM_CONSTANT_MethodHandle:
 683     {
 684       int ref_kind                 = this_cp->method_handle_ref_kind_at(index);
 685       int callee_index             = this_cp->method_handle_klass_index_at(index);
 686       Symbol*  name =      this_cp->method_handle_name_ref_at(index);
 687       Symbol*  signature = this_cp->method_handle_signature_ref_at(index);
 688       constantTag m_tag  = this_cp->tag_at(this_cp->method_handle_index_at(index));
 689       { ResourceMark rm(THREAD);
 690         log_debug(class, resolve)("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
 691                               ref_kind, index, this_cp->method_handle_index_at(index),
 692                               callee_index, name->as_C_string(), signature->as_C_string());
 693       }
 694 
 695       Klass* k = klass_at_impl(this_cp, callee_index, true, CHECK_NULL);
 696       KlassHandle callee(THREAD, k);
 697 
 698       // Check constant pool method consistency
 699       if ((callee->is_interface() && m_tag.is_method()) ||
 700           ((!callee->is_interface() && m_tag.is_interface_method()))) {
 701         ResourceMark rm(THREAD);
 702         char buf[400];
 703         jio_snprintf(buf, sizeof(buf),
 704           "Inconsistent constant pool data in classfile for class %s. "
 705           "Method %s%s at index %d is %s and should be %s",
 706           callee->name()->as_C_string(), name->as_C_string(), signature->as_C_string(), index,
 707           callee->is_interface() ? "CONSTANT_MethodRef" : "CONSTANT_InterfaceMethodRef",
 708           callee->is_interface() ? "CONSTANT_InterfaceMethodRef" : "CONSTANT_MethodRef");
 709         THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 710       }
 711 
 712       KlassHandle klass(THREAD, this_cp->pool_holder());
 713       Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
 714                                                                    callee, name, signature,
 715                                                                    THREAD);
 716       result_oop = value();
 717       if (HAS_PENDING_EXCEPTION) {
 718         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 719       }
 720       break;
 721     }
 722 
 723   case JVM_CONSTANT_MethodType:
 724     {
 725       Symbol*  signature = this_cp->method_type_signature_at(index);
 726       { ResourceMark rm(THREAD);
 727         log_debug(class, resolve)("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
 728                               index, this_cp->method_type_index_at(index),
 729                               signature->as_C_string());
 730       }
 731       KlassHandle klass(THREAD, this_cp->pool_holder());
 732       Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
 733       result_oop = value();
 734       if (HAS_PENDING_EXCEPTION) {
 735         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 736       }
 737       break;
 738     }
 739 
 740   case JVM_CONSTANT_Integer:
 741     assert(cache_index == _no_index_sentinel, "should not have been set");
 742     prim_value.i = this_cp->int_at(index);
 743     result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
 744     break;
 745 
 746   case JVM_CONSTANT_Float:
 747     assert(cache_index == _no_index_sentinel, "should not have been set");
 748     prim_value.f = this_cp->float_at(index);
 749     result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
 750     break;
 751 


 827     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
 828     oop arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK_NULL);
 829     info->obj_at_put(1+i, arg_oop);
 830   }
 831 
 832   return info();
 833 }
 834 
 835 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
 836   // If the string has already been interned, this entry will be non-null
 837   oop str = this_cp->resolved_references()->obj_at(obj_index);
 838   if (str != NULL) return str;
 839   Symbol* sym = this_cp->unresolved_string_at(which);
 840   str = StringTable::intern(sym, CHECK_(NULL));
 841   this_cp->string_at_put(which, obj_index, str);
 842   assert(java_lang_String::is_instance(str), "must be string");
 843   return str;
 844 }
 845 
 846 
 847 bool ConstantPool::klass_name_at_matches(instanceKlassHandle k,
 848                                                 int which) {
 849   // Names are interned, so we can compare Symbol*s directly
 850   Symbol* cp_name = klass_name_at(which);
 851   return (cp_name == k->name());
 852 }
 853 
 854 
 855 // Iterate over symbols and decrement ones which are Symbol*s
 856 // This is done during GC.
 857 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
 858 // these symbols but didn't increment the reference count.
 859 void ConstantPool::unreference_symbols() {
 860   for (int index = 1; index < length(); index++) { // Index 0 is unused
 861     constantTag tag = tag_at(index);
 862     if (tag.is_symbol()) {
 863       symbol_at(index)->decrement_refcount();
 864     }
 865   }
 866 }
 867 
 868 




 175 void ConstantPool::remove_unshareable_info() {
 176   // Resolved references are not in the shared archive.
 177   // Save the length for restoration.  It is not necessarily the same length
 178   // as reference_map.length() if invokedynamic is saved.
 179   set_resolved_reference_length(
 180     resolved_references() != NULL ? resolved_references()->length() : 0);
 181   set_resolved_references(NULL);
 182 }
 183 
 184 int ConstantPool::cp_to_object_index(int cp_index) {
 185   // this is harder don't do this so much.
 186   int i = reference_map()->find(cp_index);
 187   // We might not find the index for jsr292 call.
 188   return (i < 0) ? _no_index_sentinel : i;
 189 }
 190 
 191 void ConstantPool::string_at_put(int which, int obj_index, oop str) {
 192   resolved_references()->obj_at_put(obj_index, str);
 193 }
 194 
 195 void ConstantPool::trace_class_resolution(const constantPoolHandle& this_cp, Klass* k) {
 196   ResourceMark rm;
 197   int line_number = -1;
 198   const char * source_file = NULL;
 199   if (JavaThread::current()->has_last_Java_frame()) {
 200     // try to identify the method which called this function.
 201     vframeStream vfst(JavaThread::current());
 202     if (!vfst.at_end()) {
 203       line_number = vfst.method()->line_number_from_bci(vfst.bci());
 204       Symbol* s = vfst.method()->method_holder()->source_file_name();
 205       if (s != NULL) {
 206         source_file = s->as_C_string();
 207       }
 208     }
 209   }
 210   if (k != this_cp->pool_holder()) {
 211     // only print something if the classes are different
 212     if (source_file != NULL) {
 213       log_debug(class, resolve)("%s %s %s:%d",
 214                  this_cp->pool_holder()->external_name(),
 215                  k->external_name(), source_file, line_number);
 216     } else {
 217       log_debug(class, resolve)("%s %s",
 218                  this_cp->pool_holder()->external_name(),
 219                  k->external_name());
 220     }
 221   }
 222 }
 223 
 224 Klass* ConstantPool::klass_at_impl(const constantPoolHandle& this_cp, int which,
 225                                    bool save_resolution_error, TRAPS) {
 226   assert(THREAD->is_Java_thread(), "must be a Java thread");
 227 
 228   // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
 229   // It is not safe to rely on the tag bit's here, since we don't have a lock, and
 230   // the entry and tag is not updated atomicly.


 236   }
 237 
 238   // This tag doesn't change back to unresolved class unless at a safepoint.
 239   if (this_cp->tag_at(which).is_unresolved_klass_in_error()) {
 240     // The original attempt to resolve this constant pool entry failed so find the
 241     // class of the original error and throw another error of the same class
 242     // (JVMS 5.4.3).
 243     // If there is a detail message, pass that detail message to the error.
 244     // The JVMS does not strictly require us to duplicate the same detail message,
 245     // or any internal exception fields such as cause or stacktrace.  But since the
 246     // detail message is often a class name or other literal string, we will repeat it
 247     // if we can find it in the symbol table.
 248     throw_resolution_error(this_cp, which, CHECK_0);
 249     ShouldNotReachHere();
 250   }
 251 
 252   Handle mirror_handle;
 253   Symbol* name = entry.get_symbol();
 254   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
 255   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
 256   Klass* k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);

 257   if (!HAS_PENDING_EXCEPTION) {
 258     // preserve the resolved klass from unloading
 259     mirror_handle = Handle(THREAD, k->java_mirror());
 260     // Do access check for klasses
 261     verify_constant_pool_resolve(this_cp, k, THREAD);
 262   }
 263 
 264   // Failed to resolve class. We must record the errors so that subsequent attempts
 265   // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
 266   if (HAS_PENDING_EXCEPTION) {
 267     if (save_resolution_error) {
 268       save_and_throw_exception(this_cp, which, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_NULL);
 269       // If CHECK_NULL above doesn't return the exception, that means that
 270       // some other thread has beaten us and has resolved the class.
 271       // To preserve old behavior, we return the resolved class.
 272       entry = this_cp->resolved_klass_at(which);
 273       assert(entry.is_resolved(), "must be resolved if exception was cleared");
 274       assert(entry.get_klass()->is_klass(), "must be resolved to a klass");
 275       return entry.get_klass();
 276     } else {
 277       return NULL;  // return the pending exception
 278     }
 279   }
 280 
 281   // Make this class loader depend upon the class loader owning the class reference
 282   ClassLoaderData* this_key = this_cp->pool_holder()->class_loader_data();
 283   this_key->record_dependency(k, CHECK_NULL); // Can throw OOM
 284 
 285   // logging for class+resolve.
 286   if (log_is_enabled(Debug, class, resolve)){
 287     trace_class_resolution(this_cp, k);
 288   }
 289   this_cp->klass_at_put(which, k);
 290   entry = this_cp->resolved_klass_at(which);
 291   assert(entry.is_resolved() && entry.get_klass()->is_klass(), "must be resolved at this point");
 292   return entry.get_klass();
 293 }
 294 
 295 
 296 // Does not update ConstantPool* - to avoid any exception throwing. Used
 297 // by compiler and exception handling.  Also used to avoid classloads for
 298 // instanceof operations. Returns NULL if the class has not been loaded or
 299 // if the verification of constant pool failed
 300 Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 301   CPSlot entry = this_cp->slot_at(which);
 302   if (entry.is_resolved()) {
 303     assert(entry.get_klass()->is_klass(), "must be");
 304     return entry.get_klass();
 305   } else {
 306     assert(entry.is_unresolved(), "must be either symbol or klass");
 307     Thread *thread = Thread::current();
 308     Symbol* name = entry.get_symbol();
 309     oop loader = this_cp->pool_holder()->class_loader();
 310     oop protection_domain = this_cp->pool_holder()->protection_domain();
 311     Handle h_prot (thread, protection_domain);
 312     Handle h_loader (thread, loader);
 313     Klass* k = SystemDictionary::find(name, h_loader, h_prot, thread);
 314 
 315     if (k != NULL) {
 316       // Make sure that resolving is legal
 317       EXCEPTION_MARK;

 318       // return NULL if verification fails
 319       verify_constant_pool_resolve(this_cp, k, THREAD);
 320       if (HAS_PENDING_EXCEPTION) {
 321         CLEAR_PENDING_EXCEPTION;
 322         return NULL;
 323       }
 324       return k;
 325     } else {
 326       return k;
 327     }
 328   }
 329 }
 330 
 331 
 332 Klass* ConstantPool::klass_ref_at_if_loaded(const constantPoolHandle& this_cp, int which) {
 333   return klass_at_if_loaded(this_cp, this_cp->klass_ref_index_at(which));
 334 }
 335 
 336 
 337 Method* ConstantPool::method_at_if_loaded(const constantPoolHandle& cpool,
 338                                                    int which) {
 339   if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
 340   int cache_index = decode_cpcache_index(which, true);
 341   if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
 342     // FIXME: should be an assert
 343     log_debug(class, resolve)("bad operand %d in:", which); cpool->print();
 344     return NULL;


 436   if (!uncached && cache() != NULL) {
 437     // change byte-ordering and go via cache
 438     i = remap_instruction_operand_from_cache(which);
 439   }
 440   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 441   jint ref_index = *int_at_addr(i);
 442   return extract_low_short_from_int(ref_index);
 443 }
 444 
 445 
 446 
 447 int ConstantPool::remap_instruction_operand_from_cache(int operand) {
 448   int cpc_index = operand;
 449   DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
 450   assert((int)(u2)cpc_index == cpc_index, "clean u2");
 451   int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
 452   return member_index;
 453 }
 454 
 455 
 456 void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* k, TRAPS) {
 457  if (k->is_instance_klass() || k->is_objArray_klass()) {
 458     InstanceKlass* holder = this_cp->pool_holder();
 459     Klass* elem = k->is_instance_klass() ? k : ObjArrayKlass::cast(k)->bottom_klass();

 460 
 461     // The element type could be a typeArray - we only need the access check if it is
 462     // an reference to another class
 463     if (elem->is_instance_klass()) {
 464       LinkResolver::check_klass_accessability(holder, elem, CHECK);
 465     }
 466   }
 467 }
 468 
 469 
 470 int ConstantPool::name_ref_index_at(int which_nt) {
 471   jint ref_index = name_and_type_at(which_nt);
 472   return extract_low_short_from_int(ref_index);
 473 }
 474 
 475 
 476 int ConstantPool::signature_ref_index_at(int which_nt) {
 477   jint ref_index = name_and_type_at(which_nt);
 478   return extract_high_short_from_int(ref_index);
 479 }
 480 
 481 
 482 Klass* ConstantPool::klass_ref_at(int which, TRAPS) {
 483   return klass_at(klass_ref_index_at(which), THREAD);
 484 }


 672   case JVM_CONSTANT_MethodHandleInError:
 673   case JVM_CONSTANT_MethodTypeInError:
 674     {
 675       throw_resolution_error(this_cp, index, CHECK_NULL);
 676       break;
 677     }
 678 
 679   case JVM_CONSTANT_MethodHandle:
 680     {
 681       int ref_kind                 = this_cp->method_handle_ref_kind_at(index);
 682       int callee_index             = this_cp->method_handle_klass_index_at(index);
 683       Symbol*  name =      this_cp->method_handle_name_ref_at(index);
 684       Symbol*  signature = this_cp->method_handle_signature_ref_at(index);
 685       constantTag m_tag  = this_cp->tag_at(this_cp->method_handle_index_at(index));
 686       { ResourceMark rm(THREAD);
 687         log_debug(class, resolve)("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
 688                               ref_kind, index, this_cp->method_handle_index_at(index),
 689                               callee_index, name->as_C_string(), signature->as_C_string());
 690       }
 691 
 692       Klass* callee = klass_at_impl(this_cp, callee_index, true, CHECK_NULL);

 693 
 694       // Check constant pool method consistency
 695       if ((callee->is_interface() && m_tag.is_method()) ||
 696           ((!callee->is_interface() && m_tag.is_interface_method()))) {
 697         ResourceMark rm(THREAD);
 698         char buf[400];
 699         jio_snprintf(buf, sizeof(buf),
 700           "Inconsistent constant pool data in classfile for class %s. "
 701           "Method %s%s at index %d is %s and should be %s",
 702           callee->name()->as_C_string(), name->as_C_string(), signature->as_C_string(), index,
 703           callee->is_interface() ? "CONSTANT_MethodRef" : "CONSTANT_InterfaceMethodRef",
 704           callee->is_interface() ? "CONSTANT_InterfaceMethodRef" : "CONSTANT_MethodRef");
 705         THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 706       }
 707 
 708       Klass* klass = this_cp->pool_holder();
 709       Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
 710                                                                    callee, name, signature,
 711                                                                    THREAD);
 712       result_oop = value();
 713       if (HAS_PENDING_EXCEPTION) {
 714         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 715       }
 716       break;
 717     }
 718 
 719   case JVM_CONSTANT_MethodType:
 720     {
 721       Symbol*  signature = this_cp->method_type_signature_at(index);
 722       { ResourceMark rm(THREAD);
 723         log_debug(class, resolve)("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
 724                               index, this_cp->method_type_index_at(index),
 725                               signature->as_C_string());
 726       }
 727       Klass* klass = this_cp->pool_holder();
 728       Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
 729       result_oop = value();
 730       if (HAS_PENDING_EXCEPTION) {
 731         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 732       }
 733       break;
 734     }
 735 
 736   case JVM_CONSTANT_Integer:
 737     assert(cache_index == _no_index_sentinel, "should not have been set");
 738     prim_value.i = this_cp->int_at(index);
 739     result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
 740     break;
 741 
 742   case JVM_CONSTANT_Float:
 743     assert(cache_index == _no_index_sentinel, "should not have been set");
 744     prim_value.f = this_cp->float_at(index);
 745     result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
 746     break;
 747 


 823     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
 824     oop arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK_NULL);
 825     info->obj_at_put(1+i, arg_oop);
 826   }
 827 
 828   return info();
 829 }
 830 
 831 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
 832   // If the string has already been interned, this entry will be non-null
 833   oop str = this_cp->resolved_references()->obj_at(obj_index);
 834   if (str != NULL) return str;
 835   Symbol* sym = this_cp->unresolved_string_at(which);
 836   str = StringTable::intern(sym, CHECK_(NULL));
 837   this_cp->string_at_put(which, obj_index, str);
 838   assert(java_lang_String::is_instance(str), "must be string");
 839   return str;
 840 }
 841 
 842 
 843 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {

 844   // Names are interned, so we can compare Symbol*s directly
 845   Symbol* cp_name = klass_name_at(which);
 846   return (cp_name == k->name());
 847 }
 848 
 849 
 850 // Iterate over symbols and decrement ones which are Symbol*s
 851 // This is done during GC.
 852 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
 853 // these symbols but didn't increment the reference count.
 854 void ConstantPool::unreference_symbols() {
 855   for (int index = 1; index < length(); index++) { // Index 0 is unused
 856     constantTag tag = tag_at(index);
 857     if (tag.is_symbol()) {
 858       symbol_at(index)->decrement_refcount();
 859     }
 860   }
 861 }
 862 
 863 


< prev index next >