< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page
rev 52749 : Bootstrap method consolidation
* clean up and simplify JDK support code for BSM invocation
* simplify JVM bootstrap handshake: use BootstrapCallInfo only
* remove unused JVM paths and data fields
* move bootstrap argument processing from MethodHandleNatives to ConstantPool
* remove ConstantGroup; merge argument access into BootstrapCallInfo
* adjust BSM argument access: remove copyArguments, add argumentRef API
* add metadata-free BSM modes, including symbolic arguments from CP


2495     #endif //PRODUCT
2496       }
2497       (*appendix_result) = Handle(THREAD, appendix);
2498       // the target is stored in the cpCache and if a reference to this
2499       // MemberName is dropped we need a way to make sure the
2500       // class_loader containing this method is kept alive.
2501       ClassLoaderData* this_key = accessing_klass->class_loader_data();
2502       this_key->record_dependency(m->method_holder());
2503       return methodHandle(THREAD, m);
2504     }
2505   }
2506   THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2507   return empty;
2508 }
2509 
2510 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
2511                                                           Symbol* name,
2512                                                           Symbol* signature,
2513                                                           Klass* accessing_klass,
2514                                                           Handle *appendix_result,
2515                                                           Handle *method_type_result,
2516                                                           TRAPS) {
2517   methodHandle empty;
2518   assert(THREAD->can_call_java() ,"");
2519   Handle method_type =
2520     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2521 
2522   int ref_kind = JVM_REF_invokeVirtual;
2523   oop name_oop = StringTable::intern(name, CHECK_(empty));
2524   Handle name_str (THREAD, name_oop);
2525   objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
2526   assert(appendix_box->obj_at(0) == NULL, "");
2527 
2528   // This should not happen.  JDK code should take care of that.
2529   if (accessing_klass == NULL || method_type.is_null()) {
2530     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
2531   }
2532 
2533   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
2534   JavaCallArguments args;
2535   args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
2536   args.push_int(ref_kind);
2537   args.push_oop(Handle(THREAD, klass->java_mirror()));
2538   args.push_oop(name_str);
2539   args.push_oop(method_type);
2540   args.push_oop(appendix_box);
2541   JavaValue result(T_OBJECT);
2542   JavaCalls::call_static(&result,
2543                          SystemDictionary::MethodHandleNatives_klass(),
2544                          vmSymbols::linkMethod_name(),
2545                          vmSymbols::linkMethod_signature(),
2546                          &args, CHECK_(empty));
2547   Handle mname(THREAD, (oop) result.get_jobject());
2548   (*method_type_result) = method_type;
2549   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
2550 }
2551 
2552 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
2553 // We must ensure that all class loaders everywhere will reach this class, for any client.
2554 // This is a safe bet for public classes in java.lang, such as Object and String.
2555 // We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
2556 // Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
2557 static bool is_always_visible_class(oop mirror) {
2558   Klass* klass = java_lang_Class::as_Klass(mirror);
2559   if (klass->is_objArray_klass()) {
2560     klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
2561   }
2562   if (klass->is_typeArray_klass()) {
2563     return true; // primitive array
2564   }
2565   assert(klass->is_instance_klass(), "%s", klass->external_name());
2566   return klass->is_public() &&
2567          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2568           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2569 }
2570 
2571 
2572 // Return the Java mirror (java.lang.Class instance) for a single-character
2573 // descriptor.  This result, when available, is the same as produced by the
2574 // heavier API point of the same name that takes a Symbol.
2575 oop SystemDictionary::find_java_mirror_for_type(char signature_char) {
2576   return java_lang_Class::primitive_mirror(char2type(signature_char));
2577 }
2578 
2579 // Find or construct the Java mirror (java.lang.Class instance) for a
2580 // for the given field type signature, as interpreted relative to the
2581 // given class loader.  Handles primitives, void, references, arrays,
2582 // and all other reflectable types, except method types.
2583 // N.B.  Code in reflection should use this entry point.
2584 Handle SystemDictionary::find_java_mirror_for_type(Symbol* signature,
2585                                                    Klass* accessing_klass,
2586                                                    Handle class_loader,
2587                                                    Handle protection_domain,
2588                                                    SignatureStream::FailureMode failure_mode,

2589                                                    TRAPS) {
2590   Handle empty;
2591 
2592   assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),
2593          "one or the other, or perhaps neither");
2594 
2595   Symbol* type = signature;
2596 
2597   // What we have here must be a valid field descriptor,
2598   // and all valid field descriptors are supported.
2599   // Produce the same java.lang.Class that reflection reports.
2600   if (type->utf8_length() == 1) {
2601 
2602     // It's a primitive.  (Void has a primitive mirror too.)
2603     char ch = (char) type->byte_at(0);
2604     assert(is_java_primitive(char2type(ch)) || ch == 'V', "");
2605     return Handle(THREAD, find_java_mirror_for_type(ch));
2606 
2607   } else if (FieldType::is_obj(type) || FieldType::is_array(type)) {
2608 
2609     // It's a reference type.
2610     if (accessing_klass != NULL) {
2611       class_loader      = Handle(THREAD, accessing_klass->class_loader());
2612       protection_domain = Handle(THREAD, accessing_klass->protection_domain());
2613     }
2614     Klass* constant_type_klass;
2615     if (failure_mode == SignatureStream::ReturnNull) {
2616       constant_type_klass = resolve_or_null(type, class_loader, protection_domain,
2617                                             CHECK_(empty));
2618     } else {
2619       bool throw_error = (failure_mode == SignatureStream::NCDFError);
2620       constant_type_klass = resolve_or_fail(type, class_loader, protection_domain,
2621                                             throw_error, CHECK_(empty));
2622     }
2623     if (constant_type_klass == NULL) {
2624       return Handle();  // report failure this way
2625     }
2626     Handle mirror(THREAD, constant_type_klass->java_mirror());
2627 
2628     // Check accessibility, emulating ConstantPool::verify_constant_pool_resolve.
2629     if (accessing_klass != NULL) {
2630       Klass* sel_klass = constant_type_klass;
2631       bool fold_type_to_class = true;
2632       LinkResolver::check_klass_accessability(accessing_klass, sel_klass,
2633                                               fold_type_to_class, CHECK_(empty));
2634     }
2635 
2636     return mirror;
2637 
2638   }
2639 
2640   // Fall through to an error.
2641   assert(false, "unsupported mirror syntax");
2642   THROW_MSG_(vmSymbols::java_lang_InternalError(), "unsupported mirror syntax", empty);
2643 }
2644 
2645 
2646 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2647 // signature, as interpreted relative to the given class loader.
2648 // Because of class loader constraints, all method handle usage must be
2649 // consistent with this loader.


