src/hotspot/share/oops/constantPool.cpp
changeset 48826 c4d9d1b08e2e
parent 48785 4d1970962ee9
child 49036 bc92debe57e4
equal deleted inserted replaced
48825:ef8a98bc71f8 48826:c4d9d1b08e2e
   605 Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
   605 Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
   606   int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
   606   int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
   607   return symbol_at(signature_index);
   607   return symbol_at(signature_index);
   608 }
   608 }
   609 
   609 
   610 
       
   611 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
   610 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
   612   int i = which;
   611   int i = which;
   613   if (!uncached && cache() != NULL) {
   612   if (!uncached && cache() != NULL) {
   614     if (ConstantPool::is_invokedynamic_index(which)) {
   613     if (ConstantPool::is_invokedynamic_index(which)) {
   615       // Invokedynamic index is index into the constant pool cache
   614       // Invokedynamic index is index into the constant pool cache
   619       return pool_index;
   618       return pool_index;
   620     }
   619     }
   621     // change byte-ordering and go via cache
   620     // change byte-ordering and go via cache
   622     i = remap_instruction_operand_from_cache(which);
   621     i = remap_instruction_operand_from_cache(which);
   623   } else {
   622   } else {
   624     if (tag_at(which).is_invoke_dynamic()) {
   623     if (tag_at(which).is_invoke_dynamic() ||
       
   624         tag_at(which).is_dynamic_constant() ||
       
   625         tag_at(which).is_dynamic_constant_in_error()) {
   625       int pool_index = invoke_dynamic_name_and_type_ref_index_at(which);
   626       int pool_index = invoke_dynamic_name_and_type_ref_index_at(which);
   626       assert(tag_at(pool_index).is_name_and_type(), "");
   627       assert(tag_at(pool_index).is_name_and_type(), "");
   627       return pool_index;
   628       return pool_index;
   628     }
   629     }
   629   }
   630   }
   630   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
   631   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
   631   assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
   632   assert(!tag_at(i).is_invoke_dynamic() &&
       
   633          !tag_at(i).is_dynamic_constant() &&
       
   634          !tag_at(i).is_dynamic_constant_in_error(), "Must be handled above");
   632   jint ref_index = *int_at_addr(i);
   635   jint ref_index = *int_at_addr(i);
   633   return extract_high_short_from_int(ref_index);
   636   return extract_high_short_from_int(ref_index);
   634 }
   637 }
   635 
   638 
   636 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
   639 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
   670   return member_index;
   673   return member_index;
   671 }
   674 }
   672 
   675 
   673 
   676 
   674 void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* k, TRAPS) {
   677 void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* k, TRAPS) {
   675  if (k->is_instance_klass() || k->is_objArray_klass()) {
   678   if (!(k->is_instance_klass() || k->is_objArray_klass())) {
   676     InstanceKlass* holder = this_cp->pool_holder();
   679     return;  // short cut, typeArray klass is always accessible
   677     Klass* elem = k->is_instance_klass() ? k : ObjArrayKlass::cast(k)->bottom_klass();
   680   }
   678 
   681   Klass* holder = this_cp->pool_holder();
   679     // The element type could be a typeArray - we only need the access check if it is
   682   bool fold_type_to_class = true;
   680     // an reference to another class
   683   LinkResolver::check_klass_accessability(holder, k, fold_type_to_class, CHECK);
   681     if (elem->is_instance_klass()) {
       
   682       LinkResolver::check_klass_accessability(holder, elem, CHECK);
       
   683     }
       
   684   }
       
   685 }
   684 }
   686 
   685 
   687 
   686 
   688 int ConstantPool::name_ref_index_at(int which_nt) {
   687 int ConstantPool::name_ref_index_at(int which_nt) {
   689   jint ref_index = name_and_type_at(which_nt);
   688   jint ref_index = name_and_type_at(which_nt);
   767   CLEAR_PENDING_EXCEPTION;
   766   CLEAR_PENDING_EXCEPTION;
   768   ResourceMark rm;
   767   ResourceMark rm;
   769   THROW_MSG(error, message->as_C_string());
   768   THROW_MSG(error, message->as_C_string());
   770 }
   769 }
   771 
   770 
   772 // If resolution for Class, MethodHandle or MethodType fails, save the exception
   771 // If resolution for Class, Dynamic constant, MethodHandle or MethodType fails, save the
   773 // in the resolution error table, so that the same exception is thrown again.
   772 // exception in the resolution error table, so that the same exception is thrown again.
   774 void ConstantPool::save_and_throw_exception(const constantPoolHandle& this_cp, int which,
   773 void ConstantPool::save_and_throw_exception(const constantPoolHandle& this_cp, int which,
   775                                             constantTag tag, TRAPS) {
   774                                             constantTag tag, TRAPS) {
   776   Symbol* error = PENDING_EXCEPTION->klass()->name();
   775   Symbol* error = PENDING_EXCEPTION->klass()->name();
   777 
   776 
   778   int error_tag = tag.error_value();
   777   int error_tag = tag.error_value();
   804     // some other thread put this in error state
   803     // some other thread put this in error state
   805     throw_resolution_error(this_cp, which, CHECK);
   804     throw_resolution_error(this_cp, which, CHECK);
   806   }
   805   }
   807 }
   806 }
   808 
   807 
       
   808 BasicType ConstantPool::basic_type_for_constant_at(int which) {
       
   809   constantTag tag = tag_at(which);
       
   810   if (tag.is_dynamic_constant() ||
       
   811       tag.is_dynamic_constant_in_error()) {
       
   812     // have to look at the signature for this one
       
   813     Symbol* constant_type = uncached_signature_ref_at(which);
       
   814     return FieldType::basic_type(constant_type);
       
   815   }
       
   816   return tag.basic_type();
       
   817 }
       
   818 
   809 // Called to resolve constants in the constant pool and return an oop.
   819 // Called to resolve constants in the constant pool and return an oop.
   810 // Some constant pool entries cache their resolved oop. This is also
   820 // Some constant pool entries cache their resolved oop. This is also
   811 // called to create oops from constants to use in arguments for invokedynamic
   821 // called to create oops from constants to use in arguments for invokedynamic
   812 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp, int index, int cache_index, TRAPS) {
   822 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
       
   823                                            int index, int cache_index,
       
   824                                            bool* status_return, TRAPS) {
   813   oop result_oop = NULL;
   825   oop result_oop = NULL;
   814   Handle throw_exception;
   826   Handle throw_exception;
   815 
   827 
   816   if (cache_index == _possible_index_sentinel) {
   828   if (cache_index == _possible_index_sentinel) {
   817     // It is possible that this constant is one which is cached in the objects.
   829     // It is possible that this constant is one which is cached in the objects.
   818     // We'll do a linear search.  This should be OK because this usage is rare.
   830     // We'll do a linear search.  This should be OK because this usage is rare.
       
   831     // FIXME: If bootstrap specifiers stress this code, consider putting in
       
   832     // a reverse index.  Binary search over a short array should do it.
   819     assert(index > 0, "valid index");
   833     assert(index > 0, "valid index");
   820     cache_index = this_cp->cp_to_object_index(index);
   834     cache_index = this_cp->cp_to_object_index(index);
   821   }
   835   }
   822   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
   836   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
   823   assert(index == _no_index_sentinel || index >= 0, "");
   837   assert(index == _no_index_sentinel || index >= 0, "");
   824 
   838 
   825   if (cache_index >= 0) {
   839   if (cache_index >= 0) {
   826     result_oop = this_cp->resolved_references()->obj_at(cache_index);
   840     result_oop = this_cp->resolved_references()->obj_at(cache_index);
   827     if (result_oop != NULL) {
   841     if (result_oop != NULL) {
       
   842       if (result_oop == Universe::the_null_sentinel()) {
       
   843         DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
       
   844         assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
       
   845         result_oop = NULL;
       
   846       }
       
   847       if (status_return != NULL)  (*status_return) = true;
   828       return result_oop;
   848       return result_oop;
   829       // That was easy...
   849       // That was easy...
   830     }
   850     }
   831     index = this_cp->object_to_cp_index(cache_index);
   851     index = this_cp->object_to_cp_index(cache_index);
   832   }
   852   }
   833 
   853 
   834   jvalue prim_value;  // temp used only in a few cases below
   854   jvalue prim_value;  // temp used only in a few cases below
   835 
   855 
   836   constantTag tag = this_cp->tag_at(index);
   856   constantTag tag = this_cp->tag_at(index);
       
   857 
       
   858   if (status_return != NULL) {
       
   859     // don't trigger resolution if the constant might need it
       
   860     switch (tag.value()) {
       
   861     case JVM_CONSTANT_Class:
       
   862     {
       
   863       CPKlassSlot kslot = this_cp->klass_slot_at(index);
       
   864       int resolved_klass_index = kslot.resolved_klass_index();
       
   865       if (this_cp->resolved_klasses()->at(resolved_klass_index) == NULL) {
       
   866         (*status_return) = false;
       
   867         return NULL;
       
   868       }
       
   869       // the klass is waiting in the CP; go get it
       
   870       break;
       
   871     }
       
   872     case JVM_CONSTANT_String:
       
   873     case JVM_CONSTANT_Integer:
       
   874     case JVM_CONSTANT_Float:
       
   875     case JVM_CONSTANT_Long:
       
   876     case JVM_CONSTANT_Double:
       
   877       // these guys trigger OOM at worst
       
   878       break;
       
   879     default:
       
   880       (*status_return) = false;
       
   881       return NULL;
       
   882     }
       
   883     // from now on there is either success or an OOME
       
   884     (*status_return) = true;
       
   885   }
   837 
   886 
   838   switch (tag.value()) {
   887   switch (tag.value()) {
   839 
   888 
   840   case JVM_CONSTANT_UnresolvedClass:
   889   case JVM_CONSTANT_UnresolvedClass:
   841   case JVM_CONSTANT_UnresolvedClassInError:
   890   case JVM_CONSTANT_UnresolvedClassInError:
   846       // ldc wants the java mirror.
   895       // ldc wants the java mirror.
   847       result_oop = resolved->java_mirror();
   896       result_oop = resolved->java_mirror();
   848       break;
   897       break;
   849     }
   898     }
   850 
   899 
       
   900   case JVM_CONSTANT_Dynamic:
       
   901     {
       
   902       Klass* current_klass  = this_cp->pool_holder();
       
   903       Symbol* constant_name = this_cp->uncached_name_ref_at(index);
       
   904       Symbol* constant_type = this_cp->uncached_signature_ref_at(index);
       
   905 
       
   906       // The initial step in resolving an unresolved symbolic reference to a
       
   907       // dynamically-computed constant is to resolve the symbolic reference to a
       
   908       // method handle which will be the bootstrap method for the dynamically-computed
       
   909       // constant. If resolution of the java.lang.invoke.MethodHandle for the bootstrap
       
   910       // method fails, then a MethodHandleInError is stored at the corresponding
       
   911       // bootstrap method's CP index for the CONSTANT_MethodHandle_info. No need to
       
   912       // set a DynamicConstantInError here since any subsequent use of this
       
   913       // bootstrap method will encounter the resolution of MethodHandleInError.
       
   914       oop bsm_info = this_cp->resolve_bootstrap_specifier_at(index, THREAD);
       
   915       Exceptions::wrap_dynamic_exception(CHECK_NULL);
       
   916       assert(bsm_info != NULL, "");
       
   917       // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_Dynamic.
       
   918       Handle bootstrap_specifier = Handle(THREAD, bsm_info);
       
   919 
       
   920       // Resolve the Dynamically-Computed constant to invoke the BSM in order to obtain the resulting oop.
       
   921       Handle value = SystemDictionary::link_dynamic_constant(current_klass,
       
   922                                                              index,
       
   923                                                              bootstrap_specifier,
       
   924                                                              constant_name,
       
   925                                                              constant_type,
       
   926                                                              THREAD);
       
   927       result_oop = value();
       
   928       Exceptions::wrap_dynamic_exception(THREAD);
       
   929       if (HAS_PENDING_EXCEPTION) {
       
   930         // Resolution failure of the dynamically-computed constant, save_and_throw_exception
       
   931         // will check for a LinkageError and store a DynamicConstantInError.
       
   932         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
       
   933       }
       
   934       BasicType type = FieldType::basic_type(constant_type);
       
   935       if (!is_reference_type(type)) {
       
   936         // Make sure the primitive value is properly boxed.
       
   937         // This is a JDK responsibility.
       
   938         const char* fail = NULL;
       
   939         if (result_oop == NULL) {
       
   940           fail = "null result instead of box";
       
   941         } else if (!is_java_primitive(type)) {
       
   942           // FIXME: support value types via unboxing
       
   943           fail = "can only handle references and primitives";
       
   944         } else if (!java_lang_boxing_object::is_instance(result_oop, type)) {
       
   945           fail = "primitive is not properly boxed";
       
   946         }
       
   947         if (fail != NULL) {
       
   948           // Since this exception is not a LinkageError, throw exception
       
   949           // but do not save a DynamicInError resolution result.
       
   950           // See section 5.4.3 of the VM spec.
       
   951           THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), fail);
       
   952         }
       
   953       }
       
   954       break;
       
   955     }
       
   956 
   851   case JVM_CONSTANT_String:
   957   case JVM_CONSTANT_String:
   852     assert(cache_index != _no_index_sentinel, "should have been set");
   958     assert(cache_index != _no_index_sentinel, "should have been set");
   853     if (this_cp->is_pseudo_string_at(index)) {
   959     if (this_cp->is_pseudo_string_at(index)) {
   854       result_oop = this_cp->pseudo_string_at(index, cache_index);
   960       result_oop = this_cp->pseudo_string_at(index, cache_index);
   855       break;
   961       break;
   856     }
   962     }
   857     result_oop = string_at_impl(this_cp, index, cache_index, CHECK_NULL);
   963     result_oop = string_at_impl(this_cp, index, cache_index, CHECK_NULL);
   858     break;
   964     break;
   859 
   965 
       
   966   case JVM_CONSTANT_DynamicInError:
   860   case JVM_CONSTANT_MethodHandleInError:
   967   case JVM_CONSTANT_MethodHandleInError:
   861   case JVM_CONSTANT_MethodTypeInError:
   968   case JVM_CONSTANT_MethodTypeInError:
   862     {
   969     {
   863       throw_resolution_error(this_cp, index, CHECK_NULL);
   970       throw_resolution_error(this_cp, index, CHECK_NULL);
   864       break;
   971       break;
   955   if (cache_index >= 0) {
  1062   if (cache_index >= 0) {
   956     // Benign race condition:  resolved_references may already be filled in.
  1063     // Benign race condition:  resolved_references may already be filled in.
   957     // The important thing here is that all threads pick up the same result.
  1064     // The important thing here is that all threads pick up the same result.
   958     // It doesn't matter which racing thread wins, as long as only one
  1065     // It doesn't matter which racing thread wins, as long as only one
   959     // result is used by all threads, and all future queries.
  1066     // result is used by all threads, and all future queries.
   960     oop old_result = this_cp->resolved_references()->atomic_compare_exchange_oop(cache_index, result_oop, NULL);
  1067     oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
       
  1068     oop old_result = this_cp->resolved_references()
       
  1069       ->atomic_compare_exchange_oop(cache_index, new_result, NULL);
   961     if (old_result == NULL) {
  1070     if (old_result == NULL) {
   962       return result_oop;  // was installed
  1071       return result_oop;  // was installed
   963     } else {
  1072     } else {
   964       // Return the winning thread's result.  This can be different than
  1073       // Return the winning thread's result.  This can be different than
   965       // the result here for MethodHandles.
  1074       // the result here for MethodHandles.
       
  1075       if (old_result == Universe::the_null_sentinel())
       
  1076         old_result = NULL;
   966       return old_result;
  1077       return old_result;
   967     }
  1078     }
   968   } else {
  1079   } else {
       
  1080     assert(result_oop != Universe::the_null_sentinel(), "");
   969     return result_oop;
  1081     return result_oop;
   970   }
  1082   }
   971 }
  1083 }
   972 
  1084 
   973 oop ConstantPool::uncached_string_at(int which, TRAPS) {
  1085 oop ConstantPool::uncached_string_at(int which, TRAPS) {
   977   return str;
  1089   return str;
   978 }
  1090 }
   979 
  1091 
   980 
  1092 
   981 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
  1093 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
   982   assert(this_cp->tag_at(index).is_invoke_dynamic(), "Corrupted constant pool");
  1094   assert((this_cp->tag_at(index).is_invoke_dynamic() ||
   983 
  1095           this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
   984   Handle bsm;
  1096   Handle bsm;
   985   int argc;
  1097   int argc;
   986   {
  1098   {
   987     // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments
  1099     // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
   988     // The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
  1100     // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments
       
  1101     // In both cases, the bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
   989     // It is accompanied by the optional arguments.
  1102     // It is accompanied by the optional arguments.
   990     int bsm_index = this_cp->invoke_dynamic_bootstrap_method_ref_index_at(index);
  1103     int bsm_index = this_cp->invoke_dynamic_bootstrap_method_ref_index_at(index);
   991     oop bsm_oop = this_cp->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL);
  1104     oop bsm_oop = this_cp->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL);
   992     if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) {
  1105     if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) {
   993       THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle");
  1106       THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle");
   994     }
  1107     }
   995 
  1108 
   996     // Extract the optional static arguments.
  1109     // Extract the optional static arguments.
   997     argc = this_cp->invoke_dynamic_argument_count_at(index);
  1110     argc = this_cp->invoke_dynamic_argument_count_at(index);
   998     if (argc == 0)  return bsm_oop;
  1111 
       
  1112     // if there are no static arguments, return the bsm by itself:
       
  1113     if (argc == 0 && UseBootstrapCallInfo < 2)  return bsm_oop;
   999 
  1114 
  1000     bsm = Handle(THREAD, bsm_oop);
  1115     bsm = Handle(THREAD, bsm_oop);
  1001   }
  1116   }
  1002 
  1117 
       
  1118   // We are going to return an ordered pair of {bsm, info}, using a 2-array.
  1003   objArrayHandle info;
  1119   objArrayHandle info;
  1004   {
  1120   {
  1005     objArrayOop info_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1+argc, CHECK_NULL);
  1121     objArrayOop info_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 2, CHECK_NULL);
  1006     info = objArrayHandle(THREAD, info_oop);
  1122     info = objArrayHandle(THREAD, info_oop);
  1007   }
  1123   }
  1008 
  1124 
  1009   info->obj_at_put(0, bsm());
  1125   info->obj_at_put(0, bsm());
  1010   for (int i = 0; i < argc; i++) {
  1126 
       
  1127   bool use_BSCI;
       
  1128   switch (UseBootstrapCallInfo) {
       
  1129   default: use_BSCI = true;  break;  // stress mode
       
  1130   case 0:  use_BSCI = false; break;  // stress mode
       
  1131   case 1:                            // normal mode
       
  1132     // If we were to support an alternative mode of BSM invocation,
       
  1133     // we'd convert to pull mode here if the BSM could be a candidate
       
  1134     // for that alternative mode.  We can't easily test for things
       
  1135     // like varargs here, but we can get away with approximate testing,
       
  1136     // since the JDK runtime will make up the difference either way.
       
  1137     // For now, exercise the pull-mode path if the BSM is of arity 2,
       
  1138     // or if there is a potential condy loop (see below).
       
  1139     oop mt_oop = java_lang_invoke_MethodHandle::type(bsm());
       
  1140     use_BSCI = (java_lang_invoke_MethodType::ptype_count(mt_oop) == 2);
       
  1141     break;
       
  1142   }
       
  1143 
       
  1144   // Here's a reason to use BSCI even if it wasn't requested:
       
  1145   // If a condy uses a condy argument, we want to avoid infinite
       
  1146   // recursion (condy loops) in the C code.  It's OK in Java,
       
  1147   // because Java has stack overflow checking, so we punt
       
  1148   // potentially cyclic cases from C to Java.
       
  1149   if (!use_BSCI && this_cp->tag_at(index).is_dynamic_constant()) {
       
  1150     bool found_unresolved_condy = false;
       
  1151     for (int i = 0; i < argc; i++) {
       
  1152       int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
       
  1153       if (this_cp->tag_at(arg_index).is_dynamic_constant()) {
       
  1154         // potential recursion point condy -> condy
       
  1155         bool found_it = false;
       
  1156         this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL);
       
  1157         if (!found_it) { found_unresolved_condy = true; break; }
       
  1158       }
       
  1159     }
       
  1160     if (found_unresolved_condy)
       
  1161       use_BSCI = true;
       
  1162   }
       
  1163 
       
  1164   const int SMALL_ARITY = 5;
       
  1165   if (use_BSCI && argc <= SMALL_ARITY && UseBootstrapCallInfo <= 2) {
       
  1166     // If there are only a few arguments, and none of them need linking,
       
  1167     // push them, instead of asking the JDK runtime to turn around and
       
  1168     // pull them, saving a JVM/JDK transition in some simple cases.
       
  1169     bool all_resolved = true;
       
  1170     for (int i = 0; i < argc; i++) {
       
  1171       bool found_it = false;
       
  1172       int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
       
  1173       this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL);
       
  1174       if (!found_it) { all_resolved = false; break; }
       
  1175     }
       
  1176     if (all_resolved)
       
  1177       use_BSCI = false;
       
  1178   }
       
  1179 
       
  1180   if (!use_BSCI) {
       
  1181     // return {bsm, {arg...}}; resolution of arguments is done immediately, before JDK code is called
       
  1182     objArrayOop args_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), argc, CHECK_NULL);
       
  1183     info->obj_at_put(1, args_oop);   // may overwrite with args[0] below
       
  1184     objArrayHandle args(THREAD, args_oop);
       
  1185     copy_bootstrap_arguments_at_impl(this_cp, index, 0, argc, args, 0, true, Handle(), CHECK_NULL);
       
  1186     if (argc == 1) {
       
  1187       // try to discard the singleton array
       
  1188       oop arg_oop = args->obj_at(0);
       
  1189       if (arg_oop != NULL && !arg_oop->is_array()) {
       
  1190         // JVM treats arrays and nulls specially in this position,
       
  1191         // but other things are just single arguments
       
  1192         info->obj_at_put(1, arg_oop);
       
  1193       }
       
  1194     }
       
  1195   } else {
       
  1196     // return {bsm, {arg_count, pool_index}}; JDK code must pull the arguments as needed
       
  1197     typeArrayOop ints_oop = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL);
       
  1198     ints_oop->int_at_put(0, argc);
       
  1199     ints_oop->int_at_put(1, index);
       
  1200     info->obj_at_put(1, ints_oop);
       
  1201   }
       
  1202   return info();
       
  1203 }
       
  1204 
       
  1205 void ConstantPool::copy_bootstrap_arguments_at_impl(const constantPoolHandle& this_cp, int index,
       
  1206                                                     int start_arg, int end_arg,
       
  1207                                                     objArrayHandle info, int pos,
       
  1208                                                     bool must_resolve, Handle if_not_available,
       
  1209                                                     TRAPS) {
       
  1210   int argc;
       
  1211   int limit = pos + end_arg - start_arg;
       
  1212   // checks: index in range [0..this_cp->length),
       
  1213   // tag at index, start..end in range [0..argc],
       
  1214   // info array non-null, pos..limit in [0..info.length]
       
  1215   if ((0 >= index    || index >= this_cp->length())  ||
       
  1216       !(this_cp->tag_at(index).is_invoke_dynamic()    ||
       
  1217         this_cp->tag_at(index).is_dynamic_constant()) ||
       
  1218       (0 > start_arg || start_arg > end_arg) ||
       
  1219       (end_arg > (argc = this_cp->invoke_dynamic_argument_count_at(index))) ||
       
  1220       (0 > pos       || pos > limit)         ||
       
  1221       (info.is_null() || limit > info->length())) {
       
  1222     // An index or something else went wrong; throw an error.
       
  1223     // Since this is an internal API, we don't expect this,
       
  1224     // so we don't bother to craft a nice message.
       
  1225     THROW_MSG(vmSymbols::java_lang_LinkageError(), "bad BSM argument access");
       
  1226   }
       
  1227   // now we can loop safely
       
  1228   int info_i = pos;
       
  1229   for (int i = start_arg; i < end_arg; i++) {
  1011     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
  1230     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
  1012     oop arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK_NULL);
  1231     oop arg_oop;
  1013     info->obj_at_put(1+i, arg_oop);
  1232     if (must_resolve) {
  1014   }
  1233       arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
  1015 
  1234     } else {
  1016   return info();
  1235       bool found_it = false;
       
  1236       arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
       
  1237       if (!found_it)  arg_oop = if_not_available();
       
  1238     }
       
  1239     info->obj_at_put(info_i++, arg_oop);
       
  1240   }
  1017 }
  1241 }
  1018 
  1242 
  1019 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
  1243 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
  1020   // If the string has already been interned, this entry will be non-null
  1244   // If the string has already been interned, this entry will be non-null
  1021   oop str = this_cp->resolved_references()->obj_at(obj_index);
  1245   oop str = this_cp->resolved_references()->obj_at(obj_index);
       
  1246   assert(str != Universe::the_null_sentinel(), "");
  1022   if (str != NULL) return str;
  1247   if (str != NULL) return str;
  1023   Symbol* sym = this_cp->unresolved_string_at(which);
  1248   Symbol* sym = this_cp->unresolved_string_at(which);
  1024   str = StringTable::intern(sym, CHECK_(NULL));
  1249   str = StringTable::intern(sym, CHECK_(NULL));
  1025   this_cp->string_at_put(which, obj_index, str);
  1250   this_cp->string_at_put(which, obj_index, str);
  1026   assert(java_lang_String::is_instance(str), "must be string");
  1251   assert(java_lang_String::is_instance(str), "must be string");
  1195       bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
  1420       bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
  1196       if (match) {
  1421       if (match) {
  1197         return true;
  1422         return true;
  1198       }
  1423       }
  1199     }
  1424     }
       
  1425   } break;
       
  1426 
       
  1427   case JVM_CONSTANT_Dynamic:
       
  1428   {
       
  1429     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
       
  1430     int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
       
  1431     int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
       
  1432     int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
       
  1433     // separate statements and variables because CHECK_false is used
       
  1434     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
       
  1435     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
       
  1436     return (match_entry && match_operand);
  1200   } break;
  1437   } break;
  1201 
  1438 
  1202   case JVM_CONSTANT_InvokeDynamic:
  1439   case JVM_CONSTANT_InvokeDynamic:
  1203   {
  1440   {
  1204     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
  1441     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
  1523     int k1 = from_cp->method_handle_ref_kind_at(from_i);
  1760     int k1 = from_cp->method_handle_ref_kind_at(from_i);
  1524     int k2 = from_cp->method_handle_index_at(from_i);
  1761     int k2 = from_cp->method_handle_index_at(from_i);
  1525     to_cp->method_handle_index_at_put(to_i, k1, k2);
  1762     to_cp->method_handle_index_at_put(to_i, k1, k2);
  1526   } break;
  1763   } break;
  1527 
  1764 
       
  1765   case JVM_CONSTANT_Dynamic:
       
  1766   case JVM_CONSTANT_DynamicInError:
       
  1767   {
       
  1768     int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
       
  1769     int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
       
  1770     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
       
  1771     to_cp->dynamic_constant_at_put(to_i, k1, k2);
       
  1772   } break;
       
  1773 
  1528   case JVM_CONSTANT_InvokeDynamic:
  1774   case JVM_CONSTANT_InvokeDynamic:
  1529   {
  1775   {
  1530     int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
  1776     int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
  1531     int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
  1777     int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
  1532     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
  1778     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
  1784     case JVM_CONSTANT_Methodref:
  2030     case JVM_CONSTANT_Methodref:
  1785     case JVM_CONSTANT_InterfaceMethodref:
  2031     case JVM_CONSTANT_InterfaceMethodref:
  1786     case JVM_CONSTANT_NameAndType:
  2032     case JVM_CONSTANT_NameAndType:
  1787       return 5;
  2033       return 5;
  1788 
  2034 
       
  2035     case JVM_CONSTANT_Dynamic:
       
  2036     case JVM_CONSTANT_DynamicInError:
  1789     case JVM_CONSTANT_InvokeDynamic:
  2037     case JVM_CONSTANT_InvokeDynamic:
  1790       // u1 tag, u2 bsm, u2 nt
  2038       // u1 tag, u2 bsm, u2 nt
  1791       return 5;
  2039       return 5;
  1792 
  2040 
  1793     case JVM_CONSTANT_Long:
  2041     case JVM_CONSTANT_Long:
  1967       case JVM_CONSTANT_MethodTypeInError: {
  2215       case JVM_CONSTANT_MethodTypeInError: {
  1968         *bytes = JVM_CONSTANT_MethodType;
  2216         *bytes = JVM_CONSTANT_MethodType;
  1969         idx1 = method_type_index_at(idx);
  2217         idx1 = method_type_index_at(idx);
  1970         Bytes::put_Java_u2((address) (bytes+1), idx1);
  2218         Bytes::put_Java_u2((address) (bytes+1), idx1);
  1971         DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
  2219         DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
       
  2220         break;
       
  2221       }
       
  2222       case JVM_CONSTANT_Dynamic:
       
  2223       case JVM_CONSTANT_DynamicInError: {
       
  2224         *bytes = tag;
       
  2225         idx1 = extract_low_short_from_int(*int_at_addr(idx));
       
  2226         idx2 = extract_high_short_from_int(*int_at_addr(idx));
       
  2227         assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4");
       
  2228         Bytes::put_Java_u2((address) (bytes+1), idx1);
       
  2229         Bytes::put_Java_u2((address) (bytes+3), idx2);
       
  2230         DBG(printf("JVM_CONSTANT_Dynamic: %hd %hd", idx1, idx2));
  1972         break;
  2231         break;
  1973       }
  2232       }
  1974       case JVM_CONSTANT_InvokeDynamic: {
  2233       case JVM_CONSTANT_InvokeDynamic: {
  1975         *bytes = tag;
  2234         *bytes = tag;
  1976         idx1 = extract_low_short_from_int(*int_at_addr(idx));
  2235         idx1 = extract_low_short_from_int(*int_at_addr(idx));
  2174       break;
  2433       break;
  2175     case JVM_CONSTANT_MethodType :
  2434     case JVM_CONSTANT_MethodType :
  2176     case JVM_CONSTANT_MethodTypeInError :
  2435     case JVM_CONSTANT_MethodTypeInError :
  2177       st->print("signature_index=%d", method_type_index_at(index));
  2436       st->print("signature_index=%d", method_type_index_at(index));
  2178       break;
  2437       break;
       
  2438     case JVM_CONSTANT_Dynamic :
       
  2439     case JVM_CONSTANT_DynamicInError :
       
  2440       {
       
  2441         st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
       
  2442         st->print(" type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
       
  2443         int argc = invoke_dynamic_argument_count_at(index);
       
  2444         if (argc > 0) {
       
  2445           for (int arg_i = 0; arg_i < argc; arg_i++) {
       
  2446             int arg = invoke_dynamic_argument_index_at(index, arg_i);
       
  2447             st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
       
  2448           }
       
  2449           st->print("}");
       
  2450         }
       
  2451       }
       
  2452       break;
  2179     case JVM_CONSTANT_InvokeDynamic :
  2453     case JVM_CONSTANT_InvokeDynamic :
  2180       {
  2454       {
  2181         st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
  2455         st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
  2182         st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
  2456         st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
  2183         int argc = invoke_dynamic_argument_count_at(index);
  2457         int argc = invoke_dynamic_argument_count_at(index);