< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page
rev 52749 : Bootstrap method consolidation
* clean up and simplify JDK support code for BSM invocation
* simplify JVM bootstrap handshake: use BootstrapCallInfo only
* remove unused JVM paths and data fields
* move bootstrap argument processing from MethodHandleNatives to ConstantPool
* remove ConstantGroup; merge argument access into BootstrapCallInfo
* adjust BSM argument access: remove copyArguments, add argumentRef API
* add metadata-free BSM modes, including symbolic arguments from CP


 571   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 572   return e->method_if_resolved(cpool);
 573 }
 574 
 575 
 576 bool ConstantPool::has_appendix_at_if_loaded(const constantPoolHandle& cpool, int which) {
 577   if (cpool->cache() == NULL)  return false;  // nothing to load yet
 578   int cache_index = decode_cpcache_index(which, true);
 579   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 580   return e->has_appendix();
 581 }
 582 
 583 oop ConstantPool::appendix_at_if_loaded(const constantPoolHandle& cpool, int which) {
 584   if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
 585   int cache_index = decode_cpcache_index(which, true);
 586   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 587   return e->appendix_if_resolved(cpool);
 588 }
 589 
 590 
 591 bool ConstantPool::has_method_type_at_if_loaded(const constantPoolHandle& cpool, int which) {
 592   if (cpool->cache() == NULL)  return false;  // nothing to load yet
 593   int cache_index = decode_cpcache_index(which, true);
 594   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 595   return e->has_method_type();
 596 }
 597 
 598 oop ConstantPool::method_type_at_if_loaded(const constantPoolHandle& cpool, int which) {
 599   if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
 600   int cache_index = decode_cpcache_index(which, true);
 601   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 602   return e->method_type_if_resolved(cpool);
 603 }
 604 
 605 
 606 Symbol* ConstantPool::impl_name_ref_at(int which, bool uncached) {
 607   int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
 608   return symbol_at(name_index);
 609 }
 610 
 611 
 612 Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
 613   int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
 614   return symbol_at(signature_index);
 615 }
 616 
 617 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
 618   int i = which;
 619   if (!uncached && cache() != NULL) {
 620     if (ConstantPool::is_invokedynamic_index(which)) {
 621       // Invokedynamic index is index into the constant pool cache
 622       int pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index();
 623       pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index);
 624       assert(tag_at(pool_index).is_name_and_type(), "");
 625       return pool_index;
 626     }
 627     // change byte-ordering and go via cache
 628     i = remap_instruction_operand_from_cache(which);
 629   } else {
 630     if (tag_at(which).is_invoke_dynamic() ||
 631         tag_at(which).is_dynamic_constant() ||
 632         tag_at(which).is_dynamic_constant_in_error()) {
 633       int pool_index = invoke_dynamic_name_and_type_ref_index_at(which);
 634       assert(tag_at(pool_index).is_name_and_type(), "");
 635       return pool_index;
 636     }
 637   }
 638   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 639   assert(!tag_at(i).is_invoke_dynamic() &&
 640          !tag_at(i).is_dynamic_constant() &&
 641          !tag_at(i).is_dynamic_constant_in_error(), "Must be handled above");
 642   jint ref_index = *int_at_addr(i);
 643   return extract_high_short_from_int(ref_index);
 644 }
 645 
 646 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
 647   int pool_index = which;
 648   if (!uncached && cache() != NULL) {
 649     if (ConstantPool::is_invokedynamic_index(which)) {
 650       // Invokedynamic index is index into resolved_references
 651       pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index();
 652     } else {
 653       // change byte-ordering and go via cache
 654       pool_index = remap_instruction_operand_from_cache(which);
 655     }
 656   }
 657   return tag_at(pool_index);
 658 }
 659 
 660 int ConstantPool::impl_klass_ref_index_at(int which, bool uncached) {
 661   guarantee(!ConstantPool::is_invokedynamic_index(which),
 662             "an invokedynamic instruction does not have a klass");
 663   int i = which;
 664   if (!uncached && cache() != NULL) {
 665     // change byte-ordering and go via cache
 666     i = remap_instruction_operand_from_cache(which);
 667   }
 668   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 669   jint ref_index = *int_at_addr(i);
 670   return extract_low_short_from_int(ref_index);
 671 }


 836     return FieldType::basic_type(constant_type);
 837   }
 838   return tag.basic_type();
 839 }
 840 
 841 // Called to resolve constants in the constant pool and return an oop.
 842 // Some constant pool entries cache their resolved oop. This is also
 843 // called to create oops from constants to use in arguments for invokedynamic
 844 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 845                                            int index, int cache_index,
 846                                            bool* status_return, TRAPS) {
 847   oop result_oop = NULL;
 848   Handle throw_exception;
 849 
 850   if (cache_index == _possible_index_sentinel) {
 851     // It is possible that this constant is one which is cached in the objects.
 852     // We'll do a linear search.  This should be OK because this usage is rare.
 853     // FIXME: If bootstrap specifiers stress this code, consider putting in
 854     // a reverse index.  Binary search over a short array should do it.
 855     assert(index > 0, "valid index");



 856     cache_index = this_cp->cp_to_object_index(index);
 857   }
 858   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
 859   assert(index == _no_index_sentinel || index >= 0, "");
 860 
 861   if (cache_index >= 0) {
 862     result_oop = this_cp->resolved_references()->obj_at(cache_index);
 863     if (result_oop != NULL) {
 864       if (oopDesc::equals(result_oop, Universe::the_null_sentinel())) {
 865         DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
 866         assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
 867         result_oop = NULL;
 868       }
 869       if (status_return != NULL)  (*status_return) = true;
 870       return result_oop;
 871       // That was easy...
 872     }
 873     index = this_cp->object_to_cp_index(cache_index);
 874   }
 875 


 904     }
 905     // from now on there is either success or an OOME
 906     (*status_return) = true;
 907   }
 908 
 909   switch (tag.value()) {
 910 
 911   case JVM_CONSTANT_UnresolvedClass:
 912   case JVM_CONSTANT_UnresolvedClassInError:
 913   case JVM_CONSTANT_Class:
 914     {
 915       assert(cache_index == _no_index_sentinel, "should not have been set");
 916       Klass* resolved = klass_at_impl(this_cp, index, true, CHECK_NULL);
 917       // ldc wants the java mirror.
 918       result_oop = resolved->java_mirror();
 919       break;
 920     }
 921 
 922   case JVM_CONSTANT_Dynamic:
 923     {
 924       Klass* current_klass  = this_cp->pool_holder();
 925       Symbol* constant_name = this_cp->uncached_name_ref_at(index);
 926       Symbol* constant_type = this_cp->uncached_signature_ref_at(index);
 927 
 928       // The initial step in resolving an unresolved symbolic reference to a
 929       // dynamically-computed constant is to resolve the symbolic reference to a
 930       // method handle which will be the bootstrap method for the dynamically-computed
 931       // constant. If resolution of the java.lang.invoke.MethodHandle for the bootstrap
 932       // method fails, then a MethodHandleInError is stored at the corresponding
 933       // bootstrap method's CP index for the CONSTANT_MethodHandle_info. No need to
 934       // set a DynamicConstantInError here since any subsequent use of this
 935       // bootstrap method will encounter the resolution of MethodHandleInError.
 936       oop bsm_info = this_cp->resolve_bootstrap_specifier_at(index, THREAD);
 937       Exceptions::wrap_dynamic_exception(CHECK_NULL);
 938       assert(bsm_info != NULL, "");
 939       // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_Dynamic.
 940       Handle bootstrap_specifier = Handle(THREAD, bsm_info);
 941 
 942       // Resolve the Dynamically-Computed constant to invoke the BSM in order to obtain the resulting oop.
 943       Handle value = SystemDictionary::link_dynamic_constant(current_klass,
 944                                                              index,
 945                                                              bootstrap_specifier,
 946                                                              constant_name,
 947                                                              constant_type,
 948                                                              THREAD);
 949       result_oop = value();
 950       Exceptions::wrap_dynamic_exception(THREAD);
 951       if (HAS_PENDING_EXCEPTION) {
 952         // Resolution failure of the dynamically-computed constant, save_and_throw_exception
 953         // will check for a LinkageError and store a DynamicConstantInError.
 954         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 955       }
 956       BasicType type = FieldType::basic_type(constant_type);

 957       if (!is_reference_type(type)) {
 958         // Make sure the primitive value is properly boxed.
 959         // This is a JDK responsibility.
 960         const char* fail = NULL;
 961         if (result_oop == NULL) {
 962           fail = "null result instead of box";
 963         } else if (!is_java_primitive(type)) {
 964           // FIXME: support value types via unboxing
 965           fail = "can only handle references and primitives";
 966         } else if (!java_lang_boxing_object::is_instance(result_oop, type)) {
 967           fail = "primitive is not properly boxed";
 968         }
 969         if (fail != NULL) {
 970           // Since this exception is not a LinkageError, throw exception
 971           // but do not save a DynamicInError resolution result.
 972           // See section 5.4.3 of the VM spec.
 973           THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), fail);
 974         }
 975       }
 976       break;


