Thu, 20 May 2010 06:34:23 -0700
6951083: oops and relocations should part of nmethod not CodeBlob
Summary: This moves the oops from Codeblob to nmethod.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
twisti@1798 | 2 | * Copyright 1997-2010 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_codeCache.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // Helper class for printing in CodeCache |
duke@435 | 29 | |
duke@435 | 30 | class CodeBlob_sizes { |
duke@435 | 31 | private: |
duke@435 | 32 | int count; |
duke@435 | 33 | int total_size; |
duke@435 | 34 | int header_size; |
duke@435 | 35 | int code_size; |
duke@435 | 36 | int stub_size; |
duke@435 | 37 | int relocation_size; |
duke@435 | 38 | int scopes_oop_size; |
duke@435 | 39 | int scopes_data_size; |
duke@435 | 40 | int scopes_pcs_size; |
duke@435 | 41 | |
duke@435 | 42 | public: |
duke@435 | 43 | CodeBlob_sizes() { |
duke@435 | 44 | count = 0; |
duke@435 | 45 | total_size = 0; |
duke@435 | 46 | header_size = 0; |
duke@435 | 47 | code_size = 0; |
duke@435 | 48 | stub_size = 0; |
duke@435 | 49 | relocation_size = 0; |
duke@435 | 50 | scopes_oop_size = 0; |
duke@435 | 51 | scopes_data_size = 0; |
duke@435 | 52 | scopes_pcs_size = 0; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | int total() { return total_size; } |
duke@435 | 56 | bool is_empty() { return count == 0; } |
duke@435 | 57 | |
duke@435 | 58 | void print(const char* title) { |
duke@435 | 59 | tty->print_cr(" #%d %s = %dK (hdr %d%%, loc %d%%, code %d%%, stub %d%%, [oops %d%%, data %d%%, pcs %d%%])", |
duke@435 | 60 | count, |
duke@435 | 61 | title, |
duke@435 | 62 | total() / K, |
duke@435 | 63 | header_size * 100 / total_size, |
duke@435 | 64 | relocation_size * 100 / total_size, |
duke@435 | 65 | code_size * 100 / total_size, |
duke@435 | 66 | stub_size * 100 / total_size, |
duke@435 | 67 | scopes_oop_size * 100 / total_size, |
duke@435 | 68 | scopes_data_size * 100 / total_size, |
duke@435 | 69 | scopes_pcs_size * 100 / total_size); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | void add(CodeBlob* cb) { |
duke@435 | 73 | count++; |
duke@435 | 74 | total_size += cb->size(); |
duke@435 | 75 | header_size += cb->header_size(); |
duke@435 | 76 | relocation_size += cb->relocation_size(); |
duke@435 | 77 | if (cb->is_nmethod()) { |
twisti@1918 | 78 | nmethod* nm = cb->as_nmethod_or_null(); |
duke@435 | 79 | code_size += nm->code_size(); |
duke@435 | 80 | stub_size += nm->stub_size(); |
duke@435 | 81 | |
twisti@1918 | 82 | scopes_oop_size += nm->oops_size(); |
duke@435 | 83 | scopes_data_size += nm->scopes_data_size(); |
duke@435 | 84 | scopes_pcs_size += nm->scopes_pcs_size(); |
duke@435 | 85 | } else { |
duke@435 | 86 | code_size += cb->instructions_size(); |
duke@435 | 87 | } |
duke@435 | 88 | } |
duke@435 | 89 | }; |
duke@435 | 90 | |
duke@435 | 91 | |
duke@435 | 92 | // CodeCache implementation |
duke@435 | 93 | |
duke@435 | 94 | CodeHeap * CodeCache::_heap = new CodeHeap(); |
duke@435 | 95 | int CodeCache::_number_of_blobs = 0; |
duke@435 | 96 | int CodeCache::_number_of_nmethods_with_dependencies = 0; |
duke@435 | 97 | bool CodeCache::_needs_cache_clean = false; |
jrose@1424 | 98 | nmethod* CodeCache::_scavenge_root_nmethods = NULL; |
kvn@1637 | 99 | nmethod* CodeCache::_saved_nmethods = NULL; |
duke@435 | 100 | |
duke@435 | 101 | |
duke@435 | 102 | CodeBlob* CodeCache::first() { |
duke@435 | 103 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 104 | return (CodeBlob*)_heap->first(); |
duke@435 | 105 | } |
duke@435 | 106 | |
duke@435 | 107 | |
duke@435 | 108 | CodeBlob* CodeCache::next(CodeBlob* cb) { |
duke@435 | 109 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 110 | return (CodeBlob*)_heap->next(cb); |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | |
duke@435 | 114 | CodeBlob* CodeCache::alive(CodeBlob *cb) { |
duke@435 | 115 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 116 | while (cb != NULL && !cb->is_alive()) cb = next(cb); |
duke@435 | 117 | return cb; |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | |
duke@435 | 121 | nmethod* CodeCache::alive_nmethod(CodeBlob* cb) { |
duke@435 | 122 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 123 | while (cb != NULL && (!cb->is_alive() || !cb->is_nmethod())) cb = next(cb); |
duke@435 | 124 | return (nmethod*)cb; |
duke@435 | 125 | } |
duke@435 | 126 | |
never@1893 | 127 | nmethod* CodeCache::first_nmethod() { |
never@1893 | 128 | assert_locked_or_safepoint(CodeCache_lock); |
never@1893 | 129 | CodeBlob* cb = first(); |
never@1893 | 130 | while (cb != NULL && !cb->is_nmethod()) { |
never@1893 | 131 | cb = next(cb); |
never@1893 | 132 | } |
never@1893 | 133 | return (nmethod*)cb; |
never@1893 | 134 | } |
never@1893 | 135 | |
never@1893 | 136 | nmethod* CodeCache::next_nmethod (CodeBlob* cb) { |
never@1893 | 137 | assert_locked_or_safepoint(CodeCache_lock); |
never@1893 | 138 | cb = next(cb); |
never@1893 | 139 | while (cb != NULL && !cb->is_nmethod()) { |
never@1893 | 140 | cb = next(cb); |
never@1893 | 141 | } |
never@1893 | 142 | return (nmethod*)cb; |
never@1893 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | CodeBlob* CodeCache::allocate(int size) { |
duke@435 | 146 | // Do not seize the CodeCache lock here--if the caller has not |
duke@435 | 147 | // already done so, we are going to lose bigtime, since the code |
duke@435 | 148 | // cache will contain a garbage CodeBlob until the caller can |
duke@435 | 149 | // run the constructor for the CodeBlob subclass he is busy |
duke@435 | 150 | // instantiating. |
duke@435 | 151 | guarantee(size >= 0, "allocation request must be reasonable"); |
duke@435 | 152 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 153 | CodeBlob* cb = NULL; |
duke@435 | 154 | _number_of_blobs++; |
duke@435 | 155 | while (true) { |
duke@435 | 156 | cb = (CodeBlob*)_heap->allocate(size); |
duke@435 | 157 | if (cb != NULL) break; |
duke@435 | 158 | if (!_heap->expand_by(CodeCacheExpansionSize)) { |
duke@435 | 159 | // Expansion failed |
duke@435 | 160 | return NULL; |
duke@435 | 161 | } |
duke@435 | 162 | if (PrintCodeCacheExtension) { |
duke@435 | 163 | ResourceMark rm; |
duke@435 | 164 | tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%d bytes)", |
duke@435 | 165 | (intptr_t)_heap->begin(), (intptr_t)_heap->end(), |
duke@435 | 166 | (address)_heap->end() - (address)_heap->begin()); |
duke@435 | 167 | } |
duke@435 | 168 | } |
duke@435 | 169 | verify_if_often(); |
jrose@1424 | 170 | print_trace("allocation", cb, size); |
duke@435 | 171 | return cb; |
duke@435 | 172 | } |
duke@435 | 173 | |
duke@435 | 174 | void CodeCache::free(CodeBlob* cb) { |
duke@435 | 175 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 176 | verify_if_often(); |
duke@435 | 177 | |
jrose@1424 | 178 | print_trace("free", cb); |
duke@435 | 179 | if (cb->is_nmethod() && ((nmethod *)cb)->has_dependencies()) { |
duke@435 | 180 | _number_of_nmethods_with_dependencies--; |
duke@435 | 181 | } |
duke@435 | 182 | _number_of_blobs--; |
duke@435 | 183 | |
duke@435 | 184 | _heap->deallocate(cb); |
duke@435 | 185 | |
duke@435 | 186 | verify_if_often(); |
duke@435 | 187 | assert(_number_of_blobs >= 0, "sanity check"); |
duke@435 | 188 | } |
duke@435 | 189 | |
duke@435 | 190 | |
duke@435 | 191 | void CodeCache::commit(CodeBlob* cb) { |
duke@435 | 192 | // this is called by nmethod::nmethod, which must already own CodeCache_lock |
duke@435 | 193 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 194 | if (cb->is_nmethod() && ((nmethod *)cb)->has_dependencies()) { |
duke@435 | 195 | _number_of_nmethods_with_dependencies++; |
duke@435 | 196 | } |
duke@435 | 197 | // flush the hardware I-cache |
duke@435 | 198 | ICache::invalidate_range(cb->instructions_begin(), cb->instructions_size()); |
duke@435 | 199 | } |
duke@435 | 200 | |
duke@435 | 201 | |
duke@435 | 202 | void CodeCache::flush() { |
duke@435 | 203 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 204 | Unimplemented(); |
duke@435 | 205 | } |
duke@435 | 206 | |
duke@435 | 207 | |
duke@435 | 208 | // Iteration over CodeBlobs |
duke@435 | 209 | |
duke@435 | 210 | #define FOR_ALL_BLOBS(var) for (CodeBlob *var = first() ; var != NULL; var = next(var) ) |
duke@435 | 211 | #define FOR_ALL_ALIVE_BLOBS(var) for (CodeBlob *var = alive(first()); var != NULL; var = alive(next(var))) |
duke@435 | 212 | #define FOR_ALL_ALIVE_NMETHODS(var) for (nmethod *var = alive_nmethod(first()); var != NULL; var = alive_nmethod(next(var))) |
duke@435 | 213 | |
duke@435 | 214 | |
duke@435 | 215 | bool CodeCache::contains(void *p) { |
duke@435 | 216 | // It should be ok to call contains without holding a lock |
duke@435 | 217 | return _heap->contains(p); |
duke@435 | 218 | } |
duke@435 | 219 | |
duke@435 | 220 | |
duke@435 | 221 | // This method is safe to call without holding the CodeCache_lock, as long as a dead codeblob is not |
duke@435 | 222 | // looked up (i.e., one that has been marked for deletion). It only dependes on the _segmap to contain |
duke@435 | 223 | // valid indices, which it will always do, as long as the CodeBlob is not in the process of being recycled. |
duke@435 | 224 | CodeBlob* CodeCache::find_blob(void* start) { |
duke@435 | 225 | CodeBlob* result = find_blob_unsafe(start); |
duke@435 | 226 | if (result == NULL) return NULL; |
duke@435 | 227 | // We could potientially look up non_entrant methods |
duke@435 | 228 | guarantee(!result->is_zombie() || result->is_locked_by_vm() || is_error_reported(), "unsafe access to zombie method"); |
duke@435 | 229 | return result; |
duke@435 | 230 | } |
duke@435 | 231 | |
duke@435 | 232 | nmethod* CodeCache::find_nmethod(void* start) { |
duke@435 | 233 | CodeBlob *cb = find_blob(start); |
duke@435 | 234 | assert(cb == NULL || cb->is_nmethod(), "did not find an nmethod"); |
duke@435 | 235 | return (nmethod*)cb; |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | |
duke@435 | 239 | void CodeCache::blobs_do(void f(CodeBlob* nm)) { |
duke@435 | 240 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 241 | FOR_ALL_BLOBS(p) { |
duke@435 | 242 | f(p); |
duke@435 | 243 | } |
duke@435 | 244 | } |
duke@435 | 245 | |
duke@435 | 246 | |
duke@435 | 247 | void CodeCache::nmethods_do(void f(nmethod* nm)) { |
duke@435 | 248 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 249 | FOR_ALL_BLOBS(nm) { |
duke@435 | 250 | if (nm->is_nmethod()) f((nmethod*)nm); |
duke@435 | 251 | } |
duke@435 | 252 | } |
duke@435 | 253 | |
duke@435 | 254 | |
duke@435 | 255 | int CodeCache::alignment_unit() { |
duke@435 | 256 | return (int)_heap->alignment_unit(); |
duke@435 | 257 | } |
duke@435 | 258 | |
duke@435 | 259 | |
duke@435 | 260 | int CodeCache::alignment_offset() { |
duke@435 | 261 | return (int)_heap->alignment_offset(); |
duke@435 | 262 | } |
duke@435 | 263 | |
duke@435 | 264 | |
twisti@1918 | 265 | // Mark nmethods for unloading if they contain otherwise unreachable |
twisti@1918 | 266 | // oops. |
duke@435 | 267 | void CodeCache::do_unloading(BoolObjectClosure* is_alive, |
duke@435 | 268 | OopClosure* keep_alive, |
duke@435 | 269 | bool unloading_occurred) { |
duke@435 | 270 | assert_locked_or_safepoint(CodeCache_lock); |
twisti@1918 | 271 | FOR_ALL_ALIVE_NMETHODS(nm) { |
twisti@1918 | 272 | nm->do_unloading(is_alive, keep_alive, unloading_occurred); |
duke@435 | 273 | } |
duke@435 | 274 | } |
duke@435 | 275 | |
jrose@1424 | 276 | void CodeCache::blobs_do(CodeBlobClosure* f) { |
duke@435 | 277 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 278 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 279 | f->do_code_blob(cb); |
jrose@1424 | 280 | |
jrose@1424 | 281 | #ifdef ASSERT |
jrose@1424 | 282 | if (cb->is_nmethod()) |
jrose@1424 | 283 | ((nmethod*)cb)->verify_scavenge_root_oops(); |
jrose@1424 | 284 | #endif //ASSERT |
duke@435 | 285 | } |
duke@435 | 286 | } |
duke@435 | 287 | |
jrose@1424 | 288 | // Walk the list of methods which might contain non-perm oops. |
jrose@1424 | 289 | void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) { |
jrose@1424 | 290 | assert_locked_or_safepoint(CodeCache_lock); |
jrose@1424 | 291 | debug_only(mark_scavenge_root_nmethods()); |
jrose@1424 | 292 | |
jrose@1424 | 293 | for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { |
jrose@1424 | 294 | debug_only(cur->clear_scavenge_root_marked()); |
jrose@1424 | 295 | assert(cur->scavenge_root_not_marked(), ""); |
jrose@1424 | 296 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 297 | |
jrose@1424 | 298 | bool is_live = (!cur->is_zombie() && !cur->is_unloaded()); |
jrose@1424 | 299 | #ifndef PRODUCT |
jrose@1424 | 300 | if (TraceScavenge) { |
jrose@1424 | 301 | cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr(); |
jrose@1424 | 302 | } |
jrose@1424 | 303 | #endif //PRODUCT |
twisti@1798 | 304 | if (is_live) { |
jrose@1424 | 305 | // Perform cur->oops_do(f), maybe just once per nmethod. |
jrose@1424 | 306 | f->do_code_blob(cur); |
twisti@1798 | 307 | cur->fix_oop_relocations(); |
twisti@1798 | 308 | } |
jrose@1424 | 309 | } |
jrose@1424 | 310 | |
jrose@1424 | 311 | // Check for stray marks. |
jrose@1424 | 312 | debug_only(verify_perm_nmethods(NULL)); |
jrose@1424 | 313 | } |
jrose@1424 | 314 | |
jrose@1424 | 315 | void CodeCache::add_scavenge_root_nmethod(nmethod* nm) { |
jrose@1424 | 316 | assert_locked_or_safepoint(CodeCache_lock); |
jrose@1424 | 317 | nm->set_on_scavenge_root_list(); |
jrose@1424 | 318 | nm->set_scavenge_root_link(_scavenge_root_nmethods); |
jrose@1424 | 319 | set_scavenge_root_nmethods(nm); |
jrose@1424 | 320 | print_trace("add_scavenge_root", nm); |
jrose@1424 | 321 | } |
jrose@1424 | 322 | |
jrose@1424 | 323 | void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) { |
jrose@1424 | 324 | assert_locked_or_safepoint(CodeCache_lock); |
jrose@1424 | 325 | print_trace("drop_scavenge_root", nm); |
jrose@1424 | 326 | nmethod* last = NULL; |
jrose@1424 | 327 | nmethod* cur = scavenge_root_nmethods(); |
jrose@1424 | 328 | while (cur != NULL) { |
jrose@1424 | 329 | nmethod* next = cur->scavenge_root_link(); |
jrose@1424 | 330 | if (cur == nm) { |
jrose@1424 | 331 | if (last != NULL) |
jrose@1424 | 332 | last->set_scavenge_root_link(next); |
jrose@1424 | 333 | else set_scavenge_root_nmethods(next); |
jrose@1424 | 334 | nm->set_scavenge_root_link(NULL); |
jrose@1424 | 335 | nm->clear_on_scavenge_root_list(); |
jrose@1424 | 336 | return; |
jrose@1424 | 337 | } |
jrose@1424 | 338 | last = cur; |
jrose@1424 | 339 | cur = next; |
jrose@1424 | 340 | } |
jrose@1424 | 341 | assert(false, "should have been on list"); |
jrose@1424 | 342 | } |
jrose@1424 | 343 | |
jrose@1424 | 344 | void CodeCache::prune_scavenge_root_nmethods() { |
jrose@1424 | 345 | assert_locked_or_safepoint(CodeCache_lock); |
jrose@1424 | 346 | debug_only(mark_scavenge_root_nmethods()); |
jrose@1424 | 347 | |
jrose@1424 | 348 | nmethod* last = NULL; |
jrose@1424 | 349 | nmethod* cur = scavenge_root_nmethods(); |
jrose@1424 | 350 | while (cur != NULL) { |
jrose@1424 | 351 | nmethod* next = cur->scavenge_root_link(); |
jrose@1424 | 352 | debug_only(cur->clear_scavenge_root_marked()); |
jrose@1424 | 353 | assert(cur->scavenge_root_not_marked(), ""); |
jrose@1424 | 354 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 355 | |
jrose@1424 | 356 | if (!cur->is_zombie() && !cur->is_unloaded() |
jrose@1424 | 357 | && cur->detect_scavenge_root_oops()) { |
jrose@1424 | 358 | // Keep it. Advance 'last' to prevent deletion. |
jrose@1424 | 359 | last = cur; |
jrose@1424 | 360 | } else { |
jrose@1424 | 361 | // Prune it from the list, so we don't have to look at it any more. |
jrose@1424 | 362 | print_trace("prune_scavenge_root", cur); |
jrose@1424 | 363 | cur->set_scavenge_root_link(NULL); |
jrose@1424 | 364 | cur->clear_on_scavenge_root_list(); |
jrose@1424 | 365 | if (last != NULL) |
jrose@1424 | 366 | last->set_scavenge_root_link(next); |
jrose@1424 | 367 | else set_scavenge_root_nmethods(next); |
jrose@1424 | 368 | } |
jrose@1424 | 369 | cur = next; |
jrose@1424 | 370 | } |
jrose@1424 | 371 | |
jrose@1424 | 372 | // Check for stray marks. |
jrose@1424 | 373 | debug_only(verify_perm_nmethods(NULL)); |
jrose@1424 | 374 | } |
jrose@1424 | 375 | |
jrose@1424 | 376 | #ifndef PRODUCT |
jrose@1424 | 377 | void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) { |
jrose@1424 | 378 | // While we are here, verify the integrity of the list. |
jrose@1424 | 379 | mark_scavenge_root_nmethods(); |
jrose@1424 | 380 | for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { |
jrose@1424 | 381 | assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); |
jrose@1424 | 382 | cur->clear_scavenge_root_marked(); |
jrose@1424 | 383 | } |
jrose@1424 | 384 | verify_perm_nmethods(f); |
jrose@1424 | 385 | } |
jrose@1424 | 386 | |
jrose@1424 | 387 | // Temporarily mark nmethods that are claimed to be on the non-perm list. |
jrose@1424 | 388 | void CodeCache::mark_scavenge_root_nmethods() { |
jrose@1424 | 389 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 390 | if (cb->is_nmethod()) { |
jrose@1424 | 391 | nmethod *nm = (nmethod*)cb; |
jrose@1424 | 392 | assert(nm->scavenge_root_not_marked(), "clean state"); |
jrose@1424 | 393 | if (nm->on_scavenge_root_list()) |
jrose@1424 | 394 | nm->set_scavenge_root_marked(); |
jrose@1424 | 395 | } |
jrose@1424 | 396 | } |
jrose@1424 | 397 | } |
jrose@1424 | 398 | |
jrose@1424 | 399 | // If the closure is given, run it on the unlisted nmethods. |
jrose@1424 | 400 | // Also make sure that the effects of mark_scavenge_root_nmethods is gone. |
jrose@1424 | 401 | void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) { |
jrose@1424 | 402 | FOR_ALL_ALIVE_BLOBS(cb) { |
jrose@1424 | 403 | bool call_f = (f_or_null != NULL); |
jrose@1424 | 404 | if (cb->is_nmethod()) { |
jrose@1424 | 405 | nmethod *nm = (nmethod*)cb; |
jrose@1424 | 406 | assert(nm->scavenge_root_not_marked(), "must be already processed"); |
jrose@1424 | 407 | if (nm->on_scavenge_root_list()) |
jrose@1424 | 408 | call_f = false; // don't show this one to the client |
jrose@1424 | 409 | nm->verify_scavenge_root_oops(); |
jrose@1424 | 410 | } else { |
jrose@1424 | 411 | call_f = false; // not an nmethod |
jrose@1424 | 412 | } |
jrose@1424 | 413 | if (call_f) f_or_null->do_code_blob(cb); |
jrose@1424 | 414 | } |
jrose@1424 | 415 | } |
jrose@1424 | 416 | #endif //PRODUCT |
jrose@1424 | 417 | |
kvn@1637 | 418 | |
kvn@1637 | 419 | nmethod* CodeCache::find_and_remove_saved_code(methodOop m) { |
kvn@1637 | 420 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
kvn@1637 | 421 | nmethod* saved = _saved_nmethods; |
kvn@1637 | 422 | nmethod* prev = NULL; |
kvn@1637 | 423 | while (saved != NULL) { |
kvn@1637 | 424 | if (saved->is_in_use() && saved->method() == m) { |
kvn@1637 | 425 | if (prev != NULL) { |
kvn@1637 | 426 | prev->set_saved_nmethod_link(saved->saved_nmethod_link()); |
kvn@1637 | 427 | } else { |
kvn@1637 | 428 | _saved_nmethods = saved->saved_nmethod_link(); |
kvn@1637 | 429 | } |
kvn@1637 | 430 | assert(saved->is_speculatively_disconnected(), "shouldn't call for other nmethods"); |
kvn@1637 | 431 | saved->set_speculatively_disconnected(false); |
kvn@1637 | 432 | saved->set_saved_nmethod_link(NULL); |
kvn@1637 | 433 | if (PrintMethodFlushing) { |
never@1893 | 434 | saved->print_on(tty, " ### nmethod is reconnected\n"); |
kvn@1637 | 435 | } |
kvn@1637 | 436 | if (LogCompilation && (xtty != NULL)) { |
kvn@1637 | 437 | ttyLocker ttyl; |
kvn@1637 | 438 | xtty->begin_elem("nmethod_reconnected compile_id='%3d'", saved->compile_id()); |
kvn@1637 | 439 | xtty->method(methodOop(m)); |
kvn@1637 | 440 | xtty->stamp(); |
kvn@1637 | 441 | xtty->end_elem(); |
kvn@1637 | 442 | } |
kvn@1637 | 443 | return saved; |
kvn@1637 | 444 | } |
kvn@1637 | 445 | prev = saved; |
kvn@1637 | 446 | saved = saved->saved_nmethod_link(); |
kvn@1637 | 447 | } |
kvn@1637 | 448 | return NULL; |
kvn@1637 | 449 | } |
kvn@1637 | 450 | |
kvn@1637 | 451 | void CodeCache::remove_saved_code(nmethod* nm) { |
never@1893 | 452 | // For conc swpr this will be called with CodeCache_lock taken by caller |
never@1893 | 453 | assert_locked_or_safepoint(CodeCache_lock); |
kvn@1637 | 454 | assert(nm->is_speculatively_disconnected(), "shouldn't call for other nmethods"); |
kvn@1637 | 455 | nmethod* saved = _saved_nmethods; |
kvn@1637 | 456 | nmethod* prev = NULL; |
kvn@1637 | 457 | while (saved != NULL) { |
kvn@1637 | 458 | if (saved == nm) { |
kvn@1637 | 459 | if (prev != NULL) { |
kvn@1637 | 460 | prev->set_saved_nmethod_link(saved->saved_nmethod_link()); |
kvn@1637 | 461 | } else { |
kvn@1637 | 462 | _saved_nmethods = saved->saved_nmethod_link(); |
kvn@1637 | 463 | } |
kvn@1637 | 464 | if (LogCompilation && (xtty != NULL)) { |
kvn@1637 | 465 | ttyLocker ttyl; |
kvn@1637 | 466 | xtty->begin_elem("nmethod_removed compile_id='%3d'", nm->compile_id()); |
kvn@1637 | 467 | xtty->stamp(); |
kvn@1637 | 468 | xtty->end_elem(); |
kvn@1637 | 469 | } |
kvn@1637 | 470 | return; |
kvn@1637 | 471 | } |
kvn@1637 | 472 | prev = saved; |
kvn@1637 | 473 | saved = saved->saved_nmethod_link(); |
kvn@1637 | 474 | } |
kvn@1637 | 475 | ShouldNotReachHere(); |
kvn@1637 | 476 | } |
kvn@1637 | 477 | |
kvn@1637 | 478 | void CodeCache::speculatively_disconnect(nmethod* nm) { |
kvn@1637 | 479 | assert_locked_or_safepoint(CodeCache_lock); |
kvn@1637 | 480 | assert(nm->is_in_use() && !nm->is_speculatively_disconnected(), "should only disconnect live nmethods"); |
kvn@1637 | 481 | nm->set_saved_nmethod_link(_saved_nmethods); |
kvn@1637 | 482 | _saved_nmethods = nm; |
kvn@1637 | 483 | if (PrintMethodFlushing) { |
never@1893 | 484 | nm->print_on(tty, " ### nmethod is speculatively disconnected\n"); |
kvn@1637 | 485 | } |
kvn@1637 | 486 | if (LogCompilation && (xtty != NULL)) { |
kvn@1637 | 487 | ttyLocker ttyl; |
kvn@1637 | 488 | xtty->begin_elem("nmethod_disconnected compile_id='%3d'", nm->compile_id()); |
kvn@1637 | 489 | xtty->method(methodOop(nm->method())); |
kvn@1637 | 490 | xtty->stamp(); |
kvn@1637 | 491 | xtty->end_elem(); |
kvn@1637 | 492 | } |
kvn@1637 | 493 | nm->method()->clear_code(); |
kvn@1637 | 494 | nm->set_speculatively_disconnected(true); |
kvn@1637 | 495 | } |
kvn@1637 | 496 | |
kvn@1637 | 497 | |
duke@435 | 498 | void CodeCache::gc_prologue() { |
jrose@1424 | 499 | assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_epilogue must be called"); |
duke@435 | 500 | } |
duke@435 | 501 | |
duke@435 | 502 | |
duke@435 | 503 | void CodeCache::gc_epilogue() { |
duke@435 | 504 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 505 | FOR_ALL_ALIVE_BLOBS(cb) { |
duke@435 | 506 | if (cb->is_nmethod()) { |
duke@435 | 507 | nmethod *nm = (nmethod*)cb; |
duke@435 | 508 | assert(!nm->is_unloaded(), "Tautology"); |
duke@435 | 509 | if (needs_cache_clean()) { |
duke@435 | 510 | nm->cleanup_inline_caches(); |
duke@435 | 511 | } |
twisti@1918 | 512 | DEBUG_ONLY(nm->verify()); |
twisti@1918 | 513 | nm->fix_oop_relocations(); |
duke@435 | 514 | } |
duke@435 | 515 | } |
duke@435 | 516 | set_needs_cache_clean(false); |
jrose@1424 | 517 | prune_scavenge_root_nmethods(); |
jrose@1424 | 518 | assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called"); |
duke@435 | 519 | } |
duke@435 | 520 | |
duke@435 | 521 | |
duke@435 | 522 | address CodeCache::first_address() { |
duke@435 | 523 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 524 | return (address)_heap->begin(); |
duke@435 | 525 | } |
duke@435 | 526 | |
duke@435 | 527 | |
duke@435 | 528 | address CodeCache::last_address() { |
duke@435 | 529 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 530 | return (address)_heap->end(); |
duke@435 | 531 | } |
duke@435 | 532 | |
duke@435 | 533 | |
duke@435 | 534 | void icache_init(); |
duke@435 | 535 | |
duke@435 | 536 | void CodeCache::initialize() { |
duke@435 | 537 | assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points"); |
duke@435 | 538 | #ifdef COMPILER2 |
duke@435 | 539 | assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment, "CodeCacheSegmentSize must be large enough to align inner loops"); |
duke@435 | 540 | #endif |
duke@435 | 541 | assert(CodeCacheSegmentSize >= sizeof(jdouble), "CodeCacheSegmentSize must be large enough to align constants"); |
duke@435 | 542 | // This was originally just a check of the alignment, causing failure, instead, round |
duke@435 | 543 | // the code cache to the page size. In particular, Solaris is moving to a larger |
duke@435 | 544 | // default page size. |
duke@435 | 545 | CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size()); |
duke@435 | 546 | InitialCodeCacheSize = round_to(InitialCodeCacheSize, os::vm_page_size()); |
duke@435 | 547 | ReservedCodeCacheSize = round_to(ReservedCodeCacheSize, os::vm_page_size()); |
duke@435 | 548 | if (!_heap->reserve(ReservedCodeCacheSize, InitialCodeCacheSize, CodeCacheSegmentSize)) { |
duke@435 | 549 | vm_exit_during_initialization("Could not reserve enough space for code cache"); |
duke@435 | 550 | } |
duke@435 | 551 | |
duke@435 | 552 | MemoryService::add_code_heap_memory_pool(_heap); |
duke@435 | 553 | |
duke@435 | 554 | // Initialize ICache flush mechanism |
duke@435 | 555 | // This service is needed for os::register_code_area |
duke@435 | 556 | icache_init(); |
duke@435 | 557 | |
duke@435 | 558 | // Give OS a chance to register generated code area. |
duke@435 | 559 | // This is used on Windows 64 bit platforms to register |
duke@435 | 560 | // Structured Exception Handlers for our generated code. |
duke@435 | 561 | os::register_code_area(_heap->low_boundary(), _heap->high_boundary()); |
duke@435 | 562 | } |
duke@435 | 563 | |
duke@435 | 564 | |
duke@435 | 565 | void codeCache_init() { |
duke@435 | 566 | CodeCache::initialize(); |
duke@435 | 567 | } |
duke@435 | 568 | |
duke@435 | 569 | //------------------------------------------------------------------------------------------------ |
duke@435 | 570 | |
duke@435 | 571 | int CodeCache::number_of_nmethods_with_dependencies() { |
duke@435 | 572 | return _number_of_nmethods_with_dependencies; |
duke@435 | 573 | } |
duke@435 | 574 | |
duke@435 | 575 | void CodeCache::clear_inline_caches() { |
duke@435 | 576 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 577 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 578 | nm->clear_inline_caches(); |
duke@435 | 579 | } |
duke@435 | 580 | } |
duke@435 | 581 | |
duke@435 | 582 | #ifndef PRODUCT |
duke@435 | 583 | // used to keep track of how much time is spent in mark_for_deoptimization |
duke@435 | 584 | static elapsedTimer dependentCheckTime; |
duke@435 | 585 | static int dependentCheckCount = 0; |
duke@435 | 586 | #endif // PRODUCT |
duke@435 | 587 | |
duke@435 | 588 | |
duke@435 | 589 | int CodeCache::mark_for_deoptimization(DepChange& changes) { |
duke@435 | 590 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 591 | |
duke@435 | 592 | #ifndef PRODUCT |
duke@435 | 593 | dependentCheckTime.start(); |
duke@435 | 594 | dependentCheckCount++; |
duke@435 | 595 | #endif // PRODUCT |
duke@435 | 596 | |
duke@435 | 597 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 598 | |
duke@435 | 599 | // search the hierarchy looking for nmethods which are affected by the loading of this class |
duke@435 | 600 | |
duke@435 | 601 | // then search the interfaces this class implements looking for nmethods |
duke@435 | 602 | // which might be dependent of the fact that an interface only had one |
duke@435 | 603 | // implementor. |
duke@435 | 604 | |
duke@435 | 605 | { No_Safepoint_Verifier nsv; |
duke@435 | 606 | for (DepChange::ContextStream str(changes, nsv); str.next(); ) { |
duke@435 | 607 | klassOop d = str.klass(); |
duke@435 | 608 | number_of_marked_CodeBlobs += instanceKlass::cast(d)->mark_dependent_nmethods(changes); |
duke@435 | 609 | } |
duke@435 | 610 | } |
duke@435 | 611 | |
duke@435 | 612 | if (VerifyDependencies) { |
duke@435 | 613 | // Turn off dependency tracing while actually testing deps. |
duke@435 | 614 | NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) ); |
duke@435 | 615 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 616 | if (!nm->is_marked_for_deoptimization() && |
duke@435 | 617 | nm->check_all_dependencies()) { |
duke@435 | 618 | ResourceMark rm; |
duke@435 | 619 | tty->print_cr("Should have been marked for deoptimization:"); |
duke@435 | 620 | changes.print(); |
duke@435 | 621 | nm->print(); |
duke@435 | 622 | nm->print_dependencies(); |
duke@435 | 623 | } |
duke@435 | 624 | } |
duke@435 | 625 | } |
duke@435 | 626 | |
duke@435 | 627 | #ifndef PRODUCT |
duke@435 | 628 | dependentCheckTime.stop(); |
duke@435 | 629 | #endif // PRODUCT |
duke@435 | 630 | |
duke@435 | 631 | return number_of_marked_CodeBlobs; |
duke@435 | 632 | } |
duke@435 | 633 | |
duke@435 | 634 | |
duke@435 | 635 | #ifdef HOTSWAP |
duke@435 | 636 | int CodeCache::mark_for_evol_deoptimization(instanceKlassHandle dependee) { |
duke@435 | 637 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 638 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 639 | |
duke@435 | 640 | // Deoptimize all methods of the evolving class itself |
duke@435 | 641 | objArrayOop old_methods = dependee->methods(); |
duke@435 | 642 | for (int i = 0; i < old_methods->length(); i++) { |
duke@435 | 643 | ResourceMark rm; |
duke@435 | 644 | methodOop old_method = (methodOop) old_methods->obj_at(i); |
duke@435 | 645 | nmethod *nm = old_method->code(); |
duke@435 | 646 | if (nm != NULL) { |
duke@435 | 647 | nm->mark_for_deoptimization(); |
duke@435 | 648 | number_of_marked_CodeBlobs++; |
duke@435 | 649 | } |
duke@435 | 650 | } |
duke@435 | 651 | |
duke@435 | 652 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 653 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 654 | // ...Already marked in the previous pass; don't count it again. |
duke@435 | 655 | } else if (nm->is_evol_dependent_on(dependee())) { |
duke@435 | 656 | ResourceMark rm; |
duke@435 | 657 | nm->mark_for_deoptimization(); |
duke@435 | 658 | number_of_marked_CodeBlobs++; |
duke@435 | 659 | } else { |
duke@435 | 660 | // flush caches in case they refer to a redefined methodOop |
duke@435 | 661 | nm->clear_inline_caches(); |
duke@435 | 662 | } |
duke@435 | 663 | } |
duke@435 | 664 | |
duke@435 | 665 | return number_of_marked_CodeBlobs; |
duke@435 | 666 | } |
duke@435 | 667 | #endif // HOTSWAP |
duke@435 | 668 | |
duke@435 | 669 | |
duke@435 | 670 | // Deoptimize all methods |
duke@435 | 671 | void CodeCache::mark_all_nmethods_for_deoptimization() { |
duke@435 | 672 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 673 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 674 | nm->mark_for_deoptimization(); |
duke@435 | 675 | } |
duke@435 | 676 | } |
duke@435 | 677 | |
duke@435 | 678 | |
duke@435 | 679 | int CodeCache::mark_for_deoptimization(methodOop dependee) { |
duke@435 | 680 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 681 | int number_of_marked_CodeBlobs = 0; |
duke@435 | 682 | |
duke@435 | 683 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 684 | if (nm->is_dependent_on_method(dependee)) { |
duke@435 | 685 | ResourceMark rm; |
duke@435 | 686 | nm->mark_for_deoptimization(); |
duke@435 | 687 | number_of_marked_CodeBlobs++; |
duke@435 | 688 | } |
duke@435 | 689 | } |
duke@435 | 690 | |
duke@435 | 691 | return number_of_marked_CodeBlobs; |
duke@435 | 692 | } |
duke@435 | 693 | |
duke@435 | 694 | void CodeCache::make_marked_nmethods_zombies() { |
duke@435 | 695 | assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
duke@435 | 696 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 697 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 698 | |
duke@435 | 699 | // If the nmethod has already been made non-entrant and it can be converted |
duke@435 | 700 | // then zombie it now. Otherwise make it non-entrant and it will eventually |
duke@435 | 701 | // be zombied when it is no longer seen on the stack. Note that the nmethod |
duke@435 | 702 | // might be "entrant" and not on the stack and so could be zombied immediately |
duke@435 | 703 | // but we can't tell because we don't track it on stack until it becomes |
duke@435 | 704 | // non-entrant. |
duke@435 | 705 | |
duke@435 | 706 | if (nm->is_not_entrant() && nm->can_not_entrant_be_converted()) { |
duke@435 | 707 | nm->make_zombie(); |
duke@435 | 708 | } else { |
duke@435 | 709 | nm->make_not_entrant(); |
duke@435 | 710 | } |
duke@435 | 711 | } |
duke@435 | 712 | } |
duke@435 | 713 | } |
duke@435 | 714 | |
duke@435 | 715 | void CodeCache::make_marked_nmethods_not_entrant() { |
duke@435 | 716 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 717 | FOR_ALL_ALIVE_NMETHODS(nm) { |
duke@435 | 718 | if (nm->is_marked_for_deoptimization()) { |
duke@435 | 719 | nm->make_not_entrant(); |
duke@435 | 720 | } |
duke@435 | 721 | } |
duke@435 | 722 | } |
duke@435 | 723 | |
duke@435 | 724 | void CodeCache::verify() { |
duke@435 | 725 | _heap->verify(); |
duke@435 | 726 | FOR_ALL_ALIVE_BLOBS(p) { |
duke@435 | 727 | p->verify(); |
duke@435 | 728 | } |
duke@435 | 729 | } |
duke@435 | 730 | |
duke@435 | 731 | //------------------------------------------------------------------------------------------------ |
duke@435 | 732 | // Non-product version |
duke@435 | 733 | |
duke@435 | 734 | #ifndef PRODUCT |
duke@435 | 735 | |
duke@435 | 736 | void CodeCache::verify_if_often() { |
duke@435 | 737 | if (VerifyCodeCacheOften) { |
duke@435 | 738 | _heap->verify(); |
duke@435 | 739 | } |
duke@435 | 740 | } |
duke@435 | 741 | |
jrose@1424 | 742 | void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) { |
jrose@1424 | 743 | if (PrintCodeCache2) { // Need to add a new flag |
jrose@1424 | 744 | ResourceMark rm; |
jrose@1424 | 745 | if (size == 0) size = cb->size(); |
jrose@1424 | 746 | tty->print_cr("CodeCache %s: addr: " INTPTR_FORMAT ", size: 0x%x", event, cb, size); |
jrose@1424 | 747 | } |
jrose@1424 | 748 | } |
jrose@1424 | 749 | |
duke@435 | 750 | void CodeCache::print_internals() { |
duke@435 | 751 | int nmethodCount = 0; |
duke@435 | 752 | int runtimeStubCount = 0; |
duke@435 | 753 | int adapterCount = 0; |
duke@435 | 754 | int deoptimizationStubCount = 0; |
duke@435 | 755 | int uncommonTrapStubCount = 0; |
duke@435 | 756 | int bufferBlobCount = 0; |
duke@435 | 757 | int total = 0; |
duke@435 | 758 | int nmethodAlive = 0; |
duke@435 | 759 | int nmethodNotEntrant = 0; |
duke@435 | 760 | int nmethodZombie = 0; |
duke@435 | 761 | int nmethodUnloaded = 0; |
duke@435 | 762 | int nmethodJava = 0; |
duke@435 | 763 | int nmethodNative = 0; |
duke@435 | 764 | int maxCodeSize = 0; |
duke@435 | 765 | ResourceMark rm; |
duke@435 | 766 | |
duke@435 | 767 | CodeBlob *cb; |
duke@435 | 768 | for (cb = first(); cb != NULL; cb = next(cb)) { |
duke@435 | 769 | total++; |
duke@435 | 770 | if (cb->is_nmethod()) { |
duke@435 | 771 | nmethod* nm = (nmethod*)cb; |
duke@435 | 772 | |
duke@435 | 773 | if (Verbose && nm->method() != NULL) { |
duke@435 | 774 | ResourceMark rm; |
duke@435 | 775 | char *method_name = nm->method()->name_and_sig_as_C_string(); |
duke@435 | 776 | tty->print("%s", method_name); |
duke@435 | 777 | if(nm->is_alive()) { tty->print_cr(" alive"); } |
duke@435 | 778 | if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); } |
duke@435 | 779 | if(nm->is_zombie()) { tty->print_cr(" zombie"); } |
duke@435 | 780 | } |
duke@435 | 781 | |
duke@435 | 782 | nmethodCount++; |
duke@435 | 783 | |
duke@435 | 784 | if(nm->is_alive()) { nmethodAlive++; } |
duke@435 | 785 | if(nm->is_not_entrant()) { nmethodNotEntrant++; } |
duke@435 | 786 | if(nm->is_zombie()) { nmethodZombie++; } |
duke@435 | 787 | if(nm->is_unloaded()) { nmethodUnloaded++; } |
duke@435 | 788 | if(nm->is_native_method()) { nmethodNative++; } |
duke@435 | 789 | |
duke@435 | 790 | if(nm->method() != NULL && nm->is_java_method()) { |
duke@435 | 791 | nmethodJava++; |
duke@435 | 792 | if(nm->code_size() > maxCodeSize) { |
duke@435 | 793 | maxCodeSize = nm->code_size(); |
duke@435 | 794 | } |
duke@435 | 795 | } |
duke@435 | 796 | } else if (cb->is_runtime_stub()) { |
duke@435 | 797 | runtimeStubCount++; |
duke@435 | 798 | } else if (cb->is_deoptimization_stub()) { |
duke@435 | 799 | deoptimizationStubCount++; |
duke@435 | 800 | } else if (cb->is_uncommon_trap_stub()) { |
duke@435 | 801 | uncommonTrapStubCount++; |
duke@435 | 802 | } else if (cb->is_adapter_blob()) { |
duke@435 | 803 | adapterCount++; |
duke@435 | 804 | } else if (cb->is_buffer_blob()) { |
duke@435 | 805 | bufferBlobCount++; |
duke@435 | 806 | } |
duke@435 | 807 | } |
duke@435 | 808 | |
duke@435 | 809 | int bucketSize = 512; |
duke@435 | 810 | int bucketLimit = maxCodeSize / bucketSize + 1; |
duke@435 | 811 | int *buckets = NEW_C_HEAP_ARRAY(int, bucketLimit); |
duke@435 | 812 | memset(buckets,0,sizeof(int) * bucketLimit); |
duke@435 | 813 | |
duke@435 | 814 | for (cb = first(); cb != NULL; cb = next(cb)) { |
duke@435 | 815 | if (cb->is_nmethod()) { |
duke@435 | 816 | nmethod* nm = (nmethod*)cb; |
duke@435 | 817 | if(nm->is_java_method()) { |
duke@435 | 818 | buckets[nm->code_size() / bucketSize]++; |
duke@435 | 819 | } |
duke@435 | 820 | } |
duke@435 | 821 | } |
duke@435 | 822 | tty->print_cr("Code Cache Entries (total of %d)",total); |
duke@435 | 823 | tty->print_cr("-------------------------------------------------"); |
duke@435 | 824 | tty->print_cr("nmethods: %d",nmethodCount); |
duke@435 | 825 | tty->print_cr("\talive: %d",nmethodAlive); |
duke@435 | 826 | tty->print_cr("\tnot_entrant: %d",nmethodNotEntrant); |
duke@435 | 827 | tty->print_cr("\tzombie: %d",nmethodZombie); |
duke@435 | 828 | tty->print_cr("\tunloaded: %d",nmethodUnloaded); |
duke@435 | 829 | tty->print_cr("\tjava: %d",nmethodJava); |
duke@435 | 830 | tty->print_cr("\tnative: %d",nmethodNative); |
duke@435 | 831 | tty->print_cr("runtime_stubs: %d",runtimeStubCount); |
duke@435 | 832 | tty->print_cr("adapters: %d",adapterCount); |
duke@435 | 833 | tty->print_cr("buffer blobs: %d",bufferBlobCount); |
duke@435 | 834 | tty->print_cr("deoptimization_stubs: %d",deoptimizationStubCount); |
duke@435 | 835 | tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount); |
duke@435 | 836 | tty->print_cr("\nnmethod size distribution (non-zombie java)"); |
duke@435 | 837 | tty->print_cr("-------------------------------------------------"); |
duke@435 | 838 | |
duke@435 | 839 | for(int i=0; i<bucketLimit; i++) { |
duke@435 | 840 | if(buckets[i] != 0) { |
duke@435 | 841 | tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize); |
duke@435 | 842 | tty->fill_to(40); |
duke@435 | 843 | tty->print_cr("%d",buckets[i]); |
duke@435 | 844 | } |
duke@435 | 845 | } |
duke@435 | 846 | |
duke@435 | 847 | FREE_C_HEAP_ARRAY(int, buckets); |
duke@435 | 848 | } |
duke@435 | 849 | |
duke@435 | 850 | void CodeCache::print() { |
duke@435 | 851 | CodeBlob_sizes live; |
duke@435 | 852 | CodeBlob_sizes dead; |
duke@435 | 853 | |
duke@435 | 854 | FOR_ALL_BLOBS(p) { |
duke@435 | 855 | if (!p->is_alive()) { |
duke@435 | 856 | dead.add(p); |
duke@435 | 857 | } else { |
duke@435 | 858 | live.add(p); |
duke@435 | 859 | } |
duke@435 | 860 | } |
duke@435 | 861 | |
duke@435 | 862 | tty->print_cr("CodeCache:"); |
duke@435 | 863 | |
duke@435 | 864 | tty->print_cr("nmethod dependency checking time %f", dependentCheckTime.seconds(), |
duke@435 | 865 | dependentCheckTime.seconds() / dependentCheckCount); |
duke@435 | 866 | |
duke@435 | 867 | if (!live.is_empty()) { |
duke@435 | 868 | live.print("live"); |
duke@435 | 869 | } |
duke@435 | 870 | if (!dead.is_empty()) { |
duke@435 | 871 | dead.print("dead"); |
duke@435 | 872 | } |
duke@435 | 873 | |
duke@435 | 874 | |
duke@435 | 875 | if (Verbose) { |
duke@435 | 876 | // print the oop_map usage |
duke@435 | 877 | int code_size = 0; |
duke@435 | 878 | int number_of_blobs = 0; |
duke@435 | 879 | int number_of_oop_maps = 0; |
duke@435 | 880 | int map_size = 0; |
duke@435 | 881 | FOR_ALL_BLOBS(p) { |
duke@435 | 882 | if (p->is_alive()) { |
duke@435 | 883 | number_of_blobs++; |
duke@435 | 884 | code_size += p->instructions_size(); |
duke@435 | 885 | OopMapSet* set = p->oop_maps(); |
duke@435 | 886 | if (set != NULL) { |
duke@435 | 887 | number_of_oop_maps += set->size(); |
duke@435 | 888 | map_size += set->heap_size(); |
duke@435 | 889 | } |
duke@435 | 890 | } |
duke@435 | 891 | } |
duke@435 | 892 | tty->print_cr("OopMaps"); |
duke@435 | 893 | tty->print_cr(" #blobs = %d", number_of_blobs); |
duke@435 | 894 | tty->print_cr(" code size = %d", code_size); |
duke@435 | 895 | tty->print_cr(" #oop_maps = %d", number_of_oop_maps); |
duke@435 | 896 | tty->print_cr(" map size = %d", map_size); |
duke@435 | 897 | } |
duke@435 | 898 | |
duke@435 | 899 | } |
duke@435 | 900 | |
duke@435 | 901 | #endif // PRODUCT |