623 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) { |
623 int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) { |
624 int i = which; |
624 int i = which; |
625 if (!uncached && cache() != NULL) { |
625 if (!uncached && cache() != NULL) { |
626 if (ConstantPool::is_invokedynamic_index(which)) { |
626 if (ConstantPool::is_invokedynamic_index(which)) { |
627 // Invokedynamic index is index into the constant pool cache |
627 // Invokedynamic index is index into the constant pool cache |
628 int pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index(); |
628 int pool_index = invokedynamic_bootstrap_ref_index_at(which); |
629 pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); |
629 pool_index = bootstrap_name_and_type_ref_index_at(pool_index); |
630 assert(tag_at(pool_index).is_name_and_type(), ""); |
630 assert(tag_at(pool_index).is_name_and_type(), ""); |
631 return pool_index; |
631 return pool_index; |
632 } |
632 } |
633 // change byte-ordering and go via cache |
633 // change byte-ordering and go via cache |
634 i = remap_instruction_operand_from_cache(which); |
634 i = remap_instruction_operand_from_cache(which); |
635 } else { |
635 } else { |
636 if (tag_at(which).is_invoke_dynamic() || |
636 if (tag_at(which).has_bootstrap()) { |
637 tag_at(which).is_dynamic_constant() || |
637 int pool_index = bootstrap_name_and_type_ref_index_at(which); |
638 tag_at(which).is_dynamic_constant_in_error()) { |
|
639 int pool_index = invoke_dynamic_name_and_type_ref_index_at(which); |
|
640 assert(tag_at(pool_index).is_name_and_type(), ""); |
638 assert(tag_at(pool_index).is_name_and_type(), ""); |
641 return pool_index; |
639 return pool_index; |
642 } |
640 } |
643 } |
641 } |
644 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
642 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
645 assert(!tag_at(i).is_invoke_dynamic() && |
643 assert(!tag_at(i).has_bootstrap(), "Must be handled above"); |
646 !tag_at(i).is_dynamic_constant() && |
|
647 !tag_at(i).is_dynamic_constant_in_error(), "Must be handled above"); |
|
648 jint ref_index = *int_at_addr(i); |
644 jint ref_index = *int_at_addr(i); |
649 return extract_high_short_from_int(ref_index); |
645 return extract_high_short_from_int(ref_index); |
650 } |
646 } |
651 |
647 |
652 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) { |
648 constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) { |
653 int pool_index = which; |
649 int pool_index = which; |
654 if (!uncached && cache() != NULL) { |
650 if (!uncached && cache() != NULL) { |
655 if (ConstantPool::is_invokedynamic_index(which)) { |
651 if (ConstantPool::is_invokedynamic_index(which)) { |
656 // Invokedynamic index is index into resolved_references |
652 // Invokedynamic index is index into resolved_references |
657 pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index(); |
653 pool_index = invokedynamic_bootstrap_ref_index_at(which); |
658 } else { |
654 } else { |
659 // change byte-ordering and go via cache |
655 // change byte-ordering and go via cache |
660 pool_index = remap_instruction_operand_from_cache(which); |
656 pool_index = remap_instruction_operand_from_cache(which); |
661 } |
657 } |
662 } |
658 } |
1126 { |
1122 { |
1127 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments |
1123 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments |
1128 // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments |
1124 // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments |
1129 // In both cases, the bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry. |
1125 // In both cases, the bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry. |
1130 // It is accompanied by the optional arguments. |
1126 // It is accompanied by the optional arguments. |
1131 int bsm_index = this_cp->invoke_dynamic_bootstrap_method_ref_index_at(index); |
1127 int bsm_index = this_cp->bootstrap_method_ref_index_at(index); |
1132 oop bsm_oop = this_cp->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL); |
1128 oop bsm_oop = this_cp->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL); |
1133 if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) { |
1129 if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) { |
1134 THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle"); |
1130 THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle"); |
1135 } |
1131 } |
1136 |
1132 |
1137 // Extract the optional static arguments. |
1133 // Extract the optional static arguments. |
1138 argc = this_cp->invoke_dynamic_argument_count_at(index); |
1134 argc = this_cp->bootstrap_argument_count_at(index); |
1139 |
1135 |
1140 // if there are no static arguments, return the bsm by itself: |
1136 // if there are no static arguments, return the bsm by itself: |
1141 if (argc == 0 && UseBootstrapCallInfo < 2) return bsm_oop; |
1137 if (argc == 0 && UseBootstrapCallInfo < 2) return bsm_oop; |
1142 |
1138 |
1143 bsm = Handle(THREAD, bsm_oop); |
1139 bsm = Handle(THREAD, bsm_oop); |
1175 // because Java has stack overflow checking, so we punt |
1171 // because Java has stack overflow checking, so we punt |
1176 // potentially cyclic cases from C to Java. |
1172 // potentially cyclic cases from C to Java. |
1177 if (!use_BSCI && this_cp->tag_at(index).is_dynamic_constant()) { |
1173 if (!use_BSCI && this_cp->tag_at(index).is_dynamic_constant()) { |
1178 bool found_unresolved_condy = false; |
1174 bool found_unresolved_condy = false; |
1179 for (int i = 0; i < argc; i++) { |
1175 for (int i = 0; i < argc; i++) { |
1180 int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i); |
1176 int arg_index = this_cp->bootstrap_argument_index_at(index, i); |
1181 if (this_cp->tag_at(arg_index).is_dynamic_constant()) { |
1177 if (this_cp->tag_at(arg_index).is_dynamic_constant()) { |
1182 // potential recursion point condy -> condy |
1178 // potential recursion point condy -> condy |
1183 bool found_it = false; |
1179 bool found_it = false; |
1184 this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL); |
1180 this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL); |
1185 if (!found_it) { found_unresolved_condy = true; break; } |
1181 if (!found_it) { found_unresolved_condy = true; break; } |
1195 // push them, instead of asking the JDK runtime to turn around and |
1191 // push them, instead of asking the JDK runtime to turn around and |
1196 // pull them, saving a JVM/JDK transition in some simple cases. |
1192 // pull them, saving a JVM/JDK transition in some simple cases. |
1197 bool all_resolved = true; |
1193 bool all_resolved = true; |
1198 for (int i = 0; i < argc; i++) { |
1194 for (int i = 0; i < argc; i++) { |
1199 bool found_it = false; |
1195 bool found_it = false; |
1200 int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i); |
1196 int arg_index = this_cp->bootstrap_argument_index_at(index, i); |
1201 this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL); |
1197 this_cp->find_cached_constant_at(arg_index, found_it, CHECK_NULL); |
1202 if (!found_it) { all_resolved = false; break; } |
1198 if (!found_it) { all_resolved = false; break; } |
1203 } |
1199 } |
1204 if (all_resolved) |
1200 if (all_resolved) |
1205 use_BSCI = false; |
1201 use_BSCI = false; |
1242 // info array non-null, pos..limit in [0..info.length] |
1238 // info array non-null, pos..limit in [0..info.length] |
1243 if ((0 >= index || index >= this_cp->length()) || |
1239 if ((0 >= index || index >= this_cp->length()) || |
1244 !(this_cp->tag_at(index).is_invoke_dynamic() || |
1240 !(this_cp->tag_at(index).is_invoke_dynamic() || |
1245 this_cp->tag_at(index).is_dynamic_constant()) || |
1241 this_cp->tag_at(index).is_dynamic_constant()) || |
1246 (0 > start_arg || start_arg > end_arg) || |
1242 (0 > start_arg || start_arg > end_arg) || |
1247 (end_arg > (argc = this_cp->invoke_dynamic_argument_count_at(index))) || |
1243 (end_arg > (argc = this_cp->bootstrap_argument_count_at(index))) || |
1248 (0 > pos || pos > limit) || |
1244 (0 > pos || pos > limit) || |
1249 (info.is_null() || limit > info->length())) { |
1245 (info.is_null() || limit > info->length())) { |
1250 // An index or something else went wrong; throw an error. |
1246 // An index or something else went wrong; throw an error. |
1251 // Since this is an internal API, we don't expect this, |
1247 // Since this is an internal API, we don't expect this, |
1252 // so we don't bother to craft a nice message. |
1248 // so we don't bother to craft a nice message. |
1253 THROW_MSG(vmSymbols::java_lang_LinkageError(), "bad BSM argument access"); |
1249 THROW_MSG(vmSymbols::java_lang_LinkageError(), "bad BSM argument access"); |
1254 } |
1250 } |
1255 // now we can loop safely |
1251 // now we can loop safely |
1256 int info_i = pos; |
1252 int info_i = pos; |
1257 for (int i = start_arg; i < end_arg; i++) { |
1253 for (int i = start_arg; i < end_arg; i++) { |
1258 int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i); |
1254 int arg_index = this_cp->bootstrap_argument_index_at(index, i); |
1259 oop arg_oop; |
1255 oop arg_oop; |
1260 if (must_resolve) { |
1256 if (must_resolve) { |
1261 arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK); |
1257 arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK); |
1262 } else { |
1258 } else { |
1263 bool found_it = false; |
1259 bool found_it = false; |
1452 } |
1448 } |
1453 } break; |
1449 } break; |
1454 |
1450 |
1455 case JVM_CONSTANT_Dynamic: |
1451 case JVM_CONSTANT_Dynamic: |
1456 { |
1452 { |
1457 int k1 = invoke_dynamic_name_and_type_ref_index_at(index1); |
1453 int k1 = bootstrap_name_and_type_ref_index_at(index1); |
1458 int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); |
1454 int k2 = cp2->bootstrap_name_and_type_ref_index_at(index2); |
1459 int i1 = invoke_dynamic_bootstrap_specifier_index(index1); |
1455 int i1 = bootstrap_methods_attribute_index(index1); |
1460 int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2); |
1456 int i2 = cp2->bootstrap_methods_attribute_index(index2); |
1461 // separate statements and variables because CHECK_false is used |
1457 // separate statements and variables because CHECK_false is used |
1462 bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false); |
1458 bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false); |
1463 bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false); |
1459 bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false); |
1464 return (match_entry && match_operand); |
1460 return (match_entry && match_operand); |
1465 } break; |
1461 } break; |
1466 |
1462 |
1467 case JVM_CONSTANT_InvokeDynamic: |
1463 case JVM_CONSTANT_InvokeDynamic: |
1468 { |
1464 { |
1469 int k1 = invoke_dynamic_name_and_type_ref_index_at(index1); |
1465 int k1 = bootstrap_name_and_type_ref_index_at(index1); |
1470 int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); |
1466 int k2 = cp2->bootstrap_name_and_type_ref_index_at(index2); |
1471 int i1 = invoke_dynamic_bootstrap_specifier_index(index1); |
1467 int i1 = bootstrap_methods_attribute_index(index1); |
1472 int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2); |
1468 int i2 = cp2->bootstrap_methods_attribute_index(index2); |
1473 // separate statements and variables because CHECK_false is used |
1469 // separate statements and variables because CHECK_false is used |
1474 bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false); |
1470 bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false); |
1475 bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false); |
1471 bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false); |
1476 return (match_entry && match_operand); |
1472 return (match_entry && match_operand); |
1477 } break; |
1473 } break; |
1791 } break; |
1787 } break; |
1792 |
1788 |
1793 case JVM_CONSTANT_Dynamic: |
1789 case JVM_CONSTANT_Dynamic: |
1794 case JVM_CONSTANT_DynamicInError: |
1790 case JVM_CONSTANT_DynamicInError: |
1795 { |
1791 { |
1796 int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i); |
1792 int k1 = from_cp->bootstrap_methods_attribute_index(from_i); |
1797 int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i); |
1793 int k2 = from_cp->bootstrap_name_and_type_ref_index_at(from_i); |
1798 k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands |
1794 k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands |
1799 to_cp->dynamic_constant_at_put(to_i, k1, k2); |
1795 to_cp->dynamic_constant_at_put(to_i, k1, k2); |
1800 } break; |
1796 } break; |
1801 |
1797 |
1802 case JVM_CONSTANT_InvokeDynamic: |
1798 case JVM_CONSTANT_InvokeDynamic: |
1803 { |
1799 { |
1804 int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i); |
1800 int k1 = from_cp->bootstrap_methods_attribute_index(from_i); |
1805 int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i); |
1801 int k2 = from_cp->bootstrap_name_and_type_ref_index_at(from_i); |
1806 k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands |
1802 k1 += operand_array_length(to_cp->operands()); // to_cp might already have operands |
1807 to_cp->invoke_dynamic_at_put(to_i, k1, k2); |
1803 to_cp->invoke_dynamic_at_put(to_i, k1, k2); |
1808 } break; |
1804 } break; |
1809 |
1805 |
1810 // Invalid is used as the tag for the second constant pool entry |
1806 // Invalid is used as the tag for the second constant pool entry |
2250 case JVM_CONSTANT_Dynamic: |
2246 case JVM_CONSTANT_Dynamic: |
2251 case JVM_CONSTANT_DynamicInError: { |
2247 case JVM_CONSTANT_DynamicInError: { |
2252 *bytes = tag; |
2248 *bytes = tag; |
2253 idx1 = extract_low_short_from_int(*int_at_addr(idx)); |
2249 idx1 = extract_low_short_from_int(*int_at_addr(idx)); |
2254 idx2 = extract_high_short_from_int(*int_at_addr(idx)); |
2250 idx2 = extract_high_short_from_int(*int_at_addr(idx)); |
2255 assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4"); |
2251 assert(idx2 == bootstrap_name_and_type_ref_index_at(idx), "correct half of u4"); |
2256 Bytes::put_Java_u2((address) (bytes+1), idx1); |
2252 Bytes::put_Java_u2((address) (bytes+1), idx1); |
2257 Bytes::put_Java_u2((address) (bytes+3), idx2); |
2253 Bytes::put_Java_u2((address) (bytes+3), idx2); |
2258 DBG(printf("JVM_CONSTANT_Dynamic: %hd %hd", idx1, idx2)); |
2254 DBG(printf("JVM_CONSTANT_Dynamic: %hd %hd", idx1, idx2)); |
2259 break; |
2255 break; |
2260 } |
2256 } |
2261 case JVM_CONSTANT_InvokeDynamic: { |
2257 case JVM_CONSTANT_InvokeDynamic: { |
2262 *bytes = tag; |
2258 *bytes = tag; |
2263 idx1 = extract_low_short_from_int(*int_at_addr(idx)); |
2259 idx1 = extract_low_short_from_int(*int_at_addr(idx)); |
2264 idx2 = extract_high_short_from_int(*int_at_addr(idx)); |
2260 idx2 = extract_high_short_from_int(*int_at_addr(idx)); |
2265 assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4"); |
2261 assert(idx2 == bootstrap_name_and_type_ref_index_at(idx), "correct half of u4"); |
2266 Bytes::put_Java_u2((address) (bytes+1), idx1); |
2262 Bytes::put_Java_u2((address) (bytes+1), idx1); |
2267 Bytes::put_Java_u2((address) (bytes+3), idx2); |
2263 Bytes::put_Java_u2((address) (bytes+3), idx2); |
2268 DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2)); |
2264 DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2)); |
2269 break; |
2265 break; |
2270 } |
2266 } |
2441 st->print("signature_index=%d", method_type_index_at(index)); |
2437 st->print("signature_index=%d", method_type_index_at(index)); |
2442 break; |
2438 break; |
2443 case JVM_CONSTANT_Dynamic : |
2439 case JVM_CONSTANT_Dynamic : |
2444 case JVM_CONSTANT_DynamicInError : |
2440 case JVM_CONSTANT_DynamicInError : |
2445 { |
2441 { |
2446 st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index)); |
2442 st->print("bootstrap_method_index=%d", bootstrap_method_ref_index_at(index)); |
2447 st->print(" type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index)); |
2443 st->print(" type_index=%d", bootstrap_name_and_type_ref_index_at(index)); |
2448 int argc = invoke_dynamic_argument_count_at(index); |
2444 int argc = bootstrap_argument_count_at(index); |
2449 if (argc > 0) { |
2445 if (argc > 0) { |
2450 for (int arg_i = 0; arg_i < argc; arg_i++) { |
2446 for (int arg_i = 0; arg_i < argc; arg_i++) { |
2451 int arg = invoke_dynamic_argument_index_at(index, arg_i); |
2447 int arg = bootstrap_argument_index_at(index, arg_i); |
2452 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg); |
2448 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg); |
2453 } |
2449 } |
2454 st->print("}"); |
2450 st->print("}"); |
2455 } |
2451 } |
2456 } |
2452 } |
2457 break; |
2453 break; |
2458 case JVM_CONSTANT_InvokeDynamic : |
2454 case JVM_CONSTANT_InvokeDynamic : |
2459 { |
2455 { |
2460 st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index)); |
2456 st->print("bootstrap_method_index=%d", bootstrap_method_ref_index_at(index)); |
2461 st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index)); |
2457 st->print(" name_and_type_index=%d", bootstrap_name_and_type_ref_index_at(index)); |
2462 int argc = invoke_dynamic_argument_count_at(index); |
2458 int argc = bootstrap_argument_count_at(index); |
2463 if (argc > 0) { |
2459 if (argc > 0) { |
2464 for (int arg_i = 0; arg_i < argc; arg_i++) { |
2460 for (int arg_i = 0; arg_i < argc; arg_i++) { |
2465 int arg = invoke_dynamic_argument_index_at(index, arg_i); |
2461 int arg = bootstrap_argument_index_at(index, arg_i); |
2466 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg); |
2462 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg); |
2467 } |
2463 } |
2468 st->print("}"); |
2464 st->print("}"); |
2469 } |
2465 } |
2470 } |
2466 } |