1094     } else {
1095       // Return the winning thread's result.  This can be different than
1096       // the result here for MethodHandles.
1097       if (oopDesc::equals(old_result, Universe::the_null_sentinel()))
1098         old_result = NULL;
1099       return old_result;
1100     }
1101   } else {
1102     assert(!oopDesc::equals(result_oop, Universe::the_null_sentinel()), "");
1103     return result_oop;
1104   }
1105 }
1106 
1107 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1108   Symbol* sym = unresolved_string_at(which);
1109   oop str = StringTable::intern(sym, CHECK_(NULL));
1110   assert(java_lang_String::is_instance(str), "must be string");
1111   return str;
1112 }
1113 
1114 
1115 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
1116   assert((this_cp->tag_at(index).is_invoke_dynamic() ||
1117           this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
1118   Handle bsm;
1119   int argc;
1120   {
1121     // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
1122     // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments
1123     // In both cases, the bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
1124     // It is accompanied by the optional arguments.
1125     int bsm_index = this_cp->invoke_dynamic_bootstrap_method_ref_index_at(index);
1126     oop bsm_oop = this_cp->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL);
1127     if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) {
1128       THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle");
1129     }
1130 
1131     // Extract the optional static arguments.
1132     argc = this_cp->invoke_dynamic_argument_count_at(index);
1133 
1134     // if there are no static arguments, return the bsm by itself:
1135     if (argc == 0 && UseBootstrapCallInfo < 2)  return bsm_oop;
1136 
1137     bsm = Handle(THREAD, bsm_oop);
1138   }
1139 
1140   // We are going to return an ordered pair of {bsm, info}, using a 2-array.
1141   objArrayHandle info;
1142   {
1143     objArrayOop info_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 2, CHECK_NULL);
1144     info = objArrayHandle(THREAD, info_oop);
1145   }
1146 
1147   info->obj_at_put(0, bsm());
1148 
1149   bool use_BSCI;
1150   switch (UseBootstrapCallInfo) {
1151   default: use_BSCI = true;  break;  // stress mode
1152   case 0:  use_BSCI = false; break;  // stress mode
1153   case 1:                            // normal mode
1154     // If we were to support an alternative mode of BSM invocation,
1155     // we'd convert to pull mode here if the BSM could be a candidate
1156     // for that alternative mode.  We can't easily test for things
1157     // like varargs here, but we can get away with approximate testing,
1158     // since the JDK runtime will make up the difference either way.
1159     // For now, exercise the pull-mode path if the BSM is of arity 2,
1160     // or if there is a potential condy loop (see below).
1161     oop mt_oop = java_lang_invoke_MethodHandle::type(bsm());
1162     use_BSCI = (java_lang_invoke_MethodType::ptype_count(mt_oop) == 2);
1163     break;
1164   }
1165 
1166   // Here's a reason to use BSCI even if it wasn't requested:
1167   // If a condy uses a condy argument, we want to avoid infinite
1168   // recursion (condy loops) in the C code.  It's OK in Java,
1169   // because Java has stack overflow checking, so we punt
1170   // potentially cyclic cases from C to Java.
1171   if (!use_BSCI && this_cp->tag_at(index).is_dynamic_constant()) {
1172     bool found_unresolved_condy = false;
1173     for (int i = 0; i < argc; i++) {
1174       int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1175       if (this_cp->tag_at(arg_index).is_dynamic_constant()) {
1176         // potential recursion point condy -> condy
1177         bool found_it = false;
1178         this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL);
1179         if (!found_it) { found_unresolved_condy = true; break; }
1180       }
1181     }
1182     if (found_unresolved_condy)
1183       use_BSCI = true;
1184   }
1185 
1186   const int SMALL_ARITY = 5;
1187   if (use_BSCI && argc <= SMALL_ARITY && UseBootstrapCallInfo <= 2) {
1188     // If there are only a few arguments, and none of them need linking,
1189     // push them, instead of asking the JDK runtime to turn around and
1190     // pull them, saving a JVM/JDK transition in some simple cases.
1191     bool all_resolved = true;
1192     for (int i = 0; i < argc; i++) {
1193       bool found_it = false;
1194       int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1195       this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL);
1196       if (!found_it) { all_resolved = false; break; }
1197     }
1198     if (all_resolved)
1199       use_BSCI = false;
1200   }
1201 
1202   if (!use_BSCI) {
1203     // return {bsm, {arg...}}; resolution of arguments is done immediately, before JDK code is called
1204     objArrayOop args_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), argc, CHECK_NULL);
1205     info->obj_at_put(1, args_oop);   // may overwrite with args[0] below
1206     objArrayHandle args(THREAD, args_oop);
1207     copy_bootstrap_arguments_at_impl(this_cp, index, 0, argc, args, 0, true, Handle(), CHECK_NULL);
1208     if (argc == 1) {
1209       // try to discard the singleton array
1210       oop arg_oop = args->obj_at(0);
1211       if (arg_oop != NULL && !arg_oop->is_array()) {
1212         // JVM treats arrays and nulls specially in this position,
1213         // but other things are just single arguments
1214         info->obj_at_put(1, arg_oop);
1215       }
1216     }
1217   } else {
1218     // return {bsm, {arg_count, pool_index}}; JDK code must pull the arguments as needed
1219     typeArrayOop ints_oop = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL);
1220     ints_oop->int_at_put(0, argc);
1221     ints_oop->int_at_put(1, index);
1222     info->obj_at_put(1, ints_oop);
1223   }
1224   return info();
1225 }
1226 
1227 void ConstantPool::copy_bootstrap_arguments_at_impl(const constantPoolHandle& this_cp, int index,
1228                                                     int start_arg, int end_arg,
1229                                                     objArrayHandle info, int pos,
1230                                                     bool must_resolve, Handle if_not_available,




1231                                                     TRAPS) {

















1232   int argc;
1233   int limit = pos + end_arg - start_arg;
1234   // checks: index in range [0..this_cp->length),
1235   // tag at index, start..end in range [0..argc],
1236   // info array non-null, pos..limit in [0..info.length]
1237   if ((0 >= index    || index >= this_cp->length())  ||
1238       !(this_cp->tag_at(index).is_invoke_dynamic()    ||
1239         this_cp->tag_at(index).is_dynamic_constant()) ||
1240       (0 > start_arg || start_arg > end_arg) ||
1241       (end_arg > (argc = this_cp->invoke_dynamic_argument_count_at(index))) ||
1242       (0 > pos       || pos > limit)         ||
1243       (info.is_null() || limit > info->length())) {
1244     // An index or something else went wrong; throw an error.
1245     // Since this is an internal API, we don't expect this,
1246     // so we don't bother to craft a nice message.
1247     THROW_MSG(vmSymbols::java_lang_LinkageError(), "bad BSM argument access");
1248   }
1249   // now we can loop safely
1250   int info_i = pos;
1251   for (int i = start_arg; i < end_arg; i++) {
1252     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1253     oop arg_oop;
1254     if (must_resolve) {












1255       arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1256     } else {
1257       bool found_it = false;

1258       arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1259       if (!found_it)  arg_oop = if_not_available();
1260     }
1261     info->obj_at_put(info_i++, arg_oop);










1262   }
1263 }
1264 
1265 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1266   // If the string has already been interned, this entry will be non-null
1267   oop str = this_cp->resolved_references()->obj_at(obj_index);
1268   assert(!oopDesc::equals(str, Universe::the_null_sentinel()), "");
1269   if (str != NULL) return str;
1270   Symbol* sym = this_cp->unresolved_string_at(which);
1271   str = StringTable::intern(sym, CHECK_(NULL));
1272   this_cp->string_at_put(which, obj_index, str);
1273   assert(java_lang_String::is_instance(str), "must be string");
1274   return str;
1275 }
1276 
1277 
1278 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1279   // Names are interned, so we can compare Symbol*s directly
1280   Symbol* cp_name = klass_name_at(which);
1281   return (cp_name == k->name());


