Mercurial > hg > graal-jvmci-8
comparison src/share/vm/oops/klassVtable.cpp @ 12355:cefad50507d8
Merge with hs25-b53
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 11 Oct 2013 10:38:03 +0200 |
parents | 36b97be47bde |
children | ac9cb1d5a202 |
comparison
equal
deleted
inserted
replaced
12058:ccb4f2af2319 | 12355:cefad50507d8 |
---|---|
45 return (InstanceKlass*)k; | 45 return (InstanceKlass*)k; |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 // this function computes the vtable size (including the size needed for miranda | 49 // this function computes the vtable size (including the size needed for miranda |
50 // methods) and the number of miranda methods in this class | 50 // methods) and the number of miranda methods in this class. |
51 // Note on Miranda methods: Let's say there is a class C that implements | 51 // Note on Miranda methods: Let's say there is a class C that implements |
52 // interface I. Let's say there is a method m in I that neither C nor any | 52 // interface I, and none of C's superclasses implements I. |
53 // of its super classes implement (i.e there is no method of any access, with | 53 // Let's say there is an abstract method m in I that neither C |
54 // the same name and signature as m), then m is a Miranda method which is | 54 // nor any of its super classes implement (i.e there is no method of any access, |
55 // with the same name and signature as m), then m is a Miranda method which is | |
55 // entered as a public abstract method in C's vtable. From then on it should | 56 // entered as a public abstract method in C's vtable. From then on it should |
56 // treated as any other public method in C for method over-ride purposes. | 57 // treated as any other public method in C for method over-ride purposes. |
57 void klassVtable::compute_vtable_size_and_num_mirandas( | 58 void klassVtable::compute_vtable_size_and_num_mirandas( |
58 int* vtable_length_ret, int* num_new_mirandas, | 59 int* vtable_length_ret, int* num_new_mirandas, |
59 GrowableArray<Method*>* all_mirandas, Klass* super, | 60 GrowableArray<Method*>* all_mirandas, Klass* super, |
109 | 110 |
110 *vtable_length_ret = vtable_length; | 111 *vtable_length_ret = vtable_length; |
111 } | 112 } |
112 | 113 |
113 int klassVtable::index_of(Method* m, int len) const { | 114 int klassVtable::index_of(Method* m, int len) const { |
114 assert(m->vtable_index() >= 0, "do not ask this of non-vtable methods"); | 115 assert(m->has_vtable_index(), "do not ask this of non-vtable methods"); |
115 return m->vtable_index(); | 116 return m->vtable_index(); |
116 } | 117 } |
117 | 118 |
119 // Copy super class's vtable to the first part (prefix) of this class's vtable, | |
120 // and return the number of entries copied. Expects that 'super' is the Java | |
121 // super class (arrays can have "array" super classes that must be skipped). | |
118 int klassVtable::initialize_from_super(KlassHandle super) { | 122 int klassVtable::initialize_from_super(KlassHandle super) { |
119 if (super.is_null()) { | 123 if (super.is_null()) { |
120 return 0; | 124 return 0; |
121 } else { | 125 } else { |
122 // copy methods from superKlass | 126 // copy methods from superKlass |
137 #endif | 141 #endif |
138 return superVtable->length(); | 142 return superVtable->length(); |
139 } | 143 } |
140 } | 144 } |
141 | 145 |
142 // Revised lookup semantics introduced 1.3 (Kestral beta) | 146 // |
147 // Revised lookup semantics introduced 1.3 (Kestrel beta) | |
143 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { | 148 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { |
144 | 149 |
145 // Note: Arrays can have intermediate array supers. Use java_super to skip them. | 150 // Note: Arrays can have intermediate array supers. Use java_super to skip them. |
146 KlassHandle super (THREAD, klass()->java_super()); | 151 KlassHandle super (THREAD, klass()->java_super()); |
147 int nofNewEntries = 0; | 152 int nofNewEntries = 0; |
148 | |
149 | 153 |
150 if (PrintVtables && !klass()->oop_is_array()) { | 154 if (PrintVtables && !klass()->oop_is_array()) { |
151 ResourceMark rm(THREAD); | 155 ResourceMark rm(THREAD); |
152 tty->print_cr("Initializing: %s", _klass->name()->as_C_string()); | 156 tty->print_cr("Initializing: %s", _klass->name()->as_C_string()); |
153 } | 157 } |
172 | 176 |
173 Array<Method*>* methods = ik()->methods(); | 177 Array<Method*>* methods = ik()->methods(); |
174 int len = methods->length(); | 178 int len = methods->length(); |
175 int initialized = super_vtable_len; | 179 int initialized = super_vtable_len; |
176 | 180 |
177 // update_inherited_vtable can stop for gc - ensure using handles | 181 // Check each of this class's methods against super; |
182 // if override, replace in copy of super vtable, otherwise append to end | |
178 for (int i = 0; i < len; i++) { | 183 for (int i = 0; i < len; i++) { |
184 // update_inherited_vtable can stop for gc - ensure using handles | |
179 HandleMark hm(THREAD); | 185 HandleMark hm(THREAD); |
180 assert(methods->at(i)->is_method(), "must be a Method*"); | 186 assert(methods->at(i)->is_method(), "must be a Method*"); |
181 methodHandle mh(THREAD, methods->at(i)); | 187 methodHandle mh(THREAD, methods->at(i)); |
182 | 188 |
183 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK); | 189 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK); |
187 mh()->set_vtable_index(initialized); // set primary vtable index | 193 mh()->set_vtable_index(initialized); // set primary vtable index |
188 initialized++; | 194 initialized++; |
189 } | 195 } |
190 } | 196 } |
191 | 197 |
192 // add miranda methods; it will also update the value of initialized | 198 // add miranda methods to end of vtable. |
193 fill_in_mirandas(&initialized); | 199 initialized = fill_in_mirandas(initialized); |
194 | 200 |
195 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> | 201 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> |
196 // package_private -> publicprotected), the vtable might actually be smaller than our initial | 202 // package_private -> public/protected), the vtable might actually be smaller than our initial |
197 // calculation. | 203 // calculation. |
198 assert(initialized <= _length, "vtable initialization failed"); | 204 assert(initialized <= _length, "vtable initialization failed"); |
199 for(;initialized < _length; initialized++) { | 205 for(;initialized < _length; initialized++) { |
200 put_method_at(NULL, initialized); | 206 put_method_at(NULL, initialized); |
201 } | 207 } |
246 } | 252 } |
247 | 253 |
248 return superk; | 254 return superk; |
249 } | 255 } |
250 | 256 |
251 // Methods that are "effectively" final don't need vtable entries. | |
252 bool method_is_effectively_final( | |
253 AccessFlags klass_flags, methodHandle target) { | |
254 return target->is_final() || klass_flags.is_final() && !target->is_overpass(); | |
255 } | |
256 | |
257 // Update child's copy of super vtable for overrides | 257 // Update child's copy of super vtable for overrides |
258 // OR return true if a new vtable entry is required | 258 // OR return true if a new vtable entry is required. |
259 // Only called for InstanceKlass's, i.e. not for arrays | 259 // Only called for InstanceKlass's, i.e. not for arrays |
260 // If that changed, could not use _klass as handle for klass | 260 // If that changed, could not use _klass as handle for klass |
261 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, | 261 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, |
262 bool checkconstraints, TRAPS) { | 262 bool checkconstraints, TRAPS) { |
263 ResourceMark rm; | 263 ResourceMark rm; |
264 bool allocate_new = true; | 264 bool allocate_new = true; |
265 assert(klass->oop_is_instance(), "must be InstanceKlass"); | 265 assert(klass->oop_is_instance(), "must be InstanceKlass"); |
266 assert(klass == target_method()->method_holder(), "caller resp."); | |
266 | 267 |
267 // Initialize the method's vtable index to "nonvirtual". | 268 // Initialize the method's vtable index to "nonvirtual". |
268 // If we allocate a vtable entry, we will update it to a non-negative number. | 269 // If we allocate a vtable entry, we will update it to a non-negative number. |
269 target_method()->set_vtable_index(Method::nonvirtual_vtable_index); | 270 target_method()->set_vtable_index(Method::nonvirtual_vtable_index); |
270 | 271 |
271 // Static and <init> methods are never in | 272 // Static and <init> methods are never in |
272 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) { | 273 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) { |
273 return false; | 274 return false; |
274 } | 275 } |
275 | 276 |
276 if (method_is_effectively_final(klass->access_flags(), target_method)) { | 277 if (target_method->is_final_method(klass->access_flags())) { |
277 // a final method never needs a new entry; final methods can be statically | 278 // a final method never needs a new entry; final methods can be statically |
278 // resolved and they have to be present in the vtable only if they override | 279 // resolved and they have to be present in the vtable only if they override |
279 // a super's method, in which case they re-use its entry | 280 // a super's method, in which case they re-use its entry |
280 allocate_new = false; | 281 allocate_new = false; |
282 } else if (klass->is_interface()) { | |
283 allocate_new = false; // see note below in needs_new_vtable_entry | |
284 // An interface never allocates new vtable slots, only inherits old ones. | |
285 // This method will either be assigned its own itable index later, | |
286 // or be assigned an inherited vtable index in the loop below. | |
287 target_method()->set_vtable_index(Method::pending_itable_index); | |
281 } | 288 } |
282 | 289 |
283 // we need a new entry if there is no superclass | 290 // we need a new entry if there is no superclass |
284 if (klass->super() == NULL) { | 291 if (klass->super() == NULL) { |
285 return allocate_new; | 292 return allocate_new; |
286 } | 293 } |
287 | 294 |
288 // private methods always have a new entry in the vtable | 295 // private methods in classes always have a new entry in the vtable |
289 // specification interpretation since classic has | 296 // specification interpretation since classic has |
290 // private methods not overriding | 297 // private methods not overriding |
298 // JDK8 adds private methods in interfaces which require invokespecial | |
291 if (target_method()->is_private()) { | 299 if (target_method()->is_private()) { |
292 return allocate_new; | 300 return allocate_new; |
293 } | 301 } |
294 | 302 |
295 // search through the vtable and update overridden entries | 303 // search through the vtable and update overridden entries |
409 Klass* super, | 417 Klass* super, |
410 Handle classloader, | 418 Handle classloader, |
411 Symbol* classname, | 419 Symbol* classname, |
412 AccessFlags class_flags, | 420 AccessFlags class_flags, |
413 TRAPS) { | 421 TRAPS) { |
414 | 422 if (class_flags.is_interface()) { |
415 if (method_is_effectively_final(class_flags, target_method) || | 423 // Interfaces do not use vtables, so there is no point to assigning |
424 // a vtable index to any of their methods. If we refrain from doing this, | |
425 // we can use Method::_vtable_index to hold the itable index | |
426 return false; | |
427 } | |
428 | |
429 if (target_method->is_final_method(class_flags) || | |
416 // a final method never needs a new entry; final methods can be statically | 430 // a final method never needs a new entry; final methods can be statically |
417 // resolved and they have to be present in the vtable only if they override | 431 // resolved and they have to be present in the vtable only if they override |
418 // a super's method, in which case they re-use its entry | 432 // a super's method, in which case they re-use its entry |
419 (target_method()->is_static()) || | 433 (target_method()->is_static()) || |
420 // static methods don't need to be in vtable | 434 // static methods don't need to be in vtable |
427 // we need a new entry if there is no superclass | 441 // we need a new entry if there is no superclass |
428 if (super == NULL) { | 442 if (super == NULL) { |
429 return true; | 443 return true; |
430 } | 444 } |
431 | 445 |
432 // private methods always have a new entry in the vtable | 446 // private methods in classes always have a new entry in the vtable |
433 // specification interpretation since classic has | 447 // specification interpretation since classic has |
434 // private methods not overriding | 448 // private methods not overriding |
449 // JDK8 adds private methods in interfaces which require invokespecial | |
435 if (target_method()->is_private()) { | 450 if (target_method()->is_private()) { |
436 return true; | 451 return true; |
437 } | 452 } |
438 | 453 |
439 // search through the super class hierarchy to see if we need | 454 // search through the super class hierarchy to see if we need |
498 } | 513 } |
499 } | 514 } |
500 return Method::invalid_vtable_index; | 515 return Method::invalid_vtable_index; |
501 } | 516 } |
502 | 517 |
503 // check if an entry is miranda | 518 // check if an entry at an index is miranda |
519 // requires that method m at entry be declared ("held") by an interface. | |
504 bool klassVtable::is_miranda_entry_at(int i) { | 520 bool klassVtable::is_miranda_entry_at(int i) { |
505 Method* m = method_at(i); | 521 Method* m = method_at(i); |
506 Klass* method_holder = m->method_holder(); | 522 Klass* method_holder = m->method_holder(); |
507 InstanceKlass *mhk = InstanceKlass::cast(method_holder); | 523 InstanceKlass *mhk = InstanceKlass::cast(method_holder); |
508 | 524 |
509 // miranda methods are interface methods in a class's vtable | 525 // miranda methods are public abstract instance interface methods in a class's vtable |
510 if (mhk->is_interface()) { | 526 if (mhk->is_interface()) { |
511 assert(m->is_public(), "should be public"); | 527 assert(m->is_public(), "should be public"); |
512 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); | 528 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); |
513 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method"); | 529 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method"); |
514 return true; | 530 return true; |
515 } | 531 } |
516 return false; | 532 return false; |
517 } | 533 } |
518 | 534 |
519 // check if a method is a miranda method, given a class's methods table and it's super | 535 // check if a method is a miranda method, given a class's methods table and its super |
536 // "miranda" means not static, not defined by this class, and not defined | |
537 // in super unless it is private and therefore inaccessible to this class. | |
520 // the caller must make sure that the method belongs to an interface implemented by the class | 538 // the caller must make sure that the method belongs to an interface implemented by the class |
539 // Miranda methods only include public interface instance methods | |
540 // Not private methods, not static methods, not default = concrete abstract | |
521 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) { | 541 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) { |
522 if (m->is_static()) { | 542 if (m->is_static()) { |
523 return false; | 543 return false; |
524 } | 544 } |
525 Symbol* name = m->name(); | 545 Symbol* name = m->name(); |
539 } | 559 } |
540 | 560 |
541 return false; | 561 return false; |
542 } | 562 } |
543 | 563 |
564 // Scans current_interface_methods for miranda methods that do not | |
565 // already appear in new_mirandas and are also not defined-and-non-private | |
566 // in super (superclass). These mirandas are added to all_mirandas if it is | |
567 // not null; in addition, those that are not duplicates of miranda methods | |
568 // inherited by super from its interfaces are added to new_mirandas. | |
569 // Thus, new_mirandas will be the set of mirandas that this class introduces, | |
570 // all_mirandas will be the set of all mirandas applicable to this class | |
571 // including all defined in superclasses. | |
544 void klassVtable::add_new_mirandas_to_lists( | 572 void klassVtable::add_new_mirandas_to_lists( |
545 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, | 573 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, |
546 Array<Method*>* current_interface_methods, Array<Method*>* class_methods, | 574 Array<Method*>* current_interface_methods, Array<Method*>* class_methods, |
547 Klass* super) { | 575 Klass* super) { |
548 // iterate thru the current interface's method to see if it a miranda | 576 // iterate thru the current interface's method to see if it a miranda |
597 sik->methods(), class_methods, super); | 625 sik->methods(), class_methods, super); |
598 } | 626 } |
599 } | 627 } |
600 } | 628 } |
601 | 629 |
602 // fill in mirandas | 630 // Discover miranda methods ("miranda" = "interface abstract, no binding"), |
603 void klassVtable::fill_in_mirandas(int* initialized) { | 631 // and append them into the vtable starting at index initialized, |
632 // return the new value of initialized. | |
633 int klassVtable::fill_in_mirandas(int initialized) { | |
604 GrowableArray<Method*> mirandas(20); | 634 GrowableArray<Method*> mirandas(20); |
605 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), | 635 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), |
606 ik()->local_interfaces()); | 636 ik()->local_interfaces()); |
607 for (int i = 0; i < mirandas.length(); i++) { | 637 for (int i = 0; i < mirandas.length(); i++) { |
608 put_method_at(mirandas.at(i), *initialized); | 638 put_method_at(mirandas.at(i), initialized); |
609 ++(*initialized); | 639 ++initialized; |
610 } | 640 } |
611 } | 641 return initialized; |
612 | 642 } |
643 | |
644 // Copy this class's vtable to the vtable beginning at start. | |
645 // Used to copy superclass vtable to prefix of subclass's vtable. | |
613 void klassVtable::copy_vtable_to(vtableEntry* start) { | 646 void klassVtable::copy_vtable_to(vtableEntry* start) { |
614 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); | 647 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); |
615 } | 648 } |
616 | 649 |
617 #if INCLUDE_JVMTI | 650 #if INCLUDE_JVMTI |
721 | 754 |
722 static int initialize_count = 0; | 755 static int initialize_count = 0; |
723 | 756 |
724 // Initialization | 757 // Initialization |
725 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { | 758 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
759 if (_klass->is_interface()) { | |
760 // This needs to go after vtable indexes are assigned but | |
761 // before implementors need to know the number of itable indexes. | |
762 assign_itable_indexes_for_interface(_klass()); | |
763 } | |
764 | |
726 // Cannot be setup doing bootstrapping, interfaces don't have | 765 // Cannot be setup doing bootstrapping, interfaces don't have |
727 // itables, and klass with only ones entry have empty itables | 766 // itables, and klass with only ones entry have empty itables |
728 if (Universe::is_bootstrapping() || | 767 if (Universe::is_bootstrapping() || |
729 _klass->is_interface() || | 768 _klass->is_interface() || |
730 _klass->itable_length() == itableOffsetEntry::size()) return; | 769 _klass->itable_length() == itableOffsetEntry::size()) return; |
752 itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1); | 791 itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1); |
753 guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing"); | 792 guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing"); |
754 } | 793 } |
755 | 794 |
756 | 795 |
796 inline bool interface_method_needs_itable_index(Method* m) { | |
797 if (m->is_static()) return false; // e.g., Stream.empty | |
798 if (m->is_initializer()) return false; // <init> or <clinit> | |
799 // If an interface redeclares a method from java.lang.Object, | |
800 // it should already have a vtable index, don't touch it. | |
801 // e.g., CharSequence.toString (from initialize_vtable) | |
802 // if (m->has_vtable_index()) return false; // NO! | |
803 return true; | |
804 } | |
805 | |
806 int klassItable::assign_itable_indexes_for_interface(Klass* klass) { | |
807 // an interface does not have an itable, but its methods need to be numbered | |
808 if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count, | |
809 klass->name()->as_C_string()); | |
810 Array<Method*>* methods = InstanceKlass::cast(klass)->methods(); | |
811 int nof_methods = methods->length(); | |
812 int ime_num = 0; | |
813 for (int i = 0; i < nof_methods; i++) { | |
814 Method* m = methods->at(i); | |
815 if (interface_method_needs_itable_index(m)) { | |
816 assert(!m->is_final_method(), "no final interface methods"); | |
817 // If m is already assigned a vtable index, do not disturb it. | |
818 if (!m->has_vtable_index()) { | |
819 assert(m->vtable_index() == Method::pending_itable_index, "set by initialize_vtable"); | |
820 m->set_itable_index(ime_num); | |
821 // Progress to next itable entry | |
822 ime_num++; | |
823 } | |
824 } | |
825 } | |
826 assert(ime_num == method_count_for_interface(klass), "proper sizing"); | |
827 return ime_num; | |
828 } | |
829 | |
830 int klassItable::method_count_for_interface(Klass* interf) { | |
831 assert(interf->oop_is_instance(), "must be"); | |
832 assert(interf->is_interface(), "must be"); | |
833 Array<Method*>* methods = InstanceKlass::cast(interf)->methods(); | |
834 int nof_methods = methods->length(); | |
835 while (nof_methods > 0) { | |
836 Method* m = methods->at(nof_methods-1); | |
837 if (m->has_itable_index()) { | |
838 int length = m->itable_index() + 1; | |
839 #ifdef ASSERT | |
840 while (nof_methods = 0) { | |
841 m = methods->at(--nof_methods); | |
842 assert(!m->has_itable_index() || m->itable_index() < length, ""); | |
843 } | |
844 #endif //ASSERT | |
845 return length; // return the rightmost itable index, plus one | |
846 } | |
847 nof_methods -= 1; | |
848 } | |
849 // no methods have itable indexes | |
850 return 0; | |
851 } | |
852 | |
853 | |
757 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { | 854 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { |
758 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods(); | 855 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods(); |
759 int nof_methods = methods->length(); | 856 int nof_methods = methods->length(); |
760 HandleMark hm; | 857 HandleMark hm; |
761 KlassHandle klass = _klass; | |
762 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable"); | 858 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable"); |
763 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader()); | 859 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader()); |
764 int ime_num = 0; | 860 |
765 | 861 int ime_count = method_count_for_interface(interf_h()); |
766 // Skip first Method* if it is a class initializer | 862 for (int i = 0; i < nof_methods; i++) { |
767 int i = methods->at(0)->is_static_initializer() ? 1 : 0; | |
768 | |
769 // m, method_name, method_signature, klass reset each loop so they | |
770 // don't need preserving across check_signature_loaders call | |
771 // methods needs a handle in case of gc from check_signature_loaders | |
772 for(; i < nof_methods; i++) { | |
773 Method* m = methods->at(i); | 863 Method* m = methods->at(i); |
774 Symbol* method_name = m->name(); | 864 methodHandle target; |
775 Symbol* method_signature = m->signature(); | 865 if (m->has_itable_index()) { |
776 | 866 LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK); |
777 // This is same code as in Linkresolver::lookup_instance_method_in_klasses | |
778 Method* target = klass->uncached_lookup_method(method_name, method_signature); | |
779 while (target != NULL && target->is_static()) { | |
780 // continue with recursive lookup through the superclass | |
781 Klass* super = target->method_holder()->super(); | |
782 target = (super == NULL) ? (Method*)NULL : super->uncached_lookup_method(method_name, method_signature); | |
783 } | 867 } |
784 if (target == NULL || !target->is_public() || target->is_abstract()) { | 868 if (target == NULL || !target->is_public() || target->is_abstract()) { |
785 // Entry do not resolve. Leave it empty | 869 // Entry do not resolve. Leave it empty |
786 } else { | 870 } else { |
787 // Entry did resolve, check loader constraints before initializing | 871 // Entry did resolve, check loader constraints before initializing |
788 // if checkconstraints requested | 872 // if checkconstraints requested |
789 methodHandle target_h (THREAD, target); // preserve across gc | |
790 if (checkconstraints) { | 873 if (checkconstraints) { |
791 Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); | 874 Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); |
792 if (method_holder_loader() != interface_loader()) { | 875 if (method_holder_loader() != interface_loader()) { |
793 ResourceMark rm(THREAD); | 876 ResourceMark rm(THREAD); |
794 Symbol* failed_type_symbol = | 877 Symbol* failed_type_symbol = |
795 SystemDictionary::check_signature_loaders(method_signature, | 878 SystemDictionary::check_signature_loaders(m->signature(), |
796 method_holder_loader, | 879 method_holder_loader, |
797 interface_loader, | 880 interface_loader, |
798 true, CHECK); | 881 true, CHECK); |
799 if (failed_type_symbol != NULL) { | 882 if (failed_type_symbol != NULL) { |
800 const char* msg = "loader constraint violation in interface " | 883 const char* msg = "loader constraint violation in interface " |
801 "itable initialization: when resolving method \"%s\" the class" | 884 "itable initialization: when resolving method \"%s\" the class" |
802 " loader (instance of %s) of the current class, %s, " | 885 " loader (instance of %s) of the current class, %s, " |
803 "and the class loader (instance of %s) for interface " | 886 "and the class loader (instance of %s) for interface " |
804 "%s have different Class objects for the type %s " | 887 "%s have different Class objects for the type %s " |
805 "used in the signature"; | 888 "used in the signature"; |
806 char* sig = target_h()->name_and_sig_as_C_string(); | 889 char* sig = target()->name_and_sig_as_C_string(); |
807 const char* loader1 = SystemDictionary::loader_name(method_holder_loader()); | 890 const char* loader1 = SystemDictionary::loader_name(method_holder_loader()); |
808 char* current = klass->name()->as_C_string(); | 891 char* current = _klass->name()->as_C_string(); |
809 const char* loader2 = SystemDictionary::loader_name(interface_loader()); | 892 const char* loader2 = SystemDictionary::loader_name(interface_loader()); |
810 char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string(); | 893 char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string(); |
811 char* failed_type_name = failed_type_symbol->as_C_string(); | 894 char* failed_type_name = failed_type_symbol->as_C_string(); |
812 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + | 895 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + |
813 strlen(current) + strlen(loader2) + strlen(iface) + | 896 strlen(current) + strlen(loader2) + strlen(iface) + |
819 } | 902 } |
820 } | 903 } |
821 } | 904 } |
822 | 905 |
823 // ime may have moved during GC so recalculate address | 906 // ime may have moved during GC so recalculate address |
824 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target_h()); | 907 int ime_num = m->itable_index(); |
825 } | 908 assert(ime_num < ime_count, "oob"); |
826 // Progress to next entry | 909 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target()); |
827 ime_num++; | 910 } |
828 } | 911 } |
829 } | 912 } |
830 | 913 |
831 // Update entry for specific Method* | 914 // Update entry for specific Method* |
832 void klassItable::initialize_with_method(Method* m) { | 915 void klassItable::initialize_with_method(Method* m) { |
911 class InterfaceVisiterClosure : public StackObj { | 994 class InterfaceVisiterClosure : public StackObj { |
912 public: | 995 public: |
913 virtual void doit(Klass* intf, int method_count) = 0; | 996 virtual void doit(Klass* intf, int method_count) = 0; |
914 }; | 997 }; |
915 | 998 |
916 // Visit all interfaces with at-least one method (excluding <clinit>) | 999 // Visit all interfaces with at least one itable method |
917 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) { | 1000 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) { |
918 // Handle array argument | 1001 // Handle array argument |
919 for(int i = 0; i < transitive_intf->length(); i++) { | 1002 for(int i = 0; i < transitive_intf->length(); i++) { |
920 Klass* intf = transitive_intf->at(i); | 1003 Klass* intf = transitive_intf->at(i); |
921 assert(intf->is_interface(), "sanity check"); | 1004 assert(intf->is_interface(), "sanity check"); |
922 | 1005 |
923 // Find no. of methods excluding a <clinit> | 1006 // Find no. of itable methods |
924 int method_count = InstanceKlass::cast(intf)->methods()->length(); | 1007 int method_count = 0; |
925 if (method_count > 0) { | 1008 // method_count = klassItable::method_count_for_interface(intf); |
926 Method* m = InstanceKlass::cast(intf)->methods()->at(0); | 1009 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
927 assert(m != NULL && m->is_method(), "sanity check"); | 1010 if (methods->length() > 0) { |
928 if (m->name() == vmSymbols::object_initializer_name()) { | 1011 for (int i = methods->length(); --i >= 0; ) { |
929 method_count--; | 1012 if (interface_method_needs_itable_index(methods->at(i))) { |
1013 method_count++; | |
1014 } | |
930 } | 1015 } |
931 } | 1016 } |
932 | 1017 |
933 // Only count interfaces with at least one method | 1018 // Only count interfaces with at least one method |
934 if (method_count > 0) { | 1019 if (method_count > 0) { |
1022 assert( (oop*)(ime) == v, "wrong offset calculation (2)"); | 1107 assert( (oop*)(ime) == v, "wrong offset calculation (2)"); |
1023 #endif | 1108 #endif |
1024 } | 1109 } |
1025 | 1110 |
1026 | 1111 |
1027 // m must be a method in an interface | 1112 // inverse to itable_index |
1028 int klassItable::compute_itable_index(Method* m) { | |
1029 InstanceKlass* intf = m->method_holder(); | |
1030 assert(intf->is_interface(), "sanity check"); | |
1031 Array<Method*>* methods = intf->methods(); | |
1032 int index = 0; | |
1033 while(methods->at(index) != m) { | |
1034 index++; | |
1035 assert(index < methods->length(), "should find index for resolve_invoke"); | |
1036 } | |
1037 // Adjust for <clinit>, which is left out of table if first method | |
1038 if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { | |
1039 index--; | |
1040 } | |
1041 return index; | |
1042 } | |
1043 | |
1044 | |
1045 // inverse to compute_itable_index | |
1046 Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) { | 1113 Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) { |
1047 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); | 1114 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); |
1115 assert(intf->verify_itable_index(itable_index), ""); | |
1048 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); | 1116 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
1049 | 1117 |
1118 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) | |
1119 return NULL; // help caller defend against bad indexes | |
1120 | |
1050 int index = itable_index; | 1121 int index = itable_index; |
1051 // Adjust for <clinit>, which is left out of table if first method | |
1052 if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { | |
1053 index++; | |
1054 } | |
1055 | |
1056 if (itable_index < 0 || index >= methods->length()) | |
1057 return NULL; // help caller defend against bad indexes | |
1058 | |
1059 Method* m = methods->at(index); | 1122 Method* m = methods->at(index); |
1060 assert(compute_itable_index(m) == itable_index, "correct inverse"); | 1123 int index2 = -1; |
1124 while (!m->has_itable_index() || | |
1125 (index2 = m->itable_index()) != itable_index) { | |
1126 assert(index2 < itable_index, "monotonic"); | |
1127 if (++index == methods->length()) | |
1128 return NULL; | |
1129 m = methods->at(index); | |
1130 } | |
1131 assert(m->itable_index() == itable_index, "correct inverse"); | |
1061 | 1132 |
1062 return m; | 1133 return m; |
1063 } | 1134 } |
1064 | 1135 |
1065 void klassVtable::verify(outputStream* st, bool forced) { | 1136 void klassVtable::verify(outputStream* st, bool forced) { |