< prev index next >

src/hotspot/share/compiler/compileBroker.cpp

Print this page
rev 54099 : 8219586: CodeHeap State Analytics processes dead nmethods
Reviewed-by: thartmann, eosterlund


2757   bool methodNames = !strcmp(function, "MethodNames") || allFun;
2758   bool discard = !strcmp(function, "discard") || allFun;
2759 
2760   if (out == NULL) {
2761     out = tty;
2762   }
2763 
2764   if (!(aggregate || usedSpace || freeSpace || methodCount || methodSpace || methodAge || methodNames || discard)) {
2765     out->print_cr("\n__ CodeHeapStateAnalytics: Function %s is not supported", function);
2766     out->cr();
2767     return;
2768   }
2769 
2770   ts_total.update(); // record starting point
2771 
2772   if (aggregate) {
2773     print_info(out);
2774   }
2775 
2776   // We hold the CodeHeapStateAnalytics_lock all the time, from here until we leave this function.
2777   // That prevents another thread from destroying our view on the CodeHeap.
2778   // When we request individual parts of the analysis via the jcmd interface, it is possible
2779   // that in between another thread (another jcmd user or the vm running into CodeCache OOM)
2780   // updated the aggregated data. That's a tolerable tradeoff because we can't hold a lock
2781   // across user interaction.
2782   // Acquire this lock before acquiring the CodeCache_lock.
2783   // CodeHeapStateAnalytics_lock could be held by a concurrent thread for a long time,
2784   // leading to an unnecessarily long hold time of the CodeCache_lock.


2785   ts.update(); // record starting point
2786   MutexLockerEx mu1(CodeHeapStateAnalytics_lock, Mutex::_no_safepoint_check_flag);
2787   out->print_cr("\n__ CodeHeapStateAnalytics lock wait took %10.3f seconds _________\n", ts.seconds());
2788 
2789   // If we serve an "allFun" call, it is beneficial to hold the CodeCache_lock
2790   // for the entire duration of aggregation and printing. That makes sure
2791   // we see a consistent picture and do not run into issues caused by
2792   // the CodeHeap being altered concurrently.
2793   Monitor* global_lock   = allFun ? CodeCache_lock : NULL;
2794   Monitor* function_lock = allFun ? NULL : CodeCache_lock;













2795   ts_global.update(); // record starting point
2796   MutexLockerEx mu2(global_lock, Mutex::_no_safepoint_check_flag);
2797   if (global_lock != NULL) {
2798     out->print_cr("\n__ CodeCache (global) lock wait took %10.3f seconds _________\n", ts_global.seconds());

2799     ts_global.update(); // record starting point
2800   }
2801 
2802   if (aggregate) {
2803     ts.update(); // record starting point
2804     MutexLockerEx mu3(function_lock, Mutex::_no_safepoint_check_flag);
2805     if (function_lock != NULL) {
2806       out->print_cr("\n__ CodeCache (function) lock wait took %10.3f seconds _________\n", ts.seconds());

2807     }
2808 
2809     ts.update(); // record starting point
2810     CodeCache::aggregate(out, granularity);
2811     if (function_lock != NULL) {
2812       out->print_cr("\n__ CodeCache (function) lock hold took %10.3f seconds _________\n", ts.seconds());
2813     }
2814   }
2815 
2816   if (usedSpace) CodeCache::print_usedSpace(out);
2817   if (freeSpace) CodeCache::print_freeSpace(out);
2818   if (methodCount) CodeCache::print_count(out);
2819   if (methodSpace) CodeCache::print_space(out);
2820   if (methodAge) CodeCache::print_age(out);
2821   if (methodNames) {
2822     // print_names() has shown to be sensitive to concurrent CodeHeap modifications.
2823     // Therefore, request  the CodeCache_lock before calling...
2824     MutexLockerEx mu3(function_lock, Mutex::_no_safepoint_check_flag);
2825     CodeCache::print_names(out);



2826   }
2827   if (discard) CodeCache::discard(out);
2828 
2829   if (global_lock != NULL) {
2830     out->print_cr("\n__ CodeCache (global) lock hold took %10.3f seconds _________\n", ts_global.seconds());
2831   }
2832   out->print_cr("\n__ CodeHeapStateAnalytics total duration %10.3f seconds _________\n", ts_total.seconds());
2833 }


