comparison src/share/vm/runtime/sweeper.cpp @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents d8041d695d19
children 52b4284cb496
comparison
equal deleted inserted replaced
14908:8db6e76cb658 14909:4ca6dc0799b6
127 #define SWEEP(nm) 127 #define SWEEP(nm)
128 #endif 128 #endif
129 129
130 nmethod* NMethodSweeper::_current = NULL; // Current nmethod 130 nmethod* NMethodSweeper::_current = NULL; // Current nmethod
131 long NMethodSweeper::_traversals = 0; // Stack scan count, also sweep ID. 131 long NMethodSweeper::_traversals = 0; // Stack scan count, also sweep ID.
132 long NMethodSweeper::_total_nof_code_cache_sweeps = 0; // Total number of full sweeps of the code cache
133 long NMethodSweeper::_time_counter = 0; // Virtual time used to periodically invoke sweeper 132 long NMethodSweeper::_time_counter = 0; // Virtual time used to periodically invoke sweeper
134 long NMethodSweeper::_last_sweep = 0; // Value of _time_counter when the last sweep happened 133 long NMethodSweeper::_last_sweep = 0; // Value of _time_counter when the last sweep happened
135 int NMethodSweeper::_seen = 0; // Nof. nmethod we have currently processed in current pass of CodeCache 134 int NMethodSweeper::_seen = 0; // Nof. nmethod we have currently processed in current pass of CodeCache
136 int NMethodSweeper::_flushed_count = 0; // Nof. nmethods flushed in current sweep 135 int NMethodSweeper::_flushed_count = 0; // Nof. nmethods flushed in current sweep
137 int NMethodSweeper::_zombified_count = 0; // Nof. nmethods made zombie in current sweep 136 int NMethodSweeper::_zombified_count = 0; // Nof. nmethods made zombie in current sweep
142 volatile int NMethodSweeper::_sweep_started = 0; // Flag to control conc sweeper 141 volatile int NMethodSweeper::_sweep_started = 0; // Flag to control conc sweeper
143 volatile int NMethodSweeper::_bytes_changed = 0; // Counts the total nmethod size if the nmethod changed from: 142 volatile int NMethodSweeper::_bytes_changed = 0; // Counts the total nmethod size if the nmethod changed from:
144 // 1) alive -> not_entrant 143 // 1) alive -> not_entrant
145 // 2) not_entrant -> zombie 144 // 2) not_entrant -> zombie
146 // 3) zombie -> marked_for_reclamation 145 // 3) zombie -> marked_for_reclamation
147 int NMethodSweeper::_hotness_counter_reset_val = 0; 146
148 147 int NMethodSweeper::_total_nof_methods_reclaimed = 0; // Accumulated nof methods flushed
149 long NMethodSweeper::_total_nof_methods_reclaimed = 0; // Accumulated nof methods flushed 148 Tickspan NMethodSweeper::_total_time_sweeping; // Accumulated time sweeping
150 long NMethodSweeper::_total_nof_c2_methods_reclaimed = 0; // Accumulated nof methods flushed 149 Tickspan NMethodSweeper::_total_time_this_sweep; // Total time this sweep
151 size_t NMethodSweeper::_total_flushed_size = 0; // Total number of bytes flushed from the code cache 150 Tickspan NMethodSweeper::_peak_sweep_time; // Peak time for a full sweep
152 Tickspan NMethodSweeper::_total_time_sweeping; // Accumulated time sweeping 151 Tickspan NMethodSweeper::_peak_sweep_fraction_time; // Peak time sweeping one fraction
153 Tickspan NMethodSweeper::_total_time_this_sweep; // Total time this sweep 152 int NMethodSweeper::_hotness_counter_reset_val = 0;
154 Tickspan NMethodSweeper::_peak_sweep_time; // Peak time for a full sweep
155 Tickspan NMethodSweeper::_peak_sweep_fraction_time; // Peak time sweeping one fraction
156
157 153
158 154
159 class MarkActivationClosure: public CodeBlobClosure { 155 class MarkActivationClosure: public CodeBlobClosure {
160 public: 156 public:
161 virtual void do_code_blob(CodeBlob* cb) { 157 virtual void do_code_blob(CodeBlob* cb) {
259 // As a result, we invoke the sweeper after 255 // As a result, we invoke the sweeper after
260 // 15 invocations of 'mark_active_nmethods. 256 // 15 invocations of 'mark_active_nmethods.
261 // Large ReservedCodeCacheSize: (e.g., 256M + code Cache is 90% full). The formula 257 // Large ReservedCodeCacheSize: (e.g., 256M + code Cache is 90% full). The formula
262 // computes: (256 / 16) - 10 = 6. 258 // computes: (256 / 16) - 10 = 6.
263 if (!_should_sweep) { 259 if (!_should_sweep) {
264 const int time_since_last_sweep = _time_counter - _last_sweep; 260 int time_since_last_sweep = _time_counter - _last_sweep;
265 // ReservedCodeCacheSize has an 'unsigned' type. We need a 'signed' type for max_wait_time, 261 double wait_until_next_sweep = (ReservedCodeCacheSize / (16 * M)) - time_since_last_sweep -
266 // since 'time_since_last_sweep' can be larger than 'max_wait_time'. If that happens using 262 CodeCache::reverse_free_ratio();
267 // an unsigned type would cause an underflow (wait_until_next_sweep becomes a large positive
268 // value) that disables the intended periodic sweeps.
269 const int max_wait_time = ReservedCodeCacheSize / (16 * M);
270 double wait_until_next_sweep = max_wait_time - time_since_last_sweep - CodeCache::reverse_free_ratio();
271 assert(wait_until_next_sweep <= (double)max_wait_time, "Calculation of code cache sweeper interval is incorrect");
272 263
273 if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) { 264 if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) {
274 _should_sweep = true; 265 _should_sweep = true;
275 } 266 }
276 } 267 }
294 _sweep_fractions_left--; 285 _sweep_fractions_left--;
295 } 286 }
296 287
297 // We are done with sweeping the code cache once. 288 // We are done with sweeping the code cache once.
298 if (_sweep_fractions_left == 0) { 289 if (_sweep_fractions_left == 0) {
299 _total_nof_code_cache_sweeps++;
300 _last_sweep = _time_counter; 290 _last_sweep = _time_counter;
301 // Reset flag; temporarily disables sweeper 291 // Reset flag; temporarily disables sweeper
302 _should_sweep = false; 292 _should_sweep = false;
303 // If there was enough state change, 'possibly_enable_sweeper()' 293 // If there was enough state change, 'possibly_enable_sweeper()'
304 // sets '_should_sweep' to true 294 // sets '_should_sweep' to true
307 // can further increase by calls to 'report_state_change'. 297 // can further increase by calls to 'report_state_change'.
308 if (_should_sweep) { 298 if (_should_sweep) {
309 _bytes_changed = 0; 299 _bytes_changed = 0;
310 } 300 }
311 } 301 }
312 // Release work, because another compiler thread could continue. 302 _sweep_started = 0;
313 OrderAccess::release_store((int*)&_sweep_started, 0);
314 } 303 }
315 } 304 }
316 305
317 void NMethodSweeper::sweep_code_cache() { 306 void NMethodSweeper::sweep_code_cache() {
318 Ticks sweep_start_counter = Ticks::now(); 307 Ticks sweep_start_counter = Ticks::now();
382 const Ticks sweep_end_counter = Ticks::now(); 371 const Ticks sweep_end_counter = Ticks::now();
383 const Tickspan sweep_time = sweep_end_counter - sweep_start_counter; 372 const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
384 _total_time_sweeping += sweep_time; 373 _total_time_sweeping += sweep_time;
385 _total_time_this_sweep += sweep_time; 374 _total_time_this_sweep += sweep_time;
386 _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time); 375 _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
387 _total_flushed_size += freed_memory;
388 _total_nof_methods_reclaimed += _flushed_count; 376 _total_nof_methods_reclaimed += _flushed_count;
389 377
390 EventSweepCodeCache event(UNTIMED); 378 EventSweepCodeCache event(UNTIMED);
391 if (event.should_commit()) { 379 if (event.should_commit()) {
392 event.set_starttime(sweep_start_counter); 380 event.set_starttime(sweep_start_counter);
522 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods"); 510 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods");
523 if (PrintMethodFlushing && Verbose) { 511 if (PrintMethodFlushing && Verbose) {
524 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm); 512 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
525 } 513 }
526 freed_memory = nm->total_size(); 514 freed_memory = nm->total_size();
527 if (nm->is_compiled_by_c2()) {
528 _total_nof_c2_methods_reclaimed++;
529 }
530 release_nmethod(nm); 515 release_nmethod(nm);
531 _flushed_count++; 516 _flushed_count++;
532 } else { 517 } else {
533 if (PrintMethodFlushing && Verbose) { 518 if (PrintMethodFlushing && Verbose) {
534 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm); 519 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
563 } 548 }
564 if (nm->is_osr_method()) { 549 if (nm->is_osr_method()) {
565 SWEEP(nm); 550 SWEEP(nm);
566 // No inline caches will ever point to osr methods, so we can just remove it 551 // No inline caches will ever point to osr methods, so we can just remove it
567 freed_memory = nm->total_size(); 552 freed_memory = nm->total_size();
568 if (nm->is_compiled_by_c2()) {
569 _total_nof_c2_methods_reclaimed++;
570 }
571 release_nmethod(nm); 553 release_nmethod(nm);
572 _flushed_count++; 554 _flushed_count++;
573 } else { 555 } else {
574 // Code cache state change is tracked in make_zombie() 556 // Code cache state change is tracked in make_zombie()
575 nm->make_zombie(); 557 nm->make_zombie();
653 xtty->print(s.as_string()); 635 xtty->print(s.as_string());
654 xtty->stamp(); 636 xtty->stamp();
655 xtty->end_elem(); 637 xtty->end_elem();
656 } 638 }
657 } 639 }
658
659 void NMethodSweeper::print() {
660 ttyLocker ttyl;
661 tty->print_cr("Code cache sweeper statistics:");
662 tty->print_cr(" Total sweep time: %1.0lfms", (double)_total_time_sweeping.value()/1000000);
663 tty->print_cr(" Total number of full sweeps: %ld", _total_nof_code_cache_sweeps);
664 tty->print_cr(" Total number of flushed methods: %ld(%ld C2 methods)", _total_nof_methods_reclaimed,
665 _total_nof_c2_methods_reclaimed);
666 tty->print_cr(" Total size of flushed methods: " SIZE_FORMAT "kB", _total_flushed_size/K);
667 }