src/share/vm/memory/genCollectedHeap.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
   1 /*
   2  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/icBuffer.hpp"
  30 #include "gc_implementation/shared/collectorCounters.hpp"

  31 #include "gc_implementation/shared/vmGCOperations.hpp"
  32 #include "gc_interface/collectedHeap.inline.hpp"
  33 #include "memory/filemap.hpp"
  34 #include "memory/gcLocker.inline.hpp"
  35 #include "memory/genCollectedHeap.hpp"
  36 #include "memory/genOopClosures.inline.hpp"
  37 #include "memory/generation.inline.hpp"
  38 #include "memory/generationSpec.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/sharedHeap.hpp"
  41 #include "memory/space.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/oop.inline2.hpp"
  44 #include "runtime/aprofiler.hpp"
  45 #include "runtime/biasedLocking.hpp"
  46 #include "runtime/fprofiler.hpp"
  47 #include "runtime/handles.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/vmThread.hpp"


 371   if (GC_locker::check_active_before_gc()) {
 372     return; // GC is disabled (e.g. JNI GetXXXCritical operation)
 373   }
 374 
 375   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
 376                           collector_policy()->should_clear_all_soft_refs();
 377 
 378   ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
 379 
 380   const size_t metadata_prev_used = MetaspaceAux::allocated_used_bytes();
 381 
 382   print_heap_before_gc();
 383 
 384   {
 385     FlagSetting fl(_is_gc_active, true);
 386 
 387     bool complete = full && (max_level == (n_gens()-1));
 388     const char* gc_cause_prefix = complete ? "Full GC" : "GC";
 389     gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
 390     TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
 391     TraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, gclog_or_tty);
 392 
 393     gc_prologue(complete);
 394     increment_total_collections(complete);
 395 
 396     size_t gch_prev_used = used();
 397 
 398     int starting_level = 0;
 399     if (full) {
 400       // Search for the oldest generation which will collect all younger
 401       // generations, and start collection loop there.
 402       for (int i = max_level; i >= 0; i--) {
 403         if (_gens[i]->full_collects_younger_generations()) {
 404           starting_level = i;
 405           break;
 406         }
 407       }
 408     }
 409 
 410     bool must_restore_marks_for_biased_locking = false;
 411 
 412     int max_level_collected = starting_level;
 413     for (int i = starting_level; i <= max_level; i++) {
 414       if (_gens[i]->should_collect(full, size, is_tlab)) {
 415         if (i == n_gens() - 1) {  // a major collection is to happen
 416           if (!complete) {
 417             // The full_collections increment was missed above.
 418             increment_total_full_collections();
 419           }
 420           pre_full_gc_dump();    // do any pre full gc dumps
 421         }
 422         // Timer for individual generations. Last argument is false: no CR
 423         TraceTime t1(_gens[i]->short_name(), PrintGCDetails, false, gclog_or_tty);

 424         TraceCollectorStats tcs(_gens[i]->counters());
 425         TraceMemoryManagerStats tmms(_gens[i]->kind(),gc_cause());
 426 
 427         size_t prev_used = _gens[i]->used();
 428         _gens[i]->stat_record()->invocations++;
 429         _gens[i]->stat_record()->accumulated_time.start();
 430 
 431         // Must be done anew before each collection because
 432         // a previous collection will do mangling and will
 433         // change top of some spaces.
 434         record_gen_tops_before_GC();
 435 
 436         if (PrintGC && Verbose) {
 437           gclog_or_tty->print("level=%d invoke=%d size=" SIZE_FORMAT,
 438                      i,
 439                      _gens[i]->stat_record()->invocations,
 440                      size*HeapWordSize);
 441         }
 442 
 443         if (VerifyBeforeGC && i >= VerifyGCLevel &&


 517 
 518         if (VerifyAfterGC && i >= VerifyGCLevel &&
 519             total_collections() >= VerifyGCStartAt) {
 520           HandleMark hm;  // Discard invalid handles created during verification
 521           Universe::verify(" VerifyAfterGC:");
 522         }
 523 
 524         if (PrintGCDetails) {
 525           gclog_or_tty->print(":");
 526           _gens[i]->print_heap_change(prev_used);
 527         }
 528       }
 529     }
 530 
 531     // Update "complete" boolean wrt what actually transpired --
 532     // for instance, a promotion failure could have led to
 533     // a whole heap collection.
 534     complete = complete || (max_level_collected == n_gens() - 1);
 535 
 536     if (complete) { // We did a "major" collection
 537       post_full_gc_dump();   // do any post full gc dumps

 538     }
 539 
 540     if (PrintGCDetails) {
 541       print_heap_change(gch_prev_used);
 542 
 543       // Print metaspace info for full GC with PrintGCDetails flag.
 544       if (complete) {
 545         MetaspaceAux::print_metaspace_change(metadata_prev_used);
 546       }
 547     }
 548 
 549     for (int j = max_level_collected; j >= 0; j -= 1) {
 550       // Adjust generation sizes.
 551       _gens[j]->compute_new_size();
 552     }
 553 
 554     if (complete) {
 555       // Delete metaspaces for unloaded class loaders and clean up loader_data graph
 556       ClassLoaderDataGraph::purge();
 557       MetaspaceAux::verify_metrics();


   1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/icBuffer.hpp"
  30 #include "gc_implementation/shared/collectorCounters.hpp"
  31 #include "gc_implementation/shared/gcTraceTime.hpp"
  32 #include "gc_implementation/shared/vmGCOperations.hpp"
  33 #include "gc_interface/collectedHeap.inline.hpp"
  34 #include "memory/filemap.hpp"
  35 #include "memory/gcLocker.inline.hpp"
  36 #include "memory/genCollectedHeap.hpp"
  37 #include "memory/genOopClosures.inline.hpp"
  38 #include "memory/generation.inline.hpp"
  39 #include "memory/generationSpec.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "memory/sharedHeap.hpp"
  42 #include "memory/space.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "oops/oop.inline2.hpp"
  45 #include "runtime/aprofiler.hpp"
  46 #include "runtime/biasedLocking.hpp"
  47 #include "runtime/fprofiler.hpp"
  48 #include "runtime/handles.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/vmThread.hpp"


 372   if (GC_locker::check_active_before_gc()) {
 373     return; // GC is disabled (e.g. JNI GetXXXCritical operation)
 374   }
 375 
 376   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
 377                           collector_policy()->should_clear_all_soft_refs();
 378 
 379   ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
 380 
 381   const size_t metadata_prev_used = MetaspaceAux::allocated_used_bytes();
 382 
 383   print_heap_before_gc();
 384 
 385   {
 386     FlagSetting fl(_is_gc_active, true);
 387 
 388     bool complete = full && (max_level == (n_gens()-1));
 389     const char* gc_cause_prefix = complete ? "Full GC" : "GC";
 390     gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
 391     TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
 392     GCTraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, NULL);
 393 
 394     gc_prologue(complete);
 395     increment_total_collections(complete);
 396 
 397     size_t gch_prev_used = used();
 398 
 399     int starting_level = 0;
 400     if (full) {
 401       // Search for the oldest generation which will collect all younger
 402       // generations, and start collection loop there.
 403       for (int i = max_level; i >= 0; i--) {
 404         if (_gens[i]->full_collects_younger_generations()) {
 405           starting_level = i;
 406           break;
 407         }
 408       }
 409     }
 410 
 411     bool must_restore_marks_for_biased_locking = false;
 412 
 413     int max_level_collected = starting_level;
 414     for (int i = starting_level; i <= max_level; i++) {
 415       if (_gens[i]->should_collect(full, size, is_tlab)) {
 416         if (i == n_gens() - 1) {  // a major collection is to happen
 417           if (!complete) {
 418             // The full_collections increment was missed above.
 419             increment_total_full_collections();
 420           }
 421           pre_full_gc_dump(NULL);    // do any pre full gc dumps
 422         }
 423         // Timer for individual generations. Last argument is false: no CR
 424         // FIXME: We should try to start the timing earlier to cover more of the GC pause
 425         GCTraceTime t1(_gens[i]->short_name(), PrintGCDetails, false, NULL);
 426         TraceCollectorStats tcs(_gens[i]->counters());
 427         TraceMemoryManagerStats tmms(_gens[i]->kind(),gc_cause());
 428 
 429         size_t prev_used = _gens[i]->used();
 430         _gens[i]->stat_record()->invocations++;
 431         _gens[i]->stat_record()->accumulated_time.start();
 432 
 433         // Must be done anew before each collection because
 434         // a previous collection will do mangling and will
 435         // change top of some spaces.
 436         record_gen_tops_before_GC();
 437 
 438         if (PrintGC && Verbose) {
 439           gclog_or_tty->print("level=%d invoke=%d size=" SIZE_FORMAT,
 440                      i,
 441                      _gens[i]->stat_record()->invocations,
 442                      size*HeapWordSize);
 443         }
 444 
 445         if (VerifyBeforeGC && i >= VerifyGCLevel &&


 519 
 520         if (VerifyAfterGC && i >= VerifyGCLevel &&
 521             total_collections() >= VerifyGCStartAt) {
 522           HandleMark hm;  // Discard invalid handles created during verification
 523           Universe::verify(" VerifyAfterGC:");
 524         }
 525 
 526         if (PrintGCDetails) {
 527           gclog_or_tty->print(":");
 528           _gens[i]->print_heap_change(prev_used);
 529         }
 530       }
 531     }
 532 
 533     // Update "complete" boolean wrt what actually transpired --
 534     // for instance, a promotion failure could have led to
 535     // a whole heap collection.
 536     complete = complete || (max_level_collected == n_gens() - 1);
 537 
 538     if (complete) { // We did a "major" collection
 539       // FIXME: See comment at pre_full_gc_dump call
 540       post_full_gc_dump(NULL);   // do any post full gc dumps
 541     }
 542 
 543     if (PrintGCDetails) {
 544       print_heap_change(gch_prev_used);
 545 
 546       // Print metaspace info for full GC with PrintGCDetails flag.
 547       if (complete) {
 548         MetaspaceAux::print_metaspace_change(metadata_prev_used);
 549       }
 550     }
 551 
 552     for (int j = max_level_collected; j >= 0; j -= 1) {
 553       // Adjust generation sizes.
 554       _gens[j]->compute_new_size();
 555     }
 556 
 557     if (complete) {
 558       // Delete metaspaces for unloaded class loaders and clean up loader_data graph
 559       ClassLoaderDataGraph::purge();
 560       MetaspaceAux::verify_metrics();