2757   bool methodNames = !strcmp(function, "MethodNames") || allFun;
2758   bool discard = !strcmp(function, "discard") || allFun;
2759 
2760   if (out == NULL) {
2761     out = tty;
2762   }
2763 
2764   if (!(aggregate || usedSpace || freeSpace || methodCount || methodSpace || methodAge || methodNames || discard)) {
2765     out->print_cr("\n__ CodeHeapStateAnalytics: Function %s is not supported", function);
2766     out->cr();
2767     return;
2768   }
2769 
2770   ts_total.update(); // record starting point
2771 
2772   if (aggregate) {
2773     print_info(out);
2774   }
2775 
2776   // We hold the CodeHeapStateAnalytics_lock all the time, from here until we leave this function.
2777   // That prevents other threads from destroying (making inconsistent) our view on the CodeHeap.
2778   // When we request individual parts of the analysis via the jcmd interface, it is possible
2779   // that in between another thread (another jcmd user or the vm running into CodeCache OOM)
2780   // updated the aggregated data. We will then see a modified, but again consistent, view
2781   // on the CodeHeap. That's a tolerable tradeoff we have to accept because we can't hold
2782   // a lock across user interaction.
2783 
2784   // We should definitely acquire this lock before acquiring Compile_lock and CodeCache_lock.
2785   // CodeHeapStateAnalytics_lock may be held by a concurrent thread for a long time,
2786   // leading to an unnecessarily long hold time of the other locks we acquired before.
2787   ts.update(); // record starting point
2788   MutexLockerEx mu0(CodeHeapStateAnalytics_lock);
2789   out->print_cr("\n__ CodeHeapStateAnalytics lock wait took %10.3f seconds _________\n", ts.seconds());
2790 
2791   // Holding the CodeCache_lock protects from concurrent alterations of the CodeCache.
2792   // Unfortunately, such protection is not sufficient:
2793   // When a new nmethod is created via ciEnv::register_method(), the
2794   // Compile_lock is taken first. After some initializations,
2795   // nmethod::new_nmethod() takes over, grabbing the CodeCache_lock
2796   // immediately (after finalizing the oop references). To lock out concurrent
2797   // modifiers, we have to grab both locks as well in the described sequence.
2798   //
2799   // If we serve an "allFun" call, it is beneficial to hold CodeCache_lock and Compile_lock
2800   // for the entire duration of aggregation and printing. That makes sure we see
2801   // a consistent picture and do not run into issues caused by concurrent alterations.
2802   bool should_take_Compile_lock   = !SafepointSynchronize::is_at_safepoint() &&
2803                                     !Compile_lock->owned_by_self();
2804   bool should_take_CodeCache_lock = !SafepointSynchronize::is_at_safepoint() &&
2805                                     !CodeCache_lock->owned_by_self();
2806   Mutex*   global_lock_1   = allFun ? (should_take_Compile_lock   ? Compile_lock   : NULL) : NULL;
2807   Monitor* global_lock_2   = allFun ? (should_take_CodeCache_lock ? CodeCache_lock : NULL) : NULL;
2808   Mutex*   function_lock_1 = allFun ? NULL : (should_take_Compile_lock   ? Compile_lock    : NULL);
2809   Monitor* function_lock_2 = allFun ? NULL : (should_take_CodeCache_lock ? CodeCache_lock  : NULL);
2810   ts_global.update(); // record starting point
2811   MutexLockerEx mu1(global_lock_1);
2812   MutexLockerEx mu2(global_lock_2, Mutex::_no_safepoint_check_flag);
2813   if ((global_lock_1 != NULL) || (global_lock_2 != NULL)) {
2814     out->print_cr("\n__ Compile & CodeCache (global) lock wait took %10.3f seconds _________\n", ts_global.seconds());
2815     ts_global.update(); // record starting point
2816   }
2817 
2818   if (aggregate) {
2819     ts.update(); // record starting point
2820     MutexLockerEx mu11(function_lock_1);
2821     MutexLockerEx mu22(function_lock_2, Mutex::_no_safepoint_check_flag);
2822     if ((function_lock_1 != NULL) || (function_lock_1 != NULL)) {
2823       out->print_cr("\n__ Compile & CodeCache (function) lock wait took %10.3f seconds _________\n", ts.seconds());
2824     }
2825 
2826     ts.update(); // record starting point
2827     CodeCache::aggregate(out, granularity);
2828     if ((function_lock_1 != NULL) || (function_lock_1 != NULL)) {
2829       out->print_cr("\n__ Compile & CodeCache (function) lock hold took %10.3f seconds _________\n", ts.seconds());
2830     }
2831   }
2832 
2833   if (usedSpace) CodeCache::print_usedSpace(out);
2834   if (freeSpace) CodeCache::print_freeSpace(out);
2835   if (methodCount) CodeCache::print_count(out);
2836   if (methodSpace) CodeCache::print_space(out);
2837   if (methodAge) CodeCache::print_age(out);
2838   if (methodNames) {
2839     if (allFun) {
2840       // print_names() can only be used safely if the locks have been continuously held
2841       // since aggregation begin. That is true only for function "all".
2842       CodeCache::print_names(out);
2843     } else {
2844       out->print_cr("\nCodeHeapStateAnalytics: Function 'MethodNames' is only available as part of function 'all'");
2845     }
2846   }
2847   if (discard) CodeCache::discard(out);
2848 
2849   if ((global_lock_1 != NULL) || (global_lock_2 != NULL)) {
2850     out->print_cr("\n__ Compile & CodeCache (global) lock hold took %10.3f seconds _________\n", ts_global.seconds());
2851   }
2852   out->print_cr("\n__ CodeHeapStateAnalytics total duration %10.3f seconds _________\n", ts_total.seconds());
2853 }
< prev index next >