1431       return true;
1432     }
1433   } break;
1434 
1435   case JVM_CONSTANT_MethodHandle:
1436   {
1437     int k1 = method_handle_ref_kind_at(index1);
1438     int k2 = cp2->method_handle_ref_kind_at(index2);
1439     if (k1 == k2) {
1440       int i1 = method_handle_index_at(index1);
1441       int i2 = cp2->method_handle_index_at(index2);
1442       bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
1443       if (match) {
1444         return true;
1445       }
1446     }
1447   } break;
1448 
1449   case JVM_CONSTANT_Dynamic:
1450   {
1451     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
1452     int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
1453     int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
1454     int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
1455     // separate statements and variables because CHECK_false is used
1456     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
1457     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
1458     return (match_entry && match_operand);
1459   } break;
1460 
1461   case JVM_CONSTANT_InvokeDynamic:
1462   {
1463     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
1464     int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
1465     int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
1466     int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
1467     // separate statements and variables because CHECK_false is used
1468     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
1469     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
1470     return (match_entry && match_operand);
1471   } break;
1472 
1473   case JVM_CONSTANT_String:
1474   {
1475     Symbol* s1 = unresolved_string_at(index1);
1476     Symbol* s2 = cp2->unresolved_string_at(index2);
1477     if (s1 == s2) {
1478       return true;
1479     }
1480   } break;
1481 
1482   case JVM_CONSTANT_Utf8:
1483   {
1484     Symbol* s1 = symbol_at(index1);
1485     Symbol* s2 = cp2->symbol_at(index2);
1486     if (s1 == s2) {


1770   } break;
1771 
1772   case JVM_CONSTANT_MethodType:
1773   case JVM_CONSTANT_MethodTypeInError:
1774   {
1775     jint k = from_cp->method_type_index_at(from_i);
1776     to_cp->method_type_index_at_put(to_i, k);
1777   } break;
1778 
1779   case JVM_CONSTANT_MethodHandle:
1780   case JVM_CONSTANT_MethodHandleInError:
1781   {
1782     int k1 = from_cp->method_handle_ref_kind_at(from_i);
1783     int k2 = from_cp->method_handle_index_at(from_i);
1784     to_cp->method_handle_index_at_put(to_i, k1, k2);
1785   } break;
1786 
1787   case JVM_CONSTANT_Dynamic:
1788   case JVM_CONSTANT_DynamicInError:
1789   {
1790     int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
1791     int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
1792     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
1793     to_cp->dynamic_constant_at_put(to_i, k1, k2);
1794   } break;
1795 
1796   case JVM_CONSTANT_InvokeDynamic:
1797   {
1798     int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
1799     int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
1800     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
1801     to_cp->invoke_dynamic_at_put(to_i, k1, k2);
1802   } break;
1803 
1804   // Invalid is used as the tag for the second constant pool entry
1805   // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
1806   // not be seen by itself.
1807   case JVM_CONSTANT_Invalid: // fall through
1808 
1809   default:
1810   {
1811     ShouldNotReachHere();
1812   } break;
1813   }
1814 } // end copy_entry_to()
1815 
1816 // Search constant pool search_cp for an entry that matches this
1817 // constant pool's entry at pattern_i. Returns the index of a
1818 // matching entry or zero (0) if there is no matching entry.
1819 int ConstantPool::find_matching_entry(int pattern_i,


1840 
1841   if (!match) {
1842     return false;
1843   }
1844   int argc = operand_argument_count_at(idx1);
1845   if (argc == cp2->operand_argument_count_at(idx2)) {
1846     for (int j = 0; j < argc; j++) {
1847       k1 = operand_argument_index_at(idx1, j);
1848       k2 = cp2->operand_argument_index_at(idx2, j);
1849       match = compare_entry_to(k1, cp2, k2, CHECK_false);
1850       if (!match) {
1851         return false;
1852       }
1853     }
1854     return true;           // got through loop; all elements equal
1855   }
1856   return false;
1857 } // end compare_operand_to()
1858 
1859 // Search constant pool search_cp for a bootstrap specifier that matches
1860 // this constant pool's bootstrap specifier at pattern_i index.
1861 // Return the index of a matching bootstrap specifier or (-1) if there is no match.
1862 int ConstantPool::find_matching_operand(int pattern_i,
1863                     const constantPoolHandle& search_cp, int search_len, TRAPS) {
1864   for (int i = 0; i < search_len; i++) {
1865     bool found = compare_operand_to(pattern_i, search_cp, i, CHECK_(-1));
1866     if (found) {
1867       return i;
1868     }
1869   }
1870   return -1;  // bootstrap specifier not found; return unused index (-1)
1871 } // end find_matching_operand()
1872 
1873 
1874 #ifndef PRODUCT
1875 
1876 const char* ConstantPool::printable_name_at(int which) {
1877 
1878   constantTag tag = tag_at(which);
1879 
1880   if (tag.is_string()) {
1881     return string_at_noresolve(which);
1882   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
1883     return klass_name_at(which)->as_C_string();
1884   } else if (tag.is_symbol()) {
1885     return symbol_at(which)->as_C_string();
1886   }
1887   return "";
1888 }
1889 
1890 #endif // PRODUCT


