comparison src/share/vm/prims/methodHandles.cpp @ 2491:0654ee04b214

Merge with OpenJDK.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 22 Apr 2011 15:30:53 +0200
parents 328926869b15
children 2a23b1b5a0a8
comparison
equal deleted inserted replaced
2490:29246b1d2d3c 2491:0654ee04b214
110 110
111 //------------------------------------------------------------------------------ 111 //------------------------------------------------------------------------------
112 // MethodHandles::generate_adapters 112 // MethodHandles::generate_adapters
113 // 113 //
114 void MethodHandles::generate_adapters() { 114 void MethodHandles::generate_adapters() {
115 if (!EnableMethodHandles || SystemDictionary::MethodHandle_klass() == NULL) return; 115 if (!EnableInvokeDynamic || SystemDictionary::MethodHandle_klass() == NULL) return;
116 116
117 assert(_adapter_code == NULL, "generate only once"); 117 assert(_adapter_code == NULL, "generate only once");
118 118
119 ResourceMark rm; 119 ResourceMark rm;
120 TraceTime timer("MethodHandles adapters generation", TraceStartupTime); 120 TraceTime timer("MethodHandles adapters generation", TraceStartupTime);
141 } 141 }
142 142
143 143
144 void MethodHandles::set_enabled(bool z) { 144 void MethodHandles::set_enabled(bool z) {
145 if (_enabled != z) { 145 if (_enabled != z) {
146 guarantee(z && EnableMethodHandles, "can only enable once, and only if -XX:+EnableMethodHandles"); 146 guarantee(z && EnableInvokeDynamic, "can only enable once, and only if -XX:+EnableInvokeDynamic");
147 _enabled = z; 147 _enabled = z;
148 } 148 }
149 } 149 }
150 150
151 // Note: A method which does not have a TRAPS argument cannot block in the GC 151 // Note: A method which does not have a TRAPS argument cannot block in the GC
161 // this DMH performs no dispatch; it is directly bound to a methodOop 161 // this DMH performs no dispatch; it is directly bound to a methodOop
162 // A MemberName may either be directly bound to a methodOop, 162 // A MemberName may either be directly bound to a methodOop,
163 // or it may use the klass/index form; both forms mean the same thing. 163 // or it may use the klass/index form; both forms mean the same thing.
164 methodOop m = decode_methodOop(methodOop(vmtarget), decode_flags_result); 164 methodOop m = decode_methodOop(methodOop(vmtarget), decode_flags_result);
165 if ((decode_flags_result & _dmf_has_receiver) != 0 165 if ((decode_flags_result & _dmf_has_receiver) != 0
166 && java_dyn_MethodType::is_instance(mtype)) { 166 && java_lang_invoke_MethodType::is_instance(mtype)) {
167 // Extract receiver type restriction from mtype.ptypes[0]. 167 // Extract receiver type restriction from mtype.ptypes[0].
168 objArrayOop ptypes = java_dyn_MethodType::ptypes(mtype); 168 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype);
169 oop ptype0 = (ptypes == NULL || ptypes->length() < 1) ? oop(NULL) : ptypes->obj_at(0); 169 oop ptype0 = (ptypes == NULL || ptypes->length() < 1) ? oop(NULL) : ptypes->obj_at(0);
170 if (java_lang_Class::is_instance(ptype0)) 170 if (java_lang_Class::is_instance(ptype0))
171 receiver_limit_result = java_lang_Class::as_klassOop(ptype0); 171 receiver_limit_result = java_lang_Class::as_klassOop(ptype0);
172 } 172 }
173 if (vmindex == methodOopDesc::nonvirtual_vtable_index) { 173 if (vmindex == methodOopDesc::nonvirtual_vtable_index) {
197 197
198 // MemberName and DirectMethodHandle have the same linkage to the JVM internals. 198 // MemberName and DirectMethodHandle have the same linkage to the JVM internals.
199 // (MemberName is the non-operational name used for queries and setup.) 199 // (MemberName is the non-operational name used for queries and setup.)
200 200
201 methodOop MethodHandles::decode_DirectMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { 201 methodOop MethodHandles::decode_DirectMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) {
202 oop vmtarget = sun_dyn_DirectMethodHandle::vmtarget(mh); 202 oop vmtarget = java_lang_invoke_DirectMethodHandle::vmtarget(mh);
203 int vmindex = sun_dyn_DirectMethodHandle::vmindex(mh); 203 int vmindex = java_lang_invoke_DirectMethodHandle::vmindex(mh);
204 oop mtype = sun_dyn_DirectMethodHandle::type(mh); 204 oop mtype = java_lang_invoke_DirectMethodHandle::type(mh);
205 return decode_vmtarget(vmtarget, vmindex, mtype, receiver_limit_result, decode_flags_result); 205 return decode_vmtarget(vmtarget, vmindex, mtype, receiver_limit_result, decode_flags_result);
206 } 206 }
207 207
208 methodOop MethodHandles::decode_BoundMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { 208 methodOop MethodHandles::decode_BoundMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) {
209 assert(sun_dyn_BoundMethodHandle::is_instance(mh), ""); 209 assert(java_lang_invoke_BoundMethodHandle::is_instance(mh), "");
210 assert(mh->klass() != SystemDictionary::AdapterMethodHandle_klass(), ""); 210 assert(mh->klass() != SystemDictionary::AdapterMethodHandle_klass(), "");
211 for (oop bmh = mh;;) { 211 for (oop bmh = mh;;) {
212 // Bound MHs can be stacked to bind several arguments. 212 // Bound MHs can be stacked to bind several arguments.
213 oop target = java_dyn_MethodHandle::vmtarget(bmh); 213 oop target = java_lang_invoke_MethodHandle::vmtarget(bmh);
214 if (target == NULL) return NULL; 214 if (target == NULL) return NULL;
215 decode_flags_result |= MethodHandles::_dmf_binds_argument; 215 decode_flags_result |= MethodHandles::_dmf_binds_argument;
216 klassOop tk = target->klass(); 216 klassOop tk = target->klass();
217 if (tk == SystemDictionary::BoundMethodHandle_klass()) { 217 if (tk == SystemDictionary::BoundMethodHandle_klass()) {
218 bmh = target; 218 bmh = target;
219 continue; 219 continue;
220 } else { 220 } else {
221 if (java_dyn_MethodHandle::is_subclass(tk)) { 221 if (java_lang_invoke_MethodHandle::is_subclass(tk)) {
222 //assert(tk == SystemDictionary::DirectMethodHandle_klass(), "end of BMH chain must be DMH"); 222 //assert(tk == SystemDictionary::DirectMethodHandle_klass(), "end of BMH chain must be DMH");
223 return decode_MethodHandle(target, receiver_limit_result, decode_flags_result); 223 return decode_MethodHandle(target, receiver_limit_result, decode_flags_result);
224 } else { 224 } else {
225 // Optimized case: binding a receiver to a non-dispatched DMH 225 // Optimized case: binding a receiver to a non-dispatched DMH
226 // short-circuits directly to the methodOop. 226 // short-circuits directly to the methodOop.
238 238
239 methodOop MethodHandles::decode_AdapterMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { 239 methodOop MethodHandles::decode_AdapterMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) {
240 assert(mh->klass() == SystemDictionary::AdapterMethodHandle_klass(), ""); 240 assert(mh->klass() == SystemDictionary::AdapterMethodHandle_klass(), "");
241 for (oop amh = mh;;) { 241 for (oop amh = mh;;) {
242 // Adapter MHs can be stacked to convert several arguments. 242 // Adapter MHs can be stacked to convert several arguments.
243 int conv_op = adapter_conversion_op(sun_dyn_AdapterMethodHandle::conversion(amh)); 243 int conv_op = adapter_conversion_op(java_lang_invoke_AdapterMethodHandle::conversion(amh));
244 decode_flags_result |= (_dmf_adapter_lsb << conv_op) & _DMF_ADAPTER_MASK; 244 decode_flags_result |= (_dmf_adapter_lsb << conv_op) & _DMF_ADAPTER_MASK;
245 oop target = java_dyn_MethodHandle::vmtarget(amh); 245 oop target = java_lang_invoke_MethodHandle::vmtarget(amh);
246 if (target == NULL) return NULL; 246 if (target == NULL) return NULL;
247 klassOop tk = target->klass(); 247 klassOop tk = target->klass();
248 if (tk == SystemDictionary::AdapterMethodHandle_klass()) { 248 if (tk == SystemDictionary::AdapterMethodHandle_klass()) {
249 amh = target; 249 amh = target;
250 continue; 250 continue;
256 } 256 }
257 257
258 methodOop MethodHandles::decode_MethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { 258 methodOop MethodHandles::decode_MethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) {
259 if (mh == NULL) return NULL; 259 if (mh == NULL) return NULL;
260 klassOop mhk = mh->klass(); 260 klassOop mhk = mh->klass();
261 assert(java_dyn_MethodHandle::is_subclass(mhk), "must be a MethodHandle"); 261 assert(java_lang_invoke_MethodHandle::is_subclass(mhk), "must be a MethodHandle");
262 if (mhk == SystemDictionary::DirectMethodHandle_klass()) { 262 if (mhk == SystemDictionary::DirectMethodHandle_klass()) {
263 return decode_DirectMethodHandle(mh, receiver_limit_result, decode_flags_result); 263 return decode_DirectMethodHandle(mh, receiver_limit_result, decode_flags_result);
264 } else if (mhk == SystemDictionary::BoundMethodHandle_klass()) { 264 } else if (mhk == SystemDictionary::BoundMethodHandle_klass()) {
265 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); 265 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result);
266 } else if (mhk == SystemDictionary::AdapterMethodHandle_klass()) { 266 } else if (mhk == SystemDictionary::AdapterMethodHandle_klass()) {
267 return decode_AdapterMethodHandle(mh, receiver_limit_result, decode_flags_result); 267 return decode_AdapterMethodHandle(mh, receiver_limit_result, decode_flags_result);
268 } else if (sun_dyn_BoundMethodHandle::is_subclass(mhk)) { 268 } else if (java_lang_invoke_BoundMethodHandle::is_subclass(mhk)) {
269 // could be a JavaMethodHandle (but not an adapter MH) 269 // could be a JavaMethodHandle (but not an adapter MH)
270 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); 270 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result);
271 } else { 271 } else {
272 assert(false, "cannot parse this MH"); 272 assert(false, "cannot parse this MH");
273 return NULL; // random MH? 273 return NULL; // random MH?
306 if (xk == Universe::methodKlassObj()) { 306 if (xk == Universe::methodKlassObj()) {
307 return decode_methodOop((methodOop) x, decode_flags_result); 307 return decode_methodOop((methodOop) x, decode_flags_result);
308 } else if (xk == SystemDictionary::MemberName_klass()) { 308 } else if (xk == SystemDictionary::MemberName_klass()) {
309 // Note: This only works if the MemberName has already been resolved. 309 // Note: This only works if the MemberName has already been resolved.
310 return decode_MemberName(x, receiver_limit_result, decode_flags_result); 310 return decode_MemberName(x, receiver_limit_result, decode_flags_result);
311 } else if (java_dyn_MethodHandle::is_subclass(xk)) { 311 } else if (java_lang_invoke_MethodHandle::is_subclass(xk)) {
312 return decode_MethodHandle(x, receiver_limit_result, decode_flags_result); 312 return decode_MethodHandle(x, receiver_limit_result, decode_flags_result);
313 } else if (xk == SystemDictionary::reflect_Method_klass()) { 313 } else if (xk == SystemDictionary::reflect_Method_klass()) {
314 oop clazz = java_lang_reflect_Method::clazz(x); 314 oop clazz = java_lang_reflect_Method::clazz(x);
315 int slot = java_lang_reflect_Method::slot(x); 315 int slot = java_lang_reflect_Method::slot(x);
316 klassOop k = java_lang_Class::as_klassOop(clazz); 316 klassOop k = java_lang_Class::as_klassOop(clazz);
325 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot), 325 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot),
326 decode_flags_result); 326 decode_flags_result);
327 } else { 327 } else {
328 // unrecognized object 328 // unrecognized object
329 assert(!x->is_method(), "already checked"); 329 assert(!x->is_method(), "already checked");
330 assert(!sun_dyn_MemberName::is_instance(x), "already checked"); 330 assert(!java_lang_invoke_MemberName::is_instance(x), "already checked");
331 } 331 }
332 return NULL; 332 return NULL;
333 } 333 }
334 334
335 335
336 int MethodHandles::decode_MethodHandle_stack_pushes(oop mh) { 336 int MethodHandles::decode_MethodHandle_stack_pushes(oop mh) {
337 if (mh->klass() == SystemDictionary::DirectMethodHandle_klass()) 337 if (mh->klass() == SystemDictionary::DirectMethodHandle_klass())
338 return 0; // no push/pop 338 return 0; // no push/pop
339 int this_vmslots = java_dyn_MethodHandle::vmslots(mh); 339 int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh);
340 int last_vmslots = 0; 340 int last_vmslots = 0;
341 oop last_mh = mh; 341 oop last_mh = mh;
342 for (;;) { 342 for (;;) {
343 oop target = java_dyn_MethodHandle::vmtarget(last_mh); 343 oop target = java_lang_invoke_MethodHandle::vmtarget(last_mh);
344 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { 344 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) {
345 last_vmslots = java_dyn_MethodHandle::vmslots(target); 345 last_vmslots = java_lang_invoke_MethodHandle::vmslots(target);
346 break; 346 break;
347 } else if (!java_dyn_MethodHandle::is_instance(target)) { 347 } else if (!java_lang_invoke_MethodHandle::is_instance(target)) {
348 // might be klass or method 348 // might be klass or method
349 assert(target->is_method(), "must get here with a direct ref to method"); 349 assert(target->is_method(), "must get here with a direct ref to method");
350 last_vmslots = methodOop(target)->size_of_parameters(); 350 last_vmslots = methodOop(target)->size_of_parameters();
351 break; 351 break;
352 } 352 }
359 } 359 }
360 360
361 361
362 // MemberName support 362 // MemberName support
363 363
364 // import sun_dyn_MemberName.* 364 // import java_lang_invoke_MemberName.*
365 enum { 365 enum {
366 IS_METHOD = sun_dyn_MemberName::MN_IS_METHOD, 366 IS_METHOD = java_lang_invoke_MemberName::MN_IS_METHOD,
367 IS_CONSTRUCTOR = sun_dyn_MemberName::MN_IS_CONSTRUCTOR, 367 IS_CONSTRUCTOR = java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR,
368 IS_FIELD = sun_dyn_MemberName::MN_IS_FIELD, 368 IS_FIELD = java_lang_invoke_MemberName::MN_IS_FIELD,
369 IS_TYPE = sun_dyn_MemberName::MN_IS_TYPE, 369 IS_TYPE = java_lang_invoke_MemberName::MN_IS_TYPE,
370 SEARCH_SUPERCLASSES = sun_dyn_MemberName::MN_SEARCH_SUPERCLASSES, 370 SEARCH_SUPERCLASSES = java_lang_invoke_MemberName::MN_SEARCH_SUPERCLASSES,
371 SEARCH_INTERFACES = sun_dyn_MemberName::MN_SEARCH_INTERFACES, 371 SEARCH_INTERFACES = java_lang_invoke_MemberName::MN_SEARCH_INTERFACES,
372 ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE, 372 ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE,
373 VM_INDEX_UNINITIALIZED = sun_dyn_MemberName::VM_INDEX_UNINITIALIZED 373 VM_INDEX_UNINITIALIZED = java_lang_invoke_MemberName::VM_INDEX_UNINITIALIZED
374 }; 374 };
375 375
376 Handle MethodHandles::new_MemberName(TRAPS) { 376 Handle MethodHandles::new_MemberName(TRAPS) {
377 Handle empty; 377 Handle empty;
378 instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass()); 378 instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass());
403 oop vmtarget = m; 403 oop vmtarget = m;
404 int vmindex = methodOopDesc::invalid_vtable_index; // implies no info yet 404 int vmindex = methodOopDesc::invalid_vtable_index; // implies no info yet
405 if (!do_dispatch || (flags & IS_CONSTRUCTOR) || m->can_be_statically_bound()) 405 if (!do_dispatch || (flags & IS_CONSTRUCTOR) || m->can_be_statically_bound())
406 vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch 406 vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch
407 assert(vmindex != VM_INDEX_UNINITIALIZED, "Java sentinel value"); 407 assert(vmindex != VM_INDEX_UNINITIALIZED, "Java sentinel value");
408 sun_dyn_MemberName::set_vmtarget(mname_oop, vmtarget); 408 java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget);
409 sun_dyn_MemberName::set_vmindex(mname_oop, vmindex); 409 java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);
410 sun_dyn_MemberName::set_flags(mname_oop, flags); 410 java_lang_invoke_MemberName::set_flags(mname_oop, flags);
411 sun_dyn_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror()); 411 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror());
412 } 412 }
413 413
414 void MethodHandles::init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset) { 414 void MethodHandles::init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset) {
415 int flags = (IS_FIELD | (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS )); 415 int flags = (IS_FIELD | (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ));
416 oop vmtarget = field_holder; 416 oop vmtarget = field_holder;
417 int vmindex = offset; // determines the field uniquely when combined with static bit 417 int vmindex = offset; // determines the field uniquely when combined with static bit
418 assert(vmindex != VM_INDEX_UNINITIALIZED, "bad alias on vmindex"); 418 assert(vmindex != VM_INDEX_UNINITIALIZED, "bad alias on vmindex");
419 sun_dyn_MemberName::set_vmtarget(mname_oop, vmtarget); 419 java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget);
420 sun_dyn_MemberName::set_vmindex(mname_oop, vmindex); 420 java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);
421 sun_dyn_MemberName::set_flags(mname_oop, flags); 421 java_lang_invoke_MemberName::set_flags(mname_oop, flags);
422 sun_dyn_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); 422 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror());
423 } 423 }
424 424
425 425
426 methodOop MethodHandles::decode_MemberName(oop mname, klassOop& receiver_limit_result, int& decode_flags_result) { 426 methodOop MethodHandles::decode_MemberName(oop mname, klassOop& receiver_limit_result, int& decode_flags_result) {
427 int flags = sun_dyn_MemberName::flags(mname); 427 int flags = java_lang_invoke_MemberName::flags(mname);
428 if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) == 0) return NULL; // not invocable 428 if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) == 0) return NULL; // not invocable
429 oop vmtarget = sun_dyn_MemberName::vmtarget(mname); 429 oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname);
430 int vmindex = sun_dyn_MemberName::vmindex(mname); 430 int vmindex = java_lang_invoke_MemberName::vmindex(mname);
431 if (vmindex == VM_INDEX_UNINITIALIZED) return NULL; // not resolved 431 if (vmindex == VM_INDEX_UNINITIALIZED) return NULL; // not resolved
432 methodOop m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit_result, decode_flags_result); 432 methodOop m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit_result, decode_flags_result);
433 oop clazz = sun_dyn_MemberName::clazz(mname); 433 oop clazz = java_lang_invoke_MemberName::clazz(mname);
434 if (clazz != NULL && java_lang_Class::is_instance(clazz)) { 434 if (clazz != NULL && java_lang_Class::is_instance(clazz)) {
435 klassOop klass = java_lang_Class::as_klassOop(clazz); 435 klassOop klass = java_lang_Class::as_klassOop(clazz);
436 if (klass != NULL) receiver_limit_result = klass; 436 if (klass != NULL) receiver_limit_result = klass;
437 } 437 }
438 return m; 438 return m;
440 440
441 // convert the external string or reflective type to an internal signature 441 // convert the external string or reflective type to an internal signature
442 Symbol* MethodHandles::convert_to_signature(oop type_str, 442 Symbol* MethodHandles::convert_to_signature(oop type_str,
443 bool polymorphic, 443 bool polymorphic,
444 TRAPS) { 444 TRAPS) {
445 if (java_dyn_MethodType::is_instance(type_str)) { 445 if (java_lang_invoke_MethodType::is_instance(type_str)) {
446 return java_dyn_MethodType::as_signature(type_str, polymorphic, CHECK_NULL); 446 return java_lang_invoke_MethodType::as_signature(type_str, polymorphic, CHECK_NULL);
447 } else if (java_lang_Class::is_instance(type_str)) { 447 } else if (java_lang_Class::is_instance(type_str)) {
448 return java_lang_Class::as_signature(type_str, false, CHECK_NULL); 448 return java_lang_Class::as_signature(type_str, false, CHECK_NULL);
449 } else if (java_lang_String::is_instance(type_str)) { 449 } else if (java_lang_String::is_instance(type_str)) {
450 if (polymorphic) { 450 if (polymorphic) {
451 return java_lang_String::as_symbol(type_str, CHECK_NULL); 451 return java_lang_String::as_symbol(type_str, CHECK_NULL);
459 459
460 // An unresolved member name is a mere symbolic reference. 460 // An unresolved member name is a mere symbolic reference.
461 // Resolving it plants a vmtarget/vmindex in it, 461 // Resolving it plants a vmtarget/vmindex in it,
462 // which refers dirctly to JVM internals. 462 // which refers dirctly to JVM internals.
463 void MethodHandles::resolve_MemberName(Handle mname, TRAPS) { 463 void MethodHandles::resolve_MemberName(Handle mname, TRAPS) {
464 assert(sun_dyn_MemberName::is_instance(mname()), ""); 464 assert(java_lang_invoke_MemberName::is_instance(mname()), "");
465 #ifdef ASSERT 465 #ifdef ASSERT
466 // If this assert throws, renegotiate the sentinel value used by the Java code, 466 // If this assert throws, renegotiate the sentinel value used by the Java code,
467 // so that it is distinct from any valid vtable index value, and any special 467 // so that it is distinct from any valid vtable index value, and any special
468 // values defined in methodOopDesc::VtableIndexFlag. 468 // values defined in methodOopDesc::VtableIndexFlag.
469 // The point of the slop is to give the Java code and the JVM some room 469 // The point of the slop is to give the Java code and the JVM some room
470 // to independently specify sentinel values. 470 // to independently specify sentinel values.
471 const int sentinel_slop = 10; 471 const int sentinel_slop = 10;
472 const int sentinel_limit = methodOopDesc::highest_unused_vtable_index_value - sentinel_slop; 472 const int sentinel_limit = methodOopDesc::highest_unused_vtable_index_value - sentinel_slop;
473 assert(VM_INDEX_UNINITIALIZED < sentinel_limit, "Java sentinel != JVM sentinels"); 473 assert(VM_INDEX_UNINITIALIZED < sentinel_limit, "Java sentinel != JVM sentinels");
474 #endif 474 #endif
475 if (sun_dyn_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED) 475 if (java_lang_invoke_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED)
476 return; // already resolved 476 return; // already resolved
477 oop defc_oop = sun_dyn_MemberName::clazz(mname()); 477 oop defc_oop = java_lang_invoke_MemberName::clazz(mname());
478 oop name_str = sun_dyn_MemberName::name(mname()); 478 oop name_str = java_lang_invoke_MemberName::name(mname());
479 oop type_str = sun_dyn_MemberName::type(mname()); 479 oop type_str = java_lang_invoke_MemberName::type(mname());
480 int flags = sun_dyn_MemberName::flags(mname()); 480 int flags = java_lang_invoke_MemberName::flags(mname());
481 481
482 if (defc_oop == NULL || name_str == NULL || type_str == NULL) { 482 if (defc_oop == NULL || name_str == NULL || type_str == NULL) {
483 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve"); 483 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve");
484 } 484 }
485 klassOop defc_klassOop = java_lang_Class::as_klassOop(defc_oop); 485 klassOop defc_klassOop = java_lang_Class::as_klassOop(defc_oop);
508 methodOopDesc::is_method_handle_invoke_name(name))) 508 methodOopDesc::is_method_handle_invoke_name(name)))
509 polymorphic_signature = true; 509 polymorphic_signature = true;
510 510
511 // convert the external string or reflective type to an internal signature 511 // convert the external string or reflective type to an internal signature
512 TempNewSymbol type = convert_to_signature(type_str, polymorphic_signature, CHECK); 512 TempNewSymbol type = convert_to_signature(type_str, polymorphic_signature, CHECK);
513 if (java_dyn_MethodType::is_instance(type_str) && polymorphic_signature) { 513 if (java_lang_invoke_MethodType::is_instance(type_str) && polymorphic_signature) {
514 polymorphic_method_type = Handle(THREAD, type_str); //preserve exactly 514 polymorphic_method_type = Handle(THREAD, type_str); //preserve exactly
515 } 515 }
516 516
517 if (type == NULL) return; // no such signature exists in the VM 517 if (type == NULL) return; // no such signature exists in the VM
518 type_str = NULL; // safety 518 type_str = NULL; // safety
555 vmtarget = m(); 555 vmtarget = m();
556 } else { 556 } else {
557 vmtarget = result.resolved_klass()->as_klassOop(); 557 vmtarget = result.resolved_klass()->as_klassOop();
558 } 558 }
559 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); 559 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS);
560 sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); 560 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget);
561 sun_dyn_MemberName::set_vmindex(mname(), vmindex); 561 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex);
562 sun_dyn_MemberName::set_modifiers(mname(), mods); 562 java_lang_invoke_MemberName::set_modifiers(mname(), mods);
563 DEBUG_ONLY(int junk; klassOop junk2); 563 DEBUG_ONLY(int junk; klassOop junk2);
564 assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(), 564 assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(),
565 "properly stored for later decoding"); 565 "properly stored for later decoding");
566 return; 566 return;
567 } 567 }
584 assert(result.is_statically_bound(), ""); 584 assert(result.is_statically_bound(), "");
585 methodHandle m = result.resolved_method(); 585 methodHandle m = result.resolved_method();
586 oop vmtarget = m(); 586 oop vmtarget = m();
587 int vmindex = methodOopDesc::nonvirtual_vtable_index; 587 int vmindex = methodOopDesc::nonvirtual_vtable_index;
588 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); 588 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS);
589 sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); 589 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget);
590 sun_dyn_MemberName::set_vmindex(mname(), vmindex); 590 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex);
591 sun_dyn_MemberName::set_modifiers(mname(), mods); 591 java_lang_invoke_MemberName::set_modifiers(mname(), mods);
592 DEBUG_ONLY(int junk; klassOop junk2); 592 DEBUG_ONLY(int junk; klassOop junk2);
593 assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(), 593 assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(),
594 "properly stored for later decoding"); 594 "properly stored for later decoding");
595 return; 595 return;
596 } 596 }
603 if (sel_klass.is_null()) return; 603 if (sel_klass.is_null()) return;
604 oop vmtarget = sel_klass->as_klassOop(); 604 oop vmtarget = sel_klass->as_klassOop();
605 int vmindex = fd.offset(); 605 int vmindex = fd.offset();
606 int mods = (fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS); 606 int mods = (fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS);
607 if (vmindex == VM_INDEX_UNINITIALIZED) break; // should not happen 607 if (vmindex == VM_INDEX_UNINITIALIZED) break; // should not happen
608 sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); 608 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget);
609 sun_dyn_MemberName::set_vmindex(mname(), vmindex); 609 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex);
610 sun_dyn_MemberName::set_modifiers(mname(), mods); 610 java_lang_invoke_MemberName::set_modifiers(mname(), mods);
611 return; 611 return;
612 } 612 }
613 default: 613 default:
614 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); 614 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format");
615 } 615 }
616 616
617 // Second chance. 617 // Second chance.
618 if (polymorphic_method_type.not_null()) { 618 if (polymorphic_method_type.not_null()) {
619 // Look on a non-null class loader. 619 // Look on a non-null class loader.
620 Handle cur_class_loader; 620 Handle cur_class_loader;
621 const int nptypes = java_dyn_MethodType::ptype_count(polymorphic_method_type()); 621 const int nptypes = java_lang_invoke_MethodType::ptype_count(polymorphic_method_type());
622 for (int i = 0; i <= nptypes; i++) { 622 for (int i = 0; i <= nptypes; i++) {
623 oop type_mirror; 623 oop type_mirror;
624 if (i < nptypes) type_mirror = java_dyn_MethodType::ptype(polymorphic_method_type(), i); 624 if (i < nptypes) type_mirror = java_lang_invoke_MethodType::ptype(polymorphic_method_type(), i);
625 else type_mirror = java_dyn_MethodType::rtype(polymorphic_method_type()); 625 else type_mirror = java_lang_invoke_MethodType::rtype(polymorphic_method_type());
626 klassOop example_type = java_lang_Class::as_klassOop(type_mirror); 626 klassOop example_type = java_lang_Class::as_klassOop(type_mirror);
627 if (example_type == NULL) continue; 627 if (example_type == NULL) continue;
628 oop class_loader = Klass::cast(example_type)->class_loader(); 628 oop class_loader = Klass::cast(example_type)->class_loader();
629 if (class_loader == NULL || class_loader == cur_class_loader()) continue; 629 if (class_loader == NULL || class_loader == cur_class_loader()) continue;
630 cur_class_loader = Handle(THREAD, class_loader); 630 cur_class_loader = Handle(THREAD, class_loader);
637 m = NULL; 637 m = NULL;
638 // try again with a different class loader... 638 // try again with a different class loader...
639 } 639 }
640 if (m != NULL) { 640 if (m != NULL) {
641 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); 641 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS);
642 sun_dyn_MemberName::set_vmtarget(mname(), m); 642 java_lang_invoke_MemberName::set_vmtarget(mname(), m);
643 sun_dyn_MemberName::set_vmindex(mname(), m->vtable_index()); 643 java_lang_invoke_MemberName::set_vmindex(mname(), m->vtable_index());
644 sun_dyn_MemberName::set_modifiers(mname(), mods); 644 java_lang_invoke_MemberName::set_modifiers(mname(), mods);
645 return; 645 return;
646 } 646 }
647 } 647 }
648 } 648 }
649 } 649 }
651 // Conversely, a member name which is only initialized from JVM internals 651 // Conversely, a member name which is only initialized from JVM internals
652 // may have null defc, name, and type fields. 652 // may have null defc, name, and type fields.
653 // Resolving it plants a vmtarget/vmindex in it, 653 // Resolving it plants a vmtarget/vmindex in it,
654 // which refers directly to JVM internals. 654 // which refers directly to JVM internals.
655 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) { 655 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {
656 assert(sun_dyn_MemberName::is_instance(mname()), ""); 656 assert(java_lang_invoke_MemberName::is_instance(mname()), "");
657 oop vmtarget = sun_dyn_MemberName::vmtarget(mname()); 657 oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
658 int vmindex = sun_dyn_MemberName::vmindex(mname()); 658 int vmindex = java_lang_invoke_MemberName::vmindex(mname());
659 if (vmtarget == NULL || vmindex == VM_INDEX_UNINITIALIZED) { 659 if (vmtarget == NULL || vmindex == VM_INDEX_UNINITIALIZED) {
660 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand"); 660 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand");
661 } 661 }
662 662
663 bool have_defc = (sun_dyn_MemberName::clazz(mname()) != NULL); 663 bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != NULL);
664 bool have_name = (sun_dyn_MemberName::name(mname()) != NULL); 664 bool have_name = (java_lang_invoke_MemberName::name(mname()) != NULL);
665 bool have_type = (sun_dyn_MemberName::type(mname()) != NULL); 665 bool have_type = (java_lang_invoke_MemberName::type(mname()) != NULL);
666 int flags = sun_dyn_MemberName::flags(mname()); 666 int flags = java_lang_invoke_MemberName::flags(mname());
667 667
668 if (suppress != 0) { 668 if (suppress != 0) {
669 if (suppress & _suppress_defc) have_defc = true; 669 if (suppress & _suppress_defc) have_defc = true;
670 if (suppress & _suppress_name) have_name = true; 670 if (suppress & _suppress_name) have_name = true;
671 if (suppress & _suppress_type) have_type = true; 671 if (suppress & _suppress_type) have_type = true;
685 if (!have_defc) { 685 if (!have_defc) {
686 klassOop defc = m->method_holder(); 686 klassOop defc = m->method_holder();
687 if (receiver_limit != NULL && receiver_limit != defc 687 if (receiver_limit != NULL && receiver_limit != defc
688 && Klass::cast(receiver_limit)->is_subtype_of(defc)) 688 && Klass::cast(receiver_limit)->is_subtype_of(defc))
689 defc = receiver_limit; 689 defc = receiver_limit;
690 sun_dyn_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror()); 690 java_lang_invoke_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror());
691 } 691 }
692 if (!have_name) { 692 if (!have_name) {
693 //not java_lang_String::create_from_symbol; let's intern member names 693 //not java_lang_String::create_from_symbol; let's intern member names
694 Handle name = StringTable::intern(m->name(), CHECK); 694 Handle name = StringTable::intern(m->name(), CHECK);
695 sun_dyn_MemberName::set_name(mname(), name()); 695 java_lang_invoke_MemberName::set_name(mname(), name());
696 } 696 }
697 if (!have_type) { 697 if (!have_type) {
698 Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK); 698 Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
699 sun_dyn_MemberName::set_type(mname(), type()); 699 java_lang_invoke_MemberName::set_type(mname(), type());
700 } 700 }
701 return; 701 return;
702 } 702 }
703 case IS_FIELD: 703 case IS_FIELD:
704 { 704 {
709 bool is_static = ((flags & JVM_ACC_STATIC) != 0); 709 bool is_static = ((flags & JVM_ACC_STATIC) != 0);
710 fieldDescriptor fd; // find_field initializes fd if found 710 fieldDescriptor fd; // find_field initializes fd if found
711 if (!defc->find_field_from_offset(vmindex, is_static, &fd)) 711 if (!defc->find_field_from_offset(vmindex, is_static, &fd))
712 break; // cannot expand 712 break; // cannot expand
713 if (!have_defc) { 713 if (!have_defc) {
714 sun_dyn_MemberName::set_clazz(mname(), defc->java_mirror()); 714 java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
715 } 715 }
716 if (!have_name) { 716 if (!have_name) {
717 //not java_lang_String::create_from_symbol; let's intern member names 717 //not java_lang_String::create_from_symbol; let's intern member names
718 Handle name = StringTable::intern(fd.name(), CHECK); 718 Handle name = StringTable::intern(fd.name(), CHECK);
719 sun_dyn_MemberName::set_name(mname(), name()); 719 java_lang_invoke_MemberName::set_name(mname(), name());
720 } 720 }
721 if (!have_type) { 721 if (!have_type) {
722 Handle type = java_lang_String::create_from_symbol(fd.signature(), CHECK); 722 Handle type = java_lang_String::create_from_symbol(fd.signature(), CHECK);
723 sun_dyn_MemberName::set_type(mname(), type()); 723 java_lang_invoke_MemberName::set_type(mname(), type());
724 } 724 }
725 return; 725 return;
726 } 726 }
727 } 727 }
728 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); 728 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format");
773 // passed the filters 773 // passed the filters
774 if (rskip > 0) { 774 if (rskip > 0) {
775 --rskip; 775 --rskip;
776 } else if (rfill < rlimit) { 776 } else if (rfill < rlimit) {
777 oop result = results->obj_at(rfill++); 777 oop result = results->obj_at(rfill++);
778 if (!sun_dyn_MemberName::is_instance(result)) 778 if (!java_lang_invoke_MemberName::is_instance(result))
779 return -99; // caller bug! 779 return -99; // caller bug!
780 MethodHandles::init_MemberName(result, st.klass()->as_klassOop(), st.access_flags(), st.offset()); 780 MethodHandles::init_MemberName(result, st.klass()->as_klassOop(), st.access_flags(), st.offset());
781 } else if (++overflow >= overflow_limit) { 781 } else if (++overflow >= overflow_limit) {
782 match_flags = 0; break; // got tired of looking at overflow 782 match_flags = 0; break; // got tired of looking at overflow
783 } 783 }
821 // passed the filters 821 // passed the filters
822 if (rskip > 0) { 822 if (rskip > 0) {
823 --rskip; 823 --rskip;
824 } else if (rfill < rlimit) { 824 } else if (rfill < rlimit) {
825 oop result = results->obj_at(rfill++); 825 oop result = results->obj_at(rfill++);
826 if (!sun_dyn_MemberName::is_instance(result)) 826 if (!java_lang_invoke_MemberName::is_instance(result))
827 return -99; // caller bug! 827 return -99; // caller bug!
828 MethodHandles::init_MemberName(result, m, true); 828 MethodHandles::init_MemberName(result, m, true);
829 } else if (++overflow >= overflow_limit) { 829 } else if (++overflow >= overflow_limit) {
830 match_flags = 0; break; // got tired of looking at overflow 830 match_flags = 0; break; // got tired of looking at overflow
831 } 831 }
855 855
856 // Decode the vmtarget field of a method handle. 856 // Decode the vmtarget field of a method handle.
857 // Sanitize out methodOops, klassOops, and any other non-Java data. 857 // Sanitize out methodOops, klassOops, and any other non-Java data.
858 // This is for debugging and reflection. 858 // This is for debugging and reflection.
859 oop MethodHandles::encode_target(Handle mh, int format, TRAPS) { 859 oop MethodHandles::encode_target(Handle mh, int format, TRAPS) {
860 assert(java_dyn_MethodHandle::is_instance(mh()), "must be a MH"); 860 assert(java_lang_invoke_MethodHandle::is_instance(mh()), "must be a MH");
861 if (format == ETF_HANDLE_OR_METHOD_NAME) { 861 if (format == ETF_HANDLE_OR_METHOD_NAME) {
862 oop target = java_dyn_MethodHandle::vmtarget(mh()); 862 oop target = java_lang_invoke_MethodHandle::vmtarget(mh());
863 if (target == NULL) { 863 if (target == NULL) {
864 return NULL; // unformed MH 864 return NULL; // unformed MH
865 } 865 }
866 klassOop tklass = target->klass(); 866 klassOop tklass = target->klass();
867 if (Klass::cast(tklass)->is_subclass_of(SystemDictionary::Object_klass())) { 867 if (Klass::cast(tklass)->is_subclass_of(SystemDictionary::Object_klass())) {
872 oop target = mh(); 872 oop target = mh();
873 for (;;) { 873 for (;;) {
874 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { 874 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) {
875 return target; 875 return target;
876 } 876 }
877 if (!java_dyn_MethodHandle::is_instance(target)){ 877 if (!java_lang_invoke_MethodHandle::is_instance(target)){
878 return NULL; // unformed MH 878 return NULL; // unformed MH
879 } 879 }
880 target = java_dyn_MethodHandle::vmtarget(target); 880 target = java_lang_invoke_MethodHandle::vmtarget(target);
881 } 881 }
882 } 882 }
883 // cases of metadata in MH.vmtarget: 883 // cases of metadata in MH.vmtarget:
884 // - AMH can have methodOop for static invoke with bound receiver 884 // - AMH can have methodOop for static invoke with bound receiver
885 // - DMH can have methodOop for static invoke (on variable receiver) 885 // - DMH can have methodOop for static invoke (on variable receiver)
902 { 902 {
903 if (SystemDictionary::MemberName_klass() == NULL) break; 903 if (SystemDictionary::MemberName_klass() == NULL) break;
904 instanceKlassHandle mname_klass(THREAD, SystemDictionary::MemberName_klass()); 904 instanceKlassHandle mname_klass(THREAD, SystemDictionary::MemberName_klass());
905 mname_klass->initialize(CHECK_NULL); 905 mname_klass->initialize(CHECK_NULL);
906 Handle mname = mname_klass->allocate_instance_handle(CHECK_NULL); 906 Handle mname = mname_klass->allocate_instance_handle(CHECK_NULL);
907 sun_dyn_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED); 907 java_lang_invoke_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED);
908 bool do_dispatch = ((decode_flags & MethodHandles::_dmf_does_dispatch) != 0); 908 bool do_dispatch = ((decode_flags & MethodHandles::_dmf_does_dispatch) != 0);
909 init_MemberName(mname(), m, do_dispatch); 909 init_MemberName(mname(), m, do_dispatch);
910 expand_MemberName(mname, 0, CHECK_NULL); 910 expand_MemberName(mname, 0, CHECK_NULL);
911 return mname(); 911 return mname();
912 } 912 }
921 static const char* always_null_names[] = { 921 static const char* always_null_names[] = {
922 "java/lang/Void", 922 "java/lang/Void",
923 "java/lang/Null", 923 "java/lang/Null",
924 //"java/lang/Nothing", 924 //"java/lang/Nothing",
925 "sun/dyn/empty/Empty", 925 "sun/dyn/empty/Empty",
926 "sun/invoke/empty/Empty",
926 NULL 927 NULL
927 }; 928 };
928 929
929 static bool is_always_null_type(klassOop klass) { 930 static bool is_always_null_type(klassOop klass) {
931 if (klass == NULL) return false; // safety
930 if (!Klass::cast(klass)->oop_is_instance()) return false; 932 if (!Klass::cast(klass)->oop_is_instance()) return false;
931 instanceKlass* ik = instanceKlass::cast(klass); 933 instanceKlass* ik = instanceKlass::cast(klass);
932 // Must be on the boot class path: 934 // Must be on the boot class path:
933 if (ik->class_loader() != NULL) return false; 935 if (ik->class_loader() != NULL) return false;
934 // Check the name. 936 // Check the name.
941 } 943 }
942 return false; 944 return false;
943 } 945 }
944 946
945 bool MethodHandles::class_cast_needed(klassOop src, klassOop dst) { 947 bool MethodHandles::class_cast_needed(klassOop src, klassOop dst) {
948 if (dst == NULL) return true;
949 if (src == NULL) return (dst != SystemDictionary::Object_klass());
946 if (src == dst || dst == SystemDictionary::Object_klass()) 950 if (src == dst || dst == SystemDictionary::Object_klass())
947 return false; // quickest checks 951 return false; // quickest checks
948 Klass* srck = Klass::cast(src); 952 Klass* srck = Klass::cast(src);
949 Klass* dstk = Klass::cast(dst); 953 Klass* dstk = Klass::cast(dst);
950 if (dstk->is_interface()) { 954 if (dstk->is_interface()) {
1023 void MethodHandles::verify_method_signature(methodHandle m, 1027 void MethodHandles::verify_method_signature(methodHandle m,
1024 Handle mtype, 1028 Handle mtype,
1025 int first_ptype_pos, 1029 int first_ptype_pos,
1026 KlassHandle insert_ptype, 1030 KlassHandle insert_ptype,
1027 TRAPS) { 1031 TRAPS) {
1028 objArrayHandle ptypes(THREAD, java_dyn_MethodType::ptypes(mtype())); 1032 Handle mhi_type;
1033 if (m->is_method_handle_invoke()) {
1034 // use this more exact typing instead of the symbolic signature:
1035 mhi_type = Handle(THREAD, m->method_handle_type());
1036 }
1037 objArrayHandle ptypes(THREAD, java_lang_invoke_MethodType::ptypes(mtype()));
1029 int pnum = first_ptype_pos; 1038 int pnum = first_ptype_pos;
1030 int pmax = ptypes->length(); 1039 int pmax = ptypes->length();
1031 int mnum = 0; // method argument 1040 int anum = 0; // method argument
1032 const char* err = NULL; 1041 const char* err = NULL;
1033 ResourceMark rm(THREAD); 1042 ResourceMark rm(THREAD);
1034 for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) { 1043 for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) {
1035 oop ptype_oop = NULL; 1044 oop ptype_oop = NULL;
1036 if (ss.at_return_type()) { 1045 if (ss.at_return_type()) {
1037 if (pnum != pmax) 1046 if (pnum != pmax)
1038 { err = "too many arguments"; break; } 1047 { err = "too many arguments"; break; }
1039 ptype_oop = java_dyn_MethodType::rtype(mtype()); 1048 ptype_oop = java_lang_invoke_MethodType::rtype(mtype());
1040 } else { 1049 } else {
1041 if (pnum >= pmax) 1050 if (pnum >= pmax)
1042 { err = "not enough arguments"; break; } 1051 { err = "not enough arguments"; break; }
1043 if (pnum >= 0) 1052 if (pnum >= 0)
1044 ptype_oop = ptypes->obj_at(pnum); 1053 ptype_oop = ptypes->obj_at(pnum);
1045 else if (insert_ptype.is_null()) 1054 else if (insert_ptype.is_null())
1046 ptype_oop = NULL; 1055 ptype_oop = NULL;
1047 else 1056 else
1048 ptype_oop = insert_ptype->java_mirror(); 1057 ptype_oop = insert_ptype->java_mirror();
1049 pnum += 1; 1058 pnum += 1;
1050 mnum += 1; 1059 anum += 1;
1051 } 1060 }
1052 klassOop pklass = NULL; 1061 KlassHandle pklass;
1053 BasicType ptype = T_OBJECT; 1062 BasicType ptype = T_OBJECT;
1054 if (ptype_oop != NULL) 1063 bool have_ptype = false;
1055 ptype = java_lang_Class::as_BasicType(ptype_oop, &pklass); 1064 // missing ptype_oop does not match any non-reference; use Object to report the error
1056 else 1065 pklass = SystemDictionaryHandles::Object_klass();
1057 // null does not match any non-reference; use Object to report the error 1066 if (ptype_oop != NULL) {
1058 pklass = SystemDictionary::Object_klass(); 1067 have_ptype = true;
1059 klassOop mklass = NULL; 1068 klassOop pklass_oop = NULL;
1060 BasicType mtype = ss.type(); 1069 ptype = java_lang_Class::as_BasicType(ptype_oop, &pklass_oop);
1061 if (mtype == T_ARRAY) mtype = T_OBJECT; // fold all refs to T_OBJECT 1070 pklass = KlassHandle(THREAD, pklass_oop);
1062 if (mtype == T_OBJECT) { 1071 }
1063 if (ptype_oop == NULL) { 1072 ptype_oop = NULL; //done with this
1073 KlassHandle aklass;
1074 BasicType atype = ss.type();
1075 if (atype == T_ARRAY) atype = T_OBJECT; // fold all refs to T_OBJECT
1076 if (atype == T_OBJECT) {
1077 if (!have_ptype) {
1064 // null matches any reference 1078 // null matches any reference
1065 continue; 1079 continue;
1066 } 1080 }
1067 KlassHandle pklass_handle(THREAD, pklass); pklass = NULL; 1081 if (mhi_type.is_null()) {
1068 // If we fail to resolve types at this point, we will throw an error. 1082 // If we fail to resolve types at this point, we will usually throw an error.
1069 Symbol* name = ss.as_symbol(CHECK); 1083 TempNewSymbol name = ss.as_symbol_or_null();
1070 instanceKlass* mk = instanceKlass::cast(m->method_holder()); 1084 if (name != NULL) {
1071 Handle loader(THREAD, mk->class_loader()); 1085 instanceKlass* mk = instanceKlass::cast(m->method_holder());
1072 Handle domain(THREAD, mk->protection_domain()); 1086 Handle loader(THREAD, mk->class_loader());
1073 mklass = SystemDictionary::resolve_or_null(name, loader, domain, CHECK); 1087 Handle domain(THREAD, mk->protection_domain());
1074 pklass = pklass_handle(); 1088 klassOop aklass_oop = SystemDictionary::resolve_or_null(name, loader, domain, CHECK);
1075 if (mklass == NULL && pklass != NULL && 1089 if (aklass_oop != NULL)
1076 Klass::cast(pklass)->name() == name && 1090 aklass = KlassHandle(THREAD, aklass_oop);
1077 m->is_method_handle_invoke()) { 1091 }
1078 // Assume a match. We can't really decode the signature of MH.invoke*. 1092 } else {
1079 continue; 1093 // for method handle invokers we don't look at the name in the signature
1094 oop atype_oop;
1095 if (ss.at_return_type())
1096 atype_oop = java_lang_invoke_MethodType::rtype(mhi_type());
1097 else
1098 atype_oop = java_lang_invoke_MethodType::ptype(mhi_type(), anum-1);
1099 klassOop aklass_oop = NULL;
1100 atype = java_lang_Class::as_BasicType(atype_oop, &aklass_oop);
1101 aklass = KlassHandle(THREAD, aklass_oop);
1080 } 1102 }
1081 } 1103 }
1082 if (!ss.at_return_type()) { 1104 if (!ss.at_return_type()) {
1083 err = check_argument_type_change(ptype, pklass, mtype, mklass, mnum); 1105 err = check_argument_type_change(ptype, pklass(), atype, aklass(), anum);
1084 } else { 1106 } else {
1085 err = check_return_type_change(mtype, mklass, ptype, pklass); // note reversal! 1107 err = check_return_type_change(atype, aklass(), ptype, pklass()); // note reversal!
1086 } 1108 }
1087 if (err != NULL) break; 1109 if (err != NULL) break;
1088 } 1110 }
1089 1111
1090 if (err != NULL) { 1112 if (err != NULL) {
1113 #ifndef PRODUCT
1114 if (PrintMiscellaneous && (Verbose || WizardMode)) {
1115 tty->print("*** verify_method_signature failed: ");
1116 java_lang_invoke_MethodType::print_signature(mtype(), tty);
1117 tty->cr();
1118 tty->print_cr(" first_ptype_pos = %d, insert_ptype = "UINTX_FORMAT, first_ptype_pos, insert_ptype());
1119 tty->print(" Failing method: ");
1120 m->print();
1121 }
1122 #endif //PRODUCT
1091 THROW_MSG(vmSymbols::java_lang_InternalError(), err); 1123 THROW_MSG(vmSymbols::java_lang_InternalError(), err);
1092 } 1124 }
1093 } 1125 }
1094 1126
1095 // Main routine for verifying the MethodHandle.type of a proposed 1127 // Main routine for verifying the MethodHandle.type of a proposed
1109 if (m_needs_receiver && bound_recv_type.is_null()) 1141 if (m_needs_receiver && bound_recv_type.is_null())
1110 { err = "bound receiver is not an object"; goto die; } 1142 { err = "bound receiver is not an object"; goto die; }
1111 } 1143 }
1112 1144
1113 if (m_needs_receiver && err == NULL) { 1145 if (m_needs_receiver && err == NULL) {
1114 objArrayOop ptypes = java_dyn_MethodType::ptypes(mtype()); 1146 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype());
1115 if (ptypes->length() < first_ptype_pos) 1147 if (ptypes->length() < first_ptype_pos)
1116 { err = "receiver argument is missing"; goto die; } 1148 { err = "receiver argument is missing"; goto die; }
1117 if (has_bound_recv) 1149 if (has_bound_recv)
1118 err = check_method_receiver(m(), bound_recv_type->as_klassOop()); 1150 err = check_method_receiver(m(), bound_recv_type->as_klassOop());
1119 else 1151 else
1129 THROW_MSG(vmSymbols::java_lang_InternalError(), err); 1161 THROW_MSG(vmSymbols::java_lang_InternalError(), err);
1130 } 1162 }
1131 1163
1132 void MethodHandles::verify_vmslots(Handle mh, TRAPS) { 1164 void MethodHandles::verify_vmslots(Handle mh, TRAPS) {
1133 // Verify vmslots. 1165 // Verify vmslots.
1134 int check_slots = argument_slot_count(java_dyn_MethodHandle::type(mh())); 1166 int check_slots = argument_slot_count(java_lang_invoke_MethodHandle::type(mh()));
1135 if (java_dyn_MethodHandle::vmslots(mh()) != check_slots) { 1167 if (java_lang_invoke_MethodHandle::vmslots(mh()) != check_slots) {
1136 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH"); 1168 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH");
1137 } 1169 }
1138 } 1170 }
1139 1171
1140 void MethodHandles::verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS) { 1172 void MethodHandles::verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS) {
1141 // Verify that argslot points at the given argnum. 1173 // Verify that argslot points at the given argnum.
1142 int check_slot = argument_slot(java_dyn_MethodHandle::type(mh()), argnum); 1174 int check_slot = argument_slot(java_lang_invoke_MethodHandle::type(mh()), argnum);
1143 if (argslot != check_slot || argslot < 0) { 1175 if (argslot != check_slot || argslot < 0) {
1144 const char* fmt = "for argnum of %d, vmargslot is %d, should be %d"; 1176 const char* fmt = "for argnum of %d, vmargslot is %d, should be %d";
1145 size_t msglen = strlen(fmt) + 3*11 + 1; 1177 size_t msglen = strlen(fmt) + 3*11 + 1;
1146 char* msg = NEW_RESOURCE_ARRAY(char, msglen); 1178 char* msg = NEW_RESOURCE_ARRAY(char, msglen);
1147 jio_snprintf(msg, msglen, fmt, argnum, argslot, check_slot); 1179 jio_snprintf(msg, msglen, fmt, argnum, argslot, check_slot);
1158 int insert_argnum, oop insert_type, 1190 int insert_argnum, oop insert_type,
1159 int change_argnum, oop change_type, 1191 int change_argnum, oop change_type,
1160 int delete_argnum, 1192 int delete_argnum,
1161 oop dst_mtype, int dst_beg, int dst_end, 1193 oop dst_mtype, int dst_beg, int dst_end,
1162 bool raw) { 1194 bool raw) {
1163 objArrayOop src_ptypes = java_dyn_MethodType::ptypes(src_mtype); 1195 objArrayOop src_ptypes = java_lang_invoke_MethodType::ptypes(src_mtype);
1164 objArrayOop dst_ptypes = java_dyn_MethodType::ptypes(dst_mtype); 1196 objArrayOop dst_ptypes = java_lang_invoke_MethodType::ptypes(dst_mtype);
1165 1197
1166 int src_max = src_ptypes->length(); 1198 int src_max = src_ptypes->length();
1167 int dst_max = dst_ptypes->length(); 1199 int dst_max = dst_ptypes->length();
1168 1200
1169 if (src_end == -1) src_end = src_max; 1201 if (src_end == -1) src_end = src_max;
1222 if (err != NULL) return err; 1254 if (err != NULL) return err;
1223 } 1255 }
1224 } 1256 }
1225 1257
1226 // Now compare return types also. 1258 // Now compare return types also.
1227 oop src_rtype = java_dyn_MethodType::rtype(src_mtype); 1259 oop src_rtype = java_lang_invoke_MethodType::rtype(src_mtype);
1228 oop dst_rtype = java_dyn_MethodType::rtype(dst_mtype); 1260 oop dst_rtype = java_lang_invoke_MethodType::rtype(dst_mtype);
1229 if (src_rtype != dst_rtype) { 1261 if (src_rtype != dst_rtype) {
1230 err = check_return_type_change(dst_rtype, src_rtype, raw); // note reversal! 1262 err = check_return_type_change(dst_rtype, src_rtype, raw); // note reversal!
1231 if (err != NULL) return err; 1263 if (err != NULL) return err;
1232 } 1264 }
1233 1265
1285 } 1317 }
1286 1318
1287 // format, format, format 1319 // format, format, format
1288 const char* src_name = type2name(src_type); 1320 const char* src_name = type2name(src_type);
1289 const char* dst_name = type2name(dst_type); 1321 const char* dst_name = type2name(dst_type);
1290 if (src_type == T_OBJECT) src_name = Klass::cast(src_klass)->external_name();
1291 if (dst_type == T_OBJECT) dst_name = Klass::cast(dst_klass)->external_name();
1292 if (src_name == NULL) src_name = "unknown type"; 1322 if (src_name == NULL) src_name = "unknown type";
1293 if (dst_name == NULL) dst_name = "unknown type"; 1323 if (dst_name == NULL) dst_name = "unknown type";
1324 if (src_type == T_OBJECT)
1325 src_name = (src_klass != NULL) ? Klass::cast(src_klass)->external_name() : "an unresolved class";
1326 if (dst_type == T_OBJECT)
1327 dst_name = (dst_klass != NULL) ? Klass::cast(dst_klass)->external_name() : "an unresolved class";
1294 1328
1295 size_t msglen = strlen(err) + strlen(src_name) + strlen(dst_name) + (argnum < 10 ? 1 : 11); 1329 size_t msglen = strlen(err) + strlen(src_name) + strlen(dst_name) + (argnum < 10 ? 1 : 11);
1296 char* msg = NEW_RESOURCE_ARRAY(char, msglen + 1); 1330 char* msg = NEW_RESOURCE_ARRAY(char, msglen + 1);
1297 if (argnum >= 0) { 1331 if (argnum >= 0) {
1298 assert(strstr(err, "%d") != NULL, ""); 1332 assert(strstr(err, "%d") != NULL, "");
1312 // will be the size of all arguments, including the first. 1346 // will be the size of all arguments, including the first.
1313 // If the argument is neither -1 nor a valid argument index, 1347 // If the argument is neither -1 nor a valid argument index,
1314 // then return a negative number. Otherwise, the result 1348 // then return a negative number. Otherwise, the result
1315 // is in the range [0..vmslots] inclusive. 1349 // is in the range [0..vmslots] inclusive.
1316 int MethodHandles::argument_slot(oop method_type, int arg) { 1350 int MethodHandles::argument_slot(oop method_type, int arg) {
1317 objArrayOop ptypes = java_dyn_MethodType::ptypes(method_type); 1351 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type);
1318 int argslot = 0; 1352 int argslot = 0;
1319 int len = ptypes->length(); 1353 int len = ptypes->length();
1320 if (arg < -1 || arg >= len) return -99; 1354 if (arg < -1 || arg >= len) return -99;
1321 for (int i = len-1; i > arg; i--) { 1355 for (int i = len-1; i > arg; i--) {
1322 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); 1356 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i));
1326 return argslot; 1360 return argslot;
1327 } 1361 }
1328 1362
1329 // Given a slot number, return the argument number. 1363 // Given a slot number, return the argument number.
1330 int MethodHandles::argument_slot_to_argnum(oop method_type, int query_argslot) { 1364 int MethodHandles::argument_slot_to_argnum(oop method_type, int query_argslot) {
1331 objArrayOop ptypes = java_dyn_MethodType::ptypes(method_type); 1365 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type);
1332 int argslot = 0; 1366 int argslot = 0;
1333 int len = ptypes->length(); 1367 int len = ptypes->length();
1334 for (int i = len-1; i >= 0; i--) { 1368 for (int i = len-1; i >= 0; i--) {
1335 if (query_argslot == argslot) return i; 1369 if (query_argslot == argslot) return i;
1336 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); 1370 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i));
1392 } 1426 }
1393 } 1427 }
1394 1428
1395 void MethodHandles::verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS) { 1429 void MethodHandles::verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS) {
1396 // Verify type. 1430 // Verify type.
1397 Handle mtype(THREAD, java_dyn_MethodHandle::type(mh())); 1431 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh()));
1398 verify_method_type(m, mtype, false, KlassHandle(), CHECK); 1432 verify_method_type(m, mtype, false, KlassHandle(), CHECK);
1399 1433
1400 // Verify vmslots. 1434 // Verify vmslots.
1401 if (java_dyn_MethodHandle::vmslots(mh()) != m->size_of_parameters()) { 1435 if (java_lang_invoke_MethodHandle::vmslots(mh()) != m->size_of_parameters()) {
1402 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in DMH"); 1436 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in DMH");
1403 } 1437 }
1404 } 1438 }
1405 1439
1406 void MethodHandles::init_DirectMethodHandle(Handle mh, methodHandle m, bool do_dispatch, TRAPS) { 1440 void MethodHandles::init_DirectMethodHandle(Handle mh, methodHandle m, bool do_dispatch, TRAPS) {
1408 if (mh.is_null() || m.is_null() || 1442 if (mh.is_null() || m.is_null() ||
1409 (!do_dispatch && m->is_abstract())) { 1443 (!do_dispatch && m->is_abstract())) {
1410 THROW(vmSymbols::java_lang_InternalError()); 1444 THROW(vmSymbols::java_lang_InternalError());
1411 } 1445 }
1412 1446
1413 java_dyn_MethodHandle::init_vmslots(mh()); 1447 java_lang_invoke_MethodHandle::init_vmslots(mh());
1414 1448
1415 if (VerifyMethodHandles) { 1449 if (VerifyMethodHandles) {
1416 // The privileged code which invokes this routine should not make 1450 // The privileged code which invokes this routine should not make
1417 // a mistake about types, but it's better to verify. 1451 // a mistake about types, but it's better to verify.
1418 verify_DirectMethodHandle(mh, m, CHECK); 1452 verify_DirectMethodHandle(mh, m, CHECK);
1468 me = MethodHandles::entry(MethodHandles::_invokevirtual_mh); 1502 me = MethodHandles::entry(MethodHandles::_invokevirtual_mh);
1469 } 1503 }
1470 1504
1471 if (me == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 1505 if (me == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
1472 1506
1473 sun_dyn_DirectMethodHandle::set_vmtarget(mh(), vmtarget); 1507 java_lang_invoke_DirectMethodHandle::set_vmtarget(mh(), vmtarget);
1474 sun_dyn_DirectMethodHandle::set_vmindex(mh(), vmindex); 1508 java_lang_invoke_DirectMethodHandle::set_vmindex(mh(), vmindex);
1475 DEBUG_ONLY(int flags; klassOop rlimit); 1509 DEBUG_ONLY(int flags; klassOop rlimit);
1476 assert(MethodHandles::decode_method(mh(), rlimit, flags) == m(), 1510 assert(MethodHandles::decode_method(mh(), rlimit, flags) == m(),
1477 "properly stored for later decoding"); 1511 "properly stored for later decoding");
1478 DEBUG_ONLY(bool actual_do_dispatch = ((flags & _dmf_does_dispatch) != 0)); 1512 DEBUG_ONLY(bool actual_do_dispatch = ((flags & _dmf_does_dispatch) != 0));
1479 assert(!(actual_do_dispatch && !do_dispatch), 1513 assert(!(actual_do_dispatch && !do_dispatch),
1480 "do not perform dispatch if !do_dispatch specified"); 1514 "do not perform dispatch if !do_dispatch specified");
1481 assert(actual_do_dispatch == (vmindex >= 0), "proper later decoding of do_dispatch"); 1515 assert(actual_do_dispatch == (vmindex >= 0), "proper later decoding of do_dispatch");
1482 assert(decode_MethodHandle_stack_pushes(mh()) == 0, "DMH does not move stack"); 1516 assert(decode_MethodHandle_stack_pushes(mh()) == 0, "DMH does not move stack");
1483 1517
1484 // Done! 1518 // Done!
1485 java_dyn_MethodHandle::set_vmentry(mh(), me); 1519 java_lang_invoke_MethodHandle::set_vmentry(mh(), me);
1486 } 1520 }
1487 1521
1488 void MethodHandles::verify_BoundMethodHandle_with_receiver(Handle mh, 1522 void MethodHandles::verify_BoundMethodHandle_with_receiver(Handle mh,
1489 methodHandle m, 1523 methodHandle m,
1490 TRAPS) { 1524 TRAPS) {
1491 // Verify type. 1525 // Verify type.
1492 oop receiver = sun_dyn_BoundMethodHandle::argument(mh()); 1526 oop receiver = java_lang_invoke_BoundMethodHandle::argument(mh());
1493 Handle mtype(THREAD, java_dyn_MethodHandle::type(mh())); 1527 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh()));
1494 KlassHandle bound_recv_type; 1528 KlassHandle bound_recv_type;
1495 if (receiver != NULL) bound_recv_type = KlassHandle(THREAD, receiver->klass()); 1529 if (receiver != NULL) bound_recv_type = KlassHandle(THREAD, receiver->klass());
1496 verify_method_type(m, mtype, true, bound_recv_type, CHECK); 1530 verify_method_type(m, mtype, true, bound_recv_type, CHECK);
1497 1531
1498 int receiver_pos = m->size_of_parameters() - 1; 1532 int receiver_pos = m->size_of_parameters() - 1;
1499 1533
1500 // Verify MH.vmargslot, which should point at the bound receiver. 1534 // Verify MH.vmargslot, which should point at the bound receiver.
1501 verify_vmargslot(mh, -1, sun_dyn_BoundMethodHandle::vmargslot(mh()), CHECK); 1535 verify_vmargslot(mh, -1, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK);
1502 //verify_vmslots(mh, CHECK); 1536 //verify_vmslots(mh, CHECK);
1503 1537
1504 // Verify vmslots. 1538 // Verify vmslots.
1505 if (java_dyn_MethodHandle::vmslots(mh()) != receiver_pos) { 1539 if (java_lang_invoke_MethodHandle::vmslots(mh()) != receiver_pos) {
1506 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH (receiver)"); 1540 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH (receiver)");
1507 } 1541 }
1508 } 1542 }
1509 1543
1510 // Initialize a BMH with a receiver bound directly to a methodOop. 1544 // Initialize a BMH with a receiver bound directly to a methodOop.
1518 THROW(vmSymbols::java_lang_InternalError()); 1552 THROW(vmSymbols::java_lang_InternalError());
1519 } 1553 }
1520 1554
1521 KlassHandle receiver_klass; 1555 KlassHandle receiver_klass;
1522 { 1556 {
1523 oop receiver_oop = sun_dyn_BoundMethodHandle::argument(mh()); 1557 oop receiver_oop = java_lang_invoke_BoundMethodHandle::argument(mh());
1524 if (receiver_oop != NULL) 1558 if (receiver_oop != NULL)
1525 receiver_klass = KlassHandle(THREAD, receiver_oop->klass()); 1559 receiver_klass = KlassHandle(THREAD, receiver_oop->klass());
1526 } 1560 }
1527 methodHandle m = dispatch_decoded_method(original_m, 1561 methodHandle m = dispatch_decoded_method(original_m,
1528 receiver_limit, decode_flags, 1562 receiver_limit, decode_flags,
1529 receiver_klass, 1563 receiver_klass,
1530 CHECK); 1564 CHECK);
1531 if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } 1565 if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); }
1532 if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); } 1566 if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); }
1533 1567
1534 java_dyn_MethodHandle::init_vmslots(mh()); 1568 java_lang_invoke_MethodHandle::init_vmslots(mh());
1535 1569
1536 if (VerifyMethodHandles) { 1570 if (VerifyMethodHandles) {
1537 verify_BoundMethodHandle_with_receiver(mh, m, CHECK); 1571 verify_BoundMethodHandle_with_receiver(mh, m, CHECK);
1538 } 1572 }
1539 1573
1540 sun_dyn_BoundMethodHandle::set_vmtarget(mh(), m()); 1574 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m());
1541 1575
1542 DEBUG_ONLY(int junk; klassOop junk2); 1576 DEBUG_ONLY(int junk; klassOop junk2);
1543 assert(MethodHandles::decode_method(mh(), junk2, junk) == m(), "properly stored for later decoding"); 1577 assert(MethodHandles::decode_method(mh(), junk2, junk) == m(), "properly stored for later decoding");
1544 assert(decode_MethodHandle_stack_pushes(mh()) == 1, "BMH pushes one stack slot"); 1578 assert(decode_MethodHandle_stack_pushes(mh()) == 1, "BMH pushes one stack slot");
1545 1579
1546 // Done! 1580 // Done!
1547 java_dyn_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh)); 1581 java_lang_invoke_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh));
1548 } 1582 }
1549 1583
1550 void MethodHandles::verify_BoundMethodHandle(Handle mh, Handle target, int argnum, 1584 void MethodHandles::verify_BoundMethodHandle(Handle mh, Handle target, int argnum,
1551 bool direct_to_method, TRAPS) { 1585 bool direct_to_method, TRAPS) {
1552 Handle ptype_handle(THREAD, 1586 Handle ptype_handle(THREAD,
1553 java_dyn_MethodType::ptype(java_dyn_MethodHandle::type(target()), argnum)); 1587 java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum));
1554 KlassHandle ptype_klass; 1588 KlassHandle ptype_klass;
1555 BasicType ptype = java_lang_Class::as_BasicType(ptype_handle(), &ptype_klass); 1589 BasicType ptype = java_lang_Class::as_BasicType(ptype_handle(), &ptype_klass);
1556 int slots_pushed = type2size[ptype]; 1590 int slots_pushed = type2size[ptype];
1557 1591
1558 oop argument = sun_dyn_BoundMethodHandle::argument(mh()); 1592 oop argument = java_lang_invoke_BoundMethodHandle::argument(mh());
1559 1593
1560 const char* err = NULL; 1594 const char* err = NULL;
1561 1595
1562 switch (ptype) { 1596 switch (ptype) {
1563 case T_OBJECT: 1597 case T_OBJECT:
1621 } 1655 }
1622 } 1656 }
1623 1657
1624 if (err == NULL) { 1658 if (err == NULL) {
1625 // Verify the rest of the method type. 1659 // Verify the rest of the method type.
1626 err = check_method_type_insertion(java_dyn_MethodHandle::type(mh()), 1660 err = check_method_type_insertion(java_lang_invoke_MethodHandle::type(mh()),
1627 argnum, ptype_handle(), 1661 argnum, ptype_handle(),
1628 java_dyn_MethodHandle::type(target())); 1662 java_lang_invoke_MethodHandle::type(target()));
1629 } 1663 }
1630 1664
1631 if (err != NULL) { 1665 if (err != NULL) {
1632 THROW_MSG(vmSymbols::java_lang_InternalError(), err); 1666 THROW_MSG(vmSymbols::java_lang_InternalError(), err);
1633 } 1667 }
1634 } 1668 }
1635 1669
1636 void MethodHandles::init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { 1670 void MethodHandles::init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS) {
1637 // Check arguments. 1671 // Check arguments.
1638 if (mh.is_null() || target.is_null() || !java_dyn_MethodHandle::is_instance(target())) { 1672 if (mh.is_null() || target.is_null() || !java_lang_invoke_MethodHandle::is_instance(target())) {
1639 THROW(vmSymbols::java_lang_InternalError()); 1673 THROW(vmSymbols::java_lang_InternalError());
1640 } 1674 }
1641 1675
1642 java_dyn_MethodHandle::init_vmslots(mh()); 1676 java_lang_invoke_MethodHandle::init_vmslots(mh());
1643 1677
1644 if (VerifyMethodHandles) { 1678 if (VerifyMethodHandles) {
1645 int insert_after = argnum - 1; 1679 int insert_after = argnum - 1;
1646 verify_vmargslot(mh, insert_after, sun_dyn_BoundMethodHandle::vmargslot(mh()), CHECK); 1680 verify_vmargslot(mh, insert_after, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK);
1647 verify_vmslots(mh, CHECK); 1681 verify_vmslots(mh, CHECK);
1648 } 1682 }
1649 1683
1650 // Get bound type and required slots. 1684 // Get bound type and required slots.
1651 oop ptype_oop = java_dyn_MethodType::ptype(java_dyn_MethodHandle::type(target()), argnum); 1685 oop ptype_oop = java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum);
1652 BasicType ptype = java_lang_Class::as_BasicType(ptype_oop); 1686 BasicType ptype = java_lang_Class::as_BasicType(ptype_oop);
1653 int slots_pushed = type2size[ptype]; 1687 int slots_pushed = type2size[ptype];
1654 1688
1655 // If (a) the target is a direct non-dispatched method handle, 1689 // If (a) the target is a direct non-dispatched method handle,
1656 // or (b) the target is a dispatched direct method handle and we 1690 // or (b) the target is a dispatched direct method handle and we
1657 // are binding the receiver, cut out the middle-man. 1691 // are binding the receiver, cut out the middle-man.
1658 // Do this by decoding the DMH and using its methodOop directly as vmtarget. 1692 // Do this by decoding the DMH and using its methodOop directly as vmtarget.
1659 bool direct_to_method = false; 1693 bool direct_to_method = false;
1660 if (OptimizeMethodHandles && 1694 if (OptimizeMethodHandles &&
1661 target->klass() == SystemDictionary::DirectMethodHandle_klass() && 1695 target->klass() == SystemDictionary::DirectMethodHandle_klass() &&
1662 (argnum == 0 || sun_dyn_DirectMethodHandle::vmindex(target()) < 0)) { 1696 (argnum == 0 || java_lang_invoke_DirectMethodHandle::vmindex(target()) < 0)) {
1663 int decode_flags = 0; klassOop receiver_limit_oop = NULL; 1697 int decode_flags = 0; klassOop receiver_limit_oop = NULL;
1664 methodHandle m(THREAD, decode_method(target(), receiver_limit_oop, decode_flags)); 1698 methodHandle m(THREAD, decode_method(target(), receiver_limit_oop, decode_flags));
1665 if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "DMH failed to decode"); } 1699 if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "DMH failed to decode"); }
1666 DEBUG_ONLY(int m_vmslots = m->size_of_parameters() - slots_pushed); // pos. of 1st arg. 1700 DEBUG_ONLY(int m_vmslots = m->size_of_parameters() - slots_pushed); // pos. of 1st arg.
1667 assert(sun_dyn_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig"); 1701 assert(java_lang_invoke_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig");
1668 if (argnum == 0 && (decode_flags & _dmf_has_receiver) != 0) { 1702 if (argnum == 0 && (decode_flags & _dmf_has_receiver) != 0) {
1669 KlassHandle receiver_limit(THREAD, receiver_limit_oop); 1703 KlassHandle receiver_limit(THREAD, receiver_limit_oop);
1670 init_BoundMethodHandle_with_receiver(mh, m, 1704 init_BoundMethodHandle_with_receiver(mh, m,
1671 receiver_limit, decode_flags, 1705 receiver_limit, decode_flags,
1672 CHECK); 1706 CHECK);
1675 1709
1676 // Even if it is not a bound receiver, we still might be able 1710 // Even if it is not a bound receiver, we still might be able
1677 // to bind another argument and still invoke the methodOop directly. 1711 // to bind another argument and still invoke the methodOop directly.
1678 if (!(decode_flags & _dmf_does_dispatch)) { 1712 if (!(decode_flags & _dmf_does_dispatch)) {
1679 direct_to_method = true; 1713 direct_to_method = true;
1680 sun_dyn_BoundMethodHandle::set_vmtarget(mh(), m()); 1714 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m());
1681 } 1715 }
1682 } 1716 }
1683 if (!direct_to_method) 1717 if (!direct_to_method)
1684 sun_dyn_BoundMethodHandle::set_vmtarget(mh(), target()); 1718 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), target());
1685 1719
1686 if (VerifyMethodHandles) { 1720 if (VerifyMethodHandles) {
1687 verify_BoundMethodHandle(mh, target, argnum, direct_to_method, CHECK); 1721 verify_BoundMethodHandle(mh, target, argnum, direct_to_method, CHECK);
1688 } 1722 }
1689 1723
1701 } else { 1735 } else {
1702 assert(false, ""); 1736 assert(false, "");
1703 } 1737 }
1704 1738
1705 // Done! 1739 // Done!
1706 java_dyn_MethodHandle::set_vmentry(mh(), me); 1740 java_lang_invoke_MethodHandle::set_vmentry(mh(), me);
1707 } 1741 }
1708 1742
1709 static void throw_InternalError_for_bad_conversion(int conversion, const char* err, TRAPS) { 1743 static void throw_InternalError_for_bad_conversion(int conversion, const char* err, TRAPS) {
1710 char msg[200]; 1744 char msg[200];
1711 jio_snprintf(msg, sizeof(msg), "bad adapter (conversion=0x%08x): %s", conversion, err); 1745 jio_snprintf(msg, sizeof(msg), "bad adapter (conversion=0x%08x): %s", conversion, err);
1712 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), msg); 1746 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), msg);
1713 } 1747 }
1714 1748
1715 void MethodHandles::verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS) { 1749 void MethodHandles::verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS) {
1716 jint conversion = sun_dyn_AdapterMethodHandle::conversion(mh()); 1750 jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh());
1717 int argslot = sun_dyn_AdapterMethodHandle::vmargslot(mh()); 1751 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh());
1718 1752
1719 verify_vmargslot(mh, argnum, argslot, CHECK); 1753 verify_vmargslot(mh, argnum, argslot, CHECK);
1720 verify_vmslots(mh, CHECK); 1754 verify_vmslots(mh, CHECK);
1721 1755
1722 jint conv_op = adapter_conversion_op(conversion); 1756 jint conv_op = adapter_conversion_op(conversion);
1729 int stack_move = adapter_conversion_stack_move(conversion); 1763 int stack_move = adapter_conversion_stack_move(conversion);
1730 BasicType src = adapter_conversion_src_type(conversion); 1764 BasicType src = adapter_conversion_src_type(conversion);
1731 BasicType dest = adapter_conversion_dest_type(conversion); 1765 BasicType dest = adapter_conversion_dest_type(conversion);
1732 int vminfo = adapter_conversion_vminfo(conversion); // should be zero 1766 int vminfo = adapter_conversion_vminfo(conversion); // should be zero
1733 1767
1734 Handle argument(THREAD, sun_dyn_AdapterMethodHandle::argument(mh())); 1768 Handle argument(THREAD, java_lang_invoke_AdapterMethodHandle::argument(mh()));
1735 Handle target(THREAD, sun_dyn_AdapterMethodHandle::vmtarget(mh())); 1769 Handle target(THREAD, java_lang_invoke_AdapterMethodHandle::vmtarget(mh()));
1736 Handle src_mtype(THREAD, java_dyn_MethodHandle::type(mh())); 1770 Handle src_mtype(THREAD, java_lang_invoke_MethodHandle::type(mh()));
1737 Handle dst_mtype(THREAD, java_dyn_MethodHandle::type(target())); 1771 Handle dst_mtype(THREAD, java_lang_invoke_MethodHandle::type(target()));
1738 1772
1739 const char* err = NULL; 1773 const char* err = NULL;
1740 1774
1741 if (err == NULL) { 1775 if (err == NULL) {
1742 // Check that the correct argument is supplied, but only if it is required. 1776 // Check that the correct argument is supplied, but only if it is required.
1758 } 1792 }
1759 } 1793 }
1760 break; 1794 break;
1761 case _adapter_flyby: 1795 case _adapter_flyby:
1762 case _adapter_ricochet: 1796 case _adapter_ricochet:
1763 if (!java_dyn_MethodHandle::is_instance(argument())) 1797 if (!java_lang_invoke_MethodHandle::is_instance(argument()))
1764 { err = "MethodHandle adapter argument required"; break; } 1798 { err = "MethodHandle adapter argument required"; break; }
1765 break; 1799 break;
1766 default: 1800 default:
1767 if (argument.not_null()) 1801 if (argument.not_null())
1768 { err = "adapter has spurious argument"; break; } 1802 { err = "adapter has spurious argument"; break; }
1804 { 1838 {
1805 if (!src || src != dest) { 1839 if (!src || src != dest) {
1806 err = "adapter requires src/dest conversion subfields for swap"; break; 1840 err = "adapter requires src/dest conversion subfields for swap"; break;
1807 } 1841 }
1808 int swap_size = type2size[src]; 1842 int swap_size = type2size[src];
1809 oop src_mtype = sun_dyn_AdapterMethodHandle::type(mh()); 1843 oop src_mtype = java_lang_invoke_AdapterMethodHandle::type(mh());
1810 oop dest_mtype = sun_dyn_AdapterMethodHandle::type(target()); 1844 oop dest_mtype = java_lang_invoke_AdapterMethodHandle::type(target());
1811 int slot_limit = sun_dyn_AdapterMethodHandle::vmslots(target()); 1845 int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(target());
1812 int src_slot = argslot; 1846 int src_slot = argslot;
1813 int dest_slot = vminfo; 1847 int dest_slot = vminfo;
1814 bool rotate_up = (src_slot > dest_slot); // upward rotation 1848 bool rotate_up = (src_slot > dest_slot); // upward rotation
1815 int src_arg = argnum; 1849 int src_arg = argnum;
1816 int dest_arg = argument_slot_to_argnum(dest_mtype, dest_slot); 1850 int dest_arg = argument_slot_to_argnum(dest_mtype, dest_slot);
1819 !(src_slot >= dest_slot + swap_size)) { 1853 !(src_slot >= dest_slot + swap_size)) {
1820 err = "source, destination slots must be distinct"; 1854 err = "source, destination slots must be distinct";
1821 } else if (ek == _adapter_swap_args && !(src_slot > dest_slot)) { 1855 } else if (ek == _adapter_swap_args && !(src_slot > dest_slot)) {
1822 err = "source of swap must be deeper in stack"; 1856 err = "source of swap must be deeper in stack";
1823 } else if (ek == _adapter_swap_args) { 1857 } else if (ek == _adapter_swap_args) {
1824 err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, dest_arg), 1858 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, dest_arg),
1825 java_dyn_MethodType::ptype(dest_mtype, src_arg), 1859 java_lang_invoke_MethodType::ptype(dest_mtype, src_arg),
1826 dest_arg); 1860 dest_arg);
1827 } else if (ek == _adapter_rot_args) { 1861 } else if (ek == _adapter_rot_args) {
1828 if (rotate_up) { 1862 if (rotate_up) {
1829 assert((src_slot > dest_slot) && (src_arg < dest_arg), ""); 1863 assert((src_slot > dest_slot) && (src_arg < dest_arg), "");
1830 // rotate up: [dest_slot..src_slot-ss] --> [dest_slot+ss..src_slot] 1864 // rotate up: [dest_slot..src_slot-ss] --> [dest_slot+ss..src_slot]
1831 // that is: [src_arg+1..dest_arg] --> [src_arg..dest_arg-1] 1865 // that is: [src_arg+1..dest_arg] --> [src_arg..dest_arg-1]
1832 for (int i = src_arg+1; i <= dest_arg && err == NULL; i++) { 1866 for (int i = src_arg+1; i <= dest_arg && err == NULL; i++) {
1833 err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, i), 1867 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i),
1834 java_dyn_MethodType::ptype(dest_mtype, i-1), 1868 java_lang_invoke_MethodType::ptype(dest_mtype, i-1),
1835 i); 1869 i);
1836 } 1870 }
1837 } else { // rotate down 1871 } else { // rotate down
1838 assert((src_slot < dest_slot) && (src_arg > dest_arg), ""); 1872 assert((src_slot < dest_slot) && (src_arg > dest_arg), "");
1839 // rotate down: [src_slot+ss..dest_slot] --> [src_slot..dest_slot-ss] 1873 // rotate down: [src_slot+ss..dest_slot] --> [src_slot..dest_slot-ss]
1840 // that is: [dest_arg..src_arg-1] --> [dst_arg+1..src_arg] 1874 // that is: [dest_arg..src_arg-1] --> [dst_arg+1..src_arg]
1841 for (int i = dest_arg; i <= src_arg-1 && err == NULL; i++) { 1875 for (int i = dest_arg; i <= src_arg-1 && err == NULL; i++) {
1842 err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, i), 1876 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i),
1843 java_dyn_MethodType::ptype(dest_mtype, i+1), 1877 java_lang_invoke_MethodType::ptype(dest_mtype, i+1),
1844 i); 1878 i);
1845 } 1879 }
1846 } 1880 }
1847 } 1881 }
1848 if (err == NULL) 1882 if (err == NULL)
1849 err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, src_arg), 1883 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, src_arg),
1850 java_dyn_MethodType::ptype(dest_mtype, dest_arg), 1884 java_lang_invoke_MethodType::ptype(dest_mtype, dest_arg),
1851 src_arg); 1885 src_arg);
1852 } 1886 }
1853 break; 1887 break;
1854 case _adapter_collect_args: 1888 case _adapter_collect_args:
1855 case _adapter_spread_args: 1889 case _adapter_spread_args:
1916 } 1950 }
1917 1951
1918 if (err == NULL) { 1952 if (err == NULL) {
1919 // Make sure this adapter does not push too deeply. 1953 // Make sure this adapter does not push too deeply.
1920 int slots_pushed = stack_move / stack_move_unit(); 1954 int slots_pushed = stack_move / stack_move_unit();
1921 int this_vmslots = java_dyn_MethodHandle::vmslots(mh()); 1955 int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh());
1922 int target_vmslots = java_dyn_MethodHandle::vmslots(target()); 1956 int target_vmslots = java_lang_invoke_MethodHandle::vmslots(target());
1923 if (slots_pushed != (target_vmslots - this_vmslots)) { 1957 if (slots_pushed != (target_vmslots - this_vmslots)) {
1924 err = "stack_move inconsistent with previous and current MethodType vmslots"; 1958 err = "stack_move inconsistent with previous and current MethodType vmslots";
1925 } else if (slots_pushed > 0) { 1959 } else if (slots_pushed > 0) {
1926 // verify stack_move against MethodHandlePushLimit 1960 // verify stack_move against MethodHandlePushLimit
1927 int target_pushes = decode_MethodHandle_stack_pushes(target()); 1961 int target_pushes = decode_MethodHandle_stack_pushes(target());
1959 break; 1993 break;
1960 1994
1961 case _adapter_check_cast: 1995 case _adapter_check_cast:
1962 { 1996 {
1963 // The actual value being checked must be a reference: 1997 // The actual value being checked must be a reference:
1964 err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype(), argnum), 1998 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), argnum),
1965 object_java_mirror(), argnum); 1999 object_java_mirror(), argnum);
1966 if (err != NULL) break; 2000 if (err != NULL) break;
1967 2001
1968 // The output of the cast must fit with the destination argument: 2002 // The output of the cast must fit with the destination argument:
1969 Handle cast_class = argument; 2003 Handle cast_class = argument;
1983 } 2017 }
1984 2018
1985 } 2019 }
1986 2020
1987 void MethodHandles::init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { 2021 void MethodHandles::init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS) {
1988 oop argument = sun_dyn_AdapterMethodHandle::argument(mh()); 2022 oop argument = java_lang_invoke_AdapterMethodHandle::argument(mh());
1989 int argslot = sun_dyn_AdapterMethodHandle::vmargslot(mh()); 2023 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh());
1990 jint conversion = sun_dyn_AdapterMethodHandle::conversion(mh()); 2024 jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh());
1991 jint conv_op = adapter_conversion_op(conversion); 2025 jint conv_op = adapter_conversion_op(conversion);
1992 2026
1993 // adjust the adapter code to the internal EntryKind enumeration: 2027 // adjust the adapter code to the internal EntryKind enumeration:
1994 EntryKind ek_orig = adapter_entry_kind(conv_op); 2028 EntryKind ek_orig = adapter_entry_kind(conv_op);
1995 EntryKind ek_opt = ek_orig; // may be optimized 2029 EntryKind ek_opt = ek_orig; // may be optimized
1996 2030
1997 // Finalize the vmtarget field (Java initialized it to null). 2031 // Finalize the vmtarget field (Java initialized it to null).
1998 if (!java_dyn_MethodHandle::is_instance(target())) { 2032 if (!java_lang_invoke_MethodHandle::is_instance(target())) {
1999 throw_InternalError_for_bad_conversion(conversion, "bad target", THREAD); 2033 throw_InternalError_for_bad_conversion(conversion, "bad target", THREAD);
2000 return; 2034 return;
2001 } 2035 }
2002 sun_dyn_AdapterMethodHandle::set_vmtarget(mh(), target()); 2036 java_lang_invoke_AdapterMethodHandle::set_vmtarget(mh(), target());
2003 2037
2004 if (VerifyMethodHandles) { 2038 if (VerifyMethodHandles) {
2005 verify_AdapterMethodHandle(mh, argnum, CHECK); 2039 verify_AdapterMethodHandle(mh, argnum, CHECK);
2006 } 2040 }
2007 2041
2081 2115
2082 case _adapter_swap_args: 2116 case _adapter_swap_args:
2083 case _adapter_rot_args: 2117 case _adapter_rot_args:
2084 { 2118 {
2085 int swap_slots = type2size[src]; 2119 int swap_slots = type2size[src];
2086 int slot_limit = sun_dyn_AdapterMethodHandle::vmslots(mh()); 2120 int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(mh());
2087 int src_slot = argslot; 2121 int src_slot = argslot;
2088 int dest_slot = vminfo; 2122 int dest_slot = vminfo;
2089 int rotate = (ek_orig == _adapter_swap_args) ? 0 : (src_slot > dest_slot) ? 1 : -1; 2123 int rotate = (ek_orig == _adapter_swap_args) ? 0 : (src_slot > dest_slot) ? 1 : -1;
2090 switch (swap_slots) { 2124 switch (swap_slots) {
2091 case 1: 2125 case 1:
2145 2179
2146 // Rebuild the conversion value; maybe parts of it were changed. 2180 // Rebuild the conversion value; maybe parts of it were changed.
2147 jint new_conversion = adapter_conversion(conv_op, src, dest, stack_move, vminfo); 2181 jint new_conversion = adapter_conversion(conv_op, src, dest, stack_move, vminfo);
2148 2182
2149 // Finalize the conversion field. (Note that it is final to Java code.) 2183 // Finalize the conversion field. (Note that it is final to Java code.)
2150 sun_dyn_AdapterMethodHandle::set_conversion(mh(), new_conversion); 2184 java_lang_invoke_AdapterMethodHandle::set_conversion(mh(), new_conversion);
2151 2185
2152 // Done! 2186 // Done!
2153 java_dyn_MethodHandle::set_vmentry(mh(), entry(ek_opt)); 2187 java_lang_invoke_MethodHandle::set_vmentry(mh(), entry(ek_opt));
2154 2188
2155 // There should be enough memory barriers on exit from native methods 2189 // There should be enough memory barriers on exit from native methods
2156 // to ensure that the MH is fully initialized to all threads before 2190 // to ensure that the MH is fully initialized to all threads before
2157 // Java code can publish it in global data structures. 2191 // Java code can publish it in global data structures.
2158 } 2192 }
2159 2193
2160 // 2194 //
2161 // Here are the native methods on sun.dyn.MethodHandleImpl. 2195 // Here are the native methods on sun.invoke.MethodHandleImpl.
2162 // They are the private interface between this JVM and the HotSpot-specific 2196 // They are the private interface between this JVM and the HotSpot-specific
2163 // Java code that implements JSR 292 method handles. 2197 // Java code that implements JSR 292 method handles.
2164 // 2198 //
2165 // Note: We use a JVM_ENTRY macro to define each of these, for this is the way 2199 // Note: We use a JVM_ENTRY macro to define each of these, for this is the way
2166 // that intrinsic (non-JNI) native methods are defined in HotSpot. 2200 // that intrinsic (non-JNI) native methods are defined in HotSpot.
2167 // 2201 //
2168 2202
2169 // direct method handles for invokestatic or invokespecial 2203 // direct method handles for invokestatic or invokespecial
2170 // void init(DirectMethodHandle self, MemberName ref, boolean doDispatch, Class<?> caller); 2204 // void init(DirectMethodHandle self, MemberName ref, boolean doDispatch, Class<?> caller);
2171 JVM_ENTRY(void, MHI_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh, 2205 JVM_ENTRY(void, MHN_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh,
2172 jobject target_jh, jboolean do_dispatch, jobject caller_jh)) { 2206 jobject target_jh, jboolean do_dispatch, jobject caller_jh)) {
2173 ResourceMark rm; // for error messages 2207 ResourceMark rm; // for error messages
2174 2208
2175 // This is the guy we are initializing: 2209 // This is the guy we are initializing:
2176 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2210 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2177 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); 2211 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh));
2178 2212
2179 // Early returns out of this method leave the DMH in an unfinished state. 2213 // Early returns out of this method leave the DMH in an unfinished state.
2180 assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); 2214 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null");
2181 2215
2182 // which method are we really talking about? 2216 // which method are we really talking about?
2183 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2217 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2184 oop target_oop = JNIHandles::resolve_non_null(target_jh); 2218 oop target_oop = JNIHandles::resolve_non_null(target_jh);
2185 if (sun_dyn_MemberName::is_instance(target_oop) && 2219 if (java_lang_invoke_MemberName::is_instance(target_oop) &&
2186 sun_dyn_MemberName::vmindex(target_oop) == VM_INDEX_UNINITIALIZED) { 2220 java_lang_invoke_MemberName::vmindex(target_oop) == VM_INDEX_UNINITIALIZED) {
2187 Handle mname(THREAD, target_oop); 2221 Handle mname(THREAD, target_oop);
2188 MethodHandles::resolve_MemberName(mname, CHECK); 2222 MethodHandles::resolve_MemberName(mname, CHECK);
2189 target_oop = mname(); // in case of GC 2223 target_oop = mname(); // in case of GC
2190 } 2224 }
2191 2225
2230 MethodHandles::init_DirectMethodHandle(mh, m, (do_dispatch != JNI_FALSE), CHECK); 2264 MethodHandles::init_DirectMethodHandle(mh, m, (do_dispatch != JNI_FALSE), CHECK);
2231 } 2265 }
2232 JVM_END 2266 JVM_END
2233 2267
2234 // bound method handles 2268 // bound method handles
2235 JVM_ENTRY(void, MHI_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh, 2269 JVM_ENTRY(void, MHN_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh,
2236 jobject target_jh, int argnum)) { 2270 jobject target_jh, int argnum)) {
2237 ResourceMark rm; // for error messages 2271 ResourceMark rm; // for error messages
2238 2272
2239 // This is the guy we are initializing: 2273 // This is the guy we are initializing:
2240 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2274 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2241 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); 2275 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh));
2242 2276
2243 // Early returns out of this method leave the BMH in an unfinished state. 2277 // Early returns out of this method leave the BMH in an unfinished state.
2244 assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); 2278 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null");
2245 2279
2246 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2280 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2247 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); 2281 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh));
2248 2282
2249 if (!java_dyn_MethodHandle::is_instance(target())) { 2283 if (!java_lang_invoke_MethodHandle::is_instance(target())) {
2250 // Target object is a reflective method. (%%% Do we need this alternate path?) 2284 // Target object is a reflective method. (%%% Do we need this alternate path?)
2251 Untested("init_BMH of non-MH"); 2285 Untested("init_BMH of non-MH");
2252 if (argnum != 0) { THROW(vmSymbols::java_lang_InternalError()); } 2286 if (argnum != 0) { THROW(vmSymbols::java_lang_InternalError()); }
2253 int decode_flags = 0; klassOop receiver_limit_oop = NULL; 2287 int decode_flags = 0; klassOop receiver_limit_oop = NULL;
2254 methodHandle m(THREAD, 2288 methodHandle m(THREAD,
2267 MethodHandles::init_BoundMethodHandle(mh, target, argnum, CHECK); 2301 MethodHandles::init_BoundMethodHandle(mh, target, argnum, CHECK);
2268 } 2302 }
2269 JVM_END 2303 JVM_END
2270 2304
2271 // adapter method handles 2305 // adapter method handles
2272 JVM_ENTRY(void, MHI_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh, 2306 JVM_ENTRY(void, MHN_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh,
2273 jobject target_jh, int argnum)) { 2307 jobject target_jh, int argnum)) {
2274 // This is the guy we are initializing: 2308 // This is the guy we are initializing:
2275 if (mh_jh == NULL || target_jh == NULL) { 2309 if (mh_jh == NULL || target_jh == NULL) {
2276 THROW(vmSymbols::java_lang_InternalError()); 2310 THROW(vmSymbols::java_lang_InternalError());
2277 } 2311 }
2278 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); 2312 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh));
2279 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); 2313 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh));
2280 2314
2281 // Early returns out of this method leave the AMH in an unfinished state. 2315 // Early returns out of this method leave the AMH in an unfinished state.
2282 assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); 2316 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null");
2283 2317
2284 MethodHandles::init_AdapterMethodHandle(mh, target, argnum, CHECK); 2318 MethodHandles::init_AdapterMethodHandle(mh, target, argnum, CHECK);
2285 } 2319 }
2286 JVM_END 2320 JVM_END
2287 2321
2288 // method type forms 2322 // method type forms
2289 JVM_ENTRY(void, MHI_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) { 2323 JVM_ENTRY(void, MHN_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) {
2290 if (erased_jh == NULL) return; 2324 if (erased_jh == NULL) return;
2291 if (TraceMethodHandles) { 2325 if (TraceMethodHandles) {
2292 tty->print("creating MethodType form "); 2326 tty->print("creating MethodType form ");
2293 if (WizardMode || Verbose) { // Warning: this calls Java code on the MH! 2327 if (WizardMode || Verbose) { // Warning: this calls Java code on the MH!
2294 // call Object.toString() 2328 // call Object.toString()
2305 } 2339 }
2306 } 2340 }
2307 JVM_END 2341 JVM_END
2308 2342
2309 // debugging and reflection 2343 // debugging and reflection
2310 JVM_ENTRY(jobject, MHI_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) { 2344 JVM_ENTRY(jobject, MHN_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) {
2311 Handle mh(THREAD, JNIHandles::resolve(mh_jh)); 2345 Handle mh(THREAD, JNIHandles::resolve(mh_jh));
2312 if (!java_dyn_MethodHandle::is_instance(mh())) { 2346 if (!java_lang_invoke_MethodHandle::is_instance(mh())) {
2313 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException()); 2347 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
2314 } 2348 }
2315 oop target = MethodHandles::encode_target(mh, format, CHECK_NULL); 2349 oop target = MethodHandles::encode_target(mh, format, CHECK_NULL);
2316 return JNIHandles::make_local(THREAD, target); 2350 return JNIHandles::make_local(THREAD, target);
2317 } 2351 }
2318 JVM_END 2352 JVM_END
2319 2353
2320 JVM_ENTRY(jint, MHI_getConstant(JNIEnv *env, jobject igcls, jint which)) { 2354 JVM_ENTRY(jint, MHN_getConstant(JNIEnv *env, jobject igcls, jint which)) {
2321 switch (which) { 2355 switch (which) {
2322 case MethodHandles::GC_JVM_PUSH_LIMIT: 2356 case MethodHandles::GC_JVM_PUSH_LIMIT:
2323 guarantee(MethodHandlePushLimit >= 2 && MethodHandlePushLimit <= 0xFF, 2357 guarantee(MethodHandlePushLimit >= 2 && MethodHandlePushLimit <= 0xFF,
2324 "MethodHandlePushLimit parameter must be in valid range"); 2358 "MethodHandlePushLimit parameter must be in valid range");
2325 return MethodHandlePushLimit; 2359 return MethodHandlePushLimit;
2339 template(MethodHandles,GC_JVM_STACK_MOVE_UNIT) \ 2373 template(MethodHandles,GC_JVM_STACK_MOVE_UNIT) \
2340 template(MethodHandles,ETF_HANDLE_OR_METHOD_NAME) \ 2374 template(MethodHandles,ETF_HANDLE_OR_METHOD_NAME) \
2341 template(MethodHandles,ETF_DIRECT_HANDLE) \ 2375 template(MethodHandles,ETF_DIRECT_HANDLE) \
2342 template(MethodHandles,ETF_METHOD_NAME) \ 2376 template(MethodHandles,ETF_METHOD_NAME) \
2343 template(MethodHandles,ETF_REFLECT_METHOD) \ 2377 template(MethodHandles,ETF_REFLECT_METHOD) \
2344 template(sun_dyn_MemberName,MN_IS_METHOD) \ 2378 template(java_lang_invoke_MemberName,MN_IS_METHOD) \
2345 template(sun_dyn_MemberName,MN_IS_CONSTRUCTOR) \ 2379 template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \
2346 template(sun_dyn_MemberName,MN_IS_FIELD) \ 2380 template(java_lang_invoke_MemberName,MN_IS_FIELD) \
2347 template(sun_dyn_MemberName,MN_IS_TYPE) \ 2381 template(java_lang_invoke_MemberName,MN_IS_TYPE) \
2348 template(sun_dyn_MemberName,MN_SEARCH_SUPERCLASSES) \ 2382 template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \
2349 template(sun_dyn_MemberName,MN_SEARCH_INTERFACES) \ 2383 template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \
2350 template(sun_dyn_MemberName,VM_INDEX_UNINITIALIZED) \ 2384 template(java_lang_invoke_MemberName,VM_INDEX_UNINITIALIZED) \
2351 template(sun_dyn_AdapterMethodHandle,OP_RETYPE_ONLY) \ 2385 template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_ONLY) \
2352 template(sun_dyn_AdapterMethodHandle,OP_RETYPE_RAW) \ 2386 template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_RAW) \
2353 template(sun_dyn_AdapterMethodHandle,OP_CHECK_CAST) \ 2387 template(java_lang_invoke_AdapterMethodHandle,OP_CHECK_CAST) \
2354 template(sun_dyn_AdapterMethodHandle,OP_PRIM_TO_PRIM) \ 2388 template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_PRIM) \
2355 template(sun_dyn_AdapterMethodHandle,OP_REF_TO_PRIM) \ 2389 template(java_lang_invoke_AdapterMethodHandle,OP_REF_TO_PRIM) \
2356 template(sun_dyn_AdapterMethodHandle,OP_PRIM_TO_REF) \ 2390 template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_REF) \
2357 template(sun_dyn_AdapterMethodHandle,OP_SWAP_ARGS) \ 2391 template(java_lang_invoke_AdapterMethodHandle,OP_SWAP_ARGS) \
2358 template(sun_dyn_AdapterMethodHandle,OP_ROT_ARGS) \ 2392 template(java_lang_invoke_AdapterMethodHandle,OP_ROT_ARGS) \
2359 template(sun_dyn_AdapterMethodHandle,OP_DUP_ARGS) \ 2393 template(java_lang_invoke_AdapterMethodHandle,OP_DUP_ARGS) \
2360 template(sun_dyn_AdapterMethodHandle,OP_DROP_ARGS) \ 2394 template(java_lang_invoke_AdapterMethodHandle,OP_DROP_ARGS) \
2361 template(sun_dyn_AdapterMethodHandle,OP_COLLECT_ARGS) \ 2395 template(java_lang_invoke_AdapterMethodHandle,OP_COLLECT_ARGS) \
2362 template(sun_dyn_AdapterMethodHandle,OP_SPREAD_ARGS) \ 2396 template(java_lang_invoke_AdapterMethodHandle,OP_SPREAD_ARGS) \
2363 template(sun_dyn_AdapterMethodHandle,OP_FLYBY) \ 2397 template(java_lang_invoke_AdapterMethodHandle,OP_FLYBY) \
2364 template(sun_dyn_AdapterMethodHandle,OP_RICOCHET) \ 2398 template(java_lang_invoke_AdapterMethodHandle,OP_RICOCHET) \
2365 template(sun_dyn_AdapterMethodHandle,CONV_OP_LIMIT) \ 2399 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_LIMIT) \
2366 template(sun_dyn_AdapterMethodHandle,CONV_OP_MASK) \ 2400 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_MASK) \
2367 template(sun_dyn_AdapterMethodHandle,CONV_VMINFO_MASK) \ 2401 template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_MASK) \
2368 template(sun_dyn_AdapterMethodHandle,CONV_VMINFO_SHIFT) \ 2402 template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_SHIFT) \
2369 template(sun_dyn_AdapterMethodHandle,CONV_OP_SHIFT) \ 2403 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_SHIFT) \
2370 template(sun_dyn_AdapterMethodHandle,CONV_DEST_TYPE_SHIFT) \ 2404 template(java_lang_invoke_AdapterMethodHandle,CONV_DEST_TYPE_SHIFT) \
2371 template(sun_dyn_AdapterMethodHandle,CONV_SRC_TYPE_SHIFT) \ 2405 template(java_lang_invoke_AdapterMethodHandle,CONV_SRC_TYPE_SHIFT) \
2372 template(sun_dyn_AdapterMethodHandle,CONV_STACK_MOVE_SHIFT) \ 2406 template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_SHIFT) \
2373 template(sun_dyn_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \ 2407 template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \
2374 /*end*/ 2408 /*end*/
2375 2409
2376 #define ONE_PLUS(scope,value) 1+ 2410 #define ONE_PLUS(scope,value) 1+
2377 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS) 0; 2411 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS) 0;
2378 #define VALUE_COMMA(scope,value) scope::value, 2412 #define VALUE_COMMA(scope,value) scope::value,
2384 #undef VALUE_COMMA 2418 #undef VALUE_COMMA
2385 #undef STRING_NULL 2419 #undef STRING_NULL
2386 #undef EACH_NAMED_CON 2420 #undef EACH_NAMED_CON
2387 #endif 2421 #endif
2388 2422
2389 JVM_ENTRY(jint, MHI_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) { 2423 JVM_ENTRY(jint, MHN_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) {
2390 #ifndef PRODUCT 2424 #ifndef PRODUCT
2391 if (which >= 0 && which < con_value_count) { 2425 if (which >= 0 && which < con_value_count) {
2392 int con = con_values[which]; 2426 int con = con_values[which];
2393 objArrayOop box = (objArrayOop) JNIHandles::resolve(box_jh); 2427 objArrayOop box = (objArrayOop) JNIHandles::resolve(box_jh);
2394 if (box != NULL && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) { 2428 if (box != NULL && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) {
2404 return 0; 2438 return 0;
2405 } 2439 }
2406 JVM_END 2440 JVM_END
2407 2441
2408 // void init(MemberName self, AccessibleObject ref) 2442 // void init(MemberName self, AccessibleObject ref)
2409 JVM_ENTRY(void, MHI_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) { 2443 JVM_ENTRY(void, MHN_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) {
2410 if (mname_jh == NULL || target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2444 if (mname_jh == NULL || target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2411 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); 2445 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
2412 oop target_oop = JNIHandles::resolve_non_null(target_jh); 2446 oop target_oop = JNIHandles::resolve_non_null(target_jh);
2413 MethodHandles::init_MemberName(mname(), target_oop); 2447 MethodHandles::init_MemberName(mname(), target_oop);
2414 } 2448 }
2415 JVM_END 2449 JVM_END
2416 2450
2417 // void expand(MemberName self) 2451 // void expand(MemberName self)
2418 JVM_ENTRY(void, MHI_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) { 2452 JVM_ENTRY(void, MHN_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) {
2419 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2453 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2420 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); 2454 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
2421 MethodHandles::expand_MemberName(mname, 0, CHECK); 2455 MethodHandles::expand_MemberName(mname, 0, CHECK);
2422 } 2456 }
2423 JVM_END 2457 JVM_END
2424 2458
2425 // void resolve(MemberName self, Class<?> caller) 2459 // void resolve(MemberName self, Class<?> caller)
2426 JVM_ENTRY(void, MHI_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) { 2460 JVM_ENTRY(void, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) {
2427 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } 2461 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); }
2428 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); 2462 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
2429 2463
2430 // The trusted Java code that calls this method should already have performed 2464 // The trusted Java code that calls this method should already have performed
2431 // access checks on behalf of the given caller. But, we can verify this. 2465 // access checks on behalf of the given caller. But, we can verify this.
2432 if (VerifyMethodHandles && caller_jh != NULL) { 2466 if (VerifyMethodHandles && caller_jh != NULL) {
2433 klassOop reference_klass = java_lang_Class::as_klassOop(sun_dyn_MemberName::clazz(mname())); 2467 klassOop reference_klass = java_lang_Class::as_klassOop(java_lang_invoke_MemberName::clazz(mname()));
2434 if (reference_klass != NULL) { 2468 if (reference_klass != NULL) {
2435 // Emulate LinkResolver::check_klass_accessability. 2469 // Emulate LinkResolver::check_klass_accessability.
2436 klassOop caller = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh)); 2470 klassOop caller = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh));
2437 if (!Reflection::verify_class_access(caller, 2471 if (!Reflection::verify_class_access(caller,
2438 reference_klass, 2472 reference_klass,
2446 } 2480 }
2447 JVM_END 2481 JVM_END
2448 2482
2449 // static native int getMembers(Class<?> defc, String matchName, String matchSig, 2483 // static native int getMembers(Class<?> defc, String matchName, String matchSig,
2450 // int matchFlags, Class<?> caller, int skip, MemberName[] results); 2484 // int matchFlags, Class<?> caller, int skip, MemberName[] results);
2451 JVM_ENTRY(jint, MHI_getMembers(JNIEnv *env, jobject igcls, 2485 JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls,
2452 jclass clazz_jh, jstring name_jh, jstring sig_jh, 2486 jclass clazz_jh, jstring name_jh, jstring sig_jh,
2453 int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) { 2487 int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) {
2454 if (clazz_jh == NULL || results_jh == NULL) return -1; 2488 if (clazz_jh == NULL || results_jh == NULL) return -1;
2455 klassOop k_oop = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz_jh)); 2489 klassOop k_oop = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz_jh));
2456 2490
2485 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks 2519 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks
2486 return res; 2520 return res;
2487 } 2521 }
2488 JVM_END 2522 JVM_END
2489 2523
2490 JVM_ENTRY(void, MHI_registerBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh, jobject bsm_jh)) {
2491 instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD);
2492 if (!AllowTransitionalJSR292) {
2493 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2494 "registerBootstrapMethod is only supported in JSR 292 EDR");
2495 }
2496 ik->link_class(CHECK);
2497 if (!java_dyn_MethodHandle::is_instance(JNIHandles::resolve(bsm_jh))) {
2498 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "method handle");
2499 }
2500 const char* err = NULL;
2501 if (ik->is_initialized() || ik->is_in_error_state()) {
2502 err = "too late: class is already initialized";
2503 } else {
2504 ObjectLocker ol(ik, THREAD); // note: this should be a recursive lock
2505 if (ik->is_not_initialized() ||
2506 (ik->is_being_initialized() && ik->is_reentrant_initialization(THREAD))) {
2507 if (ik->bootstrap_method() != NULL) {
2508 err = "class is already equipped with a bootstrap method";
2509 } else {
2510 ik->set_bootstrap_method(JNIHandles::resolve_non_null(bsm_jh));
2511 err = NULL;
2512 }
2513 } else {
2514 err = "class is already initialized";
2515 if (ik->is_being_initialized())
2516 err = "class is already being initialized in a different thread";
2517 }
2518 }
2519 if (err != NULL) {
2520 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), err);
2521 }
2522 }
2523 JVM_END
2524
2525 JVM_ENTRY(jobject, MHI_getBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh)) {
2526 instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD);
2527 return JNIHandles::make_local(THREAD, ik->bootstrap_method());
2528 }
2529 JVM_END
2530
2531 JVM_ENTRY(void, MHI_setCallSiteTarget(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) {
2532 // No special action required, yet.
2533 oop site_oop = JNIHandles::resolve(site_jh);
2534 if (!java_dyn_CallSite::is_instance(site_oop))
2535 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "not a CallSite");
2536 java_dyn_CallSite::set_target(site_oop, JNIHandles::resolve(target_jh));
2537 }
2538 JVM_END
2539
2540 2524
2541 /// JVM_RegisterMethodHandleMethods 2525 /// JVM_RegisterMethodHandleMethods
2542 2526
2543 #define ADR "J"
2544
2545 #define LANG "Ljava/lang/" 2527 #define LANG "Ljava/lang/"
2546 #define JDYN "Ljava/dyn/" 2528 #define JLINV "Ljava/lang/invoke/"
2547 #define IDYN "Lsun/dyn/"
2548 2529
2549 #define OBJ LANG"Object;" 2530 #define OBJ LANG"Object;"
2550 #define CLS LANG"Class;" 2531 #define CLS LANG"Class;"
2551 #define STRG LANG"String;" 2532 #define STRG LANG"String;"
2552 #define CST JDYN"CallSite;" 2533 #define MT JLINV"MethodType;"
2553 #define MT JDYN"MethodType;" 2534 #define MH JLINV"MethodHandle;"
2554 #define MH JDYN"MethodHandle;" 2535 #define MEM JLINV"MemberName;"
2555 #define MHI IDYN"MethodHandleImpl;" 2536 #define AMH JLINV"AdapterMethodHandle;"
2556 #define MEM IDYN"MemberName;" 2537 #define BMH JLINV"BoundMethodHandle;"
2557 #define AMH IDYN"AdapterMethodHandle;" 2538 #define DMH JLINV"DirectMethodHandle;"
2558 #define BMH IDYN"BoundMethodHandle;"
2559 #define DMH IDYN"DirectMethodHandle;"
2560 2539
2561 #define CC (char*) /*cast a literal from (const char*)*/ 2540 #define CC (char*) /*cast a literal from (const char*)*/
2562 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) 2541 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
2563 2542
2564 // These are the native methods on sun.dyn.MethodHandleNatives. 2543 // These are the native methods on sun.invoke.MethodHandleNatives.
2565 static JNINativeMethod methods[] = { 2544 static JNINativeMethod methods[] = {
2566 // void init(MemberName self, AccessibleObject ref) 2545 // void init(MemberName self, AccessibleObject ref)
2567 {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHI_init_AMH)}, 2546 {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)},
2568 {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHI_init_BMH)}, 2547 {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)},
2569 {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHI_init_DMH)}, 2548 {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)},
2570 {CC"init", CC"("MT")V", FN_PTR(MHI_init_MT)}, 2549 {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)},
2571 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHI_init_Mem)}, 2550 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)},
2572 {CC"expand", CC"("MEM")V", FN_PTR(MHI_expand_Mem)}, 2551 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)},
2573 {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHI_resolve_Mem)}, 2552 {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)},
2574 {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHI_getTarget)}, 2553 {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)},
2575 {CC"getConstant", CC"(I)I", FN_PTR(MHI_getConstant)}, 2554 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)},
2576 // static native int getNamedCon(int which, Object[] name) 2555 // static native int getNamedCon(int which, Object[] name)
2577 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHI_getNamedCon)}, 2556 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)},
2578 // static native int getMembers(Class<?> defc, String matchName, String matchSig, 2557 // static native int getMembers(Class<?> defc, String matchName, String matchSig,
2579 // int matchFlags, Class<?> caller, int skip, MemberName[] results); 2558 // int matchFlags, Class<?> caller, int skip, MemberName[] results);
2580 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHI_getMembers)} 2559 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)}
2581 }; 2560 };
2582
2583 // More entry points specifically for EnableInvokeDynamic.
2584 static JNINativeMethod methods2[] = {
2585 {CC"registerBootstrap", CC"("CLS MH")V", FN_PTR(MHI_registerBootstrap)},
2586 {CC"getBootstrap", CC"("CLS")"MH, FN_PTR(MHI_getBootstrap)},
2587 {CC"setCallSiteTarget", CC"("CST MH")V", FN_PTR(MHI_setCallSiteTarget)}
2588 };
2589
2590 2561
2591 // This one function is exported, used by NativeLookup. 2562 // This one function is exported, used by NativeLookup.
2592 2563
2593 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { 2564 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
2594 assert(MethodHandles::spot_check_entry_names(), "entry enum is OK"); 2565 assert(MethodHandles::spot_check_entry_names(), "entry enum is OK");
2595 2566
2596 // note: this explicit warning-producing stuff will be replaced by auto-detection of the JSR 292 classes 2567 if (!EnableInvokeDynamic) {
2597 2568 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable.");
2598 if (!EnableMethodHandles) {
2599 warning("JSR 292 method handles are disabled in this JVM. Use -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles to enable.");
2600 return; // bind nothing 2569 return; // bind nothing
2601 } 2570 }
2602 2571
2603 bool enable_MH = true; 2572 bool enable_MH = true;
2604 2573
2613 env->ExceptionClear(); 2582 env->ExceptionClear();
2614 } 2583 }
2615 } 2584 }
2616 2585
2617 if (enable_MH) { 2586 if (enable_MH) {
2618 KlassHandle MHI_klass = SystemDictionaryHandles::MethodHandleImpl_klass(); 2587 KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass();
2619 if (MHI_klass.not_null()) { 2588 if (MHN_klass.not_null()) {
2620 TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK); 2589 TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK);
2621 TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK); 2590 TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK);
2622 methodOop raiseException_method = instanceKlass::cast(MHI_klass->as_klassOop()) 2591 methodOop raiseException_method = instanceKlass::cast(MHN_klass->as_klassOop())
2623 ->find_method(raiseException_name, raiseException_sig); 2592 ->find_method(raiseException_name, raiseException_sig);
2624 if (raiseException_method != NULL && raiseException_method->is_static()) { 2593 if (raiseException_method != NULL && raiseException_method->is_static()) {
2625 MethodHandles::set_raise_exception_method(raiseException_method); 2594 MethodHandles::set_raise_exception_method(raiseException_method);
2626 } else { 2595 } else {
2627 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); 2596 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support.");
2631 enable_MH = false; 2600 enable_MH = false;
2632 } 2601 }
2633 } 2602 }
2634 2603
2635 if (enable_MH) { 2604 if (enable_MH) {
2636 // We need to link the MethodHandleImpl klass before we generate
2637 // the method handle adapters as the _raise_exception adapter uses
2638 // one of its methods (and its c2i-adapter).
2639 KlassHandle k = SystemDictionaryHandles::MethodHandleImpl_klass();
2640 instanceKlass* ik = instanceKlass::cast(k());
2641 ik->link_class(CHECK);
2642
2643 MethodHandles::generate_adapters(); 2605 MethodHandles::generate_adapters();
2644 MethodHandles::set_enabled(true); 2606 MethodHandles::set_enabled(true);
2645 } 2607 }
2646
2647 if (!EnableInvokeDynamic) {
2648 warning("JSR 292 invokedynamic is disabled in this JVM. Use -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic to enable.");
2649 return; // bind nothing
2650 }
2651
2652 {
2653 ThreadToNativeFromVM ttnfv(thread);
2654
2655 int status = env->RegisterNatives(MHN_class, methods2, sizeof(methods2)/sizeof(JNINativeMethod));
2656 if (env->ExceptionOccurred()) {
2657 MethodHandles::set_enabled(false);
2658 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support.");
2659 env->ExceptionClear();
2660 } else {
2661 MethodHandles::set_enabled(true);
2662 }
2663 }
2664 } 2608 }
2665 JVM_END 2609 JVM_END