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. |
913 if (doing_subtype_search()) { |
913 if (doing_subtype_search()) { |
914 return Dependencies::is_concrete_klass(k); |
914 return Dependencies::is_concrete_klass(k); |
915 } else if (!k->oop_is_instance()) { |
915 } else if (!k->oop_is_instance()) { |
916 return false; // no methods to find in an array type |
916 return false; // no methods to find in an array type |
917 } else { |
917 } else { |
918 Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); |
918 // Search class hierarchy first. |
919 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; |
919 Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature); |
|
920 if (!Dependencies::is_concrete_method(m, k)) { |
|
921 // Check interface defaults also, if any exist. |
|
922 Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods(); |
|
923 if (default_methods == NULL) |
|
924 return false; |
|
925 m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature); |
|
926 if (!Dependencies::is_concrete_method(m, NULL)) |
|
927 return false; |
|
928 } |
920 _found_methods[_num_participants] = m; |
929 _found_methods[_num_participants] = m; |
921 // Note: If add_participant(k) is called, |
930 // Note: If add_participant(k) is called, |
922 // the method m will already be memoized for it. |
931 // the method m will already be memoized for it. |
923 return true; |
932 return true; |
924 } |
933 } |
1207 // This would require a deoptimization barrier on first instantiation. |
1216 // This would require a deoptimization barrier on first instantiation. |
1208 //if (k->is_not_instantiated()) return false; |
1217 //if (k->is_not_instantiated()) return false; |
1209 return true; |
1218 return true; |
1210 } |
1219 } |
1211 |
1220 |
1212 bool Dependencies::is_concrete_method(Method* m) { |
1221 bool Dependencies::is_concrete_method(Method* m, Klass * k) { |
1213 // Statics are irrelevant to virtual call sites. |
1222 // NULL is not a concrete method, |
1214 if (m->is_static()) return false; |
1223 // statics are irrelevant to virtual call sites, |
1215 |
1224 // abstract methods are not concrete, |
1216 // We could also return false if m does not yet appear to be |
1225 // overpass (error) methods are not concrete if k is abstract |
1217 // executed, if the VM version supports this distinction also. |
1226 // |
1218 // Default methods are considered "concrete" as well. |
1227 // note "true" is conservative answer -- |
1219 return !m->is_abstract() && |
1228 // overpass clause is false if k == NULL, implies return true if |
1220 !m->is_overpass(); // error functions aren't concrete |
1229 // answer depends on overpass clause. |
|
1230 return ! ( m == NULL || m -> is_static() || m -> is_abstract() || |
|
1231 m->is_overpass() && k != NULL && k -> is_abstract() ); |
1221 } |
1232 } |
1222 |
1233 |
1223 |
1234 |
1224 Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
1235 Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
1225 if (k->is_interface()) return NULL; |
1236 if (k->is_interface()) return NULL; |
1239 // We could also return false if k does not yet appear to be |
1250 // We could also return false if k does not yet appear to be |
1240 // instantiated, if the VM version supports this distinction also. |
1251 // instantiated, if the VM version supports this distinction also. |
1241 //if (k->is_not_instantiated()) return false; |
1252 //if (k->is_not_instantiated()) return false; |
1242 return true; |
1253 return true; |
1243 } |
1254 } |
1244 |
|
1245 bool Dependencies::is_concrete_method(ciMethod* m) { |
|
1246 // Statics are irrelevant to virtual call sites. |
|
1247 if (m->is_static()) return false; |
|
1248 |
|
1249 // We could also return false if m does not yet appear to be |
|
1250 // executed, if the VM version supports this distinction also. |
|
1251 return !m->is_abstract(); |
|
1252 } |
|
1253 |
|
1254 |
1255 |
1255 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
1256 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
1256 return k->has_finalizable_subclass(); |
1257 return k->has_finalizable_subclass(); |
1257 } |
1258 } |
1258 |
1259 |
1467 assert(wf.check_method_context(ctxk, m), "proper context"); |
1468 assert(wf.check_method_context(ctxk, m), "proper context"); |
1468 wf.record_witnesses(1); |
1469 wf.record_witnesses(1); |
1469 Klass* wit = wf.find_witness_definer(ctxk); |
1470 Klass* wit = wf.find_witness_definer(ctxk); |
1470 if (wit != NULL) return NULL; // Too many witnesses. |
1471 if (wit != NULL) return NULL; // Too many witnesses. |
1471 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
1472 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
1472 if (Dependencies::is_concrete_method(m)) { |
1473 if (Dependencies::is_concrete_method(m, ctxk)) { |
1473 if (fm == NULL) { |
1474 if (fm == NULL) { |
1474 // It turns out that m was always the only implementation. |
1475 // It turns out that m was always the only implementation. |
1475 fm = m; |
1476 fm = m; |
1476 } else if (fm != m) { |
1477 } else if (fm != m) { |
1477 // Two conflicting implementations after all. |
1478 // Two conflicting implementations after all. |
1497 wf.add_participant(m1->method_holder()); |
1498 wf.add_participant(m1->method_holder()); |
1498 wf.add_participant(m2->method_holder()); |
1499 wf.add_participant(m2->method_holder()); |
1499 return wf.find_witness_definer(ctxk, changes); |
1500 return wf.find_witness_definer(ctxk, changes); |
1500 } |
1501 } |
1501 |
1502 |
1502 // Find the set of all non-abstract methods under ctxk that match m[0]. |
|
1503 // (The method m[0] must be defined or inherited in ctxk.) |
|
1504 // Include m itself in the set, unless it is abstract. |
|
1505 // Fill the given array m[0..(mlen-1)] with this set, and return the length. |
|
1506 // (The length may be zero if no concrete methods are found anywhere.) |
|
1507 // If there are too many concrete methods to fit in marray, return -1. |
|
1508 int Dependencies::find_exclusive_concrete_methods(Klass* ctxk, |
|
1509 int mlen, |
|
1510 Method* marray[]) { |
|
1511 Method* m0 = marray[0]; |
|
1512 ClassHierarchyWalker wf(m0); |
|
1513 assert(wf.check_method_context(ctxk, m0), "proper context"); |
|
1514 wf.record_witnesses(mlen); |
|
1515 bool participants_hide_witnesses = true; |
|
1516 Klass* wit = wf.find_witness_definer(ctxk); |
|
1517 if (wit != NULL) return -1; // Too many witnesses. |
|
1518 int num = wf.num_participants(); |
|
1519 assert(num <= mlen, "oob"); |
|
1520 // Keep track of whether m is also part of the result set. |
|
1521 int mfill = 0; |
|
1522 assert(marray[mfill] == m0, "sanity"); |
|
1523 if (Dependencies::is_concrete_method(m0)) |
|
1524 mfill++; // keep m0 as marray[0], the first result |
|
1525 for (int i = 0; i < num; i++) { |
|
1526 Method* fm = wf.found_method(i); |
|
1527 if (fm == m0) continue; // Already put this guy in the list. |
|
1528 if (mfill == mlen) { |
|
1529 return -1; // Oops. Too many methods after all! |
|
1530 } |
|
1531 marray[mfill++] = fm; |
|
1532 } |
|
1533 #ifndef PRODUCT |
|
1534 // Make sure the dependency mechanism will pass this discovery: |
|
1535 if (VerifyDependencies) { |
|
1536 // Turn off dependency tracing while actually testing deps. |
|
1537 FlagSetting fs(TraceDependencies, false); |
|
1538 switch (mfill) { |
|
1539 case 1: |
|
1540 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]), |
|
1541 "verify dep."); |
|
1542 break; |
|
1543 case 2: |
|
1544 guarantee(NULL == (void *) |
|
1545 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]), |
|
1546 "verify dep."); |
|
1547 break; |
|
1548 default: |
|
1549 ShouldNotReachHere(); // mlen > 2 yet supported |
|
1550 } |
|
1551 } |
|
1552 #endif //PRODUCT |
|
1553 return mfill; |
|
1554 } |
|
1555 |
|
1556 |
|
1557 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
1503 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
1558 Klass* search_at = ctxk; |
1504 Klass* search_at = ctxk; |
1559 if (changes != NULL) |
1505 if (changes != NULL) |
1560 search_at = changes->new_type(); // just look at the new bit |
1506 search_at = changes->new_type(); // just look at the new bit |
1561 return find_finalizable_subclass(search_at); |
1507 return find_finalizable_subclass(search_at); |
1562 } |
1508 } |
1563 |
|
1564 |
1509 |
1565 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
1510 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
1566 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
1511 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
1567 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
1512 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
1568 if (changes == NULL) { |
1513 if (changes == NULL) { |