2229         int kind = method_handle_ref_kind_at(idx);
2230         idx1 = method_handle_index_at(idx);
2231         *(bytes+1) = (unsigned char) kind;
2232         Bytes::put_Java_u2((address) (bytes+2), idx1);
2233         DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
2234         break;
2235       }
2236       case JVM_CONSTANT_MethodType:
2237       case JVM_CONSTANT_MethodTypeInError: {
2238         *bytes = JVM_CONSTANT_MethodType;
2239         idx1 = method_type_index_at(idx);
2240         Bytes::put_Java_u2((address) (bytes+1), idx1);
2241         DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
2242         break;
2243       }
2244       case JVM_CONSTANT_Dynamic:
2245       case JVM_CONSTANT_DynamicInError: {
2246         *bytes = tag;
2247         idx1 = extract_low_short_from_int(*int_at_addr(idx));
2248         idx2 = extract_high_short_from_int(*int_at_addr(idx));
2249         assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4");
2250         Bytes::put_Java_u2((address) (bytes+1), idx1);
2251         Bytes::put_Java_u2((address) (bytes+3), idx2);
2252         DBG(printf("JVM_CONSTANT_Dynamic: %hd %hd", idx1, idx2));
2253         break;
2254       }
2255       case JVM_CONSTANT_InvokeDynamic: {
2256         *bytes = tag;
2257         idx1 = extract_low_short_from_int(*int_at_addr(idx));
2258         idx2 = extract_high_short_from_int(*int_at_addr(idx));
2259         assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4");
2260         Bytes::put_Java_u2((address) (bytes+1), idx1);
2261         Bytes::put_Java_u2((address) (bytes+3), idx2);
2262         DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2));
2263         break;
2264       }
2265     }
2266     DBG(printf("\n"));
2267     bytes += ent_size;
2268     size  += ent_size;
2269   }
2270   assert(size == cpool_size, "Size mismatch");
2271 
2272   // Keep temorarily for debugging until it's stable.
2273   DBG(print_cpool_bytes(cnt, start_bytes));
2274   return (int)(bytes - start_bytes);
2275 } /* end copy_cpool_bytes */
2276 
2277 #undef DBG
2278 
2279 


