2375 |
2394 |
2376 |
2395 |
2377 // Support for java_lang_invoke_MethodHandle |
2396 // Support for java_lang_invoke_MethodHandle |
2378 |
2397 |
2379 int java_lang_invoke_MethodHandle::_type_offset; |
2398 int java_lang_invoke_MethodHandle::_type_offset; |
2380 int java_lang_invoke_MethodHandle::_vmtarget_offset; |
2399 int java_lang_invoke_MethodHandle::_form_offset; |
2381 int java_lang_invoke_MethodHandle::_vmentry_offset; |
|
2382 |
2400 |
2383 int java_lang_invoke_MemberName::_clazz_offset; |
2401 int java_lang_invoke_MemberName::_clazz_offset; |
2384 int java_lang_invoke_MemberName::_name_offset; |
2402 int java_lang_invoke_MemberName::_name_offset; |
2385 int java_lang_invoke_MemberName::_type_offset; |
2403 int java_lang_invoke_MemberName::_type_offset; |
2386 int java_lang_invoke_MemberName::_flags_offset; |
2404 int java_lang_invoke_MemberName::_flags_offset; |
2387 int java_lang_invoke_MemberName::_vmtarget_offset; |
2405 int java_lang_invoke_MemberName::_vmtarget_offset; |
2388 int java_lang_invoke_MemberName::_vmindex_offset; |
2406 int java_lang_invoke_MemberName::_vmindex_offset; |
2389 |
2407 |
2390 int java_lang_invoke_DirectMethodHandle::_vmindex_offset; |
2408 int java_lang_invoke_LambdaForm::_vmentry_offset; |
2391 |
|
2392 int java_lang_invoke_BoundMethodHandle::_argument_offset; |
|
2393 int java_lang_invoke_BoundMethodHandle::_vmargslot_offset; |
|
2394 |
|
2395 int java_lang_invoke_AdapterMethodHandle::_conversion_offset; |
|
2396 |
|
2397 int java_lang_invoke_CountingMethodHandle::_vmcount_offset; |
|
2398 |
2409 |
2399 void java_lang_invoke_MethodHandle::compute_offsets() { |
2410 void java_lang_invoke_MethodHandle::compute_offsets() { |
2400 klassOop klass_oop = SystemDictionary::MethodHandle_klass(); |
2411 klassOop klass_oop = SystemDictionary::MethodHandle_klass(); |
2401 if (klass_oop != NULL && EnableInvokeDynamic) { |
2412 if (klass_oop != NULL && EnableInvokeDynamic) { |
2402 bool allow_super = false; |
2413 compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature()); |
2403 compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature(), allow_super); |
2414 compute_optional_offset(_form_offset, klass_oop, vmSymbols::form_name(), vmSymbols::java_lang_invoke_LambdaForm_signature()); |
2404 METHODHANDLE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
2415 if (_form_offset == 0) { |
|
2416 EnableInvokeDynamic = false; |
|
2417 } |
2405 } |
2418 } |
2406 } |
2419 } |
2407 |
2420 |
2408 void java_lang_invoke_MemberName::compute_offsets() { |
2421 void java_lang_invoke_MemberName::compute_offsets() { |
2409 klassOop klass_oop = SystemDictionary::MemberName_klass(); |
2422 klassOop klass_oop = SystemDictionary::MemberName_klass(); |
2410 if (klass_oop != NULL && EnableInvokeDynamic) { |
2423 if (klass_oop != NULL && EnableInvokeDynamic) { |
2411 compute_offset(_clazz_offset, klass_oop, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
2424 compute_offset(_clazz_offset, klass_oop, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
2412 compute_offset(_name_offset, klass_oop, vmSymbols::name_name(), vmSymbols::string_signature()); |
2425 compute_offset(_name_offset, klass_oop, vmSymbols::name_name(), vmSymbols::string_signature()); |
2413 compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::object_signature()); |
2426 compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::object_signature()); |
2414 compute_offset(_flags_offset, klass_oop, vmSymbols::flags_name(), vmSymbols::int_signature()); |
2427 compute_offset(_flags_offset, klass_oop, vmSymbols::flags_name(), vmSymbols::int_signature()); |
2415 compute_offset(_vmindex_offset, klass_oop, vmSymbols::vmindex_name(), vmSymbols::int_signature()); |
|
2416 MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
2428 MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
2417 } |
2429 } |
2418 } |
2430 } |
2419 |
2431 |
2420 void java_lang_invoke_DirectMethodHandle::compute_offsets() { |
2432 void java_lang_invoke_LambdaForm::compute_offsets() { |
2421 klassOop k = SystemDictionary::DirectMethodHandle_klass(); |
2433 klassOop klass_oop = SystemDictionary::LambdaForm_klass(); |
2422 if (k != NULL && EnableInvokeDynamic) { |
2434 if (klass_oop != NULL && EnableInvokeDynamic) { |
2423 DIRECTMETHODHANDLE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
2435 compute_offset(_vmentry_offset, klass_oop, vmSymbols::vmentry_name(), vmSymbols::java_lang_invoke_MemberName_signature()); |
2424 } |
2436 } |
2425 } |
|
2426 |
|
2427 void java_lang_invoke_BoundMethodHandle::compute_offsets() { |
|
2428 klassOop k = SystemDictionary::BoundMethodHandle_klass(); |
|
2429 if (k != NULL && EnableInvokeDynamic) { |
|
2430 compute_offset(_vmargslot_offset, k, vmSymbols::vmargslot_name(), vmSymbols::int_signature(), true); |
|
2431 compute_offset(_argument_offset, k, vmSymbols::argument_name(), vmSymbols::object_signature(), true); |
|
2432 } |
|
2433 } |
|
2434 |
|
2435 void java_lang_invoke_AdapterMethodHandle::compute_offsets() { |
|
2436 klassOop k = SystemDictionary::AdapterMethodHandle_klass(); |
|
2437 if (k != NULL && EnableInvokeDynamic) { |
|
2438 compute_offset(_conversion_offset, k, vmSymbols::conversion_name(), vmSymbols::int_signature(), true); |
|
2439 } |
|
2440 } |
|
2441 |
|
2442 void java_lang_invoke_CountingMethodHandle::compute_offsets() { |
|
2443 klassOop k = SystemDictionary::CountingMethodHandle_klass(); |
|
2444 if (k != NULL && EnableInvokeDynamic) { |
|
2445 compute_offset(_vmcount_offset, k, vmSymbols::vmcount_name(), vmSymbols::int_signature(), true); |
|
2446 } |
|
2447 } |
|
2448 |
|
2449 int java_lang_invoke_CountingMethodHandle::vmcount(oop mh) { |
|
2450 assert(is_instance(mh), "CMH only"); |
|
2451 return mh->int_field(_vmcount_offset); |
|
2452 } |
|
2453 |
|
2454 void java_lang_invoke_CountingMethodHandle::set_vmcount(oop mh, int count) { |
|
2455 assert(is_instance(mh), "CMH only"); |
|
2456 mh->int_field_put(_vmcount_offset, count); |
|
2457 } |
2437 } |
2458 |
2438 |
2459 oop java_lang_invoke_MethodHandle::type(oop mh) { |
2439 oop java_lang_invoke_MethodHandle::type(oop mh) { |
2460 return mh->obj_field(_type_offset); |
2440 return mh->obj_field(_type_offset); |
2461 } |
2441 } |
2462 |
2442 |
2463 void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) { |
2443 void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) { |
2464 mh->obj_field_put(_type_offset, mtype); |
2444 mh->obj_field_put(_type_offset, mtype); |
2465 } |
2445 } |
2466 |
2446 |
2467 // fetch type.form.vmslots, which is the number of JVM stack slots |
2447 oop java_lang_invoke_MethodHandle::form(oop mh) { |
2468 // required to carry the arguments of this MH |
2448 assert(_form_offset != 0, ""); |
2469 int java_lang_invoke_MethodHandle::vmslots(oop mh) { |
2449 return mh->obj_field(_form_offset); |
2470 oop mtype = type(mh); |
2450 } |
2471 if (mtype == NULL) return 0; // Java code would get NPE |
2451 |
2472 oop form = java_lang_invoke_MethodType::form(mtype); |
2452 void java_lang_invoke_MethodHandle::set_form(oop mh, oop lform) { |
2473 if (form == NULL) return 0; // Java code would get NPE |
2453 assert(_form_offset != 0, ""); |
2474 return java_lang_invoke_MethodTypeForm::vmslots(form); |
2454 mh->obj_field_put(_form_offset, lform); |
2475 } |
|
2476 |
|
2477 // fetch the low-level entry point for this mh |
|
2478 MethodHandleEntry* java_lang_invoke_MethodHandle::vmentry(oop mh) { |
|
2479 return (MethodHandleEntry*) mh->address_field(_vmentry_offset); |
|
2480 } |
|
2481 |
|
2482 void java_lang_invoke_MethodHandle::set_vmentry(oop mh, MethodHandleEntry* me) { |
|
2483 assert(_vmentry_offset != 0, "must be present"); |
|
2484 |
|
2485 // This is always the final step that initializes a valid method handle: |
|
2486 mh->release_address_field_put(_vmentry_offset, (address) me); |
|
2487 |
|
2488 // There should be enough memory barriers on exit from native methods |
|
2489 // to ensure that the MH is fully initialized to all threads before |
|
2490 // Java code can publish it in global data structures. |
|
2491 // But just in case, we use release_address_field_put. |
|
2492 } |
2455 } |
2493 |
2456 |
2494 /// MemberName accessors |
2457 /// MemberName accessors |
2495 |
2458 |
2496 oop java_lang_invoke_MemberName::clazz(oop mname) { |
2459 oop java_lang_invoke_MemberName::clazz(oop mname) { |
2538 return mname->obj_field(_vmtarget_offset); |
2501 return mname->obj_field(_vmtarget_offset); |
2539 } |
2502 } |
2540 |
2503 |
2541 void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) { |
2504 void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) { |
2542 assert(is_instance(mname), "wrong type"); |
2505 assert(is_instance(mname), "wrong type"); |
|
2506 #ifdef ASSERT |
|
2507 // check the type of the vmtarget |
|
2508 if (ref != NULL) { |
|
2509 switch (flags(mname) & (MN_IS_METHOD | |
|
2510 MN_IS_CONSTRUCTOR | |
|
2511 MN_IS_FIELD)) { |
|
2512 case MN_IS_METHOD: |
|
2513 case MN_IS_CONSTRUCTOR: |
|
2514 assert(ref->is_method(), "should be a method"); |
|
2515 break; |
|
2516 case MN_IS_FIELD: |
|
2517 assert(ref->is_klass(), "should be a class"); |
|
2518 break; |
|
2519 default: |
|
2520 ShouldNotReachHere(); |
|
2521 } |
|
2522 } |
|
2523 #endif //ASSERT |
2543 mname->obj_field_put(_vmtarget_offset, ref); |
2524 mname->obj_field_put(_vmtarget_offset, ref); |
2544 } |
2525 } |
2545 |
2526 |
2546 int java_lang_invoke_MemberName::vmindex(oop mname) { |
2527 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) { |
2547 assert(is_instance(mname), "wrong type"); |
2528 assert(is_instance(mname), "wrong type"); |
2548 return mname->int_field(_vmindex_offset); |
2529 return (intptr_t) mname->address_field(_vmindex_offset); |
2549 } |
2530 } |
2550 |
2531 |
2551 void java_lang_invoke_MemberName::set_vmindex(oop mname, int index) { |
2532 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) { |
2552 assert(is_instance(mname), "wrong type"); |
2533 assert(is_instance(mname), "wrong type"); |
2553 mname->int_field_put(_vmindex_offset, index); |
2534 mname->address_field_put(_vmindex_offset, (address) index); |
2554 } |
2535 } |
2555 |
2536 |
2556 oop java_lang_invoke_MethodHandle::vmtarget(oop mh) { |
2537 oop java_lang_invoke_LambdaForm::vmentry(oop lform) { |
2557 assert(is_instance(mh), "MH only"); |
2538 assert(is_instance(lform), "wrong type"); |
2558 return mh->obj_field(_vmtarget_offset); |
2539 return lform->obj_field(_vmentry_offset); |
2559 } |
|
2560 |
|
2561 void java_lang_invoke_MethodHandle::set_vmtarget(oop mh, oop ref) { |
|
2562 assert(is_instance(mh), "MH only"); |
|
2563 mh->obj_field_put(_vmtarget_offset, ref); |
|
2564 } |
|
2565 |
|
2566 int java_lang_invoke_DirectMethodHandle::vmindex(oop mh) { |
|
2567 assert(is_instance(mh), "DMH only"); |
|
2568 return mh->int_field(_vmindex_offset); |
|
2569 } |
|
2570 |
|
2571 void java_lang_invoke_DirectMethodHandle::set_vmindex(oop mh, int index) { |
|
2572 assert(is_instance(mh), "DMH only"); |
|
2573 mh->int_field_put(_vmindex_offset, index); |
|
2574 } |
|
2575 |
|
2576 int java_lang_invoke_BoundMethodHandle::vmargslot(oop mh) { |
|
2577 assert(is_instance(mh), "BMH only"); |
|
2578 return mh->int_field(_vmargslot_offset); |
|
2579 } |
|
2580 |
|
2581 oop java_lang_invoke_BoundMethodHandle::argument(oop mh) { |
|
2582 assert(is_instance(mh), "BMH only"); |
|
2583 return mh->obj_field(_argument_offset); |
|
2584 } |
|
2585 |
|
2586 int java_lang_invoke_AdapterMethodHandle::conversion(oop mh) { |
|
2587 assert(is_instance(mh), "AMH only"); |
|
2588 return mh->int_field(_conversion_offset); |
|
2589 } |
|
2590 |
|
2591 void java_lang_invoke_AdapterMethodHandle::set_conversion(oop mh, int conv) { |
|
2592 assert(is_instance(mh), "AMH only"); |
|
2593 mh->int_field_put(_conversion_offset, conv); |
|
2594 } |
2540 } |
2595 |
2541 |
2596 |
2542 |
2597 // Support for java_lang_invoke_MethodType |
2543 // Support for java_lang_invoke_MethodType |
2598 |
2544 |
2599 int java_lang_invoke_MethodType::_rtype_offset; |
2545 int java_lang_invoke_MethodType::_rtype_offset; |
2600 int java_lang_invoke_MethodType::_ptypes_offset; |
2546 int java_lang_invoke_MethodType::_ptypes_offset; |
2601 int java_lang_invoke_MethodType::_form_offset; |
|
2602 |
2547 |
2603 void java_lang_invoke_MethodType::compute_offsets() { |
2548 void java_lang_invoke_MethodType::compute_offsets() { |
2604 klassOop k = SystemDictionary::MethodType_klass(); |
2549 klassOop k = SystemDictionary::MethodType_klass(); |
2605 if (k != NULL) { |
2550 if (k != NULL) { |
2606 compute_offset(_rtype_offset, k, vmSymbols::rtype_name(), vmSymbols::class_signature()); |
2551 compute_offset(_rtype_offset, k, vmSymbols::rtype_name(), vmSymbols::class_signature()); |
2607 compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature()); |
2552 compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature()); |
2608 compute_offset(_form_offset, k, vmSymbols::form_name(), vmSymbols::java_lang_invoke_MethodTypeForm_signature()); |
|
2609 } |
2553 } |
2610 } |
2554 } |
2611 |
2555 |
2612 void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) { |
2556 void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) { |
2613 st->print("("); |
2557 st->print("("); |
2654 objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) { |
2600 objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) { |
2655 assert(is_instance(mt), "must be a MethodType"); |
2601 assert(is_instance(mt), "must be a MethodType"); |
2656 return (objArrayOop) mt->obj_field(_ptypes_offset); |
2602 return (objArrayOop) mt->obj_field(_ptypes_offset); |
2657 } |
2603 } |
2658 |
2604 |
2659 oop java_lang_invoke_MethodType::form(oop mt) { |
|
2660 assert(is_instance(mt), "must be a MethodType"); |
|
2661 return mt->obj_field(_form_offset); |
|
2662 } |
|
2663 |
|
2664 oop java_lang_invoke_MethodType::ptype(oop mt, int idx) { |
2605 oop java_lang_invoke_MethodType::ptype(oop mt, int idx) { |
2665 return ptypes(mt)->obj_at(idx); |
2606 return ptypes(mt)->obj_at(idx); |
2666 } |
2607 } |
2667 |
2608 |
2668 int java_lang_invoke_MethodType::ptype_count(oop mt) { |
2609 int java_lang_invoke_MethodType::ptype_count(oop mt) { |
2669 return ptypes(mt)->length(); |
2610 return ptypes(mt)->length(); |
2670 } |
2611 } |
2671 |
2612 |
2672 |
2613 int java_lang_invoke_MethodType::ptype_slot_count(oop mt) { |
2673 |
2614 objArrayOop pts = ptypes(mt); |
2674 // Support for java_lang_invoke_MethodTypeForm |
2615 int count = pts->length(); |
2675 |
2616 int slots = 0; |
2676 int java_lang_invoke_MethodTypeForm::_vmslots_offset; |
2617 for (int i = 0; i < count; i++) { |
2677 int java_lang_invoke_MethodTypeForm::_vmlayout_offset; |
2618 BasicType bt = java_lang_Class::as_BasicType(pts->obj_at(i)); |
2678 int java_lang_invoke_MethodTypeForm::_erasedType_offset; |
2619 slots += type2size[bt]; |
2679 int java_lang_invoke_MethodTypeForm::_genericInvoker_offset; |
2620 } |
2680 |
2621 return slots; |
2681 void java_lang_invoke_MethodTypeForm::compute_offsets() { |
2622 } |
2682 klassOop k = SystemDictionary::MethodTypeForm_klass(); |
2623 |
2683 if (k != NULL) { |
2624 int java_lang_invoke_MethodType::rtype_slot_count(oop mt) { |
2684 compute_optional_offset(_vmslots_offset, k, vmSymbols::vmslots_name(), vmSymbols::int_signature(), true); |
2625 BasicType bt = java_lang_Class::as_BasicType(rtype(mt)); |
2685 compute_optional_offset(_vmlayout_offset, k, vmSymbols::vmlayout_name(), vmSymbols::object_signature()); |
2626 return type2size[bt]; |
2686 compute_optional_offset(_erasedType_offset, k, vmSymbols::erasedType_name(), vmSymbols::java_lang_invoke_MethodType_signature(), true); |
|
2687 compute_optional_offset(_genericInvoker_offset, k, vmSymbols::genericInvoker_name(), vmSymbols::java_lang_invoke_MethodHandle_signature(), true); |
|
2688 if (_genericInvoker_offset == 0) _genericInvoker_offset = -1; // set to explicit "empty" value |
|
2689 METHODTYPEFORM_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
|
2690 } |
|
2691 } |
|
2692 |
|
2693 int java_lang_invoke_MethodTypeForm::vmslots(oop mtform) { |
|
2694 assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); |
|
2695 assert(_vmslots_offset > 0, ""); |
|
2696 return mtform->int_field(_vmslots_offset); |
|
2697 } |
|
2698 |
|
2699 oop java_lang_invoke_MethodTypeForm::vmlayout(oop mtform) { |
|
2700 assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); |
|
2701 assert(_vmlayout_offset > 0, ""); |
|
2702 return mtform->obj_field(_vmlayout_offset); |
|
2703 } |
|
2704 |
|
2705 oop java_lang_invoke_MethodTypeForm::init_vmlayout(oop mtform, oop cookie) { |
|
2706 assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); |
|
2707 oop previous = vmlayout(mtform); |
|
2708 if (previous != NULL) { |
|
2709 return previous; // someone else beat us to it |
|
2710 } |
|
2711 HeapWord* cookie_addr = (HeapWord*) mtform->obj_field_addr<oop>(_vmlayout_offset); |
|
2712 OrderAccess::storestore(); // make sure our copy is fully committed |
|
2713 previous = oopDesc::atomic_compare_exchange_oop(cookie, cookie_addr, previous); |
|
2714 if (previous != NULL) { |
|
2715 return previous; // someone else beat us to it |
|
2716 } |
|
2717 return cookie; |
|
2718 } |
|
2719 |
|
2720 oop java_lang_invoke_MethodTypeForm::erasedType(oop mtform) { |
|
2721 assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); |
|
2722 return mtform->obj_field(_erasedType_offset); |
|
2723 } |
|
2724 |
|
2725 oop java_lang_invoke_MethodTypeForm::genericInvoker(oop mtform) { |
|
2726 assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); |
|
2727 return mtform->obj_field(_genericInvoker_offset); |
|
2728 } |
2627 } |
2729 |
2628 |
2730 |
2629 |
2731 // Support for java_lang_invoke_CallSite |
2630 // Support for java_lang_invoke_CallSite |
2732 |
2631 |