Fri, 13 Sep 2013 22:38:02 -0400
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
Summary: Enhance method resolution and resulting data structures, plus some refactoring.
Reviewed-by: twisti, acorn, jrose
1.1 --- a/src/share/vm/c1/c1_Runtime1.cpp Tue Sep 17 23:12:27 2013 +0200 1.2 +++ b/src/share/vm/c1/c1_Runtime1.cpp Fri Sep 13 22:38:02 2013 -0400 1.3 @@ -709,10 +709,10 @@ 1.4 Bytecodes::Code code = field_access.code(); 1.5 1.6 // We must load class, initialize class and resolvethe field 1.7 - FieldAccessInfo result; // initialize class if needed 1.8 + fieldDescriptor result; // initialize class if needed 1.9 constantPoolHandle constants(THREAD, caller->constants()); 1.10 - LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK_NULL); 1.11 - return result.klass()(); 1.12 + LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL); 1.13 + return result.field_holder(); 1.14 } 1.15 1.16 1.17 @@ -826,11 +826,11 @@ 1.18 if (stub_id == Runtime1::access_field_patching_id) { 1.19 1.20 Bytecode_field field_access(caller_method, bci); 1.21 - FieldAccessInfo result; // initialize class if needed 1.22 + fieldDescriptor result; // initialize class if needed 1.23 Bytecodes::Code code = field_access.code(); 1.24 constantPoolHandle constants(THREAD, caller_method->constants()); 1.25 - LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK); 1.26 - patch_field_offset = result.field_offset(); 1.27 + LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK); 1.28 + patch_field_offset = result.offset(); 1.29 1.30 // If we're patching a field which is volatile then at compile it 1.31 // must not have been know to be volatile, so the generated code
2.1 --- a/src/share/vm/ci/ciField.cpp Tue Sep 17 23:12:27 2013 +0200 2.2 +++ b/src/share/vm/ci/ciField.cpp Fri Sep 13 22:38:02 2013 -0400 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -75,7 +75,6 @@ 2.11 2.12 assert(klass->get_instanceKlass()->is_linked(), "must be linked before using its constan-pool"); 2.13 2.14 - _cp_index = index; 2.15 constantPoolHandle cpool(thread, klass->get_instanceKlass()->constants()); 2.16 2.17 // Get the field's name, signature, and type. 2.18 @@ -116,7 +115,7 @@ 2.19 // The declared holder of this field may not have been loaded. 2.20 // Bail out with partial field information. 2.21 if (!holder_is_accessible) { 2.22 - // _cp_index and _type have already been set. 2.23 + // _type has already been set. 2.24 // The default values for _flags and _constant_value will suffice. 2.25 // We need values for _holder, _offset, and _is_constant, 2.26 _holder = declared_holder; 2.27 @@ -146,8 +145,6 @@ 2.28 ciField::ciField(fieldDescriptor *fd): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { 2.29 ASSERT_IN_VM; 2.30 2.31 - _cp_index = -1; 2.32 - 2.33 // Get the field's name, signature, and type. 2.34 ciEnv* env = CURRENT_ENV; 2.35 _name = env->get_symbol(fd->name()); 2.36 @@ -351,12 +348,11 @@ 2.37 } 2.38 } 2.39 2.40 - FieldAccessInfo result; 2.41 - constantPoolHandle c_pool(THREAD, 2.42 - accessing_klass->get_instanceKlass()->constants()); 2.43 - LinkResolver::resolve_field(result, c_pool, _cp_index, 2.44 - Bytecodes::java_code(bc), 2.45 - true, false, KILL_COMPILE_ON_FATAL_(false)); 2.46 + fieldDescriptor result; 2.47 + LinkResolver::resolve_field(result, _holder->get_instanceKlass(), 2.48 + _name->get_symbol(), _signature->get_symbol(), 2.49 + accessing_klass->get_Klass(), bc, true, false, 2.50 + KILL_COMPILE_ON_FATAL_(false)); 2.51 2.52 // update the hit-cache, unless there is a problem with memory scoping: 2.53 if (accessing_klass->is_shared() || !is_shared()) {
3.1 --- a/src/share/vm/ci/ciField.hpp Tue Sep 17 23:12:27 2013 +0200 3.2 +++ b/src/share/vm/ci/ciField.hpp Fri Sep 13 22:38:02 2013 -0400 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -53,9 +53,6 @@ 3.11 ciInstanceKlass* _known_to_link_with_get; 3.12 ciConstant _constant_value; 3.13 3.14 - // Used for will_link 3.15 - int _cp_index; 3.16 - 3.17 ciType* compute_type(); 3.18 ciType* compute_type_impl(); 3.19
4.1 --- a/src/share/vm/ci/ciInstanceKlass.cpp Tue Sep 17 23:12:27 2013 +0200 4.2 +++ b/src/share/vm/ci/ciInstanceKlass.cpp Fri Sep 13 22:38:02 2013 -0400 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -522,8 +522,7 @@ 4.11 4.12 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 4.13 if (fs.access_flags().is_static()) continue; 4.14 - fieldDescriptor fd; 4.15 - fd.initialize(k, fs.index()); 4.16 + fieldDescriptor& fd = fs.field_descriptor(); 4.17 ciField* field = new (arena) ciField(&fd); 4.18 fields->append(field); 4.19 }
5.1 --- a/src/share/vm/ci/ciMethod.cpp Tue Sep 17 23:12:27 2013 +0200 5.2 +++ b/src/share/vm/ci/ciMethod.cpp Fri Sep 13 22:38:02 2013 -0400 5.3 @@ -286,7 +286,10 @@ 5.4 check_is_loaded(); 5.5 assert(holder()->is_linked(), "must be linked"); 5.6 VM_ENTRY_MARK; 5.7 - return klassItable::compute_itable_index(get_Method()); 5.8 + Method* m = get_Method(); 5.9 + if (!m->has_itable_index()) 5.10 + return Method::nonvirtual_vtable_index; 5.11 + return m->itable_index(); 5.12 } 5.13 #endif // SHARK 5.14 5.15 @@ -1137,6 +1140,10 @@ 5.16 // ------------------------------------------------------------------ 5.17 // ciMethod::check_call 5.18 bool ciMethod::check_call(int refinfo_index, bool is_static) const { 5.19 + // This method is used only in C2 from InlineTree::ok_to_inline, 5.20 + // and is only used under -Xcomp or -XX:CompileTheWorld. 5.21 + // It appears to fail when applied to an invokeinterface call site. 5.22 + // FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points. 5.23 VM_ENTRY_MARK; 5.24 { 5.25 EXCEPTION_MARK;
6.1 --- a/src/share/vm/ci/ciSymbol.hpp Tue Sep 17 23:12:27 2013 +0200 6.2 +++ b/src/share/vm/ci/ciSymbol.hpp Fri Sep 13 22:38:02 2013 -0400 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -44,6 +44,7 @@ 6.11 friend class ciInstanceKlass; 6.12 friend class ciSignature; 6.13 friend class ciMethod; 6.14 + friend class ciField; 6.15 friend class ciObjArrayKlass; 6.16 6.17 private:
7.1 --- a/src/share/vm/classfile/classFileParser.cpp Tue Sep 17 23:12:27 2013 +0200 7.2 +++ b/src/share/vm/classfile/classFileParser.cpp Fri Sep 13 22:38:02 2013 -0400 7.3 @@ -3954,9 +3954,8 @@ 7.4 this_klass->set_has_final_method(); 7.5 } 7.6 this_klass->copy_method_ordering(method_ordering, CHECK_NULL); 7.7 - // The InstanceKlass::_methods_jmethod_ids cache and the 7.8 - // InstanceKlass::_methods_cached_itable_indices cache are 7.9 - // both managed on the assumption that the initial cache 7.10 + // The InstanceKlass::_methods_jmethod_ids cache 7.11 + // is managed on the assumption that the initial cache 7.12 // size is equal to the number of methods in the class. If 7.13 // that changes, then InstanceKlass::idnum_can_increment() 7.14 // has to be changed accordingly.
8.1 --- a/src/share/vm/code/compiledIC.cpp Tue Sep 17 23:12:27 2013 +0200 8.2 +++ b/src/share/vm/code/compiledIC.cpp Fri Sep 13 22:38:02 2013 -0400 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -161,31 +161,36 @@ 8.11 8.12 8.13 void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { 8.14 - methodHandle method = call_info->selected_method(); 8.15 - bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index()); 8.16 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 8.17 assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); 8.18 assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); 8.19 8.20 address entry; 8.21 - if (is_invoke_interface) { 8.22 - int index = klassItable::compute_itable_index(call_info->resolved_method()()); 8.23 - entry = VtableStubs::create_stub(false, index, method()); 8.24 + if (call_info->call_kind() == CallInfo::itable_call) { 8.25 + assert(bytecode == Bytecodes::_invokeinterface, ""); 8.26 + int itable_index = call_info->itable_index(); 8.27 + entry = VtableStubs::find_itable_stub(itable_index); 8.28 +#ifdef ASSERT 8.29 assert(entry != NULL, "entry not computed"); 8.30 + int index = call_info->resolved_method()->itable_index(); 8.31 + assert(index == itable_index, "CallInfo pre-computes this"); 8.32 +#endif //ASSERT 8.33 InstanceKlass* k = call_info->resolved_method()->method_holder(); 8.34 - assert(k->is_interface(), "sanity check"); 8.35 + assert(k->verify_itable_index(itable_index), "sanity check"); 8.36 InlineCacheBuffer::create_transition_stub(this, k, entry); 8.37 } else { 8.38 - // Can be different than method->vtable_index(), due to package-private etc. 8.39 + assert(call_info->call_kind() == CallInfo::vtable_call, "either itable or vtable"); 8.40 + // Can be different than selected_method->vtable_index(), due to package-private etc. 8.41 int vtable_index = call_info->vtable_index(); 8.42 - entry = VtableStubs::create_stub(true, vtable_index, method()); 8.43 - InlineCacheBuffer::create_transition_stub(this, method(), entry); 8.44 + assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check"); 8.45 + entry = VtableStubs::find_vtable_stub(vtable_index); 8.46 + InlineCacheBuffer::create_transition_stub(this, NULL, entry); 8.47 } 8.48 8.49 if (TraceICs) { 8.50 ResourceMark rm; 8.51 tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT, 8.52 - instruction_address(), method->print_value_string(), entry); 8.53 + instruction_address(), call_info->selected_method()->print_value_string(), entry); 8.54 } 8.55 8.56 // We can't check this anymore. With lazy deopt we could have already
9.1 --- a/src/share/vm/code/vtableStubs.cpp Tue Sep 17 23:12:27 2013 +0200 9.2 +++ b/src/share/vm/code/vtableStubs.cpp Fri Sep 13 22:38:02 2013 -0400 9.3 @@ -111,7 +111,7 @@ 9.4 } 9.5 9.6 9.7 -address VtableStubs::create_stub(bool is_vtable_stub, int vtable_index, Method* method) { 9.8 +address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { 9.9 assert(vtable_index >= 0, "must be positive"); 9.10 9.11 VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL;
10.1 --- a/src/share/vm/code/vtableStubs.hpp Tue Sep 17 23:12:27 2013 +0200 10.2 +++ b/src/share/vm/code/vtableStubs.hpp Fri Sep 13 22:38:02 2013 -0400 10.3 @@ -121,9 +121,11 @@ 10.4 static VtableStub* lookup (bool is_vtable_stub, int vtable_index); 10.5 static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); 10.6 static inline uint hash (bool is_vtable_stub, int vtable_index); 10.7 + static address find_stub (bool is_vtable_stub, int vtable_index); 10.8 10.9 public: 10.10 - static address create_stub(bool is_vtable_stub, int vtable_index, Method* method); // return the entry point of a stub for this call 10.11 + static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } 10.12 + static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } 10.13 static bool is_entry_point(address pc); // is pc a vtable stub entry point? 10.14 static bool contains(address pc); // is pc within any stub? 10.15 static VtableStub* stub_containing(address pc); // stub containing pc or NULL
11.1 --- a/src/share/vm/interpreter/interpreterRuntime.cpp Tue Sep 17 23:12:27 2013 +0200 11.2 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Fri Sep 13 22:38:02 2013 -0400 11.3 @@ -496,15 +496,15 @@ 11.4 11.5 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) 11.6 // resolve field 11.7 - FieldAccessInfo info; 11.8 + fieldDescriptor info; 11.9 constantPoolHandle pool(thread, method(thread)->constants()); 11.10 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic); 11.11 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); 11.12 11.13 { 11.14 JvmtiHideSingleStepping jhss(thread); 11.15 - LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode), 11.16 - bytecode, false, CHECK); 11.17 + LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode), 11.18 + bytecode, CHECK); 11.19 } // end JvmtiHideSingleStepping 11.20 11.21 // check if link resolution caused cpCache to be updated 11.22 @@ -524,7 +524,7 @@ 11.23 // class is intitialized. This is required so that access to the static 11.24 // field will call the initialization function every time until the class 11.25 // is completely initialized ala. in 2.17.5 in JVM Specification. 11.26 - InstanceKlass *klass = InstanceKlass::cast(info.klass()()); 11.27 + InstanceKlass* klass = InstanceKlass::cast(info.field_holder()); 11.28 bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && 11.29 !klass->is_initialized()); 11.30 Bytecodes::Code get_code = (Bytecodes::Code)0; 11.31 @@ -539,9 +539,9 @@ 11.32 cache_entry(thread)->set_field( 11.33 get_code, 11.34 put_code, 11.35 - info.klass(), 11.36 - info.field_index(), 11.37 - info.field_offset(), 11.38 + info.field_holder(), 11.39 + info.index(), 11.40 + info.offset(), 11.41 state, 11.42 info.access_flags().is_final(), 11.43 info.access_flags().is_volatile(), 11.44 @@ -686,29 +686,55 @@ 11.45 if (already_resolved(thread)) return; 11.46 11.47 if (bytecode == Bytecodes::_invokeinterface) { 11.48 - 11.49 if (TraceItables && Verbose) { 11.50 ResourceMark rm(thread); 11.51 tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); 11.52 } 11.53 + } 11.54 +#ifdef ASSERT 11.55 + if (bytecode == Bytecodes::_invokeinterface) { 11.56 if (info.resolved_method()->method_holder() == 11.57 SystemDictionary::Object_klass()) { 11.58 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec 11.59 - // (see also cpCacheOop.cpp for details) 11.60 + // (see also CallInfo::set_interface for details) 11.61 + assert(info.call_kind() == CallInfo::vtable_call || 11.62 + info.call_kind() == CallInfo::direct_call, ""); 11.63 methodHandle rm = info.resolved_method(); 11.64 assert(rm->is_final() || info.has_vtable_index(), 11.65 "should have been set already"); 11.66 - cache_entry(thread)->set_method(bytecode, rm, info.vtable_index()); 11.67 + } else if (!info.resolved_method()->has_itable_index()) { 11.68 + // Resolved something like CharSequence.toString. Use vtable not itable. 11.69 + assert(info.call_kind() != CallInfo::itable_call, ""); 11.70 } else { 11.71 // Setup itable entry 11.72 - int index = klassItable::compute_itable_index(info.resolved_method()()); 11.73 - cache_entry(thread)->set_interface_call(info.resolved_method(), index); 11.74 + assert(info.call_kind() == CallInfo::itable_call, ""); 11.75 + int index = info.resolved_method()->itable_index(); 11.76 + assert(info.itable_index() == index, ""); 11.77 } 11.78 } else { 11.79 - cache_entry(thread)->set_method( 11.80 + assert(info.call_kind() == CallInfo::direct_call || 11.81 + info.call_kind() == CallInfo::vtable_call, ""); 11.82 + } 11.83 +#endif 11.84 + switch (info.call_kind()) { 11.85 + case CallInfo::direct_call: 11.86 + cache_entry(thread)->set_direct_call( 11.87 + bytecode, 11.88 + info.resolved_method()); 11.89 + break; 11.90 + case CallInfo::vtable_call: 11.91 + cache_entry(thread)->set_vtable_call( 11.92 bytecode, 11.93 info.resolved_method(), 11.94 info.vtable_index()); 11.95 + break; 11.96 + case CallInfo::itable_call: 11.97 + cache_entry(thread)->set_itable_call( 11.98 + bytecode, 11.99 + info.resolved_method(), 11.100 + info.itable_index()); 11.101 + break; 11.102 + default: ShouldNotReachHere(); 11.103 } 11.104 } 11.105 IRT_END
12.1 --- a/src/share/vm/interpreter/linkResolver.cpp Tue Sep 17 23:12:27 2013 +0200 12.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Fri Sep 13 22:38:02 2013 -0400 12.3 @@ -46,19 +46,6 @@ 12.4 #include "runtime/thread.inline.hpp" 12.5 #include "runtime/vmThread.hpp" 12.6 12.7 -//------------------------------------------------------------------------------------------------------------------------ 12.8 -// Implementation of FieldAccessInfo 12.9 - 12.10 -void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset, 12.11 -BasicType field_type, AccessFlags access_flags) { 12.12 - _klass = klass; 12.13 - _name = name; 12.14 - _field_index = field_index; 12.15 - _field_offset = field_offset; 12.16 - _field_type = field_type; 12.17 - _access_flags = access_flags; 12.18 -} 12.19 - 12.20 12.21 //------------------------------------------------------------------------------------------------------------------------ 12.22 // Implementation of CallInfo 12.23 @@ -66,26 +53,25 @@ 12.24 12.25 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { 12.26 int vtable_index = Method::nonvirtual_vtable_index; 12.27 - set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); 12.28 + set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); 12.29 } 12.30 12.31 12.32 -void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { 12.33 +void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) { 12.34 // This is only called for interface methods. If the resolved_method 12.35 // comes from java/lang/Object, it can be the subject of a virtual call, so 12.36 // we should pick the vtable index from the resolved method. 12.37 - // Other than that case, there is no valid vtable index to specify. 12.38 - int vtable_index = Method::invalid_vtable_index; 12.39 - if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { 12.40 - assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); 12.41 - vtable_index = resolved_method->vtable_index(); 12.42 - } 12.43 - set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); 12.44 + // In that case, the caller must call set_virtual instead of set_interface. 12.45 + assert(resolved_method->method_holder()->is_interface(), ""); 12.46 + assert(itable_index == resolved_method()->itable_index(), ""); 12.47 + set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); 12.48 } 12.49 12.50 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { 12.51 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); 12.52 - set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); 12.53 + assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); 12.54 + CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); 12.55 + set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); 12.56 assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); 12.57 } 12.58 12.59 @@ -98,20 +84,29 @@ 12.60 resolved_method->is_compiled_lambda_form(), 12.61 "linkMethod must return one of these"); 12.62 int vtable_index = Method::nonvirtual_vtable_index; 12.63 - assert(resolved_method->vtable_index() == vtable_index, ""); 12.64 - set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); 12.65 + assert(!resolved_method->has_vtable_index(), ""); 12.66 + set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); 12.67 _resolved_appendix = resolved_appendix; 12.68 _resolved_method_type = resolved_method_type; 12.69 } 12.70 12.71 -void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { 12.72 +void CallInfo::set_common(KlassHandle resolved_klass, 12.73 + KlassHandle selected_klass, 12.74 + methodHandle resolved_method, 12.75 + methodHandle selected_method, 12.76 + CallKind kind, 12.77 + int index, 12.78 + TRAPS) { 12.79 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); 12.80 _resolved_klass = resolved_klass; 12.81 _selected_klass = selected_klass; 12.82 _resolved_method = resolved_method; 12.83 _selected_method = selected_method; 12.84 - _vtable_index = vtable_index; 12.85 + _call_kind = kind; 12.86 + _call_index = index; 12.87 _resolved_appendix = Handle(); 12.88 + DEBUG_ONLY(verify()); // verify before making side effects 12.89 + 12.90 if (CompilationPolicy::must_be_compiled(selected_method)) { 12.91 // This path is unusual, mostly used by the '-Xcomp' stress test mode. 12.92 12.93 @@ -138,6 +133,65 @@ 12.94 } 12.95 } 12.96 12.97 +// utility query for unreflecting a method 12.98 +CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { 12.99 + Klass* resolved_method_holder = resolved_method->method_holder(); 12.100 + if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st 12.101 + resolved_klass = resolved_method_holder; 12.102 + } 12.103 + _resolved_klass = resolved_klass; 12.104 + _selected_klass = resolved_klass; 12.105 + _resolved_method = resolved_method; 12.106 + _selected_method = resolved_method; 12.107 + // classify: 12.108 + CallKind kind = CallInfo::unknown_kind; 12.109 + int index = resolved_method->vtable_index(); 12.110 + if (resolved_method->can_be_statically_bound()) { 12.111 + kind = CallInfo::direct_call; 12.112 + } else if (!resolved_method_holder->is_interface()) { 12.113 + // Could be an Object method inherited into an interface, but still a vtable call. 12.114 + kind = CallInfo::vtable_call; 12.115 + } else if (!resolved_klass->is_interface()) { 12.116 + // A miranda method. Compute the vtable index. 12.117 + ResourceMark rm; 12.118 + klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable(); 12.119 + index = vt->index_of_miranda(resolved_method->name(), 12.120 + resolved_method->signature()); 12.121 + kind = CallInfo::vtable_call; 12.122 + } else { 12.123 + // A regular interface call. 12.124 + kind = CallInfo::itable_call; 12.125 + index = resolved_method->itable_index(); 12.126 + } 12.127 + assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index)); 12.128 + _call_kind = kind; 12.129 + _call_index = index; 12.130 + _resolved_appendix = Handle(); 12.131 + DEBUG_ONLY(verify()); 12.132 +} 12.133 + 12.134 +#ifdef ASSERT 12.135 +void CallInfo::verify() { 12.136 + switch (call_kind()) { // the meaning and allowed value of index depends on kind 12.137 + case CallInfo::direct_call: 12.138 + if (_call_index == Method::nonvirtual_vtable_index) break; 12.139 + // else fall through to check vtable index: 12.140 + case CallInfo::vtable_call: 12.141 + assert(resolved_klass()->verify_vtable_index(_call_index), ""); 12.142 + break; 12.143 + case CallInfo::itable_call: 12.144 + assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); 12.145 + break; 12.146 + case CallInfo::unknown_kind: 12.147 + assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); 12.148 + break; 12.149 + default: 12.150 + fatal(err_msg_res("Unexpected call kind %d", call_kind())); 12.151 + } 12.152 +} 12.153 +#endif //ASSERT 12.154 + 12.155 + 12.156 12.157 //------------------------------------------------------------------------------------------------------------------------ 12.158 // Klass resolution 12.159 @@ -163,13 +217,6 @@ 12.160 result = KlassHandle(THREAD, result_oop); 12.161 } 12.162 12.163 -void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { 12.164 - Klass* result_oop = 12.165 - ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK); 12.166 - result = KlassHandle(THREAD, result_oop); 12.167 -} 12.168 - 12.169 - 12.170 //------------------------------------------------------------------------------------------------------------------------ 12.171 // Method resolution 12.172 // 12.173 @@ -360,7 +407,12 @@ 12.174 12.175 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, 12.176 Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { 12.177 - 12.178 + // This method is used only 12.179 + // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), 12.180 + // and 12.181 + // (2) in Bytecode_invoke::static_target 12.182 + // It appears to fail when applied to an invokeinterface call site. 12.183 + // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. 12.184 // resolve klass 12.185 if (code == Bytecodes::_invokedynamic) { 12.186 resolved_klass = SystemDictionary::MethodHandle_klass(); 12.187 @@ -580,45 +632,49 @@ 12.188 } 12.189 } 12.190 12.191 -void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { 12.192 - resolve_field(result, pool, index, byte, check_only, true, CHECK); 12.193 +void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { 12.194 + // Load these early in case the resolve of the containing klass fails 12.195 + Symbol* field = pool->name_ref_at(index); 12.196 + Symbol* sig = pool->signature_ref_at(index); 12.197 + 12.198 + // resolve specified klass 12.199 + KlassHandle resolved_klass; 12.200 + resolve_klass(resolved_klass, pool, index, CHECK); 12.201 + 12.202 + KlassHandle current_klass(THREAD, pool->pool_holder()); 12.203 + resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK); 12.204 } 12.205 12.206 -void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { 12.207 +void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig, 12.208 + KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class, 12.209 + TRAPS) { 12.210 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || 12.211 - byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); 12.212 + byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || 12.213 + (byte == Bytecodes::_nop && !check_access), "bad field access bytecode"); 12.214 12.215 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); 12.216 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); 12.217 12.218 - // resolve specified klass 12.219 - KlassHandle resolved_klass; 12.220 - if (update_pool) { 12.221 - resolve_klass(resolved_klass, pool, index, CHECK); 12.222 - } else { 12.223 - resolve_klass_no_update(resolved_klass, pool, index, CHECK); 12.224 - } 12.225 - // Load these early in case the resolve of the containing klass fails 12.226 - Symbol* field = pool->name_ref_at(index); 12.227 - Symbol* sig = pool->signature_ref_at(index); 12.228 // Check if there's a resolved klass containing the field 12.229 - if( resolved_klass.is_null() ) { 12.230 + if (resolved_klass.is_null()) { 12.231 ResourceMark rm(THREAD); 12.232 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 12.233 } 12.234 12.235 // Resolve instance field 12.236 - fieldDescriptor fd; // find_field initializes fd if found 12.237 KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); 12.238 // check if field exists; i.e., if a klass containing the field def has been selected 12.239 - if (sel_klass.is_null()){ 12.240 + if (sel_klass.is_null()) { 12.241 ResourceMark rm(THREAD); 12.242 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 12.243 } 12.244 12.245 + if (!check_access) 12.246 + // Access checking may be turned off when calling from within the VM. 12.247 + return; 12.248 + 12.249 // check access 12.250 - KlassHandle ref_klass(THREAD, pool->pool_holder()); 12.251 - check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); 12.252 + check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); 12.253 12.254 // check for errors 12.255 if (is_static != fd.is_static()) { 12.256 @@ -629,7 +685,7 @@ 12.257 } 12.258 12.259 // Final fields can only be accessed from its own class. 12.260 - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { 12.261 + if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { 12.262 THROW(vmSymbols::java_lang_IllegalAccessError()); 12.263 } 12.264 12.265 @@ -639,19 +695,18 @@ 12.266 // 12.267 // note 2: we don't want to force initialization if we are just checking 12.268 // if the field access is legal; e.g., during compilation 12.269 - if (is_static && !check_only) { 12.270 + if (is_static && initialize_class) { 12.271 sel_klass->initialize(CHECK); 12.272 } 12.273 12.274 - { 12.275 + if (sel_klass() != current_klass()) { 12.276 HandleMark hm(THREAD); 12.277 - Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader()); 12.278 + Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); 12.279 Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); 12.280 - Symbol* signature_ref = pool->signature_ref_at(index); 12.281 { 12.282 ResourceMark rm(THREAD); 12.283 Symbol* failed_type_symbol = 12.284 - SystemDictionary::check_signature_loaders(signature_ref, 12.285 + SystemDictionary::check_signature_loaders(sig, 12.286 ref_loader, sel_loader, 12.287 false, 12.288 CHECK); 12.289 @@ -677,9 +732,6 @@ 12.290 12.291 // return information. note that the klass is set to the actual klass containing the 12.292 // field, otherwise access of static fields in superclasses will not work. 12.293 - KlassHandle holder (THREAD, fd.field_holder()); 12.294 - Symbol* name = fd.name(); 12.295 - result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); 12.296 } 12.297 12.298 12.299 @@ -907,10 +959,6 @@ 12.300 } 12.301 12.302 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s 12.303 - // has not been rewritten, and the vtable initialized. 12.304 - assert(resolved_method->method_holder()->is_linked(), "must be linked"); 12.305 - 12.306 - // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s 12.307 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since 12.308 // a missing receiver might result in a bogus lookup. 12.309 assert(resolved_method->method_holder()->is_linked(), "must be linked"); 12.310 @@ -920,6 +968,7 @@ 12.311 vtable_index = vtable_index_of_miranda_method(resolved_klass, 12.312 resolved_method->name(), 12.313 resolved_method->signature(), CHECK); 12.314 + 12.315 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); 12.316 12.317 InstanceKlass* inst = InstanceKlass::cast(recv_klass()); 12.318 @@ -927,6 +976,7 @@ 12.319 } else { 12.320 // at this point we are sure that resolved_method is virtual and not 12.321 // a miranda method; therefore, it must have a valid vtable index. 12.322 + assert(!resolved_method->has_itable_index(), ""); 12.323 vtable_index = resolved_method->vtable_index(); 12.324 // We could get a negative vtable_index for final methods, 12.325 // because as an optimization they are they are never put in the vtable, 12.326 @@ -1006,6 +1056,12 @@ 12.327 lookup_instance_method_in_klasses(sel_method, recv_klass, 12.328 resolved_method->name(), 12.329 resolved_method->signature(), CHECK); 12.330 + if (sel_method.is_null() && !check_null_and_abstract) { 12.331 + // In theory this is a harmless placeholder value, but 12.332 + // in practice leaving in null affects the nsk default method tests. 12.333 + // This needs further study. 12.334 + sel_method = resolved_method; 12.335 + } 12.336 // check if method exists 12.337 if (sel_method.is_null()) { 12.338 ResourceMark rm(THREAD); 12.339 @@ -1046,7 +1102,14 @@ 12.340 sel_method->signature())); 12.341 } 12.342 // setup result 12.343 - result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); 12.344 + if (!resolved_method->has_itable_index()) { 12.345 + int vtable_index = resolved_method->vtable_index(); 12.346 + assert(vtable_index == sel_method->vtable_index(), "sanity check"); 12.347 + result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); 12.348 + return; 12.349 + } 12.350 + int itable_index = resolved_method()->itable_index(); 12.351 + result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); 12.352 } 12.353 12.354 12.355 @@ -1293,7 +1356,8 @@ 12.356 } 12.357 12.358 if (TraceMethodHandles) { 12.359 - tty->print_cr("resolve_invokedynamic #%d %s %s", 12.360 + ResourceMark rm(THREAD); 12.361 + tty->print_cr("resolve_invokedynamic #%d %s %s", 12.362 ConstantPool::decode_invokedynamic_index(index), 12.363 method_name->as_C_string(), method_signature->as_C_string()); 12.364 tty->print(" BSM info: "); bootstrap_specifier->print(); 12.365 @@ -1342,9 +1406,16 @@ 12.366 //------------------------------------------------------------------------------------------------------------------------ 12.367 #ifndef PRODUCT 12.368 12.369 -void FieldAccessInfo::print() { 12.370 +void CallInfo::print() { 12.371 ResourceMark rm; 12.372 - tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); 12.373 + const char* kindstr = "unknown"; 12.374 + switch (_call_kind) { 12.375 + case direct_call: kindstr = "direct"; break; 12.376 + case vtable_call: kindstr = "vtable"; break; 12.377 + case itable_call: kindstr = "itable"; break; 12.378 + } 12.379 + tty->print_cr("Call %s@%d %s", kindstr, _call_index, 12.380 + _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); 12.381 } 12.382 12.383 #endif
13.1 --- a/src/share/vm/interpreter/linkResolver.hpp Tue Sep 17 23:12:27 2013 +0200 13.2 +++ b/src/share/vm/interpreter/linkResolver.hpp Fri Sep 13 22:38:02 2013 -0400 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -30,63 +30,54 @@ 13.11 13.12 // All the necessary definitions for run-time link resolution. 13.13 13.14 -// LinkInfo & its subclasses provide all the information gathered 13.15 -// for a particular link after resolving it. A link is any reference 13.16 +// CallInfo provides all the information gathered for a particular 13.17 +// linked call site after resolving it. A link is any reference 13.18 // made from within the bytecodes of a method to an object outside of 13.19 // that method. If the info is invalid, the link has not been resolved 13.20 // successfully. 13.21 13.22 -class LinkInfo VALUE_OBJ_CLASS_SPEC { 13.23 -}; 13.24 - 13.25 - 13.26 -// Link information for getfield/putfield & getstatic/putstatic bytecodes. 13.27 - 13.28 -class FieldAccessInfo: public LinkInfo { 13.29 - protected: 13.30 - KlassHandle _klass; 13.31 - Symbol* _name; 13.32 - AccessFlags _access_flags; 13.33 - int _field_index; // original index in the klass 13.34 - int _field_offset; 13.35 - BasicType _field_type; 13.36 - 13.37 +class CallInfo VALUE_OBJ_CLASS_SPEC { 13.38 public: 13.39 - void set(KlassHandle klass, Symbol* name, int field_index, int field_offset, 13.40 - BasicType field_type, AccessFlags access_flags); 13.41 - KlassHandle klass() const { return _klass; } 13.42 - Symbol* name() const { return _name; } 13.43 - int field_index() const { return _field_index; } 13.44 - int field_offset() const { return _field_offset; } 13.45 - BasicType field_type() const { return _field_type; } 13.46 - AccessFlags access_flags() const { return _access_flags; } 13.47 - 13.48 - // debugging 13.49 - void print() PRODUCT_RETURN; 13.50 -}; 13.51 - 13.52 - 13.53 -// Link information for all calls. 13.54 - 13.55 -class CallInfo: public LinkInfo { 13.56 + // Ways that a method call might be selected (or not) based on receiver type. 13.57 + // Note that an invokevirtual instruction might be linked with no_dispatch, 13.58 + // and an invokeinterface instruction might be linked with any of the three options 13.59 + enum CallKind { 13.60 + direct_call, // jump into resolved_method (must be concrete) 13.61 + vtable_call, // select recv.klass.method_at_vtable(index) 13.62 + itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index) 13.63 + unknown_kind = -1 13.64 + }; 13.65 private: 13.66 - KlassHandle _resolved_klass; // static receiver klass 13.67 + KlassHandle _resolved_klass; // static receiver klass, resolved from a symbolic reference 13.68 KlassHandle _selected_klass; // dynamic receiver class (same as static, or subklass) 13.69 methodHandle _resolved_method; // static target method 13.70 methodHandle _selected_method; // dynamic (actual) target method 13.71 - int _vtable_index; // vtable index of selected method 13.72 + CallKind _call_kind; // kind of call (static(=bytecode static/special + 13.73 + // others inferred), vtable, itable) 13.74 + int _call_index; // vtable or itable index of selected class method (if any) 13.75 Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix) 13.76 Handle _resolved_method_type; // MethodType (for invokedynamic and invokehandle call sites) 13.77 13.78 void set_static( KlassHandle resolved_klass, methodHandle resolved_method , TRAPS); 13.79 - void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method , TRAPS); 13.80 + void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index , TRAPS); 13.81 void set_virtual( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS); 13.82 void set_handle( methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS); 13.83 - void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS); 13.84 + void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, CallKind kind, int index, TRAPS); 13.85 13.86 friend class LinkResolver; 13.87 13.88 public: 13.89 + CallInfo() { 13.90 +#ifndef PRODUCT 13.91 + _call_kind = CallInfo::unknown_kind; 13.92 + _call_index = Method::garbage_vtable_index; 13.93 +#endif //PRODUCT 13.94 + } 13.95 + 13.96 + // utility to extract an effective CallInfo from a method and an optional receiver limit 13.97 + // does not queue the method for compilation 13.98 + CallInfo(Method* resolved_method, Klass* resolved_klass = NULL); 13.99 + 13.100 KlassHandle resolved_klass() const { return _resolved_klass; } 13.101 KlassHandle selected_klass() const { return _selected_klass; } 13.102 methodHandle resolved_method() const { return _resolved_method; } 13.103 @@ -95,21 +86,43 @@ 13.104 Handle resolved_method_type() const { return _resolved_method_type; } 13.105 13.106 BasicType result_type() const { return selected_method()->result_type(); } 13.107 - bool has_vtable_index() const { return _vtable_index >= 0; } 13.108 - bool is_statically_bound() const { return _vtable_index == Method::nonvirtual_vtable_index; } 13.109 + CallKind call_kind() const { return _call_kind; } 13.110 + int call_index() const { return _call_index; } 13.111 int vtable_index() const { 13.112 // Even for interface calls the vtable index could be non-negative. 13.113 // See CallInfo::set_interface. 13.114 assert(has_vtable_index() || is_statically_bound(), ""); 13.115 - return _vtable_index; 13.116 + assert(call_kind() == vtable_call || call_kind() == direct_call, ""); 13.117 + // The returned value is < 0 if the call is statically bound. 13.118 + // But, the returned value may be >= 0 even if the kind is direct_call. 13.119 + // It is up to the caller to decide which way to go. 13.120 + return _call_index; 13.121 } 13.122 + int itable_index() const { 13.123 + assert(call_kind() == itable_call, ""); 13.124 + // The returned value is always >= 0, a valid itable index. 13.125 + return _call_index; 13.126 + } 13.127 + 13.128 + // debugging 13.129 +#ifdef ASSERT 13.130 + bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; } 13.131 + bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; } 13.132 +#endif //ASSERT 13.133 + void verify() PRODUCT_RETURN; 13.134 + void print() PRODUCT_RETURN; 13.135 }; 13.136 13.137 +// Link information for getfield/putfield & getstatic/putstatic bytecodes 13.138 +// is represented using a fieldDescriptor. 13.139 13.140 // The LinkResolver is used to resolve constant-pool references at run-time. 13.141 // It does all necessary link-time checks & throws exceptions if necessary. 13.142 13.143 class LinkResolver: AllStatic { 13.144 + friend class klassVtable; 13.145 + friend class klassItable; 13.146 + 13.147 private: 13.148 static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); 13.149 static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); 13.150 @@ -120,7 +133,6 @@ 13.151 static int vtable_index_of_miranda_method(KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); 13.152 13.153 static void resolve_klass (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); 13.154 - static void resolve_klass_no_update (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); // no update of constantPool entry 13.155 13.156 static void resolve_pool (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS); 13.157 13.158 @@ -148,9 +160,16 @@ 13.159 Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS); 13.160 13.161 // runtime/static resolving for fields 13.162 - static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS); 13.163 - // takes an extra bool argument "update_pool" to decide whether to update the constantPool during klass resolution. 13.164 - static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS); 13.165 + static void resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS); 13.166 + static void resolve_field(fieldDescriptor& result, KlassHandle resolved_klass, Symbol* field_name, Symbol* field_signature, 13.167 + KlassHandle current_klass, Bytecodes::Code access_kind, bool check_access, bool initialize_class, TRAPS); 13.168 + 13.169 + // source of access_kind codes: 13.170 + static Bytecodes::Code field_access_kind(bool is_static, bool is_put) { 13.171 + return (is_static 13.172 + ? (is_put ? Bytecodes::_putstatic : Bytecodes::_getstatic) 13.173 + : (is_put ? Bytecodes::_putfield : Bytecodes::_getfield )); 13.174 + } 13.175 13.176 // runtime resolving: 13.177 // resolved_klass = specified class (i.e., static receiver class)
14.1 --- a/src/share/vm/oops/constantPool.cpp Tue Sep 17 23:12:27 2013 +0200 14.2 +++ b/src/share/vm/oops/constantPool.cpp Fri Sep 13 22:38:02 2013 -0400 14.3 @@ -396,32 +396,6 @@ 14.4 } 14.5 14.6 14.7 -// This is an interface for the compiler that allows accessing non-resolved entries 14.8 -// in the constant pool - but still performs the validations tests. Must be used 14.9 -// in a pre-parse of the compiler - to determine what it can do and not do. 14.10 -// Note: We cannot update the ConstantPool from the vm_thread. 14.11 -Klass* ConstantPool::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { 14.12 - int which = this_oop->klass_ref_index_at(index); 14.13 - CPSlot entry = this_oop->slot_at(which); 14.14 - if (entry.is_resolved()) { 14.15 - assert(entry.get_klass()->is_klass(), "must be"); 14.16 - return entry.get_klass(); 14.17 - } else { 14.18 - assert(entry.is_unresolved(), "must be either symbol or klass"); 14.19 - Symbol* name = entry.get_symbol(); 14.20 - oop loader = this_oop->pool_holder()->class_loader(); 14.21 - oop protection_domain = this_oop->pool_holder()->protection_domain(); 14.22 - Handle h_loader(THREAD, loader); 14.23 - Handle h_prot (THREAD, protection_domain); 14.24 - KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); 14.25 - 14.26 - // Do access check for klasses 14.27 - if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL); 14.28 - return k(); 14.29 - } 14.30 -} 14.31 - 14.32 - 14.33 Method* ConstantPool::method_at_if_loaded(constantPoolHandle cpool, 14.34 int which) { 14.35 if (cpool->cache() == NULL) return NULL; // nothing to load yet
15.1 --- a/src/share/vm/oops/constantPool.hpp Tue Sep 17 23:12:27 2013 +0200 15.2 +++ b/src/share/vm/oops/constantPool.hpp Fri Sep 13 22:38:02 2013 -0400 15.3 @@ -730,8 +730,6 @@ 15.4 static oop method_type_at_if_loaded (constantPoolHandle this_oop, int which); 15.5 static Klass* klass_at_if_loaded (constantPoolHandle this_oop, int which); 15.6 static Klass* klass_ref_at_if_loaded (constantPoolHandle this_oop, int which); 15.7 - // Same as above - but does LinkResolving. 15.8 - static Klass* klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); 15.9 15.10 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the 15.11 // future by other Java code. These take constant pool indices rather than
16.1 --- a/src/share/vm/oops/cpCache.cpp Tue Sep 17 23:12:27 2013 +0200 16.2 +++ b/src/share/vm/oops/cpCache.cpp Fri Sep 13 22:38:02 2013 -0400 16.3 @@ -140,9 +140,10 @@ 16.4 err_msg("size must not change: parameter_size=%d, value=%d", parameter_size(), value)); 16.5 } 16.6 16.7 -void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, 16.8 - methodHandle method, 16.9 - int vtable_index) { 16.10 +void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code, 16.11 + methodHandle method, 16.12 + int vtable_index) { 16.13 + bool is_vtable_call = (vtable_index >= 0); // FIXME: split this method on this boolean 16.14 assert(method->interpreter_entry() != NULL, "should have been set at this point"); 16.15 assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache"); 16.16 16.17 @@ -160,7 +161,8 @@ 16.18 // ...and fall through as if we were handling invokevirtual: 16.19 case Bytecodes::_invokevirtual: 16.20 { 16.21 - if (method->can_be_statically_bound()) { 16.22 + if (!is_vtable_call) { 16.23 + assert(method->can_be_statically_bound(), ""); 16.24 // set_f2_as_vfinal_method checks if is_vfinal flag is true. 16.25 set_method_flags(as_TosState(method->result_type()), 16.26 ( 1 << is_vfinal_shift) | 16.27 @@ -169,6 +171,7 @@ 16.28 method()->size_of_parameters()); 16.29 set_f2_as_vfinal_method(method()); 16.30 } else { 16.31 + assert(!method->can_be_statically_bound(), ""); 16.32 assert(vtable_index >= 0, "valid index"); 16.33 assert(!method->is_final_method(), "sanity"); 16.34 set_method_flags(as_TosState(method->result_type()), 16.35 @@ -182,6 +185,7 @@ 16.36 16.37 case Bytecodes::_invokespecial: 16.38 case Bytecodes::_invokestatic: 16.39 + assert(!is_vtable_call, ""); 16.40 // Note: Read and preserve the value of the is_vfinal flag on any 16.41 // invokevirtual bytecode shared with this constant pool cache entry. 16.42 // It is cheap and safe to consult is_vfinal() at all times. 16.43 @@ -232,8 +236,22 @@ 16.44 NOT_PRODUCT(verify(tty)); 16.45 } 16.46 16.47 +void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, methodHandle method) { 16.48 + int index = Method::nonvirtual_vtable_index; 16.49 + // index < 0; FIXME: inline and customize set_direct_or_vtable_call 16.50 + set_direct_or_vtable_call(invoke_code, method, index); 16.51 +} 16.52 16.53 -void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index) { 16.54 +void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, methodHandle method, int index) { 16.55 + // either the method is a miranda or its holder should accept the given index 16.56 + assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), ""); 16.57 + // index >= 0; FIXME: inline and customize set_direct_or_vtable_call 16.58 + set_direct_or_vtable_call(invoke_code, method, index); 16.59 +} 16.60 + 16.61 +void ConstantPoolCacheEntry::set_itable_call(Bytecodes::Code invoke_code, methodHandle method, int index) { 16.62 + assert(method->method_holder()->verify_itable_index(index), ""); 16.63 + assert(invoke_code == Bytecodes::_invokeinterface, ""); 16.64 InstanceKlass* interf = method->method_holder(); 16.65 assert(interf->is_interface(), "must be an interface"); 16.66 assert(!method->is_final_method(), "interfaces do not have final methods; cannot link to one here");
17.1 --- a/src/share/vm/oops/cpCache.hpp Tue Sep 17 23:12:27 2013 +0200 17.2 +++ b/src/share/vm/oops/cpCache.hpp Fri Sep 13 22:38:02 2013 -0400 17.3 @@ -219,15 +219,29 @@ 17.4 Klass* root_klass // needed by the GC to dirty the klass 17.5 ); 17.6 17.7 - void set_method( // sets entry to resolved method entry 17.8 + private: 17.9 + void set_direct_or_vtable_call( 17.10 Bytecodes::Code invoke_code, // the bytecode used for invoking the method 17.11 methodHandle method, // the method/prototype if any (NULL, otherwise) 17.12 int vtable_index // the vtable index if any, else negative 17.13 ); 17.14 17.15 - void set_interface_call( 17.16 - methodHandle method, // Resolved method 17.17 - int index // Method index into interface 17.18 + public: 17.19 + void set_direct_call( // sets entry to exact concrete method entry 17.20 + Bytecodes::Code invoke_code, // the bytecode used for invoking the method 17.21 + methodHandle method // the method to call 17.22 + ); 17.23 + 17.24 + void set_vtable_call( // sets entry to vtable index 17.25 + Bytecodes::Code invoke_code, // the bytecode used for invoking the method 17.26 + methodHandle method, // resolved method which declares the vtable index 17.27 + int vtable_index // the vtable index 17.28 + ); 17.29 + 17.30 + void set_itable_call( 17.31 + Bytecodes::Code invoke_code, // the bytecode used; must be invokeinterface 17.32 + methodHandle method, // the resolved interface method 17.33 + int itable_index // index into itable for the method 17.34 ); 17.35 17.36 void set_method_handle(
18.1 --- a/src/share/vm/oops/fieldStreams.hpp Tue Sep 17 23:12:27 2013 +0200 18.2 +++ b/src/share/vm/oops/fieldStreams.hpp Fri Sep 13 22:38:02 2013 -0400 18.3 @@ -1,5 +1,5 @@ 18.4 /* 18.5 - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 18.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 18.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.8 * 18.9 * This code is free software; you can redistribute it and/or modify it 18.10 @@ -27,6 +27,7 @@ 18.11 18.12 #include "oops/instanceKlass.hpp" 18.13 #include "oops/fieldInfo.hpp" 18.14 +#include "runtime/fieldDescriptor.hpp" 18.15 18.16 // The is the base class for iteration over the fields array 18.17 // describing the declared fields in the class. Several subclasses 18.18 @@ -43,8 +44,10 @@ 18.19 int _index; 18.20 int _limit; 18.21 int _generic_signature_slot; 18.22 + fieldDescriptor _fd_buf; 18.23 18.24 FieldInfo* field() const { return FieldInfo::from_field_array(_fields, _index); } 18.25 + InstanceKlass* field_holder() const { return _constants->pool_holder(); } 18.26 18.27 int init_generic_signature_start_slot() { 18.28 int length = _fields->length(); 18.29 @@ -102,6 +105,7 @@ 18.30 _index = 0; 18.31 _limit = klass->java_fields_count(); 18.32 init_generic_signature_start_slot(); 18.33 + assert(klass == field_holder(), ""); 18.34 } 18.35 FieldStreamBase(instanceKlassHandle klass) { 18.36 _fields = klass->fields(); 18.37 @@ -109,6 +113,7 @@ 18.38 _index = 0; 18.39 _limit = klass->java_fields_count(); 18.40 init_generic_signature_start_slot(); 18.41 + assert(klass == field_holder(), ""); 18.42 } 18.43 18.44 // accessors 18.45 @@ -180,6 +185,12 @@ 18.46 return field()->contended_group(); 18.47 } 18.48 18.49 + // bridge to a heavier API: 18.50 + fieldDescriptor& field_descriptor() const { 18.51 + fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf); 18.52 + field.reinitialize(field_holder(), _index); 18.53 + return field; 18.54 + } 18.55 }; 18.56 18.57 // Iterate over only the internal fields
19.1 --- a/src/share/vm/oops/instanceKlass.cpp Tue Sep 17 23:12:27 2013 +0200 19.2 +++ b/src/share/vm/oops/instanceKlass.cpp Fri Sep 13 22:38:02 2013 -0400 19.3 @@ -286,7 +286,6 @@ 19.4 init_previous_versions(); 19.5 set_generic_signature_index(0); 19.6 release_set_methods_jmethod_ids(NULL); 19.7 - release_set_methods_cached_itable_indices(NULL); 19.8 set_annotations(NULL); 19.9 set_jvmti_cached_class_field_map(NULL); 19.10 set_initial_method_idnum(0); 19.11 @@ -1149,7 +1148,7 @@ 19.12 Symbol* f_name = fs.name(); 19.13 Symbol* f_sig = fs.signature(); 19.14 if (f_name == name && f_sig == sig) { 19.15 - fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); 19.16 + fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index()); 19.17 return true; 19.18 } 19.19 } 19.20 @@ -1218,7 +1217,7 @@ 19.21 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { 19.22 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { 19.23 if (fs.offset() == offset) { 19.24 - fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); 19.25 + fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index()); 19.26 if (fd->is_static() == is_static) return true; 19.27 } 19.28 } 19.29 @@ -1251,8 +1250,7 @@ 19.30 void InstanceKlass::do_local_static_fields(FieldClosure* cl) { 19.31 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { 19.32 if (fs.access_flags().is_static()) { 19.33 - fieldDescriptor fd; 19.34 - fd.initialize(this, fs.index()); 19.35 + fieldDescriptor& fd = fs.field_descriptor(); 19.36 cl->do_field(&fd); 19.37 } 19.38 } 19.39 @@ -1268,8 +1266,7 @@ 19.40 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { 19.41 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { 19.42 if (fs.access_flags().is_static()) { 19.43 - fieldDescriptor fd; 19.44 - fd.initialize(this_oop(), fs.index()); 19.45 + fieldDescriptor& fd = fs.field_descriptor(); 19.46 f(&fd, CHECK); 19.47 } 19.48 } 19.49 @@ -1291,7 +1288,7 @@ 19.50 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass); 19.51 int j = 0; 19.52 for (int i = 0; i < length; i += 1) { 19.53 - fd.initialize(this, i); 19.54 + fd.reinitialize(this, i); 19.55 if (!fd.is_static()) { 19.56 fields_sorted[j + 0] = fd.offset(); 19.57 fields_sorted[j + 1] = i; 19.58 @@ -1303,7 +1300,7 @@ 19.59 // _sort_Fn is defined in growableArray.hpp. 19.60 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); 19.61 for (int i = 0; i < length; i += 2) { 19.62 - fd.initialize(this, fields_sorted[i + 1]); 19.63 + fd.reinitialize(this, fields_sorted[i + 1]); 19.64 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); 19.65 cl->do_field(&fd); 19.66 } 19.67 @@ -1686,87 +1683,6 @@ 19.68 } 19.69 19.70 19.71 -// Cache an itable index 19.72 -void InstanceKlass::set_cached_itable_index(size_t idnum, int index) { 19.73 - int* indices = methods_cached_itable_indices_acquire(); 19.74 - int* to_dealloc_indices = NULL; 19.75 - 19.76 - // We use a double-check locking idiom here because this cache is 19.77 - // performance sensitive. In the normal system, this cache only 19.78 - // transitions from NULL to non-NULL which is safe because we use 19.79 - // release_set_methods_cached_itable_indices() to advertise the 19.80 - // new cache. A partially constructed cache should never be seen 19.81 - // by a racing thread. Cache reads and writes proceed without a 19.82 - // lock, but creation of the cache itself requires no leaks so a 19.83 - // lock is generally acquired in that case. 19.84 - // 19.85 - // If the RedefineClasses() API has been used, then this cache can 19.86 - // grow and we'll have transitions from non-NULL to bigger non-NULL. 19.87 - // Cache creation requires no leaks and we require safety between all 19.88 - // cache accesses and freeing of the old cache so a lock is generally 19.89 - // acquired when the RedefineClasses() API has been used. 19.90 - 19.91 - if (indices == NULL || idnum_can_increment()) { 19.92 - // we need a cache or the cache can grow 19.93 - MutexLocker ml(JNICachedItableIndex_lock); 19.94 - // reacquire the cache to see if another thread already did the work 19.95 - indices = methods_cached_itable_indices_acquire(); 19.96 - size_t length = 0; 19.97 - // cache size is stored in element[0], other elements offset by one 19.98 - if (indices == NULL || (length = (size_t)indices[0]) <= idnum) { 19.99 - size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count()); 19.100 - int* new_indices = NEW_C_HEAP_ARRAY(int, size+1, mtClass); 19.101 - new_indices[0] = (int)size; 19.102 - // copy any existing entries 19.103 - size_t i; 19.104 - for (i = 0; i < length; i++) { 19.105 - new_indices[i+1] = indices[i+1]; 19.106 - } 19.107 - // Set all the rest to -1 19.108 - for (i = length; i < size; i++) { 19.109 - new_indices[i+1] = -1; 19.110 - } 19.111 - if (indices != NULL) { 19.112 - // We have an old cache to delete so save it for after we 19.113 - // drop the lock. 19.114 - to_dealloc_indices = indices; 19.115 - } 19.116 - release_set_methods_cached_itable_indices(indices = new_indices); 19.117 - } 19.118 - 19.119 - if (idnum_can_increment()) { 19.120 - // this cache can grow so we have to write to it safely 19.121 - indices[idnum+1] = index; 19.122 - } 19.123 - } else { 19.124 - CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 19.125 - } 19.126 - 19.127 - if (!idnum_can_increment()) { 19.128 - // The cache cannot grow and this JNI itable index value does not 19.129 - // have to be unique like a jmethodID. If there is a race to set it, 19.130 - // it doesn't matter. 19.131 - indices[idnum+1] = index; 19.132 - } 19.133 - 19.134 - if (to_dealloc_indices != NULL) { 19.135 - // we allocated a new cache so free the old one 19.136 - FreeHeap(to_dealloc_indices); 19.137 - } 19.138 -} 19.139 - 19.140 - 19.141 -// Retrieve a cached itable index 19.142 -int InstanceKlass::cached_itable_index(size_t idnum) { 19.143 - int* indices = methods_cached_itable_indices_acquire(); 19.144 - if (indices != NULL && ((size_t)indices[0]) > idnum) { 19.145 - // indices exist and are long enough, retrieve possible cached 19.146 - return indices[idnum+1]; 19.147 - } 19.148 - return -1; 19.149 -} 19.150 - 19.151 - 19.152 // 19.153 // Walk the list of dependent nmethods searching for nmethods which 19.154 // are dependent on the changes that were passed in and mark them for 19.155 @@ -2326,12 +2242,6 @@ 19.156 } 19.157 } 19.158 19.159 - int* indices = methods_cached_itable_indices_acquire(); 19.160 - if (indices != (int*)NULL) { 19.161 - release_set_methods_cached_itable_indices(NULL); 19.162 - FreeHeap(indices); 19.163 - } 19.164 - 19.165 // release dependencies 19.166 nmethodBucket* b = _dependencies; 19.167 _dependencies = NULL; 19.168 @@ -2782,6 +2692,18 @@ 19.169 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" 19.170 }; 19.171 19.172 +static void print_vtable(intptr_t* start, int len, outputStream* st) { 19.173 + for (int i = 0; i < len; i++) { 19.174 + intptr_t e = start[i]; 19.175 + st->print("%d : " INTPTR_FORMAT, i, e); 19.176 + if (e != 0 && ((Metadata*)e)->is_metaspace_object()) { 19.177 + st->print(" "); 19.178 + ((Metadata*)e)->print_value_on(st); 19.179 + } 19.180 + st->cr(); 19.181 + } 19.182 +} 19.183 + 19.184 void InstanceKlass::print_on(outputStream* st) const { 19.185 assert(is_klass(), "must be klass"); 19.186 Klass::print_on(st); 19.187 @@ -2816,7 +2738,7 @@ 19.188 19.189 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); 19.190 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); 19.191 - if (Verbose) { 19.192 + if (Verbose || WizardMode) { 19.193 Array<Method*>* method_array = methods(); 19.194 for(int i = 0; i < method_array->length(); i++) { 19.195 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); 19.196 @@ -2874,7 +2796,9 @@ 19.197 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr(); 19.198 st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr(); 19.199 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable()); st->cr(); 19.200 + if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st); 19.201 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr(); 19.202 + if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st); 19.203 st->print_cr(BULLET"---- static fields (%d words):", static_field_size()); 19.204 FieldPrinter print_static_field(st); 19.205 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field); 19.206 @@ -2896,6 +2820,7 @@ 19.207 19.208 void InstanceKlass::print_value_on(outputStream* st) const { 19.209 assert(is_klass(), "must be klass"); 19.210 + if (Verbose || WizardMode) access_flags().print_on(st); 19.211 name()->print_value_on(st); 19.212 } 19.213
20.1 --- a/src/share/vm/oops/instanceKlass.hpp Tue Sep 17 23:12:27 2013 +0200 20.2 +++ b/src/share/vm/oops/instanceKlass.hpp Fri Sep 13 22:38:02 2013 -0400 20.3 @@ -245,7 +245,6 @@ 20.4 MemberNameTable* _member_names; // Member names 20.5 JNIid* _jni_ids; // First JNI identifier for static fields in this class 20.6 jmethodID* _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none 20.7 - int* _methods_cached_itable_indices; // itable_index cache for JNI invoke corresponding to methods idnum, or NULL 20.8 nmethodBucket* _dependencies; // list of dependent nmethods 20.9 nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class 20.10 BreakpointInfo* _breakpoints; // bpt lists, managed by Method* 20.11 @@ -690,10 +689,6 @@ 20.12 size_t *length_p, jmethodID* id_p); 20.13 jmethodID jmethod_id_or_null(Method* method); 20.14 20.15 - // cached itable index support 20.16 - void set_cached_itable_index(size_t idnum, int index); 20.17 - int cached_itable_index(size_t idnum); 20.18 - 20.19 // annotations support 20.20 Annotations* annotations() const { return _annotations; } 20.21 void set_annotations(Annotations* anno) { _annotations = anno; } 20.22 @@ -994,11 +989,6 @@ 20.23 void release_set_methods_jmethod_ids(jmethodID* jmeths) 20.24 { OrderAccess::release_store_ptr(&_methods_jmethod_ids, jmeths); } 20.25 20.26 - int* methods_cached_itable_indices_acquire() const 20.27 - { return (int*)OrderAccess::load_ptr_acquire(&_methods_cached_itable_indices); } 20.28 - void release_set_methods_cached_itable_indices(int* indices) 20.29 - { OrderAccess::release_store_ptr(&_methods_cached_itable_indices, indices); } 20.30 - 20.31 // Lock during initialization 20.32 public: 20.33 // Lock for (1) initialization; (2) access to the ConstantPool of this class.
21.1 --- a/src/share/vm/oops/klass.cpp Tue Sep 17 23:12:27 2013 +0200 21.2 +++ b/src/share/vm/oops/klass.cpp Fri Sep 13 22:38:02 2013 -0400 21.3 @@ -674,13 +674,23 @@ 21.4 21.5 #ifndef PRODUCT 21.6 21.7 -void Klass::verify_vtable_index(int i) { 21.8 +bool Klass::verify_vtable_index(int i) { 21.9 if (oop_is_instance()) { 21.10 - assert(i>=0 && i<((InstanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); 21.11 + int limit = ((InstanceKlass*)this)->vtable_length()/vtableEntry::size(); 21.12 + assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); 21.13 } else { 21.14 assert(oop_is_array(), "Must be"); 21.15 - assert(i>=0 && i<((ArrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); 21.16 + int limit = ((ArrayKlass*)this)->vtable_length()/vtableEntry::size(); 21.17 + assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); 21.18 } 21.19 + return true; 21.20 +} 21.21 + 21.22 +bool Klass::verify_itable_index(int i) { 21.23 + assert(oop_is_instance(), ""); 21.24 + int method_count = klassItable::method_count_for_interface(this); 21.25 + assert(i >= 0 && i < method_count, "index out of bounds"); 21.26 + return true; 21.27 } 21.28 21.29 #endif
22.1 --- a/src/share/vm/oops/klass.hpp Tue Sep 17 23:12:27 2013 +0200 22.2 +++ b/src/share/vm/oops/klass.hpp Fri Sep 13 22:38:02 2013 -0400 22.3 @@ -699,7 +699,8 @@ 22.4 void verify(bool check_dictionary = true) { verify_on(tty, check_dictionary); } 22.5 22.6 #ifndef PRODUCT 22.7 - void verify_vtable_index(int index); 22.8 + bool verify_vtable_index(int index); 22.9 + bool verify_itable_index(int index); 22.10 #endif 22.11 22.12 virtual void oop_verify_on(oop obj, outputStream* st);
23.1 --- a/src/share/vm/oops/klassVtable.cpp Tue Sep 17 23:12:27 2013 +0200 23.2 +++ b/src/share/vm/oops/klassVtable.cpp Fri Sep 13 22:38:02 2013 -0400 23.3 @@ -47,11 +47,12 @@ 23.4 23.5 23.6 // this function computes the vtable size (including the size needed for miranda 23.7 -// methods) and the number of miranda methods in this class 23.8 +// methods) and the number of miranda methods in this class. 23.9 // Note on Miranda methods: Let's say there is a class C that implements 23.10 -// interface I. Let's say there is a method m in I that neither C nor any 23.11 -// of its super classes implement (i.e there is no method of any access, with 23.12 -// the same name and signature as m), then m is a Miranda method which is 23.13 +// interface I, and none of C's superclasses implements I. 23.14 +// Let's say there is an abstract method m in I that neither C 23.15 +// nor any of its super classes implement (i.e there is no method of any access, 23.16 +// with the same name and signature as m), then m is a Miranda method which is 23.17 // entered as a public abstract method in C's vtable. From then on it should 23.18 // treated as any other public method in C for method over-ride purposes. 23.19 void klassVtable::compute_vtable_size_and_num_mirandas( 23.20 @@ -111,10 +112,13 @@ 23.21 } 23.22 23.23 int klassVtable::index_of(Method* m, int len) const { 23.24 - assert(m->vtable_index() >= 0, "do not ask this of non-vtable methods"); 23.25 + assert(m->has_vtable_index(), "do not ask this of non-vtable methods"); 23.26 return m->vtable_index(); 23.27 } 23.28 23.29 +// Copy super class's vtable to the first part (prefix) of this class's vtable, 23.30 +// and return the number of entries copied. Expects that 'super' is the Java 23.31 +// super class (arrays can have "array" super classes that must be skipped). 23.32 int klassVtable::initialize_from_super(KlassHandle super) { 23.33 if (super.is_null()) { 23.34 return 0; 23.35 @@ -139,14 +143,14 @@ 23.36 } 23.37 } 23.38 23.39 -// Revised lookup semantics introduced 1.3 (Kestral beta) 23.40 +// 23.41 +// Revised lookup semantics introduced 1.3 (Kestrel beta) 23.42 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { 23.43 23.44 // Note: Arrays can have intermediate array supers. Use java_super to skip them. 23.45 KlassHandle super (THREAD, klass()->java_super()); 23.46 int nofNewEntries = 0; 23.47 23.48 - 23.49 if (PrintVtables && !klass()->oop_is_array()) { 23.50 ResourceMark rm(THREAD); 23.51 tty->print_cr("Initializing: %s", _klass->name()->as_C_string()); 23.52 @@ -174,8 +178,10 @@ 23.53 int len = methods->length(); 23.54 int initialized = super_vtable_len; 23.55 23.56 - // update_inherited_vtable can stop for gc - ensure using handles 23.57 + // Check each of this class's methods against super; 23.58 + // if override, replace in copy of super vtable, otherwise append to end 23.59 for (int i = 0; i < len; i++) { 23.60 + // update_inherited_vtable can stop for gc - ensure using handles 23.61 HandleMark hm(THREAD); 23.62 assert(methods->at(i)->is_method(), "must be a Method*"); 23.63 methodHandle mh(THREAD, methods->at(i)); 23.64 @@ -189,11 +195,11 @@ 23.65 } 23.66 } 23.67 23.68 - // add miranda methods; it will also update the value of initialized 23.69 - fill_in_mirandas(&initialized); 23.70 + // add miranda methods to end of vtable. 23.71 + initialized = fill_in_mirandas(initialized); 23.72 23.73 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> 23.74 - // package_private -> publicprotected), the vtable might actually be smaller than our initial 23.75 + // package_private -> public/protected), the vtable might actually be smaller than our initial 23.76 // calculation. 23.77 assert(initialized <= _length, "vtable initialization failed"); 23.78 for(;initialized < _length; initialized++) { 23.79 @@ -248,14 +254,8 @@ 23.80 return superk; 23.81 } 23.82 23.83 -// Methods that are "effectively" final don't need vtable entries. 23.84 -bool method_is_effectively_final( 23.85 - AccessFlags klass_flags, methodHandle target) { 23.86 - return target->is_final() || klass_flags.is_final() && !target->is_overpass(); 23.87 -} 23.88 - 23.89 // Update child's copy of super vtable for overrides 23.90 -// OR return true if a new vtable entry is required 23.91 +// OR return true if a new vtable entry is required. 23.92 // Only called for InstanceKlass's, i.e. not for arrays 23.93 // If that changed, could not use _klass as handle for klass 23.94 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, 23.95 @@ -263,6 +263,7 @@ 23.96 ResourceMark rm; 23.97 bool allocate_new = true; 23.98 assert(klass->oop_is_instance(), "must be InstanceKlass"); 23.99 + assert(klass == target_method()->method_holder(), "caller resp."); 23.100 23.101 // Initialize the method's vtable index to "nonvirtual". 23.102 // If we allocate a vtable entry, we will update it to a non-negative number. 23.103 @@ -273,11 +274,17 @@ 23.104 return false; 23.105 } 23.106 23.107 - if (method_is_effectively_final(klass->access_flags(), target_method)) { 23.108 + if (target_method->is_final_method(klass->access_flags())) { 23.109 // a final method never needs a new entry; final methods can be statically 23.110 // resolved and they have to be present in the vtable only if they override 23.111 // a super's method, in which case they re-use its entry 23.112 allocate_new = false; 23.113 + } else if (klass->is_interface()) { 23.114 + allocate_new = false; // see note below in needs_new_vtable_entry 23.115 + // An interface never allocates new vtable slots, only inherits old ones. 23.116 + // This method will either be assigned its own itable index later, 23.117 + // or be assigned an inherited vtable index in the loop below. 23.118 + target_method()->set_vtable_index(Method::pending_itable_index); 23.119 } 23.120 23.121 // we need a new entry if there is no superclass 23.122 @@ -411,8 +418,14 @@ 23.123 Symbol* classname, 23.124 AccessFlags class_flags, 23.125 TRAPS) { 23.126 + if (class_flags.is_interface()) { 23.127 + // Interfaces do not use vtables, so there is no point to assigning 23.128 + // a vtable index to any of their methods. If we refrain from doing this, 23.129 + // we can use Method::_vtable_index to hold the itable index 23.130 + return false; 23.131 + } 23.132 23.133 - if (method_is_effectively_final(class_flags, target_method) || 23.134 + if (target_method->is_final_method(class_flags) || 23.135 // a final method never needs a new entry; final methods can be statically 23.136 // resolved and they have to be present in the vtable only if they override 23.137 // a super's method, in which case they re-use its entry 23.138 @@ -500,7 +513,8 @@ 23.139 return Method::invalid_vtable_index; 23.140 } 23.141 23.142 -// check if an entry is miranda 23.143 +// check if an entry at an index is miranda 23.144 +// requires that method m at entry be declared ("held") by an interface. 23.145 bool klassVtable::is_miranda_entry_at(int i) { 23.146 Method* m = method_at(i); 23.147 Klass* method_holder = m->method_holder(); 23.148 @@ -516,7 +530,9 @@ 23.149 return false; 23.150 } 23.151 23.152 -// check if a method is a miranda method, given a class's methods table and it's super 23.153 +// check if a method is a miranda method, given a class's methods table and its super 23.154 +// "miranda" means not static, not defined by this class, and not defined 23.155 +// in super unless it is private and therefore inaccessible to this class. 23.156 // the caller must make sure that the method belongs to an interface implemented by the class 23.157 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) { 23.158 if (m->is_static()) { 23.159 @@ -541,6 +557,14 @@ 23.160 return false; 23.161 } 23.162 23.163 +// Scans current_interface_methods for miranda methods that do not 23.164 +// already appear in new_mirandas and are also not defined-and-non-private 23.165 +// in super (superclass). These mirandas are added to all_mirandas if it is 23.166 +// not null; in addition, those that are not duplicates of miranda methods 23.167 +// inherited by super from its interfaces are added to new_mirandas. 23.168 +// Thus, new_mirandas will be the set of mirandas that this class introduces, 23.169 +// all_mirandas will be the set of all mirandas applicable to this class 23.170 +// including all defined in superclasses. 23.171 void klassVtable::add_new_mirandas_to_lists( 23.172 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, 23.173 Array<Method*>* current_interface_methods, Array<Method*>* class_methods, 23.174 @@ -599,17 +623,22 @@ 23.175 } 23.176 } 23.177 23.178 -// fill in mirandas 23.179 -void klassVtable::fill_in_mirandas(int* initialized) { 23.180 +// Discover miranda methods ("miranda" = "interface abstract, no binding"), 23.181 +// and append them into the vtable starting at index initialized, 23.182 +// return the new value of initialized. 23.183 +int klassVtable::fill_in_mirandas(int initialized) { 23.184 GrowableArray<Method*> mirandas(20); 23.185 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), 23.186 ik()->local_interfaces()); 23.187 for (int i = 0; i < mirandas.length(); i++) { 23.188 - put_method_at(mirandas.at(i), *initialized); 23.189 - ++(*initialized); 23.190 + put_method_at(mirandas.at(i), initialized); 23.191 + ++initialized; 23.192 } 23.193 + return initialized; 23.194 } 23.195 23.196 +// Copy this class's vtable to the vtable beginning at start. 23.197 +// Used to copy superclass vtable to prefix of subclass's vtable. 23.198 void klassVtable::copy_vtable_to(vtableEntry* start) { 23.199 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); 23.200 } 23.201 @@ -723,6 +752,12 @@ 23.202 23.203 // Initialization 23.204 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { 23.205 + if (_klass->is_interface()) { 23.206 + // This needs to go after vtable indexes are assigned but 23.207 + // before implementors need to know the number of itable indexes. 23.208 + assign_itable_indexes_for_interface(_klass()); 23.209 + } 23.210 + 23.211 // Cannot be setup doing bootstrapping, interfaces don't have 23.212 // itables, and klass with only ones entry have empty itables 23.213 if (Universe::is_bootstrapping() || 23.214 @@ -754,45 +789,89 @@ 23.215 } 23.216 23.217 23.218 +inline bool interface_method_needs_itable_index(Method* m) { 23.219 + if (m->is_static()) return false; // e.g., Stream.empty 23.220 + if (m->is_initializer()) return false; // <init> or <clinit> 23.221 + // If an interface redeclares a method from java.lang.Object, 23.222 + // it should already have a vtable index, don't touch it. 23.223 + // e.g., CharSequence.toString (from initialize_vtable) 23.224 + // if (m->has_vtable_index()) return false; // NO! 23.225 + return true; 23.226 +} 23.227 + 23.228 +int klassItable::assign_itable_indexes_for_interface(Klass* klass) { 23.229 + // an interface does not have an itable, but its methods need to be numbered 23.230 + if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count, 23.231 + klass->name()->as_C_string()); 23.232 + Array<Method*>* methods = InstanceKlass::cast(klass)->methods(); 23.233 + int nof_methods = methods->length(); 23.234 + int ime_num = 0; 23.235 + for (int i = 0; i < nof_methods; i++) { 23.236 + Method* m = methods->at(i); 23.237 + if (interface_method_needs_itable_index(m)) { 23.238 + assert(!m->is_final_method(), "no final interface methods"); 23.239 + // If m is already assigned a vtable index, do not disturb it. 23.240 + if (!m->has_vtable_index()) { 23.241 + assert(m->vtable_index() == Method::pending_itable_index, "set by initialize_vtable"); 23.242 + m->set_itable_index(ime_num); 23.243 + // Progress to next itable entry 23.244 + ime_num++; 23.245 + } 23.246 + } 23.247 + } 23.248 + assert(ime_num == method_count_for_interface(klass), "proper sizing"); 23.249 + return ime_num; 23.250 +} 23.251 + 23.252 +int klassItable::method_count_for_interface(Klass* interf) { 23.253 + assert(interf->oop_is_instance(), "must be"); 23.254 + assert(interf->is_interface(), "must be"); 23.255 + Array<Method*>* methods = InstanceKlass::cast(interf)->methods(); 23.256 + int nof_methods = methods->length(); 23.257 + while (nof_methods > 0) { 23.258 + Method* m = methods->at(nof_methods-1); 23.259 + if (m->has_itable_index()) { 23.260 + int length = m->itable_index() + 1; 23.261 +#ifdef ASSERT 23.262 + while (nof_methods = 0) { 23.263 + m = methods->at(--nof_methods); 23.264 + assert(!m->has_itable_index() || m->itable_index() < length, ""); 23.265 + } 23.266 +#endif //ASSERT 23.267 + return length; // return the rightmost itable index, plus one 23.268 + } 23.269 + nof_methods -= 1; 23.270 + } 23.271 + // no methods have itable indexes 23.272 + return 0; 23.273 +} 23.274 + 23.275 + 23.276 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { 23.277 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods(); 23.278 int nof_methods = methods->length(); 23.279 HandleMark hm; 23.280 - KlassHandle klass = _klass; 23.281 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable"); 23.282 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader()); 23.283 - int ime_num = 0; 23.284 23.285 - // Skip first Method* if it is a class initializer 23.286 - int i = methods->at(0)->is_static_initializer() ? 1 : 0; 23.287 - 23.288 - // m, method_name, method_signature, klass reset each loop so they 23.289 - // don't need preserving across check_signature_loaders call 23.290 - // methods needs a handle in case of gc from check_signature_loaders 23.291 - for(; i < nof_methods; i++) { 23.292 + int ime_count = method_count_for_interface(interf_h()); 23.293 + for (int i = 0; i < nof_methods; i++) { 23.294 Method* m = methods->at(i); 23.295 - Symbol* method_name = m->name(); 23.296 - Symbol* method_signature = m->signature(); 23.297 - 23.298 - // This is same code as in Linkresolver::lookup_instance_method_in_klasses 23.299 - Method* target = klass->uncached_lookup_method(method_name, method_signature); 23.300 - while (target != NULL && target->is_static()) { 23.301 - // continue with recursive lookup through the superclass 23.302 - Klass* super = target->method_holder()->super(); 23.303 - target = (super == NULL) ? (Method*)NULL : super->uncached_lookup_method(method_name, method_signature); 23.304 + methodHandle target; 23.305 + if (m->has_itable_index()) { 23.306 + LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK); 23.307 } 23.308 if (target == NULL || !target->is_public() || target->is_abstract()) { 23.309 // Entry do not resolve. Leave it empty 23.310 } else { 23.311 // Entry did resolve, check loader constraints before initializing 23.312 // if checkconstraints requested 23.313 - methodHandle target_h (THREAD, target); // preserve across gc 23.314 if (checkconstraints) { 23.315 Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); 23.316 if (method_holder_loader() != interface_loader()) { 23.317 ResourceMark rm(THREAD); 23.318 Symbol* failed_type_symbol = 23.319 - SystemDictionary::check_signature_loaders(method_signature, 23.320 + SystemDictionary::check_signature_loaders(m->signature(), 23.321 method_holder_loader, 23.322 interface_loader, 23.323 true, CHECK); 23.324 @@ -803,9 +882,9 @@ 23.325 "and the class loader (instance of %s) for interface " 23.326 "%s have different Class objects for the type %s " 23.327 "used in the signature"; 23.328 - char* sig = target_h()->name_and_sig_as_C_string(); 23.329 + char* sig = target()->name_and_sig_as_C_string(); 23.330 const char* loader1 = SystemDictionary::loader_name(method_holder_loader()); 23.331 - char* current = klass->name()->as_C_string(); 23.332 + char* current = _klass->name()->as_C_string(); 23.333 const char* loader2 = SystemDictionary::loader_name(interface_loader()); 23.334 char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string(); 23.335 char* failed_type_name = failed_type_symbol->as_C_string(); 23.336 @@ -821,10 +900,10 @@ 23.337 } 23.338 23.339 // ime may have moved during GC so recalculate address 23.340 - itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target_h()); 23.341 + int ime_num = m->itable_index(); 23.342 + assert(ime_num < ime_count, "oob"); 23.343 + itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target()); 23.344 } 23.345 - // Progress to next entry 23.346 - ime_num++; 23.347 } 23.348 } 23.349 23.350 @@ -913,20 +992,22 @@ 23.351 virtual void doit(Klass* intf, int method_count) = 0; 23.352 }; 23.353 23.354 -// Visit all interfaces with at-least one method (excluding <clinit>) 23.355 +// Visit all interfaces with at least one itable method 23.356 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) { 23.357 // Handle array argument 23.358 for(int i = 0; i < transitive_intf->length(); i++) { 23.359 Klass* intf = transitive_intf->at(i); 23.360 assert(intf->is_interface(), "sanity check"); 23.361 23.362 - // Find no. of methods excluding a <clinit> 23.363 - int method_count = InstanceKlass::cast(intf)->methods()->length(); 23.364 - if (method_count > 0) { 23.365 - Method* m = InstanceKlass::cast(intf)->methods()->at(0); 23.366 - assert(m != NULL && m->is_method(), "sanity check"); 23.367 - if (m->name() == vmSymbols::object_initializer_name()) { 23.368 - method_count--; 23.369 + // Find no. of itable methods 23.370 + int method_count = 0; 23.371 + // method_count = klassItable::method_count_for_interface(intf); 23.372 + Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); 23.373 + if (methods->length() > 0) { 23.374 + for (int i = methods->length(); --i >= 0; ) { 23.375 + if (interface_method_needs_itable_index(methods->at(i))) { 23.376 + method_count++; 23.377 + } 23.378 } 23.379 } 23.380 23.381 @@ -1024,40 +1105,26 @@ 23.382 } 23.383 23.384 23.385 -// m must be a method in an interface 23.386 -int klassItable::compute_itable_index(Method* m) { 23.387 - InstanceKlass* intf = m->method_holder(); 23.388 - assert(intf->is_interface(), "sanity check"); 23.389 - Array<Method*>* methods = intf->methods(); 23.390 - int index = 0; 23.391 - while(methods->at(index) != m) { 23.392 - index++; 23.393 - assert(index < methods->length(), "should find index for resolve_invoke"); 23.394 - } 23.395 - // Adjust for <clinit>, which is left out of table if first method 23.396 - if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { 23.397 - index--; 23.398 - } 23.399 - return index; 23.400 -} 23.401 - 23.402 - 23.403 -// inverse to compute_itable_index 23.404 +// inverse to itable_index 23.405 Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) { 23.406 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); 23.407 + assert(intf->verify_itable_index(itable_index), ""); 23.408 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); 23.409 23.410 - int index = itable_index; 23.411 - // Adjust for <clinit>, which is left out of table if first method 23.412 - if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { 23.413 - index++; 23.414 - } 23.415 - 23.416 - if (itable_index < 0 || index >= methods->length()) 23.417 + if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) 23.418 return NULL; // help caller defend against bad indexes 23.419 23.420 + int index = itable_index; 23.421 Method* m = methods->at(index); 23.422 - assert(compute_itable_index(m) == itable_index, "correct inverse"); 23.423 + int index2 = -1; 23.424 + while (!m->has_itable_index() || 23.425 + (index2 = m->itable_index()) != itable_index) { 23.426 + assert(index2 < itable_index, "monotonic"); 23.427 + if (++index == methods->length()) 23.428 + return NULL; 23.429 + m = methods->at(index); 23.430 + } 23.431 + assert(m->itable_index() == itable_index, "correct inverse"); 23.432 23.433 return m; 23.434 }
24.1 --- a/src/share/vm/oops/klassVtable.hpp Tue Sep 17 23:12:27 2013 +0200 24.2 +++ b/src/share/vm/oops/klassVtable.hpp Fri Sep 13 22:38:02 2013 -0400 24.3 @@ -124,7 +124,7 @@ 24.4 24.5 // support for miranda methods 24.6 bool is_miranda_entry_at(int i); 24.7 - void fill_in_mirandas(int* initialized); 24.8 + int fill_in_mirandas(int initialized); 24.9 static bool is_miranda(Method* m, Array<Method*>* class_methods, Klass* super); 24.10 static void add_new_mirandas_to_lists( 24.11 GrowableArray<Method*>* new_mirandas, 24.12 @@ -290,12 +290,12 @@ 24.13 #endif // INCLUDE_JVMTI 24.14 24.15 // Setup of itable 24.16 + static int assign_itable_indexes_for_interface(Klass* klass); 24.17 + static int method_count_for_interface(Klass* klass); 24.18 static int compute_itable_size(Array<Klass*>* transitive_interfaces); 24.19 static void setup_itable_offset_table(instanceKlassHandle klass); 24.20 24.21 // Resolving of method to index 24.22 - static int compute_itable_index(Method* m); 24.23 - // ...and back again: 24.24 static Method* method_for_itable_index(Klass* klass, int itable_index); 24.25 24.26 // Debugging/Statistics
25.1 --- a/src/share/vm/oops/method.cpp Tue Sep 17 23:12:27 2013 +0200 25.2 +++ b/src/share/vm/oops/method.cpp Fri Sep 13 22:38:02 2013 -0400 25.3 @@ -509,24 +509,31 @@ 25.4 return _access_flags.has_loops(); 25.5 } 25.6 25.7 +bool Method::is_final_method(AccessFlags class_access_flags) const { 25.8 + // or "does_not_require_vtable_entry" 25.9 + // overpass can occur, is not final (reuses vtable entry) 25.10 + // private methods get vtable entries for backward class compatibility. 25.11 + if (is_overpass()) return false; 25.12 + return is_final() || class_access_flags.is_final(); 25.13 +} 25.14 25.15 bool Method::is_final_method() const { 25.16 - // %%% Should return true for private methods also, 25.17 - // since there is no way to override them. 25.18 - return is_final() || method_holder()->is_final(); 25.19 + return is_final_method(method_holder()->access_flags()); 25.20 } 25.21 25.22 - 25.23 -bool Method::is_strict_method() const { 25.24 - return is_strict(); 25.25 -} 25.26 - 25.27 - 25.28 -bool Method::can_be_statically_bound() const { 25.29 - if (is_final_method()) return true; 25.30 +bool Method::can_be_statically_bound(AccessFlags class_access_flags) const { 25.31 + if (is_final_method(class_access_flags)) return true; 25.32 +#ifdef ASSERT 25.33 + bool is_nonv = (vtable_index() == nonvirtual_vtable_index); 25.34 + if (class_access_flags.is_interface()) assert(is_nonv == is_static(), err_msg("is_nonv=%s", is_nonv)); 25.35 +#endif 25.36 + assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question"); 25.37 return vtable_index() == nonvirtual_vtable_index; 25.38 } 25.39 25.40 +bool Method::can_be_statically_bound() const { 25.41 + return can_be_statically_bound(method_holder()->access_flags()); 25.42 +} 25.43 25.44 bool Method::is_accessor() const { 25.45 if (code_size() != 5) return false; 25.46 @@ -967,7 +974,7 @@ 25.47 25.48 assert(ik->is_subclass_of(method_holder()), "should be subklass"); 25.49 assert(ik->vtable() != NULL, "vtable should exist"); 25.50 - if (vtable_index() == nonvirtual_vtable_index) { 25.51 + if (!has_vtable_index()) { 25.52 return false; 25.53 } else { 25.54 Method* vt_m = ik->method_at_vtable(vtable_index()); 25.55 @@ -1959,7 +1966,7 @@ 25.56 25.57 void Method::print_value_on(outputStream* st) const { 25.58 assert(is_method(), "must be method"); 25.59 - st->print_cr(internal_name()); 25.60 + st->print(internal_name()); 25.61 print_address_on(st); 25.62 st->print(" "); 25.63 name()->print_value_on(st); 25.64 @@ -1967,6 +1974,7 @@ 25.65 signature()->print_value_on(st); 25.66 st->print(" in "); 25.67 method_holder()->print_value_on(st); 25.68 + if (WizardMode) st->print("#%d", _vtable_index); 25.69 if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); 25.70 if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code()); 25.71 }
26.1 --- a/src/share/vm/oops/method.hpp Tue Sep 17 23:12:27 2013 +0200 26.2 +++ b/src/share/vm/oops/method.hpp Fri Sep 13 22:38:02 2013 -0400 26.3 @@ -448,16 +448,22 @@ 26.4 enum VtableIndexFlag { 26.5 // Valid vtable indexes are non-negative (>= 0). 26.6 // These few negative values are used as sentinels. 26.7 - highest_unused_vtable_index_value = -5, 26.8 + itable_index_max = -10, // first itable index, growing downward 26.9 + pending_itable_index = -9, // itable index will be assigned 26.10 invalid_vtable_index = -4, // distinct from any valid vtable index 26.11 garbage_vtable_index = -3, // not yet linked; no vtable layout yet 26.12 nonvirtual_vtable_index = -2 // there is no need for vtable dispatch 26.13 // 6330203 Note: Do not use -1, which was overloaded with many meanings. 26.14 }; 26.15 DEBUG_ONLY(bool valid_vtable_index() const { return _vtable_index >= nonvirtual_vtable_index; }) 26.16 - int vtable_index() const { assert(valid_vtable_index(), ""); 26.17 - return _vtable_index; } 26.18 + bool has_vtable_index() const { return _vtable_index >= 0; } 26.19 + int vtable_index() const { return _vtable_index; } 26.20 void set_vtable_index(int index) { _vtable_index = index; } 26.21 + DEBUG_ONLY(bool valid_itable_index() const { return _vtable_index <= pending_itable_index; }) 26.22 + bool has_itable_index() const { return _vtable_index <= itable_index_max; } 26.23 + int itable_index() const { assert(valid_itable_index(), ""); 26.24 + return itable_index_max - _vtable_index; } 26.25 + void set_itable_index(int index) { _vtable_index = itable_index_max - index; assert(valid_itable_index(), ""); } 26.26 26.27 // interpreter entry 26.28 address interpreter_entry() const { return _i2i_entry; } 26.29 @@ -560,10 +566,11 @@ 26.30 26.31 // checks method and its method holder 26.32 bool is_final_method() const; 26.33 - bool is_strict_method() const; 26.34 + bool is_final_method(AccessFlags class_access_flags) const; 26.35 26.36 // true if method needs no dynamic dispatch (final and/or no vtable entry) 26.37 bool can_be_statically_bound() const; 26.38 + bool can_be_statically_bound(AccessFlags class_access_flags) const; 26.39 26.40 // returns true if the method has any backward branches. 26.41 bool has_loops() { 26.42 @@ -740,10 +747,6 @@ 26.43 // so handles are not used to avoid deadlock. 26.44 jmethodID find_jmethod_id_or_null() { return method_holder()->jmethod_id_or_null(this); } 26.45 26.46 - // JNI static invoke cached itable index accessors 26.47 - int cached_itable_index() { return method_holder()->cached_itable_index(method_idnum()); } 26.48 - void set_cached_itable_index(int index) { method_holder()->set_cached_itable_index(method_idnum(), index); } 26.49 - 26.50 // Support for inlining of intrinsic methods 26.51 vmIntrinsics::ID intrinsic_id() const { return (vmIntrinsics::ID) _intrinsic_id; } 26.52 void set_intrinsic_id(vmIntrinsics::ID id) { _intrinsic_id = (u1) id; }
27.1 --- a/src/share/vm/oops/symbol.hpp Tue Sep 17 23:12:27 2013 +0200 27.2 +++ b/src/share/vm/oops/symbol.hpp Fri Sep 13 22:38:02 2013 -0400 27.3 @@ -45,7 +45,7 @@ 27.4 // in the SymbolTable bucket (the _literal field in HashtableEntry) 27.5 // that points to the Symbol. All other stores of a Symbol* 27.6 // to a field of a persistent variable (e.g., the _name filed in 27.7 -// FieldAccessInfo or _ptr in a CPSlot) is reference counted. 27.8 +// fieldDescriptor or _ptr in a CPSlot) is reference counted. 27.9 // 27.10 // 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for 27.11 // "name" and returns a pointer to F or finds a pre-existing Symbol F for
28.1 --- a/src/share/vm/opto/library_call.cpp Tue Sep 17 23:12:27 2013 +0200 28.2 +++ b/src/share/vm/opto/library_call.cpp Fri Sep 13 22:38:02 2013 -0400 28.3 @@ -3734,6 +3734,8 @@ 28.4 RegionNode* slow_region) { 28.5 ciMethod* method = callee(); 28.6 int vtable_index = method->vtable_index(); 28.7 + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 28.8 + err_msg_res("bad index %d", vtable_index)); 28.9 // Get the Method* out of the appropriate vtable entry. 28.10 int entry_offset = (InstanceKlass::vtable_start_offset() + 28.11 vtable_index*vtableEntry::size()) * wordSize + 28.12 @@ -3784,6 +3786,8 @@ 28.13 // so the vtable index is fixed. 28.14 // No need to use the linkResolver to get it. 28.15 vtable_index = method->vtable_index(); 28.16 + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 28.17 + err_msg_res("bad index %d", vtable_index)); 28.18 } 28.19 slow_call = new(C) CallDynamicJavaNode(tf, 28.20 SharedRuntime::get_resolve_virtual_call_stub(),
29.1 --- a/src/share/vm/prims/jni.cpp Tue Sep 17 23:12:27 2013 +0200 29.2 +++ b/src/share/vm/prims/jni.cpp Fri Sep 13 22:38:02 2013 -0400 29.3 @@ -1336,6 +1336,7 @@ 29.4 if (call_type == JNI_VIRTUAL) { 29.5 // jni_GetMethodID makes sure class is linked and initialized 29.6 // so m should have a valid vtable index. 29.7 + assert(!m->has_itable_index(), ""); 29.8 int vtbl_index = m->vtable_index(); 29.9 if (vtbl_index != Method::nonvirtual_vtable_index) { 29.10 Klass* k = h_recv->klass(); 29.11 @@ -1355,12 +1356,7 @@ 29.12 // interface call 29.13 KlassHandle h_holder(THREAD, holder); 29.14 29.15 - int itbl_index = m->cached_itable_index(); 29.16 - if (itbl_index == -1) { 29.17 - itbl_index = klassItable::compute_itable_index(m); 29.18 - m->set_cached_itable_index(itbl_index); 29.19 - // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again 29.20 - } 29.21 + int itbl_index = m->itable_index(); 29.22 Klass* k = h_recv->klass(); 29.23 selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); 29.24 }
30.1 --- a/src/share/vm/prims/jvm.cpp Tue Sep 17 23:12:27 2013 +0200 30.2 +++ b/src/share/vm/prims/jvm.cpp Fri Sep 13 22:38:02 2013 -0400 30.3 @@ -1824,7 +1824,7 @@ 30.4 } 30.5 30.6 if (!publicOnly || fs.access_flags().is_public()) { 30.7 - fd.initialize(k(), fs.index()); 30.8 + fd.reinitialize(k(), fs.index()); 30.9 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); 30.10 result->obj_at_put(out_idx, field); 30.11 ++out_idx;
31.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Tue Sep 17 23:12:27 2013 +0200 31.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Fri Sep 13 22:38:02 2013 -0400 31.3 @@ -2930,7 +2930,7 @@ 31.4 for (int i = 0; i < _deleted_methods_length; ++i) { 31.5 Method* old_method = _deleted_methods[i]; 31.6 31.7 - assert(old_method->vtable_index() < 0, 31.8 + assert(!old_method->has_vtable_index(), 31.9 "cannot delete methods with vtable entries");; 31.10 31.11 // Mark all deleted methods as old and obsolete
32.1 --- a/src/share/vm/prims/methodHandles.cpp Tue Sep 17 23:12:27 2013 +0200 32.2 +++ b/src/share/vm/prims/methodHandles.cpp Fri Sep 13 22:38:02 2013 -0400 32.3 @@ -127,25 +127,37 @@ 32.4 } 32.5 32.6 oop MethodHandles::init_MemberName(Handle mname, Handle target) { 32.7 + // This method is used from java.lang.invoke.MemberName constructors. 32.8 + // It fills in the new MemberName from a java.lang.reflect.Member. 32.9 Thread* thread = Thread::current(); 32.10 oop target_oop = target(); 32.11 Klass* target_klass = target_oop->klass(); 32.12 if (target_klass == SystemDictionary::reflect_Field_klass()) { 32.13 oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder() 32.14 int slot = java_lang_reflect_Field::slot(target_oop); // fd.index() 32.15 - int mods = java_lang_reflect_Field::modifiers(target_oop); 32.16 - oop type = java_lang_reflect_Field::type(target_oop); 32.17 - oop name = java_lang_reflect_Field::name(target_oop); 32.18 KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); 32.19 - intptr_t offset = InstanceKlass::cast(k())->field_offset(slot); 32.20 - return init_field_MemberName(mname, k, accessFlags_from(mods), type, name, offset); 32.21 + if (!k.is_null() && k->oop_is_instance()) { 32.22 + fieldDescriptor fd(InstanceKlass::cast(k()), slot); 32.23 + oop mname2 = init_field_MemberName(mname, fd); 32.24 + if (mname2 != NULL) { 32.25 + // Since we have the reified name and type handy, add them to the result. 32.26 + if (java_lang_invoke_MemberName::name(mname2) == NULL) 32.27 + java_lang_invoke_MemberName::set_name(mname2, java_lang_reflect_Field::name(target_oop)); 32.28 + if (java_lang_invoke_MemberName::type(mname2) == NULL) 32.29 + java_lang_invoke_MemberName::set_type(mname2, java_lang_reflect_Field::type(target_oop)); 32.30 + } 32.31 + return mname2; 32.32 + } 32.33 } else if (target_klass == SystemDictionary::reflect_Method_klass()) { 32.34 oop clazz = java_lang_reflect_Method::clazz(target_oop); 32.35 int slot = java_lang_reflect_Method::slot(target_oop); 32.36 KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); 32.37 if (!k.is_null() && k->oop_is_instance()) { 32.38 Method* m = InstanceKlass::cast(k())->method_with_idnum(slot); 32.39 - return init_method_MemberName(mname, m, true, k); 32.40 + if (m == NULL || is_signature_polymorphic(m->intrinsic_id())) 32.41 + return NULL; // do not resolve unless there is a concrete signature 32.42 + CallInfo info(m, k()); 32.43 + return init_method_MemberName(mname, info); 32.44 } 32.45 } else if (target_klass == SystemDictionary::reflect_Constructor_klass()) { 32.46 oop clazz = java_lang_reflect_Constructor::clazz(target_oop); 32.47 @@ -153,65 +165,50 @@ 32.48 KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); 32.49 if (!k.is_null() && k->oop_is_instance()) { 32.50 Method* m = InstanceKlass::cast(k())->method_with_idnum(slot); 32.51 - return init_method_MemberName(mname, m, false, k); 32.52 - } 32.53 - } else if (target_klass == SystemDictionary::MemberName_klass()) { 32.54 - // Note: This only works if the MemberName has already been resolved. 32.55 - oop clazz = java_lang_invoke_MemberName::clazz(target_oop); 32.56 - int flags = java_lang_invoke_MemberName::flags(target_oop); 32.57 - Metadata* vmtarget=java_lang_invoke_MemberName::vmtarget(target_oop); 32.58 - intptr_t vmindex = java_lang_invoke_MemberName::vmindex(target_oop); 32.59 - KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); 32.60 - int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK; 32.61 - if (vmtarget == NULL) return NULL; // not resolved 32.62 - if ((flags & IS_FIELD) != 0) { 32.63 - assert(vmtarget->is_klass(), "field vmtarget is Klass*"); 32.64 - int basic_mods = (ref_kind_is_static(ref_kind) ? JVM_ACC_STATIC : 0); 32.65 - // FIXME: how does k (receiver_limit) contribute? 32.66 - KlassHandle k_vmtarget(thread, (Klass*)vmtarget); 32.67 - return init_field_MemberName(mname, k_vmtarget, accessFlags_from(basic_mods), NULL, NULL, vmindex); 32.68 - } else if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) { 32.69 - assert(vmtarget->is_method(), "method or constructor vmtarget is Method*"); 32.70 - return init_method_MemberName(mname, (Method*)vmtarget, ref_kind_does_dispatch(ref_kind), k); 32.71 - } else { 32.72 - return NULL; 32.73 + if (m == NULL) return NULL; 32.74 + CallInfo info(m, k()); 32.75 + return init_method_MemberName(mname, info); 32.76 } 32.77 } 32.78 return NULL; 32.79 } 32.80 32.81 -oop MethodHandles::init_method_MemberName(Handle mname, Method* m, bool do_dispatch, 32.82 - KlassHandle receiver_limit_h) { 32.83 - Klass* receiver_limit = receiver_limit_h(); 32.84 - AccessFlags mods = m->access_flags(); 32.85 - int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); 32.86 - int vmindex = Method::nonvirtual_vtable_index; // implies never any dispatch 32.87 - Klass* mklass = m->method_holder(); 32.88 - if (receiver_limit == NULL) 32.89 - receiver_limit = mklass; 32.90 - if (m->is_initializer()) { 32.91 - flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); 32.92 - } else if (mods.is_static()) { 32.93 - flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT); 32.94 - } else if (receiver_limit != mklass && 32.95 - !receiver_limit->is_subtype_of(mklass)) { 32.96 - return NULL; // bad receiver limit 32.97 - } else if (do_dispatch && receiver_limit->is_interface() && 32.98 - mklass->is_interface()) { 32.99 +oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) { 32.100 + assert(info.resolved_appendix().is_null(), "only normal methods here"); 32.101 + KlassHandle receiver_limit = info.resolved_klass(); 32.102 + methodHandle m = info.resolved_method(); 32.103 + int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); 32.104 + int vmindex = Method::invalid_vtable_index; 32.105 + 32.106 + switch (info.call_kind()) { 32.107 + case CallInfo::itable_call: 32.108 + vmindex = info.itable_index(); 32.109 + // More importantly, the itable index only works with the method holder. 32.110 + receiver_limit = m->method_holder(); 32.111 + assert(receiver_limit->verify_itable_index(vmindex), ""); 32.112 flags |= IS_METHOD | (JVM_REF_invokeInterface << REFERENCE_KIND_SHIFT); 32.113 - receiver_limit = mklass; // ignore passed-in limit; interfaces are interconvertible 32.114 - vmindex = klassItable::compute_itable_index(m); 32.115 - } else if (do_dispatch && mklass != receiver_limit && mklass->is_interface()) { 32.116 + break; 32.117 + 32.118 + case CallInfo::vtable_call: 32.119 + vmindex = info.vtable_index(); 32.120 flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT); 32.121 - // it is a miranda method, so m->vtable_index is not what we want 32.122 - ResourceMark rm; 32.123 - klassVtable* vt = InstanceKlass::cast(receiver_limit)->vtable(); 32.124 - vmindex = vt->index_of_miranda(m->name(), m->signature()); 32.125 - } else if (!do_dispatch || m->can_be_statically_bound()) { 32.126 - flags |= IS_METHOD | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); 32.127 - } else { 32.128 - flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT); 32.129 - vmindex = m->vtable_index(); 32.130 + assert(receiver_limit->is_subtype_of(m->method_holder()), "virtual call must be type-safe"); 32.131 + break; 32.132 + 32.133 + case CallInfo::direct_call: 32.134 + vmindex = Method::nonvirtual_vtable_index; 32.135 + if (m->is_static()) { 32.136 + flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT); 32.137 + } else if (m->is_initializer()) { 32.138 + flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); 32.139 + assert(receiver_limit == m->method_holder(), "constructor call must be exactly typed"); 32.140 + } else { 32.141 + flags |= IS_METHOD | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); 32.142 + assert(receiver_limit->is_subtype_of(m->method_holder()), "special call must be type-safe"); 32.143 + } 32.144 + break; 32.145 + 32.146 + default: assert(false, "bad CallInfo"); return NULL; 32.147 } 32.148 32.149 // @CallerSensitive annotation detected 32.150 @@ -221,7 +218,7 @@ 32.151 32.152 oop mname_oop = mname(); 32.153 java_lang_invoke_MemberName::set_flags( mname_oop, flags); 32.154 - java_lang_invoke_MemberName::set_vmtarget(mname_oop, m); 32.155 + java_lang_invoke_MemberName::set_vmtarget(mname_oop, m()); 32.156 java_lang_invoke_MemberName::set_vmindex( mname_oop, vmindex); // vtable/itable index 32.157 java_lang_invoke_MemberName::set_clazz( mname_oop, receiver_limit->java_mirror()); 32.158 // Note: name and type can be lazily computed by resolve_MemberName, 32.159 @@ -237,59 +234,19 @@ 32.160 return mname(); 32.161 } 32.162 32.163 -Handle MethodHandles::init_method_MemberName(Handle mname, CallInfo& info, TRAPS) { 32.164 - Handle empty; 32.165 - if (info.resolved_appendix().not_null()) { 32.166 - // The resolved MemberName must not be accompanied by an appendix argument, 32.167 - // since there is no way to bind this value into the MemberName. 32.168 - // Caller is responsible to prevent this from happening. 32.169 - THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty); 32.170 - } 32.171 - methodHandle m = info.resolved_method(); 32.172 - KlassHandle defc = info.resolved_klass(); 32.173 - int vmindex = Method::invalid_vtable_index; 32.174 - if (defc->is_interface() && m->method_holder()->is_interface()) { 32.175 - // static interface methods do not reference vtable or itable 32.176 - if (m->is_static()) { 32.177 - vmindex = Method::nonvirtual_vtable_index; 32.178 - } 32.179 - // interface methods invoked via invokespecial also 32.180 - // do not reference vtable or itable. 32.181 - int ref_kind = ((java_lang_invoke_MemberName::flags(mname()) >> 32.182 - REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK); 32.183 - if (ref_kind == JVM_REF_invokeSpecial) { 32.184 - vmindex = Method::nonvirtual_vtable_index; 32.185 - } 32.186 - // If neither m is static nor ref_kind is invokespecial, 32.187 - // set it to itable index. 32.188 - if (vmindex == Method::invalid_vtable_index) { 32.189 - // LinkResolver does not report itable indexes! (fix this?) 32.190 - vmindex = klassItable::compute_itable_index(m()); 32.191 - } 32.192 - } else if (m->can_be_statically_bound()) { 32.193 - // LinkResolver reports vtable index even for final methods! 32.194 - vmindex = Method::nonvirtual_vtable_index; 32.195 - } else { 32.196 - vmindex = info.vtable_index(); 32.197 - } 32.198 - oop res = init_method_MemberName(mname, m(), (vmindex >= 0), defc()); 32.199 - assert(res == NULL || (java_lang_invoke_MemberName::vmindex(res) == vmindex), ""); 32.200 - return Handle(THREAD, res); 32.201 -} 32.202 - 32.203 -oop MethodHandles::init_field_MemberName(Handle mname, KlassHandle field_holder, 32.204 - AccessFlags mods, oop type, oop name, 32.205 - intptr_t offset, bool is_setter) { 32.206 - int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ); 32.207 - flags |= IS_FIELD | ((mods.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT); 32.208 +oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) { 32.209 + int flags = (jushort)( fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ); 32.210 + flags |= IS_FIELD | ((fd.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT); 32.211 if (is_setter) flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT); 32.212 - Metadata* vmtarget = field_holder(); 32.213 - int vmindex = offset; // determines the field uniquely when combined with static bit 32.214 + Metadata* vmtarget = fd.field_holder(); 32.215 + int vmindex = fd.offset(); // determines the field uniquely when combined with static bit 32.216 oop mname_oop = mname(); 32.217 java_lang_invoke_MemberName::set_flags(mname_oop, flags); 32.218 java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); 32.219 java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); 32.220 - java_lang_invoke_MemberName::set_clazz(mname_oop, field_holder->java_mirror()); 32.221 + java_lang_invoke_MemberName::set_clazz(mname_oop, fd.field_holder()->java_mirror()); 32.222 + oop type = field_signature_type_or_null(fd.signature()); 32.223 + oop name = field_name_or_null(fd.name()); 32.224 if (name != NULL) 32.225 java_lang_invoke_MemberName::set_name(mname_oop, name); 32.226 if (type != NULL) 32.227 @@ -305,19 +262,6 @@ 32.228 return mname(); 32.229 } 32.230 32.231 -Handle MethodHandles::init_field_MemberName(Handle mname, FieldAccessInfo& info, TRAPS) { 32.232 - return Handle(); 32.233 -#if 0 // FIXME 32.234 - KlassHandle field_holder = info.klass(); 32.235 - intptr_t field_offset = info.field_offset(); 32.236 - return init_field_MemberName(mname_oop, field_holder(), 32.237 - info.access_flags(), 32.238 - type, name, 32.239 - field_offset, false /*is_setter*/); 32.240 -#endif 32.241 -} 32.242 - 32.243 - 32.244 // JVM 2.9 Special Methods: 32.245 // A method is signature polymorphic if and only if all of the following conditions hold : 32.246 // * It is declared in the java.lang.invoke.MethodHandle class. 32.247 @@ -573,12 +517,12 @@ 32.248 return SystemDictionary::Object_klass()->java_mirror(); 32.249 } 32.250 32.251 -static oop field_name_or_null(Symbol* s) { 32.252 +oop MethodHandles::field_name_or_null(Symbol* s) { 32.253 if (s == NULL) return NULL; 32.254 return StringTable::lookup(s); 32.255 } 32.256 32.257 -static oop field_signature_type_or_null(Symbol* s) { 32.258 +oop MethodHandles::field_signature_type_or_null(Symbol* s) { 32.259 if (s == NULL) return NULL; 32.260 BasicType bt = FieldType::basic_type(s); 32.261 if (is_java_primitive(bt)) { 32.262 @@ -701,7 +645,14 @@ 32.263 return empty; 32.264 } 32.265 } 32.266 - return init_method_MemberName(mname, result, THREAD); 32.267 + if (result.resolved_appendix().not_null()) { 32.268 + // The resolved MemberName must not be accompanied by an appendix argument, 32.269 + // since there is no way to bind this value into the MemberName. 32.270 + // Caller is responsible to prevent this from happening. 32.271 + THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty); 32.272 + } 32.273 + oop mname2 = init_method_MemberName(mname, result); 32.274 + return Handle(THREAD, mname2); 32.275 } 32.276 case IS_CONSTRUCTOR: 32.277 { 32.278 @@ -719,22 +670,21 @@ 32.279 } 32.280 } 32.281 assert(result.is_statically_bound(), ""); 32.282 - return init_method_MemberName(mname, result, THREAD); 32.283 + oop mname2 = init_method_MemberName(mname, result); 32.284 + return Handle(THREAD, mname2); 32.285 } 32.286 case IS_FIELD: 32.287 { 32.288 - // This is taken from LinkResolver::resolve_field, sans access checks. 32.289 - fieldDescriptor fd; // find_field initializes fd if found 32.290 - KlassHandle sel_klass(THREAD, InstanceKlass::cast(defc())->find_field(name, type, &fd)); 32.291 - // check if field exists; i.e., if a klass containing the field def has been selected 32.292 - if (sel_klass.is_null()) return empty; // should not happen 32.293 - oop type = field_signature_type_or_null(fd.signature()); 32.294 - oop name = field_name_or_null(fd.name()); 32.295 - bool is_setter = (ref_kind_is_valid(ref_kind) && ref_kind_is_setter(ref_kind)); 32.296 - mname = Handle(THREAD, 32.297 - init_field_MemberName(mname, sel_klass, 32.298 - fd.access_flags(), type, name, fd.offset(), is_setter)); 32.299 - return mname; 32.300 + fieldDescriptor result; // find_field initializes fd if found 32.301 + { 32.302 + assert(!HAS_PENDING_EXCEPTION, ""); 32.303 + LinkResolver::resolve_field(result, defc, name, type, KlassHandle(), Bytecodes::_nop, false, false, THREAD); 32.304 + if (HAS_PENDING_EXCEPTION) { 32.305 + return empty; 32.306 + } 32.307 + } 32.308 + oop mname2 = init_field_MemberName(mname, result, ref_kind_is_setter(ref_kind)); 32.309 + return Handle(THREAD, mname2); 32.310 } 32.311 default: 32.312 THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty); 32.313 @@ -793,7 +743,6 @@ 32.314 } 32.315 case IS_FIELD: 32.316 { 32.317 - // This is taken from LinkResolver::resolve_field, sans access checks. 32.318 assert(vmtarget->is_klass(), "field vmtarget is Klass*"); 32.319 if (!((Klass*) vmtarget)->oop_is_instance()) break; 32.320 instanceKlassHandle defc(THREAD, (Klass*) vmtarget); 32.321 @@ -872,11 +821,7 @@ 32.322 Handle result(thread, results->obj_at(rfill++)); 32.323 if (!java_lang_invoke_MemberName::is_instance(result())) 32.324 return -99; // caller bug! 32.325 - oop type = field_signature_type_or_null(st.signature()); 32.326 - oop name = field_name_or_null(st.name()); 32.327 - oop saved = MethodHandles::init_field_MemberName(result, st.klass(), 32.328 - st.access_flags(), type, name, 32.329 - st.offset()); 32.330 + oop saved = MethodHandles::init_field_MemberName(result, st.field_descriptor()); 32.331 if (saved != result()) 32.332 results->obj_at_put(rfill-1, saved); // show saved instance to user 32.333 } else if (++overflow >= overflow_limit) { 32.334 @@ -926,7 +871,8 @@ 32.335 Handle result(thread, results->obj_at(rfill++)); 32.336 if (!java_lang_invoke_MemberName::is_instance(result())) 32.337 return -99; // caller bug! 32.338 - oop saved = MethodHandles::init_method_MemberName(result, m, true, NULL); 32.339 + CallInfo info(m); 32.340 + oop saved = MethodHandles::init_method_MemberName(result, info); 32.341 if (saved != result()) 32.342 results->obj_at_put(rfill-1, saved); // show saved instance to user 32.343 } else if (++overflow >= overflow_limit) { 32.344 @@ -1227,7 +1173,8 @@ 32.345 x = ((Klass*) vmtarget)->java_mirror(); 32.346 } else if (vmtarget->is_method()) { 32.347 Handle mname2 = MethodHandles::new_MemberName(CHECK_NULL); 32.348 - x = MethodHandles::init_method_MemberName(mname2, (Method*)vmtarget, false, NULL); 32.349 + CallInfo info((Method*)vmtarget); 32.350 + x = MethodHandles::init_method_MemberName(mname2, info); 32.351 } 32.352 result->obj_at_put(1, x); 32.353 return JNIHandles::make_local(env, result());
33.1 --- a/src/share/vm/prims/methodHandles.hpp Tue Sep 17 23:12:27 2013 +0200 33.2 +++ b/src/share/vm/prims/methodHandles.hpp Fri Sep 13 22:38:02 2013 -0400 33.3 @@ -49,19 +49,18 @@ 33.4 // Adapters. 33.5 static MethodHandlesAdapterBlob* _adapter_code; 33.6 33.7 + // utility functions for reifying names and types 33.8 + static oop field_name_or_null(Symbol* s); 33.9 + static oop field_signature_type_or_null(Symbol* s); 33.10 + 33.11 public: 33.12 // working with member names 33.13 static Handle resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type 33.14 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing 33.15 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName 33.16 static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target 33.17 - static oop init_method_MemberName(Handle mname_h, Method* m, bool do_dispatch, 33.18 - KlassHandle receiver_limit_h); 33.19 - static oop init_field_MemberName(Handle mname_h, KlassHandle field_holder_h, 33.20 - AccessFlags mods, oop type, oop name, 33.21 - intptr_t offset, bool is_setter = false); 33.22 - static Handle init_method_MemberName(Handle mname_h, CallInfo& info, TRAPS); 33.23 - static Handle init_field_MemberName(Handle mname_h, FieldAccessInfo& info, TRAPS); 33.24 + static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false); 33.25 + static oop init_method_MemberName(Handle mname_h, CallInfo& info); 33.26 static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true); 33.27 static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, 33.28 int mflags, KlassHandle caller,
34.1 --- a/src/share/vm/runtime/fieldDescriptor.cpp Tue Sep 17 23:12:27 2013 +0200 34.2 +++ b/src/share/vm/runtime/fieldDescriptor.cpp Fri Sep 13 22:38:02 2013 -0400 34.3 @@ -97,18 +97,32 @@ 34.4 return constants()->uncached_string_at(initial_value_index(), CHECK_0); 34.5 } 34.6 34.7 -void fieldDescriptor::initialize(InstanceKlass* ik, int index) { 34.8 - _cp = ik->constants(); 34.9 +void fieldDescriptor::reinitialize(InstanceKlass* ik, int index) { 34.10 + if (_cp.is_null() || field_holder() != ik) { 34.11 + _cp = constantPoolHandle(Thread::current(), ik->constants()); 34.12 + // _cp should now reference ik's constant pool; i.e., ik is now field_holder. 34.13 + assert(field_holder() == ik, "must be already initialized to this class"); 34.14 + } 34.15 FieldInfo* f = ik->field(index); 34.16 assert(!f->is_internal(), "regular Java fields only"); 34.17 34.18 _access_flags = accessFlags_from(f->access_flags()); 34.19 guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor"); 34.20 _index = index; 34.21 + verify(); 34.22 } 34.23 34.24 #ifndef PRODUCT 34.25 34.26 +void fieldDescriptor::verify() const { 34.27 + if (_cp.is_null()) { 34.28 + assert(_index == badInt, "constructor must be called"); // see constructor 34.29 + } else { 34.30 + assert(_index >= 0, "good index"); 34.31 + assert(_index < field_holder()->java_fields_count(), "oob"); 34.32 + } 34.33 +} 34.34 + 34.35 void fieldDescriptor::print_on(outputStream* st) const { 34.36 access_flags().print_on(st); 34.37 name()->print_value_on(st);
35.1 --- a/src/share/vm/runtime/fieldDescriptor.hpp Tue Sep 17 23:12:27 2013 +0200 35.2 +++ b/src/share/vm/runtime/fieldDescriptor.hpp Fri Sep 13 22:38:02 2013 -0400 35.3 @@ -1,5 +1,5 @@ 35.4 /* 35.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 35.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 35.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.8 * 35.9 * This code is free software; you can redistribute it and/or modify it 35.10 @@ -53,6 +53,13 @@ 35.11 } 35.12 35.13 public: 35.14 + fieldDescriptor() { 35.15 + DEBUG_ONLY(_index = badInt); 35.16 + } 35.17 + fieldDescriptor(InstanceKlass* ik, int index) { 35.18 + DEBUG_ONLY(_index = badInt); 35.19 + reinitialize(ik, index); 35.20 + } 35.21 Symbol* name() const { 35.22 return field()->name(_cp); 35.23 } 35.24 @@ -112,12 +119,13 @@ 35.25 } 35.26 35.27 // Initialization 35.28 - void initialize(InstanceKlass* ik, int index); 35.29 + void reinitialize(InstanceKlass* ik, int index); 35.30 35.31 // Print 35.32 void print() { print_on(tty); } 35.33 void print_on(outputStream* st) const PRODUCT_RETURN; 35.34 void print_on_for(outputStream* st, oop obj) PRODUCT_RETURN; 35.35 + void verify() const PRODUCT_RETURN; 35.36 }; 35.37 35.38 #endif // SHARE_VM_RUNTIME_FIELDDESCRIPTOR_HPP
36.1 --- a/src/share/vm/runtime/mutexLocker.cpp Tue Sep 17 23:12:27 2013 +0200 36.2 +++ b/src/share/vm/runtime/mutexLocker.cpp Fri Sep 13 22:38:02 2013 -0400 36.3 @@ -45,7 +45,6 @@ 36.4 Mutex* VMStatistic_lock = NULL; 36.5 Mutex* JNIGlobalHandle_lock = NULL; 36.6 Mutex* JNIHandleBlockFreeList_lock = NULL; 36.7 -Mutex* JNICachedItableIndex_lock = NULL; 36.8 Mutex* MemberNameTable_lock = NULL; 36.9 Mutex* JmethodIdCreation_lock = NULL; 36.10 Mutex* JfieldIdCreation_lock = NULL; 36.11 @@ -253,7 +252,6 @@ 36.12 } 36.13 def(Heap_lock , Monitor, nonleaf+1, false); 36.14 def(JfieldIdCreation_lock , Mutex , nonleaf+1, true ); // jfieldID, Used in VM_Operation 36.15 - def(JNICachedItableIndex_lock , Mutex , nonleaf+1, false); // Used to cache an itable index during JNI invoke 36.16 def(MemberNameTable_lock , Mutex , nonleaf+1, false); // Used to protect MemberNameTable 36.17 36.18 def(CompiledIC_lock , Mutex , nonleaf+2, false); // locks VtableStubs_lock, InlineCacheBuffer_lock
37.1 --- a/src/share/vm/runtime/mutexLocker.hpp Tue Sep 17 23:12:27 2013 +0200 37.2 +++ b/src/share/vm/runtime/mutexLocker.hpp Fri Sep 13 22:38:02 2013 -0400 37.3 @@ -1,5 +1,5 @@ 37.4 /* 37.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 37.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 37.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.8 * 37.9 * This code is free software; you can redistribute it and/or modify it 37.10 @@ -50,7 +50,6 @@ 37.11 extern Mutex* VMStatistic_lock; // a lock used to guard statistics count increment 37.12 extern Mutex* JNIGlobalHandle_lock; // a lock on creating JNI global handles 37.13 extern Mutex* JNIHandleBlockFreeList_lock; // a lock on the JNI handle block free list 37.14 -extern Mutex* JNICachedItableIndex_lock; // a lock on caching an itable index during JNI invoke 37.15 extern Mutex* MemberNameTable_lock; // a lock on the MemberNameTable updates 37.16 extern Mutex* JmethodIdCreation_lock; // a lock on creating JNI method identifiers 37.17 extern Mutex* JfieldIdCreation_lock; // a lock on creating JNI static field identifiers
38.1 --- a/src/share/vm/runtime/reflection.cpp Tue Sep 17 23:12:27 2013 +0200 38.2 +++ b/src/share/vm/runtime/reflection.cpp Fri Sep 13 22:38:02 2013 -0400 38.3 @@ -952,7 +952,8 @@ 38.4 } 38.5 } else { 38.6 // if the method can be overridden, we resolve using the vtable index. 38.7 - int index = reflected_method->vtable_index(); 38.8 + assert(!reflected_method->has_itable_index(), ""); 38.9 + int index = reflected_method->vtable_index(); 38.10 method = reflected_method; 38.11 if (index != Method::nonvirtual_vtable_index) { 38.12 // target_klass might be an arrayKlassOop but all vtables start at
39.1 --- a/src/share/vm/runtime/reflectionUtils.hpp Tue Sep 17 23:12:27 2013 +0200 39.2 +++ b/src/share/vm/runtime/reflectionUtils.hpp Fri Sep 13 22:38:02 2013 -0400 39.3 @@ -109,6 +109,8 @@ 39.4 private: 39.5 int length() const { return _klass->java_fields_count(); } 39.6 39.7 + fieldDescriptor _fd_buf; 39.8 + 39.9 public: 39.10 FieldStream(instanceKlassHandle klass, bool local_only, bool classes_only) 39.11 : KlassStream(klass, local_only, classes_only) { 39.12 @@ -134,6 +136,12 @@ 39.13 int offset() const { 39.14 return _klass->field_offset( index() ); 39.15 } 39.16 + // bridge to a heavier API: 39.17 + fieldDescriptor& field_descriptor() const { 39.18 + fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf); 39.19 + field.reinitialize(_klass(), _index); 39.20 + return field; 39.21 + } 39.22 }; 39.23 39.24 class FilteredField : public CHeapObj<mtInternal> {
40.1 --- a/src/share/vm/runtime/vmStructs.cpp Tue Sep 17 23:12:27 2013 +0200 40.2 +++ b/src/share/vm/runtime/vmStructs.cpp Fri Sep 13 22:38:02 2013 -0400 40.3 @@ -315,7 +315,6 @@ 40.4 nonstatic_field(InstanceKlass, _breakpoints, BreakpointInfo*) \ 40.5 nonstatic_field(InstanceKlass, _generic_signature_index, u2) \ 40.6 nonstatic_field(InstanceKlass, _methods_jmethod_ids, jmethodID*) \ 40.7 - nonstatic_field(InstanceKlass, _methods_cached_itable_indices, int*) \ 40.8 volatile_nonstatic_field(InstanceKlass, _idnum_allocated_count, u2) \ 40.9 nonstatic_field(InstanceKlass, _annotations, Annotations*) \ 40.10 nonstatic_field(InstanceKlass, _dependencies, nmethodBucket*) \