4141#include " runtime/handles.hpp"
4242#include " runtime/handles.inline.hpp"
4343#include " runtime/jniHandles.inline.hpp"
44+ #include " runtime/perfData.hpp"
4445#include " runtime/thread.inline.hpp"
4546#include " runtime/vmThread.hpp"
4647#include " utilities/copy.hpp"
@@ -951,7 +952,7 @@ bool DependencySignature::equals(DependencySignature const& s1, DependencySignat
951952 return true ;
952953}
953954
954- // / Checking dependencies:
955+ // / Checking dependencies
955956
956957// This hierarchy walker inspects subtypes of a given type,
957958// trying to find a "bad" class which breaks a dependency.
@@ -1145,6 +1146,24 @@ class ClassHierarchyWalker {
11451146 return false ; // not in list
11461147 }
11471148
1149+ class CountingClassHierarchyIterator : public ClassHierarchyIterator {
1150+ private:
1151+ jlong _nof_steps;
1152+ public:
1153+ CountingClassHierarchyIterator (InstanceKlass* root) : ClassHierarchyIterator(root), _nof_steps(0 ) {}
1154+
1155+ void next () {
1156+ _nof_steps++;
1157+ ClassHierarchyIterator::next ();
1158+ }
1159+
1160+ ~CountingClassHierarchyIterator () {
1161+ if (UsePerfData) {
1162+ _perf_find_witness_anywhere_steps_count->inc (_nof_steps);
1163+ }
1164+ }
1165+ };
1166+
11481167 private:
11491168 // the actual search method:
11501169 Klass* find_witness_anywhere (InstanceKlass* context_type,
@@ -1179,53 +1198,32 @@ class ClassHierarchyWalker {
11791198 return find_witness_anywhere (context_type, !participants_hide_witnesses);
11801199 }
11811200 }
1201+
1202+ private:
1203+ static PerfCounter* _perf_find_witness_anywhere_calls_count;
1204+ static PerfCounter* _perf_find_witness_anywhere_steps_count;
1205+ static PerfCounter* _perf_find_witness_in_calls_count;
1206+
1207+ public:
1208+ static void init ();
1209+ static void print_statistics ();
11821210};
11831211
1184- #ifndef PRODUCT
1185- static int deps_find_witness_calls = 0 ;
1186- static int deps_find_witness_steps = 0 ;
1187- static int deps_find_witness_recursions = 0 ;
1188- static int deps_find_witness_singles = 0 ;
1189- static int deps_find_witness_print = 0 ; // set to -1 to force a final print
1190- static bool count_find_witness_calls () {
1191- if (TraceDependencies || LogCompilation) {
1192- int pcount = deps_find_witness_print + 1 ;
1193- bool final_stats = (pcount == 0 );
1194- bool initial_call = (pcount == 1 );
1195- bool occasional_print = ((pcount & ((1 <<10 ) - 1 )) == 0 );
1196- if (pcount < 0 ) pcount = 1 ; // crude overflow protection
1197- deps_find_witness_print = pcount;
1198- if (TraceDependencies && VerifyDependencies && initial_call) {
1199- warning (" TraceDependencies results may be inflated by VerifyDependencies" );
1200- }
1201- if (occasional_print || final_stats) {
1202- // Every now and then dump a little info about dependency searching.
1203- if (xtty != NULL ) {
1204- ttyLocker ttyl;
1205- xtty->elem (" deps_find_witness calls='%d' steps='%d' recursions='%d' singles='%d'" ,
1206- deps_find_witness_calls,
1207- deps_find_witness_steps,
1208- deps_find_witness_recursions,
1209- deps_find_witness_singles);
1210- }
1211- if (final_stats || (TraceDependencies && WizardMode)) {
1212- ttyLocker ttyl;
1213- tty->print_cr (" Dependency check (find_witness) "
1214- " calls=%d, steps=%d (avg=%.1f), recursions=%d, singles=%d" ,
1215- deps_find_witness_calls,
1216- deps_find_witness_steps,
1217- (double )deps_find_witness_steps / deps_find_witness_calls,
1218- deps_find_witness_recursions,
1219- deps_find_witness_singles);
1220- }
1221- }
1222- return true ;
1212+ PerfCounter* ClassHierarchyWalker::_perf_find_witness_anywhere_calls_count = NULL ;
1213+ PerfCounter* ClassHierarchyWalker::_perf_find_witness_anywhere_steps_count = NULL ;
1214+ PerfCounter* ClassHierarchyWalker::_perf_find_witness_in_calls_count = NULL ;
1215+
1216+ void ClassHierarchyWalker::init () {
1217+ if (UsePerfData) {
1218+ EXCEPTION_MARK;
1219+ _perf_find_witness_anywhere_calls_count =
1220+ PerfDataManager::create_counter (SUN_CI, " findWitnessAnywhere" , PerfData::U_Events, CHECK);
1221+ _perf_find_witness_anywhere_steps_count =
1222+ PerfDataManager::create_counter (SUN_CI, " findWitnessAnywhereSteps" , PerfData::U_Events, CHECK);
1223+ _perf_find_witness_in_calls_count =
1224+ PerfDataManager::create_counter (SUN_CI, " findWitnessIn" , PerfData::U_Events, CHECK);
12231225 }
1224- return false ;
12251226}
1226- #else
1227- #define count_find_witness_calls () (0 )
1228- #endif // PRODUCT
12291227
12301228#ifdef ASSERT
12311229// Assert that m is inherited into ctxk, without intervening overrides.
@@ -1291,8 +1289,9 @@ Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
12911289 assert (changes.involves_context (context_type), " irrelevant dependency" );
12921290 Klass* new_type = changes.new_type ();
12931291
1294- (void )count_find_witness_calls ();
1295- NOT_PRODUCT (deps_find_witness_singles++);
1292+ if (UsePerfData) {
1293+ _perf_find_witness_in_calls_count->inc ();
1294+ }
12961295
12971296 // Current thread must be in VM (not native mode, as in CI):
12981297 assert (must_be_in_vm (), " raw oops here" );
@@ -1332,12 +1331,11 @@ Klass* ClassHierarchyWalker::find_witness_anywhere(InstanceKlass* context_type,
13321331 // Must not move the class hierarchy during this check:
13331332 assert_locked_or_safepoint (Compile_lock);
13341333
1335- bool do_counts = count_find_witness_calls ();
1334+ if (UsePerfData) {
1335+ _perf_find_witness_anywhere_calls_count->inc ();
1336+ }
13361337
13371338 // Check the root of the sub-hierarchy first.
1338- if (do_counts) {
1339- NOT_PRODUCT (deps_find_witness_calls++);
1340- }
13411339
13421340 // (Note: Interfaces do not have subclasses.)
13431341 // If it is an interface, search its direct implementors.
@@ -1362,11 +1360,9 @@ Klass* ClassHierarchyWalker::find_witness_anywhere(InstanceKlass* context_type,
13621360
13631361 assert (!context_type->is_interface (), " not allowed" );
13641362
1365- for (ClassHierarchyIterator iter (context_type); !iter.done (); iter.next ()) {
1363+ for (CountingClassHierarchyIterator iter (context_type); !iter.done (); iter.next ()) {
13661364 Klass* sub = iter.klass ();
13671365
1368- if (do_counts) { NOT_PRODUCT (deps_find_witness_steps++); }
1369-
13701366 // Do not report participant types.
13711367 if (is_participant (sub)) {
13721368 // Walk beneath a participant only when it doesn't hide witnesses.
@@ -1779,19 +1775,39 @@ bool KlassDepChange::involves_context(Klass* k) {
17791775 return is_contained;
17801776}
17811777
1782- #ifndef PRODUCT
17831778void Dependencies::print_statistics () {
1784- if (deps_find_witness_print != 0 ) {
1785- // Call one final time, to flush out the data.
1786- deps_find_witness_print = -1 ;
1787- count_find_witness_calls ();
1779+ ClassHierarchyWalker::print_statistics ();
1780+ }
1781+
1782+ void ClassHierarchyWalker::print_statistics () {
1783+ if (UsePerfData) {
1784+ jlong deps_find_witness_calls = _perf_find_witness_anywhere_calls_count->get_value ();
1785+ jlong deps_find_witness_steps = _perf_find_witness_anywhere_steps_count->get_value ();
1786+ jlong deps_find_witness_singles = _perf_find_witness_in_calls_count->get_value ();
1787+
1788+ ttyLocker ttyl;
1789+ tty->print_cr (" Dependency check (find_witness) "
1790+ " calls=" JLONG_FORMAT " , steps=" JLONG_FORMAT " (avg=%.1f), singles=" JLONG_FORMAT,
1791+ deps_find_witness_calls,
1792+ deps_find_witness_steps,
1793+ (double )deps_find_witness_steps / deps_find_witness_calls,
1794+ deps_find_witness_singles);
1795+ if (xtty != NULL ) {
1796+ xtty->elem (" deps_find_witness calls='" JLONG_FORMAT " ' steps='" JLONG_FORMAT " ' singles='" JLONG_FORMAT " '" ,
1797+ deps_find_witness_calls,
1798+ deps_find_witness_steps,
1799+ deps_find_witness_singles);
1800+ }
17881801 }
17891802}
1790- #endif
17911803
17921804CallSiteDepChange::CallSiteDepChange (Handle call_site, Handle method_handle) :
17931805 _call_site (call_site),
17941806 _method_handle (method_handle) {
17951807 assert (_call_site ()->is_a (vmClasses::CallSite_klass ()), " must be" );
17961808 assert (_method_handle.is_null () || _method_handle ()->is_a (vmClasses::MethodHandle_klass ()), " must be" );
17971809}
1810+
1811+ void dependencies_init () {
1812+ ClassHierarchyWalker::init ();
1813+ }
0 commit comments