Mercurial > hg > truffle
comparison src/share/vm/code/dependencies.cpp @ 20785:9906d432d6db jdk8u31-b11
8064524: Compiler code generation improvements
Reviewed-by: jrose, acorn, vlivanov
author | drchase |
---|---|
date | Mon, 01 Dec 2014 13:06:20 -0500 |
parents | 51e1bb81df86 |
children | c4f1e23c4139 |
comparison
equal
deleted
inserted
replaced
20784:b3a8626eefc5 | 20785:9906d432d6db |
---|---|
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. |
542 assert(arg.is_metadata(), "must be"); | 542 assert(arg.is_metadata(), "must be"); |
543 what = "context"; | 543 what = "context"; |
544 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); | 544 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); |
545 } else if (arg.is_method()) { | 545 } else if (arg.is_method()) { |
546 what = "method "; | 546 what = "method "; |
547 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value()); | 547 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value(), NULL); |
548 } else if (arg.is_klass()) { | 548 } else if (arg.is_klass()) { |
549 what = "class "; | 549 what = "class "; |
550 } else { | 550 } else { |
551 what = "object "; | 551 what = "object "; |
552 } | 552 } |
824 } | 824 } |
825 if (lm->is_static()) { | 825 if (lm->is_static()) { |
826 // Static methods don't override non-static so punt | 826 // Static methods don't override non-static so punt |
827 return true; | 827 return true; |
828 } | 828 } |
829 if ( !Dependencies::is_concrete_method(lm) | 829 if ( !Dependencies::is_concrete_method(lm, k) |
830 && !Dependencies::is_concrete_method(m) | 830 && !Dependencies::is_concrete_method(m, ctxk) |
831 && lm->method_holder()->is_subtype_of(m->method_holder())) | 831 && lm->method_holder()->is_subtype_of(m->method_holder())) |
832 // Method m is overridden by lm, but both are non-concrete. | 832 // Method m is overridden by lm, but both are non-concrete. |
833 return true; | 833 return true; |
834 } | 834 } |
835 ResourceMark rm; | 835 ResourceMark rm; |
859 | 859 |
860 bool is_witness(Klass* k) { | 860 bool is_witness(Klass* k) { |
861 if (doing_subtype_search()) { | 861 if (doing_subtype_search()) { |
862 return Dependencies::is_concrete_klass(k); | 862 return Dependencies::is_concrete_klass(k); |
863 } else { | 863 } else { |
864 Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); | 864 // Search class hierarchy first. |
865 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; | 865 Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature); |
866 if (!Dependencies::is_concrete_method(m, k)) { | |
867 // Check interface defaults also, if any exist. | |
868 Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods(); | |
869 if (default_methods == NULL) | |
870 return false; | |
871 m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature); | |
872 if (!Dependencies::is_concrete_method(m, NULL)) | |
873 return false; | |
874 } | |
866 _found_methods[_num_participants] = m; | 875 _found_methods[_num_participants] = m; |
867 // Note: If add_participant(k) is called, | 876 // Note: If add_participant(k) is called, |
868 // the method m will already be memoized for it. | 877 // the method m will already be memoized for it. |
869 return true; | 878 return true; |
870 } | 879 } |
1151 // This would require a deoptimization barrier on first instantiation. | 1160 // This would require a deoptimization barrier on first instantiation. |
1152 //if (k->is_not_instantiated()) return false; | 1161 //if (k->is_not_instantiated()) return false; |
1153 return true; | 1162 return true; |
1154 } | 1163 } |
1155 | 1164 |
1156 bool Dependencies::is_concrete_method(Method* m) { | 1165 bool Dependencies::is_concrete_method(Method* m, Klass * k) { |
1157 // Statics are irrelevant to virtual call sites. | 1166 // NULL is not a concrete method, |
1158 if (m->is_static()) return false; | 1167 // statics are irrelevant to virtual call sites, |
1159 | 1168 // abstract methods are not concrete, |
1160 // We could also return false if m does not yet appear to be | 1169 // overpass (error) methods are not concrete if k is abstract |
1161 // executed, if the VM version supports this distinction also. | 1170 // |
1162 // Default methods are considered "concrete" as well. | 1171 // note "true" is conservative answer -- |
1163 return !m->is_abstract() && | 1172 // overpass clause is false if k == NULL, implies return true if |
1164 !m->is_overpass(); // error functions aren't concrete | 1173 // answer depends on overpass clause. |
1174 return ! ( m == NULL || m -> is_static() || m -> is_abstract() || | |
1175 m->is_overpass() && k != NULL && k -> is_abstract() ); | |
1165 } | 1176 } |
1166 | 1177 |
1167 | 1178 |
1168 Klass* Dependencies::find_finalizable_subclass(Klass* k) { | 1179 Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
1169 if (k->is_interface()) return NULL; | 1180 if (k->is_interface()) return NULL; |
1183 // We could also return false if k does not yet appear to be | 1194 // We could also return false if k does not yet appear to be |
1184 // instantiated, if the VM version supports this distinction also. | 1195 // instantiated, if the VM version supports this distinction also. |
1185 //if (k->is_not_instantiated()) return false; | 1196 //if (k->is_not_instantiated()) return false; |
1186 return true; | 1197 return true; |
1187 } | 1198 } |
1188 | |
1189 bool Dependencies::is_concrete_method(ciMethod* m) { | |
1190 // Statics are irrelevant to virtual call sites. | |
1191 if (m->is_static()) return false; | |
1192 | |
1193 // We could also return false if m does not yet appear to be | |
1194 // executed, if the VM version supports this distinction also. | |
1195 return !m->is_abstract(); | |
1196 } | |
1197 | |
1198 | 1199 |
1199 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { | 1200 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
1200 return k->has_finalizable_subclass(); | 1201 return k->has_finalizable_subclass(); |
1201 } | 1202 } |
1202 | 1203 |
1407 assert(wf.check_method_context(ctxk, m), "proper context"); | 1408 assert(wf.check_method_context(ctxk, m), "proper context"); |
1408 wf.record_witnesses(1); | 1409 wf.record_witnesses(1); |
1409 Klass* wit = wf.find_witness_definer(ctxk); | 1410 Klass* wit = wf.find_witness_definer(ctxk); |
1410 if (wit != NULL) return NULL; // Too many witnesses. | 1411 if (wit != NULL) return NULL; // Too many witnesses. |
1411 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. | 1412 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
1412 if (Dependencies::is_concrete_method(m)) { | 1413 if (Dependencies::is_concrete_method(m, ctxk)) { |
1413 if (fm == NULL) { | 1414 if (fm == NULL) { |
1414 // It turns out that m was always the only implementation. | 1415 // It turns out that m was always the only implementation. |
1415 fm = m; | 1416 fm = m; |
1416 } else if (fm != m) { | 1417 } else if (fm != m) { |
1417 // Two conflicting implementations after all. | 1418 // Two conflicting implementations after all. |
1437 wf.add_participant(m1->method_holder()); | 1438 wf.add_participant(m1->method_holder()); |
1438 wf.add_participant(m2->method_holder()); | 1439 wf.add_participant(m2->method_holder()); |
1439 return wf.find_witness_definer(ctxk, changes); | 1440 return wf.find_witness_definer(ctxk, changes); |
1440 } | 1441 } |
1441 | 1442 |
1442 // Find the set of all non-abstract methods under ctxk that match m[0]. | |
1443 // (The method m[0] must be defined or inherited in ctxk.) | |
1444 // Include m itself in the set, unless it is abstract. | |
1445 // Fill the given array m[0..(mlen-1)] with this set, and return the length. | |
1446 // (The length may be zero if no concrete methods are found anywhere.) | |
1447 // If there are too many concrete methods to fit in marray, return -1. | |
1448 int Dependencies::find_exclusive_concrete_methods(Klass* ctxk, | |
1449 int mlen, | |
1450 Method* marray[]) { | |
1451 Method* m0 = marray[0]; | |
1452 ClassHierarchyWalker wf(m0); | |
1453 assert(wf.check_method_context(ctxk, m0), "proper context"); | |
1454 wf.record_witnesses(mlen); | |
1455 bool participants_hide_witnesses = true; | |
1456 Klass* wit = wf.find_witness_definer(ctxk); | |
1457 if (wit != NULL) return -1; // Too many witnesses. | |
1458 int num = wf.num_participants(); | |
1459 assert(num <= mlen, "oob"); | |
1460 // Keep track of whether m is also part of the result set. | |
1461 int mfill = 0; | |
1462 assert(marray[mfill] == m0, "sanity"); | |
1463 if (Dependencies::is_concrete_method(m0)) | |
1464 mfill++; // keep m0 as marray[0], the first result | |
1465 for (int i = 0; i < num; i++) { | |
1466 Method* fm = wf.found_method(i); | |
1467 if (fm == m0) continue; // Already put this guy in the list. | |
1468 if (mfill == mlen) { | |
1469 return -1; // Oops. Too many methods after all! | |
1470 } | |
1471 marray[mfill++] = fm; | |
1472 } | |
1473 #ifndef PRODUCT | |
1474 // Make sure the dependency mechanism will pass this discovery: | |
1475 if (VerifyDependencies) { | |
1476 // Turn off dependency tracing while actually testing deps. | |
1477 FlagSetting fs(TraceDependencies, false); | |
1478 switch (mfill) { | |
1479 case 1: | |
1480 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]), | |
1481 "verify dep."); | |
1482 break; | |
1483 case 2: | |
1484 guarantee(NULL == (void *) | |
1485 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]), | |
1486 "verify dep."); | |
1487 break; | |
1488 default: | |
1489 ShouldNotReachHere(); // mlen > 2 yet supported | |
1490 } | |
1491 } | |
1492 #endif //PRODUCT | |
1493 return mfill; | |
1494 } | |
1495 | |
1496 | |
1497 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { | 1443 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
1498 Klass* search_at = ctxk; | 1444 Klass* search_at = ctxk; |
1499 if (changes != NULL) | 1445 if (changes != NULL) |
1500 search_at = changes->new_type(); // just look at the new bit | 1446 search_at = changes->new_type(); // just look at the new bit |
1501 return find_finalizable_subclass(search_at); | 1447 return find_finalizable_subclass(search_at); |
1502 } | 1448 } |
1503 | |
1504 | 1449 |
1505 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { | 1450 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
1506 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); | 1451 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
1507 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); | 1452 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
1508 if (changes == NULL) { | 1453 if (changes == NULL) { |