src/share/vm/code/codeCache.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8604
04d83ba48607
child 9203
53eec13fbaa5
permissions
-rw-r--r--

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);
stefank@6992 340
stefank@6992 341 if (UseG1GC) {
stefank@6992 342 return;
stefank@6992 343 }
stefank@6992 344
aoqi@0 345 debug_only(mark_scavenge_root_nmethods());
aoqi@0 346
aoqi@0 347 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
aoqi@0 348 debug_only(cur->clear_scavenge_root_marked());
aoqi@0 349 assert(cur->scavenge_root_not_marked(), "");
aoqi@0 350 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
aoqi@0 351
aoqi@0 352 bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
aoqi@0 353 #ifndef PRODUCT
aoqi@0 354 if (TraceScavenge) {
aoqi@0 355 cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
aoqi@0 356 }
aoqi@0 357 #endif //PRODUCT
aoqi@0 358 if (is_live) {
aoqi@0 359 // Perform cur->oops_do(f), maybe just once per nmethod.
aoqi@0 360 f->do_code_blob(cur);
aoqi@0 361 }
aoqi@0 362 }
aoqi@0 363
aoqi@0 364 // Check for stray marks.
aoqi@0 365 debug_only(verify_perm_nmethods(NULL));
aoqi@0 366 }
aoqi@0 367
aoqi@0 368 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
aoqi@0 369 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 370
stefank@6992 371 if (UseG1GC) {
stefank@6992 372 return;
stefank@6992 373 }
stefank@6992 374
aoqi@0 375 nm->set_on_scavenge_root_list();
aoqi@0 376 nm->set_scavenge_root_link(_scavenge_root_nmethods);
aoqi@0 377 set_scavenge_root_nmethods(nm);
aoqi@0 378 print_trace("add_scavenge_root", nm);
aoqi@0 379 }
aoqi@0 380
aoqi@0 381 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
aoqi@0 382 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 383
stefank@6992 384 if (UseG1GC) {
stefank@6992 385 return;
stefank@6992 386 }
stefank@6992 387
aoqi@0 388 print_trace("drop_scavenge_root", nm);
aoqi@0 389 nmethod* last = NULL;
aoqi@0 390 nmethod* cur = scavenge_root_nmethods();
aoqi@0 391 while (cur != NULL) {
aoqi@0 392 nmethod* next = cur->scavenge_root_link();
aoqi@0 393 if (cur == nm) {
aoqi@0 394 if (last != NULL)
aoqi@0 395 last->set_scavenge_root_link(next);
aoqi@0 396 else set_scavenge_root_nmethods(next);
aoqi@0 397 nm->set_scavenge_root_link(NULL);
aoqi@0 398 nm->clear_on_scavenge_root_list();
aoqi@0 399 return;
aoqi@0 400 }
aoqi@0 401 last = cur;
aoqi@0 402 cur = next;
aoqi@0 403 }
aoqi@0 404 assert(false, "should have been on list");
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 void CodeCache::prune_scavenge_root_nmethods() {
aoqi@0 408 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 409
stefank@6992 410 if (UseG1GC) {
stefank@6992 411 return;
stefank@6992 412 }
stefank@6992 413
aoqi@0 414 debug_only(mark_scavenge_root_nmethods());
aoqi@0 415
aoqi@0 416 nmethod* last = NULL;
aoqi@0 417 nmethod* cur = scavenge_root_nmethods();
aoqi@0 418 while (cur != NULL) {
aoqi@0 419 nmethod* next = cur->scavenge_root_link();
aoqi@0 420 debug_only(cur->clear_scavenge_root_marked());
aoqi@0 421 assert(cur->scavenge_root_not_marked(), "");
aoqi@0 422 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
aoqi@0 423
aoqi@0 424 if (!cur->is_zombie() && !cur->is_unloaded()
aoqi@0 425 && cur->detect_scavenge_root_oops()) {
aoqi@0 426 // Keep it. Advance 'last' to prevent deletion.
aoqi@0 427 last = cur;
aoqi@0 428 } else {
aoqi@0 429 // Prune it from the list, so we don't have to look at it any more.
aoqi@0 430 print_trace("prune_scavenge_root", cur);
aoqi@0 431 cur->set_scavenge_root_link(NULL);
aoqi@0 432 cur->clear_on_scavenge_root_list();
aoqi@0 433 if (last != NULL)
aoqi@0 434 last->set_scavenge_root_link(next);
aoqi@0 435 else set_scavenge_root_nmethods(next);
aoqi@0 436 }
aoqi@0 437 cur = next;
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 // Check for stray marks.
aoqi@0 441 debug_only(verify_perm_nmethods(NULL));
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 #ifndef PRODUCT
aoqi@0 445 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
stefank@6992 446 if (UseG1GC) {
stefank@6992 447 return;
stefank@6992 448 }
stefank@6992 449
aoqi@0 450 // While we are here, verify the integrity of the list.
aoqi@0 451 mark_scavenge_root_nmethods();
aoqi@0 452 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
aoqi@0 453 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
aoqi@0 454 cur->clear_scavenge_root_marked();
aoqi@0 455 }
aoqi@0 456 verify_perm_nmethods(f);
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 // Temporarily mark nmethods that are claimed to be on the non-perm list.
aoqi@0 460 void CodeCache::mark_scavenge_root_nmethods() {
aoqi@0 461 FOR_ALL_ALIVE_BLOBS(cb) {
aoqi@0 462 if (cb->is_nmethod()) {
aoqi@0 463 nmethod *nm = (nmethod*)cb;
aoqi@0 464 assert(nm->scavenge_root_not_marked(), "clean state");
aoqi@0 465 if (nm->on_scavenge_root_list())
aoqi@0 466 nm->set_scavenge_root_marked();
aoqi@0 467 }
aoqi@0 468 }
aoqi@0 469 }
aoqi@0 470
aoqi@0 471 // If the closure is given, run it on the unlisted nmethods.
aoqi@0 472 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
aoqi@0 473 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
aoqi@0 474 FOR_ALL_ALIVE_BLOBS(cb) {
aoqi@0 475 bool call_f = (f_or_null != NULL);
aoqi@0 476 if (cb->is_nmethod()) {
aoqi@0 477 nmethod *nm = (nmethod*)cb;
aoqi@0 478 assert(nm->scavenge_root_not_marked(), "must be already processed");
aoqi@0 479 if (nm->on_scavenge_root_list())
aoqi@0 480 call_f = false; // don't show this one to the client
aoqi@0 481 nm->verify_scavenge_root_oops();
aoqi@0 482 } else {
aoqi@0 483 call_f = false; // not an nmethod
aoqi@0 484 }
aoqi@0 485 if (call_f) f_or_null->do_code_blob(cb);
aoqi@0 486 }
aoqi@0 487 }
aoqi@0 488 #endif //PRODUCT
aoqi@0 489
stefank@6992 490 void CodeCache::verify_clean_inline_caches() {
stefank@6992 491 #ifdef ASSERT
stefank@6992 492 FOR_ALL_ALIVE_BLOBS(cb) {
stefank@6992 493 if (cb->is_nmethod()) {
stefank@6992 494 nmethod* nm = (nmethod*)cb;
stefank@6992 495 assert(!nm->is_unloaded(), "Tautology");
stefank@6992 496 nm->verify_clean_inline_caches();
stefank@6992 497 nm->verify();
stefank@6992 498 }
stefank@6992 499 }
stefank@6992 500 #endif
stefank@6992 501 }
stefank@6992 502
stefank@6992 503 void CodeCache::verify_icholder_relocations() {
stefank@6992 504 #ifdef ASSERT
stefank@6992 505 // make sure that we aren't leaking icholders
stefank@6992 506 int count = 0;
stefank@6992 507 FOR_ALL_BLOBS(cb) {
stefank@6992 508 if (cb->is_nmethod()) {
stefank@6992 509 nmethod* nm = (nmethod*)cb;
stefank@6992 510 count += nm->verify_icholder_relocations();
stefank@6992 511 }
stefank@6992 512 }
stefank@6992 513
stefank@6992 514 assert(count + InlineCacheBuffer::pending_icholder_count() + CompiledICHolder::live_not_claimed_count() ==
stefank@6992 515 CompiledICHolder::live_count(), "must agree");
stefank@6992 516 #endif
stefank@6992 517 }
aoqi@0 518
aoqi@0 519 void CodeCache::gc_prologue() {
aoqi@0 520 }
aoqi@0 521
aoqi@0 522 void CodeCache::gc_epilogue() {
aoqi@0 523 assert_locked_or_safepoint(CodeCache_lock);
thartmann@8075 524 NOT_DEBUG(if (needs_cache_clean())) {
thartmann@8075 525 FOR_ALL_ALIVE_BLOBS(cb) {
thartmann@8075 526 if (cb->is_nmethod()) {
thartmann@8075 527 nmethod *nm = (nmethod*)cb;
thartmann@8075 528 assert(!nm->is_unloaded(), "Tautology");
thartmann@8075 529 DEBUG_ONLY(if (needs_cache_clean())) {
thartmann@8074 530 nm->cleanup_inline_caches();
thartmann@8074 531 }
thartmann@8074 532 DEBUG_ONLY(nm->verify());
thartmann@8074 533 DEBUG_ONLY(nm->verify_oop_relocations());
aoqi@0 534 }
aoqi@0 535 }
aoqi@0 536 }
aoqi@0 537 set_needs_cache_clean(false);
aoqi@0 538 prune_scavenge_root_nmethods();
aoqi@0 539
stefank@6992 540 verify_icholder_relocations();
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 void CodeCache::verify_oops() {
aoqi@0 544 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 545 VerifyOopClosure voc;
aoqi@0 546 FOR_ALL_ALIVE_BLOBS(cb) {
aoqi@0 547 if (cb->is_nmethod()) {
aoqi@0 548 nmethod *nm = (nmethod*)cb;
aoqi@0 549 nm->oops_do(&voc);
aoqi@0 550 nm->verify_oop_relocations();
aoqi@0 551 }
aoqi@0 552 }
aoqi@0 553 }
aoqi@0 554
aoqi@0 555
aoqi@0 556 address CodeCache::first_address() {
aoqi@0 557 assert_locked_or_safepoint(CodeCache_lock);
aoqi@0 558 return (address)_heap->low_boundary();
aoqi@0 559 }
aoqi@0 560
aoqi@0 561
aoqi@0 562 address CodeCache::last_address() {
aoqi@0 563 assert_locked_or_safepoint(CodeCache_lock);
aoqi@0 564 return (address)_heap->high();
aoqi@0 565 }
aoqi@0 566
aoqi@0 567 /**
aoqi@0 568 * Returns the reverse free ratio. E.g., if 25% (1/4) of the code cache
aoqi@0 569 * is free, reverse_free_ratio() returns 4.
aoqi@0 570 */
aoqi@0 571 double CodeCache::reverse_free_ratio() {
aoqi@0 572 double unallocated_capacity = (double)(CodeCache::unallocated_capacity() - CodeCacheMinimumFreeSpace);
aoqi@0 573 double max_capacity = (double)CodeCache::max_capacity();
aoqi@0 574 return max_capacity / unallocated_capacity;
aoqi@0 575 }
aoqi@0 576
aoqi@0 577 void icache_init();
aoqi@0 578
aoqi@0 579 void CodeCache::initialize() {
aoqi@0 580 assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points");
aoqi@0 581 #ifdef COMPILER2
aoqi@0 582 assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment, "CodeCacheSegmentSize must be large enough to align inner loops");
aoqi@0 583 #endif
aoqi@0 584 assert(CodeCacheSegmentSize >= sizeof(jdouble), "CodeCacheSegmentSize must be large enough to align constants");
aoqi@0 585 // This was originally just a check of the alignment, causing failure, instead, round
aoqi@0 586 // the code cache to the page size. In particular, Solaris is moving to a larger
aoqi@0 587 // default page size.
aoqi@0 588 CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size());
aoqi@0 589 InitialCodeCacheSize = round_to(InitialCodeCacheSize, os::vm_page_size());
aoqi@0 590 ReservedCodeCacheSize = round_to(ReservedCodeCacheSize, os::vm_page_size());
aoqi@0 591 if (!_heap->reserve(ReservedCodeCacheSize, InitialCodeCacheSize, CodeCacheSegmentSize)) {
aoqi@0 592 vm_exit_during_initialization("Could not reserve enough space for code cache");
aoqi@0 593 }
aoqi@0 594
aoqi@0 595 MemoryService::add_code_heap_memory_pool(_heap);
aoqi@0 596
aoqi@0 597 // Initialize ICache flush mechanism
aoqi@0 598 // This service is needed for os::register_code_area
aoqi@0 599 icache_init();
aoqi@0 600
aoqi@0 601 // Give OS a chance to register generated code area.
aoqi@0 602 // This is used on Windows 64 bit platforms to register
aoqi@0 603 // Structured Exception Handlers for our generated code.
aoqi@0 604 os::register_code_area(_heap->low_boundary(), _heap->high_boundary());
aoqi@0 605 }
aoqi@0 606
aoqi@0 607
aoqi@0 608 void codeCache_init() {
aoqi@0 609 CodeCache::initialize();
aoqi@0 610 }
aoqi@0 611
aoqi@0 612 //------------------------------------------------------------------------------------------------
aoqi@0 613
aoqi@0 614 int CodeCache::number_of_nmethods_with_dependencies() {
aoqi@0 615 return _number_of_nmethods_with_dependencies;
aoqi@0 616 }
aoqi@0 617
aoqi@0 618 void CodeCache::clear_inline_caches() {
aoqi@0 619 assert_locked_or_safepoint(CodeCache_lock);
aoqi@0 620 FOR_ALL_ALIVE_NMETHODS(nm) {
aoqi@0 621 nm->clear_inline_caches();
aoqi@0 622 }
aoqi@0 623 }
aoqi@0 624
aoqi@0 625 #ifndef PRODUCT
aoqi@0 626 // used to keep track of how much time is spent in mark_for_deoptimization
aoqi@0 627 static elapsedTimer dependentCheckTime;
aoqi@0 628 static int dependentCheckCount = 0;
aoqi@0 629 #endif // PRODUCT
aoqi@0 630
aoqi@0 631
aoqi@0 632 int CodeCache::mark_for_deoptimization(DepChange& changes) {
aoqi@0 633 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 634
aoqi@0 635 #ifndef PRODUCT
aoqi@0 636 dependentCheckTime.start();
aoqi@0 637 dependentCheckCount++;
aoqi@0 638 #endif // PRODUCT
aoqi@0 639
aoqi@0 640 int number_of_marked_CodeBlobs = 0;
aoqi@0 641
aoqi@0 642 // search the hierarchy looking for nmethods which are affected by the loading of this class
aoqi@0 643
aoqi@0 644 // then search the interfaces this class implements looking for nmethods
aoqi@0 645 // which might be dependent of the fact that an interface only had one
aoqi@0 646 // implementor.
aoqi@0 647
aoqi@0 648 { No_Safepoint_Verifier nsv;
aoqi@0 649 for (DepChange::ContextStream str(changes, nsv); str.next(); ) {
aoqi@0 650 Klass* d = str.klass();
aoqi@0 651 number_of_marked_CodeBlobs += InstanceKlass::cast(d)->mark_dependent_nmethods(changes);
aoqi@0 652 }
aoqi@0 653 }
aoqi@0 654
aoqi@0 655 if (VerifyDependencies) {
aoqi@0 656 // Turn off dependency tracing while actually testing deps.
aoqi@0 657 NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) );
aoqi@0 658 FOR_ALL_ALIVE_NMETHODS(nm) {
aoqi@0 659 if (!nm->is_marked_for_deoptimization() &&
aoqi@0 660 nm->check_all_dependencies()) {
aoqi@0 661 ResourceMark rm;
aoqi@0 662 tty->print_cr("Should have been marked for deoptimization:");
aoqi@0 663 changes.print();
aoqi@0 664 nm->print();
aoqi@0 665 nm->print_dependencies();
aoqi@0 666 }
aoqi@0 667 }
aoqi@0 668 }
aoqi@0 669
aoqi@0 670 #ifndef PRODUCT
aoqi@0 671 dependentCheckTime.stop();
aoqi@0 672 #endif // PRODUCT
aoqi@0 673
aoqi@0 674 return number_of_marked_CodeBlobs;
aoqi@0 675 }
aoqi@0 676
aoqi@0 677
aoqi@0 678 #ifdef HOTSWAP
aoqi@0 679 int CodeCache::mark_for_evol_deoptimization(instanceKlassHandle dependee) {
aoqi@0 680 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 681 int number_of_marked_CodeBlobs = 0;
aoqi@0 682
aoqi@0 683 // Deoptimize all methods of the evolving class itself
aoqi@0 684 Array<Method*>* old_methods = dependee->methods();
aoqi@0 685 for (int i = 0; i < old_methods->length(); i++) {
aoqi@0 686 ResourceMark rm;
aoqi@0 687 Method* old_method = old_methods->at(i);
aoqi@0 688 nmethod *nm = old_method->code();
aoqi@0 689 if (nm != NULL) {
aoqi@0 690 nm->mark_for_deoptimization();
aoqi@0 691 number_of_marked_CodeBlobs++;
aoqi@0 692 }
aoqi@0 693 }
aoqi@0 694
aoqi@0 695 FOR_ALL_ALIVE_NMETHODS(nm) {
aoqi@0 696 if (nm->is_marked_for_deoptimization()) {
aoqi@0 697 // ...Already marked in the previous pass; don't count it again.
aoqi@0 698 } else if (nm->is_evol_dependent_on(dependee())) {
aoqi@0 699 ResourceMark rm;
aoqi@0 700 nm->mark_for_deoptimization();
aoqi@0 701 number_of_marked_CodeBlobs++;
aoqi@0 702 } else {
aoqi@0 703 // flush caches in case they refer to a redefined Method*
aoqi@0 704 nm->clear_inline_caches();
aoqi@0 705 }
aoqi@0 706 }
aoqi@0 707
aoqi@0 708 return number_of_marked_CodeBlobs;
aoqi@0 709 }
aoqi@0 710 #endif // HOTSWAP
aoqi@0 711
aoqi@0 712
aoqi@0 713 // Deoptimize all methods
aoqi@0 714 void CodeCache::mark_all_nmethods_for_deoptimization() {
aoqi@0 715 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 716 FOR_ALL_ALIVE_NMETHODS(nm) {
iveresov@7146 717 if (!nm->method()->is_method_handle_intrinsic()) {
iveresov@7146 718 nm->mark_for_deoptimization();
iveresov@7146 719 }
aoqi@0 720 }
aoqi@0 721 }
aoqi@0 722
aoqi@0 723
aoqi@0 724 int CodeCache::mark_for_deoptimization(Method* dependee) {
aoqi@0 725 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 726 int number_of_marked_CodeBlobs = 0;
aoqi@0 727
aoqi@0 728 FOR_ALL_ALIVE_NMETHODS(nm) {
aoqi@0 729 if (nm->is_dependent_on_method(dependee)) {
aoqi@0 730 ResourceMark rm;
aoqi@0 731 nm->mark_for_deoptimization();
aoqi@0 732 number_of_marked_CodeBlobs++;
aoqi@0 733 }
aoqi@0 734 }
aoqi@0 735
aoqi@0 736 return number_of_marked_CodeBlobs;
aoqi@0 737 }
aoqi@0 738
aoqi@0 739 void CodeCache::make_marked_nmethods_not_entrant() {
aoqi@0 740 assert_locked_or_safepoint(CodeCache_lock);
aoqi@0 741 FOR_ALL_ALIVE_NMETHODS(nm) {
aoqi@0 742 if (nm->is_marked_for_deoptimization()) {
aoqi@0 743 nm->make_not_entrant();
aoqi@0 744 }
aoqi@0 745 }
aoqi@0 746 }
aoqi@0 747
aoqi@0 748 void CodeCache::verify() {
aoqi@0 749 _heap->verify();
aoqi@0 750 FOR_ALL_ALIVE_BLOBS(p) {
aoqi@0 751 p->verify();
aoqi@0 752 }
aoqi@0 753 }
aoqi@0 754
aoqi@0 755 void CodeCache::report_codemem_full() {
aoqi@0 756 _codemem_full_count++;
aoqi@0 757 EventCodeCacheFull event;
aoqi@0 758 if (event.should_commit()) {
aoqi@0 759 event.set_startAddress((u8)low_bound());
aoqi@0 760 event.set_commitedTopAddress((u8)high());
aoqi@0 761 event.set_reservedTopAddress((u8)high_bound());
aoqi@0 762 event.set_entryCount(nof_blobs());
aoqi@0 763 event.set_methodCount(nof_nmethods());
aoqi@0 764 event.set_adaptorCount(nof_adapters());
aoqi@0 765 event.set_unallocatedCapacity(unallocated_capacity()/K);
aoqi@0 766 event.set_fullCount(_codemem_full_count);
aoqi@0 767 event.commit();
aoqi@0 768 }
aoqi@0 769 }
aoqi@0 770
aoqi@0 771 //------------------------------------------------------------------------------------------------
aoqi@0 772 // Non-product version
aoqi@0 773
aoqi@0 774 #ifndef PRODUCT
aoqi@0 775
aoqi@0 776 void CodeCache::verify_if_often() {
aoqi@0 777 if (VerifyCodeCacheOften) {
aoqi@0 778 _heap->verify();
aoqi@0 779 }
aoqi@0 780 }
aoqi@0 781
aoqi@0 782 void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
aoqi@0 783 if (PrintCodeCache2) { // Need to add a new flag
aoqi@0 784 ResourceMark rm;
aoqi@0 785 if (size == 0) size = cb->size();
aoqi@0 786 tty->print_cr("CodeCache %s: addr: " INTPTR_FORMAT ", size: 0x%x", event, p2i(cb), size);
aoqi@0 787 }
aoqi@0 788 }
aoqi@0 789
aoqi@0 790 void CodeCache::print_internals() {
aoqi@0 791 int nmethodCount = 0;
aoqi@0 792 int runtimeStubCount = 0;
aoqi@0 793 int adapterCount = 0;
aoqi@0 794 int deoptimizationStubCount = 0;
aoqi@0 795 int uncommonTrapStubCount = 0;
aoqi@0 796 int bufferBlobCount = 0;
aoqi@0 797 int total = 0;
aoqi@0 798 int nmethodAlive = 0;
aoqi@0 799 int nmethodNotEntrant = 0;
aoqi@0 800 int nmethodZombie = 0;
aoqi@0 801 int nmethodUnloaded = 0;
aoqi@0 802 int nmethodJava = 0;
aoqi@0 803 int nmethodNative = 0;
aoqi@0 804 int maxCodeSize = 0;
aoqi@0 805 ResourceMark rm;
aoqi@0 806
aoqi@0 807 CodeBlob *cb;
aoqi@0 808 for (cb = first(); cb != NULL; cb = next(cb)) {
aoqi@0 809 total++;
aoqi@0 810 if (cb->is_nmethod()) {
aoqi@0 811 nmethod* nm = (nmethod*)cb;
aoqi@0 812
aoqi@0 813 if (Verbose && nm->method() != NULL) {
aoqi@0 814 ResourceMark rm;
aoqi@0 815 char *method_name = nm->method()->name_and_sig_as_C_string();
aoqi@0 816 tty->print("%s", method_name);
aoqi@0 817 if(nm->is_alive()) { tty->print_cr(" alive"); }
aoqi@0 818 if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); }
aoqi@0 819 if(nm->is_zombie()) { tty->print_cr(" zombie"); }
aoqi@0 820 }
aoqi@0 821
aoqi@0 822 nmethodCount++;
aoqi@0 823
aoqi@0 824 if(nm->is_alive()) { nmethodAlive++; }
aoqi@0 825 if(nm->is_not_entrant()) { nmethodNotEntrant++; }
aoqi@0 826 if(nm->is_zombie()) { nmethodZombie++; }
aoqi@0 827 if(nm->is_unloaded()) { nmethodUnloaded++; }
aoqi@0 828 if(nm->is_native_method()) { nmethodNative++; }
aoqi@0 829
aoqi@0 830 if(nm->method() != NULL && nm->is_java_method()) {
aoqi@0 831 nmethodJava++;
aoqi@0 832 if (nm->insts_size() > maxCodeSize) {
aoqi@0 833 maxCodeSize = nm->insts_size();
aoqi@0 834 }
aoqi@0 835 }
aoqi@0 836 } else if (cb->is_runtime_stub()) {
aoqi@0 837 runtimeStubCount++;
aoqi@0 838 } else if (cb->is_deoptimization_stub()) {
aoqi@0 839 deoptimizationStubCount++;
aoqi@0 840 } else if (cb->is_uncommon_trap_stub()) {
aoqi@0 841 uncommonTrapStubCount++;
aoqi@0 842 } else if (cb->is_adapter_blob()) {
aoqi@0 843 adapterCount++;
aoqi@0 844 } else if (cb->is_buffer_blob()) {
aoqi@0 845 bufferBlobCount++;
aoqi@0 846 }
aoqi@0 847 }
aoqi@0 848
aoqi@0 849 int bucketSize = 512;
aoqi@0 850 int bucketLimit = maxCodeSize / bucketSize + 1;
aoqi@0 851 int *buckets = NEW_C_HEAP_ARRAY(int, bucketLimit, mtCode);
aoqi@0 852 memset(buckets,0,sizeof(int) * bucketLimit);
aoqi@0 853
aoqi@0 854 for (cb = first(); cb != NULL; cb = next(cb)) {
aoqi@0 855 if (cb->is_nmethod()) {
aoqi@0 856 nmethod* nm = (nmethod*)cb;
aoqi@0 857 if(nm->is_java_method()) {
aoqi@0 858 buckets[nm->insts_size() / bucketSize]++;
aoqi@0 859 }
aoqi@0 860 }
aoqi@0 861 }
aoqi@0 862 tty->print_cr("Code Cache Entries (total of %d)",total);
aoqi@0 863 tty->print_cr("-------------------------------------------------");
aoqi@0 864 tty->print_cr("nmethods: %d",nmethodCount);
aoqi@0 865 tty->print_cr("\talive: %d",nmethodAlive);
aoqi@0 866 tty->print_cr("\tnot_entrant: %d",nmethodNotEntrant);
aoqi@0 867 tty->print_cr("\tzombie: %d",nmethodZombie);
aoqi@0 868 tty->print_cr("\tunloaded: %d",nmethodUnloaded);
aoqi@0 869 tty->print_cr("\tjava: %d",nmethodJava);
aoqi@0 870 tty->print_cr("\tnative: %d",nmethodNative);
aoqi@0 871 tty->print_cr("runtime_stubs: %d",runtimeStubCount);
aoqi@0 872 tty->print_cr("adapters: %d",adapterCount);
aoqi@0 873 tty->print_cr("buffer blobs: %d",bufferBlobCount);
aoqi@0 874 tty->print_cr("deoptimization_stubs: %d",deoptimizationStubCount);
aoqi@0 875 tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount);
aoqi@0 876 tty->print_cr("\nnmethod size distribution (non-zombie java)");
aoqi@0 877 tty->print_cr("-------------------------------------------------");
aoqi@0 878
aoqi@0 879 for(int i=0; i<bucketLimit; i++) {
aoqi@0 880 if(buckets[i] != 0) {
aoqi@0 881 tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize);
aoqi@0 882 tty->fill_to(40);
aoqi@0 883 tty->print_cr("%d",buckets[i]);
aoqi@0 884 }
aoqi@0 885 }
aoqi@0 886
aoqi@0 887 FREE_C_HEAP_ARRAY(int, buckets, mtCode);
aoqi@0 888 }
aoqi@0 889
aoqi@0 890 #endif // !PRODUCT
aoqi@0 891
aoqi@0 892 void CodeCache::print() {
aoqi@0 893 print_summary(tty);
aoqi@0 894
aoqi@0 895 #ifndef PRODUCT
aoqi@0 896 if (!Verbose) return;
aoqi@0 897
aoqi@0 898 CodeBlob_sizes live;
aoqi@0 899 CodeBlob_sizes dead;
aoqi@0 900
aoqi@0 901 FOR_ALL_BLOBS(p) {
aoqi@0 902 if (!p->is_alive()) {
aoqi@0 903 dead.add(p);
aoqi@0 904 } else {
aoqi@0 905 live.add(p);
aoqi@0 906 }
aoqi@0 907 }
aoqi@0 908
aoqi@0 909 tty->print_cr("CodeCache:");
aoqi@0 910
aoqi@0 911 tty->print_cr("nmethod dependency checking time %f, per dependent %f", dependentCheckTime.seconds(),
aoqi@0 912 dependentCheckTime.seconds() / dependentCheckCount);
aoqi@0 913
aoqi@0 914 if (!live.is_empty()) {
aoqi@0 915 live.print("live");
aoqi@0 916 }
aoqi@0 917 if (!dead.is_empty()) {
aoqi@0 918 dead.print("dead");
aoqi@0 919 }
aoqi@0 920
aoqi@0 921
aoqi@0 922 if (WizardMode) {
aoqi@0 923 // print the oop_map usage
aoqi@0 924 int code_size = 0;
aoqi@0 925 int number_of_blobs = 0;
aoqi@0 926 int number_of_oop_maps = 0;
aoqi@0 927 int map_size = 0;
aoqi@0 928 FOR_ALL_BLOBS(p) {
aoqi@0 929 if (p->is_alive()) {
aoqi@0 930 number_of_blobs++;
aoqi@0 931 code_size += p->code_size();
aoqi@0 932 OopMapSet* set = p->oop_maps();
aoqi@0 933 if (set != NULL) {
aoqi@0 934 number_of_oop_maps += set->size();
aoqi@0 935 map_size += set->heap_size();
aoqi@0 936 }
aoqi@0 937 }
aoqi@0 938 }
aoqi@0 939 tty->print_cr("OopMaps");
aoqi@0 940 tty->print_cr(" #blobs = %d", number_of_blobs);
aoqi@0 941 tty->print_cr(" code size = %d", code_size);
aoqi@0 942 tty->print_cr(" #oop_maps = %d", number_of_oop_maps);
aoqi@0 943 tty->print_cr(" map size = %d", map_size);
aoqi@0 944 }
aoqi@0 945
aoqi@0 946 #endif // !PRODUCT
aoqi@0 947 }
aoqi@0 948
aoqi@0 949 void CodeCache::print_summary(outputStream* st, bool detailed) {
aoqi@0 950 size_t total = (_heap->high_boundary() - _heap->low_boundary());
aoqi@0 951 st->print_cr("CodeCache: size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
aoqi@0 952 "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
aoqi@0 953 total/K, (total - unallocated_capacity())/K,
aoqi@0 954 maxCodeCacheUsed/K, unallocated_capacity()/K);
aoqi@0 955
aoqi@0 956 if (detailed) {
aoqi@0 957 st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
aoqi@0 958 p2i(_heap->low_boundary()),
aoqi@0 959 p2i(_heap->high()),
aoqi@0 960 p2i(_heap->high_boundary()));
aoqi@0 961 st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
aoqi@0 962 " adapters=" UINT32_FORMAT,
aoqi@0 963 nof_blobs(), nof_nmethods(), nof_adapters());
aoqi@0 964 st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
aoqi@0 965 "enabled" : Arguments::mode() == Arguments::_int ?
aoqi@0 966 "disabled (interpreter mode)" :
aoqi@0 967 "disabled (not enough contiguous free space left)");
aoqi@0 968 }
aoqi@0 969 }
aoqi@0 970
aoqi@0 971 void CodeCache::log_state(outputStream* st) {
aoqi@0 972 st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
aoqi@0 973 " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
aoqi@0 974 nof_blobs(), nof_nmethods(), nof_adapters(),
aoqi@0 975 unallocated_capacity());
aoqi@0 976 }
aoqi@0 977

mercurial