Mon, 07 Jul 2014 10:12:40 +0200
8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "code/codeBlob.hpp" |
stefank@2314 | 27 | #include "code/codeCache.hpp" |
coleenp@4037 | 28 | #include "code/compiledIC.hpp" |
stefank@2314 | 29 | #include "code/dependencies.hpp" |
coleenp@4037 | 30 | #include "code/icBuffer.hpp" |
stefank@2314 | 31 | #include "code/nmethod.hpp" |
stefank@2314 | 32 | #include "code/pcDesc.hpp" |
vladidan@4438 | 33 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 34 | #include "gc_implementation/shared/markSweep.hpp" |
stefank@2314 | 35 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 36 | #include "memory/gcLocker.hpp" |
stefank@2314 | 37 | #include "memory/iterator.hpp" |
stefank@2314 | 38 | #include "memory/resourceArea.hpp" |
coleenp@4037 | 39 | #include "oops/method.hpp" |
stefank@2314 | 40 | #include "oops/objArrayOop.hpp" |
stefank@2314 | 41 | #include "oops/oop.inline.hpp" |
stefank@2314 | 42 | #include "runtime/handles.inline.hpp" |
vladidan@4438 | 43 | #include "runtime/arguments.hpp" |
stefank@2314 | 44 | #include "runtime/icache.hpp" |
stefank@2314 | 45 | #include "runtime/java.hpp" |
stefank@2314 | 46 | #include "runtime/mutexLocker.hpp" |
stefank@2314 | 47 | #include "services/memoryService.hpp" |
sla@5237 | 48 | #include "trace/tracing.hpp" |
stefank@2314 | 49 | #include "utilities/xmlstream.hpp" |
duke@435 | 50 | |
duke@435 | 51 | // Helper class for printing in CodeCache |
duke@435 | 52 | |
duke@435 | 53 | class CodeBlob_sizes { |
duke@435 | 54 | private: |
duke@435 | 55 | int count; |
duke@435 | 56 | int total_size; |
duke@435 | 57 | int header_size; |
duke@435 | 58 | int code_size; |
duke@435 | 59 | int stub_size; |
duke@435 | 60 | int relocation_size; |
duke@435 | 61 | int scopes_oop_size; |
coleenp@4037 | 62 | int scopes_metadata_size; |
duke@435 | 63 | int scopes_data_size; |
duke@435 | 64 | int scopes_pcs_size; |
duke@435 | 65 | |
duke@435 | 66 | public: |
duke@435 | 67 | CodeBlob_sizes() { |
duke@435 | 68 | count = 0; |
duke@435 | 69 | total_size = 0; |
duke@435 | 70 | header_size = 0; |
duke@435 | 71 | code_size = 0; |
duke@435 | 72 | stub_size = 0; |
duke@435 | 73 | relocation_size = 0; |
duke@435 | 74 | scopes_oop_size = 0; |
coleenp@4037 | 75 | scopes_metadata_size = 0; |
duke@435 | 76 | scopes_data_size = 0; |
duke@435 | 77 | scopes_pcs_size = 0; |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | int total() { return total_size; } |
duke@435 | 81 | bool is_empty() { return count == 0; } |
duke@435 | 82 | |
duke@435 | 83 | void print(const char* title) { |
drchase@6680 | 84 | tty->print_cr(" #%d %s = %dK (hdr %d%%, loc %d%%, code %d%%, stub %d%%, [oops %d%%, metadata %d%%, data %d%%, pcs %d%%])", |
duke@435 | 85 | count, |
duke@435 | 86 | title, |
drchase@6680 | 87 | (int)(total() / K), |
duke@435 | 88 | header_size * 100 / total_size, |
duke@435 | 89 | relocation_size * 100 / total_size, |
duke@435 | 90 | code_size * 100 / total_size, |
duke@435 | 91 | stub_size * 100 / total_size, |
duke@435 | 92 | scopes_oop_size * 100 / total_size, |
coleenp@4037 | 93 | scopes_metadata_size * 100 / total_size, |
duke@435 | 94 | scopes_data_size * 100 / total_size, |
duke@435 | 95 | scopes_pcs_size * 100 / total_size); |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | void add(CodeBlob* cb) { |
duke@435 | 99 | count++; |
duke@435 | 100 | total_size += cb->size(); |
duke@435 | 101 | header_size += cb->header_size(); |
duke@435 | 102 | relocation_size += cb->relocation_size(); |
duke@435 | 103 | if (cb->is_nmethod()) { |
twisti@1918 | 104 | nmethod* nm = cb->as_nmethod_or_null(); |
twisti@2103 | 105 | code_size += nm->insts_size(); |
duke@435 | 106 | stub_size += nm->stub_size(); |
duke@435 | 107 | |
twisti@1918 | 108 | scopes_oop_size += nm->oops_size(); |
coleenp@4037 | 109 | scopes_metadata_size += nm->metadata_size(); |
duke@435 | 110 | scopes_data_size += nm->scopes_data_size(); |
duke@435 | 111 | scopes_pcs_size += nm->scopes_pcs_size(); |
duke@435 | 112 | } else { |
twisti@2103 | 113 | code_size += cb->code_size(); |
duke@435 | 114 | } |
duke@435 | 115 | } |
duke@435 | 116 | }; |
duke@435 | 117 | |
duke@435 | 118 | // CodeCache implementation |
duke@435 | 119 | |
duke@435 | 120 | CodeHeap * CodeCache::_heap = new CodeHeap(); |
duke@435 | 121 | int CodeCache::_number_of_blobs = 0; |
never@1999 | 122 | int CodeCache::_number_of_adapters = 0; |
never@1999 | 123 | int CodeCache::_number_of_nmethods = 0; |
duke@435 | 124 | int CodeCache::_number_of_nmethods_with_dependencies = 0; |
duke@435 | 125 | bool CodeCache::_needs_cache_clean = false; |
jrose@1424 | 126 | nmethod* CodeCache::_scavenge_root_nmethods = NULL; |
duke@435 | 127 | |
sla@5237 | 128 | int CodeCache::_codemem_full_count = 0; |
duke@435 | 129 | |
duke@435 | 130 | CodeBlob* CodeCache::first() { |
duke@435 | 131 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 132 | return (CodeBlob*)_heap->first(); |
duke@435 | 133 | } |
duke@435 | 134 | |
duke@435 | 135 | |
duke@435 | 136 | CodeBlob* CodeCache::next(CodeBlob* cb) { |
duke@435 | 137 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 138 | return (CodeBlob*)_heap->next(cb); |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | |
duke@435 | 142 | CodeBlob* CodeCache::alive(CodeBlob *cb) { |
duke@435 | 143 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 144 | while (cb != NULL && !cb->is_alive()) cb = next(cb); |
duke@435 | 145 | return cb; |
duke@435 | 146 | } |
duke@435 | 147 | |
duke@435 | 148 | |
duke@435 | 149 | nmethod* CodeCache::alive_nmethod(CodeBlob* cb) { |
duke@435 | 150 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 151 | while (cb != NULL && (!cb->is_alive() || !cb->is_nmethod())) cb = next(cb); |
duke@435 | 152 | return (nmethod*)cb; |
duke@435 | 153 | } |
duke@435 | 154 | |
never@1893 | 155 | nmethod* CodeCache::first_nmethod() { |
never@1893 | 156 | assert_locked_or_safepoint(CodeCache_lock); |
never@1893 | 157 | CodeBlob* cb = first(); |
never@1893 | 158 | while (cb != NULL && !cb->is_nmethod()) { |
never@1893 | 159 | cb = next(cb); |
never@1893 | 160 | } |
never@1893 | 161 | return (nmethod*)cb; |
never@1893 | 162 | } |
never@1893 | 163 | |
never@1893 | 164 | nmethod* CodeCache::next_nmethod (CodeBlob* cb) { |
never@1893 | 165 | assert_locked_or_safepoint(CodeCache_lock); |
never@1893 | 166 | cb = next(cb); |
never@1893 | 167 | while (cb != NULL && !cb->is_nmethod()) { |
never@1893 | 168 | cb = next(cb); |
never@1893 | 169 | } |
never@1893 | 170 | return (nmethod*)cb; |
never@1893 | 171 | } |
duke@435 | 172 | |
vladidan@4438 | 173 | static size_t maxCodeCacheUsed = 0; |
vladidan@4438 | 174 | |
neliasso@4952 | 175 | CodeBlob* CodeCache::allocate(int size, bool is_critical) { |
duke@435 | 176 | // Do not seize the CodeCache lock here--if the caller has not |
duke@435 | 177 | // already done so, we are going to lose bigtime, since the code |
duke@435 | 178 | // cache will contain a garbage CodeBlob until the caller can |
duke@435 | 179 | // run the constructor for the CodeBlob subclass he is busy |
duke@435 | 180 | // instantiating. |
duke@435 | 181 | guarantee(size >= 0, "allocation request must be reasonable"); |
duke@435 | 182 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 183 | CodeBlob* cb = NULL; |
duke@435 | 184 | _number_of_blobs++; |
duke@435 | 185 | while (true) { |
neliasso@4952 | 186 | cb = (CodeBlob*)_heap->allocate(size, is_critical); |
duke@435 | 187 | if (cb != NULL) break; |
duke@435 | 188 | if (!_heap->expand_by(CodeCacheExpansionSize)) { |
duke@435 | 189 | // Expansion failed |
duke@435 | 190 | return NULL; |
duke@435 | 191 | } |
duke@435 | 192 | if (PrintCodeCacheExtension) { |
duke@435 | 193 | ResourceMark rm; |
drchase@6680 | 194 | tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)", |
neliasso@4952 | 195 | (intptr_t)_heap->low_boundary(), (intptr_t)_heap->high(), |
neliasso@4952 | 196 | (address)_heap->high() - (address)_heap->low_boundary()); |
duke@435 | 197 | } |
duke@435 | 198 | } |
vladidan@4438 | 199 | maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() - |
vladidan@4438 | 200 | (address)_heap->low_boundary()) - unallocated_capacity()); |
duke@435 | 201 | verify_if_often(); |
jrose@1424 | 202 | print_trace("allocation", cb, size); |
duke@435 | 203 | return cb; |
duke@435 | 204 | } |
duke@435 | 205 | |
duke@435 | 206 | void CodeCache::free(CodeBlob* cb) { |
duke@435 | 207 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 208 | verify_if_often(); |
duke@435 | 209 | |
jrose@1424 | 210 | print_trace("free", cb); |
never@1999 | 211 | if (cb->is_nmethod()) { |
never@1999 | 212 | _number_of_nmethods--; |
never@1999 | 213 | if (((nmethod *)cb)->has_dependencies()) { |
never@1999 | 214 | _number_of_nmethods_with_dependencies--; |
never@1999 | 215 | } |
never@1999 | 216 | } |
never@1999 | 217 | if (cb->is_adapter_blob()) { |
never@1999 | 218 | _number_of_adapters--; |
duke@435 | 219 | } |
duke@435 | 220 | _number_of_blobs--; |
duke@435 | 221 | |
duke@435 | 222 | _heap->deallocate(cb); |
duke@435 | 223 | |
duke@435 | 224 | verify_if_often(); |
duke@435 | 225 | assert(_number_of_blobs >= 0, "sanity check"); |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | |
duke@435 | 229 | void CodeCache::commit(CodeBlob* cb) { |
duke@435 | 230 | // this is called by nmethod::nmethod, which must already own CodeCache_lock |
duke@435 | 231 | assert_locked_or_safepoint(CodeCache_lock); |
never@1999 | 232 | if (cb->is_nmethod()) { |
never@1999 | 233 | _number_of_nmethods++; |
never@1999 | 234 | if (((nmethod *)cb)->has_dependencies()) { |
never@1999 | 235 | _number_of_nmethods_with_dependencies++; |
never@1999 | 236 | } |
duke@435 | 237 | } |
never@1999 | 238 | if (cb->is_adapter_blob()) { |
never@1999 | 239 | _number_of_adapters++; |
never@1999 | 240 | } |
never@1999 | 241 | |
duke@435 | 242 | // flush the hardware I-cache |
twisti@2103 | 243 | ICache::invalidate_range(cb->content_begin(), cb->content_size()); |
duke@435 | 244 | } |
duke@435 | 245 | |
duke@435 | 246 | |
duke@435 | 247 | void CodeCache::flush() { |
duke@435 | 248 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 249 | Unimplemented(); |
duke@435 | 250 | } |
duke@435 | 251 | |
duke@435 | 252 | |
duke@435 | 253 | // Iteration over CodeBlobs |
duke@435 | 254 | |
duke@435 | 255 | #define FOR_ALL_BLOBS(var) for (CodeBlob *var = first() ; var != NULL; var = next(var) ) |
duke@435 | 256 | #define FOR_ALL_ALIVE_BLOBS(var) for (CodeBlob *var = alive(first()); var != NULL; var = alive(next(var))) |
duke@435 | 257 | #define FOR_ALL_ALIVE_NMETHODS(var) for (nmethod *var = alive_nmethod(first()); var != NULL; var = alive_nmethod(next(var))) |
duke@435 | 258 | |
duke@435 | 259 | |
duke@435 | 260 | bool CodeCache::contains(void *p) { |
duke@435 | 261 | // It should be ok to call contains without holding a lock |
duke@435 | 262 | return _heap->contains(p); |
duke@435 | 263 | } |
duke@435 | 264 | |
duke@435 | 265 | |
duke@435 | 266 | // This method is safe to call without holding the CodeCache_lock, as long as a dead codeblob is not |
duke@435 | 267 | // looked up (i.e., one that has been marked for deletion). It only dependes on the _segmap to contain |
duke@435 | 268 | // valid indices, which it will always do, as long as the CodeBlob is not in the process of being recycled. |
duke@435 | 269 | CodeBlob* CodeCache::find_blob(void* start) { |
duke@435 | 270 | CodeBlob* result = find_blob_unsafe(start); |
duke@435 | 271 | if (result == NULL) return NULL; |
duke@435 | 272 | // We could potientially look up non_entrant methods |
duke@435 | 273 | guarantee(!result->is_zombie() || result->is_locked_by_vm() || is_error_reported(), "unsafe access to zombie method"); |
duke@435 | 274 | return result; |
duke@435 | 275 | } |
duke@435 | 276 | |
duke@435 | 277 | nmethod* CodeCache::find_nmethod(void* start) { |
duke@435 | 278 | CodeBlob *cb = find_blob(start); |
duke@435 | 279 | assert(cb == NULL || cb->is_nmethod(), "did not find an nmethod"); |
duke@435 | 280 | return (nmethod*)cb; |
duke@435 | 281 | } |
duke@435 | 282 | |
duke@435 | 283 | |
duke@435 | 284 | void CodeCache::blobs_do(void f(CodeBlob* nm)) { |
duke@435 | 285 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 286 | FOR_ALL_BLOBS(p) { |
duke@435 | 287 | f(p); |
duke@435 | 288 | } |
duke@435 | 289 | } |
duke@435 | 290 | |
duke@435 | 291 | |
duke@435 | 292 | void CodeCache::nmethods_do(void f(nmethod* nm)) { |
duke@435 | 293 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 294 | FOR_ALL_BLOBS(nm) { |
duke@435 | 295 | if (nm->is_nmethod()) f((nmethod*)nm); |
duke@435 | 296 | } |
duke@435 | 297 | } |
duke@435 | 298 | |
coleenp@4037 | 299 | void CodeCache::alive_nmethods_do(void f(nmethod* nm)) { |
coleenp@4037 | 300 | assert_locked_or_safepoint(CodeCache_lock); |
coleenp@4037 | 301 | FOR_ALL_ALIVE_NMETHODS(nm) { |
coleenp@4037 | 302 | f(nm); |
coleenp@4037 | 303 | } |
coleenp@4037 | 304 | } |
duke@435 | 305 | |
duke@435 | 306 | int CodeCache::alignment_unit() { |
duke@435 | 307 | return (int)_heap->alignment_unit(); |
duke@435 | 308 | } |
duke@435 | 309 | |
duke@435 | 310 | |
duke@435 | 311 | int CodeCache::alignment_offset() { |
duke@435 | 312 | return (int)_heap->alignment_offset(); |
duke@435 | 313 | } |
duke@435 | 314 | |
duke@435 | 315 | |
twisti@1918 | 316 | // Mark nmethods for unloading if they contain otherwise unreachable |
twisti@1918 | 317 | // oops. |
brutisso@4098 | 318 | void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) { |
duke@435 | 319 | assert_locked_or_safepoint(CodeCache_lock); |
twisti@1918 | 320 | FOR_ALL_ALIVE_NMETHODS(nm) { |
brutisso@4098 | 321 | nm->do_unloading(is_alive, unloading_occurred); |
duke@435 | 322 | } |
duke@435 | 323 | } |
duke@435 | 324 | |
jrose@1424 | 325 | void CodeCache::blobs_do(CodeBlobClosure* f) { |
duke@435 | 326 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 327 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 328 | f->do_code_blob(cb); |
jrose@1424 | 329 | |
jrose@1424 | 330 | #ifdef ASSERT |
jrose@1424 | 331 | if (cb->is_nmethod()) |
jrose@1424 | 332 | ((nmethod*)cb)->verify_scavenge_root_oops(); |
jrose@1424 | 333 | #endif //ASSERT |
duke@435 | 334 | } |
duke@435 | 335 | } |
duke@435 | 336 | |
jrose@1424 | 337 | // Walk the list of methods which might contain non-perm oops. |
jrose@1424 | 338 | void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) { |
jrose@1424 | 339 | assert_locked_or_safepoint(CodeCache_lock); |
stefank@6992 | 340 | |
stefank@6992 | 341 | if (UseG1GC) { |
stefank@6992 | 342 | return; |
stefank@6992 | 343 | } |
stefank@6992 | 344 | |
jrose@1424 | 345 | debug_only(mark_scavenge_root_nmethods()); |
jrose@1424 | 346 | |
jrose@1424 | 347 | for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { |
jrose@1424 | 348 | debug_only(cur->clear_scavenge_root_marked()); |
jrose@1424 | 349 | assert(cur->scavenge_root_not_marked(), ""); |
jrose@1424 | 350 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 351 | |
jrose@1424 | 352 | bool is_live = (!cur->is_zombie() && !cur->is_unloaded()); |
jrose@1424 | 353 | #ifndef PRODUCT |
jrose@1424 | 354 | if (TraceScavenge) { |
jrose@1424 | 355 | cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr(); |
jrose@1424 | 356 | } |
jrose@1424 | 357 | #endif //PRODUCT |
twisti@1798 | 358 | if (is_live) { |
jrose@1424 | 359 | // Perform cur->oops_do(f), maybe just once per nmethod. |
jrose@1424 | 360 | f->do_code_blob(cur); |
twisti@1798 | 361 | } |
jrose@1424 | 362 | } |
jrose@1424 | 363 | |
jrose@1424 | 364 | // Check for stray marks. |
jrose@1424 | 365 | debug_only(verify_perm_nmethods(NULL)); |
jrose@1424 | 366 | } |
jrose@1424 | 367 | |
jrose@1424 | 368 | void CodeCache::add_scavenge_root_nmethod(nmethod* nm) { |
jrose@1424 | 369 | assert_locked_or_safepoint(CodeCache_lock); |
stefank@6992 | 370 | |
stefank@6992 | 371 | if (UseG1GC) { |
stefank@6992 | 372 | return; |
stefank@6992 | 373 | } |
stefank@6992 | 374 | |
jrose@1424 | 375 | nm->set_on_scavenge_root_list(); |
jrose@1424 | 376 | nm->set_scavenge_root_link(_scavenge_root_nmethods); |
jrose@1424 | 377 | set_scavenge_root_nmethods(nm); |
jrose@1424 | 378 | print_trace("add_scavenge_root", nm); |
jrose@1424 | 379 | } |
jrose@1424 | 380 | |
jrose@1424 | 381 | void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) { |
jrose@1424 | 382 | assert_locked_or_safepoint(CodeCache_lock); |
stefank@6992 | 383 | |
stefank@6992 | 384 | if (UseG1GC) { |
stefank@6992 | 385 | return; |
stefank@6992 | 386 | } |
stefank@6992 | 387 | |
jrose@1424 | 388 | print_trace("drop_scavenge_root", nm); |
jrose@1424 | 389 | nmethod* last = NULL; |
jrose@1424 | 390 | nmethod* cur = scavenge_root_nmethods(); |
jrose@1424 | 391 | while (cur != NULL) { |
jrose@1424 | 392 | nmethod* next = cur->scavenge_root_link(); |
jrose@1424 | 393 | if (cur == nm) { |
jrose@1424 | 394 | if (last != NULL) |
jrose@1424 | 395 | last->set_scavenge_root_link(next); |
jrose@1424 | 396 | else set_scavenge_root_nmethods(next); |
jrose@1424 | 397 | nm->set_scavenge_root_link(NULL); |
jrose@1424 | 398 | nm->clear_on_scavenge_root_list(); |
jrose@1424 | 399 | return; |
jrose@1424 | 400 | } |
jrose@1424 | 401 | last = cur; |
jrose@1424 | 402 | cur = next; |
jrose@1424 | 403 | } |
jrose@1424 | 404 | assert(false, "should have been on list"); |
jrose@1424 | 405 | } |
jrose@1424 | 406 | |
jrose@1424 | 407 | void CodeCache::prune_scavenge_root_nmethods() { |
jrose@1424 | 408 | assert_locked_or_safepoint(CodeCache_lock); |
stefank@6992 | 409 | |
stefank@6992 | 410 | if (UseG1GC) { |
stefank@6992 | 411 | return; |
stefank@6992 | 412 | } |
stefank@6992 | 413 | |
jrose@1424 | 414 | debug_only(mark_scavenge_root_nmethods()); |
jrose@1424 | 415 | |
jrose@1424 | 416 | nmethod* last = NULL; |
jrose@1424 | 417 | nmethod* cur = scavenge_root_nmethods(); |
jrose@1424 | 418 | while (cur != NULL) { |
jrose@1424 | 419 | nmethod* next = cur->scavenge_root_link(); |
jrose@1424 | 420 | debug_only(cur->clear_scavenge_root_marked()); |
jrose@1424 | 421 | assert(cur->scavenge_root_not_marked(), ""); |
jrose@1424 | 422 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 423 | |
jrose@1424 | 424 | if (!cur->is_zombie() && !cur->is_unloaded() |
jrose@1424 | 425 | && cur->detect_scavenge_root_oops()) { |
jrose@1424 | 426 | // Keep it. Advance 'last' to prevent deletion. |
jrose@1424 | 427 | last = cur; |
jrose@1424 | 428 | } else { |
jrose@1424 | 429 | // Prune it from the list, so we don't have to look at it any more. |
jrose@1424 | 430 | print_trace("prune_scavenge_root", cur); |
jrose@1424 | 431 | cur->set_scavenge_root_link(NULL); |
jrose@1424 | 432 | cur->clear_on_scavenge_root_list(); |
jrose@1424 | 433 | if (last != NULL) |
jrose@1424 | 434 | last->set_scavenge_root_link(next); |
jrose@1424 | 435 | else set_scavenge_root_nmethods(next); |
jrose@1424 | 436 | } |
jrose@1424 | 437 | cur = next; |
jrose@1424 | 438 | } |
jrose@1424 | 439 | |
jrose@1424 | 440 | // Check for stray marks. |
jrose@1424 | 441 | debug_only(verify_perm_nmethods(NULL)); |
jrose@1424 | 442 | } |
jrose@1424 | 443 | |
jrose@1424 | 444 | #ifndef PRODUCT |
jrose@1424 | 445 | void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) { |
stefank@6992 | 446 | if (UseG1GC) { |
stefank@6992 | 447 | return; |
stefank@6992 | 448 | } |
stefank@6992 | 449 | |
jrose@1424 | 450 | // While we are here, verify the integrity of the list. |
jrose@1424 | 451 | mark_scavenge_root_nmethods(); |
jrose@1424 | 452 | for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { |
jrose@1424 | 453 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 454 | cur->clear_scavenge_root_marked(); |
jrose@1424 | 455 | } |
jrose@1424 | 456 | verify_perm_nmethods(f); |
jrose@1424 | 457 | } |
jrose@1424 | 458 | |
jrose@1424 | 459 | // Temporarily mark nmethods that are claimed to be on the non-perm list. |
jrose@1424 | 460 | void CodeCache::mark_scavenge_root_nmethods() { |
jrose@1424 | 461 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 462 | if (cb->is_nmethod()) { |
jrose@1424 | 463 | nmethod *nm = (nmethod*)cb; |
jrose@1424 | 464 | assert(nm->scavenge_root_not_marked(), "clean state"); |
jrose@1424 | 465 | if (nm->on_scavenge_root_list()) |
jrose@1424 | 466 | nm->set_scavenge_root_marked(); |
jrose@1424 | 467 | } |
jrose@1424 | 468 | } |
jrose@1424 | 469 | } |
jrose@1424 | 470 | |
jrose@1424 | 471 | // If the closure is given, run it on the unlisted nmethods. |
jrose@1424 | 472 | // Also make sure that the effects of mark_scavenge_root_nmethods is gone. |
jrose@1424 | 473 | void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) { |
jrose@1424 | 474 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 475 | bool call_f = (f_or_null != NULL); |
jrose@1424 | 476 | if (cb->is_nmethod()) { |
jrose@1424 | 477 | nmethod *nm = (nmethod*)cb; |
jrose@1424 | 478 | assert(nm->scavenge_root_not_marked(), "must be already processed"); |
jrose@1424 | 479 | if (nm->on_scavenge_root_list()) |
jrose@1424 | 480 | call_f = false; // don't show this one to the client |
jrose@1424 | 481 | nm->verify_scavenge_root_oops(); |
jrose@1424 | 482 | } else { |
jrose@1424 | 483 | call_f = false; // not an nmethod |
jrose@1424 | 484 | } |
jrose@1424 | 485 | if (call_f) f_or_null->do_code_blob(cb); |
jrose@1424 | 486 | } |
jrose@1424 | 487 | } |
jrose@1424 | 488 | #endif //PRODUCT |
jrose@1424 | 489 | |
stefank@6992 | 490 | void CodeCache::verify_clean_inline_caches() { |
stefank@6992 | 491 | #ifdef ASSERT |
stefank@6992 | 492 | FOR_ALL_ALIVE_BLOBS(cb) { |
stefank@6992 | 493 | if (cb->is_nmethod()) { |
stefank@6992 | 494 | nmethod* nm = (nmethod*)cb; |
stefank@6992 | 495 | assert(!nm->is_unloaded(), "Tautology"); |
stefank@6992 | 496 | nm->verify_clean_inline_caches(); |
stefank@6992 | 497 | nm->verify(); |
stefank@6992 | 498 | } |
stefank@6992 | 499 | } |
stefank@6992 | 500 | #endif |
stefank@6992 | 501 | } |
stefank@6992 | 502 | |
stefank@6992 | 503 | void CodeCache::verify_icholder_relocations() { |
stefank@6992 | 504 | #ifdef ASSERT |
stefank@6992 | 505 | // make sure that we aren't leaking icholders |
stefank@6992 | 506 | int count = 0; |
stefank@6992 | 507 | FOR_ALL_BLOBS(cb) { |
stefank@6992 | 508 | if (cb->is_nmethod()) { |
stefank@6992 | 509 | nmethod* nm = (nmethod*)cb; |
stefank@6992 | 510 | count += nm->verify_icholder_relocations(); |
stefank@6992 | 511 | } |
stefank@6992 | 512 | } |
stefank@6992 | 513 | |
stefank@6992 | 514 | assert(count + InlineCacheBuffer::pending_icholder_count() + CompiledICHolder::live_not_claimed_count() == |
stefank@6992 | 515 | CompiledICHolder::live_count(), "must agree"); |
stefank@6992 | 516 | #endif |
stefank@6992 | 517 | } |
kvn@1637 | 518 | |
duke@435 | 519 | void CodeCache::gc_prologue() { |
duke@435 | 520 | } |
duke@435 | 521 | |
duke@435 | 522 | void CodeCache::gc_epilogue() { |
duke@435 | 523 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 524 | FOR_ALL_ALIVE_BLOBS(cb) { |
duke@435 | 525 | if (cb->is_nmethod()) { |
duke@435 | 526 | nmethod *nm = (nmethod*)cb; |
duke@435 | 527 | assert(!nm->is_unloaded(), "Tautology"); |
duke@435 | 528 | if (needs_cache_clean()) { |
duke@435 | 529 | nm->cleanup_inline_caches(); |
duke@435 | 530 | } |
twisti@1918 | 531 | DEBUG_ONLY(nm->verify()); |
stefank@6992 | 532 | DEBUG_ONLY(nm->verify_oop_relocations()); |
duke@435 | 533 | } |
duke@435 | 534 | } |
duke@435 | 535 | set_needs_cache_clean(false); |
jrose@1424 | 536 | prune_scavenge_root_nmethods(); |
coleenp@4037 | 537 | |
stefank@6992 | 538 | verify_icholder_relocations(); |
duke@435 | 539 | } |
duke@435 | 540 | |
never@2657 | 541 | void CodeCache::verify_oops() { |
never@2657 | 542 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
never@2657 | 543 | VerifyOopClosure voc; |
never@2657 | 544 | FOR_ALL_ALIVE_BLOBS(cb) { |
never@2657 | 545 | if (cb->is_nmethod()) { |
never@2657 | 546 | nmethod *nm = (nmethod*)cb; |
never@2657 | 547 | nm->oops_do(&voc); |
never@2657 | 548 | nm->verify_oop_relocations(); |
never@2657 | 549 | } |
never@2657 | 550 | } |
never@2657 | 551 | } |
never@2657 | 552 | |
never@2657 | 553 | |
duke@435 | 554 | address CodeCache::first_address() { |
duke@435 | 555 | assert_locked_or_safepoint(CodeCache_lock); |
neliasso@4952 | 556 | return (address)_heap->low_boundary(); |
duke@435 | 557 | } |
duke@435 | 558 | |
duke@435 | 559 | |
duke@435 | 560 | address CodeCache::last_address() { |
duke@435 | 561 | assert_locked_or_safepoint(CodeCache_lock); |
neliasso@4952 | 562 | return (address)_heap->high(); |
duke@435 | 563 | } |
duke@435 | 564 | |
anoll@5151 | 565 | /** |
anoll@5151 | 566 | * Returns the reverse free ratio. E.g., if 25% (1/4) of the code cache |
anoll@5151 | 567 | * is free, reverse_free_ratio() returns 4. |
anoll@5151 | 568 | */ |
anoll@5151 | 569 | double CodeCache::reverse_free_ratio() { |
anoll@5151 | 570 | double unallocated_capacity = (double)(CodeCache::unallocated_capacity() - CodeCacheMinimumFreeSpace); |
anoll@5151 | 571 | double max_capacity = (double)CodeCache::max_capacity(); |
anoll@5151 | 572 | return max_capacity / unallocated_capacity; |
anoll@5151 | 573 | } |
duke@435 | 574 | |
duke@435 | 575 | void icache_init(); |
duke@435 | 576 | |
duke@435 | 577 | void CodeCache::initialize() { |
duke@435 | 578 | assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points"); |
duke@435 | 579 | #ifdef COMPILER2 |
duke@435 | 580 | assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment, "CodeCacheSegmentSize must be large enough to align inner loops"); |
duke@435 | 581 | #endif |
duke@435 | 582 | assert(CodeCacheSegmentSize >= sizeof(jdouble), "CodeCacheSegmentSize must be large enough to align constants"); |
duke@435 | 583 | // This was originally just a check of the alignment, causing failure, instead, round |
duke@435 | 584 | // the code cache to the page size. In particular, Solaris is moving to a larger |
duke@435 | 585 | // default page size. |
duke@435 | 586 | CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size()); |
duke@435 | 587 | InitialCodeCacheSize = round_to(InitialCodeCacheSize, os::vm_page_size()); |
duke@435 | 588 | ReservedCodeCacheSize = round_to(ReservedCodeCacheSize, os::vm_page_size()); |
duke@435 | 589 | if (!_heap->reserve(ReservedCodeCacheSize, InitialCodeCacheSize, CodeCacheSegmentSize)) { |
duke@435 | 590 | vm_exit_during_initialization("Could not reserve enough space for code cache"); |
duke@435 | 591 | } |
duke@435 | 592 | |
duke@435 | 593 | MemoryService::add_code_heap_memory_pool(_heap); |
duke@435 | 594 | |
duke@435 | 595 | // Initialize ICache flush mechanism |
duke@435 | 596 | // This service is needed for os::register_code_area |
duke@435 | 597 | icache_init(); |
duke@435 | 598 | |
duke@435 | 599 | // Give OS a chance to register generated code area. |
duke@435 | 600 | // This is used on Windows 64 bit platforms to register |
duke@435 | 601 | // Structured Exception Handlers for our generated code. |
duke@435 | 602 | os::register_code_area(_heap->low_boundary(), _heap->high_boundary()); |
duke@435 | 603 | } |
duke@435 | 604 | |
duke@435 | 605 | |
duke@435 | 606 | void codeCache_init() { |
duke@435 | 607 | CodeCache::initialize(); |
duke@435 | 608 | } |
duke@435 | 609 | |
duke@435 | 610 | //------------------------------------------------------------------------------------------------ |
duke@435 | 611 | |
duke@435 | 612 | int CodeCache::number_of_nmethods_with_dependencies() { |
duke@435 | 613 | return _number_of_nmethods_with_dependencies; |
duke@435 | 614 | } |
duke@435 | 615 | |
duke@435 | 616 | void CodeCache::clear_inline_caches() { |
duke@435 | 617 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 618 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 619 | nm->clear_inline_caches(); |
duke@435 | 620 | } |
duke@435 | 621 | } |
duke@435 | 622 | |
duke@435 | 623 | #ifndef PRODUCT |
duke@435 | 624 | // used to keep track of how much time is spent in mark_for_deoptimization |
duke@435 | 625 | static elapsedTimer dependentCheckTime; |
duke@435 | 626 | static int dependentCheckCount = 0; |
duke@435 | 627 | #endif // PRODUCT |
duke@435 | 628 | |
duke@435 | 629 | |
duke@435 | 630 | int CodeCache::mark_for_deoptimization(DepChange& changes) { |
duke@435 | 631 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 632 | |
duke@435 | 633 | #ifndef PRODUCT |
duke@435 | 634 | dependentCheckTime.start(); |
duke@435 | 635 | dependentCheckCount++; |
duke@435 | 636 | #endif // PRODUCT |
duke@435 | 637 | |
duke@435 | 638 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 639 | |
duke@435 | 640 | // search the hierarchy looking for nmethods which are affected by the loading of this class |
duke@435 | 641 | |
duke@435 | 642 | // then search the interfaces this class implements looking for nmethods |
duke@435 | 643 | // which might be dependent of the fact that an interface only had one |
duke@435 | 644 | // implementor. |
duke@435 | 645 | |
duke@435 | 646 | { No_Safepoint_Verifier nsv; |
duke@435 | 647 | for (DepChange::ContextStream str(changes, nsv); str.next(); ) { |
coleenp@4037 | 648 | Klass* d = str.klass(); |
coleenp@4037 | 649 | number_of_marked_CodeBlobs += InstanceKlass::cast(d)->mark_dependent_nmethods(changes); |
duke@435 | 650 | } |
duke@435 | 651 | } |
duke@435 | 652 | |
duke@435 | 653 | if (VerifyDependencies) { |
duke@435 | 654 | // Turn off dependency tracing while actually testing deps. |
duke@435 | 655 | NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) ); |
duke@435 | 656 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 657 | if (!nm->is_marked_for_deoptimization() && |
duke@435 | 658 | nm->check_all_dependencies()) { |
duke@435 | 659 | ResourceMark rm; |
duke@435 | 660 | tty->print_cr("Should have been marked for deoptimization:"); |
duke@435 | 661 | changes.print(); |
duke@435 | 662 | nm->print(); |
duke@435 | 663 | nm->print_dependencies(); |
duke@435 | 664 | } |
duke@435 | 665 | } |
duke@435 | 666 | } |
duke@435 | 667 | |
duke@435 | 668 | #ifndef PRODUCT |
duke@435 | 669 | dependentCheckTime.stop(); |
duke@435 | 670 | #endif // PRODUCT |
duke@435 | 671 | |
duke@435 | 672 | return number_of_marked_CodeBlobs; |
duke@435 | 673 | } |
duke@435 | 674 | |
duke@435 | 675 | |
duke@435 | 676 | #ifdef HOTSWAP |
duke@435 | 677 | int CodeCache::mark_for_evol_deoptimization(instanceKlassHandle dependee) { |
duke@435 | 678 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 679 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 680 | |
duke@435 | 681 | // Deoptimize all methods of the evolving class itself |
coleenp@4037 | 682 | Array<Method*>* old_methods = dependee->methods(); |
duke@435 | 683 | for (int i = 0; i < old_methods->length(); i++) { |
duke@435 | 684 | ResourceMark rm; |
coleenp@4037 | 685 | Method* old_method = old_methods->at(i); |
duke@435 | 686 | nmethod *nm = old_method->code(); |
duke@435 | 687 | if (nm != NULL) { |
duke@435 | 688 | nm->mark_for_deoptimization(); |
duke@435 | 689 | number_of_marked_CodeBlobs++; |
duke@435 | 690 | } |
duke@435 | 691 | } |
duke@435 | 692 | |
duke@435 | 693 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 694 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 695 | // ...Already marked in the previous pass; don't count it again. |
duke@435 | 696 | } else if (nm->is_evol_dependent_on(dependee())) { |
duke@435 | 697 | ResourceMark rm; |
duke@435 | 698 | nm->mark_for_deoptimization(); |
duke@435 | 699 | number_of_marked_CodeBlobs++; |
duke@435 | 700 | } else { |
coleenp@4037 | 701 | // flush caches in case they refer to a redefined Method* |
duke@435 | 702 | nm->clear_inline_caches(); |
duke@435 | 703 | } |
duke@435 | 704 | } |
duke@435 | 705 | |
duke@435 | 706 | return number_of_marked_CodeBlobs; |
duke@435 | 707 | } |
duke@435 | 708 | #endif // HOTSWAP |
duke@435 | 709 | |
duke@435 | 710 | |
duke@435 | 711 | // Deoptimize all methods |
duke@435 | 712 | void CodeCache::mark_all_nmethods_for_deoptimization() { |
duke@435 | 713 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 714 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 715 | nm->mark_for_deoptimization(); |
duke@435 | 716 | } |
duke@435 | 717 | } |
duke@435 | 718 | |
duke@435 | 719 | |
coleenp@4037 | 720 | int CodeCache::mark_for_deoptimization(Method* dependee) { |
duke@435 | 721 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 722 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 723 | |
duke@435 | 724 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 725 | if (nm->is_dependent_on_method(dependee)) { |
duke@435 | 726 | ResourceMark rm; |
duke@435 | 727 | nm->mark_for_deoptimization(); |
duke@435 | 728 | number_of_marked_CodeBlobs++; |
duke@435 | 729 | } |
duke@435 | 730 | } |
duke@435 | 731 | |
duke@435 | 732 | return number_of_marked_CodeBlobs; |
duke@435 | 733 | } |
duke@435 | 734 | |
duke@435 | 735 | void CodeCache::make_marked_nmethods_zombies() { |
duke@435 | 736 | assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
duke@435 | 737 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 738 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 739 | |
duke@435 | 740 | // If the nmethod has already been made non-entrant and it can be converted |
duke@435 | 741 | // then zombie it now. Otherwise make it non-entrant and it will eventually |
duke@435 | 742 | // be zombied when it is no longer seen on the stack. Note that the nmethod |
duke@435 | 743 | // might be "entrant" and not on the stack and so could be zombied immediately |
duke@435 | 744 | // but we can't tell because we don't track it on stack until it becomes |
duke@435 | 745 | // non-entrant. |
duke@435 | 746 | |
duke@435 | 747 | if (nm->is_not_entrant() && nm->can_not_entrant_be_converted()) { |
duke@435 | 748 | nm->make_zombie(); |
duke@435 | 749 | } else { |
duke@435 | 750 | nm->make_not_entrant(); |
duke@435 | 751 | } |
duke@435 | 752 | } |
duke@435 | 753 | } |
duke@435 | 754 | } |
duke@435 | 755 | |
duke@435 | 756 | void CodeCache::make_marked_nmethods_not_entrant() { |
duke@435 | 757 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 758 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 759 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 760 | nm->make_not_entrant(); |
duke@435 | 761 | } |
duke@435 | 762 | } |
duke@435 | 763 | } |
duke@435 | 764 | |
duke@435 | 765 | void CodeCache::verify() { |
duke@435 | 766 | _heap->verify(); |
duke@435 | 767 | FOR_ALL_ALIVE_BLOBS(p) { |
duke@435 | 768 | p->verify(); |
duke@435 | 769 | } |
duke@435 | 770 | } |
duke@435 | 771 | |
sla@5237 | 772 | void CodeCache::report_codemem_full() { |
sla@5237 | 773 | _codemem_full_count++; |
sla@5237 | 774 | EventCodeCacheFull event; |
sla@5237 | 775 | if (event.should_commit()) { |
sla@5237 | 776 | event.set_startAddress((u8)low_bound()); |
sla@5237 | 777 | event.set_commitedTopAddress((u8)high()); |
sla@5237 | 778 | event.set_reservedTopAddress((u8)high_bound()); |
sla@5237 | 779 | event.set_entryCount(nof_blobs()); |
sla@5237 | 780 | event.set_methodCount(nof_nmethods()); |
sla@5237 | 781 | event.set_adaptorCount(nof_adapters()); |
sla@5237 | 782 | event.set_unallocatedCapacity(unallocated_capacity()/K); |
sla@5237 | 783 | event.set_fullCount(_codemem_full_count); |
sla@5237 | 784 | event.commit(); |
sla@5237 | 785 | } |
sla@5237 | 786 | } |
sla@5237 | 787 | |
duke@435 | 788 | //------------------------------------------------------------------------------------------------ |
duke@435 | 789 | // Non-product version |
duke@435 | 790 | |
duke@435 | 791 | #ifndef PRODUCT |
duke@435 | 792 | |
duke@435 | 793 | void CodeCache::verify_if_often() { |
duke@435 | 794 | if (VerifyCodeCacheOften) { |
duke@435 | 795 | _heap->verify(); |
duke@435 | 796 | } |
duke@435 | 797 | } |
duke@435 | 798 | |
jrose@1424 | 799 | void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) { |
jrose@1424 | 800 | if (PrintCodeCache2) { // Need to add a new flag |
jrose@1424 | 801 | ResourceMark rm; |
jrose@1424 | 802 | if (size == 0) size = cb->size(); |
drchase@6680 | 803 | tty->print_cr("CodeCache %s: addr: " INTPTR_FORMAT ", size: 0x%x", event, p2i(cb), size); |
jrose@1424 | 804 | } |
jrose@1424 | 805 | } |
jrose@1424 | 806 | |
duke@435 | 807 | void CodeCache::print_internals() { |
duke@435 | 808 | int nmethodCount = 0; |
duke@435 | 809 | int runtimeStubCount = 0; |
duke@435 | 810 | int adapterCount = 0; |
duke@435 | 811 | int deoptimizationStubCount = 0; |
duke@435 | 812 | int uncommonTrapStubCount = 0; |
duke@435 | 813 | int bufferBlobCount = 0; |
duke@435 | 814 | int total = 0; |
duke@435 | 815 | int nmethodAlive = 0; |
duke@435 | 816 | int nmethodNotEntrant = 0; |
duke@435 | 817 | int nmethodZombie = 0; |
duke@435 | 818 | int nmethodUnloaded = 0; |
duke@435 | 819 | int nmethodJava = 0; |
duke@435 | 820 | int nmethodNative = 0; |
duke@435 | 821 | int maxCodeSize = 0; |
duke@435 | 822 | ResourceMark rm; |
duke@435 | 823 | |
duke@435 | 824 | CodeBlob *cb; |
duke@435 | 825 | for (cb = first(); cb != NULL; cb = next(cb)) { |
duke@435 | 826 | total++; |
duke@435 | 827 | if (cb->is_nmethod()) { |
duke@435 | 828 | nmethod* nm = (nmethod*)cb; |
duke@435 | 829 | |
duke@435 | 830 | if (Verbose && nm->method() != NULL) { |
duke@435 | 831 | ResourceMark rm; |
duke@435 | 832 | char *method_name = nm->method()->name_and_sig_as_C_string(); |
duke@435 | 833 | tty->print("%s", method_name); |
duke@435 | 834 | if(nm->is_alive()) { tty->print_cr(" alive"); } |
duke@435 | 835 | if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); } |
duke@435 | 836 | if(nm->is_zombie()) { tty->print_cr(" zombie"); } |
duke@435 | 837 | } |
duke@435 | 838 | |
duke@435 | 839 | nmethodCount++; |
duke@435 | 840 | |
duke@435 | 841 | if(nm->is_alive()) { nmethodAlive++; } |
duke@435 | 842 | if(nm->is_not_entrant()) { nmethodNotEntrant++; } |
duke@435 | 843 | if(nm->is_zombie()) { nmethodZombie++; } |
duke@435 | 844 | if(nm->is_unloaded()) { nmethodUnloaded++; } |
duke@435 | 845 | if(nm->is_native_method()) { nmethodNative++; } |
duke@435 | 846 | |
duke@435 | 847 | if(nm->method() != NULL && nm->is_java_method()) { |
duke@435 | 848 | nmethodJava++; |
twisti@2103 | 849 | if (nm->insts_size() > maxCodeSize) { |
twisti@2103 | 850 | maxCodeSize = nm->insts_size(); |
duke@435 | 851 | } |
duke@435 | 852 | } |
duke@435 | 853 | } else if (cb->is_runtime_stub()) { |
duke@435 | 854 | runtimeStubCount++; |
duke@435 | 855 | } else if (cb->is_deoptimization_stub()) { |
duke@435 | 856 | deoptimizationStubCount++; |
duke@435 | 857 | } else if (cb->is_uncommon_trap_stub()) { |
duke@435 | 858 | uncommonTrapStubCount++; |
duke@435 | 859 | } else if (cb->is_adapter_blob()) { |
duke@435 | 860 | adapterCount++; |
duke@435 | 861 | } else if (cb->is_buffer_blob()) { |
duke@435 | 862 | bufferBlobCount++; |
duke@435 | 863 | } |
duke@435 | 864 | } |
duke@435 | 865 | |
duke@435 | 866 | int bucketSize = 512; |
duke@435 | 867 | int bucketLimit = maxCodeSize / bucketSize + 1; |
zgu@3900 | 868 | int *buckets = NEW_C_HEAP_ARRAY(int, bucketLimit, mtCode); |
duke@435 | 869 | memset(buckets,0,sizeof(int) * bucketLimit); |
duke@435 | 870 | |
duke@435 | 871 | for (cb = first(); cb != NULL; cb = next(cb)) { |
duke@435 | 872 | if (cb->is_nmethod()) { |
duke@435 | 873 | nmethod* nm = (nmethod*)cb; |
duke@435 | 874 | if(nm->is_java_method()) { |
twisti@2103 | 875 | buckets[nm->insts_size() / bucketSize]++; |
duke@435 | 876 | } |
duke@435 | 877 | } |
duke@435 | 878 | } |
duke@435 | 879 | tty->print_cr("Code Cache Entries (total of %d)",total); |
duke@435 | 880 | tty->print_cr("-------------------------------------------------"); |
duke@435 | 881 | tty->print_cr("nmethods: %d",nmethodCount); |
duke@435 | 882 | tty->print_cr("\talive: %d",nmethodAlive); |
duke@435 | 883 | tty->print_cr("\tnot_entrant: %d",nmethodNotEntrant); |
duke@435 | 884 | tty->print_cr("\tzombie: %d",nmethodZombie); |
duke@435 | 885 | tty->print_cr("\tunloaded: %d",nmethodUnloaded); |
duke@435 | 886 | tty->print_cr("\tjava: %d",nmethodJava); |
duke@435 | 887 | tty->print_cr("\tnative: %d",nmethodNative); |
duke@435 | 888 | tty->print_cr("runtime_stubs: %d",runtimeStubCount); |
duke@435 | 889 | tty->print_cr("adapters: %d",adapterCount); |
duke@435 | 890 | tty->print_cr("buffer blobs: %d",bufferBlobCount); |
duke@435 | 891 | tty->print_cr("deoptimization_stubs: %d",deoptimizationStubCount); |
duke@435 | 892 | tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount); |
duke@435 | 893 | tty->print_cr("\nnmethod size distribution (non-zombie java)"); |
duke@435 | 894 | tty->print_cr("-------------------------------------------------"); |
duke@435 | 895 | |
duke@435 | 896 | for(int i=0; i<bucketLimit; i++) { |
duke@435 | 897 | if(buckets[i] != 0) { |
duke@435 | 898 | tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize); |
duke@435 | 899 | tty->fill_to(40); |
duke@435 | 900 | tty->print_cr("%d",buckets[i]); |
duke@435 | 901 | } |
duke@435 | 902 | } |
duke@435 | 903 | |
zgu@3900 | 904 | FREE_C_HEAP_ARRAY(int, buckets, mtCode); |
duke@435 | 905 | } |
duke@435 | 906 | |
vladidan@4438 | 907 | #endif // !PRODUCT |
vladidan@4438 | 908 | |
duke@435 | 909 | void CodeCache::print() { |
vladidan@4438 | 910 | print_summary(tty); |
vladidan@4438 | 911 | |
vladidan@4438 | 912 | #ifndef PRODUCT |
vladidan@4438 | 913 | if (!Verbose) return; |
vladidan@4438 | 914 | |
duke@435 | 915 | CodeBlob_sizes live; |
duke@435 | 916 | CodeBlob_sizes dead; |
duke@435 | 917 | |
duke@435 | 918 | FOR_ALL_BLOBS(p) { |
duke@435 | 919 | if (!p->is_alive()) { |
duke@435 | 920 | dead.add(p); |
duke@435 | 921 | } else { |
duke@435 | 922 | live.add(p); |
duke@435 | 923 | } |
duke@435 | 924 | } |
duke@435 | 925 | |
duke@435 | 926 | tty->print_cr("CodeCache:"); |
duke@435 | 927 | |
drchase@6680 | 928 | tty->print_cr("nmethod dependency checking time %f, per dependent %f", dependentCheckTime.seconds(), |
duke@435 | 929 | dependentCheckTime.seconds() / dependentCheckCount); |
duke@435 | 930 | |
duke@435 | 931 | if (!live.is_empty()) { |
duke@435 | 932 | live.print("live"); |
duke@435 | 933 | } |
duke@435 | 934 | if (!dead.is_empty()) { |
duke@435 | 935 | dead.print("dead"); |
duke@435 | 936 | } |
duke@435 | 937 | |
duke@435 | 938 | |
vladidan@4438 | 939 | if (WizardMode) { |
duke@435 | 940 | // print the oop_map usage |
duke@435 | 941 | int code_size = 0; |
duke@435 | 942 | int number_of_blobs = 0; |
duke@435 | 943 | int number_of_oop_maps = 0; |
duke@435 | 944 | int map_size = 0; |
duke@435 | 945 | FOR_ALL_BLOBS(p) { |
duke@435 | 946 | if (p->is_alive()) { |
duke@435 | 947 | number_of_blobs++; |
twisti@2103 | 948 | code_size += p->code_size(); |
duke@435 | 949 | OopMapSet* set = p->oop_maps(); |
duke@435 | 950 | if (set != NULL) { |
duke@435 | 951 | number_of_oop_maps += set->size(); |
twisti@2103 | 952 | map_size += set->heap_size(); |
duke@435 | 953 | } |
duke@435 | 954 | } |
duke@435 | 955 | } |
duke@435 | 956 | tty->print_cr("OopMaps"); |
duke@435 | 957 | tty->print_cr(" #blobs = %d", number_of_blobs); |
duke@435 | 958 | tty->print_cr(" code size = %d", code_size); |
duke@435 | 959 | tty->print_cr(" #oop_maps = %d", number_of_oop_maps); |
duke@435 | 960 | tty->print_cr(" map size = %d", map_size); |
duke@435 | 961 | } |
duke@435 | 962 | |
vladidan@4438 | 963 | #endif // !PRODUCT |
duke@435 | 964 | } |
duke@435 | 965 | |
vladidan@4438 | 966 | void CodeCache::print_summary(outputStream* st, bool detailed) { |
vladidan@4438 | 967 | size_t total = (_heap->high_boundary() - _heap->low_boundary()); |
vladidan@4438 | 968 | st->print_cr("CodeCache: size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT |
neliasso@4952 | 969 | "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb", |
vladidan@4438 | 970 | total/K, (total - unallocated_capacity())/K, |
neliasso@4952 | 971 | maxCodeCacheUsed/K, unallocated_capacity()/K); |
never@2262 | 972 | |
vladidan@4438 | 973 | if (detailed) { |
vladidan@4438 | 974 | st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]", |
drchase@6680 | 975 | p2i(_heap->low_boundary()), |
drchase@6680 | 976 | p2i(_heap->high()), |
drchase@6680 | 977 | p2i(_heap->high_boundary())); |
vladidan@4438 | 978 | st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT |
vladidan@4438 | 979 | " adapters=" UINT32_FORMAT, |
vladidan@4438 | 980 | nof_blobs(), nof_nmethods(), nof_adapters()); |
vladidan@4438 | 981 | st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ? |
vladidan@4438 | 982 | "enabled" : Arguments::mode() == Arguments::_int ? |
vladidan@4438 | 983 | "disabled (interpreter mode)" : |
vladidan@4438 | 984 | "disabled (not enough contiguous free space left)"); |
vladidan@4438 | 985 | } |
never@2262 | 986 | } |
kvn@2635 | 987 | |
kvn@2635 | 988 | void CodeCache::log_state(outputStream* st) { |
kvn@2635 | 989 | st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'" |
neliasso@4952 | 990 | " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'", |
kvn@2635 | 991 | nof_blobs(), nof_nmethods(), nof_adapters(), |
neliasso@4952 | 992 | unallocated_capacity()); |
kvn@2635 | 993 | } |
never@2739 | 994 |