src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp

Mon, 28 Jul 2008 15:30:23 -0700

author
jmasa
date
Mon, 28 Jul 2008 15:30:23 -0700
changeset 704
850fdf70db2b
parent 698
12eea04c8b06
child 772
9ee9cf798b59
child 809
a4b729f5b611
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_psMarkSweep.cpp.incl"
    28 elapsedTimer        PSMarkSweep::_accumulated_time;
    29 unsigned int        PSMarkSweep::_total_invocations = 0;
    30 jlong               PSMarkSweep::_time_of_last_gc   = 0;
    31 CollectorCounters*  PSMarkSweep::_counters = NULL;
    33 void PSMarkSweep::initialize() {
    34   MemRegion mr = Universe::heap()->reserved_region();
    35   _ref_processor = new ReferenceProcessor(mr,
    36                                           true,    // atomic_discovery
    37                                           false);  // mt_discovery
    38   if (!UseParallelOldGC || !VerifyParallelOldWithMarkSweep) {
    39     _counters = new CollectorCounters("PSMarkSweep", 1);
    40   }
    41 }
    43 // This method contains all heap specific policy for invoking mark sweep.
    44 // PSMarkSweep::invoke_no_policy() will only attempt to mark-sweep-compact
    45 // the heap. It will do nothing further. If we need to bail out for policy
    46 // reasons, scavenge before full gc, or any other specialized behavior, it
    47 // needs to be added here.
    48 //
    49 // Note that this method should only be called from the vm_thread while
    50 // at a safepoint!
    51 void PSMarkSweep::invoke(bool maximum_heap_compaction) {
    52   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
    53   assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
    54   assert(!Universe::heap()->is_gc_active(), "not reentrant");
    56   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
    57   GCCause::Cause gc_cause = heap->gc_cause();
    58   PSAdaptiveSizePolicy* policy = heap->size_policy();
    60   // Before each allocation/collection attempt, find out from the
    61   // policy object if GCs are, on the whole, taking too long. If so,
    62   // bail out without attempting a collection.  The exceptions are
    63   // for explicitly requested GC's.
    64   if (!policy->gc_time_limit_exceeded() ||
    65       GCCause::is_user_requested_gc(gc_cause) ||
    66       GCCause::is_serviceability_requested_gc(gc_cause)) {
    67     IsGCActiveMark mark;
    69     if (ScavengeBeforeFullGC) {
    70       PSScavenge::invoke_no_policy();
    71     }
    73     int count = (maximum_heap_compaction)?1:MarkSweepAlwaysCompactCount;
    74     IntFlagSetting flag_setting(MarkSweepAlwaysCompactCount, count);
    75     PSMarkSweep::invoke_no_policy(maximum_heap_compaction);
    76   }
    77 }
    79 // This method contains no policy. You should probably
    80 // be calling invoke() instead.
    81 void PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
    82   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
    83   assert(ref_processor() != NULL, "Sanity");
    85   if (GC_locker::check_active_before_gc()) {
    86     return;
    87   }
    89   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
    90   GCCause::Cause gc_cause = heap->gc_cause();
    91   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
    92   PSAdaptiveSizePolicy* size_policy = heap->size_policy();
    94   PSYoungGen* young_gen = heap->young_gen();
    95   PSOldGen* old_gen = heap->old_gen();
    96   PSPermGen* perm_gen = heap->perm_gen();
    98   // Increment the invocation count
    99   heap->increment_total_collections(true /* full */);
   101   // Save information needed to minimize mangling
   102   heap->record_gen_tops_before_GC();
   104   // We need to track unique mark sweep invocations as well.
   105   _total_invocations++;
   107   AdaptiveSizePolicyOutput(size_policy, heap->total_collections());
   109   if (PrintHeapAtGC) {
   110     Universe::print_heap_before_gc();
   111   }
   113   // Fill in TLABs
   114   heap->accumulate_statistics_all_tlabs();
   115   heap->ensure_parsability(true);  // retire TLABs
   117   if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
   118     HandleMark hm;  // Discard invalid handles created during verification
   119     gclog_or_tty->print(" VerifyBeforeGC:");
   120     Universe::verify(true);
   121   }
   123   // Verify object start arrays
   124   if (VerifyObjectStartArray &&
   125       VerifyBeforeGC) {
   126     old_gen->verify_object_start_array();
   127     perm_gen->verify_object_start_array();
   128   }
   130   // Filled in below to track the state of the young gen after the collection.
   131   bool eden_empty;
   132   bool survivors_empty;
   133   bool young_gen_empty;
   135   {
   136     HandleMark hm;
   137     const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc;
   138     // This is useful for debugging but don't change the output the
   139     // the customer sees.
   140     const char* gc_cause_str = "Full GC";
   141     if (is_system_gc && PrintGCDetails) {
   142       gc_cause_str = "Full GC (System)";
   143     }
   144     gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
   145     TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
   146     TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty);
   147     TraceCollectorStats tcs(counters());
   148     TraceMemoryManagerStats tms(true /* Full GC */);
   150     if (TraceGen1Time) accumulated_time()->start();
   152     // Let the size policy know we're starting
   153     size_policy->major_collection_begin();
   155     // When collecting the permanent generation methodOops may be moving,
   156     // so we either have to flush all bcp data or convert it into bci.
   157     CodeCache::gc_prologue();
   158     Threads::gc_prologue();
   159     BiasedLocking::preserve_marks();
   161     // Capture heap size before collection for printing.
   162     size_t prev_used = heap->used();
   164     // Capture perm gen size before collection for sizing.
   165     size_t perm_gen_prev_used = perm_gen->used_in_bytes();
   167     // For PrintGCDetails
   168     size_t old_gen_prev_used = old_gen->used_in_bytes();
   169     size_t young_gen_prev_used = young_gen->used_in_bytes();
   171     allocate_stacks();
   173     NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
   174     COMPILER2_PRESENT(DerivedPointerTable::clear());
   176     ref_processor()->enable_discovery();
   178     mark_sweep_phase1(clear_all_softrefs);
   180     mark_sweep_phase2();
   182     // Don't add any more derived pointers during phase3
   183     COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity"));
   184     COMPILER2_PRESENT(DerivedPointerTable::set_active(false));
   186     mark_sweep_phase3();
   188     mark_sweep_phase4();
   190     restore_marks();
   192     deallocate_stacks();
   194     if (ZapUnusedHeapArea) {
   195       // Do a complete mangle (top to end) because the usage for
   196       // scratch does not maintain a top pointer.
   197       young_gen->to_space()->mangle_unused_area_complete();
   198     }
   200     eden_empty = young_gen->eden_space()->is_empty();
   201     if (!eden_empty) {
   202       eden_empty = absorb_live_data_from_eden(size_policy, young_gen, old_gen);
   203     }
   205     // Update heap occupancy information which is used as
   206     // input to soft ref clearing policy at the next gc.
   207     Universe::update_heap_info_at_gc();
   209     survivors_empty = young_gen->from_space()->is_empty() &&
   210                       young_gen->to_space()->is_empty();
   211     young_gen_empty = eden_empty && survivors_empty;
   213     BarrierSet* bs = heap->barrier_set();
   214     if (bs->is_a(BarrierSet::ModRef)) {
   215       ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs;
   216       MemRegion old_mr = heap->old_gen()->reserved();
   217       MemRegion perm_mr = heap->perm_gen()->reserved();
   218       assert(perm_mr.end() <= old_mr.start(), "Generations out of order");
   220       if (young_gen_empty) {
   221         modBS->clear(MemRegion(perm_mr.start(), old_mr.end()));
   222       } else {
   223         modBS->invalidate(MemRegion(perm_mr.start(), old_mr.end()));
   224       }
   225     }
   227     BiasedLocking::restore_marks();
   228     Threads::gc_epilogue();
   229     CodeCache::gc_epilogue();
   231     COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
   233     ref_processor()->enqueue_discovered_references(NULL);
   235     // Update time of last GC
   236     reset_millis_since_last_gc();
   238     // Let the size policy know we're done
   239     size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause);
   241     if (UseAdaptiveSizePolicy) {
   243       if (PrintAdaptiveSizePolicy) {
   244         gclog_or_tty->print("AdaptiveSizeStart: ");
   245         gclog_or_tty->stamp();
   246         gclog_or_tty->print_cr(" collection: %d ",
   247                        heap->total_collections());
   248         if (Verbose) {
   249           gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d"
   250             " perm_gen_capacity: %d ",
   251             old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes(),
   252             perm_gen->capacity_in_bytes());
   253         }
   254       }
   256       // Don't check if the size_policy is ready here.  Let
   257       // the size_policy check that internally.
   258       if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
   259           ((gc_cause != GCCause::_java_lang_system_gc) ||
   260             UseAdaptiveSizePolicyWithSystemGC)) {
   261         // Calculate optimal free space amounts
   262         assert(young_gen->max_size() >
   263           young_gen->from_space()->capacity_in_bytes() +
   264           young_gen->to_space()->capacity_in_bytes(),
   265           "Sizes of space in young gen are out-of-bounds");
   266         size_t max_eden_size = young_gen->max_size() -
   267           young_gen->from_space()->capacity_in_bytes() -
   268           young_gen->to_space()->capacity_in_bytes();
   269         size_policy->compute_generation_free_space(young_gen->used_in_bytes(),
   270                                  young_gen->eden_space()->used_in_bytes(),
   271                                  old_gen->used_in_bytes(),
   272                                  perm_gen->used_in_bytes(),
   273                                  young_gen->eden_space()->capacity_in_bytes(),
   274                                  old_gen->max_gen_size(),
   275                                  max_eden_size,
   276                                  true /* full gc*/,
   277                                  gc_cause);
   279         heap->resize_old_gen(size_policy->calculated_old_free_size_in_bytes());
   281         // Don't resize the young generation at an major collection.  A
   282         // desired young generation size may have been calculated but
   283         // resizing the young generation complicates the code because the
   284         // resizing of the old generation may have moved the boundary
   285         // between the young generation and the old generation.  Let the
   286         // young generation resizing happen at the minor collections.
   287       }
   288       if (PrintAdaptiveSizePolicy) {
   289         gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ",
   290                        heap->total_collections());
   291       }
   292     }
   294     if (UsePerfData) {
   295       heap->gc_policy_counters()->update_counters();
   296       heap->gc_policy_counters()->update_old_capacity(
   297         old_gen->capacity_in_bytes());
   298       heap->gc_policy_counters()->update_young_capacity(
   299         young_gen->capacity_in_bytes());
   300     }
   302     heap->resize_all_tlabs();
   304     // We collected the perm gen, so we'll resize it here.
   305     perm_gen->compute_new_size(perm_gen_prev_used);
   307     if (TraceGen1Time) accumulated_time()->stop();
   309     if (PrintGC) {
   310       if (PrintGCDetails) {
   311         // Don't print a GC timestamp here.  This is after the GC so
   312         // would be confusing.
   313         young_gen->print_used_change(young_gen_prev_used);
   314         old_gen->print_used_change(old_gen_prev_used);
   315       }
   316       heap->print_heap_change(prev_used);
   317       // Do perm gen after heap becase prev_used does
   318       // not include the perm gen (done this way in the other
   319       // collectors).
   320       if (PrintGCDetails) {
   321         perm_gen->print_used_change(perm_gen_prev_used);
   322       }
   323     }
   325     // Track memory usage and detect low memory
   326     MemoryService::track_memory_usage();
   327     heap->update_counters();
   329     if (PrintGCDetails) {
   330       if (size_policy->print_gc_time_limit_would_be_exceeded()) {
   331         if (size_policy->gc_time_limit_exceeded()) {
   332           gclog_or_tty->print_cr("      GC time is exceeding GCTimeLimit "
   333             "of %d%%", GCTimeLimit);
   334         } else {
   335           gclog_or_tty->print_cr("      GC time would exceed GCTimeLimit "
   336             "of %d%%", GCTimeLimit);
   337         }
   338       }
   339       size_policy->set_print_gc_time_limit_would_be_exceeded(false);
   340     }
   341   }
   343   if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
   344     HandleMark hm;  // Discard invalid handles created during verification
   345     gclog_or_tty->print(" VerifyAfterGC:");
   346     Universe::verify(false);
   347   }
   349   // Re-verify object start arrays
   350   if (VerifyObjectStartArray &&
   351       VerifyAfterGC) {
   352     old_gen->verify_object_start_array();
   353     perm_gen->verify_object_start_array();
   354   }
   356   if (ZapUnusedHeapArea) {
   357     old_gen->object_space()->check_mangled_unused_area_complete();
   358     perm_gen->object_space()->check_mangled_unused_area_complete();
   359   }
   361   NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
   363   if (PrintHeapAtGC) {
   364     Universe::print_heap_after_gc();
   365   }
   366 }
   368 bool PSMarkSweep::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
   369                                              PSYoungGen* young_gen,
   370                                              PSOldGen* old_gen) {
   371   MutableSpace* const eden_space = young_gen->eden_space();
   372   assert(!eden_space->is_empty(), "eden must be non-empty");
   373   assert(young_gen->virtual_space()->alignment() ==
   374          old_gen->virtual_space()->alignment(), "alignments do not match");
   376   if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) {
   377     return false;
   378   }
   380   // Both generations must be completely committed.
   381   if (young_gen->virtual_space()->uncommitted_size() != 0) {
   382     return false;
   383   }
   384   if (old_gen->virtual_space()->uncommitted_size() != 0) {
   385     return false;
   386   }
   388   // Figure out how much to take from eden.  Include the average amount promoted
   389   // in the total; otherwise the next young gen GC will simply bail out to a
   390   // full GC.
   391   const size_t alignment = old_gen->virtual_space()->alignment();
   392   const size_t eden_used = eden_space->used_in_bytes();
   393   const size_t promoted = (size_t)(size_policy->avg_promoted()->padded_average());
   394   const size_t absorb_size = align_size_up(eden_used + promoted, alignment);
   395   const size_t eden_capacity = eden_space->capacity_in_bytes();
   397   if (absorb_size >= eden_capacity) {
   398     return false; // Must leave some space in eden.
   399   }
   401   const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size;
   402   if (new_young_size < young_gen->min_gen_size()) {
   403     return false; // Respect young gen minimum size.
   404   }
   406   if (TraceAdaptiveGCBoundary && Verbose) {
   407     gclog_or_tty->print(" absorbing " SIZE_FORMAT "K:  "
   408                         "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K "
   409                         "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K "
   410                         "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ",
   411                         absorb_size / K,
   412                         eden_capacity / K, (eden_capacity - absorb_size) / K,
   413                         young_gen->from_space()->used_in_bytes() / K,
   414                         young_gen->to_space()->used_in_bytes() / K,
   415                         young_gen->capacity_in_bytes() / K, new_young_size / K);
   416   }
   418   // Fill the unused part of the old gen.
   419   MutableSpace* const old_space = old_gen->object_space();
   420   MemRegion old_gen_unused(old_space->top(), old_space->end());
   422   // If the unused part of the old gen cannot be filled, skip
   423   // absorbing eden.
   424   if (old_gen_unused.word_size() < SharedHeap::min_fill_size()) {
   425     return false;
   426   }
   428   if (!old_gen_unused.is_empty()) {
   429     SharedHeap::fill_region_with_object(old_gen_unused);
   430   }
   432   // Take the live data from eden and set both top and end in the old gen to
   433   // eden top.  (Need to set end because reset_after_change() mangles the region
   434   // from end to virtual_space->high() in debug builds).
   435   HeapWord* const new_top = eden_space->top();
   436   old_gen->virtual_space()->expand_into(young_gen->virtual_space(),
   437                                         absorb_size);
   438   young_gen->reset_after_change();
   439   old_space->set_top(new_top);
   440   old_space->set_end(new_top);
   441   old_gen->reset_after_change();
   443   // Update the object start array for the filler object and the data from eden.
   444   ObjectStartArray* const start_array = old_gen->start_array();
   445   HeapWord* const start = old_gen_unused.start();
   446   for (HeapWord* addr = start; addr < new_top; addr += oop(addr)->size()) {
   447     start_array->allocate_block(addr);
   448   }
   450   // Could update the promoted average here, but it is not typically updated at
   451   // full GCs and the value to use is unclear.  Something like
   452   //
   453   // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
   455   size_policy->set_bytes_absorbed_from_eden(absorb_size);
   456   return true;
   457 }
   459 void PSMarkSweep::allocate_stacks() {
   460   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   461   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   463   PSYoungGen* young_gen = heap->young_gen();
   465   MutableSpace* to_space = young_gen->to_space();
   466   _preserved_marks = (PreservedMark*)to_space->top();
   467   _preserved_count = 0;
   469   // We want to calculate the size in bytes first.
   470   _preserved_count_max  = pointer_delta(to_space->end(), to_space->top(), sizeof(jbyte));
   471   // Now divide by the size of a PreservedMark
   472   _preserved_count_max /= sizeof(PreservedMark);
   474   _preserved_mark_stack = NULL;
   475   _preserved_oop_stack = NULL;
   477   _marking_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(4000, true);
   479   int size = SystemDictionary::number_of_classes() * 2;
   480   _revisit_klass_stack = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(size, true);
   481 }
   484 void PSMarkSweep::deallocate_stacks() {
   485   if (_preserved_oop_stack) {
   486     delete _preserved_mark_stack;
   487     _preserved_mark_stack = NULL;
   488     delete _preserved_oop_stack;
   489     _preserved_oop_stack = NULL;
   490   }
   492   delete _marking_stack;
   493   delete _revisit_klass_stack;
   494 }
   496 void PSMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
   497   // Recursively traverse all live objects and mark them
   498   EventMark m("1 mark object");
   499   TraceTime tm("phase 1", PrintGCDetails && Verbose, true, gclog_or_tty);
   500   trace(" 1");
   502   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   503   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   505   // General strong roots.
   506   Universe::oops_do(mark_and_push_closure());
   507   ReferenceProcessor::oops_do(mark_and_push_closure());
   508   JNIHandles::oops_do(mark_and_push_closure());   // Global (strong) JNI handles
   509   Threads::oops_do(mark_and_push_closure());
   510   ObjectSynchronizer::oops_do(mark_and_push_closure());
   511   FlatProfiler::oops_do(mark_and_push_closure());
   512   Management::oops_do(mark_and_push_closure());
   513   JvmtiExport::oops_do(mark_and_push_closure());
   514   SystemDictionary::always_strong_oops_do(mark_and_push_closure());
   515   vmSymbols::oops_do(mark_and_push_closure());
   517   // Flush marking stack.
   518   follow_stack();
   520   // Process reference objects found during marking
   522   // Skipping the reference processing for VerifyParallelOldWithMarkSweep
   523   // affects the marking (makes it different).
   524   {
   525     ReferencePolicy *soft_ref_policy;
   526     if (clear_all_softrefs) {
   527       soft_ref_policy = new AlwaysClearPolicy();
   528     } else {
   529 #ifdef COMPILER2
   530       soft_ref_policy = new LRUMaxHeapPolicy();
   531 #else
   532       soft_ref_policy = new LRUCurrentHeapPolicy();
   533 #endif // COMPILER2
   534     }
   535     assert(soft_ref_policy != NULL,"No soft reference policy");
   536     ref_processor()->process_discovered_references(
   537       soft_ref_policy, is_alive_closure(), mark_and_push_closure(),
   538       follow_stack_closure(), NULL);
   539   }
   541   // Follow system dictionary roots and unload classes
   542   bool purged_class = SystemDictionary::do_unloading(is_alive_closure());
   544   // Follow code cache roots
   545   CodeCache::do_unloading(is_alive_closure(), mark_and_push_closure(),
   546                           purged_class);
   547   follow_stack(); // Flush marking stack
   549   // Update subklass/sibling/implementor links of live klasses
   550   follow_weak_klass_links();
   551   assert(_marking_stack->is_empty(), "just drained");
   553   // Visit symbol and interned string tables and delete unmarked oops
   554   SymbolTable::unlink(is_alive_closure());
   555   StringTable::unlink(is_alive_closure());
   557   assert(_marking_stack->is_empty(), "stack should be empty by now");
   558 }
   561 void PSMarkSweep::mark_sweep_phase2() {
   562   EventMark m("2 compute new addresses");
   563   TraceTime tm("phase 2", PrintGCDetails && Verbose, true, gclog_or_tty);
   564   trace("2");
   566   // Now all live objects are marked, compute the new object addresses.
   568   // It is imperative that we traverse perm_gen LAST. If dead space is
   569   // allowed a range of dead object may get overwritten by a dead int
   570   // array. If perm_gen is not traversed last a klassOop may get
   571   // overwritten. This is fine since it is dead, but if the class has dead
   572   // instances we have to skip them, and in order to find their size we
   573   // need the klassOop!
   574   //
   575   // It is not required that we traverse spaces in the same order in
   576   // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
   577   // tracking expects us to do so. See comment under phase4.
   579   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   580   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   582   PSOldGen* old_gen = heap->old_gen();
   583   PSPermGen* perm_gen = heap->perm_gen();
   585   // Begin compacting into the old gen
   586   PSMarkSweepDecorator::set_destination_decorator_tenured();
   588   // This will also compact the young gen spaces.
   589   old_gen->precompact();
   591   // Compact the perm gen into the perm gen
   592   PSMarkSweepDecorator::set_destination_decorator_perm_gen();
   594   perm_gen->precompact();
   595 }
   597 // This should be moved to the shared markSweep code!
   598 class PSAlwaysTrueClosure: public BoolObjectClosure {
   599 public:
   600   void do_object(oop p) { ShouldNotReachHere(); }
   601   bool do_object_b(oop p) { return true; }
   602 };
   603 static PSAlwaysTrueClosure always_true;
   605 void PSMarkSweep::mark_sweep_phase3() {
   606   // Adjust the pointers to reflect the new locations
   607   EventMark m("3 adjust pointers");
   608   TraceTime tm("phase 3", PrintGCDetails && Verbose, true, gclog_or_tty);
   609   trace("3");
   611   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   612   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   614   PSYoungGen* young_gen = heap->young_gen();
   615   PSOldGen* old_gen = heap->old_gen();
   616   PSPermGen* perm_gen = heap->perm_gen();
   618   // General strong roots.
   619   Universe::oops_do(adjust_root_pointer_closure());
   620   ReferenceProcessor::oops_do(adjust_root_pointer_closure());
   621   JNIHandles::oops_do(adjust_root_pointer_closure());   // Global (strong) JNI handles
   622   Threads::oops_do(adjust_root_pointer_closure());
   623   ObjectSynchronizer::oops_do(adjust_root_pointer_closure());
   624   FlatProfiler::oops_do(adjust_root_pointer_closure());
   625   Management::oops_do(adjust_root_pointer_closure());
   626   JvmtiExport::oops_do(adjust_root_pointer_closure());
   627   // SO_AllClasses
   628   SystemDictionary::oops_do(adjust_root_pointer_closure());
   629   vmSymbols::oops_do(adjust_root_pointer_closure());
   631   // Now adjust pointers in remaining weak roots.  (All of which should
   632   // have been cleared if they pointed to non-surviving objects.)
   633   // Global (weak) JNI handles
   634   JNIHandles::weak_oops_do(&always_true, adjust_root_pointer_closure());
   636   CodeCache::oops_do(adjust_pointer_closure());
   637   SymbolTable::oops_do(adjust_root_pointer_closure());
   638   StringTable::oops_do(adjust_root_pointer_closure());
   639   ref_processor()->weak_oops_do(adjust_root_pointer_closure());
   640   PSScavenge::reference_processor()->weak_oops_do(adjust_root_pointer_closure());
   642   adjust_marks();
   644   young_gen->adjust_pointers();
   645   old_gen->adjust_pointers();
   646   perm_gen->adjust_pointers();
   647 }
   649 void PSMarkSweep::mark_sweep_phase4() {
   650   EventMark m("4 compact heap");
   651   TraceTime tm("phase 4", PrintGCDetails && Verbose, true, gclog_or_tty);
   652   trace("4");
   654   // All pointers are now adjusted, move objects accordingly
   656   // It is imperative that we traverse perm_gen first in phase4. All
   657   // classes must be allocated earlier than their instances, and traversing
   658   // perm_gen first makes sure that all klassOops have moved to their new
   659   // location before any instance does a dispatch through it's klass!
   660   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   661   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   663   PSYoungGen* young_gen = heap->young_gen();
   664   PSOldGen* old_gen = heap->old_gen();
   665   PSPermGen* perm_gen = heap->perm_gen();
   667   perm_gen->compact();
   668   old_gen->compact();
   669   young_gen->compact();
   670 }
   672 jlong PSMarkSweep::millis_since_last_gc() {
   673   jlong ret_val = os::javaTimeMillis() - _time_of_last_gc;
   674   // XXX See note in genCollectedHeap::millis_since_last_gc().
   675   if (ret_val < 0) {
   676     NOT_PRODUCT(warning("time warp: %d", ret_val);)
   677     return 0;
   678   }
   679   return ret_val;
   680 }
   682 void PSMarkSweep::reset_millis_since_last_gc() {
   683   _time_of_last_gc = os::javaTimeMillis();
   684 }

mercurial