2443         Klass* klass = resolved_klasses()->at(resolved_klass_index);
2444         if (klass != NULL) {
2445           klass->print_value_on(st);
2446         } else {
2447           symbol_at(name_index)->print_value_on(st);
2448         }
2449       }
2450       break;
2451     case JVM_CONSTANT_MethodHandle :
2452     case JVM_CONSTANT_MethodHandleInError :
2453       st->print("ref_kind=%d", method_handle_ref_kind_at(index));
2454       st->print(" ref_index=%d", method_handle_index_at(index));
2455       break;
2456     case JVM_CONSTANT_MethodType :
2457     case JVM_CONSTANT_MethodTypeInError :
2458       st->print("signature_index=%d", method_type_index_at(index));
2459       break;
2460     case JVM_CONSTANT_Dynamic :
2461     case JVM_CONSTANT_DynamicInError :
2462       {
2463         st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
2464         st->print(" type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
2465         int argc = invoke_dynamic_argument_count_at(index);
2466         if (argc > 0) {
2467           for (int arg_i = 0; arg_i < argc; arg_i++) {
2468             int arg = invoke_dynamic_argument_index_at(index, arg_i);
2469             st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
2470           }
2471           st->print("}");
2472         }
2473       }
2474       break;
2475     case JVM_CONSTANT_InvokeDynamic :
2476       {
2477         st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
2478         st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));
2479         int argc = invoke_dynamic_argument_count_at(index);
2480         if (argc > 0) {
2481           for (int arg_i = 0; arg_i < argc; arg_i++) {
2482             int arg = invoke_dynamic_argument_index_at(index, arg_i);
2483             st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
2484           }
2485           st->print("}");
2486         }
2487       }
2488       break;
2489     default:
2490       ShouldNotReachHere();
2491       break;
2492   }
2493   st->cr();
2494 }
2495 
2496 void ConstantPool::print_value_on(outputStream* st) const {
2497   assert(is_constantPool(), "must be constantPool");
2498   st->print("constant pool [%d]", length());
2499   if (has_preresolution()) st->print("/preresolution");
2500   if (operands() != NULL)  st->print("/operands[%d]", operands()->length());
2501   print_address_on(st);
2502   if (pool_holder() != NULL) {




 571   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 572   return e->method_if_resolved(cpool);
 573 }
 574 
 575 
 576 bool ConstantPool::has_appendix_at_if_loaded(const constantPoolHandle& cpool, int which) {
 577   if (cpool->cache() == NULL)  return false;  // nothing to load yet
 578   int cache_index = decode_cpcache_index(which, true);
 579   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 580   return e->has_appendix();
 581 }
 582 
 583 oop ConstantPool::appendix_at_if_loaded(const constantPoolHandle& cpool, int which) {
 584   if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
 585   int cache_index = decode_cpcache_index(which, true);
 586   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 587   return e->appendix_if_resolved(cpool);
 588 }
 589 
 590 
 591 bool ConstantPool::has_local_signature_at_if_loaded(const constantPoolHandle& cpool, int which) {
 592   if (cpool->cache() == NULL)  return false;  // nothing to load yet
 593   int cache_index = decode_cpcache_index(which, true);
 594   ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
 595   return e->has_local_signature();
 596 }
 597 








 598 Symbol* ConstantPool::impl_name_ref_at(int which, bool uncached) {
 599   int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
 600   return symbol_at(name_index);
 601 }
 602 
 603 
 604 Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
 605   int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
 606   return symbol_at(signature_index);
 607 }
 608 
 609 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
 610   int i = which;
 611   if (!uncached && cache() != NULL) {
 612     if (ConstantPool::is_invokedynamic_index(which)) {
 613       // Invokedynamic index is index into the constant pool cache
 614       int pool_index = invokedynamic_bootstrap_ref_index_at(which);
 615       pool_index = bootstrap_name_and_type_ref_index_at(pool_index);
 616       assert(tag_at(pool_index).is_name_and_type(), "");
 617       return pool_index;
 618     }
 619     // change byte-ordering and go via cache
 620     i = remap_instruction_operand_from_cache(which);
 621   } else {
 622     if (tag_at(which).has_bootstrap()) {
 623       int pool_index = bootstrap_name_and_type_ref_index_at(which);


 624       assert(tag_at(pool_index).is_name_and_type(), "");
 625       return pool_index;
 626     }
 627   }
 628   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 629   assert(!tag_at(i).has_bootstrap(), "Must be handled above");


 630   jint ref_index = *int_at_addr(i);
 631   return extract_high_short_from_int(ref_index);
 632 }
 633 
 634 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
 635   int pool_index = which;
 636   if (!uncached && cache() != NULL) {
 637     if (ConstantPool::is_invokedynamic_index(which)) {
 638       // Invokedynamic index is index into resolved_references
 639       pool_index = invokedynamic_bootstrap_ref_index_at(which);
 640     } else {
 641       // change byte-ordering and go via cache
 642       pool_index = remap_instruction_operand_from_cache(which);
 643     }
 644   }
 645   return tag_at(pool_index);
 646 }
 647 
 648 int ConstantPool::impl_klass_ref_index_at(int which, bool uncached) {
 649   guarantee(!ConstantPool::is_invokedynamic_index(which),
 650             "an invokedynamic instruction does not have a klass");
 651   int i = which;
 652   if (!uncached && cache() != NULL) {
 653     // change byte-ordering and go via cache
 654     i = remap_instruction_operand_from_cache(which);
 655   }
 656   assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
 657   jint ref_index = *int_at_addr(i);
 658   return extract_low_short_from_int(ref_index);
 659 }


 824     return FieldType::basic_type(constant_type);
 825   }
 826   return tag.basic_type();
 827 }
 828 
 829 // Called to resolve constants in the constant pool and return an oop.
 830 // Some constant pool entries cache their resolved oop. This is also
 831 // called to create oops from constants to use in arguments for invokedynamic
 832 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 833                                            int index, int cache_index,
 834                                            bool* status_return, TRAPS) {
 835   oop result_oop = NULL;
 836   Handle throw_exception;
 837 
 838   if (cache_index == _possible_index_sentinel) {
 839     // It is possible that this constant is one which is cached in the objects.
 840     // We'll do a linear search.  This should be OK because this usage is rare.
 841     // FIXME: If bootstrap specifiers stress this code, consider putting in
 842     // a reverse index.  Binary search over a short array should do it.
 843     assert(index > 0, "valid index");
 844     if (this_cp->reference_map() == NULL)
 845       cache_index = _no_index_sentinel;
 846     else
 847       cache_index = this_cp->cp_to_object_index(index);
 848   }
 849   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
 850   assert(index == _no_index_sentinel || index >= 0, "");
 851 
 852   if (cache_index >= 0) {
 853     result_oop = this_cp->resolved_references()->obj_at(cache_index);
 854     if (result_oop != NULL) {
 855       if (oopDesc::equals(result_oop, Universe::the_null_sentinel())) {
 856         DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
 857         assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
 858         result_oop = NULL;
 859       }
 860       if (status_return != NULL)  (*status_return) = true;
 861       return result_oop;
 862       // That was easy...
 863     }
 864     index = this_cp->object_to_cp_index(cache_index);
 865   }
 866 


 895     }
 896     // from now on there is either success or an OOME
 897     (*status_return) = true;
 898   }
 899 
 900   switch (tag.value()) {
 901 
 902   case JVM_CONSTANT_UnresolvedClass:
 903   case JVM_CONSTANT_UnresolvedClassInError:
 904   case JVM_CONSTANT_Class:
 905     {
 906       assert(cache_index == _no_index_sentinel, "should not have been set");
 907       Klass* resolved = klass_at_impl(this_cp, index, true, CHECK_NULL);
 908       // ldc wants the java mirror.
 909       result_oop = resolved->java_mirror();
 910       break;
 911     }
 912 
 913   case JVM_CONSTANT_Dynamic:
 914     {




 915       // The initial step in resolving an unresolved symbolic reference to a
 916       // dynamically-computed constant is to resolve the symbolic reference to a
 917       // method handle which will be the bootstrap method for the dynamically-computed
 918       // constant. If resolution of the java.lang.invoke.MethodHandle for the bootstrap
 919       // method fails, then a MethodHandleInError is stored at the corresponding
 920       // bootstrap method's CP index for the CONSTANT_MethodHandle_info. No need to
 921       // set a DynamicConstantInError here since any subsequent use of this
 922       // bootstrap method will encounter the resolution of MethodHandleInError.
 923       BootstrapInfo bootstrap_specifier(this_cp, index);




 924 
 925       // Resolve the Dynamically-Computed constant to invoke the BSM in order to obtain the resulting oop.
 926       SystemDictionary::invoke_bootstrap_method(bootstrap_specifier, THREAD);






 927       Exceptions::wrap_dynamic_exception(THREAD);
 928       if (HAS_PENDING_EXCEPTION) {
 929         // Resolution failure of the dynamically-computed constant, save_and_throw_exception
 930         // will check for a LinkageError and store a DynamicConstantInError.
 931         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 932       }
 933       result_oop = bootstrap_specifier.resolved_value()();
 934       BasicType type = FieldType::basic_type(bootstrap_specifier.signature());
 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;


1072     } else {
1073       // Return the winning thread's result.  This can be different than
1074       // the result here for MethodHandles.
1075       if (oopDesc::equals(old_result, Universe::the_null_sentinel()))
1076         old_result = NULL;
1077       return old_result;
1078     }
1079   } else {
1080     assert(!oopDesc::equals(result_oop, Universe::the_null_sentinel()), "");
1081     return result_oop;
1082   }
1083 }
1084 
1085 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1086   Symbol* sym = unresolved_string_at(which);
1087   oop str = StringTable::intern(sym, CHECK_(NULL));
1088   assert(java_lang_String::is_instance(str), "must be string");
1089   return str;
1090 }
1091 

















































































