2717                          vmSymbols::findMethodHandleType_name(),
2718                          vmSymbols::findMethodHandleType_signature(),
2719                          &args, CHECK_(empty));
2720   Handle method_type(THREAD, (oop) result.get_jobject());
2721 
2722   if (can_be_cached) {
2723     // We can cache this MethodType inside the JVM.
2724     MutexLocker ml(SystemDictionary_lock, THREAD);
2725     spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2726     if (spe == NULL)
2727       spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
2728     if (spe->method_type() == NULL) {
2729       spe->set_method_type(method_type());
2730     }
2731   }
2732 
2733   // report back to the caller with the MethodType
2734   return method_type;
2735 }
2736 
2737 Handle SystemDictionary::find_field_handle_type(Symbol* signature,
2738                                                 Klass* accessing_klass,
2739                                                 TRAPS) {
2740   Handle empty;
2741   ResourceMark rm(THREAD);
2742   SignatureStream ss(signature, /*is_method=*/ false);
2743   if (!ss.is_done()) {
2744     Handle class_loader, protection_domain;
2745     if (accessing_klass != NULL) {
2746       class_loader      = Handle(THREAD, accessing_klass->class_loader());
2747       protection_domain = Handle(THREAD, accessing_klass->protection_domain());
2748     }
2749     oop mirror = ss.as_java_mirror(class_loader, protection_domain, SignatureStream::NCDFError, CHECK_(empty));
2750     ss.next();
2751     if (ss.is_done()) {
2752       return Handle(THREAD, mirror);
2753     }
2754   }
2755   return empty;
2756 }
2757 
2758 // Ask Java code to find or construct a method handle constant.
2759 Handle SystemDictionary::link_method_handle_constant(Klass* caller,
2760                                                      int ref_kind, //e.g., JVM_REF_invokeVirtual
2761                                                      Klass* callee,
2762                                                      Symbol* name,
2763                                                      Symbol* signature,
2764                                                      TRAPS) {
2765   Handle empty;
2766   if (caller == NULL) {
2767     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
2768   }
2769   Handle name_str      = java_lang_String::create_from_symbol(name,      CHECK_(empty));
2770   Handle signature_str = java_lang_String::create_from_symbol(signature, CHECK_(empty));
2771 
2772   // Put symbolic info from the MH constant into freshly created MemberName and resolve it.
2773   Handle mname = MemberName_klass()->allocate_instance_handle(CHECK_(empty));
2774   java_lang_invoke_MemberName::set_clazz(mname(), callee->java_mirror());
2775   java_lang_invoke_MemberName::set_name (mname(), name_str());
2776   java_lang_invoke_MemberName::set_type (mname(), signature_str());
2777   java_lang_invoke_MemberName::set_flags(mname(), MethodHandles::ref_kind_to_flags(ref_kind));


2789 
2790   // After method/field resolution succeeded, it's safe to resolve MH signature as well.
2791   Handle type = MethodHandles::resolve_MemberName_type(mname, caller, CHECK_(empty));
2792 
2793   // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
2794   JavaCallArguments args;
2795   args.push_oop(Handle(THREAD, caller->java_mirror()));  // the referring class
2796   args.push_int(ref_kind);
2797   args.push_oop(Handle(THREAD, callee->java_mirror()));  // the target class
2798   args.push_oop(name_str);
2799   args.push_oop(type);
2800   JavaValue result(T_OBJECT);
2801   JavaCalls::call_static(&result,
2802                          SystemDictionary::MethodHandleNatives_klass(),
2803                          vmSymbols::linkMethodHandleConstant_name(),
2804                          vmSymbols::linkMethodHandleConstant_signature(),
2805                          &args, CHECK_(empty));
2806   return Handle(THREAD, (oop) result.get_jobject());
2807 }
2808 
2809 // Ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
2810 Handle SystemDictionary::link_dynamic_constant(Klass* caller,
2811                                                int condy_index,
2812                                                Handle bootstrap_specifier,
2813                                                Symbol* name,
2814                                                Symbol* type,
2815                                                TRAPS) {
2816   Handle empty;
2817   Handle bsm, info;
2818   if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) {
2819     bsm = bootstrap_specifier;
2820   } else {
2821     assert(bootstrap_specifier->is_objArray(), "");
2822     objArrayOop args = (objArrayOop) bootstrap_specifier();
2823     assert(args->length() == 2, "");
2824     bsm  = Handle(THREAD, args->obj_at(0));
2825     info = Handle(THREAD, args->obj_at(1));
2826   }
2827   guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()),
2828             "caller must supply a valid BSM");
2829 
2830   // This should not happen.  JDK code should take care of that.
2831   if (caller == NULL) {
2832     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad dynamic constant", empty);










2833   }
2834 
2835   Handle constant_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
2836 
2837   // Resolve the constant type in the context of the caller class
2838   Handle type_mirror = find_java_mirror_for_type(type, caller, SignatureStream::NCDFError,
2839                                                  CHECK_(empty));
2840 
2841   // call java.lang.invoke.MethodHandleNatives::linkConstantDyanmic(caller, condy_index, bsm, type, info)
2842   JavaCallArguments args;
2843   args.push_oop(Handle(THREAD, caller->java_mirror()));
2844   args.push_int(condy_index);
2845   args.push_oop(bsm);
2846   args.push_oop(constant_name);
2847   args.push_oop(type_mirror);
2848   args.push_oop(info);








