aoqi@0: /* coleenp@9530: * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/classFileStream.hpp" aoqi@0: #include "classfile/javaClasses.hpp" aoqi@0: #include "classfile/stackMapTable.hpp" aoqi@0: #include "classfile/stackMapFrame.hpp" aoqi@0: #include "classfile/stackMapTableFormat.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "classfile/verifier.hpp" aoqi@0: #include "classfile/vmSymbols.hpp" aoqi@0: #include "interpreter/bytecodes.hpp" aoqi@0: #include "interpreter/bytecodeStream.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "memory/resourceArea.hpp" aoqi@0: #include "oops/instanceKlass.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/typeArrayOop.hpp" aoqi@0: #include "prims/jvm.h" aoqi@0: #include "runtime/fieldDescriptor.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/interfaceSupport.hpp" aoqi@0: #include "runtime/javaCalls.hpp" goetz@6911: #include "runtime/orderAccess.inline.hpp" aoqi@0: #include "runtime/os.hpp" aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "bytes_x86.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "bytes_mips.hpp" aoqi@1: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "bytes_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "bytes_zero.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "bytes_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "bytes_ppc.hpp" aoqi@0: #endif aoqi@0: aoqi@0: #define NOFAILOVER_MAJOR_VERSION 51 aoqi@0: #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51 aoqi@0: #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52 aoqi@0: aoqi@0: // Access to external entry for VerifyClassCodes - old byte code verifier aoqi@0: aoqi@0: extern "C" { aoqi@0: typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); aoqi@0: typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint); aoqi@0: } aoqi@0: aoqi@0: static void* volatile _verify_byte_codes_fn = NULL; aoqi@0: aoqi@0: static volatile jint _is_new_verify_byte_codes_fn = (jint) true; aoqi@0: aoqi@0: static void* verify_byte_codes_fn() { aoqi@0: if (_verify_byte_codes_fn == NULL) { aoqi@0: void *lib_handle = os::native_java_library(); aoqi@0: void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); aoqi@0: OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); aoqi@0: if (func == NULL) { aoqi@0: OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false); aoqi@0: func = os::dll_lookup(lib_handle, "VerifyClassCodes"); aoqi@0: OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); aoqi@0: } aoqi@0: } aoqi@0: return (void*)_verify_byte_codes_fn; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Methods in Verifier aoqi@0: aoqi@0: bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { aoqi@0: return (class_loader == NULL || !should_verify_class) ? aoqi@0: BytecodeVerificationLocal : BytecodeVerificationRemote; aoqi@0: } aoqi@0: aoqi@0: bool Verifier::relax_verify_for(oop loader) { aoqi@0: bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); aoqi@0: bool need_verify = aoqi@0: // verifyAll aoqi@0: (BytecodeVerificationLocal && BytecodeVerificationRemote) || aoqi@0: // verifyRemote aoqi@0: (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); aoqi@0: return !need_verify; aoqi@0: } aoqi@0: aoqi@0: bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { aoqi@0: HandleMark hm; aoqi@0: ResourceMark rm(THREAD); aoqi@0: aoqi@0: Symbol* exception_name = NULL; aoqi@0: const size_t message_buffer_len = klass->name()->utf8_length() + 1024; aoqi@0: char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); aoqi@0: char* exception_message = message_buffer; aoqi@0: aoqi@0: const char* klassName = klass->external_name(); aoqi@0: bool can_failover = FailOverToOldVerifier && aoqi@0: klass->major_version() < NOFAILOVER_MAJOR_VERSION; aoqi@0: aoqi@0: // If the class should be verified, first see if we can use the split aoqi@0: // verifier. If not, or if verification fails and FailOverToOldVerifier aoqi@0: // is set, then call the inference verifier. aoqi@0: if (is_eligible_for_verification(klass, should_verify_class)) { aoqi@0: if (TraceClassInitialization) { aoqi@0: tty->print_cr("Start class verification for: %s", klassName); aoqi@0: } aoqi@0: if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { aoqi@0: ClassVerifier split_verifier(klass, THREAD); aoqi@0: split_verifier.verify_class(THREAD); aoqi@0: exception_name = split_verifier.result(); aoqi@0: if (can_failover && !HAS_PENDING_EXCEPTION && aoqi@0: (exception_name == vmSymbols::java_lang_VerifyError() || aoqi@0: exception_name == vmSymbols::java_lang_ClassFormatError())) { aoqi@0: if (TraceClassInitialization || VerboseVerification) { aoqi@0: tty->print_cr( aoqi@0: "Fail over class verification to old verifier for: %s", klassName); aoqi@0: } aoqi@0: exception_name = inference_verify( aoqi@0: klass, message_buffer, message_buffer_len, THREAD); aoqi@0: } aoqi@0: if (exception_name != NULL) { aoqi@0: exception_message = split_verifier.exception_message(); aoqi@0: } aoqi@0: } else { aoqi@0: exception_name = inference_verify( aoqi@0: klass, message_buffer, message_buffer_len, THREAD); aoqi@0: } aoqi@0: aoqi@0: if (TraceClassInitialization || VerboseVerification) { aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: tty->print("Verification for %s has", klassName); aoqi@0: tty->print_cr(" exception pending %s ", aoqi@0: InstanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); aoqi@0: } else if (exception_name != NULL) { aoqi@0: tty->print_cr("Verification for %s failed", klassName); aoqi@0: } aoqi@0: tty->print_cr("End class verification for: %s", klassName); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: return false; // use the existing exception aoqi@0: } else if (exception_name == NULL) { aoqi@0: return true; // verifcation succeeded aoqi@0: } else { // VerifyError or ClassFormatError to be created and thrown aoqi@0: ResourceMark rm(THREAD); aoqi@0: instanceKlassHandle kls = aoqi@0: SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); aoqi@0: while (!kls.is_null()) { aoqi@0: if (kls == klass) { aoqi@0: // If the class being verified is the exception we're creating aoqi@0: // or one of it's superclasses, we're in trouble and are going aoqi@0: // to infinitely recurse when we try to initialize the exception. aoqi@0: // So bail out here by throwing the preallocated VM error. aoqi@0: THROW_OOP_(Universe::virtual_machine_error_instance(), false); aoqi@0: } aoqi@0: kls = kls->super(); aoqi@0: } aoqi@0: message_buffer[message_buffer_len - 1] = '\0'; // just to be sure aoqi@0: THROW_MSG_(exception_name, exception_message, false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { aoqi@0: Symbol* name = klass->name(); aoqi@0: Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass(); aoqi@0: aoqi@0: bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass); aoqi@0: aoqi@0: return (should_verify_for(klass->class_loader(), should_verify_class) && aoqi@0: // return if the class is a bootstrapping class aoqi@0: // or defineClass specified not to verify by default (flags override passed arg) aoqi@0: // We need to skip the following four for bootstraping aoqi@0: name != vmSymbols::java_lang_Object() && aoqi@0: name != vmSymbols::java_lang_Class() && aoqi@0: name != vmSymbols::java_lang_String() && aoqi@0: name != vmSymbols::java_lang_Throwable() && aoqi@0: aoqi@0: // Can not verify the bytecodes for shared classes because they have aoqi@0: // already been rewritten to contain constant pool cache indices, aoqi@0: // which the verifier can't understand. aoqi@0: // Shared classes shouldn't have stackmaps either. aoqi@0: !klass()->is_shared() && aoqi@0: aoqi@0: // As of the fix for 4486457 we disable verification for all of the aoqi@0: // dynamically-generated bytecodes associated with the 1.4 aoqi@0: // reflection implementation, not just those associated with aoqi@0: // sun/reflect/SerializationConstructorAccessor. aoqi@0: // NOTE: this is called too early in the bootstrapping process to be aoqi@0: // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection. aoqi@0: // Also for lambda generated code, gte jdk8 aoqi@0: (!is_reflect || VerifyReflectionBytecodes)); aoqi@0: } aoqi@0: aoqi@0: Symbol* Verifier::inference_verify( aoqi@0: instanceKlassHandle klass, char* message, size_t message_len, TRAPS) { aoqi@0: JavaThread* thread = (JavaThread*)THREAD; aoqi@0: JNIEnv *env = thread->jni_environment(); aoqi@0: aoqi@0: void* verify_func = verify_byte_codes_fn(); aoqi@0: aoqi@0: if (verify_func == NULL) { aoqi@0: jio_snprintf(message, message_len, "Could not link verifier"); aoqi@0: return vmSymbols::java_lang_VerifyError(); aoqi@0: } aoqi@0: aoqi@0: ResourceMark rm(THREAD); aoqi@0: if (VerboseVerification) { aoqi@0: tty->print_cr("Verifying class %s with old format", klass->external_name()); aoqi@0: } aoqi@0: aoqi@0: jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); aoqi@0: jint result; aoqi@0: aoqi@0: { aoqi@0: HandleMark hm(thread); aoqi@0: ThreadToNativeFromVM ttn(thread); aoqi@0: // ThreadToNativeFromVM takes care of changing thread_state, so safepoint aoqi@0: // code knows that we have left the VM aoqi@0: aoqi@0: if (_is_new_verify_byte_codes_fn) { aoqi@0: verify_byte_codes_fn_new_t func = aoqi@0: CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func); aoqi@0: result = (*func)(env, cls, message, (int)message_len, aoqi@0: klass->major_version()); aoqi@0: } else { aoqi@0: verify_byte_codes_fn_t func = aoqi@0: CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func); aoqi@0: result = (*func)(env, cls, message, (int)message_len); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: JNIHandles::destroy_local(cls); aoqi@0: aoqi@0: // These numbers are chosen so that VerifyClassCodes interface doesn't need aoqi@0: // to be changed (still return jboolean (unsigned char)), and result is aoqi@0: // 1 when verification is passed. aoqi@0: if (result == 0) { aoqi@0: return vmSymbols::java_lang_VerifyError(); aoqi@0: } else if (result == 1) { aoqi@0: return NULL; // verified. aoqi@0: } else if (result == 2) { aoqi@0: THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL); aoqi@0: } else if (result == 3) { aoqi@0: return vmSymbols::java_lang_ClassFormatError(); aoqi@0: } else { aoqi@0: ShouldNotReachHere(); aoqi@0: return NULL; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: TypeOrigin TypeOrigin::null() { aoqi@0: return TypeOrigin(); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::local(u2 index, StackMapFrame* frame) { aoqi@0: assert(frame != NULL, "Must have a frame"); aoqi@0: return TypeOrigin(CF_LOCALS, index, StackMapFrame::copy(frame), aoqi@0: frame->local_at(index)); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::stack(u2 index, StackMapFrame* frame) { aoqi@0: assert(frame != NULL, "Must have a frame"); aoqi@0: return TypeOrigin(CF_STACK, index, StackMapFrame::copy(frame), aoqi@0: frame->stack_at(index)); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::sm_local(u2 index, StackMapFrame* frame) { aoqi@0: assert(frame != NULL, "Must have a frame"); aoqi@0: return TypeOrigin(SM_LOCALS, index, StackMapFrame::copy(frame), aoqi@0: frame->local_at(index)); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::sm_stack(u2 index, StackMapFrame* frame) { aoqi@0: assert(frame != NULL, "Must have a frame"); aoqi@0: return TypeOrigin(SM_STACK, index, StackMapFrame::copy(frame), aoqi@0: frame->stack_at(index)); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::bad_index(u2 index) { aoqi@0: return TypeOrigin(BAD_INDEX, index, NULL, VerificationType::bogus_type()); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::cp(u2 index, VerificationType vt) { aoqi@0: return TypeOrigin(CONST_POOL, index, NULL, vt); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::signature(VerificationType vt) { aoqi@0: return TypeOrigin(SIG, 0, NULL, vt); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::implicit(VerificationType t) { aoqi@0: return TypeOrigin(IMPLICIT, 0, NULL, t); aoqi@0: } aoqi@0: TypeOrigin TypeOrigin::frame(StackMapFrame* frame) { aoqi@0: return TypeOrigin(FRAME_ONLY, 0, StackMapFrame::copy(frame), aoqi@0: VerificationType::bogus_type()); aoqi@0: } aoqi@0: aoqi@0: void TypeOrigin::reset_frame() { aoqi@0: if (_frame != NULL) { aoqi@0: _frame->restore(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void TypeOrigin::details(outputStream* ss) const { aoqi@0: _type.print_on(ss); aoqi@0: switch (_origin) { aoqi@0: case CF_LOCALS: aoqi@0: ss->print(" (current frame, locals[%d])", _index); aoqi@0: break; aoqi@0: case CF_STACK: aoqi@0: ss->print(" (current frame, stack[%d])", _index); aoqi@0: break; aoqi@0: case SM_LOCALS: aoqi@0: ss->print(" (stack map, locals[%d])", _index); aoqi@0: break; aoqi@0: case SM_STACK: aoqi@0: ss->print(" (stack map, stack[%d])", _index); aoqi@0: break; aoqi@0: case CONST_POOL: aoqi@0: ss->print(" (constant pool %d)", _index); aoqi@0: break; aoqi@0: case SIG: aoqi@0: ss->print(" (from method signature)"); aoqi@0: break; aoqi@0: case IMPLICIT: aoqi@0: case FRAME_ONLY: aoqi@0: case NONE: aoqi@0: default: aoqi@0: ; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: void TypeOrigin::print_on(outputStream* str) const { aoqi@0: str->print("{%d,%d,%p:", _origin, _index, _frame); aoqi@0: if (_frame != NULL) { aoqi@0: _frame->print_on(str); aoqi@0: } else { aoqi@0: str->print("null"); aoqi@0: } aoqi@0: str->print(","); aoqi@0: _type.print_on(str); aoqi@0: str->print("}"); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: void ErrorContext::details(outputStream* ss, const Method* method) const { aoqi@0: if (is_valid()) { aoqi@0: ss->cr(); aoqi@0: ss->print_cr("Exception Details:"); aoqi@0: location_details(ss, method); aoqi@0: reason_details(ss); aoqi@0: frame_details(ss); aoqi@0: bytecode_details(ss, method); aoqi@0: handler_details(ss, method); aoqi@0: stackmap_details(ss, method); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::reason_details(outputStream* ss) const { aoqi@0: streamIndentor si(ss); aoqi@0: ss->indent().print_cr("Reason:"); aoqi@0: streamIndentor si2(ss); aoqi@0: ss->indent().print("%s", ""); aoqi@0: switch (_fault) { aoqi@0: case INVALID_BYTECODE: aoqi@0: ss->print("Error exists in the bytecode"); aoqi@0: break; aoqi@0: case WRONG_TYPE: aoqi@0: if (_expected.is_valid()) { aoqi@0: ss->print("Type "); aoqi@0: _type.details(ss); aoqi@0: ss->print(" is not assignable to "); aoqi@0: _expected.details(ss); aoqi@0: } else { aoqi@0: ss->print("Invalid type: "); aoqi@0: _type.details(ss); aoqi@0: } aoqi@0: break; aoqi@0: case FLAGS_MISMATCH: aoqi@0: if (_expected.is_valid()) { aoqi@0: ss->print("Current frame's flags are not assignable " aoqi@0: "to stack map frame's."); aoqi@0: } else { aoqi@0: ss->print("Current frame's flags are invalid in this context."); aoqi@0: } aoqi@0: break; aoqi@0: case BAD_CP_INDEX: aoqi@0: ss->print("Constant pool index %d is invalid", _type.index()); aoqi@0: break; aoqi@0: case BAD_LOCAL_INDEX: aoqi@0: ss->print("Local index %d is invalid", _type.index()); aoqi@0: break; aoqi@0: case LOCALS_SIZE_MISMATCH: aoqi@0: ss->print("Current frame's local size doesn't match stackmap."); aoqi@0: break; aoqi@0: case STACK_SIZE_MISMATCH: aoqi@0: ss->print("Current frame's stack size doesn't match stackmap."); aoqi@0: break; aoqi@0: case STACK_OVERFLOW: aoqi@0: ss->print("Exceeded max stack size."); aoqi@0: break; aoqi@0: case STACK_UNDERFLOW: aoqi@0: ss->print("Attempt to pop empty stack."); aoqi@0: break; aoqi@0: case MISSING_STACKMAP: aoqi@0: ss->print("Expected stackmap frame at this location."); aoqi@0: break; aoqi@0: case BAD_STACKMAP: aoqi@0: ss->print("Invalid stackmap specification."); aoqi@0: break; aoqi@0: case UNKNOWN: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: ss->print_cr("Unknown"); aoqi@0: } aoqi@0: ss->cr(); aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::location_details(outputStream* ss, const Method* method) const { aoqi@0: if (_bci != -1 && method != NULL) { aoqi@0: streamIndentor si(ss); aoqi@0: const char* bytecode_name = ""; aoqi@0: if (method->validate_bci_from_bcx(_bci) != -1) { aoqi@0: Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci)); aoqi@0: if (Bytecodes::is_defined(code)) { aoqi@0: bytecode_name = Bytecodes::name(code); aoqi@0: } else { aoqi@0: bytecode_name = ""; aoqi@0: } aoqi@0: } aoqi@0: InstanceKlass* ik = method->method_holder(); aoqi@0: ss->indent().print_cr("Location:"); aoqi@0: streamIndentor si2(ss); aoqi@0: ss->indent().print_cr("%s.%s%s @%d: %s", aoqi@0: ik->name()->as_C_string(), method->name()->as_C_string(), aoqi@0: method->signature()->as_C_string(), _bci, bytecode_name); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::frame_details(outputStream* ss) const { aoqi@0: streamIndentor si(ss); aoqi@0: if (_type.is_valid() && _type.frame() != NULL) { aoqi@0: ss->indent().print_cr("Current Frame:"); aoqi@0: streamIndentor si2(ss); aoqi@0: _type.frame()->print_on(ss); aoqi@0: } aoqi@0: if (_expected.is_valid() && _expected.frame() != NULL) { aoqi@0: ss->indent().print_cr("Stackmap Frame:"); aoqi@0: streamIndentor si2(ss); aoqi@0: _expected.frame()->print_on(ss); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::bytecode_details(outputStream* ss, const Method* method) const { aoqi@0: if (method != NULL) { aoqi@0: streamIndentor si(ss); aoqi@0: ss->indent().print_cr("Bytecode:"); aoqi@0: streamIndentor si2(ss); aoqi@0: ss->print_data(method->code_base(), method->code_size(), false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::handler_details(outputStream* ss, const Method* method) const { aoqi@0: if (method != NULL) { aoqi@0: streamIndentor si(ss); aoqi@0: ExceptionTable table(method); aoqi@0: if (table.length() > 0) { aoqi@0: ss->indent().print_cr("Exception Handler Table:"); aoqi@0: streamIndentor si2(ss); aoqi@0: for (int i = 0; i < table.length(); ++i) { aoqi@0: ss->indent().print_cr("bci [%d, %d] => handler: %d", table.start_pc(i), aoqi@0: table.end_pc(i), table.handler_pc(i)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ErrorContext::stackmap_details(outputStream* ss, const Method* method) const { aoqi@0: if (method != NULL && method->has_stackmap_table()) { aoqi@0: streamIndentor si(ss); aoqi@0: ss->indent().print_cr("Stackmap Table:"); aoqi@0: Array* data = method->stackmap_data(); aoqi@0: stack_map_table* sm_table = aoqi@0: stack_map_table::at((address)data->adr_at(0)); aoqi@0: stack_map_frame* sm_frame = sm_table->entries(); aoqi@0: streamIndentor si2(ss); aoqi@0: int current_offset = -1; shshahma@8676: address end_of_sm_table = (address)sm_table + method->stackmap_data()->length(); aoqi@0: for (u2 i = 0; i < sm_table->number_of_entries(); ++i) { aoqi@0: ss->indent(); shshahma@8676: if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) { hseigel@8570: sm_frame->print_truncated(ss, current_offset); hseigel@8570: return; hseigel@8570: } aoqi@0: sm_frame->print_on(ss, current_offset); aoqi@0: ss->cr(); aoqi@0: current_offset += sm_frame->offset_delta(); aoqi@0: sm_frame = sm_frame->next(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Methods in ClassVerifier aoqi@0: aoqi@0: ClassVerifier::ClassVerifier( aoqi@0: instanceKlassHandle klass, TRAPS) aoqi@0: : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) { aoqi@0: _this_type = VerificationType::reference_type(klass->name()); aoqi@0: // Create list to hold symbols in reference area. aoqi@0: _symbols = new GrowableArray(100, 0, NULL); aoqi@0: } aoqi@0: aoqi@0: ClassVerifier::~ClassVerifier() { aoqi@0: // Decrement the reference count for any symbols created. aoqi@0: for (int i = 0; i < _symbols->length(); i++) { aoqi@0: Symbol* s = _symbols->at(i); aoqi@0: s->decrement_refcount(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: VerificationType ClassVerifier::object_type() const { aoqi@0: return VerificationType::reference_type(vmSymbols::java_lang_Object()); aoqi@0: } aoqi@0: aoqi@0: TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) { aoqi@0: VerificationType vt = VerificationType::reference_type( aoqi@0: create_temporary_symbol(sig, (int)strlen(sig), THREAD)); aoqi@0: return TypeOrigin::implicit(vt); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_class(TRAPS) { aoqi@0: if (VerboseVerification) { aoqi@0: tty->print_cr("Verifying class %s with new format", aoqi@0: _klass->external_name()); aoqi@0: } aoqi@0: aoqi@0: Array* methods = _klass->methods(); aoqi@0: int num_methods = methods->length(); aoqi@0: aoqi@0: for (int index = 0; index < num_methods; index++) { aoqi@0: // Check for recursive re-verification before each method. aoqi@0: if (was_recursively_verified()) return; aoqi@0: aoqi@0: Method* m = methods->at(index); aoqi@0: if (m->is_native() || m->is_abstract() || m->is_overpass()) { aoqi@0: // If m is native or abstract, skip it. It is checked in class file aoqi@0: // parser that methods do not override a final method. Overpass methods aoqi@0: // are trusted since the VM generates them. aoqi@0: continue; aoqi@0: } aoqi@0: verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: if (VerboseVerification || TraceClassInitialization) { aoqi@0: if (was_recursively_verified()) aoqi@0: tty->print_cr("Recursive verification detected for: %s", aoqi@0: _klass->external_name()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_method(methodHandle m, TRAPS) { aoqi@0: HandleMark hm(THREAD); aoqi@0: _method = m; // initialize _method aoqi@0: if (VerboseVerification) { aoqi@0: tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); aoqi@0: } aoqi@0: aoqi@0: // For clang, the only good constant format string is a literal constant format string. aoqi@0: #define bad_type_msg "Bad type on operand stack in %s" aoqi@0: aoqi@0: int32_t max_stack = m->verifier_max_stack(); aoqi@0: int32_t max_locals = m->max_locals(); aoqi@0: constantPoolHandle cp(THREAD, m->constants()); aoqi@0: aoqi@0: if (!SignatureVerifier::is_valid_method_signature(m->signature())) { aoqi@0: class_format_error("Invalid method signature"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Initial stack map frame: offset is 0, stack is initially empty. aoqi@0: StackMapFrame current_frame(max_locals, max_stack, this); aoqi@0: // Set initial locals aoqi@0: VerificationType return_type = current_frame.set_locals_from_arg( aoqi@0: m, current_type(), CHECK_VERIFY(this)); aoqi@0: aoqi@0: int32_t stackmap_index = 0; // index to the stackmap array aoqi@0: aoqi@0: u4 code_length = m->code_size(); aoqi@0: aoqi@0: // Scan the bytecode and map each instruction's start offset to a number. aoqi@0: char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this)); aoqi@0: aoqi@0: int ex_min = code_length; aoqi@0: int ex_max = -1; aoqi@0: // Look through each item on the exception table. Each of the fields must refer aoqi@0: // to a legal instruction. aoqi@0: verify_exception_handler_table( aoqi@0: code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this)); aoqi@0: aoqi@0: // Look through each entry on the local variable table and make sure aoqi@0: // its range of code array offsets is valid. (4169817) aoqi@0: if (m->has_localvariable_table()) { aoqi@0: verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: Array* stackmap_data = m->stackmap_data(); aoqi@0: StackMapStream stream(stackmap_data); aoqi@0: StackMapReader reader(this, &stream, code_data, code_length, THREAD); aoqi@0: StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, aoqi@0: code_data, code_length, CHECK_VERIFY(this)); aoqi@0: aoqi@0: if (VerboseVerification) { aoqi@0: stackmap_table.print_on(tty); aoqi@0: } aoqi@0: aoqi@0: RawBytecodeStream bcs(m); aoqi@0: aoqi@0: // Scan the byte code linearly from the start to the end aoqi@0: bool no_control_flow = false; // Set to true when there is no direct control aoqi@0: // flow from current instruction to the next aoqi@0: // instruction in sequence aoqi@0: aoqi@0: Bytecodes::Code opcode; aoqi@0: while (!bcs.is_last_bytecode()) { aoqi@0: // Check for recursive re-verification before each bytecode. aoqi@0: if (was_recursively_verified()) return; aoqi@0: aoqi@0: opcode = bcs.raw_next(); aoqi@0: u2 bci = bcs.bci(); aoqi@0: aoqi@0: // Set current frame's offset to bci aoqi@0: current_frame.set_offset(bci); aoqi@0: current_frame.set_mark(); aoqi@0: aoqi@0: // Make sure every offset in stackmap table point to the beginning to aoqi@0: // an instruction. Match current_frame to stackmap_table entry with aoqi@0: // the same offset if exists. aoqi@0: stackmap_index = verify_stackmap_table( aoqi@0: stackmap_index, bci, ¤t_frame, &stackmap_table, aoqi@0: no_control_flow, CHECK_VERIFY(this)); aoqi@0: aoqi@0: aoqi@0: bool this_uninit = false; // Set to true when invokespecial initialized 'this' hseigel@7666: bool verified_exc_handlers = false; aoqi@0: aoqi@0: // Merge with the next instruction aoqi@0: { aoqi@0: u2 index; aoqi@0: int target; aoqi@0: VerificationType type, type2; aoqi@0: VerificationType atype; aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (VerboseVerification) { aoqi@0: current_frame.print_on(tty); aoqi@0: tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Make sure wide instruction is in correct format aoqi@0: if (bcs.is_wide()) { aoqi@0: if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && aoqi@0: opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && aoqi@0: opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && aoqi@0: opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && aoqi@0: opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && aoqi@0: opcode != Bytecodes::_dstore) { aoqi@0: /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal' aoqi@0: * if we encounter a wide instruction that modifies an invalid aoqi@0: * opcode (not one of the ones listed above) */ aoqi@0: verify_error(ErrorContext::bad_code(bci), "Bad wide instruction"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: hseigel@7666: // Look for possible jump target in exception handlers and see if it hseigel@7666: // matches current_frame. Do this check here for astore*, dstore*, hseigel@7666: // fstore*, istore*, and lstore* opcodes because they can change the type hseigel@7666: // state by adding a local. JVM Spec says that the incoming type state hseigel@7666: // should be used for this check. So, do the check here before a possible hseigel@7666: // local is added to the type state. hseigel@7666: if (Bytecodes::is_store_into_local(opcode) && bci >= ex_min && bci < ex_max) { hseigel@7666: verify_exception_handler_targets( hseigel@7666: bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); hseigel@7666: verified_exc_handlers = true; hseigel@7666: } hseigel@7666: aoqi@0: switch (opcode) { aoqi@0: case Bytecodes::_nop : aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_aconst_null : aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::null_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iconst_m1 : aoqi@0: case Bytecodes::_iconst_0 : aoqi@0: case Bytecodes::_iconst_1 : aoqi@0: case Bytecodes::_iconst_2 : aoqi@0: case Bytecodes::_iconst_3 : aoqi@0: case Bytecodes::_iconst_4 : aoqi@0: case Bytecodes::_iconst_5 : aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lconst_0 : aoqi@0: case Bytecodes::_lconst_1 : aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fconst_0 : aoqi@0: case Bytecodes::_fconst_1 : aoqi@0: case Bytecodes::_fconst_2 : aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dconst_0 : aoqi@0: case Bytecodes::_dconst_1 : aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_sipush : aoqi@0: case Bytecodes::_bipush : aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_ldc : aoqi@0: verify_ldc( aoqi@0: opcode, bcs.get_index_u1(), ¤t_frame, aoqi@0: cp, bci, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_ldc_w : aoqi@0: case Bytecodes::_ldc2_w : aoqi@0: verify_ldc( aoqi@0: opcode, bcs.get_index_u2(), ¤t_frame, aoqi@0: cp, bci, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iload : aoqi@0: verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iload_0 : aoqi@0: case Bytecodes::_iload_1 : aoqi@0: case Bytecodes::_iload_2 : aoqi@0: case Bytecodes::_iload_3 : aoqi@0: index = opcode - Bytecodes::_iload_0; aoqi@0: verify_iload(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lload : aoqi@0: verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lload_0 : aoqi@0: case Bytecodes::_lload_1 : aoqi@0: case Bytecodes::_lload_2 : aoqi@0: case Bytecodes::_lload_3 : aoqi@0: index = opcode - Bytecodes::_lload_0; aoqi@0: verify_lload(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fload : aoqi@0: verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fload_0 : aoqi@0: case Bytecodes::_fload_1 : aoqi@0: case Bytecodes::_fload_2 : aoqi@0: case Bytecodes::_fload_3 : aoqi@0: index = opcode - Bytecodes::_fload_0; aoqi@0: verify_fload(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dload : aoqi@0: verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dload_0 : aoqi@0: case Bytecodes::_dload_1 : aoqi@0: case Bytecodes::_dload_2 : aoqi@0: case Bytecodes::_dload_3 : aoqi@0: index = opcode - Bytecodes::_dload_0; aoqi@0: verify_dload(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_aload : aoqi@0: verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_aload_0 : aoqi@0: case Bytecodes::_aload_1 : aoqi@0: case Bytecodes::_aload_2 : aoqi@0: case Bytecodes::_aload_3 : aoqi@0: index = opcode - Bytecodes::_aload_0; aoqi@0: verify_aload(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iaload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_int_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), aoqi@0: bad_type_msg, "iaload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_baload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_bool_array() && !atype.is_byte_array()) { aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "baload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_caload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_char_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), aoqi@0: bad_type_msg, "caload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_saload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_short_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), aoqi@0: bad_type_msg, "saload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_laload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_long_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), aoqi@0: bad_type_msg, "laload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_faload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_float_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), aoqi@0: bad_type_msg, "faload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_daload : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_double_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), aoqi@0: bad_type_msg, "daload"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_aaload : { aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_reference_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), aoqi@0: TypeOrigin::implicit(VerificationType::reference_check())), aoqi@0: bad_type_msg, "aaload"); aoqi@0: return; aoqi@0: } aoqi@0: if (atype.is_null()) { aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::null_type(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: VerificationType component = aoqi@0: atype.get_component(this, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(component, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_istore : aoqi@0: verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_istore_0 : aoqi@0: case Bytecodes::_istore_1 : aoqi@0: case Bytecodes::_istore_2 : aoqi@0: case Bytecodes::_istore_3 : aoqi@0: index = opcode - Bytecodes::_istore_0; aoqi@0: verify_istore(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lstore : aoqi@0: verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lstore_0 : aoqi@0: case Bytecodes::_lstore_1 : aoqi@0: case Bytecodes::_lstore_2 : aoqi@0: case Bytecodes::_lstore_3 : aoqi@0: index = opcode - Bytecodes::_lstore_0; aoqi@0: verify_lstore(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fstore : aoqi@0: verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fstore_0 : aoqi@0: case Bytecodes::_fstore_1 : aoqi@0: case Bytecodes::_fstore_2 : aoqi@0: case Bytecodes::_fstore_3 : aoqi@0: index = opcode - Bytecodes::_fstore_0; aoqi@0: verify_fstore(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dstore : aoqi@0: verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dstore_0 : aoqi@0: case Bytecodes::_dstore_1 : aoqi@0: case Bytecodes::_dstore_2 : aoqi@0: case Bytecodes::_dstore_3 : aoqi@0: index = opcode - Bytecodes::_dstore_0; aoqi@0: verify_dstore(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_astore : aoqi@0: verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_astore_0 : aoqi@0: case Bytecodes::_astore_1 : aoqi@0: case Bytecodes::_astore_2 : aoqi@0: case Bytecodes::_astore_3 : aoqi@0: index = opcode - Bytecodes::_astore_0; aoqi@0: verify_astore(index, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iastore : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_int_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), aoqi@0: bad_type_msg, "iastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_bastore : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_bool_array() && !atype.is_byte_array()) { aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "bastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_castore : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_char_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), aoqi@0: bad_type_msg, "castore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_sastore : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_short_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), aoqi@0: bad_type_msg, "sastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lastore : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_long_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), aoqi@0: bad_type_msg, "lastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fastore : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack aoqi@0: (VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_float_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), aoqi@0: bad_type_msg, "fastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dastore : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!atype.is_double_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), aoqi@0: bad_type_msg, "dastore"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_aastore : aoqi@0: type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: atype = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: // more type-checking is done at runtime aoqi@0: if (!atype.is_reference_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame.stack_top_ctx(), aoqi@0: TypeOrigin::implicit(VerificationType::reference_check())), aoqi@0: bad_type_msg, "aastore"); aoqi@0: return; aoqi@0: } aoqi@0: // 4938384: relaxed constraint in JVMS 3nd edition. aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_pop : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_pop2 : aoqi@0: type = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type.is_category1()) { aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type.is_category2_2nd()) { aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st on TOS aoqi@0: * which does not appear possible. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "pop2"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dup : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dup_x1 : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dup_x2 : aoqi@0: { aoqi@0: VerificationType type3; aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type2.is_category1()) { aoqi@0: type3 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type2.is_category2_2nd()) { aoqi@0: type3 = current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st at stack depth 2 with aoqi@0: * a category1 on TOS which does not appear possible. */ aoqi@0: verify_error(ErrorContext::bad_type( aoqi@0: bci, current_frame.stack_top_ctx()), bad_type_msg, "dup_x2"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type3, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_dup2 : aoqi@0: type = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type.is_category1()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type.is_category2_2nd()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st on TOS which does not aoqi@0: * appear possible. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "dup2"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dup2_x1 : aoqi@0: { aoqi@0: VerificationType type3; aoqi@0: type = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type.is_category1()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type.is_category2_2nd()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st on TOS which does aoqi@0: * not appear possible. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "dup2_x1"); aoqi@0: return; aoqi@0: } aoqi@0: type3 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type3, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_dup2_x2 : aoqi@0: { aoqi@0: VerificationType type3, type4; aoqi@0: type = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type.is_category1()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type.is_category2_2nd()) { aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st on TOS which does aoqi@0: * not appear possible. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "dup2_x2"); aoqi@0: return; aoqi@0: } aoqi@0: type3 = current_frame.pop_stack(CHECK_VERIFY(this)); aoqi@0: if (type3.is_category1()) { aoqi@0: type4 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: } else if (type3.is_category2_2nd()) { aoqi@0: type4 = current_frame.pop_stack( aoqi@0: VerificationType::category2_check(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? Would need a category2_1st on TOS after popping aoqi@0: * a long/double or two category 1's, which does not aoqi@0: * appear possible. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "dup2_x2"); aoqi@0: return; aoqi@0: } aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type4, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type3, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_swap : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::category1_check(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type2, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iadd : aoqi@0: case Bytecodes::_isub : aoqi@0: case Bytecodes::_imul : aoqi@0: case Bytecodes::_idiv : aoqi@0: case Bytecodes::_irem : aoqi@0: case Bytecodes::_ishl : aoqi@0: case Bytecodes::_ishr : aoqi@0: case Bytecodes::_iushr : aoqi@0: case Bytecodes::_ior : aoqi@0: case Bytecodes::_ixor : aoqi@0: case Bytecodes::_iand : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_ineg : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_ladd : aoqi@0: case Bytecodes::_lsub : aoqi@0: case Bytecodes::_lmul : aoqi@0: case Bytecodes::_ldiv : aoqi@0: case Bytecodes::_lrem : aoqi@0: case Bytecodes::_land : aoqi@0: case Bytecodes::_lor : aoqi@0: case Bytecodes::_lxor : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_lneg : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lshl : aoqi@0: case Bytecodes::_lshr : aoqi@0: case Bytecodes::_lushr : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fadd : aoqi@0: case Bytecodes::_fsub : aoqi@0: case Bytecodes::_fmul : aoqi@0: case Bytecodes::_fdiv : aoqi@0: case Bytecodes::_frem : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_fneg : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dadd : aoqi@0: case Bytecodes::_dsub : aoqi@0: case Bytecodes::_dmul : aoqi@0: case Bytecodes::_ddiv : aoqi@0: case Bytecodes::_drem : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_dneg : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_iinc : aoqi@0: verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_i2l : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_l2i : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_i2f : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_i2d : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_l2f : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_l2d : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_f2i : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_f2l : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_f2d : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_d2i : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_d2l : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_d2f : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_i2b : aoqi@0: case Bytecodes::_i2c : aoqi@0: case Bytecodes::_i2s : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_lcmp : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_fcmpl : aoqi@0: case Bytecodes::_fcmpg : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_dcmpl : aoqi@0: case Bytecodes::_dcmpg : aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_if_icmpeq: aoqi@0: case Bytecodes::_if_icmpne: aoqi@0: case Bytecodes::_if_icmplt: aoqi@0: case Bytecodes::_if_icmpge: aoqi@0: case Bytecodes::_if_icmpgt: aoqi@0: case Bytecodes::_if_icmple: aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_ifeq: aoqi@0: case Bytecodes::_ifne: aoqi@0: case Bytecodes::_iflt: aoqi@0: case Bytecodes::_ifge: aoqi@0: case Bytecodes::_ifgt: aoqi@0: case Bytecodes::_ifle: aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: target = bcs.dest(); aoqi@0: stackmap_table.check_jump_target( aoqi@0: ¤t_frame, target, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_if_acmpeq : aoqi@0: case Bytecodes::_if_acmpne : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: // fall through aoqi@0: case Bytecodes::_ifnull : aoqi@0: case Bytecodes::_ifnonnull : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: target = bcs.dest(); aoqi@0: stackmap_table.check_jump_target aoqi@0: (¤t_frame, target, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_goto : aoqi@0: target = bcs.dest(); aoqi@0: stackmap_table.check_jump_target( aoqi@0: ¤t_frame, target, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_goto_w : aoqi@0: target = bcs.dest_w(); aoqi@0: stackmap_table.check_jump_target( aoqi@0: ¤t_frame, target, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_tableswitch : aoqi@0: case Bytecodes::_lookupswitch : aoqi@0: verify_switch( aoqi@0: &bcs, code_length, code_data, ¤t_frame, aoqi@0: &stackmap_table, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_ireturn : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: verify_return_value(return_type, type, bci, aoqi@0: ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_lreturn : aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: verify_return_value(return_type, type, bci, aoqi@0: ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_freturn : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: verify_return_value(return_type, type, bci, aoqi@0: ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_dreturn : aoqi@0: type2 = current_frame.pop_stack( aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: verify_return_value(return_type, type, bci, aoqi@0: ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_areturn : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: verify_return_value(return_type, type, bci, aoqi@0: ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_return : aoqi@0: if (return_type != VerificationType::bogus_type()) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Method expects a return value"); aoqi@0: return; aoqi@0: } aoqi@0: // Make sure "this" has been initialized if current method is an aoqi@0: // aoqi@0: if (_method->name() == vmSymbols::object_initializer_name() && aoqi@0: current_frame.flag_this_uninit()) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Constructor must call super() or this() " aoqi@0: "before return"); aoqi@0: return; aoqi@0: } aoqi@0: no_control_flow = true; break; aoqi@0: case Bytecodes::_getstatic : aoqi@0: case Bytecodes::_putstatic : aoqi@0: case Bytecodes::_getfield : aoqi@0: case Bytecodes::_putfield : aoqi@0: verify_field_instructions( aoqi@0: &bcs, ¤t_frame, cp, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_invokevirtual : aoqi@0: case Bytecodes::_invokespecial : aoqi@0: case Bytecodes::_invokestatic : aoqi@0: verify_invoke_instructions( hseigel@7473: &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max), hseigel@7473: &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_invokeinterface : aoqi@0: case Bytecodes::_invokedynamic : aoqi@0: verify_invoke_instructions( hseigel@7473: &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max), hseigel@7473: &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_new : aoqi@0: { aoqi@0: index = bcs.get_index_u2(); aoqi@0: verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); aoqi@0: VerificationType new_class_type = aoqi@0: cp_index_to_type(index, cp, CHECK_VERIFY(this)); aoqi@0: if (!new_class_type.is_object()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: TypeOrigin::cp(index, new_class_type)), aoqi@0: "Illegal new instruction"); aoqi@0: return; aoqi@0: } aoqi@0: type = VerificationType::uninitialized_type(bci); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_newarray : aoqi@0: type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_anewarray : aoqi@0: verify_anewarray( aoqi@0: bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_arraylength : aoqi@0: type = current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (!(type.is_null() || type.is_array())) { aoqi@0: verify_error(ErrorContext::bad_type( aoqi@0: bci, current_frame.stack_top_ctx()), aoqi@0: bad_type_msg, "arraylength"); aoqi@0: } aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_checkcast : aoqi@0: { aoqi@0: index = bcs.get_index_u2(); aoqi@0: verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); aoqi@0: VerificationType klass_type = cp_index_to_type( aoqi@0: index, cp, CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack(klass_type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_instanceof : { aoqi@0: index = bcs.get_index_u2(); aoqi@0: verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); aoqi@0: current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); aoqi@0: current_frame.push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_monitorenter : aoqi@0: case Bytecodes::_monitorexit : aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: case Bytecodes::_multianewarray : aoqi@0: { aoqi@0: index = bcs.get_index_u2(); aoqi@0: u2 dim = *(bcs.bcp()+3); aoqi@0: verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); aoqi@0: VerificationType new_array_type = aoqi@0: cp_index_to_type(index, cp, CHECK_VERIFY(this)); aoqi@0: if (!new_array_type.is_array()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: TypeOrigin::cp(index, new_array_type)), aoqi@0: "Illegal constant pool index in multianewarray instruction"); aoqi@0: return; aoqi@0: } aoqi@0: if (dim < 1 || new_array_type.dimensions() < dim) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Illegal dimension in multianewarray instruction: %d", dim); aoqi@0: return; aoqi@0: } aoqi@0: for (int i = 0; i < dim; i++) { aoqi@0: current_frame.pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = false; break; aoqi@0: } aoqi@0: case Bytecodes::_athrow : aoqi@0: type = VerificationType::reference_type( aoqi@0: vmSymbols::java_lang_Throwable()); aoqi@0: current_frame.pop_stack(type, CHECK_VERIFY(this)); aoqi@0: no_control_flow = true; break; aoqi@0: default: aoqi@0: // We only need to check the valid bytecodes in class file. aoqi@0: // And jsr and ret are not in the new class file format in JDK1.5. aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Bad instruction: %02x", opcode); aoqi@0: no_control_flow = false; aoqi@0: return; aoqi@0: } // end switch aoqi@0: } // end Merge with the next instruction aoqi@0: hseigel@7666: // Look for possible jump target in exception handlers and see if it matches hseigel@7666: // current_frame. Don't do this check if it has already been done (for hseigel@7666: // ([a,d,f,i,l]store* opcodes). This check cannot be done earlier because hseigel@7666: // opcodes, such as invokespecial, may set the this_uninit flag. hseigel@7666: assert(!(verified_exc_handlers && this_uninit), hseigel@7666: "Exception handler targets got verified before this_uninit got set"); hseigel@7666: if (!verified_exc_handlers && bci >= ex_min && bci < ex_max) { aoqi@0: verify_exception_handler_targets( aoqi@0: bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: } // end while aoqi@0: aoqi@0: // Make sure that control flow does not fall through end of the method aoqi@0: if (!no_control_flow) { aoqi@0: verify_error(ErrorContext::bad_code(code_length), aoqi@0: "Control flow falls through code end"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #undef bad_type_message aoqi@0: aoqi@0: char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { aoqi@0: char* code_data = NEW_RESOURCE_ARRAY(char, code_length); aoqi@0: memset(code_data, 0, sizeof(char) * code_length); aoqi@0: RawBytecodeStream bcs(m); aoqi@0: aoqi@0: while (!bcs.is_last_bytecode()) { aoqi@0: if (bcs.raw_next() != Bytecodes::_illegal) { aoqi@0: int bci = bcs.bci(); aoqi@0: if (bcs.raw_code() == Bytecodes::_new) { aoqi@0: code_data[bci] = NEW_OFFSET; aoqi@0: } else { aoqi@0: code_data[bci] = BYTECODE_OFFSET; aoqi@0: } aoqi@0: } else { aoqi@0: verify_error(ErrorContext::bad_code(bcs.bci()), "Bad instruction"); aoqi@0: return NULL; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return code_data; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) { aoqi@0: ExceptionTable exhandlers(_method()); aoqi@0: int exlength = exhandlers.length(); aoqi@0: constantPoolHandle cp (THREAD, _method->constants()); aoqi@0: aoqi@0: for(int i = 0; i < exlength; i++) { aoqi@0: //reacquire the table in case a GC happened aoqi@0: ExceptionTable exhandlers(_method()); aoqi@0: u2 start_pc = exhandlers.start_pc(i); aoqi@0: u2 end_pc = exhandlers.end_pc(i); aoqi@0: u2 handler_pc = exhandlers.handler_pc(i); aoqi@0: if (start_pc >= code_length || code_data[start_pc] == 0) { aoqi@0: class_format_error("Illegal exception table start_pc %d", start_pc); aoqi@0: return; aoqi@0: } aoqi@0: if (end_pc != code_length) { // special case: end_pc == code_length aoqi@0: if (end_pc > code_length || code_data[end_pc] == 0) { aoqi@0: class_format_error("Illegal exception table end_pc %d", end_pc); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: if (handler_pc >= code_length || code_data[handler_pc] == 0) { aoqi@0: class_format_error("Illegal exception table handler_pc %d", handler_pc); aoqi@0: return; aoqi@0: } aoqi@0: int catch_type_index = exhandlers.catch_type_index(i); aoqi@0: if (catch_type_index != 0) { aoqi@0: VerificationType catch_type = cp_index_to_type( aoqi@0: catch_type_index, cp, CHECK_VERIFY(this)); aoqi@0: VerificationType throwable = aoqi@0: VerificationType::reference_type(vmSymbols::java_lang_Throwable()); aoqi@0: bool is_subclass = throwable.is_assignable_from( aoqi@0: catch_type, this, false, CHECK_VERIFY(this)); aoqi@0: if (!is_subclass) { aoqi@0: // 4286534: should throw VerifyError according to recent spec change aoqi@0: verify_error(ErrorContext::bad_type(handler_pc, aoqi@0: TypeOrigin::cp(catch_type_index, catch_type), aoqi@0: TypeOrigin::implicit(throwable)), aoqi@0: "Catch type is not a subclass " aoqi@0: "of Throwable in exception handler %d", handler_pc); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: if (start_pc < min) min = start_pc; aoqi@0: if (end_pc > max) max = end_pc; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) { aoqi@0: int localvariable_table_length = _method()->localvariable_table_length(); aoqi@0: if (localvariable_table_length > 0) { aoqi@0: LocalVariableTableElement* table = _method()->localvariable_table_start(); aoqi@0: for (int i = 0; i < localvariable_table_length; i++) { aoqi@0: u2 start_bci = table[i].start_bci; aoqi@0: u2 length = table[i].length; aoqi@0: aoqi@0: if (start_bci >= code_length || code_data[start_bci] == 0) { aoqi@0: class_format_error( aoqi@0: "Illegal local variable table start_pc %d", start_bci); aoqi@0: return; aoqi@0: } aoqi@0: u4 end_bci = (u4)(start_bci + length); aoqi@0: if (end_bci != code_length) { aoqi@0: if (end_bci >= code_length || code_data[end_bci] == 0) { aoqi@0: class_format_error( "Illegal local variable table length %d", length); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci, aoqi@0: StackMapFrame* current_frame, aoqi@0: StackMapTable* stackmap_table, aoqi@0: bool no_control_flow, TRAPS) { aoqi@0: if (stackmap_index < stackmap_table->get_frame_count()) { aoqi@0: u2 this_offset = stackmap_table->get_offset(stackmap_index); aoqi@0: if (no_control_flow && this_offset > bci) { aoqi@0: verify_error(ErrorContext::missing_stackmap(bci), aoqi@0: "Expecting a stack map frame"); aoqi@0: return 0; aoqi@0: } aoqi@0: if (this_offset == bci) { aoqi@0: ErrorContext ctx; aoqi@0: // See if current stack map can be assigned to the frame in table. aoqi@0: // current_frame is the stackmap frame got from the last instruction. aoqi@0: // If matched, current_frame will be updated by this method. aoqi@0: bool matches = stackmap_table->match_stackmap( aoqi@0: current_frame, this_offset, stackmap_index, kevinw@8703: !no_control_flow, true, &ctx, CHECK_VERIFY_(this, 0)); aoqi@0: if (!matches) { aoqi@0: // report type error aoqi@0: verify_error(ctx, "Instruction type does not match stack map"); aoqi@0: return 0; aoqi@0: } aoqi@0: stackmap_index++; aoqi@0: } else if (this_offset < bci) { aoqi@0: // current_offset should have met this_offset. aoqi@0: class_format_error("Bad stack map offset %d", this_offset); aoqi@0: return 0; aoqi@0: } aoqi@0: } else if (no_control_flow) { aoqi@0: verify_error(ErrorContext::bad_code(bci), "Expecting a stack map frame"); aoqi@0: return 0; aoqi@0: } aoqi@0: return stackmap_index; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame, aoqi@0: StackMapTable* stackmap_table, TRAPS) { aoqi@0: constantPoolHandle cp (THREAD, _method->constants()); aoqi@0: ExceptionTable exhandlers(_method()); aoqi@0: int exlength = exhandlers.length(); aoqi@0: for(int i = 0; i < exlength; i++) { aoqi@0: //reacquire the table in case a GC happened aoqi@0: ExceptionTable exhandlers(_method()); aoqi@0: u2 start_pc = exhandlers.start_pc(i); aoqi@0: u2 end_pc = exhandlers.end_pc(i); aoqi@0: u2 handler_pc = exhandlers.handler_pc(i); aoqi@0: int catch_type_index = exhandlers.catch_type_index(i); aoqi@0: if(bci >= start_pc && bci < end_pc) { aoqi@0: u1 flags = current_frame->flags(); aoqi@0: if (this_uninit) { flags |= FLAG_THIS_UNINIT; } aoqi@0: StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags); aoqi@0: if (catch_type_index != 0) { aoqi@0: // We know that this index refers to a subclass of Throwable aoqi@0: VerificationType catch_type = cp_index_to_type( aoqi@0: catch_type_index, cp, CHECK_VERIFY(this)); aoqi@0: new_frame->push_stack(catch_type, CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: VerificationType throwable = aoqi@0: VerificationType::reference_type(vmSymbols::java_lang_Throwable()); aoqi@0: new_frame->push_stack(throwable, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: ErrorContext ctx; aoqi@0: bool matches = stackmap_table->match_stackmap( kevinw@8703: new_frame, handler_pc, true, false, &ctx, CHECK_VERIFY(this)); aoqi@0: if (!matches) { aoqi@0: verify_error(ctx, "Stack map does not match the one at " aoqi@0: "exception handler %d", handler_pc); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_cp_index( aoqi@0: u2 bci, constantPoolHandle cp, int index, TRAPS) { aoqi@0: int nconstants = cp->length(); aoqi@0: if ((index <= 0) || (index >= nconstants)) { aoqi@0: verify_error(ErrorContext::bad_cp_index(bci, index), aoqi@0: "Illegal constant pool index %d in class %s", aoqi@0: index, cp->pool_holder()->external_name()); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_cp_type( aoqi@0: u2 bci, int index, constantPoolHandle cp, unsigned int types, TRAPS) { aoqi@0: aoqi@0: // In some situations, bytecode rewriting may occur while we're verifying. aoqi@0: // In this case, a constant pool cache exists and some indices refer to that aoqi@0: // instead. Be sure we don't pick up such indices by accident. aoqi@0: // We must check was_recursively_verified() before we get here. aoqi@0: guarantee(cp->cache() == NULL, "not rewritten yet"); aoqi@0: aoqi@0: verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); aoqi@0: unsigned int tag = cp->tag_at(index).value(); aoqi@0: if ((types & (1 << tag)) == 0) { aoqi@0: verify_error(ErrorContext::bad_cp_index(bci, index), aoqi@0: "Illegal type at constant pool entry %d in class %s", aoqi@0: index, cp->pool_holder()->external_name()); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_cp_class_type( aoqi@0: u2 bci, int index, constantPoolHandle cp, TRAPS) { aoqi@0: verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); aoqi@0: constantTag tag = cp->tag_at(index); aoqi@0: if (!tag.is_klass() && !tag.is_unresolved_klass()) { aoqi@0: verify_error(ErrorContext::bad_cp_index(bci, index), aoqi@0: "Illegal type at constant pool entry %d in class %s", aoqi@0: index, cp->pool_holder()->external_name()); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_error(ErrorContext ctx, const char* msg, ...) { aoqi@0: stringStream ss; aoqi@0: aoqi@0: ctx.reset_frames(); aoqi@0: _exception_type = vmSymbols::java_lang_VerifyError(); aoqi@0: _error_context = ctx; aoqi@0: va_list va; aoqi@0: va_start(va, msg); aoqi@0: ss.vprint(msg, va); aoqi@0: va_end(va); aoqi@0: _message = ss.as_string(); aoqi@0: #ifdef ASSERT aoqi@0: ResourceMark rm; aoqi@0: const char* exception_name = _exception_type->as_C_string(); aoqi@0: Exceptions::debug_check_abort(exception_name, NULL); aoqi@0: #endif // ndef ASSERT aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::class_format_error(const char* msg, ...) { aoqi@0: stringStream ss; aoqi@0: _exception_type = vmSymbols::java_lang_ClassFormatError(); aoqi@0: va_list va; aoqi@0: va_start(va, msg); aoqi@0: ss.vprint(msg, va); aoqi@0: va_end(va); aoqi@0: if (!_method.is_null()) { aoqi@0: ss.print(" in method %s", _method->name_and_sig_as_C_string()); aoqi@0: } aoqi@0: _message = ss.as_string(); aoqi@0: } aoqi@0: aoqi@0: Klass* ClassVerifier::load_class(Symbol* name, TRAPS) { aoqi@0: // Get current loader and protection domain first. aoqi@0: oop loader = current_class()->class_loader(); aoqi@0: oop protection_domain = current_class()->protection_domain(); aoqi@0: coleenp@9530: return SystemDictionary::resolve_or_fail( aoqi@0: name, Handle(THREAD, loader), Handle(THREAD, protection_domain), aoqi@0: true, CHECK_NULL); aoqi@0: } aoqi@0: aoqi@0: bool ClassVerifier::is_protected_access(instanceKlassHandle this_class, aoqi@0: Klass* target_class, aoqi@0: Symbol* field_name, aoqi@0: Symbol* field_sig, aoqi@0: bool is_method) { aoqi@0: No_Safepoint_Verifier nosafepoint; aoqi@0: aoqi@0: // If target class isn't a super class of this class, we don't worry about this case aoqi@0: if (!this_class->is_subclass_of(target_class)) { aoqi@0: return false; aoqi@0: } aoqi@0: // Check if the specified method or field is protected aoqi@0: InstanceKlass* target_instance = InstanceKlass::cast(target_class); aoqi@0: fieldDescriptor fd; aoqi@0: if (is_method) { dbuck@8716: Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::find_overpass); aoqi@0: if (m != NULL && m->is_protected()) { aoqi@0: if (!this_class->is_same_class_package(m->method_holder())) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd); aoqi@0: if (member_klass != NULL && fd.is_protected()) { aoqi@0: if (!this_class->is_same_class_package(member_klass)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_ldc( aoqi@0: int opcode, u2 index, StackMapFrame* current_frame, aoqi@0: constantPoolHandle cp, u2 bci, TRAPS) { aoqi@0: verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); aoqi@0: constantTag tag = cp->tag_at(index); aoqi@0: unsigned int types; aoqi@0: if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { aoqi@0: if (!tag.is_unresolved_klass()) { aoqi@0: types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) aoqi@0: | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) aoqi@0: | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType); aoqi@0: // Note: The class file parser already verified the legality of aoqi@0: // MethodHandle and MethodType constants. aoqi@0: verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: } else { aoqi@0: assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); aoqi@0: types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); aoqi@0: verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: if (tag.is_string() && cp->is_pseudo_string_at(index)) { aoqi@0: current_frame->push_stack(object_type(), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_string()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::reference_type( aoqi@0: vmSymbols::java_lang_String()), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_klass() || tag.is_unresolved_klass()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::reference_type( aoqi@0: vmSymbols::java_lang_Class()), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_int()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_float()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_double()) { aoqi@0: current_frame->push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_long()) { aoqi@0: current_frame->push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_method_handle()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::reference_type( aoqi@0: vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this)); aoqi@0: } else if (tag.is_method_type()) { aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::reference_type( aoqi@0: vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: /* Unreachable? verify_cp_type has already validated the cp type. */ aoqi@0: verify_error( aoqi@0: ErrorContext::bad_cp_index(bci, index), "Invalid index in ldc"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_switch( aoqi@0: RawBytecodeStream* bcs, u4 code_length, char* code_data, aoqi@0: StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) { aoqi@0: int bci = bcs->bci(); aoqi@0: address bcp = bcs->bcp(); aoqi@0: address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize); aoqi@0: aoqi@0: if (_klass->major_version() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) { aoqi@0: // 4639449 & 4647081: padding bytes must be 0 aoqi@0: u2 padding_offset = 1; aoqi@0: while ((bcp + padding_offset) < aligned_bcp) { aoqi@0: if(*(bcp + padding_offset) != 0) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Nonzero padding byte in lookswitch or tableswitch"); aoqi@0: return; aoqi@0: } aoqi@0: padding_offset++; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); aoqi@0: int keys, delta; aoqi@0: current_frame->pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: if (bcs->raw_code() == Bytecodes::_tableswitch) { aoqi@0: jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); aoqi@0: jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); aoqi@0: if (low > high) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "low must be less than or equal to high in tableswitch"); aoqi@0: return; aoqi@0: } aoqi@0: keys = high - low + 1; aoqi@0: if (keys < 0) { aoqi@0: verify_error(ErrorContext::bad_code(bci), "too many keys in tableswitch"); aoqi@0: return; aoqi@0: } aoqi@0: delta = 1; aoqi@0: } else { aoqi@0: keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); aoqi@0: if (keys < 0) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "number of keys in lookupswitch less than 0"); aoqi@0: return; aoqi@0: } aoqi@0: delta = 2; aoqi@0: // Make sure that the lookupswitch items are sorted aoqi@0: for (int i = 0; i < (keys - 1); i++) { aoqi@0: jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); aoqi@0: jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); aoqi@0: if (this_key >= next_key) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Bad lookupswitch instruction"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: int target = bci + default_offset; aoqi@0: stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this)); aoqi@0: for (int i = 0; i < keys; i++) { aoqi@0: // Because check_jump_target() may safepoint, the bytecode could have aoqi@0: // moved, which means 'aligned_bcp' is no good and needs to be recalculated. aoqi@0: aligned_bcp = (address)round_to((intptr_t)(bcs->bcp() + 1), jintSize); aoqi@0: target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); aoqi@0: stackmap_table->check_jump_target( aoqi@0: current_frame, target, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: NOT_PRODUCT(aligned_bcp = NULL); // no longer valid at this point aoqi@0: } aoqi@0: aoqi@0: bool ClassVerifier::name_in_supers( aoqi@0: Symbol* ref_name, instanceKlassHandle current) { aoqi@0: Klass* super = current->super(); aoqi@0: while (super != NULL) { aoqi@0: if (super->name() == ref_name) { aoqi@0: return true; aoqi@0: } aoqi@0: super = super->super(); aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, aoqi@0: StackMapFrame* current_frame, aoqi@0: constantPoolHandle cp, aoqi@0: TRAPS) { aoqi@0: u2 index = bcs->get_index_u2(); aoqi@0: verify_cp_type(bcs->bci(), index, cp, aoqi@0: 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); aoqi@0: aoqi@0: // Get field name and signature aoqi@0: Symbol* field_name = cp->name_ref_at(index); aoqi@0: Symbol* field_sig = cp->signature_ref_at(index); aoqi@0: aoqi@0: if (!SignatureVerifier::is_valid_type_signature(field_sig)) { aoqi@0: class_format_error( aoqi@0: "Invalid signature for field in class %s referenced " aoqi@0: "from constant pool index %d", _klass->external_name(), index); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Get referenced class type aoqi@0: VerificationType ref_class_type = cp_ref_index_to_type( aoqi@0: index, cp, CHECK_VERIFY(this)); aoqi@0: if (!ref_class_type.is_object()) { aoqi@0: /* Unreachable? Class file parser verifies Fieldref contents */ aoqi@0: verify_error(ErrorContext::bad_type(bcs->bci(), aoqi@0: TypeOrigin::cp(index, ref_class_type)), aoqi@0: "Expecting reference to class in class %s at constant pool index %d", aoqi@0: _klass->external_name(), index); aoqi@0: return; aoqi@0: } aoqi@0: VerificationType target_class_type = ref_class_type; aoqi@0: aoqi@0: assert(sizeof(VerificationType) == sizeof(uintptr_t), aoqi@0: "buffer type must match VerificationType size"); aoqi@0: uintptr_t field_type_buffer[2]; aoqi@0: VerificationType* field_type = (VerificationType*)field_type_buffer; aoqi@0: // If we make a VerificationType[2] array directly, the compiler calls aoqi@0: // to the c-runtime library to do the allocation instead of just aoqi@0: // stack allocating it. Plus it would run constructors. This shows up aoqi@0: // in performance profiles. aoqi@0: aoqi@0: SignatureStream sig_stream(field_sig, false); aoqi@0: VerificationType stack_object_type; aoqi@0: int n = change_sig_to_verificationType( aoqi@0: &sig_stream, field_type, CHECK_VERIFY(this)); aoqi@0: u2 bci = bcs->bci(); aoqi@0: bool is_assignable; aoqi@0: switch (bcs->raw_code()) { aoqi@0: case Bytecodes::_getstatic: { aoqi@0: for (int i = 0; i < n; i++) { aoqi@0: current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case Bytecodes::_putstatic: { aoqi@0: for (int i = n - 1; i >= 0; i--) { aoqi@0: current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case Bytecodes::_getfield: { aoqi@0: stack_object_type = current_frame->pop_stack( aoqi@0: target_class_type, CHECK_VERIFY(this)); aoqi@0: for (int i = 0; i < n; i++) { aoqi@0: current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); aoqi@0: } aoqi@0: goto check_protected; aoqi@0: } aoqi@0: case Bytecodes::_putfield: { aoqi@0: for (int i = n - 1; i >= 0; i--) { aoqi@0: current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); aoqi@0: } aoqi@0: stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); aoqi@0: aoqi@0: // The JVMS 2nd edition allows field initialization before the superclass aoqi@0: // initializer, if the field is defined within the current class. aoqi@0: fieldDescriptor fd; aoqi@0: if (stack_object_type == VerificationType::uninitialized_this_type() && aoqi@0: target_class_type.equals(current_type()) && aoqi@0: _klass->find_local_field(field_name, field_sig, &fd)) { aoqi@0: stack_object_type = current_type(); aoqi@0: } aoqi@0: is_assignable = target_class_type.is_assignable_from( aoqi@0: stack_object_type, this, false, CHECK_VERIFY(this)); aoqi@0: if (!is_assignable) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame->stack_top_ctx(), aoqi@0: TypeOrigin::cp(index, target_class_type)), aoqi@0: "Bad type on operand stack in putfield"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: check_protected: { aoqi@0: if (_this_type == stack_object_type) aoqi@0: break; // stack_object_type must be assignable to _current_class_type aoqi@0: Symbol* ref_class_name = aoqi@0: cp->klass_name_at(cp->klass_ref_index_at(index)); aoqi@0: if (!name_in_supers(ref_class_name, current_class())) aoqi@0: // stack_object_type must be assignable to _current_class_type since: aoqi@0: // 1. stack_object_type must be assignable to ref_class. aoqi@0: // 2. ref_class must be _current_class or a subclass of it. It can't aoqi@0: // be a superclass of it. See revised JVMS 5.4.4. aoqi@0: break; aoqi@0: aoqi@0: Klass* ref_class_oop = load_class(ref_class_name, CHECK); aoqi@0: if (is_protected_access(current_class(), ref_class_oop, field_name, aoqi@0: field_sig, false)) { aoqi@0: // It's protected access, check if stack object is assignable to aoqi@0: // current class. aoqi@0: is_assignable = current_type().is_assignable_from( aoqi@0: stack_object_type, this, true, CHECK_VERIFY(this)); aoqi@0: if (!is_assignable) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame->stack_top_ctx(), aoqi@0: TypeOrigin::implicit(current_type())), aoqi@0: "Bad access to protected data in getfield"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Look at the method's handlers. If the bci is in the handler's try block hseigel@7643: // then check if the handler_pc is already on the stack. If not, push it hseigel@7643: // unless the handler has already been scanned. aoqi@0: void ClassVerifier::push_handlers(ExceptionTable* exhandlers, hseigel@7643: GrowableArray* handler_list, aoqi@0: GrowableArray* handler_stack, aoqi@0: u4 bci) { aoqi@0: int exlength = exhandlers->length(); aoqi@0: for(int x = 0; x < exlength; x++) { aoqi@0: if (bci >= exhandlers->start_pc(x) && bci < exhandlers->end_pc(x)) { hseigel@7643: u4 exhandler_pc = exhandlers->handler_pc(x); hseigel@7643: if (!handler_list->contains(exhandler_pc)) { hseigel@7643: handler_stack->append_if_missing(exhandler_pc); hseigel@7643: handler_list->append(exhandler_pc); hseigel@7643: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Return TRUE if all code paths starting with start_bc_offset end in aoqi@0: // bytecode athrow or loop. aoqi@0: bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) { aoqi@0: ResourceMark rm; aoqi@0: // Create bytecode stream. aoqi@0: RawBytecodeStream bcs(method()); aoqi@0: u4 code_length = method()->code_size(); aoqi@0: bcs.set_start(start_bc_offset); aoqi@0: u4 target; aoqi@0: // Create stack for storing bytecode start offsets for if* and *switch. aoqi@0: GrowableArray* bci_stack = new GrowableArray(30); aoqi@0: // Create stack for handlers for try blocks containing this handler. aoqi@0: GrowableArray* handler_stack = new GrowableArray(30); hseigel@7643: // Create list of handlers that have been pushed onto the handler_stack hseigel@7643: // so that handlers embedded inside of their own TRY blocks only get hseigel@7643: // scanned once. hseigel@7643: GrowableArray* handler_list = new GrowableArray(30); aoqi@0: // Create list of visited branch opcodes (goto* and if*). aoqi@0: GrowableArray* visited_branches = new GrowableArray(30); aoqi@0: ExceptionTable exhandlers(_method()); aoqi@0: aoqi@0: while (true) { aoqi@0: if (bcs.is_last_bytecode()) { aoqi@0: // if no more starting offsets to parse or if at the end of the aoqi@0: // method then return false. aoqi@0: if ((bci_stack->is_empty()) || ((u4)bcs.end_bci() == code_length)) aoqi@0: return false; aoqi@0: // Pop a bytecode starting offset and scan from there. aoqi@0: bcs.set_start(bci_stack->pop()); aoqi@0: } aoqi@0: Bytecodes::Code opcode = bcs.raw_next(); aoqi@0: u4 bci = bcs.bci(); aoqi@0: aoqi@0: // If the bytecode is in a TRY block, push its handlers so they aoqi@0: // will get parsed. hseigel@7643: push_handlers(&exhandlers, handler_list, handler_stack, bci); aoqi@0: aoqi@0: switch (opcode) { aoqi@0: case Bytecodes::_if_icmpeq: aoqi@0: case Bytecodes::_if_icmpne: aoqi@0: case Bytecodes::_if_icmplt: aoqi@0: case Bytecodes::_if_icmpge: aoqi@0: case Bytecodes::_if_icmpgt: aoqi@0: case Bytecodes::_if_icmple: aoqi@0: case Bytecodes::_ifeq: aoqi@0: case Bytecodes::_ifne: aoqi@0: case Bytecodes::_iflt: aoqi@0: case Bytecodes::_ifge: aoqi@0: case Bytecodes::_ifgt: aoqi@0: case Bytecodes::_ifle: aoqi@0: case Bytecodes::_if_acmpeq: aoqi@0: case Bytecodes::_if_acmpne: aoqi@0: case Bytecodes::_ifnull: aoqi@0: case Bytecodes::_ifnonnull: aoqi@0: target = bcs.dest(); aoqi@0: if (visited_branches->contains(bci)) { shshahma@8525: if (bci_stack->is_empty()) { shshahma@8525: if (handler_stack->is_empty()) { shshahma@8525: return true; shshahma@8525: } else { shshahma@8525: // Parse the catch handlers for try blocks containing athrow. shshahma@8525: bcs.set_start(handler_stack->pop()); shshahma@8525: } shshahma@8525: } else { shshahma@8525: // Pop a bytecode starting offset and scan from there. shshahma@8525: bcs.set_start(bci_stack->pop()); shshahma@8525: } aoqi@0: } else { aoqi@0: if (target > bci) { // forward branch aoqi@0: if (target >= code_length) return false; aoqi@0: // Push the branch target onto the stack. aoqi@0: bci_stack->push(target); aoqi@0: // then, scan bytecodes starting with next. aoqi@0: bcs.set_start(bcs.next_bci()); aoqi@0: } else { // backward branch aoqi@0: // Push bytecode offset following backward branch onto the stack. aoqi@0: bci_stack->push(bcs.next_bci()); aoqi@0: // Check bytecodes starting with branch target. aoqi@0: bcs.set_start(target); aoqi@0: } aoqi@0: // Record target so we don't branch here again. aoqi@0: visited_branches->append(bci); aoqi@0: } aoqi@0: break; aoqi@0: aoqi@0: case Bytecodes::_goto: aoqi@0: case Bytecodes::_goto_w: aoqi@0: target = (opcode == Bytecodes::_goto ? bcs.dest() : bcs.dest_w()); aoqi@0: if (visited_branches->contains(bci)) { shshahma@8525: if (bci_stack->is_empty()) { shshahma@8525: if (handler_stack->is_empty()) { shshahma@8525: return true; shshahma@8525: } else { shshahma@8525: // Parse the catch handlers for try blocks containing athrow. shshahma@8525: bcs.set_start(handler_stack->pop()); shshahma@8525: } shshahma@8525: } else { shshahma@8525: // Been here before, pop new starting offset from stack. shshahma@8525: bcs.set_start(bci_stack->pop()); shshahma@8525: } aoqi@0: } else { aoqi@0: if (target >= code_length) return false; aoqi@0: // Continue scanning from the target onward. aoqi@0: bcs.set_start(target); aoqi@0: // Record target so we don't branch here again. aoqi@0: visited_branches->append(bci); aoqi@0: } aoqi@0: break; aoqi@0: aoqi@0: // Check that all switch alternatives end in 'athrow' bytecodes. Since it aoqi@0: // is difficult to determine where each switch alternative ends, parse aoqi@0: // each switch alternative until either hit a 'return', 'athrow', or reach aoqi@0: // the end of the method's bytecodes. This is gross but should be okay aoqi@0: // because: aoqi@0: // 1. tableswitch and lookupswitch byte codes in handlers for ctor explicit aoqi@0: // constructor invocations should be rare. aoqi@0: // 2. if each switch alternative ends in an athrow then the parsing should be aoqi@0: // short. If there is no athrow then it is bogus code, anyway. aoqi@0: case Bytecodes::_lookupswitch: aoqi@0: case Bytecodes::_tableswitch: aoqi@0: { aoqi@0: address aligned_bcp = (address) round_to((intptr_t)(bcs.bcp() + 1), jintSize); aoqi@0: u4 default_offset = Bytes::get_Java_u4(aligned_bcp) + bci; aoqi@0: int keys, delta; aoqi@0: if (opcode == Bytecodes::_tableswitch) { aoqi@0: jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); aoqi@0: jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); aoqi@0: // This is invalid, but let the regular bytecode verifier aoqi@0: // report this because the user will get a better error message. aoqi@0: if (low > high) return true; aoqi@0: keys = high - low + 1; aoqi@0: delta = 1; aoqi@0: } else { aoqi@0: keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); aoqi@0: delta = 2; aoqi@0: } aoqi@0: // Invalid, let the regular bytecode verifier deal with it. aoqi@0: if (keys < 0) return true; aoqi@0: aoqi@0: // Push the offset of the next bytecode onto the stack. aoqi@0: bci_stack->push(bcs.next_bci()); aoqi@0: aoqi@0: // Push the switch alternatives onto the stack. aoqi@0: for (int i = 0; i < keys; i++) { aoqi@0: u4 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); aoqi@0: if (target > code_length) return false; aoqi@0: bci_stack->push(target); aoqi@0: } aoqi@0: aoqi@0: // Start bytecode parsing for the switch at the default alternative. aoqi@0: if (default_offset > code_length) return false; aoqi@0: bcs.set_start(default_offset); aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: case Bytecodes::_return: aoqi@0: return false; aoqi@0: aoqi@0: case Bytecodes::_athrow: aoqi@0: { aoqi@0: if (bci_stack->is_empty()) { aoqi@0: if (handler_stack->is_empty()) { aoqi@0: return true; aoqi@0: } else { aoqi@0: // Parse the catch handlers for try blocks containing athrow. aoqi@0: bcs.set_start(handler_stack->pop()); aoqi@0: } aoqi@0: } else { aoqi@0: // Pop a bytecode offset and starting scanning from there. aoqi@0: bcs.set_start(bci_stack->pop()); aoqi@0: } aoqi@0: } aoqi@0: break; aoqi@0: aoqi@0: default: aoqi@0: ; aoqi@0: } // end switch aoqi@0: } // end while loop aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_invoke_init( aoqi@0: RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type, hseigel@7473: StackMapFrame* current_frame, u4 code_length, bool in_try_block, hseigel@7473: bool *this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table, hseigel@7473: TRAPS) { aoqi@0: u2 bci = bcs->bci(); aoqi@0: VerificationType type = current_frame->pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: if (type == VerificationType::uninitialized_this_type()) { aoqi@0: // The method must be an method of this class or its superclass aoqi@0: Klass* superk = current_class()->super(); aoqi@0: if (ref_class_type.name() != current_class()->name() && aoqi@0: ref_class_type.name() != superk->name()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: TypeOrigin::implicit(ref_class_type), aoqi@0: TypeOrigin::implicit(current_type())), aoqi@0: "Bad method call"); aoqi@0: return; aoqi@0: } aoqi@0: hseigel@7473: // If this invokespecial call is done from inside of a TRY block then make hseigel@7473: // sure that all catch clause paths end in a throw. Otherwise, this can hseigel@7473: // result in returning an incomplete object. hseigel@7473: if (in_try_block) { hseigel@7473: ExceptionTable exhandlers(_method()); hseigel@7473: int exlength = exhandlers.length(); hseigel@7473: for(int i = 0; i < exlength; i++) { hseigel@7473: u2 start_pc = exhandlers.start_pc(i); hseigel@7473: u2 end_pc = exhandlers.end_pc(i); aoqi@0: hseigel@7473: if (bci >= start_pc && bci < end_pc) { hseigel@7473: if (!ends_in_athrow(exhandlers.handler_pc(i))) { hseigel@7473: verify_error(ErrorContext::bad_code(bci), hseigel@7473: "Bad method call from after the start of a try block"); hseigel@7473: return; hseigel@7473: } else if (VerboseVerification) { hseigel@7473: ResourceMark rm; hseigel@7473: tty->print_cr( hseigel@7473: "Survived call to ends_in_athrow(): %s", hseigel@7473: current_class()->name()->as_C_string()); hseigel@7473: } aoqi@0: } aoqi@0: } hseigel@7473: hseigel@7473: // Check the exception handler target stackmaps with the locals from the hseigel@7473: // incoming stackmap (before initialize_object() changes them to outgoing hseigel@7473: // state). hseigel@7473: verify_exception_handler_targets(bci, true, current_frame, hseigel@7473: stackmap_table, CHECK_VERIFY(this)); hseigel@7473: } // in_try_block aoqi@0: aoqi@0: current_frame->initialize_object(type, current_type()); aoqi@0: *this_uninit = true; aoqi@0: } else if (type.is_uninitialized()) { aoqi@0: u2 new_offset = type.bci(); aoqi@0: address new_bcp = bcs->bcp() - bci + new_offset; aoqi@0: if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { aoqi@0: /* Unreachable? Stack map parsing ensures valid type and new aoqi@0: * instructions have a valid BCI. */ aoqi@0: verify_error(ErrorContext::bad_code(new_offset), aoqi@0: "Expecting new instruction"); aoqi@0: return; aoqi@0: } aoqi@0: u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); aoqi@0: verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this)); aoqi@0: aoqi@0: // The method must be an method of the indicated class aoqi@0: VerificationType new_class_type = cp_index_to_type( aoqi@0: new_class_index, cp, CHECK_VERIFY(this)); aoqi@0: if (!new_class_type.equals(ref_class_type)) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: TypeOrigin::cp(new_class_index, new_class_type), aoqi@0: TypeOrigin::cp(ref_class_index, ref_class_type)), aoqi@0: "Call to wrong method"); aoqi@0: return; aoqi@0: } aoqi@0: // According to the VM spec, if the referent class is a superclass of the aoqi@0: // current class, and is in a different runtime package, and the method is aoqi@0: // protected, then the objectref must be the current class or a subclass aoqi@0: // of the current class. aoqi@0: VerificationType objectref_type = new_class_type; aoqi@0: if (name_in_supers(ref_class_type.name(), current_class())) { hseigel@7594: Klass* ref_klass = load_class(ref_class_type.name(), CHECK); aoqi@0: Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method( aoqi@0: vmSymbols::object_initializer_name(), dbuck@8716: cp->signature_ref_at(bcs->get_index_u2()), Klass::find_overpass); aoqi@0: // Do nothing if method is not found. Let resolution detect the error. aoqi@0: if (m != NULL) { aoqi@0: instanceKlassHandle mh(THREAD, m->method_holder()); aoqi@0: if (m->is_protected() && !mh->is_same_class_package(_klass())) { aoqi@0: bool assignable = current_type().is_assignable_from( aoqi@0: objectref_type, this, true, CHECK_VERIFY(this)); aoqi@0: if (!assignable) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: TypeOrigin::cp(new_class_index, objectref_type), aoqi@0: TypeOrigin::implicit(current_type())), aoqi@0: "Bad access to protected method"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } hseigel@7473: // Check the exception handler target stackmaps with the locals from the hseigel@7473: // incoming stackmap (before initialize_object() changes them to outgoing hseigel@7473: // state). hseigel@7473: if (in_try_block) { hseigel@7473: verify_exception_handler_targets(bci, *this_uninit, current_frame, hseigel@7473: stackmap_table, CHECK_VERIFY(this)); hseigel@7473: } aoqi@0: current_frame->initialize_object(type, new_class_type); aoqi@0: } else { aoqi@0: verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()), aoqi@0: "Bad operand type when invoking "); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool ClassVerifier::is_same_or_direct_interface( aoqi@0: instanceKlassHandle klass, aoqi@0: VerificationType klass_type, aoqi@0: VerificationType ref_class_type) { aoqi@0: if (ref_class_type.equals(klass_type)) return true; aoqi@0: Array* local_interfaces = klass->local_interfaces(); aoqi@0: if (local_interfaces != NULL) { aoqi@0: for (int x = 0; x < local_interfaces->length(); x++) { aoqi@0: Klass* k = local_interfaces->at(x); aoqi@0: assert (k != NULL && k->is_interface(), "invalid interface"); aoqi@0: if (ref_class_type.equals(VerificationType::reference_type(k->name()))) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_invoke_instructions( aoqi@0: RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, hseigel@7473: bool in_try_block, bool *this_uninit, VerificationType return_type, hseigel@7473: constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS) { aoqi@0: // Make sure the constant pool item is the right type aoqi@0: u2 index = bcs->get_index_u2(); aoqi@0: Bytecodes::Code opcode = bcs->raw_code(); aoqi@0: unsigned int types; aoqi@0: switch (opcode) { aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: types = 1 << JVM_CONSTANT_InterfaceMethodref; aoqi@0: break; aoqi@0: case Bytecodes::_invokedynamic: aoqi@0: types = 1 << JVM_CONSTANT_InvokeDynamic; aoqi@0: break; aoqi@0: case Bytecodes::_invokespecial: aoqi@0: case Bytecodes::_invokestatic: aoqi@0: types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ? aoqi@0: (1 << JVM_CONSTANT_Methodref) : aoqi@0: ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref)); aoqi@0: break; aoqi@0: default: aoqi@0: types = 1 << JVM_CONSTANT_Methodref; aoqi@0: } aoqi@0: verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this)); aoqi@0: aoqi@0: // Get method name and signature aoqi@0: Symbol* method_name = cp->name_ref_at(index); aoqi@0: Symbol* method_sig = cp->signature_ref_at(index); aoqi@0: aoqi@0: if (!SignatureVerifier::is_valid_method_signature(method_sig)) { aoqi@0: class_format_error( aoqi@0: "Invalid method signature in class %s referenced " aoqi@0: "from constant pool index %d", _klass->external_name(), index); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Get referenced class type aoqi@0: VerificationType ref_class_type; aoqi@0: if (opcode == Bytecodes::_invokedynamic) { aoqi@0: if (!EnableInvokeDynamic || aoqi@0: _klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { aoqi@0: if (!EnableInvokeDynamic) { aoqi@0: class_format_error("invokedynamic instructions not enabled in this JVM"); aoqi@0: } else { aoqi@0: class_format_error("invokedynamic instructions not supported by this class file version (%d), class %s", aoqi@0: _klass->major_version(), _klass->external_name()); aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: } else { aoqi@0: ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: // For a small signature length, we just allocate 128 bytes instead aoqi@0: // of parsing the signature once to find its size. aoqi@0: // -3 is for '(', ')' and return descriptor; multiply by 2 is for aoqi@0: // longs/doubles to be consertive. aoqi@0: assert(sizeof(VerificationType) == sizeof(uintptr_t), aoqi@0: "buffer type must match VerificationType size"); aoqi@0: uintptr_t on_stack_sig_types_buffer[128]; aoqi@0: // If we make a VerificationType[128] array directly, the compiler calls aoqi@0: // to the c-runtime library to do the allocation instead of just aoqi@0: // stack allocating it. Plus it would run constructors. This shows up aoqi@0: // in performance profiles. aoqi@0: aoqi@0: VerificationType* sig_types; aoqi@0: int size = (method_sig->utf8_length() - 3) * 2; aoqi@0: if (size > 128) { aoqi@0: // Long and double occupies two slots here. aoqi@0: ArgumentSizeComputer size_it(method_sig); aoqi@0: size = size_it.size(); aoqi@0: sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size); aoqi@0: } else{ aoqi@0: sig_types = (VerificationType*)on_stack_sig_types_buffer; aoqi@0: } aoqi@0: SignatureStream sig_stream(method_sig); aoqi@0: int sig_i = 0; aoqi@0: while (!sig_stream.at_return_type()) { aoqi@0: sig_i += change_sig_to_verificationType( aoqi@0: &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this)); aoqi@0: sig_stream.next(); aoqi@0: } aoqi@0: int nargs = sig_i; aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: { aoqi@0: ArgumentSizeComputer size_it(method_sig); aoqi@0: assert(nargs == size_it.size(), "Argument sizes do not match"); aoqi@0: assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough"); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Check instruction operands aoqi@0: u2 bci = bcs->bci(); aoqi@0: if (opcode == Bytecodes::_invokeinterface) { aoqi@0: address bcp = bcs->bcp(); aoqi@0: // 4905268: count operand in invokeinterface should be nargs+1, not nargs. aoqi@0: // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is aoqi@0: // the difference between the size of the operand stack before and after the instruction aoqi@0: // executes. aoqi@0: if (*(bcp+3) != (nargs+1)) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Inconsistent args count operand in invokeinterface"); aoqi@0: return; aoqi@0: } aoqi@0: if (*(bcp+4) != 0) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Fourth operand byte of invokeinterface must be zero"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (opcode == Bytecodes::_invokedynamic) { aoqi@0: address bcp = bcs->bcp(); aoqi@0: if (*(bcp+3) != 0 || *(bcp+4) != 0) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Third and fourth operand bytes of invokedynamic must be zero"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (method_name->byte_at(0) == '<') { aoqi@0: // Make sure can only be invoked by invokespecial aoqi@0: if (opcode != Bytecodes::_invokespecial || aoqi@0: method_name != vmSymbols::object_initializer_name()) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Illegal call to internal method"); aoqi@0: return; aoqi@0: } aoqi@0: } else if (opcode == Bytecodes::_invokespecial aoqi@0: && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) aoqi@0: && !ref_class_type.equals(VerificationType::reference_type( aoqi@0: current_class()->super()->name()))) { aoqi@0: bool subtype = false; aoqi@0: bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref; aoqi@0: if (!current_class()->is_anonymous()) { aoqi@0: subtype = ref_class_type.is_assignable_from( aoqi@0: current_type(), this, false, CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: VerificationType host_klass_type = aoqi@0: VerificationType::reference_type(current_class()->host_klass()->name()); aoqi@0: subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this)); aoqi@0: aoqi@0: // If invokespecial of IMR, need to recheck for same or aoqi@0: // direct interface relative to the host class aoqi@0: have_imr_indirect = (have_imr_indirect && aoqi@0: !is_same_or_direct_interface( aoqi@0: InstanceKlass::cast(current_class()->host_klass()), aoqi@0: host_klass_type, ref_class_type)); aoqi@0: } aoqi@0: if (!subtype) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Bad invokespecial instruction: " aoqi@0: "current class isn't assignable to reference class."); aoqi@0: return; aoqi@0: } else if (have_imr_indirect) { aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Bad invokespecial instruction: " aoqi@0: "interface method reference is in an indirect superinterface."); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: // Match method descriptor with operand stack aoqi@0: for (int i = nargs - 1; i >= 0; i--) { // Run backwards aoqi@0: current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); aoqi@0: } aoqi@0: // Check objectref on operand stack aoqi@0: if (opcode != Bytecodes::_invokestatic && aoqi@0: opcode != Bytecodes::_invokedynamic) { aoqi@0: if (method_name == vmSymbols::object_initializer_name()) { // method aoqi@0: verify_invoke_init(bcs, index, ref_class_type, current_frame, hseigel@7473: code_length, in_try_block, this_uninit, cp, stackmap_table, hseigel@7473: CHECK_VERIFY(this)); aoqi@0: } else { // other methods aoqi@0: // Ensures that target class is assignable to method class. aoqi@0: if (opcode == Bytecodes::_invokespecial) { aoqi@0: if (!current_class()->is_anonymous()) { aoqi@0: current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); aoqi@0: } else { aoqi@0: // anonymous class invokespecial calls: check if the aoqi@0: // objectref is a subtype of the host_klass of the current class aoqi@0: // to allow an anonymous class to reference methods in the host_klass aoqi@0: VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this)); aoqi@0: VerificationType hosttype = aoqi@0: VerificationType::reference_type(current_class()->host_klass()->name()); aoqi@0: bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this)); aoqi@0: if (!subtype) { aoqi@0: verify_error( ErrorContext::bad_type(current_frame->offset(), aoqi@0: current_frame->stack_top_ctx(), aoqi@0: TypeOrigin::implicit(top)), aoqi@0: "Bad type on operand stack"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } else if (opcode == Bytecodes::_invokevirtual) { aoqi@0: VerificationType stack_object_type = aoqi@0: current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); aoqi@0: if (current_type() != stack_object_type) { aoqi@0: assert(cp->cache() == NULL, "not rewritten yet"); aoqi@0: Symbol* ref_class_name = aoqi@0: cp->klass_name_at(cp->klass_ref_index_at(index)); aoqi@0: // See the comments in verify_field_instructions() for aoqi@0: // the rationale behind this. aoqi@0: if (name_in_supers(ref_class_name, current_class())) { aoqi@0: Klass* ref_class = load_class(ref_class_name, CHECK); aoqi@0: if (is_protected_access( aoqi@0: _klass, ref_class, method_name, method_sig, true)) { aoqi@0: // It's protected access, check if stack object is aoqi@0: // assignable to current class. aoqi@0: bool is_assignable = current_type().is_assignable_from( aoqi@0: stack_object_type, this, true, CHECK_VERIFY(this)); aoqi@0: if (!is_assignable) { aoqi@0: if (ref_class_type.name() == vmSymbols::java_lang_Object() aoqi@0: && stack_object_type.is_array() aoqi@0: && method_name == vmSymbols::clone_name()) { aoqi@0: // Special case: arrays pretend to implement public Object aoqi@0: // clone(). aoqi@0: } else { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame->stack_top_ctx(), aoqi@0: TypeOrigin::implicit(current_type())), aoqi@0: "Bad access to protected data in invokevirtual"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered"); aoqi@0: current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // Push the result type. aoqi@0: if (sig_stream.type() != T_VOID) { aoqi@0: if (method_name == vmSymbols::object_initializer_name()) { aoqi@0: // method must have a void return type aoqi@0: /* Unreachable? Class file parser verifies that methods with '<' have aoqi@0: * void return */ aoqi@0: verify_error(ErrorContext::bad_code(bci), aoqi@0: "Return type must be void in method"); aoqi@0: return; aoqi@0: } aoqi@0: VerificationType return_type[2]; aoqi@0: int n = change_sig_to_verificationType( aoqi@0: &sig_stream, return_type, CHECK_VERIFY(this)); aoqi@0: for (int i = 0; i < n; i++) { aoqi@0: current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: VerificationType ClassVerifier::get_newarray_type( aoqi@0: u2 index, u2 bci, TRAPS) { aoqi@0: const char* from_bt[] = { aoqi@0: NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", aoqi@0: }; aoqi@0: if (index < T_BOOLEAN || index > T_LONG) { aoqi@0: verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction"); aoqi@0: return VerificationType::bogus_type(); aoqi@0: } aoqi@0: aoqi@0: // from_bt[index] contains the array signature which has a length of 2 aoqi@0: Symbol* sig = create_temporary_symbol( aoqi@0: from_bt[index], 2, CHECK_(VerificationType::bogus_type())); aoqi@0: return VerificationType::reference_type(sig); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_anewarray( aoqi@0: u2 bci, u2 index, constantPoolHandle cp, aoqi@0: StackMapFrame* current_frame, TRAPS) { aoqi@0: verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); aoqi@0: current_frame->pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: aoqi@0: VerificationType component_type = aoqi@0: cp_index_to_type(index, cp, CHECK_VERIFY(this)); aoqi@0: int length; aoqi@0: char* arr_sig_str; aoqi@0: if (component_type.is_array()) { // it's an array aoqi@0: const char* component_name = component_type.name()->as_utf8(); aoqi@0: // add one dimension to component aoqi@0: length = (int)strlen(component_name) + 1; aoqi@0: arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); aoqi@0: arr_sig_str[0] = '['; aoqi@0: strncpy(&arr_sig_str[1], component_name, length - 1); aoqi@0: } else { // it's an object or interface aoqi@0: const char* component_name = component_type.name()->as_utf8(); aoqi@0: // add one dimension to component with 'L' prepended and ';' postpended. aoqi@0: length = (int)strlen(component_name) + 3; aoqi@0: arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); aoqi@0: arr_sig_str[0] = '['; aoqi@0: arr_sig_str[1] = 'L'; aoqi@0: strncpy(&arr_sig_str[2], component_name, length - 2); aoqi@0: arr_sig_str[length - 1] = ';'; aoqi@0: } aoqi@0: Symbol* arr_sig = create_temporary_symbol( aoqi@0: arr_sig_str, length, CHECK_VERIFY(this)); aoqi@0: VerificationType new_array_type = VerificationType::reference_type(arr_sig); aoqi@0: current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->get_local( aoqi@0: index, VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->get_local_2( aoqi@0: index, VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->push_stack_2( aoqi@0: VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->get_local( aoqi@0: index, VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->push_stack( aoqi@0: VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->get_local_2( aoqi@0: index, VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->push_stack_2( aoqi@0: VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: VerificationType type = current_frame->get_local( aoqi@0: index, VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: current_frame->push_stack(type, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->pop_stack( aoqi@0: VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local( aoqi@0: index, VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->pop_stack_2( aoqi@0: VerificationType::long2_type(), aoqi@0: VerificationType::long_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local_2( aoqi@0: index, VerificationType::long_type(), aoqi@0: VerificationType::long2_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local( aoqi@0: index, VerificationType::float_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: current_frame->pop_stack_2( aoqi@0: VerificationType::double2_type(), aoqi@0: VerificationType::double_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local_2( aoqi@0: index, VerificationType::double_type(), aoqi@0: VerificationType::double2_type(), CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: VerificationType type = current_frame->pop_stack( aoqi@0: VerificationType::reference_check(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local(index, type, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) { aoqi@0: VerificationType type = current_frame->get_local( aoqi@0: index, VerificationType::integer_type(), CHECK_VERIFY(this)); aoqi@0: current_frame->set_local(index, type, CHECK_VERIFY(this)); aoqi@0: } aoqi@0: aoqi@0: void ClassVerifier::verify_return_value( aoqi@0: VerificationType return_type, VerificationType type, u2 bci, aoqi@0: StackMapFrame* current_frame, TRAPS) { aoqi@0: if (return_type == VerificationType::bogus_type()) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), aoqi@0: "Method expects a return value"); aoqi@0: return; aoqi@0: } aoqi@0: bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this)); aoqi@0: if (!match) { aoqi@0: verify_error(ErrorContext::bad_type(bci, aoqi@0: current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), aoqi@0: "Bad return type"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // The verifier creates symbols which are substrings of Symbols. aoqi@0: // These are stored in the verifier until the end of verification so that aoqi@0: // they can be reference counted. aoqi@0: Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin, aoqi@0: int end, TRAPS) { aoqi@0: Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL); aoqi@0: _symbols->push(sym); aoqi@0: return sym; aoqi@0: } aoqi@0: aoqi@0: Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) { aoqi@0: Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL); aoqi@0: _symbols->push(sym); aoqi@0: return sym; aoqi@0: }