1092 void ConstantPool::copy_bootstrap_arguments_at_impl(const constantPoolHandle& this_cp, int index,
1093                                                     int start_arg, int end_arg,
1094                                                     arrayHandle buf, int pos,
1095                                                     BootstrapArgumentReferenceMode resolving,
1096                                                     Handle if_not_available,
1097                                                     Handle if_null_constant,
1098                                                     bool skip_non_null,
1099                                                     bool skip_recursion,
1100                                                     TRAPS) {
1101   objArrayHandle obj_buf;   // set to buf if type Object[]
1102   typeArrayHandle int_buf;  // set to buf if type int[]
1103   if (buf.not_null()) {
1104     switch (resolving) {
1105     case R_IFPRESENT:  // mode = do not resolve new values
1106     case R_FORCE:      // mode = resolve any requested values (cf. skip_non_null)
1107       if (buf->klass() == Universe::objectArrayKlassObj())
1108         obj_buf = objArrayHandle(THREAD, (objArrayOop) buf());
1109       break;
1110     case R_SYMREF:     // mode = return only CP indexes (symbolic refs)
1111       if (buf->klass() == Universe::intArrayKlassObj())
1112         int_buf = typeArrayHandle(THREAD, (typeArrayOop) buf());
1113       break;
1114     }
1115     if (obj_buf.is_null() && int_buf.is_null())
1116       buf = arrayHandle();  // buf matches neither case; nullify
1117   }
1118   int argc;
1119   int limit = pos + end_arg - start_arg;
1120   // checks: index in range [0..this_cp->length),
1121   // tag at index, start..end in range [0..argc],
1122   // buf array non-null, pos..limit in [0..buf.length]
1123   if ((0 >= index    || index >= this_cp->length())  ||
1124       !this_cp->tag_at(index).has_bootstrap() ||

1125       (0 > start_arg || start_arg > end_arg) ||
1126       (end_arg > (argc = this_cp->bootstrap_argument_count_at(index))) ||
1127       (0 > pos       || pos > limit)         ||
1128       (buf.is_null() || limit > buf->length())) {
1129     // An index or something else went wrong; throw an error.
1130     // Since this is an internal API, we don't expect this,
1131     // so we don't bother to craft a nice message.
1132     THROW_MSG(vmSymbols::java_lang_LinkageError(), "bad BSM argument access");
1133   }
1134   // now we can loop safely
1135   int buf_i = pos;
1136   for (int i = start_arg; i < end_arg; i++) {
1137     if (skip_non_null && obj_buf.not_null() && obj_buf->obj_at(buf_i) != NULL) {
1138       // buf is somebody's cache; don't disturb non-null entries
1139       buf_i++;
1140       continue;
1141     }
1142     int arg_index = this_cp->bootstrap_argument_index_at(index, i);
1143     BootstrapArgumentReferenceMode mode = resolving;
1144     if (mode == R_FORCE && skip_recursion && this_cp->tag_at(arg_index).has_bootstrap()) {
1145       // don't force recursive execution of BSMs (via condy)
1146       mode = R_IFPRESENT;  // but *do* return a value if it is available
1147     }
1148     oop arg_oop = NULL;
1149     int arg_int = 0;
1150     bool found_it;
1151     if (mode == R_FORCE) {
1152       arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1153       found_it = true;
1154     } else if (mode == R_IFPRESENT) {
1155       found_it = false;
1156       arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1157     } else {
1158       assert(mode == R_SYMREF, "");
1159       arg_int = arg_index;
1160       found_it = true;
1161     }
1162     if (!found_it)
1163       arg_oop = if_not_available();  // might be NULL!
1164     else if (arg_oop == NULL)
1165       arg_oop = if_null_constant();
1166     if (obj_buf.not_null())
1167       obj_buf->obj_at_put(buf_i++, arg_oop);
1168     else
1169       int_buf->int_at_put(buf_i++, arg_int);
1170   }
1171 }
1172 
1173 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1174   // If the string has already been interned, this entry will be non-null
1175   oop str = this_cp->resolved_references()->obj_at(obj_index);
1176   assert(!oopDesc::equals(str, Universe::the_null_sentinel()), "");
1177   if (str != NULL) return str;
1178   Symbol* sym = this_cp->unresolved_string_at(which);
1179   str = StringTable::intern(sym, CHECK_(NULL));
1180   this_cp->string_at_put(which, obj_index, str);
1181   assert(java_lang_String::is_instance(str), "must be string");
1182   return str;
1183 }
1184 
1185 
1186 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1187   // Names are interned, so we can compare Symbol*s directly
1188   Symbol* cp_name = klass_name_at(which);
1189   return (cp_name == k->name());


