src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8014013 Cdiff src/share/vm/interpreter/linkResolver.cpp

src/share/vm/interpreter/linkResolver.cpp

Print this page

        

*** 44,93 **** #include "runtime/reflection.hpp" #include "runtime/signature.hpp" #include "runtime/thread.inline.hpp" #include "runtime/vmThread.hpp" - //------------------------------------------------------------------------------------------------------------------------ - // Implementation of FieldAccessInfo - - void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset, - BasicType field_type, AccessFlags access_flags) { - _klass = klass; - _name = name; - _field_index = field_index; - _field_offset = field_offset; - _field_type = field_type; - _access_flags = access_flags; - } - //------------------------------------------------------------------------------------------------------------------------ // Implementation of CallInfo void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { int vtable_index = Method::nonvirtual_vtable_index; ! set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); } ! void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { // This is only called for interface methods. If the resolved_method // comes from java/lang/Object, it can be the subject of a virtual call, so // we should pick the vtable index from the resolved method. ! // Other than that case, there is no valid vtable index to specify. ! int vtable_index = Method::invalid_vtable_index; ! if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { ! assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); ! vtable_index = resolved_method->vtable_index(); ! } ! set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); } void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); ! set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); } void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) { if (resolved_method.is_null()) { --- 44,79 ---- #include "runtime/reflection.hpp" #include "runtime/signature.hpp" #include "runtime/thread.inline.hpp" #include "runtime/vmThread.hpp" //------------------------------------------------------------------------------------------------------------------------ // Implementation of CallInfo void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { int vtable_index = Method::nonvirtual_vtable_index; ! set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); } ! void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) { // This is only called for interface methods. If the resolved_method // comes from java/lang/Object, it can be the subject of a virtual call, so // we should pick the vtable index from the resolved method. ! // In that case, the caller must call set_virtual instead of set_interface. ! assert(resolved_method->method_holder()->is_interface(), ""); ! assert(itable_index == resolved_method()->itable_index(), ""); ! set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); } void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); ! assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); ! CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); ! set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); } void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) { if (resolved_method.is_null()) {
*** 96,119 **** KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass(); assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || resolved_method->is_compiled_lambda_form(), "linkMethod must return one of these"); int vtable_index = Method::nonvirtual_vtable_index; ! assert(resolved_method->vtable_index() == vtable_index, ""); ! set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); _resolved_appendix = resolved_appendix; _resolved_method_type = resolved_method_type; } ! void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); _resolved_klass = resolved_klass; _selected_klass = selected_klass; _resolved_method = resolved_method; _selected_method = selected_method; ! _vtable_index = vtable_index; _resolved_appendix = Handle(); if (CompilationPolicy::must_be_compiled(selected_method)) { // This path is unusual, mostly used by the '-Xcomp' stress test mode. // Note: with several active threads, the must_be_compiled may be true // while can_be_compiled is false; remove assert --- 82,114 ---- KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass(); assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || resolved_method->is_compiled_lambda_form(), "linkMethod must return one of these"); int vtable_index = Method::nonvirtual_vtable_index; ! assert(!resolved_method->has_vtable_index(), ""); ! set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); _resolved_appendix = resolved_appendix; _resolved_method_type = resolved_method_type; } ! void CallInfo::set_common(KlassHandle resolved_klass, ! KlassHandle selected_klass, ! methodHandle resolved_method, ! methodHandle selected_method, ! CallKind kind, ! int index, ! TRAPS) { assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); _resolved_klass = resolved_klass; _selected_klass = selected_klass; _resolved_method = resolved_method; _selected_method = selected_method; ! _call_kind = kind; ! _call_index = index; _resolved_appendix = Handle(); + DEBUG_ONLY(verify()); // verify before making side effects + if (CompilationPolicy::must_be_compiled(selected_method)) { // This path is unusual, mostly used by the '-Xcomp' stress test mode. // Note: with several active threads, the must_be_compiled may be true // while can_be_compiled is false; remove assert
*** 136,145 **** --- 131,199 ---- CompilationPolicy::policy()->initial_compile_level(), methodHandle(), 0, "must_be_compiled", CHECK); } } + // utility query for unreflecting a method + CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { + Klass* resolved_method_holder = resolved_method->method_holder(); + if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st + resolved_klass = resolved_method_holder; + } + _resolved_klass = resolved_klass; + _selected_klass = resolved_klass; + _resolved_method = resolved_method; + _selected_method = resolved_method; + // classify: + CallKind kind = CallInfo::unknown_kind; + int index = resolved_method->vtable_index(); + if (resolved_method->can_be_statically_bound()) { + kind = CallInfo::direct_call; + } else if (!resolved_method_holder->is_interface()) { + // Could be an Object method inherited into an interface, but still a vtable call. + kind = CallInfo::vtable_call; + } else if (!resolved_klass->is_interface()) { + // A miranda method. Compute the vtable index. + ResourceMark rm; + klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable(); + index = vt->index_of_miranda(resolved_method->name(), + resolved_method->signature()); + kind = CallInfo::vtable_call; + } else { + // A regular interface call. + kind = CallInfo::itable_call; + index = resolved_method->itable_index(); + } + assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index)); + _call_kind = kind; + _call_index = index; + _resolved_appendix = Handle(); + DEBUG_ONLY(verify()); + } + + #ifdef ASSERT + void CallInfo::verify() { + switch (call_kind()) { // the meaning and allowed value of index depends on kind + case CallInfo::direct_call: + if (_call_index == Method::nonvirtual_vtable_index) break; + // else fall through to check vtable index: + case CallInfo::vtable_call: + assert(resolved_klass()->verify_vtable_index(_call_index), ""); + break; + case CallInfo::itable_call: + assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); + break; + case CallInfo::unknown_kind: + assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); + break; + default: + fatal(err_msg_res("Unexpected call kind %d", call_kind())); + } + } + #endif //ASSERT + + //------------------------------------------------------------------------------------------------------------------------ // Klass resolution void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
*** 161,177 **** void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { Klass* result_oop = pool->klass_ref_at(index, CHECK); result = KlassHandle(THREAD, result_oop); } - void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { - Klass* result_oop = - ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK); - result = KlassHandle(THREAD, result_oop); - } - - //------------------------------------------------------------------------------------------------------------------------ // Method resolution // // According to JVM spec. $5.4.3c & $5.4.3d --- 215,224 ----
*** 358,367 **** --- 405,418 ---- } } void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { + // This method is used only in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), + // and is only used under -Xcomp or -XX:CompileTheWorld. + // It appears to fail when applied to an invokeinterface call site. + // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. // resolve klass if (code == Bytecodes::_invokedynamic) { resolved_klass = SystemDictionary::MethodHandle_klass(); Symbol* method_name = vmSymbols::invoke_name();
*** 578,659 **** ); return; } } ! void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { ! resolve_field(result, pool, index, byte, check_only, true, CHECK); } ! void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || ! byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); - // resolve specified klass - KlassHandle resolved_klass; - if (update_pool) { - resolve_klass(resolved_klass, pool, index, CHECK); - } else { - resolve_klass_no_update(resolved_klass, pool, index, CHECK); - } - // Load these early in case the resolve of the containing klass fails - Symbol* field = pool->name_ref_at(index); - Symbol* sig = pool->signature_ref_at(index); // Check if there's a resolved klass containing the field ! if( resolved_klass.is_null() ) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } // Resolve instance field - fieldDescriptor fd; // find_field initializes fd if found KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); // check if field exists; i.e., if a klass containing the field def has been selected ! if (sel_klass.is_null()){ ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } // check access ! KlassHandle ref_klass(THREAD, pool->pool_holder()); ! check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); // check for errors if (is_static != fd.is_static()) { ResourceMark rm(THREAD); char msg[200]; jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); } // Final fields can only be accessed from its own class. ! if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { THROW(vmSymbols::java_lang_IllegalAccessError()); } // initialize resolved_klass if necessary // note 1: the klass which declared the field must be initialized (i.e, sel_klass) // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) // // note 2: we don't want to force initialization if we are just checking // if the field access is legal; e.g., during compilation ! if (is_static && !check_only) { sel_klass->initialize(CHECK); } ! { HandleMark hm(THREAD); ! Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader()); Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); - Symbol* signature_ref = pool->signature_ref_at(index); { ResourceMark rm(THREAD); Symbol* failed_type_symbol = ! SystemDictionary::check_signature_loaders(signature_ref, ref_loader, sel_loader, false, CHECK); if (failed_type_symbol != NULL) { const char* msg = "loader constraint violation: when resolving field" --- 629,713 ---- ); return; } } ! void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { ! // Load these early in case the resolve of the containing klass fails ! Symbol* field = pool->name_ref_at(index); ! Symbol* sig = pool->signature_ref_at(index); ! ! // resolve specified klass ! KlassHandle resolved_klass; ! resolve_klass(resolved_klass, pool, index, CHECK); ! ! KlassHandle current_klass(THREAD, pool->pool_holder()); ! resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK); } ! void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig, ! KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class, ! TRAPS) { assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || ! byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || ! (byte == Bytecodes::_nop && !check_access), "bad field access bytecode"); bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); // Check if there's a resolved klass containing the field ! if (resolved_klass.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } // Resolve instance field KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); // check if field exists; i.e., if a klass containing the field def has been selected ! if (sel_klass.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } + if (!check_access) + // Access checking may be turned off when calling from within the VM. + return; + // check access ! check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); // check for errors if (is_static != fd.is_static()) { ResourceMark rm(THREAD); char msg[200]; jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); } // Final fields can only be accessed from its own class. ! if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { THROW(vmSymbols::java_lang_IllegalAccessError()); } // initialize resolved_klass if necessary // note 1: the klass which declared the field must be initialized (i.e, sel_klass) // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) // // note 2: we don't want to force initialization if we are just checking // if the field access is legal; e.g., during compilation ! if (is_static && initialize_class) { sel_klass->initialize(CHECK); } ! if (sel_klass() != current_klass()) { HandleMark hm(THREAD); ! Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); { ResourceMark rm(THREAD); Symbol* failed_type_symbol = ! SystemDictionary::check_signature_loaders(sig, ref_loader, sel_loader, false, CHECK); if (failed_type_symbol != NULL) { const char* msg = "loader constraint violation: when resolving field"
*** 675,687 **** } } // return information. note that the klass is set to the actual klass containing the // field, otherwise access of static fields in superclasses will not work. - KlassHandle holder (THREAD, fd.field_holder()); - Symbol* name = fd.name(); - result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); } //------------------------------------------------------------------------------------------------------------------------ // Invoke resolution --- 729,738 ----
*** 905,934 **** if (check_null_and_abstract && recv.is_null()) { // check if receiver exists THROW(vmSymbols::java_lang_NullPointerException()); } // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s - // has not been rewritten, and the vtable initialized. - assert(resolved_method->method_holder()->is_linked(), "must be linked"); - - // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since // a missing receiver might result in a bogus lookup. assert(resolved_method->method_holder()->is_linked(), "must be linked"); // do lookup based on receiver klass using the vtable index if (resolved_method->method_holder()->is_interface()) { // miranda method vtable_index = vtable_index_of_miranda_method(resolved_klass, resolved_method->name(), resolved_method->signature(), CHECK); assert(vtable_index >= 0 , "we should have valid vtable index at this point"); InstanceKlass* inst = InstanceKlass::cast(recv_klass()); selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); } else { // at this point we are sure that resolved_method is virtual and not // a miranda method; therefore, it must have a valid vtable index. vtable_index = resolved_method->vtable_index(); // We could get a negative vtable_index for final methods, // because as an optimization they are they are never put in the vtable, // unless they override an existing method. // If we do get a negative, it means the resolved method is the the selected --- 956,983 ---- if (check_null_and_abstract && recv.is_null()) { // check if receiver exists THROW(vmSymbols::java_lang_NullPointerException()); } // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since // a missing receiver might result in a bogus lookup. assert(resolved_method->method_holder()->is_linked(), "must be linked"); // do lookup based on receiver klass using the vtable index if (resolved_method->method_holder()->is_interface()) { // miranda method vtable_index = vtable_index_of_miranda_method(resolved_klass, resolved_method->name(), resolved_method->signature(), CHECK); + assert(vtable_index >= 0 , "we should have valid vtable index at this point"); InstanceKlass* inst = InstanceKlass::cast(recv_klass()); selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); } else { // at this point we are sure that resolved_method is virtual and not // a miranda method; therefore, it must have a valid vtable index. + assert(!resolved_method->has_itable_index(), ""); vtable_index = resolved_method->vtable_index(); // We could get a negative vtable_index for final methods, // because as an optimization they are they are never put in the vtable, // unless they override an existing method. // If we do get a negative, it means the resolved method is the the selected
*** 941,950 **** --- 990,1002 ---- // the same place. The cast is to avoid virtual call and assertion. InstanceKlass* inst = (InstanceKlass*)recv_klass(); selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); } } + if (selected_method.is_null() && !check_null_and_abstract) { + selected_method = resolved_method; // use a non-null placeholder + } // check if method exists if (selected_method.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
*** 1004,1013 **** --- 1056,1068 ---- // do lookup based on receiver klass methodHandle sel_method; lookup_instance_method_in_klasses(sel_method, recv_klass, resolved_method->name(), resolved_method->signature(), CHECK); + if (sel_method.is_null() && !check_null_and_abstract) { + sel_method = resolved_method; // use a non-null placeholder + } // check if method exists if (sel_method.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), Method::name_and_sig_as_C_string(recv_klass(),
*** 1044,1054 **** Method::name_and_sig_as_C_string(recv_klass(), sel_method->name(), sel_method->signature())); } // setup result ! result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); } methodHandle LinkResolver::linktime_resolve_interface_method_or_null( KlassHandle resolved_klass, --- 1099,1116 ---- Method::name_and_sig_as_C_string(recv_klass(), sel_method->name(), sel_method->signature())); } // setup result ! if (!resolved_method->has_itable_index()) { ! int vtable_index = resolved_method->vtable_index(); ! assert(vtable_index == sel_method->vtable_index(), "sanity check"); ! result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); ! return; ! } ! int itable_index = resolved_method()->itable_index(); ! result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); } methodHandle LinkResolver::linktime_resolve_interface_method_or_null( KlassHandle resolved_klass,
*** 1340,1350 **** } //------------------------------------------------------------------------------------------------------------------------ #ifndef PRODUCT ! void FieldAccessInfo::print() { ResourceMark rm; ! tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); } #endif --- 1402,1419 ---- } //------------------------------------------------------------------------------------------------------------------------ #ifndef PRODUCT ! void CallInfo::print() { ResourceMark rm; ! const char* kindstr = "unknown"; ! switch (_call_kind) { ! case direct_call: kindstr = "direct"; break; ! case vtable_call: kindstr = "vtable"; break; ! case itable_call: kindstr = "itable"; break; ! } ! tty->print_cr("Call %s@%d %s", kindstr, _call_index, ! _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); } #endif
src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File