< prev index next >

src/share/vm/prims/methodHandles.cpp

Print this page


   1 /*
   2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 676        // static invocation mode is required for _linkToVirtual, etc.:
 677        ref_kind == JVM_REF_invokeStatic)) {
 678     vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
 679     if (iid != vmIntrinsics::_none &&
 680         ((ref_kind == JVM_REF_invokeStatic) == is_signature_polymorphic_static(iid))) {
 681       // Virtual methods invoke and invokeExact, plus internal invokers like _invokeBasic.
 682       // For a static reference it could an internal linkage routine like _linkToVirtual, etc.
 683       mh_invoke_id = iid;
 684     }
 685   }
 686 
 687   // convert the external string or reflective type to an internal signature
 688   TempNewSymbol type = lookup_signature(type_str(), (mh_invoke_id != vmIntrinsics::_none), CHECK_(empty));
 689   if (type == NULL)  return empty;  // no such signature exists in the VM
 690 
 691   // Time to do the lookup.
 692   switch (flags & ALL_KINDS) {
 693   case IS_METHOD:
 694     {
 695       CallInfo result;
 696       LinkInfo link_info(defc, name, type, caller, caller.not_null());
 697       {
 698         assert(!HAS_PENDING_EXCEPTION, "");
 699         if (ref_kind == JVM_REF_invokeStatic) {
 700           LinkResolver::resolve_static_call(result,
 701                         link_info, false, THREAD);
 702         } else if (ref_kind == JVM_REF_invokeInterface) {
 703           LinkResolver::resolve_interface_call(result, Handle(), defc,
 704                         link_info, false, THREAD);
 705         } else if (mh_invoke_id != vmIntrinsics::_none) {
 706           assert(!is_signature_polymorphic_static(mh_invoke_id), "");
 707           LinkResolver::resolve_handle_call(result, link_info, THREAD);
 708         } else if (ref_kind == JVM_REF_invokeSpecial) {
 709           LinkResolver::resolve_special_call(result,
 710                         link_info, THREAD);
 711         } else if (ref_kind == JVM_REF_invokeVirtual) {
 712           LinkResolver::resolve_virtual_call(result, Handle(), defc,
 713                         link_info, false, THREAD);
 714         } else {
 715           assert(false, "ref_kind=%d", ref_kind);
 716         }
 717         if (HAS_PENDING_EXCEPTION) {
 718           return empty;
 719         }
 720       }
 721       if (result.resolved_appendix().not_null()) {
 722         // The resolved MemberName must not be accompanied by an appendix argument,
 723         // since there is no way to bind this value into the MemberName.
 724         // Caller is responsible to prevent this from happening.
 725         THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
 726       }
 727       oop mname2 = init_method_MemberName(mname, result);
 728       return Handle(THREAD, mname2);
 729     }
 730   case IS_CONSTRUCTOR:
 731     {
 732       CallInfo result;
 733       LinkInfo link_info(defc, name, type, caller, caller.not_null());
 734       {
 735         assert(!HAS_PENDING_EXCEPTION, "");
 736         if (name == vmSymbols::object_initializer_name()) {
 737           LinkResolver::resolve_special_call(result, link_info, THREAD);
 738         } else {
 739           break;                // will throw after end of switch
 740         }
 741         if (HAS_PENDING_EXCEPTION) {
 742           return empty;
 743         }
 744       }
 745       assert(result.is_statically_bound(), "");
 746       oop mname2 = init_method_MemberName(mname, result);
 747       return Handle(THREAD, mname2);
 748     }
 749   case IS_FIELD:
 750     {
 751       fieldDescriptor result; // find_field initializes fd if found
 752       {
 753         assert(!HAS_PENDING_EXCEPTION, "");
 754         LinkInfo link_info(defc, name, type, caller, /*check_access*/false);
 755         LinkResolver::resolve_field(result, link_info, Bytecodes::_nop, false, THREAD);
 756         if (HAS_PENDING_EXCEPTION) {
 757           return empty;
 758         }
 759       }
 760       oop mname2 = init_field_MemberName(mname, result, ref_kind_is_setter(ref_kind));
 761       return Handle(THREAD, mname2);
 762     }
 763   default:
 764     THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
 765   }
 766 
 767   return empty;
 768 }
 769 
 770 // Conversely, a member name which is only initialized from JVM internals
 771 // may have null defc, name, and type fields.
 772 // Resolving it plants a vmtarget/vmindex in it,
 773 // which refers directly to JVM internals.
 774 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {


   1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 676        // static invocation mode is required for _linkToVirtual, etc.:
 677        ref_kind == JVM_REF_invokeStatic)) {
 678     vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
 679     if (iid != vmIntrinsics::_none &&
 680         ((ref_kind == JVM_REF_invokeStatic) == is_signature_polymorphic_static(iid))) {
 681       // Virtual methods invoke and invokeExact, plus internal invokers like _invokeBasic.
 682       // For a static reference it could an internal linkage routine like _linkToVirtual, etc.
 683       mh_invoke_id = iid;
 684     }
 685   }
 686 
 687   // convert the external string or reflective type to an internal signature
 688   TempNewSymbol type = lookup_signature(type_str(), (mh_invoke_id != vmIntrinsics::_none), CHECK_(empty));
 689   if (type == NULL)  return empty;  // no such signature exists in the VM
 690 
 691   // Time to do the lookup.
 692   switch (flags & ALL_KINDS) {
 693   case IS_METHOD:
 694     {
 695       CallInfo result;
 696       LinkInfo link_info(defc, name, type, caller);
 697       {
 698         assert(!HAS_PENDING_EXCEPTION, "");
 699         if (ref_kind == JVM_REF_invokeStatic) {
 700           LinkResolver::resolve_static_call(result,
 701                         link_info, false, THREAD);
 702         } else if (ref_kind == JVM_REF_invokeInterface) {
 703           LinkResolver::resolve_interface_call(result, Handle(), defc,
 704                         link_info, false, THREAD);
 705         } else if (mh_invoke_id != vmIntrinsics::_none) {
 706           assert(!is_signature_polymorphic_static(mh_invoke_id), "");
 707           LinkResolver::resolve_handle_call(result, link_info, THREAD);
 708         } else if (ref_kind == JVM_REF_invokeSpecial) {
 709           LinkResolver::resolve_special_call(result,
 710                         link_info, THREAD);
 711         } else if (ref_kind == JVM_REF_invokeVirtual) {
 712           LinkResolver::resolve_virtual_call(result, Handle(), defc,
 713                         link_info, false, THREAD);
 714         } else {
 715           assert(false, "ref_kind=%d", ref_kind);
 716         }
 717         if (HAS_PENDING_EXCEPTION) {
 718           return empty;
 719         }
 720       }
 721       if (result.resolved_appendix().not_null()) {
 722         // The resolved MemberName must not be accompanied by an appendix argument,
 723         // since there is no way to bind this value into the MemberName.
 724         // Caller is responsible to prevent this from happening.
 725         THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
 726       }
 727       oop mname2 = init_method_MemberName(mname, result);
 728       return Handle(THREAD, mname2);
 729     }
 730   case IS_CONSTRUCTOR:
 731     {
 732       CallInfo result;
 733       LinkInfo link_info(defc, name, type, caller);
 734       {
 735         assert(!HAS_PENDING_EXCEPTION, "");
 736         if (name == vmSymbols::object_initializer_name()) {
 737           LinkResolver::resolve_special_call(result, link_info, THREAD);
 738         } else {
 739           break;                // will throw after end of switch
 740         }
 741         if (HAS_PENDING_EXCEPTION) {
 742           return empty;
 743         }
 744       }
 745       assert(result.is_statically_bound(), "");
 746       oop mname2 = init_method_MemberName(mname, result);
 747       return Handle(THREAD, mname2);
 748     }
 749   case IS_FIELD:
 750     {
 751       fieldDescriptor result; // find_field initializes fd if found
 752       {
 753         assert(!HAS_PENDING_EXCEPTION, "");
 754         LinkInfo link_info(defc, name, type, caller, LinkInfo::skip_access_check);
 755         LinkResolver::resolve_field(result, link_info, Bytecodes::_nop, false, THREAD);
 756         if (HAS_PENDING_EXCEPTION) {
 757           return empty;
 758         }
 759       }
 760       oop mname2 = init_field_MemberName(mname, result, ref_kind_is_setter(ref_kind));
 761       return Handle(THREAD, mname2);
 762     }
 763   default:
 764     THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
 765   }
 766 
 767   return empty;
 768 }
 769 
 770 // Conversely, a member name which is only initialized from JVM internals
 771 // may have null defc, name, and type fields.
 772 // Resolving it plants a vmtarget/vmindex in it,
 773 // which refers directly to JVM internals.
 774 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {


< prev index next >