2639 return klass->is_public() && |
2639 return klass->is_public() && |
2640 (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) || // java.lang |
2640 (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) || // java.lang |
2641 InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass())); // java.lang.invoke |
2641 InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass())); // java.lang.invoke |
2642 } |
2642 } |
2643 |
2643 |
|
2644 |
|
2645 // Return the Java mirror (java.lang.Class instance) for a single-character |
|
2646 // descriptor. This result, when available, is the same as produced by the |
|
2647 // heavier API point of the same name that takes a Symbol. |
|
2648 oop SystemDictionary::find_java_mirror_for_type(char signature_char) { |
|
2649 return java_lang_Class::primitive_mirror(char2type(signature_char)); |
|
2650 } |
|
2651 |
|
2652 // Find or construct the Java mirror (java.lang.Class instance) for a |
|
2653 // for the given field type signature, as interpreted relative to the |
|
2654 // given class loader. Handles primitives, void, references, arrays, |
|
2655 // and all other reflectable types, except method types. |
|
2656 // N.B. Code in reflection should use this entry point. |
|
2657 Handle SystemDictionary::find_java_mirror_for_type(Symbol* signature, |
|
2658 Klass* accessing_klass, |
|
2659 Handle class_loader, |
|
2660 Handle protection_domain, |
|
2661 SignatureStream::FailureMode failure_mode, |
|
2662 TRAPS) { |
|
2663 Handle empty; |
|
2664 |
|
2665 assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()), |
|
2666 "one or the other, or perhaps neither"); |
|
2667 |
|
2668 Symbol* type = signature; |
|
2669 |
|
2670 // What we have here must be a valid field descriptor, |
|
2671 // and all valid field descriptors are supported. |
|
2672 // Produce the same java.lang.Class that reflection reports. |
|
2673 if (type->utf8_length() == 1) { |
|
2674 |
|
2675 // It's a primitive. (Void has a primitive mirror too.) |
|
2676 char ch = (char) type->byte_at(0); |
|
2677 assert(is_java_primitive(char2type(ch)) || ch == 'V', ""); |
|
2678 return Handle(THREAD, find_java_mirror_for_type(ch)); |
|
2679 |
|
2680 } else if (FieldType::is_obj(type) || FieldType::is_array(type)) { |
|
2681 |
|
2682 // It's a reference type. |
|
2683 if (accessing_klass != NULL) { |
|
2684 class_loader = Handle(THREAD, accessing_klass->class_loader()); |
|
2685 protection_domain = Handle(THREAD, accessing_klass->protection_domain()); |
|
2686 } |
|
2687 Klass* constant_type_klass; |
|
2688 if (failure_mode == SignatureStream::ReturnNull) { |
|
2689 constant_type_klass = resolve_or_null(type, class_loader, protection_domain, |
|
2690 CHECK_(empty)); |
|
2691 } else { |
|
2692 bool throw_error = (failure_mode == SignatureStream::NCDFError); |
|
2693 constant_type_klass = resolve_or_fail(type, class_loader, protection_domain, |
|
2694 throw_error, CHECK_(empty)); |
|
2695 } |
|
2696 if (constant_type_klass == NULL) { |
|
2697 return Handle(); // report failure this way |
|
2698 } |
|
2699 Handle mirror(THREAD, constant_type_klass->java_mirror()); |
|
2700 |
|
2701 // Check accessibility, emulating ConstantPool::verify_constant_pool_resolve. |
|
2702 if (accessing_klass != NULL) { |
|
2703 Klass* sel_klass = constant_type_klass; |
|
2704 bool fold_type_to_class = true; |
|
2705 LinkResolver::check_klass_accessability(accessing_klass, sel_klass, |
|
2706 fold_type_to_class, CHECK_(empty)); |
|
2707 } |
|
2708 |
|
2709 return mirror; |
|
2710 |
|
2711 } |
|
2712 |
|
2713 // Fall through to an error. |
|
2714 assert(false, "unsupported mirror syntax"); |
|
2715 THROW_MSG_(vmSymbols::java_lang_InternalError(), "unsupported mirror syntax", empty); |
|
2716 } |
|
2717 |
|
2718 |
2644 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given |
2719 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given |
2645 // signature, as interpreted relative to the given class loader. |
2720 // signature, as interpreted relative to the given class loader. |
2646 // Because of class loader constraints, all method handle usage must be |
2721 // Because of class loader constraints, all method handle usage must be |
2647 // consistent with this loader. |
2722 // consistent with this loader. |
2648 Handle SystemDictionary::find_method_handle_type(Symbol* signature, |
2723 Handle SystemDictionary::find_method_handle_type(Symbol* signature, |
2693 rt = Handle(THREAD, mirror); |
2768 rt = Handle(THREAD, mirror); |
2694 else |
2769 else |
2695 pts->obj_at_put(arg++, mirror); |
2770 pts->obj_at_put(arg++, mirror); |
2696 |
2771 |
2697 // Check accessibility. |
2772 // Check accessibility. |
2698 if (ss.is_object() && accessing_klass != NULL) { |
2773 if (!java_lang_Class::is_primitive(mirror) && accessing_klass != NULL) { |
2699 Klass* sel_klass = java_lang_Class::as_Klass(mirror); |
2774 Klass* sel_klass = java_lang_Class::as_Klass(mirror); |
2700 mirror = NULL; // safety |
2775 mirror = NULL; // safety |
2701 // Emulate ConstantPool::verify_constant_pool_resolve. |
2776 // Emulate ConstantPool::verify_constant_pool_resolve. |
2702 if (sel_klass->is_objArray_klass()) |
2777 bool fold_type_to_class = true; |
2703 sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass(); |
2778 LinkResolver::check_klass_accessability(accessing_klass, sel_klass, |
2704 if (sel_klass->is_instance_klass()) { |
2779 fold_type_to_class, CHECK_(empty)); |
2705 LinkResolver::check_klass_accessability(accessing_klass, sel_klass, CHECK_(empty)); |
|
2706 } |
|
2707 } |
2780 } |
2708 } |
2781 } |
2709 assert(arg == npts, ""); |
2782 assert(arg == npts, ""); |
2710 |
2783 |
2711 // call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType |
2784 // call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType |
2804 vmSymbols::linkMethodHandleConstant_signature(), |
2877 vmSymbols::linkMethodHandleConstant_signature(), |
2805 &args, CHECK_(empty)); |
2878 &args, CHECK_(empty)); |
2806 return Handle(THREAD, (oop) result.get_jobject()); |
2879 return Handle(THREAD, (oop) result.get_jobject()); |
2807 } |
2880 } |
2808 |
2881 |
|
2882 // Ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry |
|
2883 Handle SystemDictionary::link_dynamic_constant(Klass* caller, |
|
2884 int condy_index, |
|
2885 Handle bootstrap_specifier, |
|
2886 Symbol* name, |
|
2887 Symbol* type, |
|
2888 TRAPS) { |
|
2889 Handle empty; |
|
2890 Handle bsm, info; |
|
2891 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
|
2892 bsm = bootstrap_specifier; |
|
2893 } else { |
|
2894 assert(bootstrap_specifier->is_objArray(), ""); |
|
2895 objArrayOop args = (objArrayOop) bootstrap_specifier(); |
|
2896 assert(args->length() == 2, ""); |
|
2897 bsm = Handle(THREAD, args->obj_at(0)); |
|
2898 info = Handle(THREAD, args->obj_at(1)); |
|
2899 } |
|
2900 guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()), |
|
2901 "caller must supply a valid BSM"); |
|
2902 |
|
2903 // This should not happen. JDK code should take care of that. |
|
2904 if (caller == NULL) { |
|
2905 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad dynamic constant", empty); |
|
2906 } |
|
2907 |
|
2908 Handle constant_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
|
2909 |
|
2910 // Resolve the constant type in the context of the caller class |
|
2911 Handle type_mirror = find_java_mirror_for_type(type, caller, SignatureStream::NCDFError, |
|
2912 CHECK_(empty)); |
|
2913 |
|
2914 // call java.lang.invoke.MethodHandleNatives::linkConstantDyanmic(caller, condy_index, bsm, type, info) |
|
2915 JavaCallArguments args; |
|
2916 args.push_oop(Handle(THREAD, caller->java_mirror())); |
|
2917 args.push_int(condy_index); |
|
2918 args.push_oop(bsm); |
|
2919 args.push_oop(constant_name); |
|
2920 args.push_oop(type_mirror); |
|
2921 args.push_oop(info); |
|
2922 JavaValue result(T_OBJECT); |
|
2923 JavaCalls::call_static(&result, |
|
2924 SystemDictionary::MethodHandleNatives_klass(), |
|
2925 vmSymbols::linkDynamicConstant_name(), |
|
2926 vmSymbols::linkDynamicConstant_signature(), |
|
2927 &args, CHECK_(empty)); |
|
2928 |
|
2929 return Handle(THREAD, (oop) result.get_jobject()); |
|
2930 } |
|
2931 |
2809 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given |
2932 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given |
2810 // name and signature, as interpreted relative to the given class loader. |
2933 // name and signature, as interpreted relative to the given class loader. |
2811 methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller, |
2934 methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller, |
|
2935 int indy_index, |
2812 Handle bootstrap_specifier, |
2936 Handle bootstrap_specifier, |
2813 Symbol* name, |
2937 Symbol* name, |
2814 Symbol* type, |
2938 Symbol* type, |
2815 Handle *appendix_result, |
2939 Handle *appendix_result, |
2816 Handle *method_type_result, |
2940 Handle *method_type_result, |
2818 methodHandle empty; |
2942 methodHandle empty; |
2819 Handle bsm, info; |
2943 Handle bsm, info; |
2820 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
2944 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
2821 bsm = bootstrap_specifier; |
2945 bsm = bootstrap_specifier; |
2822 } else { |
2946 } else { |
2823 assert(bootstrap_specifier->is_objArray(), ""); |
2947 objArrayOop args = (objArrayOop) bootstrap_specifier(); |
2824 objArrayHandle args(THREAD, (objArrayOop) bootstrap_specifier()); |
2948 assert(args->length() == 2, ""); |
2825 int len = args->length(); |
2949 bsm = Handle(THREAD, args->obj_at(0)); |
2826 assert(len >= 1, ""); |
2950 info = Handle(THREAD, args->obj_at(1)); |
2827 bsm = Handle(THREAD, args->obj_at(0)); |
|
2828 if (len > 1) { |
|
2829 objArrayOop args1 = oopFactory::new_objArray(SystemDictionary::Object_klass(), len-1, CHECK_(empty)); |
|
2830 for (int i = 1; i < len; i++) |
|
2831 args1->obj_at_put(i-1, args->obj_at(i)); |
|
2832 info = Handle(THREAD, args1); |
|
2833 } |
|
2834 } |
2951 } |
2835 guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()), |
2952 guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()), |
2836 "caller must supply a valid BSM"); |
2953 "caller must supply a valid BSM"); |
2837 |
2954 |
2838 Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
2955 Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
2844 } |
2961 } |
2845 |
2962 |
2846 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2963 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2847 assert(appendix_box->obj_at(0) == NULL, ""); |
2964 assert(appendix_box->obj_at(0) == NULL, ""); |
2848 |
2965 |
2849 // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, bsm, name, mtype, info, &appendix) |
2966 // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, indy_index, bsm, name, mtype, info, &appendix) |
2850 JavaCallArguments args; |
2967 JavaCallArguments args; |
2851 args.push_oop(Handle(THREAD, caller->java_mirror())); |
2968 args.push_oop(Handle(THREAD, caller->java_mirror())); |
|
2969 args.push_int(indy_index); |
2852 args.push_oop(bsm); |
2970 args.push_oop(bsm); |
2853 args.push_oop(method_name); |
2971 args.push_oop(method_name); |
2854 args.push_oop(method_type); |
2972 args.push_oop(method_type); |
2855 args.push_oop(info); |
2973 args.push_oop(info); |
2856 args.push_oop(appendix_box); |
2974 args.push_oop(appendix_box); |