duke@435: /* jrose@2639: * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/classFileStream.hpp" stefank@2314: #include "classfile/javaClasses.hpp" stefank@2314: #include "classfile/stackMapTable.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/verifier.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "interpreter/bytecodeStream.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/typeArrayOop.hpp" stefank@2314: #include "prims/jvm.h" stefank@2314: #include "runtime/fieldDescriptor.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/javaCalls.hpp" stefank@2314: #include "runtime/orderAccess.hpp" stefank@2314: #include "runtime/os.hpp" stefank@2314: #ifdef TARGET_ARCH_x86 stefank@2314: # include "bytes_x86.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_sparc stefank@2314: # include "bytes_sparc.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_zero stefank@2314: # include "bytes_zero.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_arm bobv@2508: # include "bytes_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_ppc bobv@2508: # include "bytes_ppc.hpp" bobv@2508: #endif duke@435: kamg@1915: #define NOFAILOVER_MAJOR_VERSION 51 kamg@1915: duke@435: // Access to external entry for VerifyClassCodes - old byte code verifier duke@435: duke@435: extern "C" { duke@435: typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); duke@435: typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint); duke@435: } duke@435: duke@435: static void* volatile _verify_byte_codes_fn = NULL; duke@435: duke@435: static volatile jint _is_new_verify_byte_codes_fn = (jint) true; duke@435: duke@435: static void* verify_byte_codes_fn() { duke@435: if (_verify_byte_codes_fn == NULL) { duke@435: void *lib_handle = os::native_java_library(); ikrylov@2322: void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); duke@435: OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); duke@435: if (func == NULL) { duke@435: OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false); ikrylov@2322: func = os::dll_lookup(lib_handle, "VerifyClassCodes"); duke@435: OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); duke@435: } duke@435: } duke@435: return (void*)_verify_byte_codes_fn; duke@435: } duke@435: duke@435: duke@435: // Methods in Verifier duke@435: acorn@1408: bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { acorn@1408: return (class_loader == NULL || !should_verify_class) ? duke@435: BytecodeVerificationLocal : BytecodeVerificationRemote; duke@435: } duke@435: duke@435: bool Verifier::relax_verify_for(oop loader) { duke@435: bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); duke@435: bool need_verify = duke@435: // verifyAll duke@435: (BytecodeVerificationLocal && BytecodeVerificationRemote) || duke@435: // verifyRemote duke@435: (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); duke@435: return !need_verify; duke@435: } duke@435: acorn@1408: bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { coleenp@2497: HandleMark hm; duke@435: ResourceMark rm(THREAD); duke@435: coleenp@2497: Symbol* exception_name = NULL; duke@435: const size_t message_buffer_len = klass->name()->utf8_length() + 1024; duke@435: char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); duke@435: duke@435: const char* klassName = klass->external_name(); duke@435: duke@435: // If the class should be verified, first see if we can use the split duke@435: // verifier. If not, or if verification fails and FailOverToOldVerifier duke@435: // is set, then call the inference verifier. acorn@1408: if (is_eligible_for_verification(klass, should_verify_class)) { duke@435: if (TraceClassInitialization) { duke@435: tty->print_cr("Start class verification for: %s", klassName); duke@435: } duke@435: if (UseSplitVerifier && duke@435: klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { duke@435: ClassVerifier split_verifier( duke@435: klass, message_buffer, message_buffer_len, THREAD); duke@435: split_verifier.verify_class(THREAD); duke@435: exception_name = split_verifier.result(); kamg@1915: if (klass->major_version() < NOFAILOVER_MAJOR_VERSION && kamg@1915: FailOverToOldVerifier && !HAS_PENDING_EXCEPTION && duke@435: (exception_name == vmSymbols::java_lang_VerifyError() || duke@435: exception_name == vmSymbols::java_lang_ClassFormatError())) { duke@435: if (TraceClassInitialization) { duke@435: tty->print_cr( duke@435: "Fail over class verification to old verifier for: %s", klassName); duke@435: } duke@435: exception_name = inference_verify( duke@435: klass, message_buffer, message_buffer_len, THREAD); duke@435: } duke@435: } else { duke@435: exception_name = inference_verify( duke@435: klass, message_buffer, message_buffer_len, THREAD); duke@435: } duke@435: duke@435: if (TraceClassInitialization) { duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: tty->print("Verification for %s has", klassName); duke@435: tty->print_cr(" exception pending %s ", duke@435: instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); coleenp@2497: } else if (exception_name != NULL) { duke@435: tty->print_cr("Verification for %s failed", klassName); duke@435: } duke@435: tty->print_cr("End class verification for: %s", klassName); duke@435: } duke@435: } duke@435: duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: return false; // use the existing exception coleenp@2497: } else if (exception_name == NULL) { duke@435: return true; // verifcation succeeded duke@435: } else { // VerifyError or ClassFormatError to be created and thrown duke@435: ResourceMark rm(THREAD); duke@435: instanceKlassHandle kls = duke@435: SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); duke@435: while (!kls.is_null()) { duke@435: if (kls == klass) { duke@435: // If the class being verified is the exception we're creating duke@435: // or one of it's superclasses, we're in trouble and are going duke@435: // to infinitely recurse when we try to initialize the exception. duke@435: // So bail out here by throwing the preallocated VM error. duke@435: THROW_OOP_(Universe::virtual_machine_error_instance(), false); duke@435: } duke@435: kls = kls->super(); duke@435: } duke@435: message_buffer[message_buffer_len - 1] = '\0'; // just to be sure duke@435: THROW_MSG_(exception_name, message_buffer, false); duke@435: } duke@435: } duke@435: acorn@1408: bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { coleenp@2497: Symbol* name = klass->name(); never@1577: klassOop refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass(); duke@435: acorn@1408: return (should_verify_for(klass->class_loader(), should_verify_class) && duke@435: // return if the class is a bootstrapping class acorn@1408: // or defineClass specified not to verify by default (flags override passed arg) duke@435: // We need to skip the following four for bootstraping duke@435: name != vmSymbols::java_lang_Object() && duke@435: name != vmSymbols::java_lang_Class() && duke@435: name != vmSymbols::java_lang_String() && duke@435: name != vmSymbols::java_lang_Throwable() && duke@435: duke@435: // Can not verify the bytecodes for shared classes because they have duke@435: // already been rewritten to contain constant pool cache indices, duke@435: // which the verifier can't understand. duke@435: // Shared classes shouldn't have stackmaps either. duke@435: !klass()->is_shared() && duke@435: duke@435: // As of the fix for 4486457 we disable verification for all of the duke@435: // dynamically-generated bytecodes associated with the 1.4 duke@435: // reflection implementation, not just those associated with duke@435: // sun/reflect/SerializationConstructorAccessor. duke@435: // NOTE: this is called too early in the bootstrapping process to be duke@435: // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection. duke@435: (refl_magic_klass == NULL || duke@435: !klass->is_subtype_of(refl_magic_klass) || duke@435: VerifyReflectionBytecodes) duke@435: ); duke@435: } duke@435: coleenp@2497: Symbol* Verifier::inference_verify( duke@435: instanceKlassHandle klass, char* message, size_t message_len, TRAPS) { duke@435: JavaThread* thread = (JavaThread*)THREAD; duke@435: JNIEnv *env = thread->jni_environment(); duke@435: duke@435: void* verify_func = verify_byte_codes_fn(); duke@435: duke@435: if (verify_func == NULL) { duke@435: jio_snprintf(message, message_len, "Could not link verifier"); duke@435: return vmSymbols::java_lang_VerifyError(); duke@435: } duke@435: duke@435: ResourceMark rm(THREAD); duke@435: if (ClassVerifier::_verify_verbose) { duke@435: tty->print_cr("Verifying class %s with old format", klass->external_name()); duke@435: } duke@435: duke@435: jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); duke@435: jint result; duke@435: duke@435: { duke@435: HandleMark hm(thread); duke@435: ThreadToNativeFromVM ttn(thread); duke@435: // ThreadToNativeFromVM takes care of changing thread_state, so safepoint duke@435: // code knows that we have left the VM duke@435: duke@435: if (_is_new_verify_byte_codes_fn) { duke@435: verify_byte_codes_fn_new_t func = duke@435: CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func); duke@435: result = (*func)(env, cls, message, (int)message_len, duke@435: klass->major_version()); duke@435: } else { duke@435: verify_byte_codes_fn_t func = duke@435: CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func); duke@435: result = (*func)(env, cls, message, (int)message_len); duke@435: } duke@435: } duke@435: duke@435: JNIHandles::destroy_local(cls); duke@435: duke@435: // These numbers are chosen so that VerifyClassCodes interface doesn't need duke@435: // to be changed (still return jboolean (unsigned char)), and result is duke@435: // 1 when verification is passed. duke@435: if (result == 0) { duke@435: return vmSymbols::java_lang_VerifyError(); duke@435: } else if (result == 1) { coleenp@2497: return NULL; // verified. duke@435: } else if (result == 2) { coleenp@2497: THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL); duke@435: } else if (result == 3) { duke@435: return vmSymbols::java_lang_ClassFormatError(); duke@435: } else { duke@435: ShouldNotReachHere(); coleenp@2497: return NULL; duke@435: } duke@435: } duke@435: duke@435: // Methods in ClassVerifier duke@435: duke@435: bool ClassVerifier::_verify_verbose = false; duke@435: duke@435: ClassVerifier::ClassVerifier( duke@435: instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS) coleenp@2497: : _thread(THREAD), _exception_type(NULL), _message(msg), duke@435: _message_buffer_len(msg_len), _klass(klass) { duke@435: _this_type = VerificationType::reference_type(klass->name()); coleenp@2497: // Create list to hold symbols in reference area. coleenp@2497: _symbols = new GrowableArray(100, 0, NULL); duke@435: } duke@435: duke@435: ClassVerifier::~ClassVerifier() { coleenp@2497: // Decrement the reference count for any symbols created. coleenp@2497: for (int i = 0; i < _symbols->length(); i++) { coleenp@2497: Symbol* s = _symbols->at(i); coleenp@2497: s->decrement_refcount(); coleenp@2497: } duke@435: } duke@435: kamg@2297: VerificationType ClassVerifier::object_type() const { kamg@2297: return VerificationType::reference_type(vmSymbols::java_lang_Object()); kamg@2297: } kamg@2297: duke@435: void ClassVerifier::verify_class(TRAPS) { duke@435: if (_verify_verbose) { duke@435: tty->print_cr("Verifying class %s with new format", duke@435: _klass->external_name()); duke@435: } duke@435: duke@435: objArrayHandle methods(THREAD, _klass->methods()); duke@435: int num_methods = methods->length(); duke@435: duke@435: for (int index = 0; index < num_methods; index++) { jrose@1925: // Check for recursive re-verification before each method. jrose@1925: if (was_recursively_verified()) return; jrose@1925: duke@435: methodOop m = (methodOop)methods->obj_at(index); duke@435: if (m->is_native() || m->is_abstract()) { duke@435: // If m is native or abstract, skip it. It is checked in class file duke@435: // parser that methods do not override a final method. duke@435: continue; duke@435: } duke@435: verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); duke@435: } jrose@1925: jrose@1925: if (_verify_verbose || TraceClassInitialization) { jrose@1925: if (was_recursively_verified()) jrose@1925: tty->print_cr("Recursive verification detected for: %s", jrose@1925: _klass->external_name()); jrose@1925: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_method(methodHandle m, TRAPS) { duke@435: _method = m; // initialize _method duke@435: if (_verify_verbose) { duke@435: tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); duke@435: } duke@435: duke@435: const char* bad_type_msg = "Bad type on operand stack in %s"; duke@435: duke@435: int32_t max_stack = m->max_stack(); duke@435: int32_t max_locals = m->max_locals(); duke@435: constantPoolHandle cp(THREAD, m->constants()); duke@435: duke@435: if (!SignatureVerifier::is_valid_method_signature(m->signature())) { duke@435: class_format_error("Invalid method signature"); duke@435: return; duke@435: } duke@435: duke@435: // Initial stack map frame: offset is 0, stack is initially empty. duke@435: StackMapFrame current_frame(max_locals, max_stack, this); duke@435: // Set initial locals duke@435: VerificationType return_type = current_frame.set_locals_from_arg( duke@435: m, current_type(), CHECK_VERIFY(this)); duke@435: duke@435: int32_t stackmap_index = 0; // index to the stackmap array duke@435: duke@435: u4 code_length = m->code_size(); duke@435: duke@435: // Scan the bytecode and map each instruction's start offset to a number. duke@435: char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this)); duke@435: duke@435: int ex_min = code_length; duke@435: int ex_max = -1; duke@435: // Look through each item on the exception table. Each of the fields must refer duke@435: // to a legal instruction. duke@435: verify_exception_handler_table( duke@435: code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this)); duke@435: duke@435: // Look through each entry on the local variable table and make sure duke@435: // its range of code array offsets is valid. (4169817) duke@435: if (m->has_localvariable_table()) { duke@435: verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: typeArrayHandle stackmap_data(THREAD, m->stackmap_data()); duke@435: StackMapStream stream(stackmap_data); duke@435: StackMapReader reader(this, &stream, code_data, code_length, THREAD); duke@435: StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, duke@435: code_data, code_length, CHECK_VERIFY(this)); duke@435: duke@435: if (_verify_verbose) { duke@435: stackmap_table.print(); duke@435: } duke@435: duke@435: RawBytecodeStream bcs(m); duke@435: duke@435: // Scan the byte code linearly from the start to the end duke@435: bool no_control_flow = false; // Set to true when there is no direct control duke@435: // flow from current instruction to the next duke@435: // instruction in sequence duke@435: Bytecodes::Code opcode; duke@435: while (!bcs.is_last_bytecode()) { jrose@1925: // Check for recursive re-verification before each bytecode. jrose@1925: if (was_recursively_verified()) return; jrose@1925: duke@435: opcode = bcs.raw_next(); duke@435: u2 bci = bcs.bci(); duke@435: duke@435: // Set current frame's offset to bci duke@435: current_frame.set_offset(bci); duke@435: duke@435: // Make sure every offset in stackmap table point to the beginning to duke@435: // an instruction. Match current_frame to stackmap_table entry with duke@435: // the same offset if exists. duke@435: stackmap_index = verify_stackmap_table( duke@435: stackmap_index, bci, ¤t_frame, &stackmap_table, duke@435: no_control_flow, CHECK_VERIFY(this)); duke@435: duke@435: bool this_uninit = false; // Set to true when invokespecial initialized 'this' duke@435: duke@435: // Merge with the next instruction duke@435: { duke@435: u2 index; duke@435: int target; duke@435: VerificationType type, type2; duke@435: VerificationType atype; duke@435: duke@435: #ifndef PRODUCT duke@435: if (_verify_verbose) { duke@435: current_frame.print(); duke@435: tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); duke@435: } duke@435: #endif duke@435: duke@435: // Make sure wide instruction is in correct format duke@435: if (bcs.is_wide()) { duke@435: if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && duke@435: opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && duke@435: opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && duke@435: opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && duke@435: opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && duke@435: opcode != Bytecodes::_dstore) { duke@435: verify_error(bci, "Bad wide instruction"); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: switch (opcode) { duke@435: case Bytecodes::_nop : duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_aconst_null : duke@435: current_frame.push_stack( duke@435: VerificationType::null_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iconst_m1 : duke@435: case Bytecodes::_iconst_0 : duke@435: case Bytecodes::_iconst_1 : duke@435: case Bytecodes::_iconst_2 : duke@435: case Bytecodes::_iconst_3 : duke@435: case Bytecodes::_iconst_4 : duke@435: case Bytecodes::_iconst_5 : duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lconst_0 : duke@435: case Bytecodes::_lconst_1 : duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fconst_0 : duke@435: case Bytecodes::_fconst_1 : duke@435: case Bytecodes::_fconst_2 : duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dconst_0 : duke@435: case Bytecodes::_dconst_1 : duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_sipush : duke@435: case Bytecodes::_bipush : duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_ldc : duke@435: verify_ldc( jrose@1920: opcode, bcs.get_index_u1(), ¤t_frame, duke@435: cp, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_ldc_w : duke@435: case Bytecodes::_ldc2_w : duke@435: verify_ldc( jrose@1920: opcode, bcs.get_index_u2(), ¤t_frame, duke@435: cp, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iload : duke@435: verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iload_0 : duke@435: case Bytecodes::_iload_1 : duke@435: case Bytecodes::_iload_2 : duke@435: case Bytecodes::_iload_3 : duke@435: index = opcode - Bytecodes::_iload_0; duke@435: verify_iload(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lload : duke@435: verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lload_0 : duke@435: case Bytecodes::_lload_1 : duke@435: case Bytecodes::_lload_2 : duke@435: case Bytecodes::_lload_3 : duke@435: index = opcode - Bytecodes::_lload_0; duke@435: verify_lload(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fload : duke@435: verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fload_0 : duke@435: case Bytecodes::_fload_1 : duke@435: case Bytecodes::_fload_2 : duke@435: case Bytecodes::_fload_3 : duke@435: index = opcode - Bytecodes::_fload_0; duke@435: verify_fload(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dload : duke@435: verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dload_0 : duke@435: case Bytecodes::_dload_1 : duke@435: case Bytecodes::_dload_2 : duke@435: case Bytecodes::_dload_3 : duke@435: index = opcode - Bytecodes::_dload_0; duke@435: verify_dload(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_aload : duke@435: verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_aload_0 : duke@435: case Bytecodes::_aload_1 : duke@435: case Bytecodes::_aload_2 : duke@435: case Bytecodes::_aload_3 : duke@435: index = opcode - Bytecodes::_aload_0; duke@435: verify_aload(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iaload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_int_array()) { duke@435: verify_error(bci, bad_type_msg, "iaload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_baload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_bool_array() && !atype.is_byte_array()) { duke@435: verify_error(bci, bad_type_msg, "baload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_caload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_char_array()) { duke@435: verify_error(bci, bad_type_msg, "caload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_saload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_short_array()) { duke@435: verify_error(bci, bad_type_msg, "saload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_laload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_long_array()) { duke@435: verify_error(bci, bad_type_msg, "laload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_faload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_float_array()) { duke@435: verify_error(bci, bad_type_msg, "faload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_daload : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_double_array()) { duke@435: verify_error(bci, bad_type_msg, "daload"); duke@435: return; duke@435: } duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_aaload : { duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_reference_array()) { duke@435: verify_error(bci, bad_type_msg, "aaload"); duke@435: return; duke@435: } duke@435: if (atype.is_null()) { duke@435: current_frame.push_stack( duke@435: VerificationType::null_type(), CHECK_VERIFY(this)); duke@435: } else { duke@435: VerificationType component = coleenp@2497: atype.get_component(this, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(component, CHECK_VERIFY(this)); duke@435: } duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_istore : duke@435: verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_istore_0 : duke@435: case Bytecodes::_istore_1 : duke@435: case Bytecodes::_istore_2 : duke@435: case Bytecodes::_istore_3 : duke@435: index = opcode - Bytecodes::_istore_0; duke@435: verify_istore(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lstore : duke@435: verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lstore_0 : duke@435: case Bytecodes::_lstore_1 : duke@435: case Bytecodes::_lstore_2 : duke@435: case Bytecodes::_lstore_3 : duke@435: index = opcode - Bytecodes::_lstore_0; duke@435: verify_lstore(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fstore : duke@435: verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fstore_0 : duke@435: case Bytecodes::_fstore_1 : duke@435: case Bytecodes::_fstore_2 : duke@435: case Bytecodes::_fstore_3 : duke@435: index = opcode - Bytecodes::_fstore_0; duke@435: verify_fstore(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dstore : duke@435: verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dstore_0 : duke@435: case Bytecodes::_dstore_1 : duke@435: case Bytecodes::_dstore_2 : duke@435: case Bytecodes::_dstore_3 : duke@435: index = opcode - Bytecodes::_dstore_0; duke@435: verify_dstore(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_astore : duke@435: verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_astore_0 : duke@435: case Bytecodes::_astore_1 : duke@435: case Bytecodes::_astore_2 : duke@435: case Bytecodes::_astore_3 : duke@435: index = opcode - Bytecodes::_astore_0; duke@435: verify_astore(index, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iastore : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_int_array()) { duke@435: verify_error(bci, bad_type_msg, "iastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_bastore : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_bool_array() && !atype.is_byte_array()) { duke@435: verify_error(bci, bad_type_msg, "bastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_castore : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_char_array()) { duke@435: verify_error(bci, bad_type_msg, "castore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_sastore : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_short_array()) { duke@435: verify_error(bci, bad_type_msg, "sastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lastore : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_long_array()) { duke@435: verify_error(bci, bad_type_msg, "lastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fastore : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack duke@435: (VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_float_array()) { duke@435: verify_error(bci, bad_type_msg, "fastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dastore : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (!atype.is_double_array()) { duke@435: verify_error(bci, bad_type_msg, "dastore"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_aastore : kamg@2297: type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: atype = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: // more type-checking is done at runtime duke@435: if (!atype.is_reference_array()) { duke@435: verify_error(bci, bad_type_msg, "aastore"); duke@435: return; duke@435: } duke@435: // 4938384: relaxed constraint in JVMS 3nd edition. duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_pop : duke@435: current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_pop2 : duke@435: type = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type.is_category1()) { duke@435: current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if (type.is_category2_2nd()) { duke@435: current_frame.pop_stack( duke@435: VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "pop2"); duke@435: return; duke@435: } duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dup : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dup_x1 : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dup_x2 : duke@435: { duke@435: VerificationType type3; duke@435: type = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type2.is_category1()) { duke@435: type3 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if (type2.is_category2_2nd()) { duke@435: type3 = current_frame.pop_stack( duke@435: VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "dup_x2"); duke@435: return; duke@435: } duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type3, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_dup2 : duke@435: type = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type.is_category1()) { duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if (type.is_category2_2nd()) { duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "dup2"); duke@435: return; duke@435: } duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dup2_x1 : duke@435: { duke@435: VerificationType type3; duke@435: type = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type.is_category1()) { duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if(type.is_category2_2nd()) { duke@435: type2 = current_frame.pop_stack duke@435: (VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "dup2_x1"); duke@435: return; duke@435: } duke@435: type3 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type3, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_dup2_x2 : duke@435: { duke@435: VerificationType type3, type4; duke@435: type = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type.is_category1()) { duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if (type.is_category2_2nd()) { duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "dup2_x2"); duke@435: return; duke@435: } duke@435: type3 = current_frame.pop_stack(CHECK_VERIFY(this)); duke@435: if (type3.is_category1()) { duke@435: type4 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: } else if (type3.is_category2_2nd()) { duke@435: type4 = current_frame.pop_stack( duke@435: VerificationType::category2_check(), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, bad_type_msg, "dup2_x2"); duke@435: return; duke@435: } duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type4, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type3, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_swap : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::category1_check(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type2, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iadd : duke@435: case Bytecodes::_isub : duke@435: case Bytecodes::_imul : duke@435: case Bytecodes::_idiv : duke@435: case Bytecodes::_irem : duke@435: case Bytecodes::_ishl : duke@435: case Bytecodes::_ishr : duke@435: case Bytecodes::_iushr : duke@435: case Bytecodes::_ior : duke@435: case Bytecodes::_ixor : duke@435: case Bytecodes::_iand : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_ineg : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_ladd : duke@435: case Bytecodes::_lsub : duke@435: case Bytecodes::_lmul : duke@435: case Bytecodes::_ldiv : duke@435: case Bytecodes::_lrem : duke@435: case Bytecodes::_land : duke@435: case Bytecodes::_lor : duke@435: case Bytecodes::_lxor : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_lneg : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lshl : duke@435: case Bytecodes::_lshr : duke@435: case Bytecodes::_lushr : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fadd : duke@435: case Bytecodes::_fsub : duke@435: case Bytecodes::_fmul : duke@435: case Bytecodes::_fdiv : duke@435: case Bytecodes::_frem : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_fneg : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dadd : duke@435: case Bytecodes::_dsub : duke@435: case Bytecodes::_dmul : duke@435: case Bytecodes::_ddiv : duke@435: case Bytecodes::_drem : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_dneg : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_iinc : duke@435: verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_i2l : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_l2i : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_i2f : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_i2d : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_l2f : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_l2d : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_f2i : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_f2l : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_f2d : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_d2i : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_d2l : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_d2f : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_i2b : duke@435: case Bytecodes::_i2c : duke@435: case Bytecodes::_i2s : duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_lcmp : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_fcmpl : duke@435: case Bytecodes::_fcmpg : duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_dcmpl : duke@435: case Bytecodes::_dcmpg : duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_if_icmpeq: duke@435: case Bytecodes::_if_icmpne: duke@435: case Bytecodes::_if_icmplt: duke@435: case Bytecodes::_if_icmpge: duke@435: case Bytecodes::_if_icmpgt: duke@435: case Bytecodes::_if_icmple: duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_ifeq: duke@435: case Bytecodes::_ifne: duke@435: case Bytecodes::_iflt: duke@435: case Bytecodes::_ifge: duke@435: case Bytecodes::_ifgt: duke@435: case Bytecodes::_ifle: duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: target = bcs.dest(); duke@435: stackmap_table.check_jump_target( duke@435: ¤t_frame, target, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_if_acmpeq : duke@435: case Bytecodes::_if_acmpne : duke@435: current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: // fall through duke@435: case Bytecodes::_ifnull : duke@435: case Bytecodes::_ifnonnull : duke@435: current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: target = bcs.dest(); duke@435: stackmap_table.check_jump_target duke@435: (¤t_frame, target, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_goto : duke@435: target = bcs.dest(); duke@435: stackmap_table.check_jump_target( duke@435: ¤t_frame, target, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_goto_w : duke@435: target = bcs.dest_w(); duke@435: stackmap_table.check_jump_target( duke@435: ¤t_frame, target, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_tableswitch : duke@435: case Bytecodes::_lookupswitch : duke@435: verify_switch( duke@435: &bcs, code_length, code_data, ¤t_frame, duke@435: &stackmap_table, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_ireturn : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_lreturn : duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: type = current_frame.pop_stack( duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_freturn : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_dreturn : duke@435: type2 = current_frame.pop_stack( duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: type = current_frame.pop_stack( duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_areturn : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_return : duke@435: if (return_type != VerificationType::bogus_type()) { duke@435: verify_error(bci, "Method expects no return value"); duke@435: return; duke@435: } duke@435: // Make sure "this" has been initialized if current method is an duke@435: // duke@435: if (_method->name() == vmSymbols::object_initializer_name() && duke@435: current_frame.flag_this_uninit()) { duke@435: verify_error(bci, duke@435: "Constructor must call super() or this() before return"); duke@435: return; duke@435: } duke@435: no_control_flow = true; break; duke@435: case Bytecodes::_getstatic : duke@435: case Bytecodes::_putstatic : duke@435: case Bytecodes::_getfield : duke@435: case Bytecodes::_putfield : duke@435: verify_field_instructions( duke@435: &bcs, ¤t_frame, cp, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_invokevirtual : duke@435: case Bytecodes::_invokespecial : duke@435: case Bytecodes::_invokestatic : duke@435: verify_invoke_instructions( duke@435: &bcs, code_length, ¤t_frame, duke@435: &this_uninit, return_type, cp, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_invokeinterface : jrose@1161: case Bytecodes::_invokedynamic : duke@435: verify_invoke_instructions( duke@435: &bcs, code_length, ¤t_frame, duke@435: &this_uninit, return_type, cp, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_new : duke@435: { jrose@1920: index = bcs.get_index_u2(); duke@435: verify_cp_class_type(index, cp, CHECK_VERIFY(this)); duke@435: VerificationType new_class_type = duke@435: cp_index_to_type(index, cp, CHECK_VERIFY(this)); duke@435: if (!new_class_type.is_object()) { duke@435: verify_error(bci, "Illegal new instruction"); duke@435: return; duke@435: } duke@435: type = VerificationType::uninitialized_type(bci); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_newarray : duke@435: type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this)); duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_anewarray : duke@435: verify_anewarray( jrose@1920: bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_arraylength : duke@435: type = current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); kamg@569: if (!(type.is_null() || type.is_array())) { duke@435: verify_error(bci, bad_type_msg, "arraylength"); duke@435: } duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_checkcast : duke@435: { jrose@1920: index = bcs.get_index_u2(); duke@435: verify_cp_class_type(index, cp, CHECK_VERIFY(this)); kamg@2297: current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); duke@435: VerificationType klass_type = cp_index_to_type( duke@435: index, cp, CHECK_VERIFY(this)); duke@435: current_frame.push_stack(klass_type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_instanceof : { jrose@1920: index = bcs.get_index_u2(); duke@435: verify_cp_class_type(index, cp, CHECK_VERIFY(this)); kamg@2297: current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); duke@435: current_frame.push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_monitorenter : duke@435: case Bytecodes::_monitorexit : duke@435: current_frame.pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: case Bytecodes::_multianewarray : duke@435: { jrose@1920: index = bcs.get_index_u2(); duke@435: u2 dim = *(bcs.bcp()+3); duke@435: verify_cp_class_type(index, cp, CHECK_VERIFY(this)); duke@435: VerificationType new_array_type = duke@435: cp_index_to_type(index, cp, CHECK_VERIFY(this)); duke@435: if (!new_array_type.is_array()) { duke@435: verify_error(bci, duke@435: "Illegal constant pool index in multianewarray instruction"); duke@435: return; duke@435: } duke@435: if (dim < 1 || new_array_type.dimensions() < dim) { duke@435: verify_error(bci, duke@435: "Illegal dimension in multianewarray instruction"); duke@435: return; duke@435: } duke@435: for (int i = 0; i < dim; i++) { duke@435: current_frame.pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: } duke@435: current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); duke@435: no_control_flow = false; break; duke@435: } duke@435: case Bytecodes::_athrow : duke@435: type = VerificationType::reference_type( duke@435: vmSymbols::java_lang_Throwable()); duke@435: current_frame.pop_stack(type, CHECK_VERIFY(this)); duke@435: no_control_flow = true; break; duke@435: default: duke@435: // We only need to check the valid bytecodes in class file. duke@435: // And jsr and ret are not in the new class file format in JDK1.5. duke@435: verify_error(bci, "Bad instruction"); duke@435: no_control_flow = false; duke@435: return; duke@435: } // end switch duke@435: } // end Merge with the next instruction duke@435: duke@435: // Look for possible jump target in exception handlers and see if it duke@435: // matches current_frame duke@435: if (bci >= ex_min && bci < ex_max) { duke@435: verify_exception_handler_targets( duke@435: bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); duke@435: } duke@435: } // end while duke@435: duke@435: // Make sure that control flow does not fall through end of the method duke@435: if (!no_control_flow) { duke@435: verify_error(code_length, "Control flow falls through code end"); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { duke@435: char* code_data = NEW_RESOURCE_ARRAY(char, code_length); duke@435: memset(code_data, 0, sizeof(char) * code_length); duke@435: RawBytecodeStream bcs(m); duke@435: duke@435: while (!bcs.is_last_bytecode()) { duke@435: if (bcs.raw_next() != Bytecodes::_illegal) { duke@435: int bci = bcs.bci(); jrose@1920: if (bcs.raw_code() == Bytecodes::_new) { duke@435: code_data[bci] = NEW_OFFSET; duke@435: } else { duke@435: code_data[bci] = BYTECODE_OFFSET; duke@435: } duke@435: } else { duke@435: verify_error(bcs.bci(), "Bad instruction"); duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: return code_data; duke@435: } duke@435: duke@435: void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) { duke@435: typeArrayHandle exhandlers (THREAD, _method->exception_table()); duke@435: constantPoolHandle cp (THREAD, _method->constants()); duke@435: duke@435: if (exhandlers() != NULL) { duke@435: for(int i = 0; i < exhandlers->length();) { duke@435: u2 start_pc = exhandlers->int_at(i++); duke@435: u2 end_pc = exhandlers->int_at(i++); duke@435: u2 handler_pc = exhandlers->int_at(i++); duke@435: if (start_pc >= code_length || code_data[start_pc] == 0) { duke@435: class_format_error("Illegal exception table start_pc %d", start_pc); duke@435: return; duke@435: } duke@435: if (end_pc != code_length) { // special case: end_pc == code_length duke@435: if (end_pc > code_length || code_data[end_pc] == 0) { duke@435: class_format_error("Illegal exception table end_pc %d", end_pc); duke@435: return; duke@435: } duke@435: } duke@435: if (handler_pc >= code_length || code_data[handler_pc] == 0) { duke@435: class_format_error("Illegal exception table handler_pc %d", handler_pc); duke@435: return; duke@435: } duke@435: int catch_type_index = exhandlers->int_at(i++); duke@435: if (catch_type_index != 0) { duke@435: VerificationType catch_type = cp_index_to_type( duke@435: catch_type_index, cp, CHECK_VERIFY(this)); duke@435: VerificationType throwable = duke@435: VerificationType::reference_type(vmSymbols::java_lang_Throwable()); duke@435: bool is_subclass = throwable.is_assignable_from( coleenp@2497: catch_type, this, CHECK_VERIFY(this)); duke@435: if (!is_subclass) { duke@435: // 4286534: should throw VerifyError according to recent spec change duke@435: verify_error( duke@435: "Catch type is not a subclass of Throwable in handler %d", duke@435: handler_pc); duke@435: return; duke@435: } duke@435: } duke@435: if (start_pc < min) min = start_pc; duke@435: if (end_pc > max) max = end_pc; duke@435: } duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) { duke@435: int localvariable_table_length = _method()->localvariable_table_length(); duke@435: if (localvariable_table_length > 0) { duke@435: LocalVariableTableElement* table = _method()->localvariable_table_start(); duke@435: for (int i = 0; i < localvariable_table_length; i++) { duke@435: u2 start_bci = table[i].start_bci; duke@435: u2 length = table[i].length; duke@435: duke@435: if (start_bci >= code_length || code_data[start_bci] == 0) { duke@435: class_format_error( duke@435: "Illegal local variable table start_pc %d", start_bci); duke@435: return; duke@435: } duke@435: u4 end_bci = (u4)(start_bci + length); duke@435: if (end_bci != code_length) { duke@435: if (end_bci >= code_length || code_data[end_bci] == 0) { duke@435: class_format_error( "Illegal local variable table length %d", length); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci, duke@435: StackMapFrame* current_frame, duke@435: StackMapTable* stackmap_table, duke@435: bool no_control_flow, TRAPS) { duke@435: if (stackmap_index < stackmap_table->get_frame_count()) { duke@435: u2 this_offset = stackmap_table->get_offset(stackmap_index); duke@435: if (no_control_flow && this_offset > bci) { duke@435: verify_error(bci, "Expecting a stack map frame"); duke@435: return 0; duke@435: } duke@435: if (this_offset == bci) { duke@435: // See if current stack map can be assigned to the frame in table. duke@435: // current_frame is the stackmap frame got from the last instruction. duke@435: // If matched, current_frame will be updated by this method. duke@435: bool match = stackmap_table->match_stackmap( duke@435: current_frame, this_offset, stackmap_index, duke@435: !no_control_flow, true, CHECK_VERIFY_(this, 0)); duke@435: if (!match) { duke@435: // report type error duke@435: verify_error(bci, "Instruction type does not match stack map"); duke@435: return 0; duke@435: } duke@435: stackmap_index++; duke@435: } else if (this_offset < bci) { duke@435: // current_offset should have met this_offset. duke@435: class_format_error("Bad stack map offset %d", this_offset); duke@435: return 0; duke@435: } duke@435: } else if (no_control_flow) { duke@435: verify_error(bci, "Expecting a stack map frame"); duke@435: return 0; duke@435: } duke@435: return stackmap_index; duke@435: } duke@435: duke@435: void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame, duke@435: StackMapTable* stackmap_table, TRAPS) { duke@435: constantPoolHandle cp (THREAD, _method->constants()); duke@435: typeArrayHandle exhandlers (THREAD, _method->exception_table()); duke@435: if (exhandlers() != NULL) { duke@435: for(int i = 0; i < exhandlers->length();) { duke@435: u2 start_pc = exhandlers->int_at(i++); duke@435: u2 end_pc = exhandlers->int_at(i++); duke@435: u2 handler_pc = exhandlers->int_at(i++); duke@435: int catch_type_index = exhandlers->int_at(i++); duke@435: if(bci >= start_pc && bci < end_pc) { duke@435: u1 flags = current_frame->flags(); duke@435: if (this_uninit) { flags |= FLAG_THIS_UNINIT; } duke@435: StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags); duke@435: if (catch_type_index != 0) { duke@435: // We know that this index refers to a subclass of Throwable duke@435: VerificationType catch_type = cp_index_to_type( duke@435: catch_type_index, cp, CHECK_VERIFY(this)); duke@435: new_frame->push_stack(catch_type, CHECK_VERIFY(this)); duke@435: } else { duke@435: VerificationType throwable = duke@435: VerificationType::reference_type(vmSymbols::java_lang_Throwable()); duke@435: new_frame->push_stack(throwable, CHECK_VERIFY(this)); duke@435: } duke@435: bool match = stackmap_table->match_stackmap( duke@435: new_frame, handler_pc, true, false, CHECK_VERIFY(this)); duke@435: if (!match) { duke@435: verify_error(bci, duke@435: "Stack map does not match the one at exception handler %d", duke@435: handler_pc); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_cp_index(constantPoolHandle cp, int index, TRAPS) { duke@435: int nconstants = cp->length(); duke@435: if ((index <= 0) || (index >= nconstants)) { duke@435: verify_error("Illegal constant pool index %d in class %s", duke@435: index, instanceKlass::cast(cp->pool_holder())->external_name()); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_cp_type( duke@435: int index, constantPoolHandle cp, unsigned int types, TRAPS) { duke@435: duke@435: // In some situations, bytecode rewriting may occur while we're verifying. duke@435: // In this case, a constant pool cache exists and some indices refer to that jrose@1925: // instead. Be sure we don't pick up such indices by accident. jrose@1925: // We must check was_recursively_verified() before we get here. jrose@1925: guarantee(cp->cache() == NULL, "not rewritten yet"); duke@435: duke@435: verify_cp_index(cp, index, CHECK_VERIFY(this)); duke@435: unsigned int tag = cp->tag_at(index).value(); duke@435: if ((types & (1 << tag)) == 0) { duke@435: verify_error( duke@435: "Illegal type at constant pool entry %d in class %s", duke@435: index, instanceKlass::cast(cp->pool_holder())->external_name()); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_cp_class_type( duke@435: int index, constantPoolHandle cp, TRAPS) { duke@435: verify_cp_index(cp, index, CHECK_VERIFY(this)); duke@435: constantTag tag = cp->tag_at(index); duke@435: if (!tag.is_klass() && !tag.is_unresolved_klass()) { duke@435: verify_error("Illegal type at constant pool entry %d in class %s", duke@435: index, instanceKlass::cast(cp->pool_holder())->external_name()); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::format_error_message( duke@435: const char* fmt, int offset, va_list va) { duke@435: ResourceMark rm(_thread); duke@435: stringStream message(_message, _message_buffer_len); duke@435: message.vprint(fmt, va); duke@435: if (!_method.is_null()) { duke@435: message.print(" in method %s", _method->name_and_sig_as_C_string()); duke@435: } duke@435: if (offset != -1) { duke@435: message.print(" at offset %d", offset); duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_error(u2 offset, const char* fmt, ...) { duke@435: _exception_type = vmSymbols::java_lang_VerifyError(); duke@435: va_list va; duke@435: va_start(va, fmt); duke@435: format_error_message(fmt, offset, va); duke@435: va_end(va); duke@435: } duke@435: duke@435: void ClassVerifier::verify_error(const char* fmt, ...) { duke@435: _exception_type = vmSymbols::java_lang_VerifyError(); duke@435: va_list va; duke@435: va_start(va, fmt); duke@435: format_error_message(fmt, -1, va); duke@435: va_end(va); duke@435: } duke@435: duke@435: void ClassVerifier::class_format_error(const char* msg, ...) { duke@435: _exception_type = vmSymbols::java_lang_ClassFormatError(); duke@435: va_list va; duke@435: va_start(va, msg); duke@435: format_error_message(msg, -1, va); duke@435: va_end(va); duke@435: } duke@435: coleenp@2497: klassOop ClassVerifier::load_class(Symbol* name, TRAPS) { duke@435: // Get current loader and protection domain first. duke@435: oop loader = current_class()->class_loader(); duke@435: oop protection_domain = current_class()->protection_domain(); duke@435: duke@435: return SystemDictionary::resolve_or_fail( duke@435: name, Handle(THREAD, loader), Handle(THREAD, protection_domain), duke@435: true, CHECK_NULL); duke@435: } duke@435: duke@435: bool ClassVerifier::is_protected_access(instanceKlassHandle this_class, duke@435: klassOop target_class, coleenp@2497: Symbol* field_name, coleenp@2497: Symbol* field_sig, duke@435: bool is_method) { duke@435: No_Safepoint_Verifier nosafepoint; duke@435: duke@435: // If target class isn't a super class of this class, we don't worry about this case duke@435: if (!this_class->is_subclass_of(target_class)) { duke@435: return false; duke@435: } duke@435: // Check if the specified method or field is protected duke@435: instanceKlass* target_instance = instanceKlass::cast(target_class); duke@435: fieldDescriptor fd; duke@435: if (is_method) { duke@435: methodOop m = target_instance->uncached_lookup_method(field_name, field_sig); duke@435: if (m != NULL && m->is_protected()) { duke@435: if (!this_class->is_same_class_package(m->method_holder())) { duke@435: return true; duke@435: } duke@435: } duke@435: } else { duke@435: klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd); duke@435: if(member_klass != NULL && fd.is_protected()) { duke@435: if (!this_class->is_same_class_package(member_klass)) { duke@435: return true; duke@435: } duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void ClassVerifier::verify_ldc( duke@435: int opcode, u2 index, StackMapFrame *current_frame, duke@435: constantPoolHandle cp, u2 bci, TRAPS) { duke@435: verify_cp_index(cp, index, CHECK_VERIFY(this)); duke@435: constantTag tag = cp->tag_at(index); duke@435: unsigned int types; duke@435: if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { duke@435: if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) { duke@435: types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) jrose@1957: | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) jrose@1957: | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType); jrose@1957: // Note: The class file parser already verified the legality of jrose@1957: // MethodHandle and MethodType constants. duke@435: verify_cp_type(index, cp, types, CHECK_VERIFY(this)); duke@435: } duke@435: } else { duke@435: assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); duke@435: types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); duke@435: verify_cp_type(index, cp, types, CHECK_VERIFY(this)); duke@435: } jrose@866: if (tag.is_string() && cp->is_pseudo_string_at(index)) { kamg@2297: current_frame->push_stack(object_type(), CHECK_VERIFY(this)); jrose@866: } else if (tag.is_string() || tag.is_unresolved_string()) { duke@435: current_frame->push_stack( duke@435: VerificationType::reference_type( duke@435: vmSymbols::java_lang_String()), CHECK_VERIFY(this)); duke@435: } else if (tag.is_klass() || tag.is_unresolved_klass()) { duke@435: current_frame->push_stack( duke@435: VerificationType::reference_type( duke@435: vmSymbols::java_lang_Class()), CHECK_VERIFY(this)); duke@435: } else if (tag.is_int()) { duke@435: current_frame->push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: } else if (tag.is_float()) { duke@435: current_frame->push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: } else if (tag.is_double()) { duke@435: current_frame->push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: } else if (tag.is_long()) { duke@435: current_frame->push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); jrose@1957: } else if (tag.is_method_handle()) { jrose@1957: current_frame->push_stack( jrose@1957: VerificationType::reference_type( jrose@2742: vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this)); jrose@1957: } else if (tag.is_method_type()) { jrose@1957: current_frame->push_stack( jrose@1957: VerificationType::reference_type( jrose@2742: vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); duke@435: } else { duke@435: verify_error(bci, "Invalid index in ldc"); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_switch( duke@435: RawBytecodeStream* bcs, u4 code_length, char* code_data, duke@435: StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) { duke@435: int bci = bcs->bci(); duke@435: address bcp = bcs->bcp(); duke@435: address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize); duke@435: duke@435: // 4639449 & 4647081: padding bytes must be 0 duke@435: u2 padding_offset = 1; duke@435: while ((bcp + padding_offset) < aligned_bcp) { duke@435: if(*(bcp + padding_offset) != 0) { duke@435: verify_error(bci, "Nonzero padding byte in lookswitch or tableswitch"); duke@435: return; duke@435: } duke@435: padding_offset++; duke@435: } duke@435: int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); duke@435: int keys, delta; duke@435: current_frame->pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); jrose@1920: if (bcs->raw_code() == Bytecodes::_tableswitch) { duke@435: jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); duke@435: jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); duke@435: if (low > high) { duke@435: verify_error(bci, duke@435: "low must be less than or equal to high in tableswitch"); duke@435: return; duke@435: } duke@435: keys = high - low + 1; duke@435: if (keys < 0) { duke@435: verify_error(bci, "too many keys in tableswitch"); duke@435: return; duke@435: } duke@435: delta = 1; duke@435: } else { duke@435: keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); duke@435: if (keys < 0) { duke@435: verify_error(bci, "number of keys in lookupswitch less than 0"); duke@435: return; duke@435: } duke@435: delta = 2; duke@435: // Make sure that the lookupswitch items are sorted duke@435: for (int i = 0; i < (keys - 1); i++) { duke@435: jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); duke@435: jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); duke@435: if (this_key >= next_key) { duke@435: verify_error(bci, "Bad lookupswitch instruction"); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: int target = bci + default_offset; duke@435: stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this)); duke@435: for (int i = 0; i < keys; i++) { kamg@3821: // Because check_jump_target() may safepoint, the bytecode could have kamg@3821: // moved, which means 'aligned_bcp' is no good and needs to be recalculated. kamg@3821: aligned_bcp = (address)round_to((intptr_t)(bcs->bcp() + 1), jintSize); duke@435: target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); duke@435: stackmap_table->check_jump_target( duke@435: current_frame, target, CHECK_VERIFY(this)); duke@435: } kamg@3821: NOT_PRODUCT(aligned_bcp = NULL); // no longer valid at this point duke@435: } duke@435: duke@435: bool ClassVerifier::name_in_supers( coleenp@2497: Symbol* ref_name, instanceKlassHandle current) { duke@435: klassOop super = current->super(); duke@435: while (super != NULL) { duke@435: if (super->klass_part()->name() == ref_name) { duke@435: return true; duke@435: } duke@435: super = super->klass_part()->super(); duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, duke@435: StackMapFrame* current_frame, duke@435: constantPoolHandle cp, duke@435: TRAPS) { jrose@1920: u2 index = bcs->get_index_u2(); duke@435: verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); duke@435: duke@435: // Get field name and signature coleenp@2497: Symbol* field_name = cp->name_ref_at(index); coleenp@2497: Symbol* field_sig = cp->signature_ref_at(index); duke@435: duke@435: if (!SignatureVerifier::is_valid_type_signature(field_sig)) { duke@435: class_format_error( duke@435: "Invalid signature for field in class %s referenced " duke@435: "from constant pool index %d", _klass->external_name(), index); duke@435: return; duke@435: } duke@435: duke@435: // Get referenced class type duke@435: VerificationType ref_class_type = cp_ref_index_to_type( duke@435: index, cp, CHECK_VERIFY(this)); duke@435: if (!ref_class_type.is_object()) { duke@435: verify_error( duke@435: "Expecting reference to class in class %s at constant pool index %d", duke@435: _klass->external_name(), index); duke@435: return; duke@435: } duke@435: VerificationType target_class_type = ref_class_type; duke@435: duke@435: assert(sizeof(VerificationType) == sizeof(uintptr_t), duke@435: "buffer type must match VerificationType size"); duke@435: uintptr_t field_type_buffer[2]; duke@435: VerificationType* field_type = (VerificationType*)field_type_buffer; duke@435: // If we make a VerificationType[2] array directly, the compiler calls duke@435: // to the c-runtime library to do the allocation instead of just duke@435: // stack allocating it. Plus it would run constructors. This shows up duke@435: // in performance profiles. duke@435: duke@435: SignatureStream sig_stream(field_sig, false); duke@435: VerificationType stack_object_type; duke@435: int n = change_sig_to_verificationType( duke@435: &sig_stream, field_type, CHECK_VERIFY(this)); duke@435: u2 bci = bcs->bci(); duke@435: bool is_assignable; jrose@1920: switch (bcs->raw_code()) { duke@435: case Bytecodes::_getstatic: { duke@435: for (int i = 0; i < n; i++) { duke@435: current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); duke@435: } duke@435: break; duke@435: } duke@435: case Bytecodes::_putstatic: { duke@435: for (int i = n - 1; i >= 0; i--) { duke@435: current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); duke@435: } duke@435: break; duke@435: } duke@435: case Bytecodes::_getfield: { duke@435: stack_object_type = current_frame->pop_stack( duke@435: target_class_type, CHECK_VERIFY(this)); duke@435: for (int i = 0; i < n; i++) { duke@435: current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); duke@435: } duke@435: goto check_protected; duke@435: } duke@435: case Bytecodes::_putfield: { duke@435: for (int i = n - 1; i >= 0; i--) { duke@435: current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); duke@435: } duke@435: stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); duke@435: duke@435: // The JVMS 2nd edition allows field initialization before the superclass duke@435: // initializer, if the field is defined within the current class. duke@435: fieldDescriptor fd; duke@435: if (stack_object_type == VerificationType::uninitialized_this_type() && duke@435: target_class_type.equals(current_type()) && coleenp@2497: _klass->find_local_field(field_name, field_sig, &fd)) { duke@435: stack_object_type = current_type(); duke@435: } duke@435: is_assignable = target_class_type.is_assignable_from( coleenp@2497: stack_object_type, this, CHECK_VERIFY(this)); duke@435: if (!is_assignable) { duke@435: verify_error(bci, "Bad type on operand stack in putfield"); duke@435: return; duke@435: } duke@435: } duke@435: check_protected: { duke@435: if (_this_type == stack_object_type) duke@435: break; // stack_object_type must be assignable to _current_class_type coleenp@2497: Symbol* ref_class_name = coleenp@2497: cp->klass_name_at(cp->klass_ref_index_at(index)); coleenp@2497: if (!name_in_supers(ref_class_name, current_class())) duke@435: // stack_object_type must be assignable to _current_class_type since: duke@435: // 1. stack_object_type must be assignable to ref_class. duke@435: // 2. ref_class must be _current_class or a subclass of it. It can't duke@435: // be a superclass of it. See revised JVMS 5.4.4. duke@435: break; duke@435: duke@435: klassOop ref_class_oop = load_class(ref_class_name, CHECK); coleenp@2497: if (is_protected_access(current_class(), ref_class_oop, field_name, coleenp@2497: field_sig, false)) { duke@435: // It's protected access, check if stack object is assignable to duke@435: // current class. duke@435: is_assignable = current_type().is_assignable_from( coleenp@2497: stack_object_type, this, CHECK_VERIFY(this)); duke@435: if (!is_assignable) { duke@435: verify_error(bci, "Bad access to protected data in getfield"); duke@435: return; duke@435: } duke@435: } duke@435: break; duke@435: } duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_invoke_init( duke@435: RawBytecodeStream* bcs, VerificationType ref_class_type, duke@435: StackMapFrame* current_frame, u4 code_length, bool *this_uninit, duke@435: constantPoolHandle cp, TRAPS) { duke@435: u2 bci = bcs->bci(); duke@435: VerificationType type = current_frame->pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: if (type == VerificationType::uninitialized_this_type()) { kamg@3858: // The method must be an method of this class or its superclass kamg@3858: klassOop superk = current_class()->super(); apangin@2032: if (ref_class_type.name() != current_class()->name() && kamg@3858: ref_class_type.name() != superk->klass_part()->name()) { duke@435: verify_error(bci, "Bad method call"); duke@435: return; duke@435: } duke@435: current_frame->initialize_object(type, current_type()); duke@435: *this_uninit = true; duke@435: } else if (type.is_uninitialized()) { duke@435: u2 new_offset = type.bci(); duke@435: address new_bcp = bcs->bcp() - bci + new_offset; duke@435: if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { duke@435: verify_error(new_offset, "Expecting new instruction"); duke@435: return; duke@435: } duke@435: u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); duke@435: verify_cp_class_type(new_class_index, cp, CHECK_VERIFY(this)); duke@435: duke@435: // The method must be an method of the indicated class duke@435: VerificationType new_class_type = cp_index_to_type( duke@435: new_class_index, cp, CHECK_VERIFY(this)); duke@435: if (!new_class_type.equals(ref_class_type)) { duke@435: verify_error(bci, "Call to wrong method"); duke@435: return; duke@435: } duke@435: // According to the VM spec, if the referent class is a superclass of the duke@435: // current class, and is in a different runtime package, and the method is duke@435: // protected, then the objectref must be the current class or a subclass duke@435: // of the current class. duke@435: VerificationType objectref_type = new_class_type; duke@435: if (name_in_supers(ref_class_type.name(), current_class())) { duke@435: klassOop ref_klass = load_class( duke@435: ref_class_type.name(), CHECK_VERIFY(this)); duke@435: methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( duke@435: vmSymbols::object_initializer_name(), jrose@1920: cp->signature_ref_at(bcs->get_index_u2())); duke@435: instanceKlassHandle mh(THREAD, m->method_holder()); duke@435: if (m->is_protected() && !mh->is_same_class_package(_klass())) { duke@435: bool assignable = current_type().is_assignable_from( coleenp@2497: objectref_type, this, CHECK_VERIFY(this)); duke@435: if (!assignable) { duke@435: verify_error(bci, "Bad access to protected method"); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: current_frame->initialize_object(type, new_class_type); duke@435: } else { duke@435: verify_error(bci, "Bad operand type when invoking "); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: void ClassVerifier::verify_invoke_instructions( duke@435: RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, duke@435: bool *this_uninit, VerificationType return_type, duke@435: constantPoolHandle cp, TRAPS) { duke@435: // Make sure the constant pool item is the right type jrose@1920: u2 index = bcs->get_index_u2(); jrose@1920: Bytecodes::Code opcode = bcs->raw_code(); duke@435: unsigned int types = (opcode == Bytecodes::_invokeinterface duke@435: ? 1 << JVM_CONSTANT_InterfaceMethodref jrose@1161: : opcode == Bytecodes::_invokedynamic jrose@2742: ? 1 << JVM_CONSTANT_InvokeDynamic duke@435: : 1 << JVM_CONSTANT_Methodref); duke@435: verify_cp_type(index, cp, types, CHECK_VERIFY(this)); duke@435: duke@435: // Get method name and signature coleenp@2497: Symbol* method_name = cp->name_ref_at(index); coleenp@2497: Symbol* method_sig = cp->signature_ref_at(index); duke@435: duke@435: if (!SignatureVerifier::is_valid_method_signature(method_sig)) { duke@435: class_format_error( duke@435: "Invalid method signature in class %s referenced " duke@435: "from constant pool index %d", _klass->external_name(), index); duke@435: return; duke@435: } duke@435: duke@435: // Get referenced class type jrose@1161: VerificationType ref_class_type; jrose@1161: if (opcode == Bytecodes::_invokedynamic) { jrose@1957: if (!EnableInvokeDynamic || jrose@1957: _klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { jrose@1161: class_format_error( jrose@1957: (!EnableInvokeDynamic ? jrose@1957: "invokedynamic instructions not enabled in this JVM" : jrose@1957: "invokedynamic instructions not supported by this class file version"), jrose@1161: _klass->external_name()); jrose@1161: return; jrose@1161: } jrose@1161: } else { jrose@1161: ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); jrose@1161: } duke@435: duke@435: // For a small signature length, we just allocate 128 bytes instead duke@435: // of parsing the signature once to find its size. duke@435: // -3 is for '(', ')' and return descriptor; multiply by 2 is for duke@435: // longs/doubles to be consertive. duke@435: assert(sizeof(VerificationType) == sizeof(uintptr_t), duke@435: "buffer type must match VerificationType size"); duke@435: uintptr_t on_stack_sig_types_buffer[128]; duke@435: // If we make a VerificationType[128] array directly, the compiler calls duke@435: // to the c-runtime library to do the allocation instead of just duke@435: // stack allocating it. Plus it would run constructors. This shows up duke@435: // in performance profiles. duke@435: duke@435: VerificationType* sig_types; duke@435: int size = (method_sig->utf8_length() - 3) * 2; duke@435: if (size > 128) { duke@435: // Long and double occupies two slots here. duke@435: ArgumentSizeComputer size_it(method_sig); duke@435: size = size_it.size(); duke@435: sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size); duke@435: } else{ duke@435: sig_types = (VerificationType*)on_stack_sig_types_buffer; duke@435: } duke@435: SignatureStream sig_stream(method_sig); duke@435: int sig_i = 0; duke@435: while (!sig_stream.at_return_type()) { duke@435: sig_i += change_sig_to_verificationType( duke@435: &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this)); duke@435: sig_stream.next(); duke@435: } duke@435: int nargs = sig_i; duke@435: duke@435: #ifdef ASSERT duke@435: { duke@435: ArgumentSizeComputer size_it(method_sig); duke@435: assert(nargs == size_it.size(), "Argument sizes do not match"); duke@435: assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough"); duke@435: } duke@435: #endif duke@435: duke@435: // Check instruction operands duke@435: u2 bci = bcs->bci(); duke@435: if (opcode == Bytecodes::_invokeinterface) { duke@435: address bcp = bcs->bcp(); duke@435: // 4905268: count operand in invokeinterface should be nargs+1, not nargs. duke@435: // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is duke@435: // the difference between the size of the operand stack before and after the instruction duke@435: // executes. duke@435: if (*(bcp+3) != (nargs+1)) { duke@435: verify_error(bci, "Inconsistent args count operand in invokeinterface"); duke@435: return; duke@435: } duke@435: if (*(bcp+4) != 0) { duke@435: verify_error(bci, "Fourth operand byte of invokeinterface must be zero"); duke@435: return; duke@435: } duke@435: } duke@435: jrose@1161: if (opcode == Bytecodes::_invokedynamic) { jrose@1161: address bcp = bcs->bcp(); jrose@1161: if (*(bcp+3) != 0 || *(bcp+4) != 0) { jrose@1161: verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero"); jrose@1161: return; jrose@1161: } jrose@1161: } jrose@1161: duke@435: if (method_name->byte_at(0) == '<') { duke@435: // Make sure can only be invoked by invokespecial duke@435: if (opcode != Bytecodes::_invokespecial || coleenp@2497: method_name != vmSymbols::object_initializer_name()) { duke@435: verify_error(bci, "Illegal call to internal method"); duke@435: return; duke@435: } duke@435: } else if (opcode == Bytecodes::_invokespecial duke@435: && !ref_class_type.equals(current_type()) duke@435: && !ref_class_type.equals(VerificationType::reference_type( duke@435: current_class()->super()->klass_part()->name()))) { duke@435: bool subtype = ref_class_type.is_assignable_from( coleenp@2497: current_type(), this, CHECK_VERIFY(this)); duke@435: if (!subtype) { duke@435: verify_error(bci, "Bad invokespecial instruction: " duke@435: "current class isn't assignable to reference class."); duke@435: return; duke@435: } duke@435: } duke@435: // Match method descriptor with operand stack duke@435: for (int i = nargs - 1; i >= 0; i--) { // Run backwards duke@435: current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); duke@435: } duke@435: // Check objectref on operand stack jrose@1161: if (opcode != Bytecodes::_invokestatic && jrose@1161: opcode != Bytecodes::_invokedynamic) { coleenp@2497: if (method_name == vmSymbols::object_initializer_name()) { // method duke@435: verify_invoke_init(bcs, ref_class_type, current_frame, duke@435: code_length, this_uninit, cp, CHECK_VERIFY(this)); duke@435: } else { // other methods duke@435: // Ensures that target class is assignable to method class. duke@435: if (opcode == Bytecodes::_invokespecial) { duke@435: current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); duke@435: } else if (opcode == Bytecodes::_invokevirtual) { duke@435: VerificationType stack_object_type = duke@435: current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); duke@435: if (current_type() != stack_object_type) { duke@435: assert(cp->cache() == NULL, "not rewritten yet"); coleenp@2497: Symbol* ref_class_name = coleenp@2497: cp->klass_name_at(cp->klass_ref_index_at(index)); duke@435: // See the comments in verify_field_instructions() for duke@435: // the rationale behind this. coleenp@2497: if (name_in_supers(ref_class_name, current_class())) { duke@435: klassOop ref_class = load_class(ref_class_name, CHECK); duke@435: if (is_protected_access( coleenp@2497: _klass, ref_class, method_name, method_sig, true)) { duke@435: // It's protected access, check if stack object is duke@435: // assignable to current class. duke@435: bool is_assignable = current_type().is_assignable_from( coleenp@2497: stack_object_type, this, CHECK_VERIFY(this)); duke@435: if (!is_assignable) { duke@435: if (ref_class_type.name() == vmSymbols::java_lang_Object() duke@435: && stack_object_type.is_array() coleenp@2497: && method_name == vmSymbols::clone_name()) { duke@435: // Special case: arrays pretend to implement public Object duke@435: // clone(). duke@435: } else { duke@435: verify_error(bci, duke@435: "Bad access to protected data in invokevirtual"); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } else { duke@435: assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered"); duke@435: current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); duke@435: } duke@435: } duke@435: } duke@435: // Push the result type. duke@435: if (sig_stream.type() != T_VOID) { coleenp@2497: if (method_name == vmSymbols::object_initializer_name()) { duke@435: // method must have a void return type duke@435: verify_error(bci, "Return type must be void in method"); duke@435: return; duke@435: } duke@435: VerificationType return_type[2]; duke@435: int n = change_sig_to_verificationType( duke@435: &sig_stream, return_type, CHECK_VERIFY(this)); duke@435: for (int i = 0; i < n; i++) { duke@435: current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards duke@435: } duke@435: } duke@435: } duke@435: duke@435: VerificationType ClassVerifier::get_newarray_type( duke@435: u2 index, u2 bci, TRAPS) { duke@435: const char* from_bt[] = { duke@435: NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", duke@435: }; duke@435: if (index < T_BOOLEAN || index > T_LONG) { duke@435: verify_error(bci, "Illegal newarray instruction"); duke@435: return VerificationType::bogus_type(); duke@435: } duke@435: duke@435: // from_bt[index] contains the array signature which has a length of 2 coleenp@2497: Symbol* sig = create_temporary_symbol( duke@435: from_bt[index], 2, CHECK_(VerificationType::bogus_type())); duke@435: return VerificationType::reference_type(sig); duke@435: } duke@435: duke@435: void ClassVerifier::verify_anewarray( duke@435: u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS) { duke@435: verify_cp_class_type(index, cp, CHECK_VERIFY(this)); duke@435: current_frame->pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: duke@435: VerificationType component_type = duke@435: cp_index_to_type(index, cp, CHECK_VERIFY(this)); duke@435: int length; duke@435: char* arr_sig_str; duke@435: if (component_type.is_array()) { // it's an array duke@435: const char* component_name = component_type.name()->as_utf8(); duke@435: // add one dimension to component duke@435: length = (int)strlen(component_name) + 1; duke@435: arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); duke@435: arr_sig_str[0] = '['; duke@435: strncpy(&arr_sig_str[1], component_name, length - 1); duke@435: } else { // it's an object or interface duke@435: const char* component_name = component_type.name()->as_utf8(); duke@435: // add one dimension to component with 'L' prepended and ';' postpended. duke@435: length = (int)strlen(component_name) + 3; duke@435: arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); duke@435: arr_sig_str[0] = '['; duke@435: arr_sig_str[1] = 'L'; duke@435: strncpy(&arr_sig_str[2], component_name, length - 2); duke@435: arr_sig_str[length - 1] = ';'; duke@435: } coleenp@2497: Symbol* arr_sig = create_temporary_symbol( duke@435: arr_sig_str, length, CHECK_VERIFY(this)); duke@435: VerificationType new_array_type = VerificationType::reference_type(arr_sig); duke@435: current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->get_local( duke@435: index, VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame->push_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->get_local_2( duke@435: index, VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: current_frame->push_stack_2( duke@435: VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->get_local( duke@435: index, VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame->push_stack( duke@435: VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->get_local_2( duke@435: index, VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: current_frame->push_stack_2( duke@435: VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: VerificationType type = current_frame->get_local( duke@435: index, VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: current_frame->push_stack(type, CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->pop_stack( duke@435: VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame->set_local( duke@435: index, VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->pop_stack_2( duke@435: VerificationType::long2_type(), duke@435: VerificationType::long_type(), CHECK_VERIFY(this)); duke@435: current_frame->set_local_2( duke@435: index, VerificationType::long_type(), duke@435: VerificationType::long2_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: current_frame->set_local( duke@435: index, VerificationType::float_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: current_frame->pop_stack_2( duke@435: VerificationType::double2_type(), duke@435: VerificationType::double_type(), CHECK_VERIFY(this)); duke@435: current_frame->set_local_2( duke@435: index, VerificationType::double_type(), duke@435: VerificationType::double2_type(), CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: VerificationType type = current_frame->pop_stack( duke@435: VerificationType::reference_check(), CHECK_VERIFY(this)); duke@435: current_frame->set_local(index, type, CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) { duke@435: VerificationType type = current_frame->get_local( duke@435: index, VerificationType::integer_type(), CHECK_VERIFY(this)); duke@435: current_frame->set_local(index, type, CHECK_VERIFY(this)); duke@435: } duke@435: duke@435: void ClassVerifier::verify_return_value( duke@435: VerificationType return_type, VerificationType type, u2 bci, TRAPS) { duke@435: if (return_type == VerificationType::bogus_type()) { duke@435: verify_error(bci, "Method expects a return value"); duke@435: return; duke@435: } coleenp@2497: bool match = return_type.is_assignable_from(type, this, CHECK_VERIFY(this)); duke@435: if (!match) { duke@435: verify_error(bci, "Bad return type"); duke@435: return; duke@435: } duke@435: } coleenp@2497: coleenp@2497: // The verifier creates symbols which are substrings of Symbols. coleenp@2497: // These are stored in the verifier until the end of verification so that coleenp@2497: // they can be reference counted. coleenp@2497: Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin, coleenp@2497: int end, TRAPS) { coleenp@2497: Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL); coleenp@2497: _symbols->push(sym); coleenp@2497: return sym; coleenp@2497: } coleenp@2497: coleenp@2497: Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) { coleenp@2497: Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL); coleenp@2497: _symbols->push(sym); coleenp@2497: return sym; coleenp@2497: }