Mercurial > hg > icedtea7-forest > hotspot
changeset 5574:75a5b21398a3
Merge
author | asaha |
---|---|
date | Tue, 25 Feb 2014 23:18:36 -0800 |
parents | a133b4873886 (current diff) e325ae91a061 (diff) |
children | 4a9635c98a91 |
files | .hgtags |
diffstat | 21 files changed, 727 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Feb 20 15:09:32 2014 -0800 +++ b/.hgtags Tue Feb 25 23:18:36 2014 -0800 @@ -621,6 +621,7 @@ 049fd2cef85bf2d557dd7dd8a90a6831a8168ce4 jdk7u55-b08 9b238ab164e6d1cf9cfb560827d88ef8a7d8c898 jdk7u55-b09 573d8d080af9eff48aa3b8f0696d8874ce36fbb1 jdk7u55-b09 +36f8bd4dd467ae4183340842fd7158ac3309b826 jdk7u55-b10 ae4adc1492d1c90a70bd2d139a939fc0c8329be9 jdk7u60-b00 af1fc2868a2b919727bfbb0858449bd991bbee4a jdk7u40-b60 cc83359f5e5eb46dd9176b0a272390b1a0a51fdc hs24.60-b01
--- a/src/cpu/sparc/vm/templateInterpreter_sparc.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/cpu/sparc/vm/templateInterpreter_sparc.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1873,6 +1873,25 @@ if (ProfileInterpreter) { __ set_method_data_pointer_for_bcp(); } + + if (EnableInvokeDynamic) { + Label L_done; + + __ ldub(Address(Lbcp, 0), G1_scratch); // Load current bytecode + __ cmp_and_br_short(G1_scratch, Bytecodes::_invokestatic, Assembler::notEqual, Assembler::pn, L_done); + + // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. + // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. + + __ call_VM(G1_scratch, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), I0, Lmethod, Lbcp); + + __ br_null(G1_scratch, false, Assembler::pn, L_done); + __ delayed()->nop(); + + __ st_ptr(G1_scratch, Lesp, wordSize); + __ bind(L_done); + } + // Resume bytecode interpretation at the current bcp __ dispatch_next(vtos); // end of JVMTI PopFrame support
--- a/src/cpu/x86/vm/templateInterpreter_x86_32.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/cpu/x86/vm/templateInterpreter_x86_32.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1789,6 +1789,27 @@ __ get_thread(thread); __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive); + if (EnableInvokeDynamic) { + Label L_done; + const Register local0 = rdi; + + __ cmpb(Address(rsi, 0), Bytecodes::_invokestatic); + __ jcc(Assembler::notEqual, L_done); + + // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. + // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. + + __ get_method(rdx); + __ movptr(rax, Address(local0, 0)); + __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), rax, rdx, rsi); + + __ testptr(rax, rax); + __ jcc(Assembler::zero, L_done); + + __ movptr(Address(rbx, 0), rax); + __ bind(L_done); + } + __ dispatch_next(vtos); // end of PopFrame support
--- a/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1815,6 +1815,27 @@ __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive); + if (EnableInvokeDynamic) { + Label L_done; + const Register local0 = r14; + + __ cmpb(Address(r13, 0), Bytecodes::_invokestatic); + __ jcc(Assembler::notEqual, L_done); + + // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. + // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. + + __ get_method(rdx); + __ movptr(rax, Address(local0, 0)); + __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), rax, rdx, r13); + + __ testptr(rax, rax); + __ jcc(Assembler::zero, L_done); + + __ movptr(Address(rbx, 0), rax); + __ bind(L_done); + } + __ dispatch_next(vtos); // end of PopFrame support
--- a/src/share/vm/classfile/javaClasses.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/classfile/javaClasses.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2388,6 +2388,26 @@ *offset = value; } +// Support for java_lang_invoke_DirectMethodHandle + +int java_lang_invoke_DirectMethodHandle::_member_offset; + +oop java_lang_invoke_DirectMethodHandle::member(oop dmh) { + oop member_name = NULL; + bool is_dmh = dmh->is_oop() && java_lang_invoke_DirectMethodHandle::is_instance(dmh); + assert(is_dmh, "a DirectMethodHandle oop is expected"); + if (is_dmh) { + member_name = dmh->obj_field(member_offset_in_bytes()); + } + return member_name; +} + +void java_lang_invoke_DirectMethodHandle::compute_offsets() { + klassOop klass_oop = SystemDictionary::DirectMethodHandle_klass(); + if (klass_oop != NULL && EnableInvokeDynamic) { + compute_offset(_member_offset, klass_oop, vmSymbols::member_name(), vmSymbols::java_lang_invoke_MemberName_signature()); + } +} // Support for java_lang_invoke_MethodHandle @@ -2497,6 +2517,13 @@ return mname->obj_field(_vmtarget_offset); } +// Can be executed on VM thread only +void java_lang_invoke_MemberName::adjust_vmtarget(oop mname, oop ref) { + assert((is_instance(mname) && (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0), "wrong type"); + assert(Thread::current()->is_VM_thread(), "not VM thread"); + mname->address_field_put(_vmtarget_offset, (address)ref); +} + void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) { assert(is_instance(mname), "wrong type"); #ifdef ASSERT @@ -3000,6 +3027,7 @@ java_lang_ThreadGroup::compute_offsets(); if (EnableInvokeDynamic) { java_lang_invoke_MethodHandle::compute_offsets(); + java_lang_invoke_DirectMethodHandle::compute_offsets(); java_lang_invoke_MemberName::compute_offsets(); java_lang_invoke_LambdaForm::compute_offsets(); java_lang_invoke_MethodType::compute_offsets();
--- a/src/share/vm/classfile/javaClasses.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/classfile/javaClasses.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -915,6 +915,32 @@ static int form_offset_in_bytes() { return _form_offset; } }; +// Interface to java.lang.invoke.DirectMethodHandle objects + +class java_lang_invoke_DirectMethodHandle: AllStatic { + friend class JavaClasses; + + private: + static int _member_offset; // the MemberName of this DMH + + static void compute_offsets(); + + public: + // Accessors + static oop member(oop mh); + + // Testers + static bool is_subclass(klassOop klass) { + return Klass::cast(klass)->is_subclass_of(SystemDictionary::DirectMethodHandle_klass()); + } + static bool is_instance(oop obj) { + return obj != NULL && is_subclass(obj->klass()); + } + + // Accessors for code generation: + static int member_offset_in_bytes() { return _member_offset; } +}; + // Interface to java.lang.invoke.LambdaForm objects // (These are a private interface for managing adapter code generation.) @@ -988,6 +1014,7 @@ static oop vmtarget(oop mname); static void set_vmtarget(oop mname, oop target); + static void adjust_vmtarget(oop mname, oop target); static intptr_t vmindex(oop mname); static void set_vmindex(oop mname, intptr_t index);
--- a/src/share/vm/classfile/systemDictionary.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/classfile/systemDictionary.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -151,6 +151,7 @@ do_klass(MemberName_klass, java_lang_invoke_MemberName, Pre_JSR292 ) \ do_klass(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives, Pre_JSR292 ) \ do_klass(LambdaForm_klass, java_lang_invoke_LambdaForm, Opt ) \ + do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle, Opt ) \ do_klass(MethodType_klass, java_lang_invoke_MethodType, Pre_JSR292 ) \ do_klass(BootstrapMethodError_klass, java_lang_BootstrapMethodError, Pre_JSR292 ) \ do_klass(CallSite_klass, java_lang_invoke_CallSite, Pre_JSR292 ) \
--- a/src/share/vm/classfile/vmSymbols.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/classfile/vmSymbols.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -243,6 +243,7 @@ /* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \ template(java_lang_invoke_CallSite, "java/lang/invoke/CallSite") \ template(java_lang_invoke_ConstantCallSite, "java/lang/invoke/ConstantCallSite") \ + template(java_lang_invoke_DirectMethodHandle, "java/lang/invoke/DirectMethodHandle") \ template(java_lang_invoke_MutableCallSite, "java/lang/invoke/MutableCallSite") \ template(java_lang_invoke_VolatileCallSite, "java/lang/invoke/VolatileCallSite") \ template(java_lang_invoke_MethodHandle, "java/lang/invoke/MethodHandle") \ @@ -338,6 +339,7 @@ template(thread_id_name, "tid") \ template(newInstance0_name, "newInstance0") \ template(limit_name, "limit") \ + template(member_name, "member") \ template(forName_name, "forName") \ template(forName0_name, "forName0") \ template(isJavaIdentifierStart_name, "isJavaIdentifierStart") \
--- a/src/share/vm/interpreter/interpreterRuntime.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1222,3 +1222,24 @@ size_of_arguments * Interpreter::stackElementSize); IRT_END #endif + +// This is a support of the JVMTI PopFrame interface. +// Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument +// and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters. +// The dmh argument is a reference to a DirectMethoHandle that has a member name field. +IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address dmh, + methodOopDesc* method, address bcp)) + Bytecodes::Code code = Bytecodes::code_at(method, bcp); + if (code != Bytecodes::_invokestatic) { + return; + } + constantPoolOopDesc* cpool = method->constants(); + int cp_index = Bytes::get_native_u2(bcp + 1) + constantPoolOopDesc::CPCACHE_INDEX_TAG; + Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index)); + Symbol* mname = cpool->name_ref_at(cp_index); + + if (MethodHandles::has_member_arg(cname, mname)) { + oop member_name = java_lang_invoke_DirectMethodHandle::member((oop)dmh); + thread->set_vm_result(member_name); + } +IRT_END
--- a/src/share/vm/interpreter/interpreterRuntime.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -106,6 +106,7 @@ static void create_exception(JavaThread* thread, char* name, char* message); static void create_klass_exception(JavaThread* thread, char* name, oopDesc* obj); static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception); + static void member_name_arg_or_null(JavaThread* thread, address dmh, methodOopDesc* m, address bcp); static void throw_pending_exception(JavaThread* thread); // Statics & fields
--- a/src/share/vm/oops/constantPoolOop.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/oops/constantPoolOop.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1026,24 +1026,13 @@ case JVM_CONSTANT_InvokeDynamic: { - int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1); - int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2); - bool match = compare_entry_to(k1, cp2, k2, CHECK_false); - if (!match) return false; - k1 = invoke_dynamic_name_and_type_ref_index_at(index1); - k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); - match = compare_entry_to(k1, cp2, k2, CHECK_false); - if (!match) return false; - int argc = invoke_dynamic_argument_count_at(index1); - if (argc == cp2->invoke_dynamic_argument_count_at(index2)) { - for (int j = 0; j < argc; j++) { - k1 = invoke_dynamic_argument_index_at(index1, j); - k2 = cp2->invoke_dynamic_argument_index_at(index2, j); - match = compare_entry_to(k1, cp2, k2, CHECK_false); - if (!match) return false; - } - return true; // got through loop; all elements equal - } + int k1 = invoke_dynamic_name_and_type_ref_index_at(index1); + int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); + int i1 = invoke_dynamic_bootstrap_specifier_index(index1); + int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2); + bool match = compare_entry_to(k1, cp2, k2, CHECK_false) && + compare_operand_to(i1, cp2, i2, CHECK_false); + return match; } break; case JVM_CONSTANT_UnresolvedString: @@ -1078,6 +1067,74 @@ } // end compare_entry_to() +// Resize the operands array with delta_len and delta_size. +// Used in RedefineClasses for CP merge. +void constantPoolOopDesc::resize_operands(int delta_len, int delta_size, TRAPS) { + int old_len = operand_array_length(operands()); + int new_len = old_len + delta_len; + int min_len = (delta_len > 0) ? old_len : new_len; + + int old_size = operands()->length(); + int new_size = old_size + delta_size; + int min_size = (delta_size > 0) ? old_size : new_size; + + typeArrayHandle new_ops = oopFactory::new_permanent_intArray(new_size, CHECK); + + // Set index in the resized array for existing elements only + for (int idx = 0; idx < min_len; idx++) { + int offset = operand_offset_at(idx); // offset in original array + operand_offset_at_put(new_ops(), idx, offset + 2*delta_len); // offset in resized array + } + // Copy the bootstrap specifiers only + Copy::conjoint_memory_atomic(operands()->short_at_addr(2*old_len), + new_ops->short_at_addr(2*new_len), + (min_size - 2*min_len) * sizeof(u2)); + // Explicit deallocation of old operands array is not needed for 7u + set_operands(new_ops()); +} // end resize_operands() + + +// Extend the operands array with the length and size of the ext_cp operands. +// Used in RedefineClasses for CP merge. +void constantPoolOopDesc::extend_operands(constantPoolHandle ext_cp, TRAPS) { + int delta_len = operand_array_length(ext_cp->operands()); + if (delta_len == 0) { + return; // nothing to do + } + int delta_size = ext_cp->operands()->length(); + + assert(delta_len > 0 && delta_size > 0, "extended operands array must be bigger"); + + if (operand_array_length(operands()) == 0) { + typeArrayHandle new_ops = oopFactory::new_permanent_intArray(delta_size, CHECK); + // The first element index defines the offset of second part + operand_offset_at_put(new_ops(), 0, 2*delta_len); // offset in new array + set_operands(new_ops()); + } else { + resize_operands(delta_len, delta_size, CHECK); + } + +} // end extend_operands() + + +// Shrink the operands array to a smaller array with new_len length. +// Used in RedefineClasses for CP merge. +void constantPoolOopDesc::shrink_operands(int new_len, TRAPS) { + int old_len = operand_array_length(operands()); + if (new_len == old_len) { + return; // nothing to do + } + assert(new_len < old_len, "shrunken operands array must be smaller"); + + int free_base = operand_next_offset_at(new_len - 1); + int delta_len = new_len - old_len; + int delta_size = 2*delta_len + free_base - operands()->length(); + + resize_operands(delta_len, delta_size, CHECK); + +} // end shrink_operands() + + void constantPoolOopDesc::copy_operands(constantPoolHandle from_cp, constantPoolHandle to_cp, TRAPS) { @@ -1093,7 +1150,7 @@ int from_len = from_cp->operands()->length(); int old_off = old_oplen * sizeof(u2); int from_off = from_oplen * sizeof(u2); - typeArrayHandle new_operands = oopFactory::new_permanent_shortArray(old_len + from_len, CHECK); + typeArrayHandle new_operands = oopFactory::new_permanent_intArray(old_len + from_len, CHECK); int fillp = 0, len = 0; // first part of dest Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0), @@ -1345,6 +1402,46 @@ } // end find_matching_entry() +// Compare this constant pool's bootstrap specifier at idx1 to the constant pool +// cp2's bootstrap specifier at idx2. +bool constantPoolOopDesc::compare_operand_to(int idx1, constantPoolHandle cp2, int idx2, TRAPS) { + int k1 = operand_bootstrap_method_ref_index_at(idx1); + int k2 = cp2->operand_bootstrap_method_ref_index_at(idx2); + bool match = compare_entry_to(k1, cp2, k2, CHECK_false); + + if (!match) { + return false; + } + int argc = operand_argument_count_at(idx1); + if (argc == cp2->operand_argument_count_at(idx2)) { + for (int j = 0; j < argc; j++) { + k1 = operand_argument_index_at(idx1, j); + k2 = cp2->operand_argument_index_at(idx2, j); + match = compare_entry_to(k1, cp2, k2, CHECK_false); + if (!match) { + return false; + } + } + return true; // got through loop; all elements equal + } + return false; +} // end compare_operand_to() + +// Search constant pool search_cp for a bootstrap specifier that matches +// this constant pool's bootstrap specifier at pattern_i index. +// Return the index of a matching bootstrap specifier or (-1) if there is no match. +int constantPoolOopDesc::find_matching_operand(int pattern_i, + constantPoolHandle search_cp, int search_len, TRAPS) { + for (int i = 0; i < search_len; i++) { + bool found = compare_operand_to(pattern_i, search_cp, i, CHECK_(-1)); + if (found) { + return i; + } + } + return -1; // bootstrap specifier not found; return unused index (-1) +} // end find_matching_operand() + + #ifndef PRODUCT const char* constantPoolOopDesc::printable_name_at(int which) {
--- a/src/share/vm/oops/constantPoolOop.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/oops/constantPoolOop.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -565,6 +565,47 @@ _indy_argc_offset = 1, // u2 argc _indy_argv_offset = 2 // u2 argv[argc] }; + + // These functions are used in RedefineClasses for CP merge + + int operand_offset_at(int bootstrap_specifier_index) { + assert(0 <= bootstrap_specifier_index && + bootstrap_specifier_index < operand_array_length(operands()), + "Corrupted CP operands"); + return operand_offset_at(operands(), bootstrap_specifier_index); + } + int operand_bootstrap_method_ref_index_at(int bootstrap_specifier_index) { + int offset = operand_offset_at(bootstrap_specifier_index); + return operands()->short_at(offset + _indy_bsm_offset); + } + int operand_argument_count_at(int bootstrap_specifier_index) { + int offset = operand_offset_at(bootstrap_specifier_index); + int argc = operands()->short_at(offset + _indy_argc_offset); + return argc; + } + int operand_argument_index_at(int bootstrap_specifier_index, int j) { + int offset = operand_offset_at(bootstrap_specifier_index); + return operands()->short_at(offset + _indy_argv_offset + j); + } + int operand_next_offset_at(int bootstrap_specifier_index) { + int offset = operand_offset_at(bootstrap_specifier_index) + _indy_argv_offset + + operand_argument_count_at(bootstrap_specifier_index); + return offset; + } + // Compare a bootsrap specifier in the operands arrays + bool compare_operand_to(int bootstrap_specifier_index1, constantPoolHandle cp2, + int bootstrap_specifier_index2, TRAPS); + // Find a bootsrap specifier in the operands array + int find_matching_operand(int bootstrap_specifier_index, constantPoolHandle search_cp, + int operands_cur_len, TRAPS); + // Resize the operands array with delta_len and delta_size + void resize_operands(int delta_len, int delta_size, TRAPS); + // Extend the operands array with the length and size of the ext_cp operands + void extend_operands(constantPoolHandle ext_cp, TRAPS); + // Shrink the operands array to a smaller array with new_len length + void shrink_operands(int new_len, TRAPS); + + int invoke_dynamic_bootstrap_method_ref_index_at(int which) { assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); int op_base = invoke_dynamic_operand_base(which);
--- a/src/share/vm/oops/instanceKlass.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/oops/instanceKlass.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1901,6 +1901,17 @@ FreeHeap(jmeths); } + // Deallocate MemberNameTable + { + Mutex* lock_or_null = SafepointSynchronize::is_at_safepoint() ? NULL : MemberNameTable_lock; + MutexLockerEx ml(lock_or_null, Mutex::_no_safepoint_check_flag); + MemberNameTable* mnt = member_names(); + if (mnt != NULL) { + delete mnt; + set_member_names(NULL); + } + } + int* indices = methods_cached_itable_indices_acquire(); if (indices != (int*)NULL) { release_set_methods_cached_itable_indices(NULL); @@ -2333,6 +2344,30 @@ return NULL; } +void instanceKlass::add_member_name(int index, Handle mem_name) { + jweak mem_name_wref = JNIHandles::make_weak_global(mem_name); + MutexLocker ml(MemberNameTable_lock); + assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds"); + DEBUG_ONLY(No_Safepoint_Verifier nsv); + + if (_member_names == NULL) { + _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count()); + } + _member_names->add_member_name(index, mem_name_wref); +} + +oop instanceKlass::get_member_name(int index) { + MutexLocker ml(MemberNameTable_lock); + assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds"); + DEBUG_ONLY(No_Safepoint_Verifier nsv); + + if (_member_names == NULL) { + return NULL; + } + oop mem_name =_member_names->get_member_name(index); + return mem_name; +} + // ----------------------------------------------------------------------------------------------------- #ifndef PRODUCT
--- a/src/share/vm/oops/instanceKlass.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/oops/instanceKlass.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -94,6 +94,7 @@ class nmethodBucket; class PreviousVersionNode; class JvmtiCachedClassFieldMap; +class MemberNameTable; // This is used in iterators below. class FieldClosure: public StackObj { @@ -265,6 +266,7 @@ int _vtable_len; // length of Java vtable (in words) int _itable_len; // length of Java itable (in words) OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily) + MemberNameTable* _member_names; // Member names JNIid* _jni_ids; // First JNI identifier for static fields in this class jmethodID* _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none int* _methods_cached_itable_indices; // itable_index cache for JNI invoke corresponding to methods idnum, or NULL @@ -972,6 +974,12 @@ // jvm support jint compute_modifier_flags(TRAPS) const; + // JSR-292 support + MemberNameTable* member_names() { return _member_names; } + void set_member_names(MemberNameTable* member_names) { _member_names = member_names; } + void add_member_name(int index, Handle member_name); + oop get_member_name(int index); + public: // JVMTI support jint jvmti_class_status() const;
--- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,7 @@ #include "prims/jvmtiImpl.hpp" #include "prims/jvmtiRedefineClasses.hpp" #include "prims/methodComparator.hpp" +#include "prims/methodHandles.hpp" #include "runtime/deoptimization.hpp" #include "runtime/relocator.hpp" #include "utilities/bitMap.inline.hpp" @@ -391,20 +392,26 @@ // this is an indirect CP entry so it needs special handling case JVM_CONSTANT_InvokeDynamic: { - // TBD: cross-checks and possible extra appends into CP and bsm operands - // are needed as well. This issue is tracked by a separate bug 8007037. - int bss_idx = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i); - - int ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i); - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p, + // Index of the bootstrap specifier in the operands array + int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i); + int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p, + merge_cp_length_p, THREAD); + // The bootstrap method NameAndType_info index + int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i); + int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p, merge_cp_length_p, THREAD); - if (new_ref_i != ref_i) { + if (new_bs_i != old_bs_i) { RC_TRACE(0x00080000, - ("InvokeDynamic entry@%d name_and_type ref_index change: %d to %d", - *merge_cp_length_p, ref_i, new_ref_i)); + ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d", + *merge_cp_length_p, old_bs_i, new_bs_i)); } - - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, bss_idx, new_ref_i); + if (new_ref_i != old_ref_i) { + RC_TRACE(0x00080000, + ("InvokeDynamic entry@%d name_and_type_index change: %d to %d", + *merge_cp_length_p, old_ref_i, new_ref_i)); + } + + (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i); if (scratch_i != *merge_cp_length_p) { // The new entry in *merge_cp_p is at a different index than // the new entry in scratch_cp so we need to map the index values. @@ -469,6 +476,105 @@ } // end find_or_append_indirect_entry() +// Append a bootstrap specifier into the merge_cp operands that is semantically equal +// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index. +// Recursively append new merge_cp entries referenced by the new bootstrap specifier. +void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i, + constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) { + + int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i); + int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p, + merge_cp_length_p, THREAD); + if (new_ref_i != old_ref_i) { + RC_TRACE(0x00080000, + ("operands entry@%d bootstrap method ref_index change: %d to %d", + _operands_cur_length, old_ref_i, new_ref_i)); + } + + typeArrayOop merge_ops = (*merge_cp_p)->operands(); + int new_bs_i = _operands_cur_length; + // We have _operands_cur_length == 0 when the merge_cp operands is empty yet. + // However, the operand_offset_at(0) was set in the extend_operands() call. + int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0) + : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1); + int argc = scratch_cp->operand_argument_count_at(old_bs_i); + + constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base); + merge_ops->short_at_put(new_base++, new_ref_i); + merge_ops->short_at_put(new_base++, argc); + + for (int i = 0; i < argc; i++) { + int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i); + int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p, + merge_cp_length_p, THREAD); + merge_ops->short_at_put(new_base++, new_arg_ref_i); + if (new_arg_ref_i != old_arg_ref_i) { + RC_TRACE(0x00080000, + ("operands entry@%d bootstrap method argument ref_index change: %d to %d", + _operands_cur_length, old_arg_ref_i, new_arg_ref_i)); + } + } + if (old_bs_i != _operands_cur_length) { + // The bootstrap specifier in *merge_cp_p is at a different index than + // that in scratch_cp so we need to map the index values. + map_operand_index(old_bs_i, new_bs_i); + } + _operands_cur_length++; +} // end append_operand() + + +int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp, + int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) { + + int new_bs_i = old_bs_i; // bootstrap specifier index + bool match = (old_bs_i < _operands_cur_length) && + scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD); + + if (!match) { + // forward reference in *merge_cp_p or not a direct match + int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p, + _operands_cur_length, THREAD); + if (found_i != -1) { + guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree"); + // found a matching operand somewhere else in *merge_cp_p so just need a mapping + new_bs_i = found_i; + map_operand_index(old_bs_i, found_i); + } else { + // no match found so we have to append this bootstrap specifier to *merge_cp_p + append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD); + new_bs_i = _operands_cur_length - 1; + } + } + return new_bs_i; +} // end find_or_append_operand() + + +void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) { + if (merge_cp->operands() == NULL) { + return; + } + // Shrink the merge_cp operands + merge_cp->shrink_operands(_operands_cur_length, CHECK); + + if (RC_TRACE_ENABLED(0x00040000)) { + // don't want to loop unless we are tracing + int count = 0; + for (int i = 1; i < _operands_index_map_p->length(); i++) { + int value = _operands_index_map_p->at(i); + if (value != -1) { + RC_TRACE_WITH_THREAD(0x00040000, THREAD, + ("operands_index_map[%d]: old=%d new=%d", count, i, value)); + count++; + } + } + } + // Clean-up + _operands_index_map_p = NULL; + _operands_cur_length = 0; + _operands_index_map_count = 0; +} // end finalize_operands_merge() + + void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) { typeArrayOop save; @@ -754,6 +860,27 @@ } // end find_new_index() +// Find new bootstrap specifier index value for old bootstrap specifier index +// value by seaching the index map. Returns zero (-1) if there is no mapped +// value for the old bootstrap specifier index. +int VM_RedefineClasses::find_new_operand_index(int old_index) { + if (_operands_index_map_count == 0) { + // map is empty so nothing can be found + return -1; + } + + if (old_index == -1 || old_index >= _operands_index_map_p->length()) { + // The old_index is out of range so it is not mapped. + // This should not happen in regular constant pool merging use. + return -1; + } + + int value = _operands_index_map_p->at(old_index); + + return value; +} // end find_new_operand_index() + + // Returns true if the current mismatch is due to a resolved/unresolved // class pair. Otherwise, returns false. bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1, @@ -1019,6 +1146,25 @@ } // end map_index() +// Map old_index to new_index as needed. +void VM_RedefineClasses::map_operand_index(int old_index, int new_index) { + if (find_new_operand_index(old_index) != -1) { + // old_index is already mapped + return; + } + + if (old_index == new_index) { + // no mapping is needed + return; + } + + _operands_index_map_p->at_put(old_index, new_index); + _operands_index_map_count++; + + RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index)); +} // end map_index() + + // Merge old_cp and scratch_cp and return the results of the merge via // merge_cp_p. The number of entries in *merge_cp_p is returned via // merge_cp_length_p. The entries in old_cp occupy the same locations @@ -1091,6 +1237,7 @@ } // end for each old_cp entry constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0); + (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0); // We don't need to sanity check that *merge_cp_length_p is within // *merge_cp_p bounds since we have the minimum on-entry check above. @@ -1214,6 +1361,7 @@ ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d", *merge_cp_length_p, scratch_i, _index_map_count)); } + finalize_operands_merge(*merge_cp_p, THREAD); return true; } // end merge_constant_pools() @@ -1261,6 +1409,11 @@ _index_map_count = 0; _index_map_p = new intArray(scratch_cp->length(), -1); + _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands()); + _operands_index_map_count = 0; + _operands_index_map_p = new intArray( + constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1); + // reference to the cp holder is needed for copy_operands() merge_cp->set_pool_holder(scratch_class()); bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp, @@ -3294,6 +3447,16 @@ // that reference methods of the evolved class. SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD); + // JSR-292 support + MemberNameTable* mnt = the_class->member_names(); + if (mnt != NULL) { + bool trace_name_printed = false; + mnt->adjust_method_entries(_matching_old_methods, + _matching_new_methods, + _matching_methods_length, + &trace_name_printed); + } + if (the_class->oop_map_cache() != NULL) { // Flush references to any obsolete methods from the oop map cache // so that obsolete methods are not pinned.
--- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -370,6 +370,13 @@ // _index_map_p contains any entries. int _index_map_count; intArray * _index_map_p; + + // _operands_index_map_count is just an optimization for knowing if + // _operands_index_map_p contains any entries. + int _operands_cur_length; + int _operands_index_map_count; + intArray * _operands_index_map_p; + // ptr to _class_count scratch_classes instanceKlassHandle * _scratch_classes; jvmtiError _res; @@ -434,14 +441,21 @@ // Support for constant pool merging (these routines are in alpha order): void append_entry(constantPoolHandle scratch_cp, int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); + void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index, + constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); + void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS); int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); + int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index, + constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); int find_new_index(int old_index); + int find_new_operand_index(int old_bootstrap_spec_index); bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1, constantPoolHandle cp2, int index2); bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1, constantPoolHandle cp2, int index2); void map_index(constantPoolHandle scratch_cp, int old_index, int new_index); + void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index); bool merge_constant_pools(constantPoolHandle old_cp, constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
--- a/src/share/vm/prims/methodHandles.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/prims/methodHandles.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ #include "interpreter/oopMapCache.hpp" #include "memory/allocation.inline.hpp" #include "memory/oopFactory.hpp" +#include "prims/jvmtiRedefineClassesTrace.hpp" #include "prims/methodHandles.hpp" #include "runtime/compilationPolicy.hpp" #include "runtime/javaCalls.hpp" @@ -123,7 +124,9 @@ return Handle(THREAD, k->allocate_instance(THREAD)); } -oop MethodHandles::init_MemberName(oop mname_oop, oop target_oop) { +oop MethodHandles::init_MemberName(Handle mname, Handle target) { + Thread* thread = Thread::current(); + oop target_oop = target(); klassOop target_klass = target_oop->klass(); if (target_klass == SystemDictionary::reflect_Field_klass()) { oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder() @@ -131,24 +134,24 @@ int mods = java_lang_reflect_Field::modifiers(target_oop); oop type = java_lang_reflect_Field::type(target_oop); oop name = java_lang_reflect_Field::name(target_oop); - klassOop k = java_lang_Class::as_klassOop(clazz); - intptr_t offset = instanceKlass::cast(k)->field_offset(slot); - return init_field_MemberName(mname_oop, k, accessFlags_from(mods), type, name, offset); + KlassHandle k(thread, java_lang_Class::as_klassOop(clazz)); + intptr_t offset = instanceKlass::cast(k())->field_offset(slot); + return init_field_MemberName(mname, k, accessFlags_from(mods), type, name, offset); } else if (target_klass == SystemDictionary::reflect_Method_klass()) { oop clazz = java_lang_reflect_Method::clazz(target_oop); int slot = java_lang_reflect_Method::slot(target_oop); - klassOop k = java_lang_Class::as_klassOop(clazz); - if (k != NULL && Klass::cast(k)->oop_is_instance()) { - methodOop m = instanceKlass::cast(k)->method_with_idnum(slot); - return init_method_MemberName(mname_oop, m, true, k); + KlassHandle k(thread, java_lang_Class::as_klassOop(clazz)); + if (!k.is_null() && k->oop_is_instance()) { + methodOop m = instanceKlass::cast(k())->method_with_idnum(slot); + return init_method_MemberName(mname, m, true, k); } } else if (target_klass == SystemDictionary::reflect_Constructor_klass()) { oop clazz = java_lang_reflect_Constructor::clazz(target_oop); int slot = java_lang_reflect_Constructor::slot(target_oop); - klassOop k = java_lang_Class::as_klassOop(clazz); - if (k != NULL && Klass::cast(k)->oop_is_instance()) { - methodOop m = instanceKlass::cast(k)->method_with_idnum(slot); - return init_method_MemberName(mname_oop, m, false, k); + KlassHandle k(thread, java_lang_Class::as_klassOop(clazz)); + if (!k.is_null() && k->oop_is_instance()) { + methodOop m = instanceKlass::cast(k())->method_with_idnum(slot); + return init_method_MemberName(mname, m, false, k); } } else if (target_klass == SystemDictionary::MemberName_klass()) { // Note: This only works if the MemberName has already been resolved. @@ -156,17 +159,18 @@ int flags = java_lang_invoke_MemberName::flags(target_oop); oop vmtarget = java_lang_invoke_MemberName::vmtarget(target_oop); intptr_t vmindex = java_lang_invoke_MemberName::vmindex(target_oop); - klassOop k = java_lang_Class::as_klassOop(clazz); + KlassHandle k(thread, java_lang_Class::as_klassOop(clazz)); int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK; if (vmtarget == NULL) return NULL; // not resolved if ((flags & IS_FIELD) != 0) { assert(vmtarget->is_klass(), "field vmtarget is klassOop"); int basic_mods = (ref_kind_is_static(ref_kind) ? JVM_ACC_STATIC : 0); // FIXME: how does k (receiver_limit) contribute? - return init_field_MemberName(mname_oop, klassOop(vmtarget), accessFlags_from(basic_mods), NULL, NULL, vmindex); + KlassHandle k_vmtarget(thread, klassOop(vmtarget)); + return init_field_MemberName(mname, k_vmtarget, accessFlags_from(basic_mods), NULL, NULL, vmindex); } else if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) { assert(vmtarget->is_method(), "method or constructor vmtarget is methodOop"); - return init_method_MemberName(mname_oop, methodOop(vmtarget), ref_kind_does_dispatch(ref_kind), k); + return init_method_MemberName(mname, methodOop(vmtarget), ref_kind_does_dispatch(ref_kind), k); } else { return NULL; } @@ -174,8 +178,9 @@ return NULL; } -oop MethodHandles::init_method_MemberName(oop mname_oop, methodOop m, bool do_dispatch, - klassOop resolved_klass) { +oop MethodHandles::init_method_MemberName(Handle mname, methodOop m, bool do_dispatch, + KlassHandle resolved_klass_h) { + klassOop resolved_klass = resolved_klass_h(); AccessFlags mods = m->access_flags(); int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); int vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch @@ -235,6 +240,7 @@ } } + oop mname_oop = mname(); java_lang_invoke_MemberName::set_flags(mname_oop, flags); java_lang_invoke_MemberName::set_vmtarget(mname_oop, m); java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); // vtable/itable index @@ -246,11 +252,12 @@ // If relevant, the vtable or itable value is stored as vmindex. // This is done eagerly, since it is readily available without // constructing any new objects. - // TO DO: maybe intern mname_oop - return mname_oop; + instanceKlass::cast(m->method_holder())->add_member_name(m->method_idnum(), mname); + + return mname(); } -Handle MethodHandles::init_method_MemberName(oop mname_oop, CallInfo& info, TRAPS) { +Handle MethodHandles::init_method_MemberName(Handle mname, CallInfo& info, TRAPS) { Handle empty; if (info.resolved_appendix().not_null()) { // The resolved MemberName must not be accompanied by an appendix argument, @@ -270,23 +277,24 @@ } else { vmindex = info.vtable_index(); } - oop res = init_method_MemberName(mname_oop, m(), (vmindex >= 0), defc()); + oop res = init_method_MemberName(mname, m(), (vmindex >= 0), defc()); assert(res == NULL || (java_lang_invoke_MemberName::vmindex(res) == vmindex), ""); return Handle(THREAD, res); } -oop MethodHandles::init_field_MemberName(oop mname_oop, klassOop field_holder, +oop MethodHandles::init_field_MemberName(Handle mname, KlassHandle field_holder, AccessFlags mods, oop type, oop name, intptr_t offset, bool is_setter) { int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ); flags |= IS_FIELD | ((mods.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT); if (is_setter) flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT); - oop vmtarget = field_holder; + oop vmtarget = field_holder(); int vmindex = offset; // determines the field uniquely when combined with static bit + oop mname_oop = mname(); java_lang_invoke_MemberName::set_flags(mname_oop, flags); java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); - java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); + java_lang_invoke_MemberName::set_clazz(mname_oop, field_holder()->java_mirror()); if (name != NULL) java_lang_invoke_MemberName::set_name(mname_oop, name); if (type != NULL) @@ -298,11 +306,10 @@ // because they unambiguously identify the field. // Although the fieldDescriptor::_index would also identify the field, // we do not use it, because it is harder to decode. - // TO DO: maybe intern mname_oop - return mname_oop; + return mname(); } -Handle MethodHandles::init_field_MemberName(oop mname_oop, FieldAccessInfo& info, TRAPS) { +Handle MethodHandles::init_field_MemberName(Handle mname, FieldAccessInfo& info, TRAPS) { return Handle(); #if 0 KlassHandle field_holder = info.klass(); @@ -728,7 +735,7 @@ return empty; } } - return init_method_MemberName(mname(), result, THREAD); + return init_method_MemberName(mname, result, THREAD); } case IS_CONSTRUCTOR: { @@ -746,7 +753,7 @@ } } assert(result.is_statically_bound(), ""); - return init_method_MemberName(mname(), result, THREAD); + return init_method_MemberName(mname, result, THREAD); } case IS_FIELD: { @@ -759,7 +766,7 @@ oop name = field_name_or_null(fd.name()); bool is_setter = (ref_kind_is_valid(ref_kind) && ref_kind_is_setter(ref_kind)); mname = Handle(THREAD, - init_field_MemberName(mname(), sel_klass->as_klassOop(), + init_field_MemberName(mname, sel_klass, fd.access_flags(), type, name, fd.offset(), is_setter)); return mname; } @@ -851,16 +858,16 @@ THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); } -int MethodHandles::find_MemberNames(klassOop k, +int MethodHandles::find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, - int mflags, klassOop caller, - int skip, objArrayOop results) { - DEBUG_ONLY(No_Safepoint_Verifier nsv); - // this code contains no safepoints! + int mflags, KlassHandle caller, + int skip, objArrayHandle results) { // %%% take caller into account! - if (k == NULL || !Klass::cast(k)->oop_is_instance()) return -1; + Thread* thread = Thread::current(); + + if (k.is_null() || !k->oop_is_instance()) return -1; int rfill = 0, rlimit = results->length(), rskip = skip; // overflow measurement: @@ -888,7 +895,7 @@ } if ((match_flags & IS_FIELD) != 0) { - for (FieldStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { + for (FieldStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) { if (name != NULL && st.name() != name) continue; if (sig != NULL && st.signature() != sig) @@ -897,15 +904,15 @@ if (rskip > 0) { --rskip; } else if (rfill < rlimit) { - oop result = results->obj_at(rfill++); - if (!java_lang_invoke_MemberName::is_instance(result)) + Handle result(thread, results->obj_at(rfill++)); + if (!java_lang_invoke_MemberName::is_instance(result())) return -99; // caller bug! oop type = field_signature_type_or_null(st.signature()); oop name = field_name_or_null(st.name()); - oop saved = MethodHandles::init_field_MemberName(result, st.klass()->as_klassOop(), + oop saved = MethodHandles::init_field_MemberName(result, st.klass(), st.access_flags(), type, name, st.offset()); - if (saved != result) + if (saved != result()) results->obj_at_put(rfill-1, saved); // show saved instance to user } else if (++overflow >= overflow_limit) { match_flags = 0; break; // got tired of looking at overflow @@ -938,7 +945,7 @@ } else { // caller will accept either sort; no need to adjust name } - for (MethodStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { + for (MethodStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) { methodOop m = st.method(); Symbol* m_name = m->name(); if (m_name == clinit_name) @@ -951,11 +958,11 @@ if (rskip > 0) { --rskip; } else if (rfill < rlimit) { - oop result = results->obj_at(rfill++); - if (!java_lang_invoke_MemberName::is_instance(result)) + Handle result(thread, results->obj_at(rfill++)); + if (!java_lang_invoke_MemberName::is_instance(result())) return -99; // caller bug! - oop saved = MethodHandles::init_method_MemberName(result, m, true, NULL); - if (saved != result) + oop saved = MethodHandles::init_method_MemberName(result, m, true, KlassHandle()); + if (saved != result()) results->obj_at_put(rfill-1, saved); // show saved instance to user } else if (++overflow >= overflow_limit) { match_flags = 0; break; // got tired of looking at overflow @@ -967,6 +974,85 @@ return rfill + overflow; } +//------------------------------------------------------------------------------ +// MemberNameTable +// + +MemberNameTable::MemberNameTable(int methods_cnt) + : GrowableArray<jweak>(methods_cnt, true) { + assert_locked_or_safepoint(MemberNameTable_lock); +} + +MemberNameTable::~MemberNameTable() { + assert_locked_or_safepoint(MemberNameTable_lock); + int len = this->length(); + + for (int idx = 0; idx < len; idx++) { + jweak ref = this->at(idx); + JNIHandles::destroy_weak_global(ref); + } +} + +void MemberNameTable::add_member_name(int index, jweak mem_name_wref) { + assert_locked_or_safepoint(MemberNameTable_lock); + this->at_put_grow(index, mem_name_wref); +} + +// Return a member name oop or NULL. +oop MemberNameTable::get_member_name(int index) { + assert_locked_or_safepoint(MemberNameTable_lock); + jweak ref = this->at(index); + oop mem_name = JNIHandles::resolve(ref); + return mem_name; +} + +oop MemberNameTable::find_member_name_by_method(methodOop old_method) { + assert_locked_or_safepoint(MemberNameTable_lock); + oop found = NULL; + int len = this->length(); + + for (int idx = 0; idx < len; idx++) { + oop mem_name = JNIHandles::resolve(this->at(idx)); + if (mem_name == NULL) { + continue; + } + methodOop method = (methodOop)java_lang_invoke_MemberName::vmtarget(mem_name); + if (method == old_method) { + found = mem_name; + break; + } + } + return found; +} + +// It is called at safepoint only +void MemberNameTable::adjust_method_entries(methodOop* old_methods, methodOop* new_methods, + int methods_length, bool *trace_name_printed) { + assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint"); + // search the MemberNameTable for uses of either obsolete or EMCP methods + for (int j = 0; j < methods_length; j++) { + methodOop old_method = old_methods[j]; + methodOop new_method = new_methods[j]; + oop mem_name = find_member_name_by_method(old_method); + if (mem_name != NULL) { + java_lang_invoke_MemberName::adjust_vmtarget(mem_name, new_method); + + if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { + if (!(*trace_name_printed)) { + // RC_TRACE_MESG macro has an embedded ResourceMark + RC_TRACE_MESG(("adjust: name=%s", + Klass::cast(old_method->method_holder())->external_name())); + *trace_name_printed = true; + } + // RC_TRACE macro has an embedded ResourceMark + RC_TRACE(0x00400000, ("MemberName method update: %s(%s)", + new_method->name()->as_C_string(), + new_method->signature()->as_C_string())); + } + } + } +} + // // Here are the native methods in java.lang.invoke.MethodHandleNatives // They are the private interface between this JVM and the HotSpot-specific @@ -1058,8 +1144,8 @@ if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); } if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); } Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); - oop target_oop = JNIHandles::resolve_non_null(target_jh); - MethodHandles::init_MemberName(mname(), target_oop); + Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); + MethodHandles::init_MemberName(mname, target); } JVM_END @@ -1174,11 +1260,12 @@ } else if (vmtarget->is_klass()) { x = Klass::cast((klassOop) vmtarget())->java_mirror(); } else { - Handle mname2 = MethodHandles::new_MemberName(CHECK_NULL); - if (vmtarget->is_method()) - x = MethodHandles::init_method_MemberName(mname2(), methodOop(vmtarget()), false, NULL); - else + if (vmtarget->is_method()) { + x = mname(); + } else { + Handle mname2 = MethodHandles::new_MemberName(CHECK_NULL); x = MethodHandles::init_MemberName(mname2(), vmtarget()); + } } result->obj_at_put(1, x); return JNIHandles::make_local(env, result()); @@ -1221,8 +1308,8 @@ // %%% TO DO } - int res = MethodHandles::find_MemberNames(k(), name, sig, mflags, - caller(), skip, results()); + int res = MethodHandles::find_MemberNames(k, name, sig, mflags, + caller, skip, results); // TO DO: expand at least some of the MemberNames, to avoid massive callbacks return res; }
--- a/src/share/vm/prims/methodHandles.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/prims/methodHandles.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,7 +39,6 @@ // in java.lang.invoke and sun.invoke. // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}. public: - public: static bool enabled() { return _enabled; } static void set_enabled(bool z); @@ -54,18 +53,18 @@ static Handle resolve_MemberName(Handle mname, KlassHandle caller, TRAPS); // compute vmtarget/vmindex from name/type static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing static Handle new_MemberName(TRAPS); // must be followed by init_MemberName - static oop init_MemberName(oop mname_oop, oop target_oop); // compute vmtarget/vmindex from target - static oop init_method_MemberName(oop mname_oop, methodOop m, bool do_dispatch, - klassOop resolved_klass); - static oop init_field_MemberName(oop mname_oop, klassOop field_holder, + static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target + static oop init_method_MemberName(Handle mname_h, methodOop m, bool do_dispatch, + KlassHandle resolved_klass_h); + static oop init_field_MemberName(Handle mname_h, KlassHandle field_holder_h, AccessFlags mods, oop type, oop name, intptr_t offset, bool is_setter = false); - static Handle init_method_MemberName(oop mname_oop, CallInfo& info, TRAPS); - static Handle init_field_MemberName(oop mname_oop, FieldAccessInfo& info, TRAPS); + static Handle init_method_MemberName(Handle mname_h, CallInfo& info, TRAPS); + static Handle init_field_MemberName(Handle mname_h, FieldAccessInfo& info, TRAPS); static int method_ref_kind(methodOop m, bool do_dispatch_if_possible = true); - static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig, - int mflags, klassOop caller, - int skip, objArrayOop results); + static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, + int mflags, KlassHandle caller, + int skip, objArrayHandle results); // bit values for suppress argument to expand_MemberName: enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; @@ -230,4 +229,26 @@ void generate(); }; +//------------------------------------------------------------------------------ +// MemberNameTable +// + +class MemberNameTable : public GrowableArray<jweak> { + public: + MemberNameTable(int methods_cnt); + ~MemberNameTable(); + + void add_member_name(int index, jweak mem_name_ref); + oop get_member_name(int index); + + public: + // RedefineClasses() API support: + // If a MemberName refers to old_method then update it + // to refer to new_method. + void adjust_method_entries(methodOop* old_methods, methodOop* new_methods, + int methods_length, bool *trace_name_printed); + private: + oop find_member_name_by_method(methodOop old_method); +}; + #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP
--- a/src/share/vm/runtime/mutexLocker.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/runtime/mutexLocker.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,6 +57,7 @@ Mutex* JNIGlobalHandle_lock = NULL; Mutex* JNIHandleBlockFreeList_lock = NULL; Mutex* JNICachedItableIndex_lock = NULL; +Mutex* MemberNameTable_lock = NULL; Mutex* JmethodIdCreation_lock = NULL; Mutex* JfieldIdCreation_lock = NULL; Monitor* JNICritical_lock = NULL; @@ -263,6 +264,7 @@ def(Heap_lock , Monitor, nonleaf+1, false); def(JfieldIdCreation_lock , Mutex , nonleaf+1, true ); // jfieldID, Used in VM_Operation def(JNICachedItableIndex_lock , Mutex , nonleaf+1, false); // Used to cache an itable index during JNI invoke + def(MemberNameTable_lock , Mutex , nonleaf+1, false); // Used to protect MemberNameTable def(CompiledIC_lock , Mutex , nonleaf+2, false); // locks VtableStubs_lock, InlineCacheBuffer_lock def(CompileTaskAlloc_lock , Mutex , nonleaf+2, true );
--- a/src/share/vm/runtime/mutexLocker.hpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/runtime/mutexLocker.hpp Tue Feb 25 23:18:36 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,6 +51,7 @@ extern Mutex* JNIGlobalHandle_lock; // a lock on creating JNI global handles extern Mutex* JNIHandleBlockFreeList_lock; // a lock on the JNI handle block free list extern Mutex* JNICachedItableIndex_lock; // a lock on caching an itable index during JNI invoke +extern Mutex* MemberNameTable_lock; // a lock on the MemberNameTable updates extern Mutex* JmethodIdCreation_lock; // a lock on creating JNI method identifiers extern Mutex* JfieldIdCreation_lock; // a lock on creating JNI static field identifiers extern Monitor* JNICritical_lock; // a lock used while entering and exiting JNI critical regions, allows GC to sometimes get in
--- a/src/share/vm/runtime/thread.cpp Thu Feb 20 15:09:32 2014 -0800 +++ b/src/share/vm/runtime/thread.cpp Tue Feb 25 23:18:36 2014 -0800 @@ -3505,11 +3505,12 @@ java_lang_Thread::set_thread_status(thread_object, java_lang_Thread::RUNNABLE); - // The VM preresolve methods to these classes. Make sure that get initialized + // The VM creates & returns objects of this class. Make sure it's initialized. + initialize_class(vmSymbols::java_lang_Class(), CHECK_0); + + // The VM preresolves methods to these classes. Make sure that they get initialized initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0); initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0); - // The VM creates & returns objects of this class. Make sure it's initialized. - initialize_class(vmSymbols::java_lang_Class(), CHECK_0); call_initializeSystemClass(CHECK_0); // get the Java runtime name after java.lang.System is initialized