41 #include "oops/constantPool.inline.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "oops/typeArrayOop.hpp"
45 #include "runtime/fieldDescriptor.hpp"
46 #include "runtime/handles.inline.hpp"
47 #include "runtime/interfaceSupport.inline.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/jniHandles.inline.hpp"
50 #include "runtime/orderAccess.hpp"
51 #include "runtime/os.hpp"
52 #include "runtime/safepointVerifiers.hpp"
53 #include "runtime/thread.hpp"
54 #include "services/threadService.hpp"
55 #include "utilities/align.hpp"
56 #include "utilities/bytes.hpp"
57
58 #define NOFAILOVER_MAJOR_VERSION 51
59 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
60 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
61 #define MAX_ARRAY_DIMENSIONS 255
62
63 // Access to external entry for VerifyClassCodes - old byte code verifier
64
65 extern "C" {
66 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
67 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
68 }
69
70 static void* volatile _verify_byte_codes_fn = NULL;
71
72 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
73
74 static void* verify_byte_codes_fn() {
75 if (OrderAccess::load_acquire(&_verify_byte_codes_fn) == NULL) {
76 void *lib_handle = os::native_java_library();
77 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
78 OrderAccess::release_store(&_verify_byte_codes_fn, func);
79 if (func == NULL) {
80 _is_new_verify_byte_codes_fn = false;
225 // to infinitely recurse when we try to initialize the exception.
226 // So bail out here by throwing the preallocated VM error.
227 THROW_OOP_(Universe::virtual_machine_error_instance(), false);
228 }
229 kls = kls->super();
230 }
231 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure
232 THROW_MSG_(exception_name, exception_message, false);
233 }
234 }
235
236 bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) {
237 Symbol* name = klass->name();
238 Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
239
240 bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
241
242 return (should_verify_for(klass->class_loader(), should_verify_class) &&
243 // return if the class is a bootstrapping class
244 // or defineClass specified not to verify by default (flags override passed arg)
245 // We need to skip the following four for bootstraping
246 name != vmSymbols::java_lang_Object() &&
247 name != vmSymbols::java_lang_Class() &&
248 name != vmSymbols::java_lang_String() &&
249 name != vmSymbols::java_lang_Throwable() &&
250
251 // Can not verify the bytecodes for shared classes because they have
252 // already been rewritten to contain constant pool cache indices,
253 // which the verifier can't understand.
254 // Shared classes shouldn't have stackmaps either.
255 !klass->is_shared() &&
256
257 // As of the fix for 4486457 we disable verification for all of the
258 // dynamically-generated bytecodes associated with the 1.4
259 // reflection implementation, not just those associated with
260 // jdk/internal/reflect/SerializationConstructorAccessor.
261 // NOTE: this is called too early in the bootstrapping process to be
262 // guarded by Universe::is_gte_jdk14x_version().
263 // Also for lambda generated code, gte jdk8
264 (!is_reflect));
265 }
456 ss->print("Local index %d is invalid", _type.index());
457 break;
458 case LOCALS_SIZE_MISMATCH:
459 ss->print("Current frame's local size doesn't match stackmap.");
460 break;
461 case STACK_SIZE_MISMATCH:
462 ss->print("Current frame's stack size doesn't match stackmap.");
463 break;
464 case STACK_OVERFLOW:
465 ss->print("Exceeded max stack size.");
466 break;
467 case STACK_UNDERFLOW:
468 ss->print("Attempt to pop empty stack.");
469 break;
470 case MISSING_STACKMAP:
471 ss->print("Expected stackmap frame at this location.");
472 break;
473 case BAD_STACKMAP:
474 ss->print("Invalid stackmap specification.");
475 break;
476 case UNKNOWN:
477 default:
478 ShouldNotReachHere();
479 ss->print_cr("Unknown");
480 }
481 ss->cr();
482 }
483
484 void ErrorContext::location_details(outputStream* ss, const Method* method) const {
485 if (_bci != -1 && method != NULL) {
486 streamIndentor si(ss);
487 const char* bytecode_name = "<invalid>";
488 if (method->validate_bci(_bci) != -1) {
489 Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci));
490 if (Bytecodes::is_defined(code)) {
491 bytecode_name = Bytecodes::name(code);
492 } else {
493 bytecode_name = "<illegal>";
494 }
495 }
550 stack_map_frame* sm_frame = sm_table->entries();
551 streamIndentor si2(ss);
552 int current_offset = -1;
553 address end_of_sm_table = (address)sm_table + method->stackmap_data()->length();
554 for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
555 ss->indent();
556 if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) {
557 sm_frame->print_truncated(ss, current_offset);
558 return;
559 }
560 sm_frame->print_on(ss, current_offset);
561 ss->cr();
562 current_offset += sm_frame->offset_delta();
563 sm_frame = sm_frame->next();
564 }
565 }
566 }
567
568 // Methods in ClassVerifier
569
570 ClassVerifier::ClassVerifier(
571 InstanceKlass* klass, TRAPS)
572 : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
573 _this_type = VerificationType::reference_type(klass->name());
574 // Create list to hold symbols in reference area.
575 _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
576 }
577
578 ClassVerifier::~ClassVerifier() {
579 // Decrement the reference count for any symbols created.
580 for (int i = 0; i < _symbols->length(); i++) {
581 Symbol* s = _symbols->at(i);
582 s->decrement_refcount();
583 }
584 }
585
586 VerificationType ClassVerifier::object_type() const {
587 return VerificationType::reference_type(vmSymbols::java_lang_Object());
588 }
589
590 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) {
591 VerificationType vt = VerificationType::reference_type(
592 create_temporary_symbol(sig, (int)strlen(sig), THREAD));
593 return TypeOrigin::implicit(vt);
943 case Bytecodes::_daload :
944 type = current_frame.pop_stack(
945 VerificationType::integer_type(), CHECK_VERIFY(this));
946 atype = current_frame.pop_stack(
947 VerificationType::reference_check(), CHECK_VERIFY(this));
948 if (!atype.is_double_array()) {
949 verify_error(ErrorContext::bad_type(bci,
950 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
951 bad_type_msg, "daload");
952 return;
953 }
954 current_frame.push_stack_2(
955 VerificationType::double_type(),
956 VerificationType::double2_type(), CHECK_VERIFY(this));
957 no_control_flow = false; break;
958 case Bytecodes::_aaload : {
959 type = current_frame.pop_stack(
960 VerificationType::integer_type(), CHECK_VERIFY(this));
961 atype = current_frame.pop_stack(
962 VerificationType::reference_check(), CHECK_VERIFY(this));
963 if (!atype.is_reference_array()) {
964 verify_error(ErrorContext::bad_type(bci,
965 current_frame.stack_top_ctx(),
966 TypeOrigin::implicit(VerificationType::reference_check())),
967 bad_type_msg, "aaload");
968 return;
969 }
970 if (atype.is_null()) {
971 current_frame.push_stack(
972 VerificationType::null_type(), CHECK_VERIFY(this));
973 } else {
974 VerificationType component =
975 atype.get_component(this, CHECK_VERIFY(this));
976 current_frame.push_stack(component, CHECK_VERIFY(this));
977 }
978 no_control_flow = false; break;
979 }
980 case Bytecodes::_istore :
981 verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
982 no_control_flow = false; break;
983 case Bytecodes::_istore_0 :
1117 VerificationType::double2_type(),
1118 VerificationType::double_type(), CHECK_VERIFY(this));
1119 current_frame.pop_stack(
1120 VerificationType::integer_type(), CHECK_VERIFY(this));
1121 atype = current_frame.pop_stack(
1122 VerificationType::reference_check(), CHECK_VERIFY(this));
1123 if (!atype.is_double_array()) {
1124 verify_error(ErrorContext::bad_type(bci,
1125 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
1126 bad_type_msg, "dastore");
1127 return;
1128 }
1129 no_control_flow = false; break;
1130 case Bytecodes::_aastore :
1131 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1132 type2 = current_frame.pop_stack(
1133 VerificationType::integer_type(), CHECK_VERIFY(this));
1134 atype = current_frame.pop_stack(
1135 VerificationType::reference_check(), CHECK_VERIFY(this));
1136 // more type-checking is done at runtime
1137 if (!atype.is_reference_array()) {
1138 verify_error(ErrorContext::bad_type(bci,
1139 current_frame.stack_top_ctx(),
1140 TypeOrigin::implicit(VerificationType::reference_check())),
1141 bad_type_msg, "aastore");
1142 return;
1143 }
1144 // 4938384: relaxed constraint in JVMS 3nd edition.
1145 no_control_flow = false; break;
1146 case Bytecodes::_pop :
1147 current_frame.pop_stack(
1148 VerificationType::category1_check(), CHECK_VERIFY(this));
1149 no_control_flow = false; break;
1150 case Bytecodes::_pop2 :
1151 type = current_frame.pop_stack(CHECK_VERIFY(this));
1152 if (type.is_category1()) {
1153 current_frame.pop_stack(
1154 VerificationType::category1_check(), CHECK_VERIFY(this));
1155 } else if (type.is_category2_2nd()) {
1156 current_frame.pop_stack(
1157 VerificationType::category2_check(), CHECK_VERIFY(this));
1517 case Bytecodes::_if_icmpgt:
1518 case Bytecodes::_if_icmple:
1519 current_frame.pop_stack(
1520 VerificationType::integer_type(), CHECK_VERIFY(this));
1521 // fall through
1522 case Bytecodes::_ifeq:
1523 case Bytecodes::_ifne:
1524 case Bytecodes::_iflt:
1525 case Bytecodes::_ifge:
1526 case Bytecodes::_ifgt:
1527 case Bytecodes::_ifle:
1528 current_frame.pop_stack(
1529 VerificationType::integer_type(), CHECK_VERIFY(this));
1530 target = bcs.dest();
1531 stackmap_table.check_jump_target(
1532 ¤t_frame, target, CHECK_VERIFY(this));
1533 no_control_flow = false; break;
1534 case Bytecodes::_if_acmpeq :
1535 case Bytecodes::_if_acmpne :
1536 current_frame.pop_stack(
1537 VerificationType::reference_check(), CHECK_VERIFY(this));
1538 // fall through
1539 case Bytecodes::_ifnull :
1540 case Bytecodes::_ifnonnull :
1541 current_frame.pop_stack(
1542 VerificationType::reference_check(), CHECK_VERIFY(this));
1543 target = bcs.dest();
1544 stackmap_table.check_jump_target
1545 (¤t_frame, target, CHECK_VERIFY(this));
1546 no_control_flow = false; break;
1547 case Bytecodes::_goto :
1548 target = bcs.dest();
1549 stackmap_table.check_jump_target(
1550 ¤t_frame, target, CHECK_VERIFY(this));
1551 no_control_flow = true; break;
1552 case Bytecodes::_goto_w :
1553 target = bcs.dest_w();
1554 stackmap_table.check_jump_target(
1555 ¤t_frame, target, CHECK_VERIFY(this));
1556 no_control_flow = true; break;
1557 case Bytecodes::_tableswitch :
1558 case Bytecodes::_lookupswitch :
1559 verify_switch(
1560 &bcs, code_length, code_data, ¤t_frame,
1561 &stackmap_table, CHECK_VERIFY(this));
1562 no_control_flow = true; break;
1573 VerificationType::long_type(), CHECK_VERIFY(this));
1574 verify_return_value(return_type, type, bci,
1575 ¤t_frame, CHECK_VERIFY(this));
1576 no_control_flow = true; break;
1577 case Bytecodes::_freturn :
1578 type = current_frame.pop_stack(
1579 VerificationType::float_type(), CHECK_VERIFY(this));
1580 verify_return_value(return_type, type, bci,
1581 ¤t_frame, CHECK_VERIFY(this));
1582 no_control_flow = true; break;
1583 case Bytecodes::_dreturn :
1584 type2 = current_frame.pop_stack(
1585 VerificationType::double2_type(), CHECK_VERIFY(this));
1586 type = current_frame.pop_stack(
1587 VerificationType::double_type(), CHECK_VERIFY(this));
1588 verify_return_value(return_type, type, bci,
1589 ¤t_frame, CHECK_VERIFY(this));
1590 no_control_flow = true; break;
1591 case Bytecodes::_areturn :
1592 type = current_frame.pop_stack(
1593 VerificationType::reference_check(), CHECK_VERIFY(this));
1594 verify_return_value(return_type, type, bci,
1595 ¤t_frame, CHECK_VERIFY(this));
1596 no_control_flow = true; break;
1597 case Bytecodes::_return :
1598 if (return_type != VerificationType::bogus_type()) {
1599 verify_error(ErrorContext::bad_code(bci),
1600 "Method expects a return value");
1601 return;
1602 }
1603 // Make sure "this" has been initialized if current method is an
1604 // <init>.
1605 if (_method->name() == vmSymbols::object_initializer_name() &&
1606 current_frame.flag_this_uninit()) {
1607 verify_error(ErrorContext::bad_code(bci),
1608 "Constructor must call super() or this() "
1609 "before return");
1610 return;
1611 }
1612 no_control_flow = true; break;
1613 case Bytecodes::_getstatic :
1614 case Bytecodes::_putstatic :
1615 // pass TRUE, operand can be an array type for getstatic/putstatic.
1616 verify_field_instructions(
1617 &bcs, ¤t_frame, cp, true, CHECK_VERIFY(this));
1618 no_control_flow = false; break;
1619 case Bytecodes::_getfield :
1620 case Bytecodes::_putfield :
1621 // pass FALSE, operand can't be an array type for getfield/putfield.
1622 verify_field_instructions(
1623 &bcs, ¤t_frame, cp, false, CHECK_VERIFY(this));
1624 no_control_flow = false; break;
1625 case Bytecodes::_invokevirtual :
1626 case Bytecodes::_invokespecial :
1627 case Bytecodes::_invokestatic :
1628 verify_invoke_instructions(
1629 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
1630 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
1631 no_control_flow = false; break;
1632 case Bytecodes::_invokeinterface :
1633 case Bytecodes::_invokedynamic :
1634 verify_invoke_instructions(
1635 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
1636 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
1637 no_control_flow = false; break;
1638 case Bytecodes::_new :
1639 {
1640 index = bcs.get_index_u2();
1641 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1642 VerificationType new_class_type =
1643 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1644 if (!new_class_type.is_object()) {
1645 verify_error(ErrorContext::bad_type(bci,
1646 TypeOrigin::cp(index, new_class_type)),
1647 "Illegal new instruction");
1648 return;
1649 }
1650 type = VerificationType::uninitialized_type(bci);
1651 current_frame.push_stack(type, CHECK_VERIFY(this));
1652 no_control_flow = false; break;
1653 }
1654 case Bytecodes::_newarray :
1655 type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
1656 current_frame.pop_stack(
1657 VerificationType::integer_type(), CHECK_VERIFY(this));
1658 current_frame.push_stack(type, CHECK_VERIFY(this));
1659 no_control_flow = false; break;
1660 case Bytecodes::_anewarray :
1661 verify_anewarray(
1662 bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this));
1663 no_control_flow = false; break;
1664 case Bytecodes::_arraylength :
1665 type = current_frame.pop_stack(
1666 VerificationType::reference_check(), CHECK_VERIFY(this));
1667 if (!(type.is_null() || type.is_array())) {
1668 verify_error(ErrorContext::bad_type(
1669 bci, current_frame.stack_top_ctx()),
1670 bad_type_msg, "arraylength");
1671 }
1672 current_frame.push_stack(
1673 VerificationType::integer_type(), CHECK_VERIFY(this));
1674 no_control_flow = false; break;
1675 case Bytecodes::_checkcast :
1676 {
1677 index = bcs.get_index_u2();
1678 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1679 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1680 VerificationType klass_type = cp_index_to_type(
1681 index, cp, CHECK_VERIFY(this));
1682 current_frame.push_stack(klass_type, CHECK_VERIFY(this));
1683 no_control_flow = false; break;
1684 }
1685 case Bytecodes::_instanceof : {
1686 index = bcs.get_index_u2();
1687 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1688 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1689 current_frame.push_stack(
1690 VerificationType::integer_type(), CHECK_VERIFY(this));
1691 no_control_flow = false; break;
1692 }
1693 case Bytecodes::_monitorenter :
1694 case Bytecodes::_monitorexit :
1695 current_frame.pop_stack(
1696 VerificationType::reference_check(), CHECK_VERIFY(this));
1697 no_control_flow = false; break;
1698 case Bytecodes::_multianewarray :
1699 {
1700 index = bcs.get_index_u2();
1701 u2 dim = *(bcs.bcp()+3);
1702 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1703 VerificationType new_array_type =
1704 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1705 if (!new_array_type.is_array()) {
1706 verify_error(ErrorContext::bad_type(bci,
1707 TypeOrigin::cp(index, new_array_type)),
1708 "Illegal constant pool index in multianewarray instruction");
1709 return;
1710 }
1711 if (dim < 1 || new_array_type.dimensions() < dim) {
1712 verify_error(ErrorContext::bad_code(bci),
1713 "Illegal dimension in multianewarray instruction: %d", dim);
1714 return;
1715 }
1716 for (int i = 0; i < dim; i++) {
1717 current_frame.pop_stack(
1936 int nconstants = cp->length();
1937 if ((index <= 0) || (index >= nconstants)) {
1938 verify_error(ErrorContext::bad_cp_index(bci, index),
1939 "Illegal constant pool index %d in class %s",
1940 index, cp->pool_holder()->external_name());
1941 return;
1942 }
1943 }
1944
1945 void ClassVerifier::verify_cp_type(
1946 u2 bci, int index, const constantPoolHandle& cp, unsigned int types, TRAPS) {
1947
1948 // In some situations, bytecode rewriting may occur while we're verifying.
1949 // In this case, a constant pool cache exists and some indices refer to that
1950 // instead. Be sure we don't pick up such indices by accident.
1951 // We must check was_recursively_verified() before we get here.
1952 guarantee(cp->cache() == NULL, "not rewritten yet");
1953
1954 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
1955 unsigned int tag = cp->tag_at(index).value();
1956 if ((types & (1 << tag)) == 0) {
1957 verify_error(ErrorContext::bad_cp_index(bci, index),
1958 "Illegal type at constant pool entry %d in class %s",
1959 index, cp->pool_holder()->external_name());
1960 return;
1961 }
1962 }
1963
1964 void ClassVerifier::verify_cp_class_type(
1965 u2 bci, int index, const constantPoolHandle& cp, TRAPS) {
1966 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
1967 constantTag tag = cp->tag_at(index);
1968 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
1969 verify_error(ErrorContext::bad_cp_index(bci, index),
1970 "Illegal type at constant pool entry %d in class %s",
1971 index, cp->pool_holder()->external_name());
1972 return;
1973 }
1974 }
1975
2236 Symbol* field_sig = cp->signature_ref_at(index);
2237
2238 if (!SignatureVerifier::is_valid_type_signature(field_sig)) {
2239 class_format_error(
2240 "Invalid signature for field in class %s referenced "
2241 "from constant pool index %d", _klass->external_name(), index);
2242 return;
2243 }
2244
2245 // Get referenced class type
2246 VerificationType ref_class_type = cp_ref_index_to_type(
2247 index, cp, CHECK_VERIFY(this));
2248 if (!ref_class_type.is_object() &&
2249 (!allow_arrays || !ref_class_type.is_array())) {
2250 verify_error(ErrorContext::bad_type(bcs->bci(),
2251 TypeOrigin::cp(index, ref_class_type)),
2252 "Expecting reference to class in class %s at constant pool index %d",
2253 _klass->external_name(), index);
2254 return;
2255 }
2256 VerificationType target_class_type = ref_class_type;
2257
2258 assert(sizeof(VerificationType) == sizeof(uintptr_t),
2259 "buffer type must match VerificationType size");
2260 uintptr_t field_type_buffer[2];
2261 VerificationType* field_type = (VerificationType*)field_type_buffer;
2262 // If we make a VerificationType[2] array directly, the compiler calls
2263 // to the c-runtime library to do the allocation instead of just
2264 // stack allocating it. Plus it would run constructors. This shows up
2265 // in performance profiles.
2266
2267 SignatureStream sig_stream(field_sig, false);
2268 VerificationType stack_object_type;
2269 int n = change_sig_to_verificationType(
2270 &sig_stream, field_type, CHECK_VERIFY(this));
2271 u2 bci = bcs->bci();
2272 bool is_assignable;
2273 switch (bcs->raw_code()) {
2274 case Bytecodes::_getstatic: {
2275 for (int i = 0; i < n; i++) {
2276 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
2277 }
2278 break;
2279 }
2280 case Bytecodes::_putstatic: {
2281 for (int i = n - 1; i >= 0; i--) {
2282 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
2283 }
2284 break;
2285 }
2286 case Bytecodes::_getfield: {
2287 stack_object_type = current_frame->pop_stack(
2288 target_class_type, CHECK_VERIFY(this));
2289 for (int i = 0; i < n; i++) {
2290 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
2291 }
2292 goto check_protected;
2293 }
2294 case Bytecodes::_putfield: {
2295 for (int i = n - 1; i >= 0; i--) {
2296 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
2297 }
2298 stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this));
2299
2300 // The JVMS 2nd edition allows field initialization before the superclass
2301 // initializer, if the field is defined within the current class.
2302 fieldDescriptor fd;
2303 if (stack_object_type == VerificationType::uninitialized_this_type() &&
2304 target_class_type.equals(current_type()) &&
2305 _klass->find_local_field(field_name, field_sig, &fd)) {
2709 types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ?
2710 (1 << JVM_CONSTANT_Methodref) :
2711 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref));
2712 break;
2713 default:
2714 types = 1 << JVM_CONSTANT_Methodref;
2715 }
2716 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this));
2717
2718 // Get method name and signature
2719 Symbol* method_name = cp->name_ref_at(index);
2720 Symbol* method_sig = cp->signature_ref_at(index);
2721
2722 if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
2723 class_format_error(
2724 "Invalid method signature in class %s referenced "
2725 "from constant pool index %d", _klass->external_name(), index);
2726 return;
2727 }
2728
2729 // Get referenced class type
2730 VerificationType ref_class_type;
2731 if (opcode == Bytecodes::_invokedynamic) {
2732 if (_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2733 class_format_error(
2734 "invokedynamic instructions not supported by this class file version (%d), class %s",
2735 _klass->major_version(), _klass->external_name());
2736 return;
2737 }
2738 } else {
2739 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
2740 }
2741
2742 // For a small signature length, we just allocate 128 bytes instead
2743 // of parsing the signature once to find its size.
2744 // -3 is for '(', ')' and return descriptor; multiply by 2 is for
2745 // longs/doubles to be consertive.
2746 assert(sizeof(VerificationType) == sizeof(uintptr_t),
2747 "buffer type must match VerificationType size");
2748 uintptr_t on_stack_sig_types_buffer[128];
2749 // If we make a VerificationType[128] array directly, the compiler calls
2801 if (opcode == Bytecodes::_invokedynamic) {
2802 address bcp = bcs->bcp();
2803 if (*(bcp+3) != 0 || *(bcp+4) != 0) {
2804 verify_error(ErrorContext::bad_code(bci),
2805 "Third and fourth operand bytes of invokedynamic must be zero");
2806 return;
2807 }
2808 }
2809
2810 if (method_name->char_at(0) == '<') {
2811 // Make sure <init> can only be invoked by invokespecial
2812 if (opcode != Bytecodes::_invokespecial ||
2813 method_name != vmSymbols::object_initializer_name()) {
2814 verify_error(ErrorContext::bad_code(bci),
2815 "Illegal call to internal method");
2816 return;
2817 }
2818 } else if (opcode == Bytecodes::_invokespecial
2819 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type)
2820 && !ref_class_type.equals(VerificationType::reference_type(
2821 current_class()->super()->name()))) {
2822 bool subtype = false;
2823 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
2824 if (!current_class()->is_unsafe_anonymous()) {
2825 subtype = ref_class_type.is_assignable_from(
2826 current_type(), this, false, CHECK_VERIFY(this));
2827 } else {
2828 VerificationType unsafe_anonymous_host_type =
2829 VerificationType::reference_type(current_class()->unsafe_anonymous_host()->name());
2830 subtype = ref_class_type.is_assignable_from(unsafe_anonymous_host_type, this, false, CHECK_VERIFY(this));
2831
2832 // If invokespecial of IMR, need to recheck for same or
2833 // direct interface relative to the host class
2834 have_imr_indirect = (have_imr_indirect &&
2835 !is_same_or_direct_interface(
2836 current_class()->unsafe_anonymous_host(),
2837 unsafe_anonymous_host_type, ref_class_type));
2838 }
2839 if (!subtype) {
2840 verify_error(ErrorContext::bad_code(bci),
2841 "Bad invokespecial instruction: "
2842 "current class isn't assignable to reference class.");
2843 return;
2844 } else if (have_imr_indirect) {
2845 verify_error(ErrorContext::bad_code(bci),
2846 "Bad invokespecial instruction: "
2847 "interface method reference is in an indirect superinterface.");
2848 return;
2849 }
2850
2851 }
2852 // Match method descriptor with operand stack
2853 for (int i = nargs - 1; i >= 0; i--) { // Run backwards
2854 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
2855 }
2856 // Check objectref on operand stack
2857 if (opcode != Bytecodes::_invokestatic &&
2858 opcode != Bytecodes::_invokedynamic) {
2859 if (method_name == vmSymbols::object_initializer_name()) { // <init> method
2860 verify_invoke_init(bcs, index, ref_class_type, current_frame,
2861 code_length, in_try_block, this_uninit, cp, stackmap_table,
2862 CHECK_VERIFY(this));
2863 if (was_recursively_verified()) return;
2864 } else { // other methods
2865 // Ensures that target class is assignable to method class.
2866 if (opcode == Bytecodes::_invokespecial) {
2867 if (!current_class()->is_unsafe_anonymous()) {
2868 current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
2869 } else {
2870 // anonymous class invokespecial calls: check if the
2871 // objectref is a subtype of the unsafe_anonymous_host of the current class
2872 // to allow an anonymous class to reference methods in the unsafe_anonymous_host
2873 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
2874 VerificationType hosttype =
2875 VerificationType::reference_type(current_class()->unsafe_anonymous_host()->name());
2876 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
2877 if (!subtype) {
2878 verify_error( ErrorContext::bad_type(current_frame->offset(),
2879 current_frame->stack_top_ctx(),
2880 TypeOrigin::implicit(top)),
2881 "Bad type on operand stack");
2882 return;
2883 }
2884 }
2885 } else if (opcode == Bytecodes::_invokevirtual) {
2886 VerificationType stack_object_type =
2887 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
2888 if (current_type() != stack_object_type) {
2889 if (was_recursively_verified()) return;
2890 assert(cp->cache() == NULL, "not rewritten yet");
2891 Symbol* ref_class_name =
2892 cp->klass_name_at(cp->klass_ref_index_at(index));
2893 // See the comments in verify_field_instructions() for
2894 // the rationale behind this.
2895 if (name_in_supers(ref_class_name, current_class())) {
2896 Klass* ref_class = load_class(ref_class_name, CHECK);
2969 VerificationType component_type =
2970 cp_index_to_type(index, cp, CHECK_VERIFY(this));
2971 int length;
2972 char* arr_sig_str;
2973 if (component_type.is_array()) { // it's an array
2974 const char* component_name = component_type.name()->as_utf8();
2975 // Check for more than MAX_ARRAY_DIMENSIONS
2976 length = (int)strlen(component_name);
2977 if (length > MAX_ARRAY_DIMENSIONS &&
2978 component_name[MAX_ARRAY_DIMENSIONS - 1] == '[') {
2979 verify_error(ErrorContext::bad_code(bci),
2980 "Illegal anewarray instruction, array has more than 255 dimensions");
2981 }
2982 // add one dimension to component
2983 length++;
2984 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
2985 int n = os::snprintf(arr_sig_str, length + 1, "[%s", component_name);
2986 assert(n == length, "Unexpected number of characters in string");
2987 } else { // it's an object or interface
2988 const char* component_name = component_type.name()->as_utf8();
2989 // add one dimension to component with 'L' prepended and ';' postpended.
2990 length = (int)strlen(component_name) + 3;
2991 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
2992 int n = os::snprintf(arr_sig_str, length + 1, "[L%s;", component_name);
2993 assert(n == length, "Unexpected number of characters in string");
2994 }
2995 Symbol* arr_sig = create_temporary_symbol(
2996 arr_sig_str, length, CHECK_VERIFY(this));
2997 VerificationType new_array_type = VerificationType::reference_type(arr_sig);
2998 current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
2999 }
3000
3001 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) {
3002 current_frame->get_local(
3003 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3004 current_frame->push_stack(
3005 VerificationType::integer_type(), CHECK_VERIFY(this));
3006 }
3007
3008 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) {
3009 current_frame->get_local_2(
3010 index, VerificationType::long_type(),
3011 VerificationType::long2_type(), CHECK_VERIFY(this));
3012 current_frame->push_stack_2(
3015 }
3016
3017 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) {
3018 current_frame->get_local(
3019 index, VerificationType::float_type(), CHECK_VERIFY(this));
3020 current_frame->push_stack(
3021 VerificationType::float_type(), CHECK_VERIFY(this));
3022 }
3023
3024 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) {
3025 current_frame->get_local_2(
3026 index, VerificationType::double_type(),
3027 VerificationType::double2_type(), CHECK_VERIFY(this));
3028 current_frame->push_stack_2(
3029 VerificationType::double_type(),
3030 VerificationType::double2_type(), CHECK_VERIFY(this));
3031 }
3032
3033 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) {
3034 VerificationType type = current_frame->get_local(
3035 index, VerificationType::reference_check(), CHECK_VERIFY(this));
3036 current_frame->push_stack(type, CHECK_VERIFY(this));
3037 }
3038
3039 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) {
3040 current_frame->pop_stack(
3041 VerificationType::integer_type(), CHECK_VERIFY(this));
3042 current_frame->set_local(
3043 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3044 }
3045
3046 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3047 current_frame->pop_stack_2(
3048 VerificationType::long2_type(),
3049 VerificationType::long_type(), CHECK_VERIFY(this));
3050 current_frame->set_local_2(
3051 index, VerificationType::long_type(),
3052 VerificationType::long2_type(), CHECK_VERIFY(this));
3053 }
3054
3055 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3056 current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this));
3057 current_frame->set_local(
3058 index, VerificationType::float_type(), CHECK_VERIFY(this));
3059 }
3060
3061 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3062 current_frame->pop_stack_2(
3063 VerificationType::double2_type(),
3064 VerificationType::double_type(), CHECK_VERIFY(this));
3065 current_frame->set_local_2(
3066 index, VerificationType::double_type(),
3067 VerificationType::double2_type(), CHECK_VERIFY(this));
3068 }
3069
3070 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) {
3071 VerificationType type = current_frame->pop_stack(
3072 VerificationType::reference_check(), CHECK_VERIFY(this));
3073 current_frame->set_local(index, type, CHECK_VERIFY(this));
3074 }
3075
3076 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) {
3077 VerificationType type = current_frame->get_local(
3078 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3079 current_frame->set_local(index, type, CHECK_VERIFY(this));
3080 }
3081
3082 void ClassVerifier::verify_return_value(
3083 VerificationType return_type, VerificationType type, u2 bci,
3084 StackMapFrame* current_frame, TRAPS) {
3085 if (return_type == VerificationType::bogus_type()) {
3086 verify_error(ErrorContext::bad_type(bci,
3087 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
3088 "Method expects a return value");
3089 return;
3090 }
3091 bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this));
3092 if (!match) {
|
41 #include "oops/constantPool.inline.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "oops/typeArrayOop.hpp"
45 #include "runtime/fieldDescriptor.hpp"
46 #include "runtime/handles.inline.hpp"
47 #include "runtime/interfaceSupport.inline.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/jniHandles.inline.hpp"
50 #include "runtime/orderAccess.hpp"
51 #include "runtime/os.hpp"
52 #include "runtime/safepointVerifiers.hpp"
53 #include "runtime/thread.hpp"
54 #include "services/threadService.hpp"
55 #include "utilities/align.hpp"
56 #include "utilities/bytes.hpp"
57
58 #define NOFAILOVER_MAJOR_VERSION 51
59 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
60 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
61 #define VALUETYPE_MAJOR_VERSION 56
62 #define MAX_ARRAY_DIMENSIONS 255
63
64 // Access to external entry for VerifyClassCodes - old byte code verifier
65
66 extern "C" {
67 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
68 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
69 }
70
71 static void* volatile _verify_byte_codes_fn = NULL;
72
73 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
74
75 static void* verify_byte_codes_fn() {
76 if (OrderAccess::load_acquire(&_verify_byte_codes_fn) == NULL) {
77 void *lib_handle = os::native_java_library();
78 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
79 OrderAccess::release_store(&_verify_byte_codes_fn, func);
80 if (func == NULL) {
81 _is_new_verify_byte_codes_fn = false;
226 // to infinitely recurse when we try to initialize the exception.
227 // So bail out here by throwing the preallocated VM error.
228 THROW_OOP_(Universe::virtual_machine_error_instance(), false);
229 }
230 kls = kls->super();
231 }
232 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure
233 THROW_MSG_(exception_name, exception_message, false);
234 }
235 }
236
237 bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) {
238 Symbol* name = klass->name();
239 Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
240
241 bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
242
243 return (should_verify_for(klass->class_loader(), should_verify_class) &&
244 // return if the class is a bootstrapping class
245 // or defineClass specified not to verify by default (flags override passed arg)
246 // We need to skip the following four for bootstrapping
247 name != vmSymbols::java_lang_Object() &&
248 name != vmSymbols::java_lang_Class() &&
249 name != vmSymbols::java_lang_String() &&
250 name != vmSymbols::java_lang_Throwable() &&
251
252 // Can not verify the bytecodes for shared classes because they have
253 // already been rewritten to contain constant pool cache indices,
254 // which the verifier can't understand.
255 // Shared classes shouldn't have stackmaps either.
256 !klass->is_shared() &&
257
258 // As of the fix for 4486457 we disable verification for all of the
259 // dynamically-generated bytecodes associated with the 1.4
260 // reflection implementation, not just those associated with
261 // jdk/internal/reflect/SerializationConstructorAccessor.
262 // NOTE: this is called too early in the bootstrapping process to be
263 // guarded by Universe::is_gte_jdk14x_version().
264 // Also for lambda generated code, gte jdk8
265 (!is_reflect));
266 }
457 ss->print("Local index %d is invalid", _type.index());
458 break;
459 case LOCALS_SIZE_MISMATCH:
460 ss->print("Current frame's local size doesn't match stackmap.");
461 break;
462 case STACK_SIZE_MISMATCH:
463 ss->print("Current frame's stack size doesn't match stackmap.");
464 break;
465 case STACK_OVERFLOW:
466 ss->print("Exceeded max stack size.");
467 break;
468 case STACK_UNDERFLOW:
469 ss->print("Attempt to pop empty stack.");
470 break;
471 case MISSING_STACKMAP:
472 ss->print("Expected stackmap frame at this location.");
473 break;
474 case BAD_STACKMAP:
475 ss->print("Invalid stackmap specification.");
476 break;
477 case WRONG_VALUE_TYPE:
478 ss->print("Type ");
479 _type.details(ss);
480 ss->print(" and type ");
481 _expected.details(ss);
482 ss->print(" must be identical value types.");
483 break;
484 case UNKNOWN:
485 default:
486 ShouldNotReachHere();
487 ss->print_cr("Unknown");
488 }
489 ss->cr();
490 }
491
492 void ErrorContext::location_details(outputStream* ss, const Method* method) const {
493 if (_bci != -1 && method != NULL) {
494 streamIndentor si(ss);
495 const char* bytecode_name = "<invalid>";
496 if (method->validate_bci(_bci) != -1) {
497 Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci));
498 if (Bytecodes::is_defined(code)) {
499 bytecode_name = Bytecodes::name(code);
500 } else {
501 bytecode_name = "<illegal>";
502 }
503 }
558 stack_map_frame* sm_frame = sm_table->entries();
559 streamIndentor si2(ss);
560 int current_offset = -1;
561 address end_of_sm_table = (address)sm_table + method->stackmap_data()->length();
562 for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
563 ss->indent();
564 if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) {
565 sm_frame->print_truncated(ss, current_offset);
566 return;
567 }
568 sm_frame->print_on(ss, current_offset);
569 ss->cr();
570 current_offset += sm_frame->offset_delta();
571 sm_frame = sm_frame->next();
572 }
573 }
574 }
575
576 // Methods in ClassVerifier
577
578 VerificationType reference_or_valuetype(InstanceKlass* klass) {
579 if (klass->is_value()) {
580 return VerificationType::valuetype_type(klass->name());
581 } else {
582 return VerificationType::reference_type(klass->name());
583 }
584 }
585
586 ClassVerifier::ClassVerifier(
587 InstanceKlass* klass, TRAPS)
588 : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
589 _this_type = reference_or_valuetype(klass);
590 // Create list to hold symbols in reference area.
591 _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
592 }
593
594 ClassVerifier::~ClassVerifier() {
595 // Decrement the reference count for any symbols created.
596 for (int i = 0; i < _symbols->length(); i++) {
597 Symbol* s = _symbols->at(i);
598 s->decrement_refcount();
599 }
600 }
601
602 VerificationType ClassVerifier::object_type() const {
603 return VerificationType::reference_type(vmSymbols::java_lang_Object());
604 }
605
606 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) {
607 VerificationType vt = VerificationType::reference_type(
608 create_temporary_symbol(sig, (int)strlen(sig), THREAD));
609 return TypeOrigin::implicit(vt);
959 case Bytecodes::_daload :
960 type = current_frame.pop_stack(
961 VerificationType::integer_type(), CHECK_VERIFY(this));
962 atype = current_frame.pop_stack(
963 VerificationType::reference_check(), CHECK_VERIFY(this));
964 if (!atype.is_double_array()) {
965 verify_error(ErrorContext::bad_type(bci,
966 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
967 bad_type_msg, "daload");
968 return;
969 }
970 current_frame.push_stack_2(
971 VerificationType::double_type(),
972 VerificationType::double2_type(), CHECK_VERIFY(this));
973 no_control_flow = false; break;
974 case Bytecodes::_aaload : {
975 type = current_frame.pop_stack(
976 VerificationType::integer_type(), CHECK_VERIFY(this));
977 atype = current_frame.pop_stack(
978 VerificationType::reference_check(), CHECK_VERIFY(this));
979 if (!atype.is_nonscalar_array()) {
980 verify_error(ErrorContext::bad_type(bci,
981 current_frame.stack_top_ctx(),
982 TypeOrigin::implicit(VerificationType::reference_check())),
983 bad_type_msg, "aaload");
984 return;
985 }
986 if (atype.is_null()) {
987 current_frame.push_stack(
988 VerificationType::null_type(), CHECK_VERIFY(this));
989 } else {
990 VerificationType component =
991 atype.get_component(this, CHECK_VERIFY(this));
992 current_frame.push_stack(component, CHECK_VERIFY(this));
993 }
994 no_control_flow = false; break;
995 }
996 case Bytecodes::_istore :
997 verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
998 no_control_flow = false; break;
999 case Bytecodes::_istore_0 :
1133 VerificationType::double2_type(),
1134 VerificationType::double_type(), CHECK_VERIFY(this));
1135 current_frame.pop_stack(
1136 VerificationType::integer_type(), CHECK_VERIFY(this));
1137 atype = current_frame.pop_stack(
1138 VerificationType::reference_check(), CHECK_VERIFY(this));
1139 if (!atype.is_double_array()) {
1140 verify_error(ErrorContext::bad_type(bci,
1141 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
1142 bad_type_msg, "dastore");
1143 return;
1144 }
1145 no_control_flow = false; break;
1146 case Bytecodes::_aastore :
1147 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1148 type2 = current_frame.pop_stack(
1149 VerificationType::integer_type(), CHECK_VERIFY(this));
1150 atype = current_frame.pop_stack(
1151 VerificationType::reference_check(), CHECK_VERIFY(this));
1152 // more type-checking is done at runtime
1153 if (!atype.is_nonscalar_array()) {
1154 verify_error(ErrorContext::bad_type(bci,
1155 current_frame.stack_top_ctx(),
1156 TypeOrigin::implicit(VerificationType::reference_check())),
1157 bad_type_msg, "aastore");
1158 return;
1159 }
1160 // 4938384: relaxed constraint in JVMS 3nd edition.
1161 no_control_flow = false; break;
1162 case Bytecodes::_pop :
1163 current_frame.pop_stack(
1164 VerificationType::category1_check(), CHECK_VERIFY(this));
1165 no_control_flow = false; break;
1166 case Bytecodes::_pop2 :
1167 type = current_frame.pop_stack(CHECK_VERIFY(this));
1168 if (type.is_category1()) {
1169 current_frame.pop_stack(
1170 VerificationType::category1_check(), CHECK_VERIFY(this));
1171 } else if (type.is_category2_2nd()) {
1172 current_frame.pop_stack(
1173 VerificationType::category2_check(), CHECK_VERIFY(this));
1533 case Bytecodes::_if_icmpgt:
1534 case Bytecodes::_if_icmple:
1535 current_frame.pop_stack(
1536 VerificationType::integer_type(), CHECK_VERIFY(this));
1537 // fall through
1538 case Bytecodes::_ifeq:
1539 case Bytecodes::_ifne:
1540 case Bytecodes::_iflt:
1541 case Bytecodes::_ifge:
1542 case Bytecodes::_ifgt:
1543 case Bytecodes::_ifle:
1544 current_frame.pop_stack(
1545 VerificationType::integer_type(), CHECK_VERIFY(this));
1546 target = bcs.dest();
1547 stackmap_table.check_jump_target(
1548 ¤t_frame, target, CHECK_VERIFY(this));
1549 no_control_flow = false; break;
1550 case Bytecodes::_if_acmpeq :
1551 case Bytecodes::_if_acmpne :
1552 current_frame.pop_stack(
1553 VerificationType::nonscalar_check(), CHECK_VERIFY(this));
1554 // fall through
1555 case Bytecodes::_ifnull :
1556 case Bytecodes::_ifnonnull :
1557 current_frame.pop_stack(
1558 VerificationType::nonscalar_check(), CHECK_VERIFY(this));
1559 target = bcs.dest();
1560 stackmap_table.check_jump_target
1561 (¤t_frame, target, CHECK_VERIFY(this));
1562 no_control_flow = false; break;
1563 case Bytecodes::_goto :
1564 target = bcs.dest();
1565 stackmap_table.check_jump_target(
1566 ¤t_frame, target, CHECK_VERIFY(this));
1567 no_control_flow = true; break;
1568 case Bytecodes::_goto_w :
1569 target = bcs.dest_w();
1570 stackmap_table.check_jump_target(
1571 ¤t_frame, target, CHECK_VERIFY(this));
1572 no_control_flow = true; break;
1573 case Bytecodes::_tableswitch :
1574 case Bytecodes::_lookupswitch :
1575 verify_switch(
1576 &bcs, code_length, code_data, ¤t_frame,
1577 &stackmap_table, CHECK_VERIFY(this));
1578 no_control_flow = true; break;
1589 VerificationType::long_type(), CHECK_VERIFY(this));
1590 verify_return_value(return_type, type, bci,
1591 ¤t_frame, CHECK_VERIFY(this));
1592 no_control_flow = true; break;
1593 case Bytecodes::_freturn :
1594 type = current_frame.pop_stack(
1595 VerificationType::float_type(), CHECK_VERIFY(this));
1596 verify_return_value(return_type, type, bci,
1597 ¤t_frame, CHECK_VERIFY(this));
1598 no_control_flow = true; break;
1599 case Bytecodes::_dreturn :
1600 type2 = current_frame.pop_stack(
1601 VerificationType::double2_type(), CHECK_VERIFY(this));
1602 type = current_frame.pop_stack(
1603 VerificationType::double_type(), CHECK_VERIFY(this));
1604 verify_return_value(return_type, type, bci,
1605 ¤t_frame, CHECK_VERIFY(this));
1606 no_control_flow = true; break;
1607 case Bytecodes::_areturn :
1608 type = current_frame.pop_stack(
1609 VerificationType::nonscalar_check(), CHECK_VERIFY(this));
1610 verify_return_value(return_type, type, bci,
1611 ¤t_frame, CHECK_VERIFY(this));
1612 no_control_flow = true; break;
1613 case Bytecodes::_return :
1614 if (return_type != VerificationType::bogus_type()) {
1615 verify_error(ErrorContext::bad_code(bci),
1616 "Method expects a return value");
1617 return;
1618 }
1619 // Make sure "this" has been initialized if current method is an
1620 // <init>.
1621 if (_method->name() == vmSymbols::object_initializer_name() &&
1622 current_frame.flag_this_uninit()) {
1623 verify_error(ErrorContext::bad_code(bci),
1624 "Constructor must call super() or this() "
1625 "before return");
1626 return;
1627 }
1628 no_control_flow = true; break;
1629 case Bytecodes::_getstatic :
1630 case Bytecodes::_putstatic :
1631 // pass TRUE, operand can be an array type for getstatic/putstatic.
1632 verify_field_instructions(
1633 &bcs, ¤t_frame, cp, true, CHECK_VERIFY(this));
1634 no_control_flow = false; break;
1635 case Bytecodes::_getfield :
1636 case Bytecodes::_putfield :
1637 // pass FALSE, operand can't be an array type for getfield/putfield.
1638 verify_field_instructions(
1639 &bcs, ¤t_frame, cp, false, CHECK_VERIFY(this));
1640 no_control_flow = false; break;
1641 case Bytecodes::_withfield :
1642 if (_klass->major_version() < VALUETYPE_MAJOR_VERSION) {
1643 class_format_error(
1644 "withfield not supported by this class file version (%d.%d), class %s",
1645 _klass->major_version(), _klass->minor_version(), _klass->external_name());
1646 return;
1647 }
1648 // pass FALSE, operand can't be an array type for withfield.
1649 verify_field_instructions(
1650 &bcs, ¤t_frame, cp, false, CHECK_VERIFY(this));
1651 no_control_flow = false; break;
1652 case Bytecodes::_invokevirtual :
1653 case Bytecodes::_invokespecial :
1654 case Bytecodes::_invokestatic :
1655 verify_invoke_instructions(
1656 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
1657 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
1658 no_control_flow = false; break;
1659 case Bytecodes::_invokeinterface :
1660 case Bytecodes::_invokedynamic :
1661 verify_invoke_instructions(
1662 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
1663 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
1664 no_control_flow = false; break;
1665 case Bytecodes::_new :
1666 {
1667 index = bcs.get_index_u2();
1668 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1669 VerificationType new_class_type =
1670 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1671 if (!new_class_type.is_object()) {
1672 verify_error(ErrorContext::bad_type(bci,
1673 TypeOrigin::cp(index, new_class_type)),
1674 "Illegal new instruction");
1675 return;
1676 }
1677 type = VerificationType::uninitialized_type(bci);
1678 current_frame.push_stack(type, CHECK_VERIFY(this));
1679 no_control_flow = false; break;
1680 }
1681 case Bytecodes::_defaultvalue :
1682 {
1683 if (_klass->major_version() < VALUETYPE_MAJOR_VERSION) {
1684 class_format_error(
1685 "defaultvalue not supported by this class file version (%d.%d), class %s",
1686 _klass->major_version(), _klass->minor_version(), _klass->external_name());
1687 return;
1688 }
1689 index = bcs.get_index_u2();
1690 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1691 VerificationType ref_type = cp_index_to_type(index, cp, CHECK_VERIFY(this));
1692 if (!ref_type.is_object()) {
1693 verify_error(ErrorContext::bad_type(bci,
1694 TypeOrigin::cp(index, ref_type)),
1695 "Illegal defaultvalue instruction");
1696 return;
1697 }
1698 VerificationType value_type =
1699 VerificationType::change_ref_to_valuetype(ref_type);
1700 current_frame.push_stack(value_type, CHECK_VERIFY(this));
1701 no_control_flow = false; break;
1702 }
1703 case Bytecodes::_newarray :
1704 type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
1705 current_frame.pop_stack(
1706 VerificationType::integer_type(), CHECK_VERIFY(this));
1707 current_frame.push_stack(type, CHECK_VERIFY(this));
1708 no_control_flow = false; break;
1709 case Bytecodes::_anewarray :
1710 verify_anewarray(
1711 bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this));
1712 no_control_flow = false; break;
1713 case Bytecodes::_arraylength :
1714 type = current_frame.pop_stack(
1715 VerificationType::reference_check(), CHECK_VERIFY(this));
1716 if (!(type.is_null() || type.is_array())) {
1717 verify_error(ErrorContext::bad_type(
1718 bci, current_frame.stack_top_ctx()),
1719 bad_type_msg, "arraylength");
1720 }
1721 current_frame.push_stack(
1722 VerificationType::integer_type(), CHECK_VERIFY(this));
1723 no_control_flow = false; break;
1724 case Bytecodes::_checkcast :
1725 {
1726 index = bcs.get_index_u2();
1727 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1728 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1729 VerificationType klass_type = cp_index_to_type(
1730 index, cp, CHECK_VERIFY(this));
1731 current_frame.push_stack(klass_type, CHECK_VERIFY(this));
1732 no_control_flow = false; break;
1733 }
1734 case Bytecodes::_instanceof : {
1735 index = bcs.get_index_u2();
1736 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1737 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
1738 current_frame.push_stack(
1739 VerificationType::integer_type(), CHECK_VERIFY(this));
1740 no_control_flow = false; break;
1741 }
1742 case Bytecodes::_monitorenter :
1743 case Bytecodes::_monitorexit : {
1744 VerificationType ref = current_frame.pop_stack(
1745 VerificationType::reference_check(), CHECK_VERIFY(this));
1746 no_control_flow = false; break;
1747 }
1748 case Bytecodes::_multianewarray :
1749 {
1750 index = bcs.get_index_u2();
1751 u2 dim = *(bcs.bcp()+3);
1752 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
1753 VerificationType new_array_type =
1754 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1755 if (!new_array_type.is_array()) {
1756 verify_error(ErrorContext::bad_type(bci,
1757 TypeOrigin::cp(index, new_array_type)),
1758 "Illegal constant pool index in multianewarray instruction");
1759 return;
1760 }
1761 if (dim < 1 || new_array_type.dimensions() < dim) {
1762 verify_error(ErrorContext::bad_code(bci),
1763 "Illegal dimension in multianewarray instruction: %d", dim);
1764 return;
1765 }
1766 for (int i = 0; i < dim; i++) {
1767 current_frame.pop_stack(
1986 int nconstants = cp->length();
1987 if ((index <= 0) || (index >= nconstants)) {
1988 verify_error(ErrorContext::bad_cp_index(bci, index),
1989 "Illegal constant pool index %d in class %s",
1990 index, cp->pool_holder()->external_name());
1991 return;
1992 }
1993 }
1994
1995 void ClassVerifier::verify_cp_type(
1996 u2 bci, int index, const constantPoolHandle& cp, unsigned int types, TRAPS) {
1997
1998 // In some situations, bytecode rewriting may occur while we're verifying.
1999 // In this case, a constant pool cache exists and some indices refer to that
2000 // instead. Be sure we don't pick up such indices by accident.
2001 // We must check was_recursively_verified() before we get here.
2002 guarantee(cp->cache() == NULL, "not rewritten yet");
2003
2004 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
2005 unsigned int tag = cp->tag_at(index).value();
2006
2007 if ((types & (1 << tag)) == 0) {
2008 verify_error(ErrorContext::bad_cp_index(bci, index),
2009 "Illegal type at constant pool entry %d in class %s",
2010 index, cp->pool_holder()->external_name());
2011 return;
2012 }
2013 }
2014
2015 void ClassVerifier::verify_cp_class_type(
2016 u2 bci, int index, const constantPoolHandle& cp, TRAPS) {
2017 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
2018 constantTag tag = cp->tag_at(index);
2019 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
2020 verify_error(ErrorContext::bad_cp_index(bci, index),
2021 "Illegal type at constant pool entry %d in class %s",
2022 index, cp->pool_holder()->external_name());
2023 return;
2024 }
2025 }
2026
2287 Symbol* field_sig = cp->signature_ref_at(index);
2288
2289 if (!SignatureVerifier::is_valid_type_signature(field_sig)) {
2290 class_format_error(
2291 "Invalid signature for field in class %s referenced "
2292 "from constant pool index %d", _klass->external_name(), index);
2293 return;
2294 }
2295
2296 // Get referenced class type
2297 VerificationType ref_class_type = cp_ref_index_to_type(
2298 index, cp, CHECK_VERIFY(this));
2299 if (!ref_class_type.is_object() &&
2300 (!allow_arrays || !ref_class_type.is_array())) {
2301 verify_error(ErrorContext::bad_type(bcs->bci(),
2302 TypeOrigin::cp(index, ref_class_type)),
2303 "Expecting reference to class in class %s at constant pool index %d",
2304 _klass->external_name(), index);
2305 return;
2306 }
2307
2308 VerificationType target_class_type = ref_class_type;
2309
2310 assert(sizeof(VerificationType) == sizeof(uintptr_t),
2311 "buffer type must match VerificationType size");
2312 uintptr_t field_type_buffer[2];
2313 VerificationType* field_type = (VerificationType*)field_type_buffer;
2314 // If we make a VerificationType[2] array directly, the compiler calls
2315 // to the c-runtime library to do the allocation instead of just
2316 // stack allocating it. Plus it would run constructors. This shows up
2317 // in performance profiles.
2318
2319 SignatureStream sig_stream(field_sig, false);
2320 VerificationType stack_object_type;
2321 int n = change_sig_to_verificationType(
2322 &sig_stream, field_type, CHECK_VERIFY(this));
2323 u2 bci = bcs->bci();
2324 bool is_assignable;
2325 switch (bcs->raw_code()) {
2326 case Bytecodes::_getstatic: {
2327 for (int i = 0; i < n; i++) {
2328 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
2329 }
2330 break;
2331 }
2332 case Bytecodes::_putstatic: {
2333 for (int i = n - 1; i >= 0; i--) {
2334 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
2335 }
2336 break;
2337 }
2338 case Bytecodes::_withfield: {
2339 for (int i = n - 1; i >= 0; i--) {
2340 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
2341 }
2342 // stack_object_type and target_class_type must be the same value type.
2343 stack_object_type =
2344 current_frame->pop_stack(VerificationType::valuetype_check(), CHECK_VERIFY(this));
2345 VerificationType target_value_type =
2346 VerificationType::change_ref_to_valuetype(target_class_type);
2347 if (!stack_object_type.equals(target_value_type)) {
2348 verify_error(ErrorContext::bad_value_type(bci,
2349 current_frame->stack_top_ctx(),
2350 TypeOrigin::cp(index, target_class_type)),
2351 "Invalid type on operand stack in withfield instruction");
2352 return;
2353 }
2354 current_frame->push_stack(target_value_type, CHECK_VERIFY(this));
2355 break;
2356 }
2357 case Bytecodes::_getfield: {
2358 stack_object_type = current_frame->pop_stack(
2359 target_class_type, CHECK_VERIFY(this));
2360 for (int i = 0; i < n; i++) {
2361 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
2362 }
2363 goto check_protected;
2364 }
2365 case Bytecodes::_putfield: {
2366 for (int i = n - 1; i >= 0; i--) {
2367 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
2368 }
2369 stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this));
2370
2371 // The JVMS 2nd edition allows field initialization before the superclass
2372 // initializer, if the field is defined within the current class.
2373 fieldDescriptor fd;
2374 if (stack_object_type == VerificationType::uninitialized_this_type() &&
2375 target_class_type.equals(current_type()) &&
2376 _klass->find_local_field(field_name, field_sig, &fd)) {
2780 types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ?
2781 (1 << JVM_CONSTANT_Methodref) :
2782 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref));
2783 break;
2784 default:
2785 types = 1 << JVM_CONSTANT_Methodref;
2786 }
2787 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this));
2788
2789 // Get method name and signature
2790 Symbol* method_name = cp->name_ref_at(index);
2791 Symbol* method_sig = cp->signature_ref_at(index);
2792
2793 if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
2794 class_format_error(
2795 "Invalid method signature in class %s referenced "
2796 "from constant pool index %d", _klass->external_name(), index);
2797 return;
2798 }
2799
2800 // Get referenced class
2801 VerificationType ref_class_type;
2802 if (opcode == Bytecodes::_invokedynamic) {
2803 if (_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2804 class_format_error(
2805 "invokedynamic instructions not supported by this class file version (%d), class %s",
2806 _klass->major_version(), _klass->external_name());
2807 return;
2808 }
2809 } else {
2810 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
2811 }
2812
2813 // For a small signature length, we just allocate 128 bytes instead
2814 // of parsing the signature once to find its size.
2815 // -3 is for '(', ')' and return descriptor; multiply by 2 is for
2816 // longs/doubles to be consertive.
2817 assert(sizeof(VerificationType) == sizeof(uintptr_t),
2818 "buffer type must match VerificationType size");
2819 uintptr_t on_stack_sig_types_buffer[128];
2820 // If we make a VerificationType[128] array directly, the compiler calls
2872 if (opcode == Bytecodes::_invokedynamic) {
2873 address bcp = bcs->bcp();
2874 if (*(bcp+3) != 0 || *(bcp+4) != 0) {
2875 verify_error(ErrorContext::bad_code(bci),
2876 "Third and fourth operand bytes of invokedynamic must be zero");
2877 return;
2878 }
2879 }
2880
2881 if (method_name->char_at(0) == '<') {
2882 // Make sure <init> can only be invoked by invokespecial
2883 if (opcode != Bytecodes::_invokespecial ||
2884 method_name != vmSymbols::object_initializer_name()) {
2885 verify_error(ErrorContext::bad_code(bci),
2886 "Illegal call to internal method");
2887 return;
2888 }
2889 } else if (opcode == Bytecodes::_invokespecial
2890 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type)
2891 && !ref_class_type.equals(VerificationType::reference_type(
2892 current_class()->super()->name()))) { // super() can never be a value_type.
2893 bool subtype = false;
2894 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
2895 if (!current_class()->is_unsafe_anonymous()) {
2896 subtype = ref_class_type.is_assignable_from(
2897 current_type(), this, false, CHECK_VERIFY(this));
2898 } else {
2899 InstanceKlass* unsafe_host = current_class()->unsafe_anonymous_host();
2900 VerificationType unsafe_anonymous_host_type = reference_or_valuetype(unsafe_host);
2901 subtype = ref_class_type.is_assignable_from(unsafe_anonymous_host_type, this, false, CHECK_VERIFY(this));
2902
2903 // If invokespecial of IMR, need to recheck for same or
2904 // direct interface relative to the host class
2905 have_imr_indirect = (have_imr_indirect &&
2906 !is_same_or_direct_interface(
2907 unsafe_host,
2908 unsafe_anonymous_host_type, ref_class_type));
2909 }
2910 if (!subtype) {
2911 verify_error(ErrorContext::bad_code(bci),
2912 "Bad invokespecial instruction: "
2913 "current class isn't assignable to reference class.");
2914 return;
2915 } else if (have_imr_indirect) {
2916 verify_error(ErrorContext::bad_code(bci),
2917 "Bad invokespecial instruction: "
2918 "interface method reference is in an indirect superinterface.");
2919 return;
2920 }
2921
2922 }
2923 // Match method descriptor with operand stack
2924 for (int i = nargs - 1; i >= 0; i--) { // Run backwards
2925 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
2926 }
2927 // Check objectref on operand stack
2928 if (opcode != Bytecodes::_invokestatic &&
2929 opcode != Bytecodes::_invokedynamic) {
2930 if (method_name == vmSymbols::object_initializer_name()) { // <init> method
2931 verify_invoke_init(bcs, index, ref_class_type, current_frame,
2932 code_length, in_try_block, this_uninit, cp, stackmap_table,
2933 CHECK_VERIFY(this));
2934 if (was_recursively_verified()) return;
2935 } else { // other methods
2936 // Ensures that target class is assignable to method class.
2937 if (opcode == Bytecodes::_invokespecial) {
2938 if (!current_class()->is_unsafe_anonymous()) {
2939 current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
2940 } else {
2941 // anonymous class invokespecial calls: check if the
2942 // objectref is a subtype of the unsafe_anonymous_host of the current class
2943 // to allow an anonymous class to reference methods in the unsafe_anonymous_host
2944 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
2945
2946 InstanceKlass* unsafe_host = current_class()->unsafe_anonymous_host();
2947 VerificationType host_type = reference_or_valuetype(unsafe_host);
2948 bool subtype = host_type.is_assignable_from(top, this, false, CHECK_VERIFY(this));
2949 if (!subtype) {
2950 verify_error( ErrorContext::bad_type(current_frame->offset(),
2951 current_frame->stack_top_ctx(),
2952 TypeOrigin::implicit(top)),
2953 "Bad type on operand stack");
2954 return;
2955 }
2956 }
2957 } else if (opcode == Bytecodes::_invokevirtual) {
2958 VerificationType stack_object_type =
2959 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
2960 if (current_type() != stack_object_type) {
2961 if (was_recursively_verified()) return;
2962 assert(cp->cache() == NULL, "not rewritten yet");
2963 Symbol* ref_class_name =
2964 cp->klass_name_at(cp->klass_ref_index_at(index));
2965 // See the comments in verify_field_instructions() for
2966 // the rationale behind this.
2967 if (name_in_supers(ref_class_name, current_class())) {
2968 Klass* ref_class = load_class(ref_class_name, CHECK);
3041 VerificationType component_type =
3042 cp_index_to_type(index, cp, CHECK_VERIFY(this));
3043 int length;
3044 char* arr_sig_str;
3045 if (component_type.is_array()) { // it's an array
3046 const char* component_name = component_type.name()->as_utf8();
3047 // Check for more than MAX_ARRAY_DIMENSIONS
3048 length = (int)strlen(component_name);
3049 if (length > MAX_ARRAY_DIMENSIONS &&
3050 component_name[MAX_ARRAY_DIMENSIONS - 1] == '[') {
3051 verify_error(ErrorContext::bad_code(bci),
3052 "Illegal anewarray instruction, array has more than 255 dimensions");
3053 }
3054 // add one dimension to component
3055 length++;
3056 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
3057 int n = os::snprintf(arr_sig_str, length + 1, "[%s", component_name);
3058 assert(n == length, "Unexpected number of characters in string");
3059 } else { // it's an object or interface
3060 const char* component_name = component_type.name()->as_utf8();
3061 char Q_or_L = component_type.is_valuetype() ? 'Q' : 'L';
3062 // add one dimension to component with 'L' or 'Q' prepended and ';' appended.
3063 length = (int)strlen(component_name) + 3;
3064 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
3065 int n = os::snprintf(arr_sig_str, length + 1, "[%c%s;", Q_or_L, component_name);
3066 assert(n == length, "Unexpected number of characters in string");
3067 }
3068 Symbol* arr_sig = create_temporary_symbol(
3069 arr_sig_str, length, CHECK_VERIFY(this));
3070 VerificationType new_array_type = VerificationType::reference_type(arr_sig);
3071 current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
3072 }
3073
3074 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) {
3075 current_frame->get_local(
3076 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3077 current_frame->push_stack(
3078 VerificationType::integer_type(), CHECK_VERIFY(this));
3079 }
3080
3081 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) {
3082 current_frame->get_local_2(
3083 index, VerificationType::long_type(),
3084 VerificationType::long2_type(), CHECK_VERIFY(this));
3085 current_frame->push_stack_2(
3088 }
3089
3090 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) {
3091 current_frame->get_local(
3092 index, VerificationType::float_type(), CHECK_VERIFY(this));
3093 current_frame->push_stack(
3094 VerificationType::float_type(), CHECK_VERIFY(this));
3095 }
3096
3097 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) {
3098 current_frame->get_local_2(
3099 index, VerificationType::double_type(),
3100 VerificationType::double2_type(), CHECK_VERIFY(this));
3101 current_frame->push_stack_2(
3102 VerificationType::double_type(),
3103 VerificationType::double2_type(), CHECK_VERIFY(this));
3104 }
3105
3106 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) {
3107 VerificationType type = current_frame->get_local(
3108 index, VerificationType::nonscalar_check(), CHECK_VERIFY(this));
3109 current_frame->push_stack(type, CHECK_VERIFY(this));
3110 }
3111
3112 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) {
3113 current_frame->pop_stack(
3114 VerificationType::integer_type(), CHECK_VERIFY(this));
3115 current_frame->set_local(
3116 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3117 }
3118
3119 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3120 current_frame->pop_stack_2(
3121 VerificationType::long2_type(),
3122 VerificationType::long_type(), CHECK_VERIFY(this));
3123 current_frame->set_local_2(
3124 index, VerificationType::long_type(),
3125 VerificationType::long2_type(), CHECK_VERIFY(this));
3126 }
3127
3128 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3129 current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this));
3130 current_frame->set_local(
3131 index, VerificationType::float_type(), CHECK_VERIFY(this));
3132 }
3133
3134 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) {
3135 current_frame->pop_stack_2(
3136 VerificationType::double2_type(),
3137 VerificationType::double_type(), CHECK_VERIFY(this));
3138 current_frame->set_local_2(
3139 index, VerificationType::double_type(),
3140 VerificationType::double2_type(), CHECK_VERIFY(this));
3141 }
3142
3143 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) {
3144 VerificationType type = current_frame->pop_stack(
3145 VerificationType::nonscalar_check(), CHECK_VERIFY(this));
3146 current_frame->set_local(index, type, CHECK_VERIFY(this));
3147 }
3148
3149 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) {
3150 VerificationType type = current_frame->get_local(
3151 index, VerificationType::integer_type(), CHECK_VERIFY(this));
3152 current_frame->set_local(index, type, CHECK_VERIFY(this));
3153 }
3154
3155 void ClassVerifier::verify_return_value(
3156 VerificationType return_type, VerificationType type, u2 bci,
3157 StackMapFrame* current_frame, TRAPS) {
3158 if (return_type == VerificationType::bogus_type()) {
3159 verify_error(ErrorContext::bad_type(bci,
3160 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
3161 "Method expects a return value");
3162 return;
3163 }
3164 bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this));
3165 if (!match) {
|