1 /* |
1 /* |
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
878 |
878 |
879 bool is_witness(Klass* k) { |
879 bool is_witness(Klass* k) { |
880 if (doing_subtype_search()) { |
880 if (doing_subtype_search()) { |
881 return Dependencies::is_concrete_klass(k); |
881 return Dependencies::is_concrete_klass(k); |
882 } else { |
882 } else { |
883 Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); |
883 // Search class hierarchy first. |
884 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; |
884 Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature); |
|
885 if (!Dependencies::is_concrete_method(m, k)) { |
|
886 // Check interface defaults also, if any exist. |
|
887 Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods(); |
|
888 if (default_methods == NULL) |
|
889 return false; |
|
890 m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature); |
|
891 if (!Dependencies::is_concrete_method(m, NULL)) |
|
892 return false; |
|
893 } |
885 _found_methods[_num_participants] = m; |
894 _found_methods[_num_participants] = m; |
886 // Note: If add_participant(k) is called, |
895 // Note: If add_participant(k) is called, |
887 // the method m will already be memoized for it. |
896 // the method m will already be memoized for it. |
888 return true; |
897 return true; |
889 } |
898 } |
1170 // This would require a deoptimization barrier on first instantiation. |
1179 // This would require a deoptimization barrier on first instantiation. |
1171 //if (k->is_not_instantiated()) return false; |
1180 //if (k->is_not_instantiated()) return false; |
1172 return true; |
1181 return true; |
1173 } |
1182 } |
1174 |
1183 |
1175 bool Dependencies::is_concrete_method(Method* m) { |
1184 bool Dependencies::is_concrete_method(Method* m, Klass * k) { |
1176 // Statics are irrelevant to virtual call sites. |
1185 // NULL is not a concrete method, |
1177 if (m->is_static()) return false; |
1186 // statics are irrelevant to virtual call sites, |
1178 |
1187 // abstract methods are not concrete, |
1179 // We could also return false if m does not yet appear to be |
1188 // overpass (error) methods are not concrete if k is abstract |
1180 // executed, if the VM version supports this distinction also. |
1189 // |
1181 // Default methods are considered "concrete" as well. |
1190 // note "true" is conservative answer -- |
1182 return !m->is_abstract() && |
1191 // overpass clause is false if k == NULL, implies return true if |
1183 !m->is_overpass(); // error functions aren't concrete |
1192 // answer depends on overpass clause. |
|
1193 return ! ( m == NULL || m -> is_static() || m -> is_abstract() || |
|
1194 m->is_overpass() && k != NULL && k -> is_abstract() ); |
1184 } |
1195 } |
1185 |
1196 |
1186 |
1197 |
1187 Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
1198 Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
1188 if (k->is_interface()) return NULL; |
1199 if (k->is_interface()) return NULL; |
1202 // We could also return false if k does not yet appear to be |
1213 // We could also return false if k does not yet appear to be |
1203 // instantiated, if the VM version supports this distinction also. |
1214 // instantiated, if the VM version supports this distinction also. |
1204 //if (k->is_not_instantiated()) return false; |
1215 //if (k->is_not_instantiated()) return false; |
1205 return true; |
1216 return true; |
1206 } |
1217 } |
1207 |
|
1208 bool Dependencies::is_concrete_method(ciMethod* m) { |
|
1209 // Statics are irrelevant to virtual call sites. |
|
1210 if (m->is_static()) return false; |
|
1211 |
|
1212 // We could also return false if m does not yet appear to be |
|
1213 // executed, if the VM version supports this distinction also. |
|
1214 return !m->is_abstract(); |
|
1215 } |
|
1216 |
|
1217 |
1218 |
1218 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
1219 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
1219 return k->has_finalizable_subclass(); |
1220 return k->has_finalizable_subclass(); |
1220 } |
1221 } |
1221 |
1222 |
1426 assert(wf.check_method_context(ctxk, m), "proper context"); |
1427 assert(wf.check_method_context(ctxk, m), "proper context"); |
1427 wf.record_witnesses(1); |
1428 wf.record_witnesses(1); |
1428 Klass* wit = wf.find_witness_definer(ctxk); |
1429 Klass* wit = wf.find_witness_definer(ctxk); |
1429 if (wit != NULL) return NULL; // Too many witnesses. |
1430 if (wit != NULL) return NULL; // Too many witnesses. |
1430 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
1431 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
1431 if (Dependencies::is_concrete_method(m)) { |
1432 if (Dependencies::is_concrete_method(m, ctxk)) { |
1432 if (fm == NULL) { |
1433 if (fm == NULL) { |
1433 // It turns out that m was always the only implementation. |
1434 // It turns out that m was always the only implementation. |
1434 fm = m; |
1435 fm = m; |
1435 } else if (fm != m) { |
1436 } else if (fm != m) { |
1436 // Two conflicting implementations after all. |
1437 // Two conflicting implementations after all. |
1456 wf.add_participant(m1->method_holder()); |
1457 wf.add_participant(m1->method_holder()); |
1457 wf.add_participant(m2->method_holder()); |
1458 wf.add_participant(m2->method_holder()); |
1458 return wf.find_witness_definer(ctxk, changes); |
1459 return wf.find_witness_definer(ctxk, changes); |
1459 } |
1460 } |
1460 |
1461 |
1461 // Find the set of all non-abstract methods under ctxk that match m[0]. |
|
1462 // (The method m[0] must be defined or inherited in ctxk.) |
|
1463 // Include m itself in the set, unless it is abstract. |
|
1464 // Fill the given array m[0..(mlen-1)] with this set, and return the length. |
|
1465 // (The length may be zero if no concrete methods are found anywhere.) |
|
1466 // If there are too many concrete methods to fit in marray, return -1. |
|
1467 int Dependencies::find_exclusive_concrete_methods(Klass* ctxk, |
|
1468 int mlen, |
|
1469 Method* marray[]) { |
|
1470 Method* m0 = marray[0]; |
|
1471 ClassHierarchyWalker wf(m0); |
|
1472 assert(wf.check_method_context(ctxk, m0), "proper context"); |
|
1473 wf.record_witnesses(mlen); |
|
1474 bool participants_hide_witnesses = true; |
|
1475 Klass* wit = wf.find_witness_definer(ctxk); |
|
1476 if (wit != NULL) return -1; // Too many witnesses. |
|
1477 int num = wf.num_participants(); |
|
1478 assert(num <= mlen, "oob"); |
|
1479 // Keep track of whether m is also part of the result set. |
|
1480 int mfill = 0; |
|
1481 assert(marray[mfill] == m0, "sanity"); |
|
1482 if (Dependencies::is_concrete_method(m0)) |
|
1483 mfill++; // keep m0 as marray[0], the first result |
|
1484 for (int i = 0; i < num; i++) { |
|
1485 Method* fm = wf.found_method(i); |
|
1486 if (fm == m0) continue; // Already put this guy in the list. |
|
1487 if (mfill == mlen) { |
|
1488 return -1; // Oops. Too many methods after all! |
|
1489 } |
|
1490 marray[mfill++] = fm; |
|
1491 } |
|
1492 #ifndef PRODUCT |
|
1493 // Make sure the dependency mechanism will pass this discovery: |
|
1494 if (VerifyDependencies) { |
|
1495 // Turn off dependency tracing while actually testing deps. |
|
1496 FlagSetting fs(TraceDependencies, false); |
|
1497 switch (mfill) { |
|
1498 case 1: |
|
1499 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]), |
|
1500 "verify dep."); |
|
1501 break; |
|
1502 case 2: |
|
1503 guarantee(NULL == (void *) |
|
1504 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]), |
|
1505 "verify dep."); |
|
1506 break; |
|
1507 default: |
|
1508 ShouldNotReachHere(); // mlen > 2 yet supported |
|
1509 } |
|
1510 } |
|
1511 #endif //PRODUCT |
|
1512 return mfill; |
|
1513 } |
|
1514 |
|
1515 |
|
1516 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
1462 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
1517 Klass* search_at = ctxk; |
1463 Klass* search_at = ctxk; |
1518 if (changes != NULL) |
1464 if (changes != NULL) |
1519 search_at = changes->new_type(); // just look at the new bit |
1465 search_at = changes->new_type(); // just look at the new bit |
1520 return find_finalizable_subclass(search_at); |
1466 return find_finalizable_subclass(search_at); |
1521 } |
1467 } |
1522 |
|
1523 |
1468 |
1524 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
1469 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
1525 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
1470 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
1526 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
1471 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
1527 if (changes == NULL) { |
1472 if (changes == NULL) { |