< prev index next >

src/hotspot/share/prims/methodHandles.cpp

Print this page

 114     StubCodeMark mark(this, "MethodHandle::interpreter_entry", vmIntrinsics::name_at(iid));
 115     address entry = MethodHandles::generate_method_handle_interpreter_entry(_masm, iid);
 116     if (entry != nullptr) {
 117       Interpreter::set_entry_for_kind(mk, entry);
 118     }
 119     // If the entry is not set, it will throw AbstractMethodError.
 120   }
 121 }
 122 
 123 void MethodHandles::set_enabled(bool z) {
 124   if (_enabled != z) {
 125     guarantee(z, "can only enable once");
 126     _enabled = z;
 127   }
 128 }
 129 
 130 // MemberName support
 131 
 132 // import java_lang_invoke_MemberName.*
 133 enum {
 134   IS_METHOD            = java_lang_invoke_MemberName::MN_IS_METHOD,
 135   IS_CONSTRUCTOR       = java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR,
 136   IS_FIELD             = java_lang_invoke_MemberName::MN_IS_FIELD,
 137   IS_TYPE              = java_lang_invoke_MemberName::MN_IS_TYPE,
 138   CALLER_SENSITIVE     = java_lang_invoke_MemberName::MN_CALLER_SENSITIVE,
 139   TRUSTED_FINAL        = java_lang_invoke_MemberName::MN_TRUSTED_FINAL,
 140   HIDDEN_MEMBER        = java_lang_invoke_MemberName::MN_HIDDEN_MEMBER,
 141   REFERENCE_KIND_SHIFT = java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT,
 142   REFERENCE_KIND_MASK  = java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK,
 143   LM_UNCONDITIONAL     = java_lang_invoke_MemberName::MN_UNCONDITIONAL_MODE,
 144   LM_MODULE            = java_lang_invoke_MemberName::MN_MODULE_MODE,
 145   LM_TRUSTED           = java_lang_invoke_MemberName::MN_TRUSTED_MODE,
 146   ALL_KINDS      = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE


 147 };
 148 
 149 int MethodHandles::ref_kind_to_flags(int ref_kind) {
 150   assert(ref_kind_is_valid(ref_kind), "%d", ref_kind);
 151   int flags = (ref_kind << REFERENCE_KIND_SHIFT);
 152   if (ref_kind_is_field(ref_kind)) {
 153     flags |= IS_FIELD;
 154   } else if (ref_kind_is_method(ref_kind)) {
 155     flags |= IS_METHOD;
 156   } else if (ref_kind == JVM_REF_newInvokeSpecial) {
 157     flags |= IS_CONSTRUCTOR;
 158   }
 159   return flags;
 160 }
 161 
 162 Handle MethodHandles::resolve_MemberName_type(Handle mname, Klass* caller, TRAPS) {
 163   Handle empty;
 164   Handle type(THREAD, java_lang_invoke_MemberName::type(mname()));
 165   if (!java_lang_String::is_instance(type())) {
 166     return type; // already resolved
 167   }
 168   Symbol* signature = java_lang_String::as_symbol_or_null(type());
 169   if (signature == nullptr) {
 170     return empty;  // no such signature exists in the VM
 171   }
 172   Handle resolved;
 173   int flags = java_lang_invoke_MemberName::flags(mname());
 174   switch (flags & ALL_KINDS) {
 175     case IS_METHOD:
 176     case IS_CONSTRUCTOR:
 177       resolved = SystemDictionary::find_method_handle_type(signature, caller, CHECK_(empty));
 178       break;
 179     case IS_FIELD:
 180       resolved = SystemDictionary::find_field_handle_type(signature, caller, CHECK_(empty));
 181       break;
 182     default:
 183       THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
 184   }
 185   if (resolved.is_null()) {
 186     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MemberName type", empty);
 187   }
 188   return resolved;
 189 }
 190 
 191 oop MethodHandles::init_MemberName(Handle mname, Handle target, TRAPS) {
 192   // This method is used from java.lang.invoke.MemberName constructors.
 193   // It fills in the new MemberName from a java.lang.reflect.Member.
 194   oop target_oop = target();
 195   Klass* target_klass = target_oop->klass();
 196   if (target_klass == vmClasses::reflect_Field_klass()) {

 298       m_klass = m_klass_non_interface;
 299     }
 300     if (lt_indy.is_enabled()) {
 301       ResourceMark rm;
 302       LogStream ls(lt_indy);
 303       ls.print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
 304                   Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
 305                   m_klass->internal_name(), vmindex);
 306        m->access_flags().print_on(&ls);
 307        if (m->is_default_method()) {
 308          ls.print("default");
 309        }
 310        ls.cr();
 311     }
 312     break;
 313 
 314   case CallInfo::direct_call:
 315     vmindex = Method::nonvirtual_vtable_index;
 316     if (m->is_static()) {
 317       flags |= IS_METHOD      | (JVM_REF_invokeStatic  << REFERENCE_KIND_SHIFT);
 318     } else if (m->is_initializer()) {
 319       flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
 320     } else {
 321       // "special" reflects that this is a direct call, not that it
 322       // necessarily originates from an invokespecial. We can also do
 323       // direct calls for private and/or final non-static methods.
 324       flags |= IS_METHOD      | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
 325     }
 326     break;
 327 
 328   default:  assert(false, "bad CallInfo");  return nullptr;
 329   }
 330 
 331   // @CallerSensitive annotation detected
 332   if (m->caller_sensitive()) {
 333     flags |= CALLER_SENSITIVE;
 334   }
 335 
 336   Handle resolved_method = info.resolved_method_name();
 337   assert(java_lang_invoke_ResolvedMethodName::vmtarget(resolved_method()) == m() || m->is_old(),
 338          "Should not change after link resolution");
 339 
 340   oop mname_oop = mname();
 341   java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
 342   java_lang_invoke_MemberName::set_method (mname_oop, resolved_method());
 343   java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);   // vtable/itable index
 344   java_lang_invoke_MemberName::set_clazz  (mname_oop, m_klass->java_mirror());
 345   // Note:  name and type can be lazily computed by resolve_MemberName,
 346   // if Java code needs them as resolved String and MethodType objects.
 347   // If relevant, the vtable or itable value is stored as vmindex.
 348   // This is done eagerly, since it is readily available without
 349   // constructing any new objects.
 350   return mname();
 351 }
 352 
 353 oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) {
 354   InstanceKlass* ik = fd.field_holder();
 355   int flags = (jushort)( fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS );
 356   flags |= IS_FIELD | ((fd.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT);
 357   if (fd.is_trusted_final()) flags |= TRUSTED_FINAL;


 358   if (is_setter)  flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT);
 359   int vmindex        = fd.offset();  // determines the field uniquely when combined with static bit
 360 
 361   oop mname_oop = mname();
 362   java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
 363   java_lang_invoke_MemberName::set_method (mname_oop, nullptr);
 364   java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);
 365   java_lang_invoke_MemberName::set_clazz  (mname_oop, ik->java_mirror());
 366 
 367   oop type = field_signature_type_or_null(fd.signature());
 368   oop name = field_name_or_null(fd.name());
 369   if (name != nullptr)
 370     java_lang_invoke_MemberName::set_name(mname_oop,   name);
 371   if (type != nullptr)
 372     java_lang_invoke_MemberName::set_type(mname_oop,   type);
 373   // Note:  name and type can be lazily computed by resolve_MemberName,
 374   // if Java code needs them as resolved String and Class objects.
 375   // Note that the incoming type oop might be pre-resolved (non-null).
 376   // The base clazz and field offset (vmindex) must be eagerly stored,
 377   // because they unambiguously identify the field.

 791         } else {
 792           assert(false, "ref_kind=%d", ref_kind);
 793         }
 794         if (HAS_PENDING_EXCEPTION) {
 795           if (speculative_resolve) {
 796             CLEAR_PENDING_EXCEPTION;
 797           }
 798           return empty;
 799         }
 800       }
 801       if (result.resolved_appendix().not_null()) {
 802         // The resolved MemberName must not be accompanied by an appendix argument,
 803         // since there is no way to bind this value into the MemberName.
 804         // Caller is responsible to prevent this from happening.
 805         THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
 806       }
 807       result.set_resolved_method_name(CHECK_(empty));
 808       oop mname2 = init_method_MemberName(mname, result);
 809       return Handle(THREAD, mname2);
 810     }
 811   case IS_CONSTRUCTOR:
 812     {
 813       CallInfo result;
 814       LinkInfo link_info(defc, name, type, caller, access_check, loader_constraint_check);
 815       {
 816         assert(!HAS_PENDING_EXCEPTION, "");
 817         if (name == vmSymbols::object_initializer_name()) {
 818           LinkResolver::resolve_special_call(result, Handle(), link_info, THREAD);


 819         } else {
 820           break;                // will throw after end of switch
 821         }
 822         if (HAS_PENDING_EXCEPTION) {
 823           if (speculative_resolve) {
 824             CLEAR_PENDING_EXCEPTION;
 825           }
 826           return empty;
 827         }
 828       }
 829       assert(result.is_statically_bound(), "");
 830       result.set_resolved_method_name(CHECK_(empty));
 831       oop mname2 = init_method_MemberName(mname, result);
 832       return Handle(THREAD, mname2);
 833     }
 834   case IS_FIELD:
 835     {
 836       fieldDescriptor result; // find_field initializes fd if found
 837       {
 838         assert(!HAS_PENDING_EXCEPTION, "");

 860 // Resolving it plants a vmtarget/vmindex in it,
 861 // which refers directly to JVM internals.
 862 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {
 863   assert(java_lang_invoke_MemberName::is_instance(mname()), "");
 864 
 865   bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != nullptr);
 866   bool have_name = (java_lang_invoke_MemberName::name(mname()) != nullptr);
 867   bool have_type = (java_lang_invoke_MemberName::type(mname()) != nullptr);
 868   int flags      = java_lang_invoke_MemberName::flags(mname());
 869 
 870   if (suppress != 0) {
 871     if (suppress & _suppress_defc)  have_defc = true;
 872     if (suppress & _suppress_name)  have_name = true;
 873     if (suppress & _suppress_type)  have_type = true;
 874   }
 875 
 876   if (have_defc && have_name && have_type)  return;  // nothing needed
 877 
 878   switch (flags & ALL_KINDS) {
 879   case IS_METHOD:
 880   case IS_CONSTRUCTOR:
 881     {
 882       Method* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
 883       if (vmtarget == nullptr) {
 884         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand");
 885       }
 886       methodHandle m(THREAD, vmtarget);
 887       DEBUG_ONLY(vmtarget = nullptr);  // safety
 888       if (!have_defc) {
 889         InstanceKlass* defc = m->method_holder();
 890         java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
 891       }
 892       if (!have_name) {
 893         //not java_lang_String::create_from_symbol; let's intern member names
 894         oop name = StringTable::intern(m->name(), CHECK);
 895         java_lang_invoke_MemberName::set_name(mname(), name);
 896       }
 897       if (!have_type) {
 898         Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
 899         java_lang_invoke_MemberName::set_type(mname(), type());
 900       }

 982     trace_method_handle(_masm, qname);
 983     // LSan appears unable to keep track of qname, ignore it.
 984     LSAN_IGNORE_OBJECT(qname);
 985     // Note:  Don't free the allocated char array because it's used
 986     // during runtime.
 987   }
 988 }
 989 
 990 //
 991 // Here are the native methods in java.lang.invoke.MethodHandleNatives
 992 // They are the private interface between this JVM and the HotSpot-specific
 993 // Java code that implements JSR 292 method handles.
 994 //
 995 // Note:  We use a JVM_ENTRY macro to define each of these, for this is the way
 996 // that intrinsic (non-JNI) native methods are defined in HotSpot.
 997 //
 998 
 999 #ifndef PRODUCT
1000 #define EACH_NAMED_CON(template, requirement) \
1001     template(java_lang_invoke_MemberName,MN_IS_METHOD) \
1002     template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \
1003     template(java_lang_invoke_MemberName,MN_IS_FIELD) \
1004     template(java_lang_invoke_MemberName,MN_IS_TYPE) \
1005     template(java_lang_invoke_MemberName,MN_CALLER_SENSITIVE) \
1006     template(java_lang_invoke_MemberName,MN_TRUSTED_FINAL) \
1007     template(java_lang_invoke_MemberName,MN_HIDDEN_MEMBER) \

1008     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_SHIFT) \
1009     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \
1010     template(java_lang_invoke_MemberName,MN_NESTMATE_CLASS) \
1011     template(java_lang_invoke_MemberName,MN_HIDDEN_CLASS) \
1012     template(java_lang_invoke_MemberName,MN_STRONG_LOADER_LINK) \
1013     template(java_lang_invoke_MemberName,MN_ACCESS_VM_ANNOTATIONS) \
1014     template(java_lang_invoke_MemberName,MN_MODULE_MODE) \
1015     template(java_lang_invoke_MemberName,MN_UNCONDITIONAL_MODE) \
1016     template(java_lang_invoke_MemberName,MN_TRUSTED_MODE) \
1017     /*end*/
1018 
1019 #define IGNORE_REQ(req_expr) /* req_expr */
1020 #define ONE_PLUS(scope,value) 1+
1021 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS, IGNORE_REQ) 0;
1022 #define VALUE_COMMA(scope,value) scope::value,
1023 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA, IGNORE_REQ) 0 };
1024 #define STRING_NULL(scope,value) #value "\0"
1025 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL, IGNORE_REQ) };
1026 
1027 static bool advertise_con_value(int which) {

1125 
1126   Klass* caller = caller_jh == nullptr ? nullptr :
1127                      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
1128   Handle resolved = MethodHandles::resolve_MemberName(mname, caller, lookup_mode,
1129                                                       speculative_resolve == JNI_TRUE,
1130                                                       CHECK_NULL);
1131 
1132   if (resolved.is_null()) {
1133     int flags = java_lang_invoke_MemberName::flags(mname());
1134     int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
1135     if (!MethodHandles::ref_kind_is_valid(ref_kind)) {
1136       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "obsolete MemberName format");
1137     }
1138     if (speculative_resolve) {
1139       assert(!HAS_PENDING_EXCEPTION, "No exceptions expected when resolving speculatively");
1140       return nullptr;
1141     }
1142     if ((flags & ALL_KINDS) == IS_FIELD) {
1143       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "field resolution failed");
1144     } else if ((flags & ALL_KINDS) == IS_METHOD ||
1145                (flags & ALL_KINDS) == IS_CONSTRUCTOR) {
1146       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), "method resolution failed");
1147     } else {
1148       THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "resolution failed");
1149     }
1150   }
1151 
1152   return JNIHandles::make_local(THREAD, resolved());
1153 }
1154 JVM_END
1155 
1156 static jlong find_member_field_offset(oop mname, bool must_be_static, TRAPS) {
1157   if (mname == nullptr ||
1158       java_lang_invoke_MemberName::clazz(mname) == nullptr) {
1159     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "mname not resolved");
1160   } else {
1161     int flags = java_lang_invoke_MemberName::flags(mname);
1162     if ((flags & IS_FIELD) != 0 &&
1163         (must_be_static
1164          ? (flags & JVM_ACC_STATIC) != 0
1165          : (flags & JVM_ACC_STATIC) == 0)) {

 114     StubCodeMark mark(this, "MethodHandle::interpreter_entry", vmIntrinsics::name_at(iid));
 115     address entry = MethodHandles::generate_method_handle_interpreter_entry(_masm, iid);
 116     if (entry != nullptr) {
 117       Interpreter::set_entry_for_kind(mk, entry);
 118     }
 119     // If the entry is not set, it will throw AbstractMethodError.
 120   }
 121 }
 122 
 123 void MethodHandles::set_enabled(bool z) {
 124   if (_enabled != z) {
 125     guarantee(z, "can only enable once");
 126     _enabled = z;
 127   }
 128 }
 129 
 130 // MemberName support
 131 
 132 // import java_lang_invoke_MemberName.*
 133 enum {
 134   IS_METHOD             = java_lang_invoke_MemberName::MN_IS_METHOD,
 135   IS_OBJECT_CONSTRUCTOR = java_lang_invoke_MemberName::MN_IS_OBJECT_CONSTRUCTOR,
 136   IS_FIELD              = java_lang_invoke_MemberName::MN_IS_FIELD,
 137   IS_TYPE               = java_lang_invoke_MemberName::MN_IS_TYPE,
 138   CALLER_SENSITIVE      = java_lang_invoke_MemberName::MN_CALLER_SENSITIVE,
 139   TRUSTED_FINAL         = java_lang_invoke_MemberName::MN_TRUSTED_FINAL,
 140   HIDDEN_MEMBER        = java_lang_invoke_MemberName::MN_HIDDEN_MEMBER,
 141   FLAT_FIELD            = java_lang_invoke_MemberName::MN_FLAT_FIELD,
 142   NULL_RESTRICTED       = java_lang_invoke_MemberName::MN_NULL_RESTRICTED_FIELD,
 143   REFERENCE_KIND_SHIFT  = java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT,
 144   REFERENCE_KIND_MASK   = java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK,
 145   LM_UNCONDITIONAL      = java_lang_invoke_MemberName::MN_UNCONDITIONAL_MODE,
 146   LM_MODULE             = java_lang_invoke_MemberName::MN_MODULE_MODE,
 147   LM_TRUSTED            = java_lang_invoke_MemberName::MN_TRUSTED_MODE,
 148   ALL_KINDS      = IS_METHOD | IS_OBJECT_CONSTRUCTOR | IS_FIELD | IS_TYPE
 149 };
 150 
 151 int MethodHandles::ref_kind_to_flags(int ref_kind) {
 152   assert(ref_kind_is_valid(ref_kind), "%d", ref_kind);
 153   int flags = (ref_kind << REFERENCE_KIND_SHIFT);
 154   if (ref_kind_is_field(ref_kind)) {
 155     flags |= IS_FIELD;
 156   } else if (ref_kind_is_method(ref_kind)) {
 157     flags |= IS_METHOD;
 158   } else if (ref_kind == JVM_REF_newInvokeSpecial) {
 159     flags |= IS_OBJECT_CONSTRUCTOR;
 160   }
 161   return flags;
 162 }
 163 
 164 Handle MethodHandles::resolve_MemberName_type(Handle mname, Klass* caller, TRAPS) {
 165   Handle empty;
 166   Handle type(THREAD, java_lang_invoke_MemberName::type(mname()));
 167   if (!java_lang_String::is_instance(type())) {
 168     return type; // already resolved
 169   }
 170   Symbol* signature = java_lang_String::as_symbol_or_null(type());
 171   if (signature == nullptr) {
 172     return empty;  // no such signature exists in the VM
 173   }
 174   Handle resolved;
 175   int flags = java_lang_invoke_MemberName::flags(mname());
 176   switch (flags & ALL_KINDS) {
 177     case IS_METHOD:
 178     case IS_OBJECT_CONSTRUCTOR:
 179       resolved = SystemDictionary::find_method_handle_type(signature, caller, CHECK_(empty));
 180       break;
 181     case IS_FIELD:
 182       resolved = SystemDictionary::find_field_handle_type(signature, caller, CHECK_(empty));
 183       break;
 184     default:
 185       THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
 186   }
 187   if (resolved.is_null()) {
 188     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MemberName type", empty);
 189   }
 190   return resolved;
 191 }
 192 
 193 oop MethodHandles::init_MemberName(Handle mname, Handle target, TRAPS) {
 194   // This method is used from java.lang.invoke.MemberName constructors.
 195   // It fills in the new MemberName from a java.lang.reflect.Member.
 196   oop target_oop = target();
 197   Klass* target_klass = target_oop->klass();
 198   if (target_klass == vmClasses::reflect_Field_klass()) {

 300       m_klass = m_klass_non_interface;
 301     }
 302     if (lt_indy.is_enabled()) {
 303       ResourceMark rm;
 304       LogStream ls(lt_indy);
 305       ls.print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
 306                   Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
 307                   m_klass->internal_name(), vmindex);
 308        m->access_flags().print_on(&ls);
 309        if (m->is_default_method()) {
 310          ls.print("default");
 311        }
 312        ls.cr();
 313     }
 314     break;
 315 
 316   case CallInfo::direct_call:
 317     vmindex = Method::nonvirtual_vtable_index;
 318     if (m->is_static()) {
 319       flags |= IS_METHOD      | (JVM_REF_invokeStatic  << REFERENCE_KIND_SHIFT);
 320     } else if (m->is_object_constructor()) {
 321       flags |= IS_OBJECT_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
 322     } else {
 323       // "special" reflects that this is a direct call, not that it
 324       // necessarily originates from an invokespecial. We can also do
 325       // direct calls for private and/or final non-static methods.
 326       flags |= IS_METHOD      | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
 327     }
 328     break;
 329 
 330   default:  assert(false, "bad CallInfo");  return nullptr;
 331   }
 332 
 333   // @CallerSensitive annotation detected
 334   if (m->caller_sensitive()) {
 335     flags |= CALLER_SENSITIVE;
 336   }
 337 
 338   Handle resolved_method = info.resolved_method_name();
 339   assert(java_lang_invoke_ResolvedMethodName::vmtarget(resolved_method()) == m() || m->is_old(),
 340          "Should not change after link resolution");
 341 
 342   oop mname_oop = mname();
 343   java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
 344   java_lang_invoke_MemberName::set_method (mname_oop, resolved_method());
 345   java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);   // vtable/itable index
 346   java_lang_invoke_MemberName::set_clazz  (mname_oop, m_klass->java_mirror());
 347   // Note:  name and type can be lazily computed by resolve_MemberName,
 348   // if Java code needs them as resolved String and MethodType objects.
 349   // If relevant, the vtable or itable value is stored as vmindex.
 350   // This is done eagerly, since it is readily available without
 351   // constructing any new objects.
 352   return mname();
 353 }
 354 
 355 oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) {
 356   InstanceKlass* ik = fd.field_holder();
 357   int flags = (jushort)( fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS );
 358   flags |= IS_FIELD | ((fd.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT);
 359   if (fd.is_trusted_final()) flags |= TRUSTED_FINAL;
 360   if (fd.is_flat()) flags |= FLAT_FIELD;
 361   if (fd.is_null_free_inline_type()) flags |= NULL_RESTRICTED;
 362   if (is_setter)  flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT);
 363   int vmindex        = fd.offset();  // determines the field uniquely when combined with static bit
 364 
 365   oop mname_oop = mname();
 366   java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
 367   java_lang_invoke_MemberName::set_method (mname_oop, nullptr);
 368   java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);
 369   java_lang_invoke_MemberName::set_clazz  (mname_oop, ik->java_mirror());
 370 
 371   oop type = field_signature_type_or_null(fd.signature());
 372   oop name = field_name_or_null(fd.name());
 373   if (name != nullptr)
 374     java_lang_invoke_MemberName::set_name(mname_oop,   name);
 375   if (type != nullptr)
 376     java_lang_invoke_MemberName::set_type(mname_oop,   type);
 377   // Note:  name and type can be lazily computed by resolve_MemberName,
 378   // if Java code needs them as resolved String and Class objects.
 379   // Note that the incoming type oop might be pre-resolved (non-null).
 380   // The base clazz and field offset (vmindex) must be eagerly stored,
 381   // because they unambiguously identify the field.

 795         } else {
 796           assert(false, "ref_kind=%d", ref_kind);
 797         }
 798         if (HAS_PENDING_EXCEPTION) {
 799           if (speculative_resolve) {
 800             CLEAR_PENDING_EXCEPTION;
 801           }
 802           return empty;
 803         }
 804       }
 805       if (result.resolved_appendix().not_null()) {
 806         // The resolved MemberName must not be accompanied by an appendix argument,
 807         // since there is no way to bind this value into the MemberName.
 808         // Caller is responsible to prevent this from happening.
 809         THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
 810       }
 811       result.set_resolved_method_name(CHECK_(empty));
 812       oop mname2 = init_method_MemberName(mname, result);
 813       return Handle(THREAD, mname2);
 814     }
 815   case IS_OBJECT_CONSTRUCTOR:
 816     {
 817       CallInfo result;
 818       LinkInfo link_info(defc, name, type, caller, access_check, loader_constraint_check);
 819       {
 820         assert(!HAS_PENDING_EXCEPTION, "");
 821         if (name == vmSymbols::object_initializer_name() && type->is_void_method_signature()) {
 822           LinkResolver::resolve_special_call(result, Handle(), link_info, THREAD);
 823         } else if (name == vmSymbols::inline_factory_name()) {
 824           LinkResolver::resolve_static_call(result, link_info, false, THREAD);
 825         } else {
 826           break;                // will throw after end of switch
 827         }
 828         if (HAS_PENDING_EXCEPTION) {
 829           if (speculative_resolve) {
 830             CLEAR_PENDING_EXCEPTION;
 831           }
 832           return empty;
 833         }
 834       }
 835       assert(result.is_statically_bound(), "");
 836       result.set_resolved_method_name(CHECK_(empty));
 837       oop mname2 = init_method_MemberName(mname, result);
 838       return Handle(THREAD, mname2);
 839     }
 840   case IS_FIELD:
 841     {
 842       fieldDescriptor result; // find_field initializes fd if found
 843       {
 844         assert(!HAS_PENDING_EXCEPTION, "");

 866 // Resolving it plants a vmtarget/vmindex in it,
 867 // which refers directly to JVM internals.
 868 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {
 869   assert(java_lang_invoke_MemberName::is_instance(mname()), "");
 870 
 871   bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != nullptr);
 872   bool have_name = (java_lang_invoke_MemberName::name(mname()) != nullptr);
 873   bool have_type = (java_lang_invoke_MemberName::type(mname()) != nullptr);
 874   int flags      = java_lang_invoke_MemberName::flags(mname());
 875 
 876   if (suppress != 0) {
 877     if (suppress & _suppress_defc)  have_defc = true;
 878     if (suppress & _suppress_name)  have_name = true;
 879     if (suppress & _suppress_type)  have_type = true;
 880   }
 881 
 882   if (have_defc && have_name && have_type)  return;  // nothing needed
 883 
 884   switch (flags & ALL_KINDS) {
 885   case IS_METHOD:
 886   case IS_OBJECT_CONSTRUCTOR:
 887     {
 888       Method* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
 889       if (vmtarget == nullptr) {
 890         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand");
 891       }
 892       methodHandle m(THREAD, vmtarget);
 893       DEBUG_ONLY(vmtarget = nullptr);  // safety
 894       if (!have_defc) {
 895         InstanceKlass* defc = m->method_holder();
 896         java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
 897       }
 898       if (!have_name) {
 899         //not java_lang_String::create_from_symbol; let's intern member names
 900         oop name = StringTable::intern(m->name(), CHECK);
 901         java_lang_invoke_MemberName::set_name(mname(), name);
 902       }
 903       if (!have_type) {
 904         Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
 905         java_lang_invoke_MemberName::set_type(mname(), type());
 906       }

 988     trace_method_handle(_masm, qname);
 989     // LSan appears unable to keep track of qname, ignore it.
 990     LSAN_IGNORE_OBJECT(qname);
 991     // Note:  Don't free the allocated char array because it's used
 992     // during runtime.
 993   }
 994 }
 995 
 996 //
 997 // Here are the native methods in java.lang.invoke.MethodHandleNatives
 998 // They are the private interface between this JVM and the HotSpot-specific
 999 // Java code that implements JSR 292 method handles.
1000 //
1001 // Note:  We use a JVM_ENTRY macro to define each of these, for this is the way
1002 // that intrinsic (non-JNI) native methods are defined in HotSpot.
1003 //
1004 
1005 #ifndef PRODUCT
1006 #define EACH_NAMED_CON(template, requirement) \
1007     template(java_lang_invoke_MemberName,MN_IS_METHOD) \
1008     template(java_lang_invoke_MemberName,MN_IS_OBJECT_CONSTRUCTOR) \
1009     template(java_lang_invoke_MemberName,MN_IS_FIELD) \
1010     template(java_lang_invoke_MemberName,MN_IS_TYPE) \
1011     template(java_lang_invoke_MemberName,MN_CALLER_SENSITIVE) \
1012     template(java_lang_invoke_MemberName,MN_TRUSTED_FINAL) \
1013     template(java_lang_invoke_MemberName,MN_HIDDEN_MEMBER) \
1014     template(java_lang_invoke_MemberName,MN_FLAT_FIELD) \
1015     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_SHIFT) \
1016     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \
1017     template(java_lang_invoke_MemberName,MN_NESTMATE_CLASS) \
1018     template(java_lang_invoke_MemberName,MN_HIDDEN_CLASS) \
1019     template(java_lang_invoke_MemberName,MN_STRONG_LOADER_LINK) \
1020     template(java_lang_invoke_MemberName,MN_ACCESS_VM_ANNOTATIONS) \
1021     template(java_lang_invoke_MemberName,MN_MODULE_MODE) \
1022     template(java_lang_invoke_MemberName,MN_UNCONDITIONAL_MODE) \
1023     template(java_lang_invoke_MemberName,MN_TRUSTED_MODE) \
1024     /*end*/
1025 
1026 #define IGNORE_REQ(req_expr) /* req_expr */
1027 #define ONE_PLUS(scope,value) 1+
1028 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS, IGNORE_REQ) 0;
1029 #define VALUE_COMMA(scope,value) scope::value,
1030 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA, IGNORE_REQ) 0 };
1031 #define STRING_NULL(scope,value) #value "\0"
1032 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL, IGNORE_REQ) };
1033 
1034 static bool advertise_con_value(int which) {

1132 
1133   Klass* caller = caller_jh == nullptr ? nullptr :
1134                      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
1135   Handle resolved = MethodHandles::resolve_MemberName(mname, caller, lookup_mode,
1136                                                       speculative_resolve == JNI_TRUE,
1137                                                       CHECK_NULL);
1138 
1139   if (resolved.is_null()) {
1140     int flags = java_lang_invoke_MemberName::flags(mname());
1141     int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
1142     if (!MethodHandles::ref_kind_is_valid(ref_kind)) {
1143       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "obsolete MemberName format");
1144     }
1145     if (speculative_resolve) {
1146       assert(!HAS_PENDING_EXCEPTION, "No exceptions expected when resolving speculatively");
1147       return nullptr;
1148     }
1149     if ((flags & ALL_KINDS) == IS_FIELD) {
1150       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "field resolution failed");
1151     } else if ((flags & ALL_KINDS) == IS_METHOD ||
1152                (flags & ALL_KINDS) == IS_OBJECT_CONSTRUCTOR) {
1153       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), "method resolution failed");
1154     } else {
1155       THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "resolution failed");
1156     }
1157   }
1158 
1159   return JNIHandles::make_local(THREAD, resolved());
1160 }
1161 JVM_END
1162 
1163 static jlong find_member_field_offset(oop mname, bool must_be_static, TRAPS) {
1164   if (mname == nullptr ||
1165       java_lang_invoke_MemberName::clazz(mname) == nullptr) {
1166     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "mname not resolved");
1167   } else {
1168     int flags = java_lang_invoke_MemberName::flags(mname);
1169     if ((flags & IS_FIELD) != 0 &&
1170         (must_be_static
1171          ? (flags & JVM_ACC_STATIC) != 0
1172          : (flags & JVM_ACC_STATIC) == 0)) {
< prev index next >