comparison src/share/vm/code/dependencies.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents dd8989d5547f c4f1e23c4139
children 91d70d102132
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
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.
31 #include "compiler/compileLog.hpp" 31 #include "compiler/compileLog.hpp"
32 #include "oops/oop.inline.hpp" 32 #include "oops/oop.inline.hpp"
33 #include "oops/objArrayKlass.hpp" 33 #include "oops/objArrayKlass.hpp"
34 #include "runtime/handles.hpp" 34 #include "runtime/handles.hpp"
35 #include "runtime/handles.inline.hpp" 35 #include "runtime/handles.inline.hpp"
36 #include "runtime/thread.inline.hpp"
36 #include "utilities/copy.hpp" 37 #include "utilities/copy.hpp"
37 38
38 39
39 #ifdef ASSERT 40 #ifdef ASSERT
40 static bool must_be_in_vm() { 41 static bool must_be_in_vm() {
616 } 617 }
617 618
618 // for the sake of the compiler log, print out current dependencies: 619 // for the sake of the compiler log, print out current dependencies:
619 void Dependencies::log_all_dependencies() { 620 void Dependencies::log_all_dependencies() {
620 if (log() == NULL) return; 621 if (log() == NULL) return;
621 ciBaseObject* args[max_arg_count]; 622 ResourceMark rm;
622 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { 623 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
623 DepType dept = (DepType)deptv; 624 DepType dept = (DepType)deptv;
624 GrowableArray<ciBaseObject*>* deps = _deps[dept]; 625 GrowableArray<ciBaseObject*>* deps = _deps[dept];
625 if (deps->length() == 0) continue; 626 int deplen = deps->length();
627 if (deplen == 0) {
628 continue;
629 }
626 int stride = dep_args(dept); 630 int stride = dep_args(dept);
631 GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride);
627 for (int i = 0; i < deps->length(); i += stride) { 632 for (int i = 0; i < deps->length(); i += stride) {
628 for (int j = 0; j < stride; j++) { 633 for (int j = 0; j < stride; j++) {
629 // flush out the identities before printing 634 // flush out the identities before printing
630 args[j] = deps->at(i+j); 635 ciargs->push(deps->at(i+j));
631 } 636 }
632 write_dependency_to(log(), dept, stride, args); 637 write_dependency_to(log(), dept, ciargs);
633 } 638 ciargs->clear();
639 }
640 guarantee(deplen == deps->length(), "deps array cannot grow inside nested ResoureMark scope");
634 } 641 }
635 } 642 }
636 643
637 void Dependencies::write_dependency_to(CompileLog* log, 644 void Dependencies::write_dependency_to(CompileLog* log,
638 DepType dept, 645 DepType dept,
639 int nargs, DepArgument args[], 646 GrowableArray<DepArgument>* args,
640 Klass* witness) { 647 Klass* witness) {
641 if (log == NULL) { 648 if (log == NULL) {
642 return; 649 return;
643 } 650 }
651 ResourceMark rm;
644 ciEnv* env = ciEnv::current(); 652 ciEnv* env = ciEnv::current();
645 ciBaseObject* ciargs[max_arg_count]; 653 GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(args->length());
646 assert(nargs <= max_arg_count, "oob"); 654 for (GrowableArrayIterator<DepArgument> it = args->begin(); it != args->end(); ++it) {
647 for (int j = 0; j < nargs; j++) { 655 DepArgument arg = *it;
648 if (args[j].is_oop()) { 656 if (arg.is_oop()) {
649 ciargs[j] = env->get_object(args[j].oop_value()); 657 ciargs->push(env->get_object(arg.oop_value()));
650 } else { 658 } else {
651 ciargs[j] = env->get_metadata(args[j].metadata_value()); 659 ciargs->push(env->get_metadata(arg.metadata_value()));
652 } 660 }
653 } 661 }
654 Dependencies::write_dependency_to(log, dept, nargs, ciargs, witness); 662 int argslen = ciargs->length();
663 Dependencies::write_dependency_to(log, dept, ciargs, witness);
664 guarantee(argslen == ciargs->length(), "ciargs array cannot grow inside nested ResoureMark scope");
655 } 665 }
656 666
657 void Dependencies::write_dependency_to(CompileLog* log, 667 void Dependencies::write_dependency_to(CompileLog* log,
658 DepType dept, 668 DepType dept,
659 int nargs, ciBaseObject* args[], 669 GrowableArray<ciBaseObject*>* args,
660 Klass* witness) { 670 Klass* witness) {
661 if (log == NULL) return; 671 if (log == NULL) {
662 assert(nargs <= max_arg_count, "oob"); 672 return;
663 int argids[max_arg_count]; 673 }
664 int ctxkj = dep_context_arg(dept); // -1 if no context arg 674 ResourceMark rm;
665 int j; 675 GrowableArray<int>* argids = new GrowableArray<int>(args->length());
666 for (j = 0; j < nargs; j++) { 676 for (GrowableArrayIterator<ciBaseObject*> it = args->begin(); it != args->end(); ++it) {
667 if (args[j]->is_object()) { 677 ciBaseObject* obj = *it;
668 argids[j] = log->identify(args[j]->as_object()); 678 if (obj->is_object()) {
679 argids->push(log->identify(obj->as_object()));
669 } else { 680 } else {
670 argids[j] = log->identify(args[j]->as_metadata()); 681 argids->push(log->identify(obj->as_metadata()));
671 } 682 }
672 } 683 }
673 if (witness != NULL) { 684 if (witness != NULL) {
674 log->begin_elem("dependency_failed"); 685 log->begin_elem("dependency_failed");
675 } else { 686 } else {
676 log->begin_elem("dependency"); 687 log->begin_elem("dependency");
677 } 688 }
678 log->print(" type='%s'", dep_name(dept)); 689 log->print(" type='%s'", dep_name(dept));
679 if (ctxkj >= 0) { 690 const int ctxkj = dep_context_arg(dept); // -1 if no context arg
680 log->print(" ctxk='%d'", argids[ctxkj]); 691 if (ctxkj >= 0 && ctxkj < argids->length()) {
692 log->print(" ctxk='%d'", argids->at(ctxkj));
681 } 693 }
682 // write remaining arguments, if any. 694 // write remaining arguments, if any.
683 for (j = 0; j < nargs; j++) { 695 for (int j = 0; j < argids->length(); j++) {
684 if (j == ctxkj) continue; // already logged 696 if (j == ctxkj) continue; // already logged
685 if (j == 1) { 697 if (j == 1) {
686 log->print( " x='%d'", argids[j]); 698 log->print( " x='%d'", argids->at(j));
687 } else { 699 } else {
688 log->print(" x%d='%d'", j, argids[j]); 700 log->print(" x%d='%d'", j, argids->at(j));
689 } 701 }
690 } 702 }
691 if (witness != NULL) { 703 if (witness != NULL) {
692 log->object("witness", witness); 704 log->object("witness", witness);
693 log->stamp(); 705 log->stamp();
695 log->end_elem(); 707 log->end_elem();
696 } 708 }
697 709
698 void Dependencies::write_dependency_to(xmlStream* xtty, 710 void Dependencies::write_dependency_to(xmlStream* xtty,
699 DepType dept, 711 DepType dept,
700 int nargs, DepArgument args[], 712 GrowableArray<DepArgument>* args,
701 Klass* witness) { 713 Klass* witness) {
702 if (xtty == NULL) return; 714 if (xtty == NULL) {
715 return;
716 }
717 ResourceMark rm;
703 ttyLocker ttyl; 718 ttyLocker ttyl;
704 int ctxkj = dep_context_arg(dept); // -1 if no context arg 719 int ctxkj = dep_context_arg(dept); // -1 if no context arg
705 if (witness != NULL) { 720 if (witness != NULL) {
706 xtty->begin_elem("dependency_failed"); 721 xtty->begin_elem("dependency_failed");
707 } else { 722 } else {
708 xtty->begin_elem("dependency"); 723 xtty->begin_elem("dependency");
709 } 724 }
710 xtty->print(" type='%s'", dep_name(dept)); 725 xtty->print(" type='%s'", dep_name(dept));
711 if (ctxkj >= 0) { 726 if (ctxkj >= 0) {
712 xtty->object("ctxk", args[ctxkj].metadata_value()); 727 xtty->object("ctxk", args->at(ctxkj).metadata_value());
713 } 728 }
714 // write remaining arguments, if any. 729 // write remaining arguments, if any.
715 for (int j = 0; j < nargs; j++) { 730 for (int j = 0; j < args->length(); j++) {
716 if (j == ctxkj) continue; // already logged 731 if (j == ctxkj) continue; // already logged
732 DepArgument arg = args->at(j);
717 if (j == 1) { 733 if (j == 1) {
718 if (args[j].is_oop()) { 734 if (arg.is_oop()) {
719 xtty->object("x", args[j].oop_value()); 735 xtty->object("x", arg.oop_value());
720 } else { 736 } else {
721 xtty->object("x", args[j].metadata_value()); 737 xtty->object("x", arg.metadata_value());
722 } 738 }
723 } else { 739 } else {
724 char xn[10]; sprintf(xn, "x%d", j); 740 char xn[10]; sprintf(xn, "x%d", j);
725 if (args[j].is_oop()) { 741 if (arg.is_oop()) {
726 xtty->object(xn, args[j].oop_value()); 742 xtty->object(xn, arg.oop_value());
727 } else { 743 } else {
728 xtty->object(xn, args[j].metadata_value()); 744 xtty->object(xn, arg.metadata_value());
729 } 745 }
730 } 746 }
731 } 747 }
732 if (witness != NULL) { 748 if (witness != NULL) {
733 xtty->object("witness", witness); 749 xtty->object("witness", witness);
734 xtty->stamp(); 750 xtty->stamp();
735 } 751 }
736 xtty->end_elem(); 752 xtty->end_elem();
737 } 753 }
738 754
739 void Dependencies::print_dependency(DepType dept, int nargs, DepArgument args[], 755 void Dependencies::print_dependency(DepType dept, GrowableArray<DepArgument>* args,
740 Klass* witness, outputStream* st) { 756 Klass* witness, outputStream* st) {
741 ResourceMark rm; 757 ResourceMark rm;
742 ttyLocker ttyl; // keep the following output all in one block 758 ttyLocker ttyl; // keep the following output all in one block
743 st->print_cr("%s of type %s", 759 st->print_cr("%s of type %s",
744 (witness == NULL)? "Dependency": "Failed dependency", 760 (witness == NULL)? "Dependency": "Failed dependency",
745 dep_name(dept)); 761 dep_name(dept));
746 // print arguments 762 // print arguments
747 int ctxkj = dep_context_arg(dept); // -1 if no context arg 763 int ctxkj = dep_context_arg(dept); // -1 if no context arg
748 for (int j = 0; j < nargs; j++) { 764 for (int j = 0; j < args->length(); j++) {
749 DepArgument arg = args[j]; 765 DepArgument arg = args->at(j);
750 bool put_star = false; 766 bool put_star = false;
751 if (arg.is_null()) continue; 767 if (arg.is_null()) continue;
752 const char* what; 768 const char* what;
753 if (j == ctxkj) { 769 if (j == ctxkj) {
754 assert(arg.is_metadata(), "must be"); 770 assert(arg.is_metadata(), "must be");
755 what = "context"; 771 what = "context";
756 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); 772 put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value());
757 } else if (arg.is_method()) { 773 } else if (arg.is_method()) {
758 what = "method "; 774 what = "method ";
759 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value()); 775 put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value(), NULL);
760 } else if (arg.is_klass()) { 776 } else if (arg.is_klass()) {
761 what = "class "; 777 what = "class ";
762 } else { 778 } else {
763 what = "object "; 779 what = "object ";
764 } 780 }
780 } 796 }
781 797
782 void Dependencies::DepStream::log_dependency(Klass* witness) { 798 void Dependencies::DepStream::log_dependency(Klass* witness) {
783 if (_deps == NULL && xtty == NULL) return; // fast cutout for runtime 799 if (_deps == NULL && xtty == NULL) return; // fast cutout for runtime
784 ResourceMark rm; 800 ResourceMark rm;
785 int nargs = argument_count(); 801 const int nargs = argument_count();
786 DepArgument args[max_arg_count]; 802 GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs);
787 for (int j = 0; j < nargs; j++) { 803 for (int j = 0; j < nargs; j++) {
788 if (type() == call_site_target_value) { 804 if (type() == call_site_target_value) {
789 args[j] = argument_oop(j); 805 args->push(argument_oop(j));
790 } else { 806 } else {
791 args[j] = argument(j); 807 args->push(argument(j));
792 } 808 }
793 } 809 }
810 int argslen = args->length();
794 if (_deps != NULL && _deps->log() != NULL) { 811 if (_deps != NULL && _deps->log() != NULL) {
795 if (ciEnv::current() != NULL) { 812 if (ciEnv::current() != NULL) {
796 Dependencies::write_dependency_to(_deps->log(), 813 Dependencies::write_dependency_to(_deps->log(),
797 type(), nargs, args, witness); 814 type(), args, witness);
798 } else { 815 } else {
799 // Treat the CompileLog as an xmlstream instead 816 // Treat the CompileLog as an xmlstream instead
800 Dependencies::write_dependency_to((xmlStream*)_deps->log(), 817 Dependencies::write_dependency_to((xmlStream*)_deps->log(),
801 type(), nargs, args, witness); 818 type(), args, witness);
802 } 819 }
803 } else { 820 } else {
804 Dependencies::write_dependency_to(xtty, 821 Dependencies::write_dependency_to(xtty, type(), args, witness);
805 type(), nargs, args, witness); 822 }
806 } 823 guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope");
807 } 824 }
808 825
809 void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose, outputStream* st) { 826 void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose, outputStream* st) {
810 int nargs = argument_count(); 827 int nargs = argument_count();
811 DepArgument args[max_arg_count]; 828 GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs);
812 for (int j = 0; j < nargs; j++) { 829 for (int j = 0; j < nargs; j++) {
813 args[j] = argument(j); 830 args->push(argument(j));
814 } 831 }
815 Dependencies::print_dependency(type(), nargs, args, witness, st); 832 int argslen = args->length();
833 Dependencies::print_dependency(type(), args, witness, st);
816 if (verbose) { 834 if (verbose) {
817 if (_code != NULL) { 835 if (_code != NULL) {
818 st->print(" code: "); 836 st->print(" code: ");
819 _code->print_value_on(st); 837 _code->print_value_on(st);
820 st->cr(); 838 st->cr();
821 } 839 }
822 } 840 }
841 guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope");
823 } 842 }
824 843
825 844
826 /// Dependency stream support (decodes dependencies from an nmethod): 845 /// Dependency stream support (decodes dependencies from an nmethod):
827 846
1042 } 1061 }
1043 if (lm->is_static()) { 1062 if (lm->is_static()) {
1044 // Static methods don't override non-static so punt 1063 // Static methods don't override non-static so punt
1045 return true; 1064 return true;
1046 } 1065 }
1047 if ( !Dependencies::is_concrete_method(lm) 1066 if ( !Dependencies::is_concrete_method(lm, k)
1048 && !Dependencies::is_concrete_method(m) 1067 && !Dependencies::is_concrete_method(m, ctxk)
1049 && lm->method_holder()->is_subtype_of(m->method_holder())) 1068 && lm->method_holder()->is_subtype_of(m->method_holder()))
1050 // Method m is overridden by lm, but both are non-concrete. 1069 // Method m is overridden by lm, but both are non-concrete.
1051 return true; 1070 return true;
1052 } 1071 }
1053 ResourceMark rm; 1072 ResourceMark rm;
1076 } 1095 }
1077 1096
1078 bool is_witness(Klass* k) { 1097 bool is_witness(Klass* k) {
1079 if (doing_subtype_search()) { 1098 if (doing_subtype_search()) {
1080 return Dependencies::is_concrete_klass(k); 1099 return Dependencies::is_concrete_klass(k);
1100 } else if (!k->oop_is_instance()) {
1101 return false; // no methods to find in an array type
1081 } else { 1102 } else {
1082 Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); 1103 // Search class hierarchy first.
1083 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; 1104 Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature);
1105 if (!Dependencies::is_concrete_method(m, k)) {
1106 // Check interface defaults also, if any exist.
1107 Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods();
1108 if (default_methods == NULL)
1109 return false;
1110 m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature);
1111 if (!Dependencies::is_concrete_method(m, NULL))
1112 return false;
1113 }
1084 _found_methods[_num_participants] = m; 1114 _found_methods[_num_participants] = m;
1085 // Note: If add_participant(k) is called, 1115 // Note: If add_participant(k) is called,
1086 // the method m will already be memoized for it. 1116 // the method m will already be memoized for it.
1087 return true; 1117 return true;
1088 } 1118 }
1282 Klass* chains[CHAINMAX]; 1312 Klass* chains[CHAINMAX];
1283 int chaini = 0; // index into worklist 1313 int chaini = 0; // index into worklist
1284 Klass* chain; // scratch variable 1314 Klass* chain; // scratch variable
1285 #define ADD_SUBCLASS_CHAIN(k) { \ 1315 #define ADD_SUBCLASS_CHAIN(k) { \
1286 assert(chaini < CHAINMAX, "oob"); \ 1316 assert(chaini < CHAINMAX, "oob"); \
1287 chain = InstanceKlass::cast(k)->subklass(); \ 1317 chain = k->subklass(); \
1288 if (chain != NULL) chains[chaini++] = chain; } 1318 if (chain != NULL) chains[chaini++] = chain; }
1289 1319
1290 // Look for non-abstract subclasses. 1320 // Look for non-abstract subclasses.
1291 // (Note: Interfaces do not have subclasses.) 1321 // (Note: Interfaces do not have subclasses.)
1292 ADD_SUBCLASS_CHAIN(context_type); 1322 ADD_SUBCLASS_CHAIN(context_type);
1293 1323
1294 // If it is an interface, search its direct implementors. 1324 // If it is an interface, search its direct implementors.
1295 // (Their subclasses are additional indirect implementors. 1325 // (Their subclasses are additional indirect implementors.
1296 // See InstanceKlass::add_implementor.) 1326 // See InstanceKlass::add_implementor.)
1297 // (Note: nof_implementors is always zero for non-interfaces.) 1327 // (Note: nof_implementors is always zero for non-interfaces.)
1298 int nof_impls = InstanceKlass::cast(context_type)->nof_implementors(); 1328 if (top_level_call) {
1299 if (nof_impls > 1) { 1329 int nof_impls = InstanceKlass::cast(context_type)->nof_implementors();
1300 // Avoid this case: *I.m > { A.m, C }; B.m > C 1330 if (nof_impls > 1) {
1301 // Here, I.m has 2 concrete implementations, but m appears unique 1331 // Avoid this case: *I.m > { A.m, C }; B.m > C
1302 // as A.m, because the search misses B.m when checking C. 1332 // Here, I.m has 2 concrete implementations, but m appears unique
1303 // The inherited method B.m was getting missed by the walker 1333 // as A.m, because the search misses B.m when checking C.
1304 // when interface 'I' was the starting point. 1334 // The inherited method B.m was getting missed by the walker
1305 // %%% Until this is fixed more systematically, bail out. 1335 // when interface 'I' was the starting point.
1306 // (Old CHA had the same limitation.) 1336 // %%% Until this is fixed more systematically, bail out.
1307 return context_type; 1337 // (Old CHA had the same limitation.)
1308 } 1338 return context_type;
1309 if (nof_impls > 0) { 1339 }
1310 Klass* impl = InstanceKlass::cast(context_type)->implementor(); 1340 if (nof_impls > 0) {
1311 assert(impl != NULL, "just checking"); 1341 Klass* impl = InstanceKlass::cast(context_type)->implementor();
1312 // If impl is the same as the context_type, then more than one 1342 assert(impl != NULL, "just checking");
1313 // implementor has seen. No exact info in this case. 1343 // If impl is the same as the context_type, then more than one
1314 if (impl == context_type) { 1344 // implementor has seen. No exact info in this case.
1315 return context_type; // report an inexact witness to this sad affair 1345 if (impl == context_type) {
1316 } 1346 return context_type; // report an inexact witness to this sad affair
1317 if (do_counts) 1347 }
1318 { NOT_PRODUCT(deps_find_witness_steps++); } 1348 if (do_counts)
1319 if (is_participant(impl)) { 1349 { NOT_PRODUCT(deps_find_witness_steps++); }
1320 if (!participants_hide_witnesses) { 1350 if (is_participant(impl)) {
1351 if (!participants_hide_witnesses) {
1352 ADD_SUBCLASS_CHAIN(impl);
1353 }
1354 } else if (is_witness(impl) && !ignore_witness(impl)) {
1355 return impl;
1356 } else {
1321 ADD_SUBCLASS_CHAIN(impl); 1357 ADD_SUBCLASS_CHAIN(impl);
1322 } 1358 }
1323 } else if (is_witness(impl) && !ignore_witness(impl)) {
1324 return impl;
1325 } else {
1326 ADD_SUBCLASS_CHAIN(impl);
1327 } 1359 }
1328 } 1360 }
1329 1361
1330 // Recursively process each non-trivial sibling chain. 1362 // Recursively process each non-trivial sibling chain.
1331 while (chaini > 0) { 1363 while (chaini > 0) {
1369 // This would require a deoptimization barrier on first instantiation. 1401 // This would require a deoptimization barrier on first instantiation.
1370 //if (k->is_not_instantiated()) return false; 1402 //if (k->is_not_instantiated()) return false;
1371 return true; 1403 return true;
1372 } 1404 }
1373 1405
1374 bool Dependencies::is_concrete_method(Method* m) { 1406 bool Dependencies::is_concrete_method(Method* m, Klass * k) {
1375 // Statics are irrelevant to virtual call sites. 1407 // NULL is not a concrete method,
1376 if (m->is_static()) return false; 1408 // statics are irrelevant to virtual call sites,
1377 1409 // abstract methods are not concrete,
1378 // We could also return false if m does not yet appear to be 1410 // overpass (error) methods are not concrete if k is abstract
1379 // executed, if the VM version supports this distinction also. 1411 //
1380 // Default methods are considered "concrete" as well. 1412 // note "true" is conservative answer --
1381 return !m->is_abstract() && 1413 // overpass clause is false if k == NULL, implies return true if
1382 !m->is_overpass(); // error functions aren't concrete 1414 // answer depends on overpass clause.
1415 return ! ( m == NULL || m -> is_static() || m -> is_abstract() ||
1416 m->is_overpass() && k != NULL && k -> is_abstract() );
1383 } 1417 }
1384 1418
1385 1419
1386 Klass* Dependencies::find_finalizable_subclass(Klass* k) { 1420 Klass* Dependencies::find_finalizable_subclass(Klass* k) {
1387 if (k->is_interface()) return NULL; 1421 if (k->is_interface()) return NULL;
1401 // We could also return false if k does not yet appear to be 1435 // We could also return false if k does not yet appear to be
1402 // instantiated, if the VM version supports this distinction also. 1436 // instantiated, if the VM version supports this distinction also.
1403 //if (k->is_not_instantiated()) return false; 1437 //if (k->is_not_instantiated()) return false;
1404 return true; 1438 return true;
1405 } 1439 }
1406
1407 bool Dependencies::is_concrete_method(ciMethod* m) {
1408 // Statics are irrelevant to virtual call sites.
1409 if (m->is_static()) return false;
1410
1411 // We could also return false if m does not yet appear to be
1412 // executed, if the VM version supports this distinction also.
1413 return !m->is_abstract();
1414 }
1415
1416 1440
1417 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { 1441 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) {
1418 return k->has_finalizable_subclass(); 1442 return k->has_finalizable_subclass();
1419 } 1443 }
1420 1444
1625 assert(wf.check_method_context(ctxk, m), "proper context"); 1649 assert(wf.check_method_context(ctxk, m), "proper context");
1626 wf.record_witnesses(1); 1650 wf.record_witnesses(1);
1627 Klass* wit = wf.find_witness_definer(ctxk); 1651 Klass* wit = wf.find_witness_definer(ctxk);
1628 if (wit != NULL) return NULL; // Too many witnesses. 1652 if (wit != NULL) return NULL; // Too many witnesses.
1629 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. 1653 Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0.
1630 if (Dependencies::is_concrete_method(m)) { 1654 if (Dependencies::is_concrete_method(m, ctxk)) {
1631 if (fm == NULL) { 1655 if (fm == NULL) {
1632 // It turns out that m was always the only implementation. 1656 // It turns out that m was always the only implementation.
1633 fm = m; 1657 fm = m;
1634 } else if (fm != m) { 1658 } else if (fm != m) {
1635 // Two conflicting implementations after all. 1659 // Two conflicting implementations after all.
1655 wf.add_participant(m1->method_holder()); 1679 wf.add_participant(m1->method_holder());
1656 wf.add_participant(m2->method_holder()); 1680 wf.add_participant(m2->method_holder());
1657 return wf.find_witness_definer(ctxk, changes); 1681 return wf.find_witness_definer(ctxk, changes);
1658 } 1682 }
1659 1683
1660 // Find the set of all non-abstract methods under ctxk that match m[0].
1661 // (The method m[0] must be defined or inherited in ctxk.)
1662 // Include m itself in the set, unless it is abstract.
1663 // Fill the given array m[0..(mlen-1)] with this set, and return the length.
1664 // (The length may be zero if no concrete methods are found anywhere.)
1665 // If there are too many concrete methods to fit in marray, return -1.
1666 int Dependencies::find_exclusive_concrete_methods(Klass* ctxk,
1667 int mlen,
1668 Method* marray[]) {
1669 Method* m0 = marray[0];
1670 ClassHierarchyWalker wf(m0);
1671 assert(wf.check_method_context(ctxk, m0), "proper context");
1672 wf.record_witnesses(mlen);
1673 bool participants_hide_witnesses = true;
1674 Klass* wit = wf.find_witness_definer(ctxk);
1675 if (wit != NULL) return -1; // Too many witnesses.
1676 int num = wf.num_participants();
1677 assert(num <= mlen, "oob");
1678 // Keep track of whether m is also part of the result set.
1679 int mfill = 0;
1680 assert(marray[mfill] == m0, "sanity");
1681 if (Dependencies::is_concrete_method(m0))
1682 mfill++; // keep m0 as marray[0], the first result
1683 for (int i = 0; i < num; i++) {
1684 Method* fm = wf.found_method(i);
1685 if (fm == m0) continue; // Already put this guy in the list.
1686 if (mfill == mlen) {
1687 return -1; // Oops. Too many methods after all!
1688 }
1689 marray[mfill++] = fm;
1690 }
1691 #ifndef PRODUCT
1692 // Make sure the dependency mechanism will pass this discovery:
1693 if (VerifyDependencies) {
1694 // Turn off dependency tracing while actually testing deps.
1695 FlagSetting fs(TraceDependencies, false);
1696 switch (mfill) {
1697 case 1:
1698 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]),
1699 "verify dep.");
1700 break;
1701 case 2:
1702 guarantee(NULL == (void *)
1703 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]),
1704 "verify dep.");
1705 break;
1706 default:
1707 ShouldNotReachHere(); // mlen > 2 yet supported
1708 }
1709 }
1710 #endif //PRODUCT
1711 return mfill;
1712 }
1713
1714
1715 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { 1684 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) {
1716 Klass* search_at = ctxk; 1685 Klass* search_at = ctxk;
1717 if (changes != NULL) 1686 if (changes != NULL)
1718 search_at = changes->new_type(); // just look at the new bit 1687 search_at = changes->new_type(); // just look at the new bit
1719 return find_finalizable_subclass(search_at); 1688 return find_finalizable_subclass(search_at);
1720 } 1689 }
1721
1722 1690
1723 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { 1691 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) {
1724 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); 1692 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity");
1725 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); 1693 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity");
1726 if (changes == NULL) { 1694 if (changes == NULL) {