< prev index next >

src/hotspot/share/prims/methodHandles.cpp

Print this page

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


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

 296       assert(info.resolved_klass()->is_subtype_of(m_klass_non_interface), "virtual call must be type-safe");
 297       m_klass = m_klass_non_interface;
 298     }
 299     if (lt_indy.is_enabled()) {
 300       ResourceMark rm;
 301       LogStream ls(lt_indy);
 302       ls.print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
 303                   Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
 304                   m_klass->internal_name(), vmindex);
 305        m->access_flags().print_on(&ls);
 306        if (m->is_default_method()) {
 307          ls.print("default");
 308        }
 309        ls.cr();
 310     }
 311     break;
 312 
 313   case CallInfo::direct_call:
 314     vmindex = Method::nonvirtual_vtable_index;
 315     if (m->is_static()) {
 316       assert(!m->is_static_initializer(), "Cannot be static initializer");
 317       flags |= IS_METHOD      | (JVM_REF_invokeStatic  << REFERENCE_KIND_SHIFT);
 318     } else if (m->is_object_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.

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

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

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

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

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

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

 298       assert(info.resolved_klass()->is_subtype_of(m_klass_non_interface), "virtual call must be type-safe");
 299       m_klass = m_klass_non_interface;
 300     }
 301     if (lt_indy.is_enabled()) {
 302       ResourceMark rm;
 303       LogStream ls(lt_indy);
 304       ls.print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
 305                   Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
 306                   m_klass->internal_name(), vmindex);
 307        m->access_flags().print_on(&ls);
 308        if (m->is_default_method()) {
 309          ls.print("default");
 310        }
 311        ls.cr();
 312     }
 313     break;
 314 
 315   case CallInfo::direct_call:
 316     vmindex = Method::nonvirtual_vtable_index;
 317     if (m->is_static()) {
 318       assert(!m->is_class_initializer(), "Cannot be static initializer");
 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());
 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.

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

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

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

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