2849   JavaValue result(T_OBJECT);
2850   JavaCalls::call_static(&result,
2851                          SystemDictionary::MethodHandleNatives_klass(),
2852                          vmSymbols::linkDynamicConstant_name(),
2853                          vmSymbols::linkDynamicConstant_signature(),
2854                          &args, CHECK_(empty));
2855 
2856   return Handle(THREAD, (oop) result.get_jobject());
2857 }
2858 
2859 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given
2860 // name and signature, as interpreted relative to the given class loader.
2861 methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller,
2862                                                               int indy_index,
2863                                                               Handle bootstrap_specifier,
2864                                                               Symbol* name,
2865                                                               Symbol* type,
2866                                                               Handle *appendix_result,
2867                                                               Handle *method_type_result,
2868                                                               TRAPS) {
2869   methodHandle empty;
2870   Handle bsm, info;
2871   if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) {
2872     bsm = bootstrap_specifier;
2873   } else {
2874     objArrayOop args = (objArrayOop) bootstrap_specifier();
2875     assert(args->length() == 2, "");
2876     bsm  = Handle(THREAD, args->obj_at(0));
2877     info = Handle(THREAD, args->obj_at(1));
2878   }
2879   guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()),
2880             "caller must supply a valid BSM");
2881 
2882   Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
2883   Handle method_type = find_method_handle_type(type, caller, CHECK_(empty));
2884 
2885   // This should not happen.  JDK code should take care of that.
2886   if (caller == NULL || method_type.is_null()) {
2887     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);



