224 } |
224 } |
225 for (int i = 0; i < len; i++) { |
225 for (int i = 0; i < len; i++) { |
226 HandleMark hm(THREAD); |
226 HandleMark hm(THREAD); |
227 assert(default_methods->at(i)->is_method(), "must be a Method*"); |
227 assert(default_methods->at(i)->is_method(), "must be a Method*"); |
228 methodHandle mh(THREAD, default_methods->at(i)); |
228 methodHandle mh(THREAD, default_methods->at(i)); |
229 |
229 assert(!mh->is_private(), "private interface method in the default method list"); |
230 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, i, checkconstraints, CHECK); |
230 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, i, checkconstraints, CHECK); |
231 |
231 |
232 // needs new entry |
232 // needs new entry |
233 if (needs_new_entry) { |
233 if (needs_new_entry) { |
234 put_method_at(mh(), initialized); |
234 put_method_at(mh(), initialized); |
360 bool allocate_new = true; |
360 bool allocate_new = true; |
361 assert(klass->is_instance_klass(), "must be InstanceKlass"); |
361 assert(klass->is_instance_klass(), "must be InstanceKlass"); |
362 |
362 |
363 Array<int>* def_vtable_indices = NULL; |
363 Array<int>* def_vtable_indices = NULL; |
364 bool is_default = false; |
364 bool is_default = false; |
365 // default methods are concrete methods in superinterfaces which are added to the vtable |
365 |
366 // with their real method_holder |
366 // default methods are non-private concrete methods in superinterfaces which are added |
|
367 // to the vtable with their real method_holder. |
367 // Since vtable and itable indices share the same storage, don't touch |
368 // Since vtable and itable indices share the same storage, don't touch |
368 // the default method's real vtable/itable index |
369 // the default method's real vtable/itable index. |
369 // default_vtable_indices stores the vtable value relative to this inheritor |
370 // default_vtable_indices stores the vtable value relative to this inheritor |
370 if (default_index >= 0 ) { |
371 if (default_index >= 0 ) { |
371 is_default = true; |
372 is_default = true; |
372 def_vtable_indices = klass->default_vtable_indices(); |
373 def_vtable_indices = klass->default_vtable_indices(); |
|
374 assert(!target_method()->is_private(), "private interface method flagged as default"); |
373 assert(def_vtable_indices != NULL, "def vtable alloc?"); |
375 assert(def_vtable_indices != NULL, "def vtable alloc?"); |
374 assert(default_index <= def_vtable_indices->length(), "def vtable len?"); |
376 assert(default_index <= def_vtable_indices->length(), "def vtable len?"); |
375 } else { |
377 } else { |
376 assert(klass == target_method()->method_holder(), "caller resp."); |
378 assert(klass == target_method()->method_holder(), "caller resp."); |
377 // Initialize the method's vtable index to "nonvirtual". |
379 // Initialize the method's vtable index to "nonvirtual". |
393 allocate_new = false; // see note below in needs_new_vtable_entry |
395 allocate_new = false; // see note below in needs_new_vtable_entry |
394 // An interface never allocates new vtable slots, only inherits old ones. |
396 // An interface never allocates new vtable slots, only inherits old ones. |
395 // This method will either be assigned its own itable index later, |
397 // This method will either be assigned its own itable index later, |
396 // or be assigned an inherited vtable index in the loop below. |
398 // or be assigned an inherited vtable index in the loop below. |
397 // default methods inherited by classes store their vtable indices |
399 // default methods inherited by classes store their vtable indices |
398 // in the inheritor's default_vtable_indices |
400 // in the inheritor's default_vtable_indices. |
399 // default methods inherited by interfaces may already have a |
401 // default methods inherited by interfaces may already have a |
400 // valid itable index, if so, don't change it |
402 // valid itable index, if so, don't change it. |
401 // overpass methods in an interface will be assigned an itable index later |
403 // Overpass methods in an interface will be assigned an itable index later |
402 // by an inheriting class |
404 // by an inheriting class. |
403 if (!is_default || !target_method()->has_itable_index()) { |
405 // Private interface methods have no itable index and are always invoked nonvirtually, |
|
406 // so they retain their nonvirtual_vtable_index value, and therefore can_be_statically_bound() |
|
407 // will return true. |
|
408 if ((!is_default || !target_method()->has_itable_index()) && !target_method()->is_private()) { |
404 target_method()->set_vtable_index(Method::pending_itable_index); |
409 target_method()->set_vtable_index(Method::pending_itable_index); |
405 } |
410 } |
406 } |
411 } |
407 |
412 |
408 // we need a new entry if there is no superclass |
413 // we need a new entry if there is no superclass |
595 |
600 |
596 // Concrete interface methods do not need new entries, they override |
601 // Concrete interface methods do not need new entries, they override |
597 // abstract method entries using default inheritance rules |
602 // abstract method entries using default inheritance rules |
598 if (target_method()->method_holder() != NULL && |
603 if (target_method()->method_holder() != NULL && |
599 target_method()->method_holder()->is_interface() && |
604 target_method()->method_holder()->is_interface() && |
600 !target_method()->is_abstract() ) { |
605 !target_method()->is_abstract()) { |
|
606 assert(target_method()->is_default_method() || target_method()->is_private(), |
|
607 "unexpected interface method type"); |
601 return false; |
608 return false; |
602 } |
609 } |
603 |
610 |
604 // we need a new entry if there is no superclass |
611 // we need a new entry if there is no superclass |
605 if (super == NULL) { |
612 if (super == NULL) { |
606 return true; |
613 return true; |
607 } |
614 } |
608 |
615 |
609 // private methods in classes always have a new entry in the vtable |
616 // private methods in classes always have a new entry in the vtable. |
610 // specification interpretation since classic has |
617 // Specification interpretation since classic has private methods not overriding. |
611 // private methods not overriding |
|
612 // JDK8 adds private methods in interfaces which require invokespecial |
|
613 if (target_method()->is_private()) { |
618 if (target_method()->is_private()) { |
614 return true; |
619 return true; |
615 } |
620 } |
616 |
621 |
617 // Package private methods always need a new entry to root their own |
622 // Package private methods always need a new entry to root their own |
1086 |
1091 |
1087 |
1092 |
1088 inline bool interface_method_needs_itable_index(Method* m) { |
1093 inline bool interface_method_needs_itable_index(Method* m) { |
1089 if (m->is_static()) return false; // e.g., Stream.empty |
1094 if (m->is_static()) return false; // e.g., Stream.empty |
1090 if (m->is_initializer()) return false; // <init> or <clinit> |
1095 if (m->is_initializer()) return false; // <init> or <clinit> |
|
1096 if (m->is_private()) return false; // requires invokeSpecial |
1091 // If an interface redeclares a method from java.lang.Object, |
1097 // If an interface redeclares a method from java.lang.Object, |
1092 // it should already have a vtable index, don't touch it. |
1098 // it should already have a vtable index, don't touch it. |
1093 // e.g., CharSequence.toString (from initialize_vtable) |
1099 // e.g., CharSequence.toString (from initialize_vtable) |
1094 // if (m->has_vtable_index()) return false; // NO! |
1100 // if (m->has_vtable_index()) return false; // NO! |
1095 return true; |
1101 return true; |