1339       return true;
1340     }
1341   } break;
1342 
1343   case JVM_CONSTANT_MethodHandle:
1344   {
1345     int k1 = method_handle_ref_kind_at(index1);
1346     int k2 = cp2->method_handle_ref_kind_at(index2);
1347     if (k1 == k2) {
1348       int i1 = method_handle_index_at(index1);
1349       int i2 = cp2->method_handle_index_at(index2);
1350       bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
1351       if (match) {
1352         return true;
1353       }
1354     }
1355   } break;
1356 
1357   case JVM_CONSTANT_Dynamic:
1358   {
1359     int k1 = bootstrap_name_and_type_ref_index_at(index1);
1360     int k2 = cp2->bootstrap_name_and_type_ref_index_at(index2);
1361     int i1 = bootstrap_methods_attribute_index(index1);
1362     int i2 = cp2->bootstrap_methods_attribute_index(index2);
1363     // separate statements and variables because CHECK_false is used
1364     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
1365     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
1366     return (match_entry && match_operand);
1367   } break;
1368 
1369   case JVM_CONSTANT_InvokeDynamic:
1370   {
1371     int k1 = bootstrap_name_and_type_ref_index_at(index1);
1372     int k2 = cp2->bootstrap_name_and_type_ref_index_at(index2);
1373     int i1 = bootstrap_methods_attribute_index(index1);
1374     int i2 = cp2->bootstrap_methods_attribute_index(index2);
1375     // separate statements and variables because CHECK_false is used
1376     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
1377     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
1378     return (match_entry && match_operand);
1379   } break;
1380 
1381   case JVM_CONSTANT_String:
1382   {
1383     Symbol* s1 = unresolved_string_at(index1);
1384     Symbol* s2 = cp2->unresolved_string_at(index2);
1385     if (s1 == s2) {
1386       return true;
1387     }
1388   } break;
1389 
1390   case JVM_CONSTANT_Utf8:
1391   {
1392     Symbol* s1 = symbol_at(index1);
1393     Symbol* s2 = cp2->symbol_at(index2);
1394     if (s1 == s2) {


1678   } break;
1679 
1680   case JVM_CONSTANT_MethodType:
1681   case JVM_CONSTANT_MethodTypeInError:
1682   {
1683     jint k = from_cp->method_type_index_at(from_i);
1684     to_cp->method_type_index_at_put(to_i, k);
1685   } break;
1686 
1687   case JVM_CONSTANT_MethodHandle:
1688   case JVM_CONSTANT_MethodHandleInError:
1689   {
1690     int k1 = from_cp->method_handle_ref_kind_at(from_i);
1691     int k2 = from_cp->method_handle_index_at(from_i);
1692     to_cp->method_handle_index_at_put(to_i, k1, k2);
1693   } break;
1694 
1695   case JVM_CONSTANT_Dynamic:
1696   case JVM_CONSTANT_DynamicInError:
1697   {
1698     int k1 = from_cp->bootstrap_methods_attribute_index(from_i);
1699     int k2 = from_cp->bootstrap_name_and_type_ref_index_at(from_i);
1700     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
1701     to_cp->dynamic_constant_at_put(to_i, k1, k2);
1702   } break;
1703 
1704   case JVM_CONSTANT_InvokeDynamic:
1705   {
1706     int k1 = from_cp->bootstrap_methods_attribute_index(from_i);
1707     int k2 = from_cp->bootstrap_name_and_type_ref_index_at(from_i);
1708     k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
1709     to_cp->invoke_dynamic_at_put(to_i, k1, k2);
1710   } break;
1711 
1712   // Invalid is used as the tag for the second constant pool entry
1713   // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
1714   // not be seen by itself.
1715   case JVM_CONSTANT_Invalid: // fall through
1716 
1717   default:
1718   {
1719     ShouldNotReachHere();
1720   } break;
1721   }
1722 } // end copy_entry_to()
1723 
1724 // Search constant pool search_cp for an entry that matches this
1725 // constant pool's entry at pattern_i. Returns the index of a
1726 // matching entry or zero (0) if there is no matching entry.
1727 int ConstantPool::find_matching_entry(int pattern_i,


1748 
1749   if (!match) {
1750     return false;
1751   }
1752   int argc = operand_argument_count_at(idx1);
1753   if (argc == cp2->operand_argument_count_at(idx2)) {
1754     for (int j = 0; j < argc; j++) {
1755       k1 = operand_argument_index_at(idx1, j);
1756       k2 = cp2->operand_argument_index_at(idx2, j);
1757       match = compare_entry_to(k1, cp2, k2, CHECK_false);
1758       if (!match) {
1759         return false;
1760       }
1761     }
1762     return true;           // got through loop; all elements equal
1763   }
1764   return false;
1765 } // end compare_operand_to()
1766 
1767 // Search constant pool search_cp for a bootstrap specifier that matches
1768 // this constant pool's bootstrap specifier data at pattern_i index.
1769 // Return the index of a matching bootstrap attribute record or (-1) if there is no match.
1770 int ConstantPool::find_matching_operand(int pattern_i,
1771                     const constantPoolHandle& search_cp, int search_len, TRAPS) {
1772   for (int i = 0; i < search_len; i++) {
1773     bool found = compare_operand_to(pattern_i, search_cp, i, CHECK_(-1));
1774     if (found) {
1775       return i;
1776     }
1777   }
1778   return -1;  // bootstrap specifier data not found; return unused index (-1)
1779 } // end find_matching_operand()
1780 
1781 
1782 #ifndef PRODUCT
1783 
1784 const char* ConstantPool::printable_name_at(int which) {
1785 
1786   constantTag tag = tag_at(which);
1787 
1788   if (tag.is_string()) {
1789     return string_at_noresolve(which);
1790   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
1791     return klass_name_at(which)->as_C_string();
1792   } else if (tag.is_symbol()) {
1793     return symbol_at(which)->as_C_string();
1794   }
1795   return "";
1796 }
1797 
1798 #endif // PRODUCT


