comparison src/share/vm/code/dependencies.cpp @ 20788:c4f1e23c4139

Merge
author asaha
date Tue, 16 Dec 2014 14:02:00 -0800
parents bee8095780db 9906d432d6db
children 7848fc12602b 7622232b7efa dc2f15e0caee
comparison
equal deleted inserted replaced
20783:4b41145051ab 20788:c4f1e23c4139
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.
558 assert(arg.is_metadata(), "must be"); 558 assert(arg.is_metadata(), "must be");
559 what = "context"; 559 what = "context";
560 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); 560 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value());
561 } else if (arg.is_method()) { 561 } else if (arg.is_method()) {
562 what = "method "; 562 what = "method ";
563 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value()); 563 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value(), NULL);
564 } else if (arg.is_klass()) { 564 } else if (arg.is_klass()) {
565 what = "class "; 565 what = "class ";
566 } else { 566 } else {
567 what = "object "; 567 what = "object ";
568 } 568 }
843 } 843 }
844 if (lm->is_static()) { 844 if (lm->is_static()) {
845 // Static methods don't override non-static so punt 845 // Static methods don't override non-static so punt
846 return true; 846 return true;
847 } 847 }
848 if ( !Dependencies::is_concrete_method(lm) 848 if ( !Dependencies::is_concrete_method(lm, k)
849 && !Dependencies::is_concrete_method(m) 849 && !Dependencies::is_concrete_method(m, ctxk)
850 && lm->method_holder()->is_subtype_of(m->method_holder())) 850 && lm->method_holder()->is_subtype_of(m->method_holder()))
851 // Method m is overridden by lm, but both are non-concrete. 851 // Method m is overridden by lm, but both are non-concrete.
852 return true; 852 return true;
853 } 853 }
854 ResourceMark rm; 854 ResourceMark rm;
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 if (!k->oop_is_instance()) { 882 } else if (!k->oop_is_instance()) {
883 return false; // no methods to find in an array type 883 return false; // no methods to find in an array type
884 } else { 884 } else {
885 Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); 885 // Search class hierarchy first.
886 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; 886 Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature);
887 if (!Dependencies::is_concrete_method(m, k)) {
888 // Check interface defaults also, if any exist.
889 Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods();
890 if (default_methods == NULL)
891 return false;
892 m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature);
893 if (!Dependencies::is_concrete_method(m, NULL))
894 return false;
895 }
887 _found_methods[_num_participants] = m; 896 _found_methods[_num_participants] = m;
888 // Note: If add_participant(k) is called, 897 // Note: If add_participant(k) is called,
889 // the method m will already be memoized for it. 898 // the method m will already be memoized for it.
890 return true; 899 return true;
891 } 900 }
1174 // This would require a deoptimization barrier on first instantiation. 1183 // This would require a deoptimization barrier on first instantiation.
1175 //if (k->is_not_instantiated()) return false; 1184 //if (k->is_not_instantiated()) return false;
1176 return true; 1185 return true;
1177 } 1186 }
1178 1187
1179 bool Dependencies::is_concrete_method(Method* m) { 1188 bool Dependencies::is_concrete_method(Method* m, Klass * k) {
1180 // Statics are irrelevant to virtual call sites. 1189 // NULL is not a concrete method,
1181 if (m->is_static()) return false; 1190 // statics are irrelevant to virtual call sites,
1182 1191 // abstract methods are not concrete,
1183 // We could also return false if m does not yet appear to be 1192 // overpass (error) methods are not concrete if k is abstract
1184 // executed, if the VM version supports this distinction also. 1193 //
1185 // Default methods are considered "concrete" as well. 1194 // note "true" is conservative answer --
1186 return !m->is_abstract() && 1195 // overpass clause is false if k == NULL, implies return true if
1187 !m->is_overpass(); // error functions aren't concrete 1196 // answer depends on overpass clause.
1197 return ! ( m == NULL || m -> is_static() || m -> is_abstract() ||
1198 m->is_overpass() && k != NULL && k -> is_abstract() );
1188 } 1199 }
1189 1200
1190 1201
1191 Klass* Dependencies::find_finalizable_subclass(Klass* k) { 1202 Klass* Dependencies::find_finalizable_subclass(Klass* k) {
1192 if (k->is_interface()) return NULL; 1203 if (k->is_interface()) return NULL;
1206 // We could also return false if k does not yet appear to be 1217 // We could also return false if k does not yet appear to be
1207 // instantiated, if the VM version supports this distinction also. 1218 // instantiated, if the VM version supports this distinction also.
1208 //if (k->is_not_instantiated()) return false; 1219 //if (k->is_not_instantiated()) return false;
1209 return true; 1220 return true;
1210 } 1221 }
1211
1212 bool Dependencies::is_concrete_method(ciMethod* m) {
1213 // Statics are irrelevant to virtual call sites.
1214 if (m->is_static()) return false;
1215
1216 // We could also return false if m does not yet appear to be
1217 // executed, if the VM version supports this distinction also.
1218 return !m->is_abstract();
1219 }
1220
1221 1222
1222 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { 1223 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) {
1223 return k->has_finalizable_subclass(); 1224 return k->has_finalizable_subclass();
1224 } 1225 }
1225 1226
1430 assert(wf.check_method_context(ctxk, m), "proper context"); 1431 assert(wf.check_method_context(ctxk, m), "proper context");
1431 wf.record_witnesses(1); 1432 wf.record_witnesses(1);
1432 Klass* wit = wf.find_witness_definer(ctxk); 1433 Klass* wit = wf.find_witness_definer(ctxk);
1433 if (wit != NULL) return NULL; // Too many witnesses. 1434 if (wit != NULL) return NULL; // Too many witnesses.
1434 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. 1435 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0.
1435 if (Dependencies::is_concrete_method(m)) { 1436 if (Dependencies::is_concrete_method(m, ctxk)) {
1436 if (fm == NULL) { 1437 if (fm == NULL) {
1437 // It turns out that m was always the only implementation. 1438 // It turns out that m was always the only implementation.
1438 fm = m; 1439 fm = m;
1439 } else if (fm != m) { 1440 } else if (fm != m) {
1440 // Two conflicting implementations after all. 1441 // Two conflicting implementations after all.
1460 wf.add_participant(m1->method_holder()); 1461 wf.add_participant(m1->method_holder());
1461 wf.add_participant(m2->method_holder()); 1462 wf.add_participant(m2->method_holder());
1462 return wf.find_witness_definer(ctxk, changes); 1463 return wf.find_witness_definer(ctxk, changes);
1463 } 1464 }
1464 1465
1465 // Find the set of all non-abstract methods under ctxk that match m[0].
1466 // (The method m[0] must be defined or inherited in ctxk.)
1467 // Include m itself in the set, unless it is abstract.
1468 // Fill the given array m[0..(mlen-1)] with this set, and return the length.
1469 // (The length may be zero if no concrete methods are found anywhere.)
1470 // If there are too many concrete methods to fit in marray, return -1.
1471 int Dependencies::find_exclusive_concrete_methods(Klass* ctxk,
1472 int mlen,
1473 Method* marray[]) {
1474 Method* m0 = marray[0];
1475 ClassHierarchyWalker wf(m0);
1476 assert(wf.check_method_context(ctxk, m0), "proper context");
1477 wf.record_witnesses(mlen);
1478 bool participants_hide_witnesses = true;
1479 Klass* wit = wf.find_witness_definer(ctxk);
1480 if (wit != NULL) return -1; // Too many witnesses.
1481 int num = wf.num_participants();
1482 assert(num <= mlen, "oob");
1483 // Keep track of whether m is also part of the result set.
1484 int mfill = 0;
1485 assert(marray[mfill] == m0, "sanity");
1486 if (Dependencies::is_concrete_method(m0))
1487 mfill++; // keep m0 as marray[0], the first result
1488 for (int i = 0; i < num; i++) {
1489 Method* fm = wf.found_method(i);
1490 if (fm == m0) continue; // Already put this guy in the list.
1491 if (mfill == mlen) {
1492 return -1; // Oops. Too many methods after all!
1493 }
1494 marray[mfill++] = fm;
1495 }
1496 #ifndef PRODUCT
1497 // Make sure the dependency mechanism will pass this discovery:
1498 if (VerifyDependencies) {
1499 // Turn off dependency tracing while actually testing deps.
1500 FlagSetting fs(TraceDependencies, false);
1501 switch (mfill) {
1502 case 1:
1503 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]),
1504 "verify dep.");
1505 break;
1506 case 2:
1507 guarantee(NULL == (void *)
1508 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]),
1509 "verify dep.");
1510 break;
1511 default:
1512 ShouldNotReachHere(); // mlen > 2 yet supported
1513 }
1514 }
1515 #endif //PRODUCT
1516 return mfill;
1517 }
1518
1519
1520 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { 1466 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) {
1521 Klass* search_at = ctxk; 1467 Klass* search_at = ctxk;
1522 if (changes != NULL) 1468 if (changes != NULL)
1523 search_at = changes->new_type(); // just look at the new bit 1469 search_at = changes->new_type(); // just look at the new bit
1524 return find_finalizable_subclass(search_at); 1470 return find_finalizable_subclass(search_at);
1525 } 1471 }
1526
1527 1472
1528 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { 1473 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) {
1529 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); 1474 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity");
1530 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); 1475 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity");
1531 if (changes == NULL) { 1476 if (changes == NULL) {