src/share/vm/code/codeCache.cpp

Thu, 26 Jul 2018 16:04:06 +0800

author
aoqi
date
Thu, 26 Jul 2018 16:04:06 +0800
changeset 9203
53eec13fbaa5
parent 9191
a0373be7fe1b
parent 8604
04d83ba48607
child 9703
2fdf635bcf28
permissions
-rw-r--r--

Merge

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

mercurial