Mercurial > hg > graal-compiler
comparison src/share/vm/oops/methodOop.cpp @ 6275:957c266d8bc5
Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 21 Aug 2012 10:39:19 +0200 |
parents | 70f715dfbb41 977007096840 |
children |
comparison
equal
deleted
inserted
replaced
5891:fd8832ae511d | 6275:957c266d8bc5 |
---|---|
38 #include "oops/methodDataOop.hpp" | 38 #include "oops/methodDataOop.hpp" |
39 #include "oops/methodOop.hpp" | 39 #include "oops/methodOop.hpp" |
40 #include "oops/oop.inline.hpp" | 40 #include "oops/oop.inline.hpp" |
41 #include "oops/symbol.hpp" | 41 #include "oops/symbol.hpp" |
42 #include "prims/jvmtiExport.hpp" | 42 #include "prims/jvmtiExport.hpp" |
43 #include "prims/methodHandleWalk.hpp" | 43 #include "prims/methodHandles.hpp" |
44 #include "prims/nativeLookup.hpp" | 44 #include "prims/nativeLookup.hpp" |
45 #include "runtime/arguments.hpp" | 45 #include "runtime/arguments.hpp" |
46 #include "runtime/compilationPolicy.hpp" | 46 #include "runtime/compilationPolicy.hpp" |
47 #include "runtime/frame.inline.hpp" | 47 #include "runtime/frame.inline.hpp" |
48 #include "runtime/handles.inline.hpp" | 48 #include "runtime/handles.inline.hpp" |
71 address methodOopDesc::get_c2i_unverified_entry() { | 71 address methodOopDesc::get_c2i_unverified_entry() { |
72 assert(_adapter != NULL, "must have"); | 72 assert(_adapter != NULL, "must have"); |
73 return _adapter->get_c2i_unverified_entry(); | 73 return _adapter->get_c2i_unverified_entry(); |
74 } | 74 } |
75 | 75 |
76 char* methodOopDesc::name_and_sig_as_C_string() { | 76 char* methodOopDesc::name_and_sig_as_C_string() const { |
77 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature()); | 77 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature()); |
78 } | 78 } |
79 | 79 |
80 char* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) { | 80 char* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) const { |
81 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size); | 81 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size); |
82 } | 82 } |
83 | 83 |
84 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { | 84 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { |
85 const char* klass_name = klass->external_name(); | 85 const char* klass_name = klass->external_name(); |
112 return buf; | 112 return buf; |
113 } | 113 } |
114 | 114 |
115 int methodOopDesc::fast_exception_handler_bci_for(KlassHandle ex_klass, int throw_bci, TRAPS) { | 115 int methodOopDesc::fast_exception_handler_bci_for(KlassHandle ex_klass, int throw_bci, TRAPS) { |
116 // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) | 116 // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) |
117 const int beg_bci_offset = 0; | |
118 const int end_bci_offset = 1; | |
119 const int handler_bci_offset = 2; | |
120 const int klass_index_offset = 3; | |
121 const int entry_size = 4; | |
122 // access exception table | 117 // access exception table |
123 typeArrayHandle table (THREAD, constMethod()->exception_table()); | 118 ExceptionTable table(this); |
124 int length = table->length(); | 119 int length = table.length(); |
125 assert(length % entry_size == 0, "exception table format has changed"); | |
126 // iterate through all entries sequentially | 120 // iterate through all entries sequentially |
127 constantPoolHandle pool(THREAD, constants()); | 121 constantPoolHandle pool(THREAD, constants()); |
128 for (int i = 0; i < length; i += entry_size) { | 122 for (int i = 0; i < length; i ++) { |
129 int beg_bci = table->int_at(i + beg_bci_offset); | 123 //reacquire the table in case a GC happened |
130 int end_bci = table->int_at(i + end_bci_offset); | 124 ExceptionTable table(this); |
125 int beg_bci = table.start_pc(i); | |
126 int end_bci = table.end_pc(i); | |
131 assert(beg_bci <= end_bci, "inconsistent exception table"); | 127 assert(beg_bci <= end_bci, "inconsistent exception table"); |
132 if (beg_bci <= throw_bci && throw_bci < end_bci) { | 128 if (beg_bci <= throw_bci && throw_bci < end_bci) { |
133 // exception handler bci range covers throw_bci => investigate further | 129 // exception handler bci range covers throw_bci => investigate further |
134 int handler_bci = table->int_at(i + handler_bci_offset); | 130 int handler_bci = table.handler_pc(i); |
135 int klass_index = table->int_at(i + klass_index_offset); | 131 int klass_index = table.catch_type_index(i); |
136 if (klass_index == 0) { | 132 if (klass_index == 0) { |
137 return handler_bci; | 133 return handler_bci; |
138 } else if (ex_klass.is_null()) { | 134 } else if (ex_klass.is_null()) { |
139 return handler_bci; | 135 return handler_bci; |
140 } else { | 136 } else { |
178 return; | 174 return; |
179 } | 175 } |
180 | 176 |
181 | 177 |
182 int methodOopDesc::bci_from(address bcp) const { | 178 int methodOopDesc::bci_from(address bcp) const { |
183 assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), "bcp doesn't belong to this method"); | 179 assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), |
180 err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string())); | |
184 return bcp - code_base(); | 181 return bcp - code_base(); |
185 } | 182 } |
186 | 183 |
187 | 184 |
188 // Return (int)bcx if it appears to be a valid BCI. | 185 // Return (int)bcx if it appears to be a valid BCI. |
532 return best_line; | 529 return best_line; |
533 } | 530 } |
534 | 531 |
535 | 532 |
536 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const { | 533 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const { |
537 if( _constants->tag_at(klass_index).is_unresolved_klass() ) { | 534 if( constants()->tag_at(klass_index).is_unresolved_klass() ) { |
538 Thread *thread = Thread::current(); | 535 Thread *thread = Thread::current(); |
539 Symbol* klass_name = _constants->klass_name_at(klass_index); | 536 Symbol* klass_name = constants()->klass_name_at(klass_index); |
540 Handle loader(thread, instanceKlass::cast(method_holder())->class_loader()); | 537 Handle loader(thread, instanceKlass::cast(method_holder())->class_loader()); |
541 Handle prot (thread, Klass::cast(method_holder())->protection_domain()); | 538 Handle prot (thread, Klass::cast(method_holder())->protection_domain()); |
542 return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; | 539 return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; |
543 } else { | 540 } else { |
544 return true; | 541 return true; |
545 } | 542 } |
546 } | 543 } |
547 | 544 |
548 | 545 |
549 bool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { | 546 bool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { |
550 int klass_index = _constants->klass_ref_index_at(refinfo_index); | 547 int klass_index = constants()->klass_ref_index_at(refinfo_index); |
551 if (must_be_resolved) { | 548 if (must_be_resolved) { |
552 // Make sure klass is resolved in constantpool. | 549 // Make sure klass is resolved in constantpool. |
553 if (constants()->tag_at(klass_index).is_unresolved_klass()) return false; | 550 if (constants()->tag_at(klass_index).is_unresolved_klass()) return false; |
554 } | 551 } |
555 return is_klass_loaded_by_klass_index(klass_index); | 552 return is_klass_loaded_by_klass_index(klass_index); |
556 } | 553 } |
557 | 554 |
558 | 555 |
559 void methodOopDesc::set_native_function(address function, bool post_event_flag) { | 556 void methodOopDesc::set_native_function(address function, bool post_event_flag) { |
560 assert(function != NULL, "use clear_native_function to unregister natives"); | 557 assert(function != NULL, "use clear_native_function to unregister natives"); |
558 assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), ""); | |
561 address* native_function = native_function_addr(); | 559 address* native_function = native_function_addr(); |
562 | 560 |
563 // We can see racers trying to place the same native function into place. Once | 561 // We can see racers trying to place the same native function into place. Once |
564 // is plenty. | 562 // is plenty. |
565 address current = *native_function; | 563 address current = *native_function; |
585 } | 583 } |
586 } | 584 } |
587 | 585 |
588 | 586 |
589 bool methodOopDesc::has_native_function() const { | 587 bool methodOopDesc::has_native_function() const { |
588 if (is_method_handle_intrinsic()) | |
589 return false; // special-cased in SharedRuntime::generate_native_wrapper | |
590 address func = native_function(); | 590 address func = native_function(); |
591 return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); | 591 return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); |
592 } | 592 } |
593 | 593 |
594 | 594 |
595 void methodOopDesc::clear_native_function() { | 595 void methodOopDesc::clear_native_function() { |
596 // Note: is_method_handle_intrinsic() is allowed here. | |
596 set_native_function( | 597 set_native_function( |
597 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), | 598 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), |
598 !native_bind_event_is_interesting); | 599 !native_bind_event_is_interesting); |
599 clear_code(); | 600 clear_code(); |
600 } | 601 } |
610 *signature_handler = handler; | 611 *signature_handler = handler; |
611 } | 612 } |
612 | 613 |
613 | 614 |
614 bool methodOopDesc::is_not_compilable(int comp_level) const { | 615 bool methodOopDesc::is_not_compilable(int comp_level) const { |
615 if (is_method_handle_invoke()) { | |
616 // compilers must recognize this method specially, or not at all | |
617 return true; | |
618 } | |
619 if (number_of_breakpoints() > 0) { | 616 if (number_of_breakpoints() > 0) { |
620 return true; | 617 return true; |
618 } | |
619 if (is_method_handle_intrinsic()) { | |
620 return !is_synthetic(); // the generated adapters must be compiled | |
621 } | 621 } |
622 if (comp_level == CompLevel_any) { | 622 if (comp_level == CompLevel_any) { |
623 return is_not_c1_compilable() || is_not_c2_compilable(); | 623 return is_not_c1_compilable() || is_not_c2_compilable(); |
624 } | 624 } |
625 if (is_c1_compile(comp_level)) { | 625 if (is_c1_compile(comp_level)) { |
720 assert(this == h_method(), "wrong h_method()" ); | 720 assert(this == h_method(), "wrong h_method()" ); |
721 address entry = Interpreter::entry_for_method(h_method); | 721 address entry = Interpreter::entry_for_method(h_method); |
722 assert(entry != NULL, "interpreter entry must be non-null"); | 722 assert(entry != NULL, "interpreter entry must be non-null"); |
723 // Sets both _i2i_entry and _from_interpreted_entry | 723 // Sets both _i2i_entry and _from_interpreted_entry |
724 set_interpreter_entry(entry); | 724 set_interpreter_entry(entry); |
725 if (is_native() && !is_method_handle_invoke()) { | 725 if (is_native() && !is_method_handle_intrinsic()) { |
726 set_native_function( | 726 set_native_function( |
727 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), | 727 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), |
728 !native_bind_event_is_interesting); | 728 !native_bind_event_is_interesting); |
729 } | 729 } |
730 | 730 |
808 } | 808 } |
809 | 809 |
810 OrderAccess::storestore(); | 810 OrderAccess::storestore(); |
811 #ifdef SHARK | 811 #ifdef SHARK |
812 mh->_from_interpreted_entry = code->insts_begin(); | 812 mh->_from_interpreted_entry = code->insts_begin(); |
813 #else | 813 #else //!SHARK |
814 mh->_from_compiled_entry = code->verified_entry_point(); | 814 mh->_from_compiled_entry = code->verified_entry_point(); |
815 OrderAccess::storestore(); | 815 OrderAccess::storestore(); |
816 // Instantly compiled code can execute. | 816 // Instantly compiled code can execute. |
817 mh->_from_interpreted_entry = mh->get_i2c_entry(); | 817 if (!mh->is_method_handle_intrinsic()) |
818 #endif // SHARK | 818 mh->_from_interpreted_entry = mh->get_i2c_entry(); |
819 | 819 #endif //!SHARK |
820 } | 820 } |
821 | 821 |
822 | 822 |
823 bool methodOopDesc::is_overridden_in(klassOop k) const { | 823 bool methodOopDesc::is_overridden_in(klassOop k) const { |
824 instanceKlass* ik = instanceKlass::cast(k); | 824 instanceKlass* ik = instanceKlass::cast(k); |
866 | 866 |
867 // caching this method should be just fine | 867 // caching this method should be just fine |
868 return false; | 868 return false; |
869 } | 869 } |
870 | 870 |
871 bool methodOopDesc::is_method_handle_invoke_name(vmSymbols::SID name_sid) { | |
872 switch (name_sid) { | |
873 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name): | |
874 case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): | |
875 return true; | |
876 } | |
877 if (AllowInvokeGeneric | |
878 && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)) | |
879 return true; | |
880 return false; | |
881 } | |
882 | |
883 // Constant pool structure for invoke methods: | 871 // Constant pool structure for invoke methods: |
884 enum { | 872 enum { |
885 _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric' | 873 _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. |
886 _imcp_invoke_signature, // utf8: (variable Symbol*) | 874 _imcp_invoke_signature, // utf8: (variable Symbol*) |
887 _imcp_method_type_value, // string: (variable java/lang/invoke/MethodType, sic) | |
888 _imcp_limit | 875 _imcp_limit |
889 }; | 876 }; |
890 | 877 |
891 oop methodOopDesc::method_handle_type() const { | 878 // Test if this method is an MH adapter frame generated by Java code. |
892 if (!is_method_handle_invoke()) { assert(false, "caller resp."); return NULL; } | 879 // Cf. java/lang/invoke/InvokerBytecodeGenerator |
893 oop mt = constants()->resolved_string_at(_imcp_method_type_value); | 880 bool methodOopDesc::is_compiled_lambda_form() const { |
894 assert(mt->klass() == SystemDictionary::MethodType_klass(), ""); | 881 return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; |
895 return mt; | 882 } |
896 } | 883 |
897 | 884 // Test if this method is an internal MH primitive method. |
898 jint* methodOopDesc::method_type_offsets_chain() { | 885 bool methodOopDesc::is_method_handle_intrinsic() const { |
899 static jint pchase[] = { -1, -1, -1 }; | 886 vmIntrinsics::ID iid = intrinsic_id(); |
900 if (pchase[0] == -1) { | 887 return (MethodHandles::is_signature_polymorphic(iid) && |
901 jint step0 = in_bytes(constants_offset()); | 888 MethodHandles::is_signature_polymorphic_intrinsic(iid)); |
902 jint step1 = (constantPoolOopDesc::header_size() + _imcp_method_type_value) * HeapWordSize; | 889 } |
903 // do this in reverse to avoid races: | 890 |
904 OrderAccess::release_store(&pchase[1], step1); | 891 bool methodOopDesc::has_member_arg() const { |
905 OrderAccess::release_store(&pchase[0], step0); | 892 vmIntrinsics::ID iid = intrinsic_id(); |
906 } | 893 return (MethodHandles::is_signature_polymorphic(iid) && |
907 return pchase; | 894 MethodHandles::has_member_arg(iid)); |
908 } | 895 } |
909 | 896 |
910 //------------------------------------------------------------------------------ | 897 // Make an instance of a signature-polymorphic internal MH primitive. |
911 // methodOopDesc::is_method_handle_adapter | 898 methodHandle methodOopDesc::make_method_handle_intrinsic(vmIntrinsics::ID iid, |
912 // | 899 Symbol* signature, |
913 // Tests if this method is an internal adapter frame from the | 900 TRAPS) { |
914 // MethodHandleCompiler. | |
915 // Must be consistent with MethodHandleCompiler::get_method_oop(). | |
916 bool methodOopDesc::is_method_handle_adapter() const { | |
917 if (is_synthetic() && | |
918 !is_native() && // has code from MethodHandleCompiler | |
919 is_method_handle_invoke_name(name()) && | |
920 MethodHandleCompiler::klass_is_method_handle_adapter_holder(method_holder())) { | |
921 assert(!is_method_handle_invoke(), "disjoint"); | |
922 return true; | |
923 } else { | |
924 return false; | |
925 } | |
926 } | |
927 | |
928 methodHandle methodOopDesc::make_invoke_method(KlassHandle holder, | |
929 Symbol* name, | |
930 Symbol* signature, | |
931 Handle method_type, TRAPS) { | |
932 ResourceMark rm; | 901 ResourceMark rm; |
933 methodHandle empty; | 902 methodHandle empty; |
934 | 903 |
935 assert(holder() == SystemDictionary::MethodHandle_klass(), | 904 KlassHandle holder = SystemDictionary::MethodHandle_klass(); |
936 "must be a JSR 292 magic type"); | 905 Symbol* name = MethodHandles::signature_polymorphic_intrinsic_name(iid); |
937 | 906 assert(iid == MethodHandles::signature_polymorphic_name_id(name), ""); |
938 if (TraceMethodHandles) { | 907 if (TraceMethodHandles) { |
939 tty->print("Creating invoke method for "); | 908 tty->print_cr("make_method_handle_intrinsic MH.%s%s", name->as_C_string(), signature->as_C_string()); |
940 signature->print_value(); | |
941 tty->cr(); | |
942 } | 909 } |
943 | 910 |
944 // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup) | 911 // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup) |
945 name->increment_refcount(); | 912 name->increment_refcount(); |
946 signature->increment_refcount(); | 913 signature->increment_refcount(); |
947 | 914 |
948 // record non-BCP method types in the constant pool | 915 int cp_length = _imcp_limit; |
949 GrowableArray<KlassHandle>* extra_klasses = NULL; | |
950 for (int i = -1, len = java_lang_invoke_MethodType::ptype_count(method_type()); i < len; i++) { | |
951 oop ptype = (i == -1 | |
952 ? java_lang_invoke_MethodType::rtype(method_type()) | |
953 : java_lang_invoke_MethodType::ptype(method_type(), i)); | |
954 klassOop klass = check_non_bcp_klass(java_lang_Class::as_klassOop(ptype)); | |
955 if (klass != NULL) { | |
956 if (extra_klasses == NULL) | |
957 extra_klasses = new GrowableArray<KlassHandle>(len+1); | |
958 bool dup = false; | |
959 for (int j = 0; j < extra_klasses->length(); j++) { | |
960 if (extra_klasses->at(j) == klass) { dup = true; break; } | |
961 } | |
962 if (!dup) | |
963 extra_klasses->append(KlassHandle(THREAD, klass)); | |
964 } | |
965 } | |
966 | |
967 int extra_klass_count = (extra_klasses == NULL ? 0 : extra_klasses->length()); | |
968 int cp_length = _imcp_limit + extra_klass_count; | |
969 constantPoolHandle cp; | 916 constantPoolHandle cp; |
970 { | 917 { |
971 constantPoolOop cp_oop = oopFactory::new_constantPool(cp_length, IsSafeConc, CHECK_(empty)); | 918 constantPoolOop cp_oop = oopFactory::new_constantPool(cp_length, IsSafeConc, CHECK_(empty)); |
972 cp = constantPoolHandle(THREAD, cp_oop); | 919 cp = constantPoolHandle(THREAD, cp_oop); |
973 } | 920 } |
974 cp->symbol_at_put(_imcp_invoke_name, name); | 921 cp->symbol_at_put(_imcp_invoke_name, name); |
975 cp->symbol_at_put(_imcp_invoke_signature, signature); | 922 cp->symbol_at_put(_imcp_invoke_signature, signature); |
976 cp->string_at_put(_imcp_method_type_value, Universe::the_null_string()); | |
977 for (int j = 0; j < extra_klass_count; j++) { | |
978 KlassHandle klass = extra_klasses->at(j); | |
979 cp->klass_at_put(_imcp_limit + j, klass()); | |
980 } | |
981 cp->set_preresolution(); | 923 cp->set_preresolution(); |
982 cp->set_pool_holder(holder()); | 924 cp->set_pool_holder(holder()); |
983 | 925 |
984 // set up the fancy stuff: | 926 // decide on access bits: public or not? |
985 cp->pseudo_string_at_put(_imcp_method_type_value, method_type()); | 927 int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL); |
928 bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid); | |
929 if (must_be_static) flags_bits |= JVM_ACC_STATIC; | |
930 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); | |
931 | |
986 methodHandle m; | 932 methodHandle m; |
987 { | 933 { |
988 int flags_bits = (JVM_MH_INVOKE_BITS | JVM_ACC_PUBLIC | JVM_ACC_FINAL); | |
989 methodOop m_oop = oopFactory::new_method(0, accessFlags_from(flags_bits), | 934 methodOop m_oop = oopFactory::new_method(0, accessFlags_from(flags_bits), |
990 0, 0, 0, IsSafeConc, CHECK_(empty)); | 935 0, 0, 0, 0, IsSafeConc, CHECK_(empty)); |
991 m = methodHandle(THREAD, m_oop); | 936 m = methodHandle(THREAD, m_oop); |
992 } | 937 } |
993 m->set_constants(cp()); | 938 m->set_constants(cp()); |
994 m->set_name_index(_imcp_invoke_name); | 939 m->set_name_index(_imcp_invoke_name); |
995 m->set_signature_index(_imcp_invoke_signature); | 940 m->set_signature_index(_imcp_invoke_signature); |
996 assert(is_method_handle_invoke_name(m->name()), ""); | 941 assert(MethodHandles::is_signature_polymorphic_name(m->name()), ""); |
997 assert(m->signature() == signature, ""); | 942 assert(m->signature() == signature, ""); |
998 assert(m->is_method_handle_invoke(), ""); | |
999 #ifdef CC_INTERP | 943 #ifdef CC_INTERP |
1000 ResultTypeFinder rtf(signature); | 944 ResultTypeFinder rtf(signature); |
1001 m->set_result_index(rtf.type()); | 945 m->set_result_index(rtf.type()); |
1002 #endif | 946 #endif |
1003 m->compute_size_of_parameters(THREAD); | 947 m->compute_size_of_parameters(THREAD); |
1004 m->set_exception_table(Universe::the_empty_int_array()); | |
1005 m->init_intrinsic_id(); | 948 m->init_intrinsic_id(); |
1006 assert(m->intrinsic_id() == vmIntrinsics::_invokeExact || | 949 assert(m->is_method_handle_intrinsic(), ""); |
1007 m->intrinsic_id() == vmIntrinsics::_invokeGeneric, "must be an invoker"); | 950 #ifdef ASSERT |
951 if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print(); | |
952 assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker"); | |
953 assert(m->intrinsic_id() == iid, "correctly predicted iid"); | |
954 #endif //ASSERT | |
1008 | 955 |
1009 // Finally, set up its entry points. | 956 // Finally, set up its entry points. |
1010 assert(m->method_handle_type() == method_type(), ""); | |
1011 assert(m->can_be_statically_bound(), ""); | 957 assert(m->can_be_statically_bound(), ""); |
1012 m->set_vtable_index(methodOopDesc::nonvirtual_vtable_index); | 958 m->set_vtable_index(methodOopDesc::nonvirtual_vtable_index); |
1013 m->link_method(m, CHECK_(empty)); | 959 m->link_method(m, CHECK_(empty)); |
1014 | |
1015 #ifdef ASSERT | |
1016 // Make sure the pointer chase works. | |
1017 address p = (address) m(); | |
1018 for (jint* pchase = method_type_offsets_chain(); (*pchase) != -1; pchase++) { | |
1019 p = *(address*)(p + (*pchase)); | |
1020 } | |
1021 assert((oop)p == method_type(), "pointer chase is correct"); | |
1022 #endif | |
1023 | 960 |
1024 if (TraceMethodHandles && (Verbose || WizardMode)) | 961 if (TraceMethodHandles && (Verbose || WizardMode)) |
1025 m->print_on(tty); | 962 m->print_on(tty); |
1026 | 963 |
1027 return m; | 964 return m; |
1035 } | 972 } |
1036 return NULL; | 973 return NULL; |
1037 } | 974 } |
1038 | 975 |
1039 | 976 |
1040 methodHandle methodOopDesc:: clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length, | 977 methodHandle methodOopDesc::clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length, |
1041 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { | 978 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { |
1042 // Code below does not work for native methods - they should never get rewritten anyway | 979 // Code below does not work for native methods - they should never get rewritten anyway |
1043 assert(!m->is_native(), "cannot rewrite native methods"); | 980 assert(!m->is_native(), "cannot rewrite native methods"); |
1044 // Allocate new methodOop | 981 // Allocate new methodOop |
1045 AccessFlags flags = m->access_flags(); | 982 AccessFlags flags = m->access_flags(); |
1046 int checked_exceptions_len = m->checked_exceptions_length(); | 983 int checked_exceptions_len = m->checked_exceptions_length(); |
1047 int localvariable_len = m->localvariable_table_length(); | 984 int localvariable_len = m->localvariable_table_length(); |
985 int exception_table_len = m->exception_table_length(); | |
1048 // Allocate newm_oop with the is_conc_safe parameter set | 986 // Allocate newm_oop with the is_conc_safe parameter set |
1049 // to IsUnsafeConc to indicate that newm_oop is not yet | 987 // to IsUnsafeConc to indicate that newm_oop is not yet |
1050 // safe for concurrent processing by a GC. | 988 // safe for concurrent processing by a GC. |
1051 methodOop newm_oop = oopFactory::new_method(new_code_length, | 989 methodOop newm_oop = oopFactory::new_method(new_code_length, |
1052 flags, | 990 flags, |
1053 new_compressed_linenumber_size, | 991 new_compressed_linenumber_size, |
1054 localvariable_len, | 992 localvariable_len, |
993 exception_table_len, | |
1055 checked_exceptions_len, | 994 checked_exceptions_len, |
1056 IsUnsafeConc, | 995 IsUnsafeConc, |
1057 CHECK_(methodHandle())); | 996 CHECK_(methodHandle())); |
1058 methodHandle newm (THREAD, newm_oop); | 997 methodHandle newm (THREAD, newm_oop); |
1059 NOT_PRODUCT(int nmsz = newm->is_parsable() ? newm->size() : -1;) | 998 NOT_PRODUCT(int nmsz = newm->is_parsable() ? newm->size() : -1;) |
1084 memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc)); | 1023 memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc)); |
1085 m->constMethod()->set_is_conc_safe(oopDesc::IsSafeConc); | 1024 m->constMethod()->set_is_conc_safe(oopDesc::IsSafeConc); |
1086 assert(m->constMethod()->is_parsable(), "Should remain parsable"); | 1025 assert(m->constMethod()->is_parsable(), "Should remain parsable"); |
1087 | 1026 |
1088 // Reset correct method/const method, method size, and parameter info | 1027 // Reset correct method/const method, method size, and parameter info |
1089 newcm->set_method(newm()); | |
1090 newm->set_constMethod(newcm); | 1028 newm->set_constMethod(newcm); |
1091 assert(newcm->method() == newm(), "check"); | |
1092 newm->constMethod()->set_code_size(new_code_length); | 1029 newm->constMethod()->set_code_size(new_code_length); |
1093 newm->constMethod()->set_constMethod_size(new_const_method_size); | 1030 newm->constMethod()->set_constMethod_size(new_const_method_size); |
1094 newm->set_method_size(new_method_size); | 1031 newm->set_method_size(new_method_size); |
1095 assert(newm->code_size() == new_code_length, "check"); | 1032 assert(newm->code_size() == new_code_length, "check"); |
1096 assert(newm->checked_exceptions_length() == checked_exceptions_len, "check"); | 1033 assert(newm->checked_exceptions_length() == checked_exceptions_len, "check"); |
1034 assert(newm->exception_table_length() == exception_table_len, "check"); | |
1097 assert(newm->localvariable_table_length() == localvariable_len, "check"); | 1035 assert(newm->localvariable_table_length() == localvariable_len, "check"); |
1098 // Copy new byte codes | 1036 // Copy new byte codes |
1099 memcpy(newm->code_base(), new_code, new_code_length); | 1037 memcpy(newm->code_base(), new_code, new_code_length); |
1100 // Copy line number table | 1038 // Copy line number table |
1101 if (new_compressed_linenumber_size > 0) { | 1039 if (new_compressed_linenumber_size > 0) { |
1107 if (checked_exceptions_len > 0) { | 1045 if (checked_exceptions_len > 0) { |
1108 memcpy(newm->checked_exceptions_start(), | 1046 memcpy(newm->checked_exceptions_start(), |
1109 m->checked_exceptions_start(), | 1047 m->checked_exceptions_start(), |
1110 checked_exceptions_len * sizeof(CheckedExceptionElement)); | 1048 checked_exceptions_len * sizeof(CheckedExceptionElement)); |
1111 } | 1049 } |
1050 // Copy exception table | |
1051 if (exception_table_len > 0) { | |
1052 memcpy(newm->exception_table_start(), | |
1053 m->exception_table_start(), | |
1054 exception_table_len * sizeof(ExceptionTableElement)); | |
1055 } | |
1112 // Copy local variable number table | 1056 // Copy local variable number table |
1113 if (localvariable_len > 0) { | 1057 if (localvariable_len > 0) { |
1114 memcpy(newm->localvariable_table_start(), | 1058 memcpy(newm->localvariable_table_start(), |
1115 m->localvariable_table_start(), | 1059 m->localvariable_table_start(), |
1116 localvariable_len * sizeof(LocalVariableTableElement)); | 1060 localvariable_len * sizeof(LocalVariableTableElement)); |
1145 vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); | 1089 vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); |
1146 assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); | 1090 assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); |
1147 | 1091 |
1148 // ditto for method and signature: | 1092 // ditto for method and signature: |
1149 vmSymbols::SID name_id = vmSymbols::find_sid(name()); | 1093 vmSymbols::SID name_id = vmSymbols::find_sid(name()); |
1150 if (name_id == vmSymbols::NO_SID) return; | 1094 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) |
1095 && name_id == vmSymbols::NO_SID) | |
1096 return; | |
1151 vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); | 1097 vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); |
1152 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) | 1098 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) |
1153 && sig_id == vmSymbols::NO_SID) return; | 1099 && sig_id == vmSymbols::NO_SID) return; |
1154 jshort flags = access_flags().as_short(); | 1100 jshort flags = access_flags().as_short(); |
1155 | 1101 |
1174 } | 1120 } |
1175 break; | 1121 break; |
1176 | 1122 |
1177 // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. | 1123 // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. |
1178 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): | 1124 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): |
1179 if (is_static() || !is_native()) break; | 1125 if (!is_native()) break; |
1180 switch (name_id) { | 1126 id = MethodHandles::signature_polymorphic_name_id(method_holder(), name()); |
1181 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name): | 1127 if (is_static() != MethodHandles::is_signature_polymorphic_static(id)) |
1182 if (!AllowInvokeGeneric) break; | 1128 id = vmIntrinsics::_none; |
1183 case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): | |
1184 id = vmIntrinsics::_invokeGeneric; | |
1185 break; | |
1186 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name): | |
1187 id = vmIntrinsics::_invokeExact; | |
1188 break; | |
1189 } | |
1190 break; | |
1191 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InvokeDynamic): | |
1192 if (!is_static() || !is_native()) break; | |
1193 id = vmIntrinsics::_invokeDynamic; | |
1194 break; | 1129 break; |
1195 } | 1130 } |
1196 | 1131 |
1197 if (id != vmIntrinsics::_none) { | 1132 if (id != vmIntrinsics::_none) { |
1198 // Set up its iid. It is an alias method. | 1133 // Set up its iid. It is an alias method. |
1201 } | 1136 } |
1202 } | 1137 } |
1203 | 1138 |
1204 // These two methods are static since a GC may move the methodOopDesc | 1139 // These two methods are static since a GC may move the methodOopDesc |
1205 bool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) { | 1140 bool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) { |
1141 if (THREAD->is_Compiler_thread()) { | |
1142 // There is nothing useful this routine can do from within the Compile thread. | |
1143 // Hopefully, the signature contains only well-known classes. | |
1144 // We could scan for this and return true/false, but the caller won't care. | |
1145 return false; | |
1146 } | |
1206 bool sig_is_loaded = true; | 1147 bool sig_is_loaded = true; |
1207 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); | 1148 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); |
1208 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); | 1149 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); |
1209 ResourceMark rm(THREAD); | 1150 ResourceMark rm(THREAD); |
1210 Symbol* signature = m->signature(); | 1151 Symbol* signature = m->signature(); |
1254 #else | 1195 #else |
1255 st->print(" %s::", method_holder()->klass_part()->internal_name()); | 1196 st->print(" %s::", method_holder()->klass_part()->internal_name()); |
1256 #endif | 1197 #endif |
1257 name()->print_symbol_on(st); | 1198 name()->print_symbol_on(st); |
1258 if (WizardMode) signature()->print_symbol_on(st); | 1199 if (WizardMode) signature()->print_symbol_on(st); |
1200 else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) | |
1201 MethodHandles::print_as_basic_type_signature_on(st, signature(), true); | |
1259 } | 1202 } |
1260 | 1203 |
1261 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array | 1204 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
1262 static void reorder_based_on_method_index(objArrayOop methods, | 1205 static void reorder_based_on_method_index(objArrayOop methods, |
1263 objArrayOop annotations, | 1206 objArrayOop annotations, |