src/share/vm/runtime/sweeper.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/sweeper.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_RUNTIME_SWEEPER_HPP
    1.29 +#define SHARE_VM_RUNTIME_SWEEPER_HPP
    1.30 +
    1.31 +#include "utilities/ticks.hpp"
    1.32 +// An NmethodSweeper is an incremental cleaner for:
    1.33 +//    - cleanup inline caches
    1.34 +//    - reclamation of nmethods
    1.35 +// Removing nmethods from the code cache includes two operations
    1.36 +//  1) mark active nmethods
    1.37 +//     Is done in 'mark_active_nmethods()'. This function is called at a
    1.38 +//     safepoint and marks all nmethods that are active on a thread's stack.
    1.39 +//  2) sweep nmethods
    1.40 +//     Is done in sweep_code_cache(). This function is the only place in the
    1.41 +//     sweeper where memory is reclaimed. Note that sweep_code_cache() is not
    1.42 +//     called at a safepoint. However, sweep_code_cache() stops executing if
    1.43 +//     another thread requests a safepoint. Consequently, 'mark_active_nmethods()'
    1.44 +//     and sweep_code_cache() cannot execute at the same time.
    1.45 +//     To reclaim memory, nmethods are first marked as 'not-entrant'. Methods can
    1.46 +//     be made not-entrant by (i) the sweeper, (ii) deoptimization, (iii) dependency
    1.47 +//     invalidation, and (iv) being replaced be a different method version (tiered
    1.48 +//     compilation). Not-entrant nmethod cannot be called by Java threads, but they
    1.49 +//     can still be active on the stack. To ensure that active nmethod are not reclaimed,
    1.50 +//     we have to wait until the next marking phase has completed. If a not-entrant
    1.51 +//     nmethod was NOT marked as active, it can be converted to 'zombie' state. To safely
    1.52 +//     remove the nmethod, all inline caches (IC) that point to the the nmethod must be
    1.53 +//     cleared. After that, the nmethod can be evicted from the code cache. Each nmethod's
    1.54 +//     state change happens during separate sweeps. It may take at least 3 sweeps before an
    1.55 +//     nmethod's space is freed. Sweeping is currently done by compiler threads between
    1.56 +//     compilations or at least each 5 sec (NmethodSweepCheckInterval) when the code cache
    1.57 +//     is full.
    1.58 +
    1.59 +class NMethodSweeper : public AllStatic {
    1.60 +  static long      _traversals;                     // Stack scan count, also sweep ID.
    1.61 +  static long      _total_nof_code_cache_sweeps;    // Total number of full sweeps of the code cache
    1.62 +  static long      _time_counter;                   // Virtual time used to periodically invoke sweeper
    1.63 +  static long      _last_sweep;                     // Value of _time_counter when the last sweep happened
    1.64 +  static nmethod*  _current;                        // Current nmethod
    1.65 +  static int       _seen;                           // Nof. nmethod we have currently processed in current pass of CodeCache
    1.66 +  static int       _flushed_count;                  // Nof. nmethods flushed in current sweep
    1.67 +  static int       _zombified_count;                // Nof. nmethods made zombie in current sweep
    1.68 +  static int       _marked_for_reclamation_count;   // Nof. nmethods marked for reclaim in current sweep
    1.69 +
    1.70 +  static volatile int  _sweep_fractions_left;       // Nof. invocations left until we are completed with this pass
    1.71 +  static volatile int  _sweep_started;              // Flag to control conc sweeper
    1.72 +  static volatile bool _should_sweep;               // Indicates if we should invoke the sweeper
    1.73 +  static volatile int  _bytes_changed;              // Counts the total nmethod size if the nmethod changed from:
    1.74 +                                                    //   1) alive       -> not_entrant
    1.75 +                                                    //   2) not_entrant -> zombie
    1.76 +                                                    //   3) zombie      -> marked_for_reclamation
    1.77 +  // Stat counters
    1.78 +  static long      _total_nof_methods_reclaimed;    // Accumulated nof methods flushed
    1.79 +  static long      _total_nof_c2_methods_reclaimed; // Accumulated nof C2-compiled methods flushed
    1.80 +  static size_t    _total_flushed_size;             // Total size of flushed methods
    1.81 +  static int       _hotness_counter_reset_val;
    1.82 +
    1.83 +  static Tickspan  _total_time_sweeping;            // Accumulated time sweeping
    1.84 +  static Tickspan  _total_time_this_sweep;          // Total time this sweep
    1.85 +  static Tickspan  _peak_sweep_time;                // Peak time for a full sweep
    1.86 +  static Tickspan  _peak_sweep_fraction_time;       // Peak time sweeping one fraction
    1.87 +
    1.88 +  static int  process_nmethod(nmethod *nm);
    1.89 +  static void release_nmethod(nmethod* nm);
    1.90 +
    1.91 +  static bool sweep_in_progress();
    1.92 +  static void sweep_code_cache();
    1.93 +
    1.94 + public:
    1.95 +  static long traversal_count()              { return _traversals; }
    1.96 +  static int  total_nof_methods_reclaimed()  { return _total_nof_methods_reclaimed; }
    1.97 +  static const Tickspan total_time_sweeping()      { return _total_time_sweeping; }
    1.98 +  static const Tickspan peak_sweep_time()          { return _peak_sweep_time; }
    1.99 +  static const Tickspan peak_sweep_fraction_time() { return _peak_sweep_fraction_time; }
   1.100 +  static void log_sweep(const char* msg, const char* format = NULL, ...) ATTRIBUTE_PRINTF(2, 3);
   1.101 +
   1.102 +
   1.103 +#ifdef ASSERT
   1.104 +  static bool is_sweeping(nmethod* which) { return _current == which; }
   1.105 +  // Keep track of sweeper activity in the ring buffer
   1.106 +  static void record_sweep(nmethod* nm, int line);
   1.107 +  static void report_events(int id, address entry);
   1.108 +  static void report_events();
   1.109 +#endif
   1.110 +
   1.111 +  static void mark_active_nmethods();      // Invoked at the end of each safepoint
   1.112 +  static void possibly_sweep();            // Compiler threads call this to sweep
   1.113 +
   1.114 +  static int hotness_counter_reset_val();
   1.115 +  static void report_state_change(nmethod* nm);
   1.116 +  static void possibly_enable_sweeper();
   1.117 +  static void print();   // Printing/debugging
   1.118 +};
   1.119 +
   1.120 +#endif // SHARE_VM_RUNTIME_SWEEPER_HPP

mercurial