2137         int kind = method_handle_ref_kind_at(idx);
2138         idx1 = method_handle_index_at(idx);
2139         *(bytes+1) = (unsigned char) kind;
2140         Bytes::put_Java_u2((address) (bytes+2), idx1);
2141         DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
2142         break;
2143       }
2144       case JVM_CONSTANT_MethodType:
2145       case JVM_CONSTANT_MethodTypeInError: {
2146         *bytes = JVM_CONSTANT_MethodType;
2147         idx1 = method_type_index_at(idx);
2148         Bytes::put_Java_u2((address) (bytes+1), idx1);
2149         DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
2150         break;
2151       }
2152       case JVM_CONSTANT_Dynamic:
2153       case JVM_CONSTANT_DynamicInError: {
2154         *bytes = tag;
2155         idx1 = extract_low_short_from_int(*int_at_addr(idx));
2156         idx2 = extract_high_short_from_int(*int_at_addr(idx));
2157         assert(idx2 == bootstrap_name_and_type_ref_index_at(idx), "correct half of u4");
2158         Bytes::put_Java_u2((address) (bytes+1), idx1);
2159         Bytes::put_Java_u2((address) (bytes+3), idx2);
2160         DBG(printf("JVM_CONSTANT_Dynamic: %hd %hd", idx1, idx2));
2161         break;
2162       }
2163       case JVM_CONSTANT_InvokeDynamic: {
2164         *bytes = tag;
2165         idx1 = extract_low_short_from_int(*int_at_addr(idx));
2166         idx2 = extract_high_short_from_int(*int_at_addr(idx));
2167         assert(idx2 == bootstrap_name_and_type_ref_index_at(idx), "correct half of u4");
2168         Bytes::put_Java_u2((address) (bytes+1), idx1);
2169         Bytes::put_Java_u2((address) (bytes+3), idx2);
2170         DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2));
2171         break;
2172       }
2173     }
2174     DBG(printf("\n"));
2175     bytes += ent_size;
2176     size  += ent_size;
2177   }
2178   assert(size == cpool_size, "Size mismatch");
2179 
2180   // Keep temorarily for debugging until it's stable.
2181   DBG(print_cpool_bytes(cnt, start_bytes));
2182   return (int)(bytes - start_bytes);
2183 } /* end copy_cpool_bytes */
2184 
2185 #undef DBG
2186 
2187 


2351         Klass* klass = resolved_klasses()->at(resolved_klass_index);
2352         if (klass != NULL) {
2353           klass->print_value_on(st);
2354         } else {
2355           symbol_at(name_index)->print_value_on(st);
2356         }
2357       }
2358       break;
2359     case JVM_CONSTANT_MethodHandle :
2360     case JVM_CONSTANT_MethodHandleInError :
2361       st->print("ref_kind=%d", method_handle_ref_kind_at(index));
2362       st->print(" ref_index=%d", method_handle_index_at(index));
2363       break;
2364     case JVM_CONSTANT_MethodType :
2365     case JVM_CONSTANT_MethodTypeInError :
2366       st->print("signature_index=%d", method_type_index_at(index));
2367       break;
2368     case JVM_CONSTANT_Dynamic :
2369     case JVM_CONSTANT_DynamicInError :
2370       {
2371         st->print("bootstrap_method_index=%d", bootstrap_method_ref_index_at(index));
2372         st->print(" type_index=%d", bootstrap_name_and_type_ref_index_at(index));
2373         int argc = bootstrap_argument_count_at(index);
2374         if (argc > 0) {
2375           for (int arg_i = 0; arg_i < argc; arg_i++) {
2376             int arg = bootstrap_argument_index_at(index, arg_i);
2377             st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
2378           }
2379           st->print("}");
2380         }
2381       }
2382       break;
2383     case JVM_CONSTANT_InvokeDynamic :
2384       {
2385         st->print("bootstrap_method_index=%d", bootstrap_method_ref_index_at(index));
2386         st->print(" name_and_type_index=%d", bootstrap_name_and_type_ref_index_at(index));
2387         int argc = bootstrap_argument_count_at(index);
2388         if (argc > 0) {
2389           for (int arg_i = 0; arg_i < argc; arg_i++) {
2390             int arg = bootstrap_argument_index_at(index, arg_i);
2391             st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
2392           }
2393           st->print("}");
2394         }
2395       }
2396       break;
2397     default:
2398       ShouldNotReachHere();
2399       break;
2400   }
2401   st->cr();
2402 }
2403 
2404 void ConstantPool::print_value_on(outputStream* st) const {
2405   assert(is_constantPool(), "must be constantPool");
2406   st->print("constant pool [%d]", length());
2407   if (has_preresolution()) st->print("/preresolution");
2408   if (operands() != NULL)  st->print("/operands[%d]", operands()->length());
2409   print_address_on(st);
2410   if (pool_holder() != NULL) {


< prev index next >