hotspot/src/share/vm/gc_implementation/g1/concurrentMarkThread.cpp
changeset 7923 fc200fcd4e05
parent 7455 22e19e8c0beb
child 8071 195789ab14f9
equal deleted inserted replaced
7922:e97540c35e38 7923:fc200fcd4e05
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    93 void ConcurrentMarkThread::run() {
    93 void ConcurrentMarkThread::run() {
    94   initialize_in_thread();
    94   initialize_in_thread();
    95   _vtime_start = os::elapsedVTime();
    95   _vtime_start = os::elapsedVTime();
    96   wait_for_universe_init();
    96   wait_for_universe_init();
    97 
    97 
    98   G1CollectedHeap* g1 = G1CollectedHeap::heap();
    98   G1CollectedHeap* g1h = G1CollectedHeap::heap();
    99   G1CollectorPolicy* g1_policy = g1->g1_policy();
    99   G1CollectorPolicy* g1_policy = g1h->g1_policy();
   100   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
   100   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
   101   Thread *current_thread = Thread::current();
   101   Thread *current_thread = Thread::current();
   102 
   102 
   103   while (!_should_terminate) {
   103   while (!_should_terminate) {
   104     // wait until started is set.
   104     // wait until started is set.
   117       }
   117       }
   118 
   118 
   119       if (!g1_policy->in_young_gc_mode()) {
   119       if (!g1_policy->in_young_gc_mode()) {
   120         // this ensures the flag is not set if we bail out of the marking
   120         // this ensures the flag is not set if we bail out of the marking
   121         // cycle; normally the flag is cleared immediately after cleanup
   121         // cycle; normally the flag is cleared immediately after cleanup
   122         g1->set_marking_complete();
   122         g1h->set_marking_complete();
   123 
   123 
   124         if (g1_policy->adaptive_young_list_length()) {
   124         if (g1_policy->adaptive_young_list_length()) {
   125           double now = os::elapsedTime();
   125           double now = os::elapsedTime();
   126           double init_prediction_ms = g1_policy->predict_init_time_ms();
   126           double init_prediction_ms = g1_policy->predict_init_time_ms();
   127           jlong sleep_time_ms = mmu_tracker->when_ms(now, init_prediction_ms);
   127           jlong sleep_time_ms = mmu_tracker->when_ms(now, init_prediction_ms);
   226         CMCleanUp cl_cl(_cm);
   226         CMCleanUp cl_cl(_cm);
   227         sprintf(verbose_str, "GC cleanup");
   227         sprintf(verbose_str, "GC cleanup");
   228         VM_CGC_Operation op(&cl_cl, verbose_str);
   228         VM_CGC_Operation op(&cl_cl, verbose_str);
   229         VMThread::execute(&op);
   229         VMThread::execute(&op);
   230       } else {
   230       } else {
   231         G1CollectedHeap::heap()->set_marking_complete();
   231         g1h->set_marking_complete();
   232       }
   232       }
   233 
   233 
   234       if (!cm()->has_aborted()) {
   234       // Check if cleanup set the free_regions_coming flag. If it
       
   235       // hasn't, we can just skip the next step.
       
   236       if (g1h->free_regions_coming()) {
       
   237         // The following will finish freeing up any regions that we
       
   238         // found to be empty during cleanup. We'll do this part
       
   239         // without joining the suspendible set. If an evacuation pause
       
   240         // takes places, then we would carry on freeing regions in
       
   241         // case they are needed by the pause. If a Full GC takes
       
   242         // places, it would wait for us to process the regions
       
   243         // reclaimed by cleanup.
       
   244 
   235         double cleanup_start_sec = os::elapsedTime();
   245         double cleanup_start_sec = os::elapsedTime();
   236         if (PrintGC) {
   246         if (PrintGC) {
   237           gclog_or_tty->date_stamp(PrintGCDateStamps);
   247           gclog_or_tty->date_stamp(PrintGCDateStamps);
   238           gclog_or_tty->stamp(PrintGCTimeStamps);
   248           gclog_or_tty->stamp(PrintGCTimeStamps);
   239           gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
   249           gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
   240         }
   250         }
   241 
   251 
   242         // Now do the remainder of the cleanup operation.
   252         // Now do the remainder of the cleanup operation.
   243         _sts.join();
       
   244         _cm->completeCleanup();
   253         _cm->completeCleanup();
   245         if (!cm()->has_aborted()) {
   254         g1_policy->record_concurrent_mark_cleanup_completed();
   246           g1_policy->record_concurrent_mark_cleanup_completed();
   255 
   247 
   256         double cleanup_end_sec = os::elapsedTime();
   248           double cleanup_end_sec = os::elapsedTime();
   257         if (PrintGC) {
   249           if (PrintGC) {
   258           gclog_or_tty->date_stamp(PrintGCDateStamps);
   250             gclog_or_tty->date_stamp(PrintGCDateStamps);
   259           gclog_or_tty->stamp(PrintGCTimeStamps);
   251             gclog_or_tty->stamp(PrintGCTimeStamps);
   260           gclog_or_tty->print_cr("[GC concurrent-cleanup-end, %1.7lf]",
   252             gclog_or_tty->print_cr("[GC concurrent-cleanup-end, %1.7lf]",
   261                                  cleanup_end_sec - cleanup_start_sec);
   253                                    cleanup_end_sec - cleanup_start_sec);
   262         }
   254           }
   263 
   255         }
   264         // We're done: no more free regions coming.
   256         _sts.leave();
   265         g1h->reset_free_regions_coming();
   257       }
   266       }
   258       // We're done: no more unclean regions coming.
   267       guarantee(cm()->cleanup_list_is_empty(),
   259       G1CollectedHeap::heap()->set_unclean_regions_coming(false);
   268                 "at this point there should be no regions on the cleanup list");
   260 
   269 
   261       if (cm()->has_aborted()) {
   270       if (cm()->has_aborted()) {
   262         if (PrintGC) {
   271         if (PrintGC) {
   263           gclog_or_tty->date_stamp(PrintGCDateStamps);
   272           gclog_or_tty->date_stamp(PrintGCDateStamps);
   264           gclog_or_tty->stamp(PrintGCTimeStamps);
   273           gclog_or_tty->stamp(PrintGCTimeStamps);
   276     // Update the number of full collections that have been
   285     // Update the number of full collections that have been
   277     // completed. This will also notify the FullGCCount_lock in case a
   286     // completed. This will also notify the FullGCCount_lock in case a
   278     // Java thread is waiting for a full GC to happen (e.g., it
   287     // Java thread is waiting for a full GC to happen (e.g., it
   279     // called System.gc() with +ExplicitGCInvokesConcurrent).
   288     // called System.gc() with +ExplicitGCInvokesConcurrent).
   280     _sts.join();
   289     _sts.join();
   281     g1->increment_full_collections_completed(true /* concurrent */);
   290     g1h->increment_full_collections_completed(true /* concurrent */);
   282     _sts.leave();
   291     _sts.leave();
   283   }
   292   }
   284   assert(_should_terminate, "just checking");
   293   assert(_should_terminate, "just checking");
   285 
   294 
   286   terminate();
   295   terminate();