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