annotate src/share/vm/runtime/sweeper.cpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents 78bbf4d43a14
children 52b4284cb496 ce8f6bb717c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17795
diff changeset
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1538
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1538
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1538
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
26 #include "code/codeCache.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
27 #include "code/compiledIC.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
28 #include "code/icBuffer.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
29 #include "code/nmethod.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
30 #include "compiler/compileBroker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
31 #include "memory/resourceArea.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
32 #include "oops/method.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
33 #include "runtime/atomic.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
34 #include "runtime/compilationPolicy.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
35 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
36 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
37 #include "runtime/sweeper.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
38 #include "runtime/vm_operations.hpp"
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
39 #include "trace/tracing.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
40 #include "utilities/events.hpp"
13400
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
41 #include "utilities/ticks.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
42 #include "utilities/xmlstream.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17795
diff changeset
44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17795
diff changeset
45
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
46 #ifdef ASSERT
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
47
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
48 #define SWEEP(nm) record_sweep(nm, __LINE__)
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
49 // Sweeper logging code
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
50 class SweeperRecord {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
51 public:
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
52 int traversal;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
53 int invocation;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
54 int compile_id;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
55 long traversal_mark;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
56 int state;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
57 const char* kind;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
58 address vep;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
59 address uep;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
60 int line;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
61
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
62 void print() {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
63 tty->print_cr("traversal = %d invocation = %d compile_id = %d %s uep = " PTR_FORMAT " vep = "
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
64 PTR_FORMAT " state = %d traversal_mark %d line = %d",
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
65 traversal,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
66 invocation,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
67 compile_id,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
68 kind == NULL ? "" : kind,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
69 uep,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
70 vep,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
71 state,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
72 traversal_mark,
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
73 line);
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
74 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
75 };
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
76
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
77 static int _sweep_index = 0;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
78 static SweeperRecord* _records = NULL;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
79
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
80 void NMethodSweeper::report_events(int id, address entry) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
81 if (_records != NULL) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
82 for (int i = _sweep_index; i < SweeperLogEntries; i++) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
83 if (_records[i].uep == entry ||
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
84 _records[i].vep == entry ||
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
85 _records[i].compile_id == id) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
86 _records[i].print();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
87 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
88 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
89 for (int i = 0; i < _sweep_index; i++) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
90 if (_records[i].uep == entry ||
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
91 _records[i].vep == entry ||
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
92 _records[i].compile_id == id) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
93 _records[i].print();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
94 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
95 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
96 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
97 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
98
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
99 void NMethodSweeper::report_events() {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
100 if (_records != NULL) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
101 for (int i = _sweep_index; i < SweeperLogEntries; i++) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
102 // skip empty records
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
103 if (_records[i].vep == NULL) continue;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
104 _records[i].print();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
105 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
106 for (int i = 0; i < _sweep_index; i++) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
107 // skip empty records
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
108 if (_records[i].vep == NULL) continue;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
109 _records[i].print();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
110 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
111 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
112 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
113
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
114 void NMethodSweeper::record_sweep(nmethod* nm, int line) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
115 if (_records != NULL) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
116 _records[_sweep_index].traversal = _traversals;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
117 _records[_sweep_index].traversal_mark = nm->_stack_traversal_mark;
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
118 _records[_sweep_index].invocation = _sweep_fractions_left;
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
119 _records[_sweep_index].compile_id = nm->compile_id();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
120 _records[_sweep_index].kind = nm->compile_kind();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
121 _records[_sweep_index].state = nm->_state;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
122 _records[_sweep_index].vep = nm->verified_entry_point();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
123 _records[_sweep_index].uep = nm->entry_point();
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
124 _records[_sweep_index].line = line;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
125 _sweep_index = (_sweep_index + 1) % SweeperLogEntries;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
126 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
127 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
128 #else
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
129 #define SWEEP(nm)
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
130 #endif
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
131
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
132 nmethod* NMethodSweeper::_current = NULL; // Current nmethod
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
133 long NMethodSweeper::_traversals = 0; // Stack scan count, also sweep ID.
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
134 long NMethodSweeper::_total_nof_code_cache_sweeps = 0; // Total number of full sweeps of the code cache
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
135 long NMethodSweeper::_time_counter = 0; // Virtual time used to periodically invoke sweeper
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
136 long NMethodSweeper::_last_sweep = 0; // Value of _time_counter when the last sweep happened
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
137 int NMethodSweeper::_seen = 0; // Nof. nmethod we have currently processed in current pass of CodeCache
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
138 int NMethodSweeper::_flushed_count = 0; // Nof. nmethods flushed in current sweep
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
139 int NMethodSweeper::_zombified_count = 0; // Nof. nmethods made zombie in current sweep
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
140 int NMethodSweeper::_marked_for_reclamation_count = 0; // Nof. nmethods marked for reclaim in current sweep
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
142 volatile bool NMethodSweeper::_should_sweep = true; // Indicates if we should invoke the sweeper
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
143 volatile int NMethodSweeper::_sweep_fractions_left = 0; // Nof. invocations left until we are completed with this pass
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
144 volatile int NMethodSweeper::_sweep_started = 0; // Flag to control conc sweeper
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
145 volatile int NMethodSweeper::_bytes_changed = 0; // Counts the total nmethod size if the nmethod changed from:
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
146 // 1) alive -> not_entrant
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
147 // 2) not_entrant -> zombie
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
148 // 3) zombie -> marked_for_reclamation
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
149 int NMethodSweeper::_hotness_counter_reset_val = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
151 long NMethodSweeper::_total_nof_methods_reclaimed = 0; // Accumulated nof methods flushed
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
152 long NMethodSweeper::_total_nof_c2_methods_reclaimed = 0; // Accumulated nof methods flushed
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
153 size_t NMethodSweeper::_total_flushed_size = 0; // Total number of bytes flushed from the code cache
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
154 Tickspan NMethodSweeper::_total_time_sweeping; // Accumulated time sweeping
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
155 Tickspan NMethodSweeper::_total_time_this_sweep; // Total time this sweep
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
156 Tickspan NMethodSweeper::_peak_sweep_time; // Peak time for a full sweep
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
157 Tickspan NMethodSweeper::_peak_sweep_fraction_time; // Peak time sweeping one fraction
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
158
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
159
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
160
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
161 class MarkActivationClosure: public CodeBlobClosure {
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
162 public:
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
163 virtual void do_code_blob(CodeBlob* cb) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
164 if (cb->is_nmethod()) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
165 nmethod* nm = (nmethod*)cb;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
166 nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
167 // If we see an activation belonging to a non_entrant nmethod, we mark it.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
168 if (nm->is_not_entrant()) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
169 nm->mark_as_seen_on_stack();
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
170 }
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
171 }
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
172 }
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
173 };
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
174 static MarkActivationClosure mark_activation_closure;
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
175
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
176 class SetHotnessClosure: public CodeBlobClosure {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
177 public:
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
178 virtual void do_code_blob(CodeBlob* cb) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
179 if (cb->is_nmethod()) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
180 nmethod* nm = (nmethod*)cb;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
181 nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
182 }
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
183 }
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
184 };
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
185 static SetHotnessClosure set_hotness_closure;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
186
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
187
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
188 int NMethodSweeper::hotness_counter_reset_val() {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
189 if (_hotness_counter_reset_val == 0) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
190 _hotness_counter_reset_val = (ReservedCodeCacheSize < M) ? 1 : (ReservedCodeCacheSize / M) * 2;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
191 }
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
192 return _hotness_counter_reset_val;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
193 }
10206
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
194 bool NMethodSweeper::sweep_in_progress() {
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
195 return (_current != NULL);
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
196 }
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
197
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
198 // Scans the stacks of all Java threads and marks activations of not-entrant methods.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
199 // No need to synchronize access, since 'mark_active_nmethods' is always executed at a
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
200 // safepoint.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
201 void NMethodSweeper::mark_active_nmethods() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
203 // If we do not want to reclaim not-entrant or zombie methods there is no need
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
204 // to scan stacks
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
205 if (!MethodFlushing) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
206 return;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
207 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
208
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
209 // Increase time so that we can estimate when to invoke the sweeper again.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
210 _time_counter++;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
211
0
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // Check for restart
a61af66fc99e Initial load
duke
parents:
diff changeset
213 assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid");
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
214 if (!sweep_in_progress()) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
215 _seen = 0;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
216 _sweep_fractions_left = NmethodSweepFraction;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
217 _current = CodeCache::first_nmethod();
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
218 _traversals += 1;
13400
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
219 _total_time_this_sweep = Tickspan();
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
220
0
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (PrintMethodFlushing) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 tty->print_cr("### Sweep: stack traversal %d", _traversals);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
224 Threads::nmethods_do(&mark_activation_closure);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
226 } else {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
227 // Only set hotness counter
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
228 Threads::nmethods_do(&set_hotness_closure);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
231 OrderAccess::storestore();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
233 /**
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
234 * This function invokes the sweeper if at least one of the three conditions is met:
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
235 * (1) The code cache is getting full
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
236 * (2) There are sufficient state changes in/since the last sweep.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
237 * (3) We have not been sweeping for 'some time'
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
238 */
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
239 void NMethodSweeper::possibly_sweep() {
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
240 assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
13383
938e1e64e28f 8028306: nsk stress tests, CodeCache fills, then safepoint asserts
anoll
parents: 13074
diff changeset
241 // Only compiler threads are allowed to sweep
938e1e64e28f 8028306: nsk stress tests, CodeCache fills, then safepoint asserts
anoll
parents: 13074
diff changeset
242 if (!MethodFlushing || !sweep_in_progress() || !Thread::current()->is_Compiler_thread()) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
243 return;
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
244 }
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
245
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
246 // If there was no state change while nmethod sweeping, 'should_sweep' will be false.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
247 // This is one of the two places where should_sweep can be set to true. The general
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
248 // idea is as follows: If there is enough free space in the code cache, there is no
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
249 // need to invoke the sweeper. The following formula (which determines whether to invoke
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
250 // the sweeper or not) depends on the assumption that for larger ReservedCodeCacheSizes
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
251 // we need less frequent sweeps than for smaller ReservedCodecCacheSizes. Furthermore,
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
252 // the formula considers how much space in the code cache is currently used. Here are
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
253 // some examples that will (hopefully) help in understanding.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
254 //
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
255 // Small ReservedCodeCacheSizes: (e.g., < 16M) We invoke the sweeper every time, since
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
256 // the result of the division is 0. This
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
257 // keeps the used code cache size small
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
258 // (important for embedded Java)
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
259 // Large ReservedCodeCacheSize : (e.g., 256M + code cache is 10% full). The formula
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
260 // computes: (256 / 16) - 1 = 15
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
261 // As a result, we invoke the sweeper after
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
262 // 15 invocations of 'mark_active_nmethods.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
263 // Large ReservedCodeCacheSize: (e.g., 256M + code Cache is 90% full). The formula
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
264 // computes: (256 / 16) - 10 = 6.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
265 if (!_should_sweep) {
17610
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
266 const int time_since_last_sweep = _time_counter - _last_sweep;
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
267 // ReservedCodeCacheSize has an 'unsigned' type. We need a 'signed' type for max_wait_time,
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
268 // since 'time_since_last_sweep' can be larger than 'max_wait_time'. If that happens using
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
269 // an unsigned type would cause an underflow (wait_until_next_sweep becomes a large positive
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
270 // value) that disables the intended periodic sweeps.
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
271 const int max_wait_time = ReservedCodeCacheSize / (16 * M);
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
272 double wait_until_next_sweep = max_wait_time - time_since_last_sweep - CodeCache::reverse_free_ratio();
908afcc9d1cb 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 13400
diff changeset
273 assert(wait_until_next_sweep <= (double)max_wait_time, "Calculation of code cache sweeper interval is incorrect");
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
274
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
275 if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
276 _should_sweep = true;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
277 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
278 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
279
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
280 if (_should_sweep && _sweep_fractions_left > 0) {
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
281 // Only one thread at a time will sweep
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
282 jint old = Atomic::cmpxchg( 1, &_sweep_started, 0 );
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
283 if (old != 0) {
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
284 return;
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
285 }
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
286 #ifdef ASSERT
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
287 if (LogSweeper && _records == NULL) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
288 // Create the ring buffer for the logging code
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4945
diff changeset
289 _records = NEW_C_HEAP_ARRAY(SweeperRecord, SweeperLogEntries, mtGC);
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
290 memset(_records, 0, sizeof(SweeperRecord) * SweeperLogEntries);
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
291 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
292 #endif
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
293
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
294 if (_sweep_fractions_left > 0) {
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
295 sweep_code_cache();
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
296 _sweep_fractions_left--;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
297 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
298
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
299 // We are done with sweeping the code cache once.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
300 if (_sweep_fractions_left == 0) {
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
301 _total_nof_code_cache_sweeps++;
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
302 _last_sweep = _time_counter;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
303 // Reset flag; temporarily disables sweeper
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
304 _should_sweep = false;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
305 // If there was enough state change, 'possibly_enable_sweeper()'
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
306 // sets '_should_sweep' to true
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
307 possibly_enable_sweeper();
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
308 // Reset _bytes_changed only if there was enough state change. _bytes_changed
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
309 // can further increase by calls to 'report_state_change'.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
310 if (_should_sweep) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
311 _bytes_changed = 0;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
312 }
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
313 }
14443
3205e78d8193 8029396: PPC64 (part 212): Several memory ordering fixes in C-code.
goetz
parents: 13400
diff changeset
314 // Release work, because another compiler thread could continue.
3205e78d8193 8029396: PPC64 (part 212): Several memory ordering fixes in C-code.
goetz
parents: 13400
diff changeset
315 OrderAccess::release_store((int*)&_sweep_started, 0);
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
316 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
317 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
318
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
319 void NMethodSweeper::sweep_code_cache() {
13400
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
320 Ticks sweep_start_counter = Ticks::now();
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
321
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
322 _flushed_count = 0;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
323 _zombified_count = 0;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
324 _marked_for_reclamation_count = 0;
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
325
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
326 if (PrintMethodFlushing && Verbose) {
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
327 tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_nmethods(), _sweep_fractions_left);
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
328 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
329
10206
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
330 if (!CompileBroker::should_compile_new_jobs()) {
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
331 // If we have turned off compilations we might as well do full sweeps
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
332 // in order to reach the clean state faster. Otherwise the sleeping compiler
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
333 // threads will slow down sweeping.
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
334 _sweep_fractions_left = 1;
10206
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
335 }
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
336
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
337 // We want to visit all nmethods after NmethodSweepFraction
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
338 // invocations so divide the remaining number of nmethods by the
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
339 // remaining number of invocations. This is only an estimate since
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
340 // the number of nmethods changes during the sweep so the final
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
341 // stage must iterate until it there are no more nmethods.
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
342 int todo = (CodeCache::nof_nmethods() - _seen) / _sweep_fractions_left;
12266
ab274453d37f 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount
anoll
parents: 10405
diff changeset
343 int swept_count = 0;
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
344
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
345
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
346 assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
347 assert(!CodeCache_lock->owned_by_self(), "just checking");
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
348
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
349 int freed_memory = 0;
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
350 {
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
351 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
352
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
353 // The last invocation iterates until there are no more nmethods
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
354 for (int i = 0; (i < todo || _sweep_fractions_left == 1) && _current != NULL; i++) {
12266
ab274453d37f 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount
anoll
parents: 10405
diff changeset
355 swept_count++;
4945
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
356 if (SafepointSynchronize::is_synchronizing()) { // Safepoint request
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
357 if (PrintMethodFlushing && Verbose) {
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
358 tty->print_cr("### Sweep at %d out of %d, invocation: %d, yielding to safepoint", _seen, CodeCache::nof_nmethods(), _sweep_fractions_left);
4945
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
359 }
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
360 MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
361
4945
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
362 assert(Thread::current()->is_Java_thread(), "should be java thread");
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
363 JavaThread* thread = (JavaThread*)Thread::current();
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
364 ThreadBlockInVM tbivm(thread);
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
365 thread->java_suspend_self();
cfdfbeac0a5b 7145345: Code cache sweeper must cooperate with safepoints
iveresov
parents: 3384
diff changeset
366 }
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
367 // Since we will give up the CodeCache_lock, always skip ahead
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
368 // to the next nmethod. Other blobs can be deleted by other
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
369 // threads but nmethods are only reclaimed by the sweeper.
1615
ff38d05ea86f 6956958: assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted() || is_optimized() || is_megam
never
parents: 1552
diff changeset
370 nmethod* next = CodeCache::next_nmethod(_current);
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
371
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
372 // Now ready to process nmethod and give up CodeCache_lock
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
373 {
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
374 MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
375 freed_memory += process_nmethod(_current);
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
376 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
377 _seen++;
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
378 _current = next;
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
379 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
380 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
381
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
382 assert(_sweep_fractions_left > 1 || _current == NULL, "must have scanned the whole cache");
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
383
13400
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
384 const Ticks sweep_end_counter = Ticks::now();
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
385 const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
386 _total_time_sweeping += sweep_time;
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
387 _total_time_this_sweep += sweep_time;
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
388 _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
389 _total_flushed_size += freed_memory;
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
390 _total_nof_methods_reclaimed += _flushed_count;
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
391
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
392 EventSweepCodeCache event(UNTIMED);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
393 if (event.should_commit()) {
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
394 event.set_starttime(sweep_start_counter);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
395 event.set_endtime(sweep_end_counter);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
396 event.set_sweepIndex(_traversals);
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
397 event.set_sweepFractionIndex(NmethodSweepFraction - _sweep_fractions_left + 1);
12266
ab274453d37f 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount
anoll
parents: 10405
diff changeset
398 event.set_sweptCount(swept_count);
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
399 event.set_flushedCount(_flushed_count);
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
400 event.set_markedCount(_marked_for_reclamation_count);
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
401 event.set_zombifiedCount(_zombified_count);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
402 event.commit();
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
403 }
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
404
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
405 #ifdef ASSERT
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
406 if(PrintMethodFlushing) {
13400
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
407 tty->print_cr("### sweeper: sweep time(%d): "
86e6d691f2e1 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 13383
diff changeset
408 INT64_FORMAT, _sweep_fractions_left, (jlong)sweep_time.value());
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
409 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
410 #endif
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
411
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
412 if (_sweep_fractions_left == 1) {
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
413 _peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep);
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
414 log_sweep("finished");
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
415 }
10206
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
416
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
417 // Sweeper is the only case where memory is released, check here if it
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
418 // is time to restart the compiler. Only checking if there is a certain
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
419 // amount of free memory in the code cache might lead to re-enabling
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
420 // compilation although no memory has been released. For example, there are
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
421 // cases when compilation was disabled although there is 4MB (or more) free
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
422 // memory in the code cache. The reason is code cache fragmentation. Therefore,
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
423 // it only makes sense to re-enable compilation if we have actually freed memory.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
424 // Note that typically several kB are released for sweeping 16MB of the code
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
425 // cache. As a result, 'freed_memory' > 0 to restart the compiler.
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
426 if (!CompileBroker::should_compile_new_jobs() && (freed_memory > 0)) {
10206
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
427 CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
428 log_sweep("restart_compiler");
0cfa93c2fcc4 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 6725
diff changeset
429 }
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
430 }
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
431
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
432 /**
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
433 * This function updates the sweeper statistics that keep track of nmethods
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
434 * state changes. If there is 'enough' state change, the sweeper is invoked
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
435 * as soon as possible. There can be data races on _bytes_changed. The data
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
436 * races are benign, since it does not matter if we loose a couple of bytes.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
437 * In the worst case we call the sweeper a little later. Also, we are guaranteed
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
438 * to invoke the sweeper if the code cache gets full.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
439 */
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
440 void NMethodSweeper::report_state_change(nmethod* nm) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
441 _bytes_changed += nm->total_size();
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
442 possibly_enable_sweeper();
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
443 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
444
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
445 /**
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
446 * Function determines if there was 'enough' state change in the code cache to invoke
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
447 * the sweeper again. Currently, we determine 'enough' as more than 1% state change in
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
448 * the code cache since the last sweep.
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
449 */
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
450 void NMethodSweeper::possibly_enable_sweeper() {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
451 double percent_changed = ((double)_bytes_changed / (double)ReservedCodeCacheSize) * 100;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
452 if (percent_changed > 1.0) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
453 _should_sweep = true;
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
454 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
455 }
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
456
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
457 class NMethodMarker: public StackObj {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
458 private:
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
459 CompilerThread* _thread;
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
460 public:
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
461 NMethodMarker(nmethod* nm) {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
462 _thread = CompilerThread::current();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
463 if (!nm->is_zombie() && !nm->is_unloaded()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
464 // Only expose live nmethods for scanning
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
465 _thread->set_scanned_nmethod(nm);
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
466 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
467 }
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
468 ~NMethodMarker() {
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
469 _thread->set_scanned_nmethod(NULL);
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
470 }
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
471 };
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
472
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
473 void NMethodSweeper::release_nmethod(nmethod *nm) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
474 // Clean up any CompiledICHolders
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
475 {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
476 ResourceMark rm;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
477 MutexLocker ml_patch(CompiledIC_lock);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
478 RelocIterator iter(nm);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
479 while (iter.next()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
480 if (iter.type() == relocInfo::virtual_call_type) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
481 CompiledIC::cleanup_call_site(iter.virtual_call_reloc());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
482 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
483 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
484 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
485
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
486 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
487 nm->flush();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
488 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
489
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
490 int NMethodSweeper::process_nmethod(nmethod *nm) {
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
491 assert(!CodeCache_lock->owned_by_self(), "just checking");
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
492
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
493 int freed_memory = 0;
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
494 // Make sure this nmethod doesn't get unloaded during the scan,
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
495 // since safepoints may happen during acquired below locks.
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
496 NMethodMarker nmm(nm);
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
497 SWEEP(nm);
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
498
0
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // Skip methods that are currently referenced by the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (nm->is_locked_by_vm()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // But still remember to clean-up inline caches for alive nmethods
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (nm->is_alive()) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
503 // Clean inline caches that point to zombie/non-entrant methods
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
504 MutexLocker cl(CompiledIC_lock);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
505 nm->cleanup_inline_caches();
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
506 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
508 return freed_memory;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 if (nm->is_zombie()) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
512 // If it is the first time we see nmethod then we mark it. Otherwise,
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
513 // we reclaim it. When we have seen a zombie method twice, we know that
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
514 // there are no inline caches that refer to it.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (nm->is_marked_for_reclamation()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods");
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
517 if (PrintMethodFlushing && Verbose) {
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
518 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
519 }
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
520 freed_memory = nm->total_size();
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
521 if (nm->is_compiled_by_c2()) {
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
522 _total_nof_c2_methods_reclaimed++;
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
523 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
524 release_nmethod(nm);
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
525 _flushed_count++;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
526 } else {
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
527 if (PrintMethodFlushing && Verbose) {
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
528 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
529 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
530 nm->mark_for_reclamation();
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
531 // Keep track of code cache state change
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
532 _bytes_changed += nm->total_size();
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
533 _marked_for_reclamation_count++;
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
534 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536 } else if (nm->is_not_entrant()) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
537 // If there are no current activations of this method on the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // stack we can safely convert it to a zombie method
a61af66fc99e Initial load
duke
parents:
diff changeset
539 if (nm->can_not_entrant_be_converted()) {
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
540 if (PrintMethodFlushing && Verbose) {
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
541 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (not entrant) being made zombie", nm->compile_id(), nm);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
542 }
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
543 // Code cache state change is tracked in make_zombie()
0
a61af66fc99e Initial load
duke
parents:
diff changeset
544 nm->make_zombie();
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
545 _zombified_count++;
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
546 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
547 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // Still alive, clean up its inline caches
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
549 MutexLocker cl(CompiledIC_lock);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
550 nm->cleanup_inline_caches();
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
551 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553 } else if (nm->is_unloaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // Unloaded code, just make it a zombie
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
555 if (PrintMethodFlushing && Verbose) {
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
556 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm);
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
557 }
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 0
diff changeset
558 if (nm->is_osr_method()) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
559 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // No inline caches will ever point to osr methods, so we can just remove it
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
561 freed_memory = nm->total_size();
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
562 if (nm->is_compiled_by_c2()) {
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
563 _total_nof_c2_methods_reclaimed++;
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
564 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
565 release_nmethod(nm);
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
566 _flushed_count++;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
567 } else {
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
568 // Code cache state change is tracked in make_zombie()
0
a61af66fc99e Initial load
duke
parents:
diff changeset
569 nm->make_zombie();
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10206
diff changeset
570 _zombified_count++;
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
571 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
573 } else {
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
574 if (UseCodeCacheFlushing) {
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
575 if (!nm->is_locked_by_vm() && !nm->is_osr_method() && !nm->is_native_method()) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
576 // Do not make native methods and OSR-methods not-entrant
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
577 nm->dec_hotness_counter();
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
578 // Get the initial value of the hotness counter. This value depends on the
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
579 // ReservedCodeCacheSize
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
580 int reset_val = hotness_counter_reset_val();
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
581 int time_since_reset = reset_val - nm->hotness_counter();
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
582 double threshold = -reset_val + (CodeCache::reverse_free_ratio() * NmethodSweepActivity);
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
583 // The less free space in the code cache we have - the bigger reverse_free_ratio() is.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
584 // I.e., 'threshold' increases with lower available space in the code cache and a higher
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
585 // NmethodSweepActivity. If the current hotness counter - which decreases from its initial
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
586 // value until it is reset by stack walking - is smaller than the computed threshold, the
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
587 // corresponding nmethod is considered for removal.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
588 if ((NmethodSweepActivity > 0) && (nm->hotness_counter() < threshold) && (time_since_reset > 10)) {
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
589 // A method is marked as not-entrant if the method is
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
590 // 1) 'old enough': nm->hotness_counter() < threshold
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
591 // 2) The method was in_use for a minimum amount of time: (time_since_reset > 10)
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
592 // The second condition is necessary if we are dealing with very small code cache
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
593 // sizes (e.g., <10m) and the code cache size is too small to hold all hot methods.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
594 // The second condition ensures that methods are not immediately made not-entrant
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
595 // after compilation.
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
596 nm->make_not_entrant();
13074
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
597 // Code cache state change is tracked in make_not_entrant()
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
598 if (PrintMethodFlushing && Verbose) {
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
599 tty->print_cr("### Nmethod %d/" PTR_FORMAT "made not-entrant: hotness counter %d/%d threshold %f",
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
600 nm->compile_id(), nm, nm->hotness_counter(), reset_val, threshold);
78da3894b86f 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 12324
diff changeset
601 }
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
602 }
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
603 }
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
604 }
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
605 // Clean-up all inline caches that point to zombie/non-reentrant methods
1538
bfe29ec02863 6950075: nmethod sweeper should operate concurrently
never
parents: 1202
diff changeset
606 MutexLocker cl(CompiledIC_lock);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
607 nm->cleanup_inline_caches();
3384
f52ed367b66d 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 2482
diff changeset
608 SWEEP(nm);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
609 }
12324
510fbd28919c 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 12266
diff changeset
610 return freed_memory;
1202
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
611 }
5f24d0319e54 4360113: Evict nmethods when code cache gets full
kvn
parents: 1000
diff changeset
612
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
613 // Print out some state information about the current sweep and the
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
614 // state of the code cache if it's requested.
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
615 void NMethodSweeper::log_sweep(const char* msg, const char* format, ...) {
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
616 if (PrintMethodFlushing) {
2482
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
617 stringStream s;
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
618 // Dump code cache state into a buffer before locking the tty,
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
619 // because log_state() will use locks causing lock conflicts.
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
620 CodeCache::log_state(&s);
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
621
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
622 ttyLocker ttyl;
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
623 tty->print("### sweeper: %s ", msg);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
624 if (format != NULL) {
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
625 va_list ap;
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
626 va_start(ap, format);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
627 tty->vprint(format, ap);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
628 va_end(ap);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
629 }
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17795
diff changeset
630 tty->print_cr("%s", s.as_string());
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
631 }
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
632
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
633 if (LogCompilation && (xtty != NULL)) {
2482
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
634 stringStream s;
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
635 // Dump code cache state into a buffer before locking the tty,
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
636 // because log_state() will use locks causing lock conflicts.
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
637 CodeCache::log_state(&s);
dbccacb79c63 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 2426
diff changeset
638
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
639 ttyLocker ttyl;
1646
8d5934a77f10 6968385: malformed xml in sweeper logging
never
parents: 1644
diff changeset
640 xtty->begin_elem("sweeper state='%s' traversals='" INTX_FORMAT "' ", msg, (intx)traversal_count());
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
641 if (format != NULL) {
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
642 va_list ap;
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
643 va_start(ap, format);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
644 xtty->vprint(format, ap);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
645 va_end(ap);
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
646 }
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17795
diff changeset
647 xtty->print("%s", s.as_string());
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
648 xtty->stamp();
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
649 xtty->end_elem();
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
650 }
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1615
diff changeset
651 }
17612
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
652
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
653 void NMethodSweeper::print() {
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
654 ttyLocker ttyl;
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
655 tty->print_cr("Code cache sweeper statistics:");
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
656 tty->print_cr(" Total sweep time: %1.0lfms", (double)_total_time_sweeping.value()/1000000);
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
657 tty->print_cr(" Total number of full sweeps: %ld", _total_nof_code_cache_sweeps);
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
658 tty->print_cr(" Total number of flushed methods: %ld(%ld C2 methods)", _total_nof_methods_reclaimed,
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
659 _total_nof_c2_methods_reclaimed);
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
660 tty->print_cr(" Total size of flushed methods: " SIZE_FORMAT "kB", _total_flushed_size/K);
6aa49042b101 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 17610
diff changeset
661 }