hotspot/src/share/vm/runtime/sweeper.hpp
author dholmes
Tue, 12 Jan 2016 19:48:00 -0500
changeset 35485 9ee1d7aba342
parent 33160 c59f1676d27e
child 36802 18b1db5a7e70
permissions -rw-r--r--
8146855: Update hotspot sources to recognize Solaris Studio 12u4 compiler Reviewed-by: dcubed, gthornbr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22210
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5924
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_SWEEPER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5924
diff changeset
    26
#define SHARE_VM_RUNTIME_SWEEPER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5924
diff changeset
    27
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
    28
class WhiteBox;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
    29
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30205
diff changeset
    30
#include "code/codeCache.hpp"
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21575
diff changeset
    31
#include "utilities/ticks.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30205
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// An NmethodSweeper is an incremental cleaner for:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//    - cleanup inline caches
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    35
//    - reclamation of nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    36
// Removing nmethods from the code cache includes two operations
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    37
//  1) mark active nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    38
//     Is done in 'mark_active_nmethods()'. This function is called at a
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    39
//     safepoint and marks all nmethods that are active on a thread's stack.
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    40
//  2) sweep nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    41
//     Is done in sweep_code_cache(). This function is the only place in the
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    42
//     sweeper where memory is reclaimed. Note that sweep_code_cache() is not
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    43
//     called at a safepoint. However, sweep_code_cache() stops executing if
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    44
//     another thread requests a safepoint. Consequently, 'mark_active_nmethods()'
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    45
//     and sweep_code_cache() cannot execute at the same time.
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    46
//     To reclaim memory, nmethods are first marked as 'not-entrant'. Methods can
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    47
//     be made not-entrant by (i) the sweeper, (ii) deoptimization, (iii) dependency
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    48
//     invalidation, and (iv) being replaced be a different method version (tiered
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    49
//     compilation). Not-entrant nmethod cannot be called by Java threads, but they
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    50
//     can still be active on the stack. To ensure that active nmethod are not reclaimed,
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    51
//     we have to wait until the next marking phase has completed. If a not-entrant
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    52
//     nmethod was NOT marked as active, it can be converted to 'zombie' state. To safely
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    53
//     remove the nmethod, all inline caches (IC) that point to the the nmethod must be
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    54
//     cleared. After that, the nmethod can be evicted from the code cache. Each nmethod's
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    55
//     state change happens during separate sweeps. It may take at least 3 sweeps before an
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
    56
//     nmethod's space is freed.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
class NMethodSweeper : public AllStatic {
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
    59
 private:
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    60
  enum MethodStateChange {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    61
    None,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    62
    MadeZombie,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    63
    MarkedForReclamation,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    64
    Flushed
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    65
  };
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    66
  static long      _traversals;                   // Stack scan count, also sweep ID.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    67
  static long      _total_nof_code_cache_sweeps;  // Total number of full sweeps of the code cache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    68
  static long      _time_counter;                 // Virtual time used to periodically invoke sweeper
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    69
  static long      _last_sweep;                   // Value of _time_counter when the last sweep happened
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    70
  static NMethodIterator _current;                // Current nmethod
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    71
  static int       _seen;                         // Nof. nmethod we have currently processed in current pass of CodeCache
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
    72
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    73
  static volatile int  _sweep_started;            // Flag to control conc sweeper
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    74
  static volatile bool _should_sweep;             // Indicates if we should invoke the sweeper
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 27917
diff changeset
    75
  static volatile bool _force_sweep;              // Indicates if we should force a sweep
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    76
  static volatile int _bytes_changed;             // Counts the total nmethod size if the nmethod changed from:
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    77
                                                  //   1) alive       -> not_entrant
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    78
                                                  //   2) not_entrant -> zombie
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    79
                                                  //   3) zombie      -> marked_for_reclamation
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
    80
  // Stat counters
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
    81
  static long      _total_nof_methods_reclaimed;    // Accumulated nof methods flushed
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
    82
  static long      _total_nof_c2_methods_reclaimed; // Accumulated nof C2-compiled methods flushed
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
    83
  static size_t    _total_flushed_size;             // Total size of flushed methods
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
    84
  static int       _hotness_counter_reset_val;
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
    85
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    86
  static Tickspan  _total_time_sweeping;          // Accumulated time sweeping
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    87
  static Tickspan  _total_time_this_sweep;        // Total time this sweep
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    88
  static Tickspan  _peak_sweep_time;              // Peak time for a full sweep
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    89
  static Tickspan  _peak_sweep_fraction_time;     // Peak time sweeping one fraction
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
    90
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    91
  static Monitor*  _stat_lock;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    92
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    93
  static MethodStateChange process_nmethod(nmethod *nm);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    94
  static void              release_nmethod(nmethod* nm);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9942
diff changeset
    95
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
    96
  static void init_sweeper_log() NOT_DEBUG_RETURN;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
    97
  static bool wait_for_stack_scanning();
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    98
  static void sweep_code_cache();
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
    99
  static void handle_safepoint_request();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
   100
  static void do_stack_scanning();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
   101
  static void possibly_sweep();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
 public:
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   103
  static long traversal_count()              { return _traversals; }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   104
  static int  total_nof_methods_reclaimed()  { return _total_nof_methods_reclaimed; }
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21575
diff changeset
   105
  static const Tickspan total_time_sweeping()      { return _total_time_sweeping; }
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21575
diff changeset
   106
  static const Tickspan peak_sweep_time()          { return _peak_sweep_time; }
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21575
diff changeset
   107
  static const Tickspan peak_sweep_fraction_time() { return _peak_sweep_fraction_time; }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22210
diff changeset
   108
  static void log_sweep(const char* msg, const char* format = NULL, ...) ATTRIBUTE_PRINTF(2, 3);
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
   109
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   111
#ifdef ASSERT
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
   112
  static bool is_sweeping(nmethod* which) { return _current.method() == which; }
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   113
  // Keep track of sweeper activity in the ring buffer
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   114
  static void record_sweep(nmethod* nm, int line);
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   115
  static void report_events(int id, address entry);
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   116
  static void report_events();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   117
#endif
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   118
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
   119
  static void mark_active_nmethods();      // Invoked at the end of each safepoint
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
   120
  static void sweeper_loop();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26796
diff changeset
   121
  static void notify(int code_blob_type);  // Possibly start the sweeper thread.
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 27917
diff changeset
   122
  static void force_sweep();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
   124
  static int hotness_counter_reset_val();
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   125
  static void report_state_change(nmethod* nm);
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   126
  static void possibly_enable_sweeper();
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   127
  static void possibly_flush(nmethod* nm);
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 21767
diff changeset
   128
  static void print();   // Printing/debugging
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5924
diff changeset
   130
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5924
diff changeset
   131
#endif // SHARE_VM_RUNTIME_SWEEPER_HPP