2888   }
2889 
2890   objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
2891   assert(appendix_box->obj_at(0) == NULL, "");
2892 
2893   // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, indy_index, bsm, name, mtype, info, &appendix)
2894   JavaCallArguments args;
2895   args.push_oop(Handle(THREAD, caller->java_mirror()));
2896   args.push_int(indy_index);
2897   args.push_oop(bsm);
2898   args.push_oop(method_name);
2899   args.push_oop(method_type);
2900   args.push_oop(info);
2901   args.push_oop(appendix_box);
2902   JavaValue result(T_OBJECT);
2903   JavaCalls::call_static(&result,
2904                          SystemDictionary::MethodHandleNatives_klass(),
2905                          vmSymbols::linkCallSite_name(),
2906                          vmSymbols::linkCallSite_signature(),
2907                          &args, CHECK_(empty));
2908   Handle mname(THREAD, (oop) result.get_jobject());
2909   (*method_type_result) = method_type;
2910   return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD);
2911 }
2912 
2913 // Protection domain cache table handling
2914 
2915 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) {
2916   return _pd_cache_table->get(protection_domain);
2917 }
2918 
2919 #if INCLUDE_CDS
2920 void SystemDictionary::reorder_dictionary_for_sharing() {
2921   ClassLoaderData::the_null_class_loader_data()->dictionary()->reorder_dictionary_for_sharing();
2922 }
2923 #endif
2924 
2925 size_t SystemDictionary::count_bytes_for_buckets() {
2926   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_buckets();
2927 }
2928 
2929 size_t SystemDictionary::count_bytes_for_table() {
2930   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_table();




2495     #endif //PRODUCT
2496       }
2497       (*appendix_result) = Handle(THREAD, appendix);
2498       // the target is stored in the cpCache and if a reference to this
2499       // MemberName is dropped we need a way to make sure the
2500       // class_loader containing this method is kept alive.
2501       ClassLoaderData* this_key = accessing_klass->class_loader_data();
2502       this_key->record_dependency(m->method_holder());
2503       return methodHandle(THREAD, m);
2504     }
2505   }
2506   THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2507   return empty;
2508 }
2509 
2510 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
2511                                                           Symbol* name,
2512                                                           Symbol* signature,
2513                                                           Klass* accessing_klass,
2514                                                           Handle *appendix_result,

