36 #include "memory/oopFactory.hpp" |
36 #include "memory/oopFactory.hpp" |
37 #include "oops/klassOop.hpp" |
37 #include "oops/klassOop.hpp" |
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/symbolOop.hpp" |
41 #include "oops/symbol.hpp" |
42 #include "prims/jvmtiExport.hpp" |
42 #include "prims/jvmtiExport.hpp" |
43 #include "prims/methodHandleWalk.hpp" |
43 #include "prims/methodHandleWalk.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" |
75 |
75 |
76 char* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) { |
76 char* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) { |
77 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size); |
77 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size); |
78 } |
78 } |
79 |
79 |
80 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature) { |
80 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { |
81 const char* klass_name = klass->external_name(); |
81 const char* klass_name = klass->external_name(); |
82 int klass_name_len = (int)strlen(klass_name); |
82 int klass_name_len = (int)strlen(klass_name); |
83 int method_name_len = method_name->utf8_length(); |
83 int method_name_len = method_name->utf8_length(); |
84 int len = klass_name_len + 1 + method_name_len + signature->utf8_length(); |
84 int len = klass_name_len + 1 + method_name_len + signature->utf8_length(); |
85 char* dest = NEW_RESOURCE_ARRAY(char, len + 1); |
85 char* dest = NEW_RESOURCE_ARRAY(char, len + 1); |
89 strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); |
89 strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); |
90 dest[len] = 0; |
90 dest[len] = 0; |
91 return dest; |
91 return dest; |
92 } |
92 } |
93 |
93 |
94 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature, char* buf, int size) { |
94 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) { |
95 symbolOop klass_name = klass->name(); |
95 Symbol* klass_name = klass->name(); |
96 klass_name->as_klass_external_name(buf, size); |
96 klass_name->as_klass_external_name(buf, size); |
97 int len = (int)strlen(buf); |
97 int len = (int)strlen(buf); |
98 |
98 |
99 if (len < size - 1) { |
99 if (len < size - 1) { |
100 buf[len++] = '.'; |
100 buf[len++] = '.'; |
219 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord; |
219 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord; |
220 return align_object_size(header_size() + extra_words); |
220 return align_object_size(header_size() + extra_words); |
221 } |
221 } |
222 |
222 |
223 |
223 |
224 symbolOop methodOopDesc::klass_name() const { |
224 Symbol* methodOopDesc::klass_name() const { |
225 klassOop k = method_holder(); |
225 klassOop k = method_holder(); |
226 assert(k->is_klass(), "must be klass"); |
226 assert(k->is_klass(), "must be klass"); |
227 instanceKlass* ik = (instanceKlass*) k->klass_part(); |
227 instanceKlass* ik = (instanceKlass*) k->klass_part(); |
228 return ik->name(); |
228 return ik->name(); |
229 } |
229 } |
331 return extra_stack_entries() * Interpreter::stackElementSize; |
331 return extra_stack_entries() * Interpreter::stackElementSize; |
332 } |
332 } |
333 |
333 |
334 |
334 |
335 void methodOopDesc::compute_size_of_parameters(Thread *thread) { |
335 void methodOopDesc::compute_size_of_parameters(Thread *thread) { |
336 symbolHandle h_signature(thread, signature()); |
336 ArgumentSizeComputer asc(signature()); |
337 ArgumentSizeComputer asc(h_signature); |
|
338 set_size_of_parameters(asc.size() + (is_static() ? 0 : 1)); |
337 set_size_of_parameters(asc.size() + (is_static() ? 0 : 1)); |
339 } |
338 } |
340 |
339 |
341 #ifdef CC_INTERP |
340 #ifdef CC_INTERP |
342 void methodOopDesc::set_result_index(BasicType type) { |
341 void methodOopDesc::set_result_index(BasicType type) { |
518 |
517 |
519 |
518 |
520 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const { |
519 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const { |
521 if( _constants->tag_at(klass_index).is_unresolved_klass() ) { |
520 if( _constants->tag_at(klass_index).is_unresolved_klass() ) { |
522 Thread *thread = Thread::current(); |
521 Thread *thread = Thread::current(); |
523 symbolHandle klass_name(thread, _constants->klass_name_at(klass_index)); |
522 Symbol* klass_name = _constants->klass_name_at(klass_index); |
524 Handle loader(thread, instanceKlass::cast(method_holder())->class_loader()); |
523 Handle loader(thread, instanceKlass::cast(method_holder())->class_loader()); |
525 Handle prot (thread, Klass::cast(method_holder())->protection_domain()); |
524 Handle prot (thread, Klass::cast(method_holder())->protection_domain()); |
526 return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; |
525 return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; |
527 } else { |
526 } else { |
528 return true; |
527 return true; |
850 } |
849 } |
851 |
850 |
852 // Constant pool structure for invoke methods: |
851 // Constant pool structure for invoke methods: |
853 enum { |
852 enum { |
854 _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric' |
853 _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric' |
855 _imcp_invoke_signature, // utf8: (variable symbolOop) |
854 _imcp_invoke_signature, // utf8: (variable Symbol*) |
856 _imcp_method_type_value, // string: (variable java/dyn/MethodType, sic) |
855 _imcp_method_type_value, // string: (variable java/dyn/MethodType, sic) |
857 _imcp_limit |
856 _imcp_limit |
858 }; |
857 }; |
859 |
858 |
860 oop methodOopDesc::method_handle_type() const { |
859 oop methodOopDesc::method_handle_type() const { |
893 return false; |
892 return false; |
894 } |
893 } |
895 } |
894 } |
896 |
895 |
897 methodHandle methodOopDesc::make_invoke_method(KlassHandle holder, |
896 methodHandle methodOopDesc::make_invoke_method(KlassHandle holder, |
898 symbolHandle name, |
897 Symbol* name, |
899 symbolHandle signature, |
898 Symbol* signature, |
900 Handle method_type, TRAPS) { |
899 Handle method_type, TRAPS) { |
901 methodHandle empty; |
900 methodHandle empty; |
902 |
901 |
903 assert(holder() == SystemDictionary::MethodHandle_klass(), |
902 assert(holder() == SystemDictionary::MethodHandle_klass(), |
904 "must be a JSR 292 magic type"); |
903 "must be a JSR 292 magic type"); |
912 constantPoolHandle cp; |
911 constantPoolHandle cp; |
913 { |
912 { |
914 constantPoolOop cp_oop = oopFactory::new_constantPool(_imcp_limit, IsSafeConc, CHECK_(empty)); |
913 constantPoolOop cp_oop = oopFactory::new_constantPool(_imcp_limit, IsSafeConc, CHECK_(empty)); |
915 cp = constantPoolHandle(THREAD, cp_oop); |
914 cp = constantPoolHandle(THREAD, cp_oop); |
916 } |
915 } |
917 cp->symbol_at_put(_imcp_invoke_name, name()); |
916 cp->symbol_at_put(_imcp_invoke_name, name); |
918 cp->symbol_at_put(_imcp_invoke_signature, signature()); |
917 cp->symbol_at_put(_imcp_invoke_signature, signature); |
919 cp->string_at_put(_imcp_method_type_value, vmSymbols::void_signature()); |
918 cp->string_at_put(_imcp_method_type_value, Universe::the_null_string()); |
920 cp->set_pool_holder(holder()); |
919 cp->set_pool_holder(holder()); |
921 |
920 |
922 // set up the fancy stuff: |
921 // set up the fancy stuff: |
923 cp->pseudo_string_at_put(_imcp_method_type_value, method_type()); |
922 cp->pseudo_string_at_put(_imcp_method_type_value, method_type()); |
924 methodHandle m; |
923 methodHandle m; |
930 } |
929 } |
931 m->set_constants(cp()); |
930 m->set_constants(cp()); |
932 m->set_name_index(_imcp_invoke_name); |
931 m->set_name_index(_imcp_invoke_name); |
933 m->set_signature_index(_imcp_invoke_signature); |
932 m->set_signature_index(_imcp_invoke_signature); |
934 assert(is_method_handle_invoke_name(m->name()), ""); |
933 assert(is_method_handle_invoke_name(m->name()), ""); |
935 assert(m->signature() == signature(), ""); |
934 assert(m->signature() == signature, ""); |
936 assert(m->is_method_handle_invoke(), ""); |
935 assert(m->is_method_handle_invoke(), ""); |
937 #ifdef CC_INTERP |
936 #ifdef CC_INTERP |
938 ResultTypeFinder rtf(signature()); |
937 ResultTypeFinder rtf(signature()); |
939 m->set_result_index(rtf.type()); |
938 m->set_result_index(rtf.type()); |
940 #endif |
939 #endif |
1045 // because we are not loading from core libraries |
1044 // because we are not loading from core libraries |
1046 if (instanceKlass::cast(holder)->class_loader() != NULL) |
1045 if (instanceKlass::cast(holder)->class_loader() != NULL) |
1047 return vmSymbols::NO_SID; // regardless of name, no intrinsics here |
1046 return vmSymbols::NO_SID; // regardless of name, no intrinsics here |
1048 |
1047 |
1049 // see if the klass name is well-known: |
1048 // see if the klass name is well-known: |
1050 symbolOop klass_name = instanceKlass::cast(holder)->name(); |
1049 Symbol* klass_name = instanceKlass::cast(holder)->name(); |
1051 return vmSymbols::find_sid(klass_name); |
1050 return vmSymbols::find_sid(klass_name); |
1052 } |
1051 } |
1053 |
1052 |
1054 void methodOopDesc::init_intrinsic_id() { |
1053 void methodOopDesc::init_intrinsic_id() { |
1055 assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); |
1054 assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); |
1121 // These two methods are static since a GC may move the methodOopDesc |
1120 // These two methods are static since a GC may move the methodOopDesc |
1122 bool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) { |
1121 bool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) { |
1123 bool sig_is_loaded = true; |
1122 bool sig_is_loaded = true; |
1124 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); |
1123 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); |
1125 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); |
1124 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); |
1126 symbolHandle signature(THREAD, m->signature()); |
1125 ResourceMark rm(THREAD); |
|
1126 Symbol* signature = m->signature(); |
1127 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
1127 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
1128 if (ss.is_object()) { |
1128 if (ss.is_object()) { |
1129 symbolOop sym = ss.as_symbol(CHECK_(false)); |
1129 Symbol* sym = ss.as_symbol(CHECK_(false)); |
1130 symbolHandle name (THREAD, sym); |
1130 Symbol* name = sym; |
1131 klassOop klass = SystemDictionary::resolve_or_null(name, class_loader, |
1131 klassOop klass = SystemDictionary::resolve_or_null(name, class_loader, |
1132 protection_domain, THREAD); |
1132 protection_domain, THREAD); |
1133 // We are loading classes eagerly. If a ClassNotFoundException or |
1133 // We are loading classes eagerly. If a ClassNotFoundException or |
1134 // a LinkageError was generated, be sure to ignore it. |
1134 // a LinkageError was generated, be sure to ignore it. |
1135 if (HAS_PENDING_EXCEPTION) { |
1135 if (HAS_PENDING_EXCEPTION) { |
1147 } |
1147 } |
1148 |
1148 |
1149 bool methodOopDesc::has_unloaded_classes_in_signature(methodHandle m, TRAPS) { |
1149 bool methodOopDesc::has_unloaded_classes_in_signature(methodHandle m, TRAPS) { |
1150 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); |
1150 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader()); |
1151 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); |
1151 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain()); |
1152 symbolHandle signature(THREAD, m->signature()); |
1152 ResourceMark rm(THREAD); |
|
1153 Symbol* signature = m->signature(); |
1153 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
1154 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
1154 if (ss.type() == T_OBJECT) { |
1155 if (ss.type() == T_OBJECT) { |
1155 symbolHandle name(THREAD, ss.as_symbol_or_null()); |
1156 Symbol* name = ss.as_symbol_or_null(); |
1156 if (name() == NULL) return true; |
1157 if (name == NULL) return true; |
1157 klassOop klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD); |
1158 klassOop klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD); |
1158 if (klass == NULL) return true; |
1159 if (klass == NULL) return true; |
1159 } |
1160 } |
1160 } |
1161 } |
1161 return false; |
1162 return false; |