src/share/vm/runtime/sweeper.cpp

Print this page
rev 13113 : 8182651: Add TRACE_ONLY conditional macro to support more fine-grained INCLUDE_TRACE programming
Reviewed-by:
   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/icBuffer.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "oops/method.hpp"
  33 #include "runtime/atomic.hpp"
  34 #include "runtime/compilationPolicy.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/orderAccess.inline.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/sweeper.hpp"
  39 #include "runtime/thread.inline.hpp"
  40 #include "runtime/vm_operations.hpp"
  41 #include "trace/tracing.hpp"
  42 #include "utilities/events.hpp"

  43 #include "utilities/ticks.inline.hpp"
  44 #include "utilities/xmlstream.hpp"




  45 
  46 #ifdef ASSERT
  47 
  48 #define SWEEP(nm) record_sweep(nm, __LINE__)
  49 // Sweeper logging code
  50 class SweeperRecord {
  51  public:
  52   int traversal;
  53   int compile_id;
  54   long traversal_mark;
  55   int state;
  56   const char* kind;
  57   address vep;
  58   address uep;
  59   int line;
  60 
  61   void print() {
  62       tty->print_cr("traversal = %d compile_id = %d %s uep = " PTR_FORMAT " vep = "
  63                     PTR_FORMAT " state = %d traversal_mark %ld line = %d",
  64                     traversal,


 468 
 469       _seen++;
 470       handle_safepoint_request();
 471     }
 472   }
 473 
 474   assert(_current.end(), "must have scanned the whole cache");
 475 
 476   const Ticks sweep_end_counter = Ticks::now();
 477   const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
 478   {
 479     MutexLockerEx mu(_stat_lock, Mutex::_no_safepoint_check_flag);
 480     _total_time_sweeping  += sweep_time;
 481     _total_time_this_sweep += sweep_time;
 482     _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
 483     _total_flushed_size += freed_memory;
 484     _total_nof_methods_reclaimed += flushed_count;
 485     _total_nof_c2_methods_reclaimed += flushed_c2_count;
 486     _peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep);
 487   }


 488   EventSweepCodeCache event(UNTIMED);
 489   if (event.should_commit()) {
 490     event.set_starttime(sweep_start_counter);
 491     event.set_endtime(sweep_end_counter);
 492     event.set_sweepId(_traversals);
 493     event.set_sweptCount(swept_count);
 494     event.set_flushedCount(flushed_count);
 495     event.set_zombifiedCount(zombified_count);
 496     event.commit();
 497   }

 498 
 499 #ifdef ASSERT
 500   if(PrintMethodFlushing) {
 501     tty->print_cr("### sweeper:      sweep time(" JLONG_FORMAT "): ", sweep_time.value());
 502   }
 503 #endif
 504 
 505   Log(codecache, sweep) log;
 506   if (log.is_debug()) {
 507     CodeCache::print_summary(log.debug_stream(), false);
 508   }
 509   log_sweep("finished");
 510 
 511   // Sweeper is the only case where memory is released, check here if it
 512   // is time to restart the compiler. Only checking if there is a certain
 513   // amount of free memory in the code cache might lead to re-enabling
 514   // compilation although no memory has been released. For example, there are
 515   // cases when compilation was disabled although there is 4MB (or more) free
 516   // memory in the code cache. The reason is code cache fragmentation. Therefore,
 517   // it only makes sense to re-enable compilation if we have actually freed memory.


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/icBuffer.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "oops/method.hpp"
  33 #include "runtime/atomic.hpp"
  34 #include "runtime/compilationPolicy.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/orderAccess.inline.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/sweeper.hpp"
  39 #include "runtime/thread.inline.hpp"
  40 #include "runtime/vm_operations.hpp"

  41 #include "utilities/events.hpp"
  42 #include "utilities/macros.hpp"
  43 #include "utilities/ticks.inline.hpp"
  44 #include "utilities/xmlstream.hpp"
  45 #if INCLUDE_TRACE
  46 #include "trace/tracing.hpp"
  47 #endif
  48 
  49 
  50 #ifdef ASSERT
  51 
  52 #define SWEEP(nm) record_sweep(nm, __LINE__)
  53 // Sweeper logging code
  54 class SweeperRecord {
  55  public:
  56   int traversal;
  57   int compile_id;
  58   long traversal_mark;
  59   int state;
  60   const char* kind;
  61   address vep;
  62   address uep;
  63   int line;
  64 
  65   void print() {
  66       tty->print_cr("traversal = %d compile_id = %d %s uep = " PTR_FORMAT " vep = "
  67                     PTR_FORMAT " state = %d traversal_mark %ld line = %d",
  68                     traversal,


 472 
 473       _seen++;
 474       handle_safepoint_request();
 475     }
 476   }
 477 
 478   assert(_current.end(), "must have scanned the whole cache");
 479 
 480   const Ticks sweep_end_counter = Ticks::now();
 481   const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
 482   {
 483     MutexLockerEx mu(_stat_lock, Mutex::_no_safepoint_check_flag);
 484     _total_time_sweeping  += sweep_time;
 485     _total_time_this_sweep += sweep_time;
 486     _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
 487     _total_flushed_size += freed_memory;
 488     _total_nof_methods_reclaimed += flushed_count;
 489     _total_nof_c2_methods_reclaimed += flushed_c2_count;
 490     _peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep);
 491   }
 492 
 493 #if INCLUDE_TRACE
 494   EventSweepCodeCache event(UNTIMED);
 495   if (event.should_commit()) {
 496     event.set_starttime(sweep_start_counter);
 497     event.set_endtime(sweep_end_counter);
 498     event.set_sweepId(_traversals);
 499     event.set_sweptCount(swept_count);
 500     event.set_flushedCount(flushed_count);
 501     event.set_zombifiedCount(zombified_count);
 502     event.commit();
 503   }
 504 #endif // INCLUDE_TRACE
 505 
 506 #ifdef ASSERT
 507   if(PrintMethodFlushing) {
 508     tty->print_cr("### sweeper:      sweep time(" JLONG_FORMAT "): ", sweep_time.value());
 509   }
 510 #endif
 511 
 512   Log(codecache, sweep) log;
 513   if (log.is_debug()) {
 514     CodeCache::print_summary(log.debug_stream(), false);
 515   }
 516   log_sweep("finished");
 517 
 518   // Sweeper is the only case where memory is released, check here if it
 519   // is time to restart the compiler. Only checking if there is a certain
 520   // amount of free memory in the code cache might lead to re-enabling
 521   // compilation although no memory has been released. For example, there are
 522   // cases when compilation was disabled although there is 4MB (or more) free
 523   // memory in the code cache. The reason is code cache fragmentation. Therefore,
 524   // it only makes sense to re-enable compilation if we have actually freed memory.