2515                                                           TRAPS) {
2516   methodHandle empty;
2517   assert(THREAD->can_call_java() ,"");
2518   Handle method_type =
2519     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2520 
2521   int ref_kind = JVM_REF_invokeVirtual;
2522   oop name_oop = StringTable::intern(name, CHECK_(empty));
2523   Handle name_str (THREAD, name_oop);
2524   objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
2525   assert(appendix_box->obj_at(0) == NULL, "");
2526 
2527   // This should not happen.  JDK code should take care of that.
2528   if (accessing_klass == NULL || method_type.is_null()) {
2529     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
2530   }
2531 
2532   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
2533   JavaCallArguments args;
2534   args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
2535   args.push_int(ref_kind);
2536   args.push_oop(Handle(THREAD, klass->java_mirror()));
2537   args.push_oop(name_str);
2538   args.push_oop(method_type);
2539   args.push_oop(appendix_box);
2540   JavaValue result(T_OBJECT);
2541   JavaCalls::call_static(&result,
2542                          SystemDictionary::MethodHandleNatives_klass(),
2543                          vmSymbols::linkMethod_name(),
2544                          vmSymbols::linkMethod_signature(),
2545                          &args, CHECK_(empty));
2546   Handle mname(THREAD, (oop) result.get_jobject());

2547   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
2548 }
2549 
2550 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
2551 // We must ensure that all class loaders everywhere will reach this class, for any client.
2552 // This is a safe bet for public classes in java.lang, such as Object and String.
2553 // We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
2554 // Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
2555 static bool is_always_visible_class(oop mirror) {
2556   Klass* klass = java_lang_Class::as_Klass(mirror);
2557   if (klass->is_objArray_klass()) {
2558     klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
2559   }
2560   if (klass->is_typeArray_klass()) {
2561     return true; // primitive array
2562   }
2563   assert(klass->is_instance_klass(), "%s", klass->external_name());
2564   return klass->is_public() &&
2565          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2566           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2567 }
2568 
2569 
2570 // Return the Java mirror (java.lang.Class instance) for a single-character
2571 // descriptor.  This result, when available, is the same as produced by the
2572 // heavier API point of the same name that takes a Symbol.
2573 oop SystemDictionary::find_java_mirror_for_type(char signature_char) {
2574   return java_lang_Class::primitive_mirror(char2type(signature_char));
2575 }
2576 
2577 // Find or construct the Java mirror (java.lang.Class instance) for a
2578 // for the given field type signature, as interpreted relative to the
2579 // given class loader.  Handles primitives, void, references, arrays,
2580 // and all other reflectable types, except method types.
2581 // N.B.  Code in reflection should use this entry point.
2582 Handle SystemDictionary::find_java_mirror_for_type(Symbol* signature,
2583                                                    Klass* accessing_klass,
2584                                                    Handle class_loader,
2585                                                    Handle protection_domain,
2586                                                    SignatureStream::FailureMode failure_mode,
2587                                                    bool check_access,
2588                                                    TRAPS) {
2589   Handle empty;
2590 
2591   assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),
2592          "one or the other, or perhaps neither");
2593 
2594   Symbol* type = signature;
2595 
2596   // What we have here must be a valid field descriptor,
2597   // and all valid field descriptors are supported.
2598   // Produce the same java.lang.Class that reflection reports.
2599   if (type->utf8_length() == 1) {
2600 
2601     // It's a primitive.  (Void has a primitive mirror too.)
2602     char ch = (char) type->byte_at(0);
2603     assert(is_java_primitive(char2type(ch)) || ch == 'V', "");
2604     return Handle(THREAD, find_java_mirror_for_type(ch));
2605 
2606   } else if (FieldType::is_obj(type) || FieldType::is_array(type)) {
2607 
2608     // It's a reference type.
2609     if (accessing_klass != NULL) {
2610       class_loader      = Handle(THREAD, accessing_klass->class_loader());
2611       protection_domain = Handle(THREAD, accessing_klass->protection_domain());
2612     }
2613     Klass* constant_type_klass;
2614     if (failure_mode == SignatureStream::ReturnNull) {
2615       constant_type_klass = resolve_or_null(type, class_loader, protection_domain,
2616                                             CHECK_(empty));
2617     } else {
2618       bool throw_error = (failure_mode == SignatureStream::NCDFError);
2619       constant_type_klass = resolve_or_fail(type, class_loader, protection_domain,
2620                                             throw_error, CHECK_(empty));
2621     }
2622     if (constant_type_klass == NULL) {
2623       return Handle();  // report failure this way
2624     }
2625     Handle mirror(THREAD, constant_type_klass->java_mirror());
2626 
2627     // Check accessibility, emulating ConstantPool::verify_constant_pool_resolve.
2628     if (check_access && accessing_klass != NULL) {
2629       Klass* sel_klass = constant_type_klass;
2630       bool fold_type_to_class = true;
2631       LinkResolver::check_klass_accessability(accessing_klass, sel_klass,
2632                                               fold_type_to_class, CHECK_(empty));
2633     }
2634 
2635     return mirror;
2636 
2637   }
2638 
2639   // Fall through to an error.
2640   assert(false, "unsupported mirror syntax");
2641   THROW_MSG_(vmSymbols::java_lang_InternalError(), "unsupported mirror syntax", empty);
2642 }
2643 
2644 
2645 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2646 // signature, as interpreted relative to the given class loader.
2647 // Because of class loader constraints, all method handle usage must be
2648 // consistent with this loader.


