< prev index next >

src/hotspot/share/code/dependencies.cpp

Print this page
rev 52894 : 8227467: Better class method invocations
Reviewed-by: thartmann, dholmes, ahgross, andrew


1224   }
1225 
1226   bool is_witness(Klass* k) {
1227     if (doing_subtype_search()) {
1228       return Dependencies::is_concrete_klass(k);
1229     } else if (!k->is_instance_klass()) {
1230       return false; // no methods to find in an array type
1231     } else {
1232       // Search class hierarchy first, skipping private implementations
1233       // as they never override any inherited methods
1234       Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature, Klass::skip_private);
1235       if (!Dependencies::is_concrete_method(m, k)) {
1236         // Check for re-abstraction of method
1237         if (!k->is_interface() && m != NULL && m->is_abstract()) {
1238           // Found a matching abstract method 'm' in the class hierarchy.
1239           // This is fine iff 'k' is an abstract class and all concrete subtypes
1240           // of 'k' override 'm' and are participates of the current search.
1241           ClassHierarchyWalker wf(_participants, _num_participants);
1242           Klass* w = wf.find_witness_subtype(k);
1243           if (w != NULL) {
1244             Method* wm = InstanceKlass::cast(w)->find_instance_method(_name, _signature);
1245             if (!Dependencies::is_concrete_method(wm, w)) {
1246               // Found a concrete subtype 'w' which does not override abstract method 'm'.
1247               // Bail out because 'm' could be called with 'w' as receiver (leading to an
1248               // AbstractMethodError) and thus the method we are looking for is not unique.
1249               _found_methods[_num_participants] = m;
1250               return true;
1251             }
1252           }
1253         }
1254         // Check interface defaults also, if any exist.
1255         Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods();
1256         if (default_methods == NULL)
1257             return false;
1258         m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature);
1259         if (!Dependencies::is_concrete_method(m, NULL))
1260             return false;
1261       }
1262       _found_methods[_num_participants] = m;
1263       // Note:  If add_participant(k) is called,
1264       // the method m will already be memoized for it.




1224   }
1225 
1226   bool is_witness(Klass* k) {
1227     if (doing_subtype_search()) {
1228       return Dependencies::is_concrete_klass(k);
1229     } else if (!k->is_instance_klass()) {
1230       return false; // no methods to find in an array type
1231     } else {
1232       // Search class hierarchy first, skipping private implementations
1233       // as they never override any inherited methods
1234       Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature, Klass::skip_private);
1235       if (!Dependencies::is_concrete_method(m, k)) {
1236         // Check for re-abstraction of method
1237         if (!k->is_interface() && m != NULL && m->is_abstract()) {
1238           // Found a matching abstract method 'm' in the class hierarchy.
1239           // This is fine iff 'k' is an abstract class and all concrete subtypes
1240           // of 'k' override 'm' and are participates of the current search.
1241           ClassHierarchyWalker wf(_participants, _num_participants);
1242           Klass* w = wf.find_witness_subtype(k);
1243           if (w != NULL) {
1244             Method* wm = InstanceKlass::cast(w)->find_instance_method(_name, _signature, Klass::skip_private);
1245             if (!Dependencies::is_concrete_method(wm, w)) {
1246               // Found a concrete subtype 'w' which does not override abstract method 'm'.
1247               // Bail out because 'm' could be called with 'w' as receiver (leading to an
1248               // AbstractMethodError) and thus the method we are looking for is not unique.
1249               _found_methods[_num_participants] = m;
1250               return true;
1251             }
1252           }
1253         }
1254         // Check interface defaults also, if any exist.
1255         Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods();
1256         if (default_methods == NULL)
1257             return false;
1258         m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature);
1259         if (!Dependencies::is_concrete_method(m, NULL))
1260             return false;
1261       }
1262       _found_methods[_num_participants] = m;
1263       // Note:  If add_participant(k) is called,
1264       // the method m will already be memoized for it.


< prev index next >