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-- |
1 | 1 |
/* |
46702 | 2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_SWEEPER_HPP |
26 |
#define SHARE_VM_RUNTIME_SWEEPER_HPP |
|
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 | 33 |
class CodeBlobClosure; |
34 |
||
1 | 35 |
// An NmethodSweeper is an incremental cleaner for: |
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 | 59 |
|
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 | 67 |
static long _traversals; // Stack scan count, also sweep ID. |
68 |
static long _total_nof_code_cache_sweeps; // Total number of full sweeps of the code cache |
|
69 |
static long _time_counter; // Virtual time used to periodically invoke sweeper |
|
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 | 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 | 74 |
static volatile int _sweep_started; // Flag to control conc sweeper |
75 |
static volatile bool _should_sweep; // Indicates if we should invoke the sweeper |
|
30205 | 76 |
static volatile bool _force_sweep; // Indicates if we should force a sweep |
26796 | 77 |
static volatile int _bytes_changed; // Counts the total nmethod size if the nmethod changed from: |
78 |
// 1) alive -> not_entrant |
|
79 |
// 2) not_entrant -> zombie |
|
18025 | 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 | 86 |
static Tickspan _total_time_sweeping; // Accumulated time sweeping |
87 |
static Tickspan _total_time_this_sweep; // Total time this sweep |
|
88 |
static Tickspan _peak_sweep_time; // Peak time for a full sweep |
|
89 |
static Tickspan _peak_sweep_fraction_time; // Peak time sweeping one fraction |
|
18025 | 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 | 102 |
public: |
18025 | 103 |
static long traversal_count() { return _traversals; } |
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 | 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 | 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 | 122 |
static void force_sweep(); |
1 | 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 | 129 |
}; |
7397 | 130 |
|
131 |
#endif // SHARE_VM_RUNTIME_SWEEPER_HPP |