2716                          vmSymbols::findMethodHandleType_name(),
2717                          vmSymbols::findMethodHandleType_signature(),
2718                          &args, CHECK_(empty));
2719   Handle method_type(THREAD, (oop) result.get_jobject());
2720 
2721   if (can_be_cached) {
2722     // We can cache this MethodType inside the JVM.
2723     MutexLocker ml(SystemDictionary_lock, THREAD);
2724     spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2725     if (spe == NULL)
2726       spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
2727     if (spe->method_type() == NULL) {
2728       spe->set_method_type(method_type());
2729     }
2730   }
2731 
2732   // report back to the caller with the MethodType
2733   return method_type;
2734 }
2735 





















2736 // Ask Java code to find or construct a method handle constant.
2737 Handle SystemDictionary::link_method_handle_constant(Klass* caller,
2738                                                      int ref_kind, //e.g., JVM_REF_invokeVirtual
2739                                                      Klass* callee,
2740                                                      Symbol* name,
2741                                                      Symbol* signature,
2742                                                      TRAPS) {
2743   Handle empty;
2744   if (caller == NULL) {
2745     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
2746   }
2747   Handle name_str      = java_lang_String::create_from_symbol(name,      CHECK_(empty));
2748   Handle signature_str = java_lang_String::create_from_symbol(signature, CHECK_(empty));
2749 
2750   // Put symbolic info from the MH constant into freshly created MemberName and resolve it.
2751   Handle mname = MemberName_klass()->allocate_instance_handle(CHECK_(empty));
2752   java_lang_invoke_MemberName::set_clazz(mname(), callee->java_mirror());
2753   java_lang_invoke_MemberName::set_name (mname(), name_str());
2754   java_lang_invoke_MemberName::set_type (mname(), signature_str());
2755   java_lang_invoke_MemberName::set_flags(mname(), MethodHandles::ref_kind_to_flags(ref_kind));


2767 
2768   // After method/field resolution succeeded, it's safe to resolve MH signature as well.
2769   Handle type = MethodHandles::resolve_MemberName_type(mname, caller, CHECK_(empty));
2770 
2771   // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
2772   JavaCallArguments args;
2773   args.push_oop(Handle(THREAD, caller->java_mirror()));  // the referring class
2774   args.push_int(ref_kind);
2775   args.push_oop(Handle(THREAD, callee->java_mirror()));  // the target class
2776   args.push_oop(name_str);
2777   args.push_oop(type);
2778   JavaValue result(T_OBJECT);
2779   JavaCalls::call_static(&result,
2780                          SystemDictionary::MethodHandleNatives_klass(),
2781                          vmSymbols::linkMethodHandleConstant_name(),
2782                          vmSymbols::linkMethodHandleConstant_signature(),
2783                          &args, CHECK_(empty));
2784   return Handle(THREAD, (oop) result.get_jobject());
2785 }
2786 
2787 // Ask Java to run a bootstrap method, in order to create a dynamic call site
2788 // while linking an invokedynamic op, or compute a constant for Dynamic_info CP entry
2789 // with linkage results being stored back into the bootstrap specifier.
2790 void SystemDictionary::invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS) {
2791   ResourceMark rm;
2792   bootstrap_specifier.resolve_bsm(CHECK);
2793   bootstrap_specifier.resolve_metadata(CHECK);
2794   BootstrapInfo::BSMMode bsm_mode = bootstrap_specifier.bsm_mode();
2795   ConstantPool::BootstrapArgumentReferenceMode arg_mode = ConstantPool::R_IFPRESENT;
2796   if (bsm_mode == BootstrapInfo::_metadata ||
2797       (bsm_mode == BootstrapInfo::_expression &&
2798        bootstrap_specifier.name() == vmSymbols::invoke_name()))
2799     // We know the BSM is going to immediately use all the arguments.
2800     arg_mode = ConstantPool::R_FORCE;
2801   // Otherwise, it can't hurt to pre-pack the object array with present arguments.
2802   bootstrap_specifier.resolve_args(arg_mode, CHECK);
2803   if (arg_mode != ConstantPool::R_FORCE) {
2804     // If we are going tentative, also grab the symbolic reference data.
2805     bootstrap_specifier.resolve_args(ConstantPool::R_SYMREF, CHECK);
2806   }
2807 
2808   Handle caller(THREAD, bootstrap_specifier.caller_mirror());
2809   typeArrayOop index_info_oop = oopFactory::new_intArray(2, CHECK);
2810   typeArrayHandle index_info(THREAD, index_info_oop);
2811   index_info->int_at_put(0, bootstrap_specifier.argc());
2812   index_info->int_at_put(1, bootstrap_specifier.bss_index());
2813 
2814   bool has_appendix = bootstrap_specifier.is_method_call();
2815   objArrayHandle appendix_box;
2816   if (has_appendix) {
2817     // Some method calls may require an appendix argument.  Arrange to receive it.
2818     objArrayOop appendix_box_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK);
2819     appendix_box = objArrayHandle(THREAD, appendix_box_oop);
2820     assert(appendix_box->obj_at(0) == NULL, "");
2821   }
2822   Handle request;
2823   if (bootstrap_specifier.indy_index() != 0) {
2824     // request is call-site specific
2825     request = Handle(THREAD, SystemDictionary::CallSite_klass()->java_mirror());
2826   }
2827 
2828   Handle cpool = reflect_ConstantPool::create_from_pool(bootstrap_specifier.pool()(), CHECK);
2829   Handle arg_indexes(THREAD, bootstrap_specifier.arg_indexes()());
2830   Handle arg_values(THREAD,  bootstrap_specifier.arg_values()());
2831 
2832   // call java.lang.invoke.MethodHandleNatives::bootstrapMethodHelper(cpool, bss_index, indy_index, argc, bsm, name, type, argIndexes, argValues, request, &appendix)
2833   JavaCallArguments args(11);
2834   args.push_oop(cpool);
2835   args.push_int(bootstrap_specifier.bss_index());
2836   args.push_int(bootstrap_specifier.indy_index());
2837   args.push_int(bootstrap_specifier.argc());
2838   args.push_oop(bootstrap_specifier.bsm());
2839   args.push_oop(bootstrap_specifier.name_arg());
2840   args.push_oop(bootstrap_specifier.type_arg());
2841   args.push_oop(bootstrap_specifier.arg_indexes());
2842   args.push_oop(bootstrap_specifier.arg_values());
2843   args.push_oop(request);
2844   args.push_oop(appendix_box);
2845   JavaValue result(T_OBJECT);
2846   JavaCalls::call_static(&result,
2847                          SystemDictionary::MethodHandleNatives_klass(),
2848                          vmSymbols::bootstrapMethodHelper_name(),
2849                          vmSymbols::bootstrapMethodHelper_signature(),
2850                          &args, CHECK);
2851   if (has_appendix) {
2852     Handle appendix;
2853     Handle mname(THREAD, (oop) result.get_jobject());
2854     methodHandle method = unpack_method_and_appendix(mname,
2855                                                      bootstrap_specifier.caller(),
2856                                                      appendix_box,
2857                                                      &appendix, CHECK);
2858     bootstrap_specifier.set_resolved_method(method, appendix);










2859   } else {
2860     Handle value(THREAD, (oop) result.get_jobject());
2861     bootstrap_specifier.set_resolved_value(value);


2862   }





2863 
2864   // sanity check
2865   if (!bootstrap_specifier.is_resolved() ||
2866       (bootstrap_specifier.is_method_call() &&
2867        bootstrap_specifier.resolved_method().is_null())) {
2868     // Could be a guarantee but throw IE instead, in case it is JDK bug.
2869     THROW_MSG(vmSymbols::java_lang_InternalError(), "bootstrap method call failed");
2870   }






















2871 }
2872 
2873 // Protection domain cache table handling
2874 
2875 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) {
2876   return _pd_cache_table->get(protection_domain);
2877 }
2878 
2879 #if INCLUDE_CDS
2880 void SystemDictionary::reorder_dictionary_for_sharing() {
2881   ClassLoaderData::the_null_class_loader_data()->dictionary()->reorder_dictionary_for_sharing();
2882 }
2883 #endif
2884 
2885 size_t SystemDictionary::count_bytes_for_buckets() {
2886   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_buckets();
2887 }
2888 
2889 size_t SystemDictionary::count_bytes_for_table() {
2890   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_table();


< prev index next >