2748 vmSymbols::linkMethodHandleConstant_signature(), |
2748 vmSymbols::linkMethodHandleConstant_signature(), |
2749 &args, CHECK_(empty)); |
2749 &args, CHECK_(empty)); |
2750 return Handle(THREAD, (oop) result.get_jobject()); |
2750 return Handle(THREAD, (oop) result.get_jobject()); |
2751 } |
2751 } |
2752 |
2752 |
2753 // Ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry |
2753 // Ask Java to run a bootstrap method, in order to create a dynamic call site |
2754 Handle SystemDictionary::link_dynamic_constant(Klass* caller, |
2754 // while linking an invokedynamic op, or compute a constant for Dynamic_info CP entry |
2755 int condy_index, |
2755 // with linkage results being stored back into the bootstrap specifier. |
2756 Handle bootstrap_specifier, |
2756 void SystemDictionary::invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS) { |
2757 Symbol* name, |
2757 // Resolve the bootstrap specifier, its name, type, and static arguments |
2758 Symbol* type, |
2758 bootstrap_specifier.resolve_bsm(CHECK); |
2759 TRAPS) { |
|
2760 Handle empty; |
|
2761 Handle bsm, info; |
|
2762 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
|
2763 bsm = bootstrap_specifier; |
|
2764 } else { |
|
2765 assert(bootstrap_specifier->is_objArray(), ""); |
|
2766 objArrayOop args = (objArrayOop) bootstrap_specifier(); |
|
2767 assert(args->length() == 2, ""); |
|
2768 bsm = Handle(THREAD, args->obj_at(0)); |
|
2769 info = Handle(THREAD, args->obj_at(1)); |
|
2770 } |
|
2771 guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()), |
|
2772 "caller must supply a valid BSM"); |
|
2773 |
2759 |
2774 // This should not happen. JDK code should take care of that. |
2760 // This should not happen. JDK code should take care of that. |
2775 if (caller == NULL) { |
2761 if (bootstrap_specifier.caller() == NULL || bootstrap_specifier.type_arg().is_null()) { |
2776 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad dynamic constant", empty); |
2762 THROW_MSG(vmSymbols::java_lang_InternalError(), "Invalid bootstrap method invocation with no caller or type argument"); |
2777 } |
2763 } |
2778 |
2764 |
2779 Handle constant_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
2765 bool is_indy = bootstrap_specifier.is_method_call(); |
2780 |
2766 objArrayHandle appendix_box; |
2781 // Resolve the constant type in the context of the caller class |
2767 if (is_indy) { |
2782 Handle type_mirror = find_java_mirror_for_type(type, caller, SignatureStream::NCDFError, |
2768 // Some method calls may require an appendix argument. Arrange to receive it. |
2783 CHECK_(empty)); |
2769 appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK); |
2784 |
2770 assert(appendix_box->obj_at(0) == NULL, ""); |
2785 // call java.lang.invoke.MethodHandleNatives::linkConstantDyanmic(caller, condy_index, bsm, type, info) |
2771 } |
|
2772 |
|
2773 // call condy: java.lang.invoke.MethodHandleNatives::linkDynamicConstant(caller, condy_index, bsm, type, info) |
|
2774 // indy: java.lang.invoke.MethodHandleNatives::linkCallSite(caller, indy_index, bsm, name, mtype, info, &appendix) |
2786 JavaCallArguments args; |
2775 JavaCallArguments args; |
2787 args.push_oop(Handle(THREAD, caller->java_mirror())); |
2776 args.push_oop(Handle(THREAD, bootstrap_specifier.caller_mirror())); |
2788 args.push_int(condy_index); |
2777 args.push_int(bootstrap_specifier.bss_index()); |
2789 args.push_oop(bsm); |
2778 args.push_oop(bootstrap_specifier.bsm()); |
2790 args.push_oop(constant_name); |
2779 args.push_oop(bootstrap_specifier.name_arg()); |
2791 args.push_oop(type_mirror); |
2780 args.push_oop(bootstrap_specifier.type_arg()); |
2792 args.push_oop(info); |
2781 args.push_oop(bootstrap_specifier.arg_values()); |
|
2782 if (is_indy) { |
|
2783 args.push_oop(appendix_box); |
|
2784 } |
2793 JavaValue result(T_OBJECT); |
2785 JavaValue result(T_OBJECT); |
2794 JavaCalls::call_static(&result, |
2786 JavaCalls::call_static(&result, |
2795 SystemDictionary::MethodHandleNatives_klass(), |
2787 SystemDictionary::MethodHandleNatives_klass(), |
2796 vmSymbols::linkDynamicConstant_name(), |
2788 is_indy ? vmSymbols::linkCallSite_name() : vmSymbols::linkDynamicConstant_name(), |
2797 vmSymbols::linkDynamicConstant_signature(), |
2789 is_indy ? vmSymbols::linkCallSite_signature() : vmSymbols::linkDynamicConstant_signature(), |
2798 &args, CHECK_(empty)); |
2790 &args, CHECK); |
2799 |
2791 |
2800 return Handle(THREAD, (oop) result.get_jobject()); |
2792 Handle value(THREAD, (oop) result.get_jobject()); |
2801 } |
2793 if (is_indy) { |
2802 |
2794 Handle appendix; |
2803 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given |
2795 methodHandle method = unpack_method_and_appendix(value, |
2804 // name and signature, as interpreted relative to the given class loader. |
2796 bootstrap_specifier.caller(), |
2805 methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller, |
2797 appendix_box, |
2806 int indy_index, |
2798 &appendix, CHECK); |
2807 Handle bootstrap_specifier, |
2799 bootstrap_specifier.set_resolved_method(method, appendix); |
2808 Symbol* name, |
|
2809 Symbol* type, |
|
2810 Handle *appendix_result, |
|
2811 TRAPS) { |
|
2812 methodHandle empty; |
|
2813 Handle bsm, info; |
|
2814 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
|
2815 bsm = bootstrap_specifier; |
|
2816 } else { |
2800 } else { |
2817 objArrayOop args = (objArrayOop) bootstrap_specifier(); |
2801 bootstrap_specifier.set_resolved_value(value); |
2818 assert(args->length() == 2, ""); |
2802 } |
2819 bsm = Handle(THREAD, args->obj_at(0)); |
2803 |
2820 info = Handle(THREAD, args->obj_at(1)); |
2804 // sanity check |
2821 } |
2805 assert(bootstrap_specifier.is_resolved() || |
2822 guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()), |
2806 (bootstrap_specifier.is_method_call() && |
2823 "caller must supply a valid BSM"); |
2807 bootstrap_specifier.resolved_method().not_null()), "bootstrap method call failed"); |
2824 |
|
2825 Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
|
2826 Handle method_type = find_method_handle_type(type, caller, CHECK_(empty)); |
|
2827 |
|
2828 // This should not happen. JDK code should take care of that. |
|
2829 if (caller == NULL || method_type.is_null()) { |
|
2830 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty); |
|
2831 } |
|
2832 |
|
2833 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
|
2834 assert(appendix_box->obj_at(0) == NULL, ""); |
|
2835 |
|
2836 // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, indy_index, bsm, name, mtype, info, &appendix) |
|
2837 JavaCallArguments args; |
|
2838 args.push_oop(Handle(THREAD, caller->java_mirror())); |
|
2839 args.push_int(indy_index); |
|
2840 args.push_oop(bsm); |
|
2841 args.push_oop(method_name); |
|
2842 args.push_oop(method_type); |
|
2843 args.push_oop(info); |
|
2844 args.push_oop(appendix_box); |
|
2845 JavaValue result(T_OBJECT); |
|
2846 JavaCalls::call_static(&result, |
|
2847 SystemDictionary::MethodHandleNatives_klass(), |
|
2848 vmSymbols::linkCallSite_name(), |
|
2849 vmSymbols::linkCallSite_signature(), |
|
2850 &args, CHECK_(empty)); |
|
2851 Handle mname(THREAD, (oop) result.get_jobject()); |
|
2852 return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD); |
|
2853 } |
2808 } |
2854 |
2809 |
2855 // Protection domain cache table handling |
2810 // Protection domain cache table handling |
2856 |
2811 |
2857 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) { |
2812 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) { |