src/hotspot/share/runtime/sweeper.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46702 hotspot/src/share/vm/runtime/sweeper.hpp@13ae789b982e
child 49611 973c9504178e
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 38133
diff changeset
     2
 * Copyright (c) 1997, 2017, 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
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 38133
diff changeset
    33
class CodeBlobClosure;
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 38133
diff changeset
    34
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// An NmethodSweeper is an incremental cleaner for:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//    - cleanup inline caches
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    37
//    - reclamation of nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    38
// 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
    39
//  1) mark active nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    40
//     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
    41
//     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
    42
//  2) sweep nmethods
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    43
//     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
    44
//     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
    45
//     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
    46
//     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
    47
//     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
    48
//     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
    49
//     be made not-entrant by (i) the sweeper, (ii) deoptimization, (iii) dependency
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 33160
diff changeset
    50
//     invalidation, and (iv) being replaced by a different method version (tiered
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 33160
diff changeset
    51
//     compilation). Not-entrant nmethods cannot be called by Java threads, but they
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 33160
diff changeset
    52
//     can still be active on the stack. To ensure that active nmethods are not reclaimed,
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    53
//     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
    54
//     nmethod was NOT marked as active, it can be converted to 'zombie' state. To safely
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 33160
diff changeset
    55
//     remove the nmethod, all inline caches (IC) that point to the nmethod must be
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
    56
//     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
    57
//     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
    58
//     nmethod's space is freed.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
class NMethodSweeper : public AllStatic {
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
    61
 private:
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    62
  enum MethodStateChange {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    63
    None,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    64
    MadeZombie,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    65
    Flushed
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    66
  };
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    67
  static long      _traversals;                   // Stack scan count, also sweep ID.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    68
  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
    69
  static long      _time_counter;                 // Virtual time used to periodically invoke sweeper
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    70
  static long      _last_sweep;                   // Value of _time_counter when the last sweep happened
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36818
diff changeset
    71
  static CompiledMethodIterator _current;         // Current compiled method
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    72
  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
    73
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    74
  static volatile int  _sweep_started;            // Flag to control conc sweeper
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    75
  static volatile bool _should_sweep;             // Indicates if we should invoke the sweeper
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 27917
diff changeset
    76
  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
    77
  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
    78
                                                  //   1) alive       -> not_entrant
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 24442
diff changeset
    79
                                                  //   2) not_entrant -> zombie
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
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36818
diff changeset
    93
  static MethodStateChange process_compiled_method(CompiledMethod *nm);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36818
diff changeset
    94
  static void              release_compiled_method(CompiledMethod* 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
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   112
  // Keep track of sweeper activity in the ring buffer
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36818
diff changeset
   113
  static void record_sweep(CompiledMethod* nm, int line);
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   114
  static void report_events(int id, address entry);
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   115
  static void report_events();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   116
#endif
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 7397
diff changeset
   117
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 19339
diff changeset
   118
  static void mark_active_nmethods();      // Invoked at the end of each safepoint
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 38133
diff changeset
   119
  static CodeBlobClosure* prepare_mark_active_nmethods();
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